Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

analytic Jacobian #94

Open
bjarthur opened this issue Aug 17, 2016 · 2 comments
Open

analytic Jacobian #94

bjarthur opened this issue Aug 17, 2016 · 2 comments

Comments

@bjarthur
Copy link

i wrote counterparts to the existing finite_difference_jacobian for the case where the function of interest is analytically differentiable. happy to submit a PR if there is interest. would just need to know the best place to put it.

function analytic_jacobian{T<:Number}(fdot::Vector{Function}, x::Vector{T})
    f_x = fdot[1](x)
    J = Array(Float64,length(f_x),length(x))
    J[:,1] = f_x
    for i = 2:length(fdot)
        J[:,i] = fdot[i](x)
    end
    J
end

"""
    `jacobian(fdot::Vector{Function}) -> g(x::Vector)`

Given a function `f` whose partial derivatives are `fdot`, return a function
`g(x)` which itself returns the Jacobian of `f` at `x`.
"""
function jacobian(fdot::Vector{Function})
    g(x::Vector) = analytic_jacobian(fdot, x)
    return g
end
@mlubin
Copy link
Collaborator

mlubin commented Aug 17, 2016

I'm very confused. What does this do? Why do you need a function to compute the jacobian if you already have functions to evaluate derivatives?

@bjarthur
Copy link
Author

this packages up the output of the derivatives into a single function which returns the Jacobian matrix. since it uses the same interface as it's finite difference counterpart, it's easy to switch between the two. for example, the code structure between the analytic and finite-difference versions of levenberg-marquardt least squares fit can be nearly identical with the addition of these two functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants