示例#1
0
 /// <summary>
 /// Sets the priors of BCC.
 /// </summary>
 /// <param name="workerCount">The number of workers.</param>
 /// <param name="priors">The priors.</param>
 protected virtual void SetPriors(int workerCount, Posteriors priors)
 {
     WorkerCount.ObservedValue = workerCount;
     if (priors == null)
     {
         BackgroundLabelProbPrior.ObservedValue = Dirichlet.Uniform(LabelCount);
         var confusionMatrixPrior = GetConfusionMatrixPrior();
         ConfusionMatrixPrior.ObservedValue = Util.ArrayInit(workerCount, worker => Util.ArrayInit(LabelCount, lab => confusionMatrixPrior[lab]));
         TrueLabelConstraint.ObservedValue  = Util.ArrayInit(TaskCount, t => Discrete.Uniform(LabelCount));
     }
     else
     {
         BackgroundLabelProbPrior.ObservedValue = priors.BackgroundLabelProb;
         ConfusionMatrixPrior.ObservedValue     = priors.WorkerConfusionMatrix;
         TrueLabelConstraint.ObservedValue      = priors.TrueLabelConstraint;
     }
 }
示例#2
0
        public Posteriors Run(bool[] recoveredControl, bool[] recoveredTreated, bool showFactorGraph = false)
        {
            Engine.ShowFactorGraph = showFactorGraph;
            // Set the observed values
            numberControl.ObservedValue         = recoveredControl.Length;
            numberTreated.ObservedValue         = recoveredTreated.Length;
            this.recoveredControl.ObservedValue = recoveredControl;
            this.recoveredTreated.ObservedValue = recoveredTreated;

            var result = new Posteriors();

            result.TreatmentHasEffect = Engine.Infer <Bernoulli>(model);
            result.ProbIfControl      = Engine.Infer <Beta>(probControl);
            result.ProbIfTreated      = Engine.Infer <Beta>(probTreated);

            return(result);
        }
示例#3
0
        /// <summary>
        /// Infers the posteriors of BCC using the attached data and priors.
        /// </summary>
        /// <param name="taskIndices">The matrix of the task indices (columns) of each worker (rows).</param>
        /// <param name="workerLabels">The matrix of the labels (columns) of each worker (rows).</param>
        /// <param name="priors">The priors of the BCC parameters.</param>
        /// <returns></returns>
        public virtual Posteriors Infer(int[][] taskIndices, int[][] workerLabels, Posteriors priors)
        {
            int workerCount = workerLabels.Length;

            SetPriors(workerCount, priors);
            AttachData(taskIndices, workerLabels, null);
            var result = new Posteriors();

            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);
        }