locked
How is the prior data and attached data passed to the Infer function? RRS feed

  • General discussion

  • The following code is from the Infer .Net sample. There is a piece of code that is confusing me.

    public virtual BCCPosteriors Infer(int[][] taskIndices, int[][] workerLabels, BCCPosteriors priors)
            {
                int workerCount = workerLabels.Length;
                SetPriors(workerCount, priors);
                AttachData(taskIndices, workerLabels, null);
                var result = new BCCPosteriors();
                Engine.NumberOfIterations = NumberOfIterations;
                result.Evidence = Engine.Infer<Bernoulli>(Evidence);
                result.BackgroundLabelProb = Engine.Infer<Dirichlet>(BackgroundLabelProb);
                result.WorkerConfusionMatrix = Engine.Infer<Dirichlet[][]>(WorkerConfusionMatrix);
                result.TrueLabel = Engine.Infer<Discrete[]>(TrueLabel);
                result.TrueLabelConstraint = Engine.Infer<Discrete[]>(TrueLabel, QueryTypes.MarginalDividedByPrior);
    
                // Prediction mode is indicated by none of the workers having a label.
                // We can just look at the first one
                if (workerLabels[0] == null)
                {
                    result.WorkerPrediction = Engine.Infer<Discrete[][]>(WorkerLabel);
                }
    
                return result;
            }

    This function infers the posteriors of BCC using the attached data and priors. Now, let's look at the line:

     result.BackgroundLabelProb = Engine.Infer<Dirichlet>(BackgroundLabelProb);

    From what I can see, it is passing the variable BackgroundLabelProb, but how is it passing the priors and attached data???

    I have been looking at this the whole day. This is confusing me. Can anyone shed some light here?

    Thanks,

    Thursday, March 5, 2015 2:06 PM

All replies

  • BackgroundLabelProb is an object that points to the other variables in the model.  The priors and data have been attached to these other variables via their ObservedValue property.
    Thursday, March 5, 2015 2:28 PM
    Owner
  • OK that makes sense. But I cannot see where and how in the code the object points to the other variables like BackgroundLabelProbPrior. Looking at itsattributes, props etc, I cannot see:

    What am I missing here?
    • Edited by cindyak Thursday, March 5, 2015 2:50 PM
    Thursday, March 5, 2015 2:50 PM
  • Look in base.definition.
    Thursday, March 5, 2015 2:53 PM
    Owner
  • I checked there already, it is null.

    There is nothing in there.

    Thursday, March 5, 2015 2:59 PM
  • You are right.  Since the variable is created inside of an If block, it would be under base.conditionalDefinitions.
    Thursday, March 5, 2015 3:09 PM
    Owner