Getting Random Variables values RRS feed

  • Question

  • Hi everyone

    I'm using Infer.Net for my master project, and, in order to make the results evaluable from a biologic point of view, I need to retrieve some random variables valus when convergence is reached. Below, some codelines to better express my problem:

    var thresholds = Variable.Array<double>(RR).Named("thresholds");
    var thresholdsPrior = Variable.Array<Gaussian>(RR).Named("ThresholdsPrior");
    thresholds[RBP]= Variable<double>.Random(thresholdsPrior[RR]);
    thresholdsPrior.ObservedValue = Util.ArrayInit(numRRs, u => Gaussian.FromMeanAndVariance(0, 1.0));
    InferenceEngine engine = new InferenceEngine();
    // Model
    using (Variable.ForEach(observation))
                 Variable<double> noisyInteractionProb =         Variable.GaussianFromMeanAndVariance(InteractionProb, noisyInteractionProbNoiseVariance);
                 Variable<double> noisyThresholds = Variable.GaussianFromMeanAndVariance(thresholds[RRData[observation]], thresholdsNoiseVariance);
                    interaction[observation] = noisyAffinity > noisyThresholds;
    engine.Compiler.ShowWarnings = true;
    observation.AddAttribute(new Sequential());  
    engine.Compiler.UseSerialSchedules = true;
    var thresholdsPosterior = engine.Infer<Gaussian[]>(thresholds);
    thresholdsPrior.ObservedValue = thresholdsPosterior;

    As you can see, I define a random variable(threshold) for each biological element R, which is used to evaluate the interaciotion between biological elements.

    Now, since I need to evaluate the thresholds and the variables interaction, also for non observed variables, i need to get the threshold values at the end of the inference process. 

    How can I get the value from a random variable, when the system has conveged? 

    Thank you a lot.

    Marco Ciabini

    Sunday, February 2, 2014 9:28 PM

All replies

  • Hi Marco

    Calling Infer on any random variable will retrieve the posterior distributions. So in your case, thresholdsPosterior holds an array of Gaussians. Do you want the means from these posteriors? If so you can get an array of doubles for example by thresholdPosteriors.Select(t => t.GetMean()).ToArray().

    Have I understood your question?


    Monday, February 3, 2014 9:10 AM