Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8894539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:31:29+00:00 2026-06-14T23:31:29+00:00

I’m trying to modify an example from Infer.NET to make it more flexible. I

  • 0

I’m trying to modify an example from Infer.NET to make it more flexible. I want to be able to send any number of metrics to draw upon for the predictions.

I created the following wrapper class (very close to the original example):

class Inference
{
    private readonly List<List<double>> _pastMetrics = new List<List<double>>();

    public void AddPastMetrics(List<double> pastMetrics)
    {
        _pastMetrics.Add(pastMetrics);
    }

    private readonly List<Boolean> _pastResults = new List<Boolean>();

    public void AddPastResults(Boolean pastResults)
    {
        _pastResults.Add(pastResults);
    }

    private readonly List<List<double>> _testMetrics = new List<List<double>>();

    public void AddTestMetrics(List<double> dayMetrics)
    {
        _testMetrics.Add(dayMetrics);
    }

    public Object GetInfer()
    {
        // Create x vector, augmented by 1
        Vector[] xdata = new Vector[_pastMetrics.Count];
        for (int i = 0; i < xdata.Length; i++)
            xdata[i] = Vector.FromList(_pastMetrics[i]);
        VariableArray<Vector> x = Variable.Observed(xdata);

        // Create target y
        VariableArray<bool> y = Variable.Observed(_pastResults.ToArray(), x.Range);
        var count = _pastMetrics.First().Count;
        Variable<Vector> w = Variable.Random(new VectorGaussian(Vector.Zero(count), PositiveDefiniteMatrix.Identity(count)));
        Range j = y.Range;
        double noise = 0.1;
        y[j] = Variable.GaussianFromMeanAndVariance(Variable.InnerProduct(w, x[j]), noise) > 0;

        InferenceEngine engine = new InferenceEngine(new ExpectationPropagation());
        VectorGaussian wPosterior = engine.Infer<VectorGaussian>(w);

        VariableArray<bool> ytest = Variable.Array<bool>(new Range(_pastMetrics.Count));
        BayesPointMachine(Variable.Random(wPosterior), ytest);
        return engine.Infer(ytest);

    }

    void BayesPointMachine(Variable<Vector> w, VariableArray<bool> y)
    {
        // Create x vector, augmented by 1
        Range j = y.Range;
        Vector[] xdata = new Vector[_testMetrics.Count];
        for (int i = 0; i < xdata.Length; i++)
            xdata[i] = Vector.FromList(_testMetrics[i]);
        VariableArray<Vector> x = Variable.Observed(xdata, j);

        // Bayes Point Machine
        double noise = 0.1;
        y[j] = Variable.GaussianFromMeanAndVariance(Variable.InnerProduct(w, x[j]), noise) > 0;
    }
}

Here’s the Main procedure:

static void Main()
{   
    var inf = new Inference();
    double[] incomes = { 63, 16, 28, 55, 22, 20 };
    double[] ages = { 38, 23, 40, 27, 18, 40 };
    for (int i = 0; i < incomes.Length; i++)
        inf.AddPastMetrics(new List<double> {incomes[i], ages[i]});

    double[] incomesTest = { 58, 18, 22 };
    double[] agesTest = { 36, 24, 37 };
    for (int i = 0; i < incomesTest.Length; i++)
        inf.AddTestMetrics(new List<double> { incomesTest[i], agesTest[i] });

    bool[] willBuy = { true, false, true, true, false, false };
    for (int i = 0; i < willBuy.Length; i++)
        inf.AddPastResults(willBuy[i]);

    Console.WriteLine("output=\n" + inf.GetInfer());

}

When I call the infer method I get the following error:

Provided array of length 3 when length 6 was expected for variable
‘vVector__1’

Any idea why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:31:30+00:00Added an answer on June 14, 2026 at 11:31 pm

    I forgot to add a 1 to the arrays. From the example page:

    We’ll use the data to train our Bayes Point Machine. To do this, we
    need to create two arrays of observations, one called x consisting of
    vectors of the input features (augmented by appending a 1) and one
    called y which just wraps willBuy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.