Vectors have different size error (Migrated from community.research.microsoft.com) RRS feed

  • Question

  • johno posted on 02-17-2009 6:15 PM

    Dear Infer.NET users,

    Thanks in advance...

    This error message occured either due to my zero experience in C# or Infer.NET:

    System.ArgumentException: Vectors have different size

    Parameter name: that

    at MicrosoftResearch.Infer.Maths.Vector.CheckCompatible(Vector that, String paramName) in C:\infernetBuilds\05-12-2008_17-31\Runtime\Core\Math\Vector.cs:line 926

    after calling Variable.InnerProduct. However I think the vectors (vbeta and vx) are both of length 2.

    I'm trying to build a simple linear regression model (code below).

    Any assistance would be greatly appreciated.

    Thanks, John

    public     void Run() {

    // Get the arrays of ages and prices from mitsub.txt

    double[ ages; double[ prices; int n;

    LoadData(@"data/mitsub.txt", out ages, out prices, out n);

    double A_tau = 0.01;

    double B_tau = 0.01; double sigma2_beta = 1.0E+8;

    Vector vmu_vbeta = new Vector(new double[ { 0.0, 0.0 });

    PositiveDefiniteMatrix mSigma_vbeta =



    // Create priors for tau, vbeta

    Variable<double> tau = Variable.GammaFromShapeAndScale(A_tau,1/B_tau).Named("tau");

    Variable<Vector> vbeta = Variable.VectorGaussianFromMeanAndPrecision(vmu_vbeta, mSigma_vbeta).Named("vbeta");


    Range agesRange = new Range(n).Named("n");

    Vector[ xdata = new Vector;

    for (int i = 0; i < n; i++) xdata = new Vector(1, ages);

    VariableArray<Vector> vx = Variable.Observed(xdata,agesRange).Named("vx");


    VariableArray<double> vmu = Variable.Array<double>(agesRange);

    using(Variable.ForEach(agesRange))  {

    vmu[agesRange] = Variable.InnerProduct(vbeta,vx[agesRange]);



    VariableArray<double> vy = Variable.Array<double>(agesRange);

    vy[agesRange] = Variable.GaussianFromMeanAndPrecision(vmu[agesRange],tau).Named("vy");

    vy.ObservedValue = prices;

    // Create an inference engine for VMP

    InferenceEngine engine = new InferenceEngine(new VariationalMessagePassing());

    Console.WriteLine("Dist over tau=\n" + engine.Infer<Gamma>(tau));

    Console.WriteLine("Dist over vbeta=\n" + engine.Infer<VectorGaussian>(vbeta));



    Friday, June 3, 2011 4:44 PM


  • minka replied on 02-18-2009 11:08 AM

    Hi John, You are calling a different constructor for Vector than you thought. Try changing to "new Vector(1.0, ages)".

    Friday, June 3, 2011 4:44 PM