wrapper #142
Replies: 5 comments 1 reply
-
This cannot work because I updated the documentation so as to make this more explicit. If you are only looking at 2x2 matrices, then you can instead write a function Alternatively, you can write a more general function that takes a matrix of numbers with uncertainty, and calls a wrapped version of the function Now, if anybody points me to a simple and efficient formula for the derivative of a determinant with respect to all the matrix coefficients, then I can implement a determinant function that works with any matrix size. I think I looked for this maybe 10 years ago and didn't find anything, but I really may have missed something. |
Beta Was this translation helpful? Give feedback.
-
Worked perfect!
*Inside* the function determinant(c00, c01, c10, c1) I wrote
C = np.array([ [c00, c01],...])
return np.linalg.det(C)
and this worked fine!
Thanks again for the prompt help!
NB: Would sympy not give a symbolic formula for the derivatives of a
determinant? I never tried, though.
Am Di., 24. Aug. 2021 um 14:48 Uhr schrieb Eric O. LEBIGOT (EOL) <
***@***.***>:
… This cannot work because wrap() allows float *arguments* to be replaced
by numbers with uncertainties. In the example above, the function instead
takes a NumPy array.
If you are only looking at 2x2 matrices, then you can instead write a
function determinant(c00, c01, c10, c11) and wrap it.
Now, if anybody points me to a simple and efficient formula for the
derivative of a determinant with respect to all the matrix coefficients,
then I can implement a determinant function that works with any matrix
size. I think I looked for this maybe 10 years ago and didn't find
anything, but I really may have missed something.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#142 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT5MQUU6SGVEV77N5USGPJDT6OIILANCNFSM5CWULRGQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
|
Beta Was this translation helpful? Give feedback.
-
Dear Eric,
I tried another example with uncertainties, this is the code I used:
*import uncertainties*
*from uncertainties.umath import **
*from uncertainties import ufloat*
*import numpy as np*
*import scipy.special as ss*
*n = 3 # Herite degree*
*hermit = ss.hermite(n, monic=True)*
*a = 3.*
*b = 0.3*
*W_hermit = uncertainties.wrap(hermit)*
I got this error message:
AttributeError Traceback (most recent call
last)<ipython-input-37-95dd3703b938> in <module> 11 a = 3. 12
b = 0.3---> 13 W_hermit = uncertainties.wrap(hermit) 14 15
print(hermit(a))
/var/mobile/Containers/Data/Application/F079A96F-4CA5-4A57-A1EE-D9836E97ACC0/Library/lib/python3.9/site-packages/uncertainties/core.py
in wrap(f, derivatives_args, derivatives_kwargs) 643 644
Original documentation:--> 645 %s""" % (f.__name__, f.__doc__))
646 def f_with_affine_output(*args, **kwargs): 647
AttributeError: 'orthopoly1d' object has no attribute '__name__'
What did I do wrong?
Thanks a lot for any help!
On Tue 24. Aug 2021 at 16:03 Eric O. LEBIGOT (EOL) ***@***.***> wrote:
Great.
An analytic formula is not the problem in itself—note that SymPy would not
give the formula for a determinant of any size., though The difficulty lies
instead in finding a *numerically stable and fast to compute* formula for
the derivative of the determinant (with respect to all the coefficients).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#142 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AT5MQUULFRR5MFWXPZ5KX2TT6ORBRANCNFSM5CWULRGQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
.
--
Best regards,
Peter Stahlecker
|
Beta Was this translation helpful? Give feedback.
-
Dear Eric,
I changed my code by introducing an intermediary function *myHermite*, see
below.
Now everything works as it should, but I am not clear, why it is working
now.
Thanks!
*import uncertainties*
*from uncertainties.umath import **
*from uncertainties import ufloat*
*import numpy as np*
*import scipy.special as ss*
*n = 7 # Hermite degree*
*hermit = ss.hermite(n, monic=True)*
*def myHermite(a):*
* return hermit(a)*
*a = 3.*
*b = 0.001*
*print(hermit(a))*
*W_hermit = uncertainties.wrap(myHermite)*
*print(W_hermit(ufloat(a, b)))*
On Wed 25. Aug 2021 at 18:12 Peter Stahlecker ***@***.***>
wrote:
Dear Eric,
I tried another example with uncertainties, this is the code I used:
*import uncertainties*
*from uncertainties.umath import **
*from uncertainties import ufloat*
*import numpy as np*
*import scipy.special as ss*
*n = 3 # Herite degree*
*hermit = ss.hermite(n, monic=True)*
*a = 3.*
*b = 0.3*
*W_hermit = uncertainties.wrap(hermit)*
I got this error message:
AttributeError Traceback (most recent call last)<ipython-input-37-95dd3703b938> in <module> 11 a = 3. 12 b = 0.3---> 13 W_hermit = uncertainties.wrap(hermit) 14 15 print(hermit(a))
/var/mobile/Containers/Data/Application/F079A96F-4CA5-4A57-A1EE-D9836E97ACC0/Library/lib/python3.9/site-packages/uncertainties/core.py in wrap(f, derivatives_args, derivatives_kwargs) 643 644 Original documentation:--> 645 %s""" % (f.__name__, f.__doc__)) 646 def f_with_affine_output(*args, **kwargs): 647
AttributeError: 'orthopoly1d' object has no attribute '__name__'
What did I do wrong?
Thanks a lot for any help!
On Tue 24. Aug 2021 at 16:03 Eric O. LEBIGOT (EOL) <
***@***.***> wrote:
> Great.
>
> An analytic formula is not the problem in itself—note that SymPy would
> not give the formula for a determinant of any size., though The difficulty
> lies instead in finding a *numerically stable and fast to compute*
> formula for the derivative of the determinant (with respect to all the
> coefficients).
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#142 (reply in thread)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/AT5MQUULFRR5MFWXPZ5KX2TT6ORBRANCNFSM5CWULRGQ>
> .
> Triage notifications on the go with GitHub Mobile for iOS
> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
> or Android
> <https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
> .
>
--
Best regards,
Peter Stahlecker
--
Best regards,
Peter Stahlecker
|
Beta Was this translation helpful? Give feedback.
-
Just curiosity:
I wanted to try if uncertainties.wrap will work for recursively defined
functions (It does!)
So, I calculated it using the standard recursive function for factorial.
I also did it the old fashioned way, calculating N! = N * (N-1) *…*1
Both, of course, gave the same result, but the uncertainty with the
recursive function is nearly twice as large compared to the old fashioned
way.
Should it not be the same, theoretically?
On Thu 26. Aug 2021 at 08:08 Peter Stahlecker ***@***.***>
wrote:
Dear Eric,
I changed my code by introducing an intermediary function *myHermite*,
see below.
Now everything works as it should, but I am not clear, why it is working
now.
Thanks!
*import uncertainties*
*from uncertainties.umath import **
*from uncertainties import ufloat*
*import numpy as np*
*import scipy.special as ss*
*n = 7 # Hermite degree*
*hermit = ss.hermite(n, monic=True)*
*def myHermite(a):*
* return hermit(a)*
*a = 3.*
*b = 0.001*
*print(hermit(a))*
*W_hermit = uncertainties.wrap(myHermite)*
*print(W_hermit(ufloat(a, b)))*
On Wed 25. Aug 2021 at 18:12 Peter Stahlecker ***@***.***>
wrote:
> Dear Eric,
>
> I tried another example with uncertainties, this is the code I used:
>
> *import uncertainties*
> *from uncertainties.umath import **
> *from uncertainties import ufloat*
> *import numpy as np*
> *import scipy.special as ss*
>
>
> *n = 3 # Herite degree*
> *hermit = ss.hermite(n, monic=True)*
>
> *a = 3.*
> *b = 0.3*
> *W_hermit = uncertainties.wrap(hermit)*
>
> I got this error message:
>
> AttributeError Traceback (most recent call last)<ipython-input-37-95dd3703b938> in <module> 11 a = 3. 12 b = 0.3---> 13 W_hermit = uncertainties.wrap(hermit) 14 15 print(hermit(a))
> /var/mobile/Containers/Data/Application/F079A96F-4CA5-4A57-A1EE-D9836E97ACC0/Library/lib/python3.9/site-packages/uncertainties/core.py in wrap(f, derivatives_args, derivatives_kwargs) 643 644 Original documentation:--> 645 %s""" % (f.__name__, f.__doc__)) 646 def f_with_affine_output(*args, **kwargs): 647
> AttributeError: 'orthopoly1d' object has no attribute '__name__'
>
>
> What did I do wrong?
>
> Thanks a lot for any help!
>
>
>
> On Tue 24. Aug 2021 at 16:03 Eric O. LEBIGOT (EOL) <
> ***@***.***> wrote:
>
>> Great.
>>
>> An analytic formula is not the problem in itself—note that SymPy would
>> not give the formula for a determinant of any size., though The difficulty
>> lies instead in finding a *numerically stable and fast to compute*
>> formula for the derivative of the determinant (with respect to all the
>> coefficients).
>>
>> —
>> You are receiving this because you authored the thread.
>> Reply to this email directly, view it on GitHub
>> <#142 (reply in thread)>,
>> or unsubscribe
>> <https://github.com/notifications/unsubscribe-auth/AT5MQUULFRR5MFWXPZ5KX2TT6ORBRANCNFSM5CWULRGQ>
>> .
>> Triage notifications on the go with GitHub Mobile for iOS
>> <https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
>> or Android
>> <https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email>
>> .
>>
> --
> Best regards,
>
> Peter Stahlecker
>
--
Best regards,
Peter Stahlecker
--
Best regards,
Peter Stahlecker
|
Beta Was this translation helpful? Give feedback.
-
I tried the following:
C = np.array([unfloat(..), .... ]] a 2x2 matrix
def determinante(C):
return np.linalg.det(C)
W_det = uncertainties.wrap(determinante)
print(W_det(C))
I got an TypeError: No loop matching the specified signature and casting was found for ufunc det
Where is my mistake? Any help is greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions