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

FE computation for Categoricals fails when the parameter vector has 0 entries #165

Closed
MagnusKoudahl opened this issue Jul 12, 2022 · 4 comments · Fixed by #169
Closed

FE computation for Categoricals fails when the parameter vector has 0 entries #165

MagnusKoudahl opened this issue Jul 12, 2022 · 4 comments · Fixed by #169

Comments

@MagnusKoudahl
Copy link
Contributor

When running an HMM, FE computation fails due to 0 entries. For example in the model

@model function t_maze(A,D,B,T)
Ac = constvar(A)
z_0 ~ Categorical(D)
z = randomvar(T)
x = datavar(Vector{Float64}, T)
z_prev = z_0
        for t in 1:T
                z[t] ~ Transition(z_prev,B[t])
                x[t] ~ Transition(z[t], Ac)
                z_prev = z[t]
        end
end

We are unable to compute FE if D contains 0's

@bartvanerp
Copy link
Member

Could be related to #75

@bvdmitri
Copy link
Member

@ismailsenoz @ThijsvdLaar

The reason for that is because we need to compute mean(log, q_p) in average energy function for Categorical node here. If q_p is a PointMass and has zero entries, this operation silently returns Inf.

Would it be reasonable to clamp values of parameter vector between tiny and 1? Do we allow this? From math point of view zero entry in p probably means that you don't need this category, so current behaviour is not really a bug IMO, but I would like to know your opinion.

@bvdmitri
Copy link
Member

For reference we already have a similar clamp procedure for the Transition node: here

@ismailsenoz
Copy link
Contributor

ismailsenoz commented Jul 12, 2022

I think clamping and renormalizing the vector should resolve the problem. By definition, the logarithm function can not accept a zero-entry, so this is not a bug in my view. ForneyLab clamp log for entropy computation for a categorical variable (https://github.com/biaslab/ForneyLab.jl/blob/fca07c3bcb3a5abe7393dfb275a2e47e54fd68aa/src/factor_nodes/categorical.jl#L136).

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

Successfully merging a pull request may close this issue.

4 participants