none
Bayesian Frontier Model

    Domanda

  • Hi,

    I am trying to estimate a Bayesian regression model of following form

                        y(i)=x(i)*beta-u(i)+e(i)                  for i=1 ...n

    where y and x are observed variables, beta is a fixed parameter to be estimated, "u" is a random term distribued as Gamma(1,.3) [independently for each "i"] and "e" is a standard error term distributed as N(0,sig2). I am new to Infer.Net and any help is appreciated. Here are my codes which fail to compile (the problem seems to be related to "u").

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    using MicrosoftResearch.Infer.Models;
    using MicrosoftResearch.Infer.Factors;
    using MicrosoftResearch.Infer.Distributions;
    using MicrosoftResearch.Infer;

    namespace myprog

    {
        class Program
        {
            static void Main(string[] args)
            {
    double[] xobs = { 3.6294,
        3.8116,
        2.2540,
        3.8268,
        3.2647,
        2.1951,
        2.5570,
        3.0938,
        3.9150,
        3.9298,
        2.3152,
        3.9412,
        3.9143,
        2.9708,
        3.6006,
        2.2838,
        2.8435,
        3.8315,
        3.5844,
        3.9190};                              
                                   
    double[] yobs = { 3.0755,
        3.4628,
        1.3355,
        3.8752,
        3.1145,
        1.7486,
        2.1976,
        2.8015,
        3.9226,
        3.6761,
        1.6433,
        3.8851,
        3.5840,
        2.6309,
        3.1924,
        1.6277,
        2.1511,
        3.7801,
        3.6262,
        3.8570};
                int n = xobs.Length;
                double A = .01;
                double B = .01;
                Range index = new Range(n).Named("index");

                VariableArray<double> y = Variable.Array<double>(index).Named("y");
                VariableArray<double> x = Variable.Array<double>(index).Named("x");
                VariableArray<double> mu = Variable.Array<double>(index).Named("mu");
                VariableArray<double> u = Variable.Array<double>(index).Named("u");
               
                Variable<double> beta = Variable.GaussianFromMeanAndVariance(0.0, 10).Named("beta");
                Variable<double> tau = Variable.GammaFromShapeAndScale(A, 1/B).Named("tau");
                u[index]= Variable.GammaFromShapeAndScale(1,.3).ForEach(index);
                mu[index] = beta * x[index]-u[index];
                y[index] = Variable.GaussianFromMeanAndPrecision(mu[index], tau);

                x.ObservedValue = xobs;
                y.ObservedValue = yobs;

                var engine = new InferenceEngine();
                engine.Algorithm = new VariationalMessagePassing();

                Console.WriteLine("beta=" + engine.Infer(beta1));
                Console.WriteLine("tau=" + engine.Infer(tau));
                Console.ReadLine();
            }
        }
    }

    Best

    Rez

    lunedì 27 febbraio 2012 13:21

Tutte le risposte

  • Infer.NET does not currently support adding a Gamma-distributed number with a Gaussian-distributed number.  If you just want to ensure that u is positive, you can give it a Gaussian prior and then impose an positivity constraint via ConstrainPositive. 

    Even if such support was added, it would not be as efficient as adding Gaussians.  We have so far deliberately avoided support for operations that we know will be inefficient, because usually there is another choice of model that gives similar results but would be much more efficient.

     

    giovedì 1 marzo 2012 17:12