Giter Club home page Giter Club logo

Comments (15)

mlubin avatar mlubin commented on May 16, 2024

try nu = zeros(eltype(para), point). For AD to work, the code need to take generic input types. zeros without an explicit types defaults to using Float64.

from forwarddiff.jl.

cwliu007 avatar cwliu007 commented on May 16, 2024

Thanks for your quick answer, it works!
Because I am a Matlab user and new to Julia, not quite understand the subtle difference. I command zeros(point) and thenu = zeros(eltype(para), point), and found they are all Float64 type. I found myself always confused with Julia type, even in simple case. :(

from forwarddiff.jl.

mlubin avatar mlubin commented on May 16, 2024

Behind the scenes, ForwardDiff will provide a vector of a different type (not Float64) to compute the derivatives.

from forwarddiff.jl.

cwliu007 avatar cwliu007 commented on May 16, 2024

Hi mlubin,

But it didn't work when using forwarddiff_hessian ...
Error is

`hessian` has no method matching hessian(::Array{FADHessian{Float64,6},1})
in g at C:\Users\genwei\.julia\v0.3\ForwardDiff\src\typed_fad\FADHessian.jl:406

from forwarddiff.jl.

mlubin avatar mlubin commented on May 16, 2024

I'm not too familiar with this code, I'll let @scidom comment on this.

from forwarddiff.jl.

papamarkou avatar papamarkou commented on May 16, 2024

@mlubin, @genwei007 I am on an island without laptop (on holidays), I will leave this issue open and will comment on it upon my return.

from forwarddiff.jl.

marcusps avatar marcusps commented on May 16, 2024

Any updates? I am running into similar problems.

from forwarddiff.jl.

mlubin avatar mlubin commented on May 16, 2024

@marcusps, also with forwarddiff_hessian?

from forwarddiff.jl.

papamarkou avatar papamarkou commented on May 16, 2024

Hi @marcusps, still haven't managed to find a bit of time to look into this, hopefully will get it off my todo list soon.

from forwarddiff.jl.

marcusps avatar marcusps commented on May 16, 2024

Not with the Hessian, but with a gradient, @mlubin. I'll try to get a minimal test case written tomorrow.

from forwarddiff.jl.

cwliu007 avatar cwliu007 commented on May 16, 2024

Hi mlubin and scidom,
Just wonder if other packages like ReverseDiffSource or DualNumbers can work for my previous syntax?

Thanks.

from forwarddiff.jl.

mlubin avatar mlubin commented on May 16, 2024

DualNumbers can be used for Jacobians but not Hessians. ReverseDiffSource could possibly work.

from forwarddiff.jl.

papamarkou avatar papamarkou commented on May 16, 2024

This is issue has been resolved after doing what @mlubin suggested. Sorry that it took months before I sat down to check it out. The problem was exactly that the routines of ForwardDiff don't work with generic input times, so when you defined zeros you have to explicitly tell what type of elements the resulting nu vector will hold. I will close this issue now. For the sake of completeness, here is the operational code for your example in Julia 0.4:

using ForwardDiff

point = 2 # can be used within function
y = [0:(point - 1);]
function GPCM(para)
  a = para[1]
  d = para[2]
  tau = para[3:4]
  t = para[5]
  nu = zeros(eltype(para), point)
  for k = 1:point
    nu[k] = exp(a.*(y[k].*(t-d) - sum(tau[1:k]) )) [1]
  end
  de =  sum(nu)
  p = nu ./ de
end

para = [1.,0.,0.,0.,1.]
Jac = forwarddiff_jacobian(GPCM, Float64, fadtype=:typed)
Jac(para)

from forwarddiff.jl.

cwliu007 avatar cwliu007 commented on May 16, 2024

Hi scidom,

How about 'forwarddiff_hessian' which is not applicable in the present case... Still got errors. Thanks.

from forwarddiff.jl.

papamarkou avatar papamarkou commented on May 16, 2024

Hi @genwei007, let me check this and will let you now if there is an obvious fix.

from forwarddiff.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.