Skip to content

Fitting using modified Bessel function of the second kind scipy.special.kn #220

Answered by s-kuberski
DarioPanfalone asked this question in Q&A
Discussion options

You must be logged in to vote

Hi Dario,

expanding on the last part of Fabians comment, there is also a more elegant way. As explained in the autograd documentation in https://github.com/HIPS/autograd/blob/master/docs/tutorial.md#extend-autograd-by-defining-your-own-primitives you can define your own differentiable functions. In your case, you need the fist and second derivative for the error propagation in the fit routine.

We can define those using

from autograd.extend import primitive, defvjp, defjvp
k0sp = lambda x: scipy.special.kn(0, x)
k1sp = lambda x: scipy.special.kn(1, x)
k2sp = lambda x: scipy.special.kn(2, x)
k0ag = primitive(k0sp)
k1ag = primitive(k1sp)
# derivatives as defined in https://functions.wolfram.…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@fjosw
Comment options

fjosw Dec 6, 2023
Maintainer

@fjosw
Comment options

fjosw Dec 6, 2023
Maintainer

@s-kuberski
Comment options

Answer selected by fjosw
Comment options

You must be logged in to vote
1 reply
@fjosw
Comment options

fjosw Jan 7, 2024
Maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants