无需数学就能写AI,MIT提出AI专用编程语言Gen( 七 )

(trace, _) = generate(my_model, (xs,), constraints)

# Iteratively update the slope then the intercept,

# using Gen's metropolis_hastings operator.

for iter=1:num_iters

(trace, _) = metropolis_hastings(trace, select(:slope))

(trace, _) = metropolis_hastings(trace, select(:intercept))

end

# From the final trace, read out the slope and

# the intercept.

choices = get_choices(trace)

return (choices[:slope], choices[:intercept])

end

最后,研究人员在一些数据上运行推理,得到下面的结果:

xs = [1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]

推荐阅读