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

invalid ASCII sequence #24

Open
baggepinnen opened this issue Nov 10, 2015 · 1 comment
Open

invalid ASCII sequence #24

baggepinnen opened this issue Nov 10, 2015 · 1 comment

Comments

@baggepinnen
Copy link

I have stumbled upon a bug I can't really explain. I'm trying out autodiff on the pdf for a MvNormal, so I have written a function which takes the parameters of a MvNormal distribution and returns a second function which is the pdf. Autodiff complains at an invalid ASCII-sequence?

using ReverseDiffSource
function fN( m, s)
    k = size(m,1)
    fpdf(x) = begin d = x-m; (sqrt((2*pi)^k*det(s))*exp(-0.5*d'*(inv(s)*d)))[1]; end
end
D = 2
fpdf = fN(zeros(D), eye(D))
dfN = rdiff(fpdf, (zeros(D), ))

julia> dfN = rdiff(fpdf, (zeros(D),))
ERROR: ArgumentError: invalid ASCII sequence
in convert at ./ascii.jl:107
in setindex! at array.jl:314
in show at /local/home/fredrikb/.julia/v0.4/ReverseDiffSource/src/graph.jl:55
in print at strings/io.jl:8
in print_to_string at ./strings/io.jl:36
in myeval at /local/home/fredrikb/.julia/v0.4/ReverseDiffSource/src/graph.jl:322
in evaluate at /local/home/fredrikb/.julia/v0.4/ReverseDiffSource/src/graph.jl:354
in calc! at /local/home/fredrikb/.julia/v0.4/ReverseDiffSource/src/graph.jl:410
in rdiff at /local/home/fredrikb/.julia/v0.4/ReverseDiffSource/src/rdiff.jl:34
in rdiff at /local/home/fredrikb/.julia/v0.4/ReverseDiffSource/src/frdiff.jl:23

@fredo-dedup
Copy link
Contributor

I've discovered not one but several issues in ReverseDiffSource with your example ! I'll see if I can solve them.

In the meantime, here's a workaround :

    D = 2
    m, s = zeros(D), eye(D)

    function fpdf2(x) 
        d = x - m
        dt = d'
        k = size(m,1)
        (sqrt((2*pi) ^ k * det(s)) * exp(-0.5 * (dt * (inv(s) * d))) )[1]
    end

        # new derivation rule needed
    @deriv_rule ctranspose(x::AbstractArray) x ctranspose(ds)
    dfN = rdiff(fpdf2, (zeros(D), ))

    dfN(2*ones(2)) # (value, gradient for x)

Variables m and s have to be defined as globals (not function-local varaibles) for derivation to work. This is a limitation of the package as it's designed currently.

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