Hi All,

Trying out Quicksand at the moment. Very little knowledge of Lua or
Terra, so would appreciate help.

I would like to, in a simple linear regression model, calculate m and
b at the same time but taking expectation over the sample space of the
program. Just to see what happens....

It goes along the lines of... (based on the QS examples)

-- Model definition
linreg = qs.program(function()
  local m = mod:open()
  return terra()
    -- The data
    var xs = array(0.0, 1.0, 2.0, 3.0)
    var ys = array(0.0, 1.0, 4.0, 6.0)
    -- Parameters
    var m = qs.gaussian(0.0, 2.0, {struc=false})
    var b = qs.gaussian(0.0, 2.0, {struc=false})
    var v = qs.gamma(1.0, 1.0, {struc=false})
    -- Condition on all the provided data
    for i=0,4 do
      qs.gaussian.observe(ys[i], m*xs[i]+b, v)
    end
    return m.MandB:init(m, b)
  end
end)

This MandB struct is what I would like to implement properly.
According to the QS guide:

" If the return type of the program is a struct type, then it must
overload several operators: binary + and -, binary * (this should be
an “inner product”), and multiplication and division by a real
number."

How do I do that? I tried plain struct, then struct within a qs.module
but still get

line.t:40: attempting to call a method on a non-structural type <error>
    return m.MandB:init(m, b)

This error on the line that calls qs.infer; or now on the one doing
local m = mod:openAs(linreg)

I understand terra is written "on top" of Lua, and QS on top of terra
- but still I am not able to grasp what's going on from the docs.

Help would be appreciated.

Best regards
Carlos
_______________________________________________
terralang mailing list
[email protected]
https://mailman.stanford.edu/mailman/listinfo/terralang

Reply via email to