Skip to content

Matrix{RandomVariable} * RandomVariable errors #163

@gvdr

Description

@gvdr

Hello. I'm trying to extend one of the examples but hitting a wall.

I'm building upon the Gaussian Linear Dynamical System example.

In particular I'm trying to generalise it so that we don't assume to know the transition matrix $A$ a priori (eventually, I'd like to get to a scenario where we learn most of those matrices). In the example $A$ is passed as an input, and then converted to a constantvar to be used in the model. I would like it to be given a prior in the model, and then inferred together with the rest of the parameters.

I tried a couple of things, but I can't make it work. A minimum reproducible example is consist in redefining model and inference as follows:

@model function rotate_ssm(n, x0, B, Q, P)
    
    # We create constvar references for better efficiency
    cB = constvar(B)
    cQ = constvar(Q)
    cP = constvar(P)
    
    # `x` is a sequence of hidden states
    x = randomvar(n)
    # THIS IS WHERE I DIVERGE FROM EXAMPLE:
    A = randomvar(2,2)
    # `y` is a sequence of "clamped" observations
    y = datavar(Vector{Float64}, n)
    
    x_prior ~ MvNormalMeanCovariance(mean(x0), cov(x0))
    x_prev = x_prior
    
    α ~ Uniform(0.0,3.0)
    β ~ Uniform(0.0,3.0)

    A .~ Gamma(α,β)
    
    for i in 1:n
        x[i] ~ MvNormalMeanCovariance(A*x_prev, cQ)
        y[i] ~ MvNormalMeanCovariance(cB * x[i], cP)
        x_prev = x[i]
    end

end

And I change the inference function accordingly

result = inference(
    model = rotate_ssm(length(y), x0, B, Q, P), 
    data = (y = y,),
    free_energy = true
)

I tried to specify $A$ in a number of ways, but never getting any luck.

When I try to run it, I get the following error:

ERROR: MethodError: no method matching make_node(::typeof(*), ::FactorNodeCreationOptions{FullFactorisation, Nothing, Nothing}, ::RandomVariable, ::Matrix{RandomVariable}, ::RandomVariable)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions