internal void ClickModel( Gaussian inputScoreMean, Gamma inputScorePrec, Gamma inputJudgePrec, Gamma inputClickPrec, Gaussian inputLowerThreshMean, Gaussian inputUpperThreshMean, Gaussian[] clickObservations) // Click observations for this label { int n = clickObservations.Length; // Add variables outside plate - all variables outside the plate should // be marked as outputs because we will be communicating their messages // across labels double scoreMean = Factor.Random(inputScoreMean); double scorePrec = Factor.Random(inputScorePrec); double judgePrec = Factor.Random(inputJudgePrec); double clickPrec = Factor.Random(inputClickPrec); double lowerThresh = Factor.Random(inputLowerThreshMean); double upperThresh = Factor.Random(inputUpperThreshMean); // Now set up the plate double[] scores = new double[n]; double[] scoresJ = new double[n]; double[] scoresC = new double[n]; bool b = true; for (int i = 0; i < n; i++) { scores[i] = Factor.Gaussian(scoreMean, 2.0); // click-based score scoresC[i] = Factor.Gaussian(scores[i], clickPrec); Constrain.EqualRandom(scoresC[i], clickObservations[i]); // judged score scoresJ[i] = Factor.Gaussian(scores[i], judgePrec); b = Factor.IsBetween(scoresJ[i], lowerThresh, upperThresh); } InferNet.Infer(scoreMean, nameof(scoreMean)); InferNet.Infer(scorePrec, nameof(scorePrec)); InferNet.Infer(judgePrec, nameof(judgePrec)); InferNet.Infer(clickPrec, nameof(clickPrec)); InferNet.Infer(lowerThresh, nameof(lowerThresh)); InferNet.Infer(upperThresh, nameof(upperThresh)); }
internal void Click5LabelModel( Gaussian inputScoreMean, Gamma inputScorePrec, Gamma inputJudgePrec, Gamma inputClickPrec, Gaussian[] inputThresh, Gaussian[][] clickObservations) { // Add variables outside plate - all variables outside the plate should // be marked as outputs because we will be communicating their messages // across chunks double scoreMean = Factor.Random(inputScoreMean); double scorePrec = Factor.Random(inputScorePrec); double judgePrec = Factor.Random(inputJudgePrec); double clickPrec = Factor.Random(inputClickPrec); double thresh0 = Factor.Random(inputThresh[0]); double thresh1 = Factor.Random(inputThresh[1]); double thresh2 = Factor.Random(inputThresh[2]); double thresh3 = Factor.Random(inputThresh[3]); double thresh4 = Factor.Random(inputThresh[4]); double thresh5 = Factor.Random(inputThresh[5]); //Attrib.AllVars(new DivideMessages(false), thresh0, thresh1, thresh2, thresh3, thresh4, thresh5); //Attrib.AllVars(new DivideMessages(false), scoreMean, scorePrec, judgePrec, clickPrec); // Plate 1 int n1 = clickObservations[0].Length; double[] scores1 = new double[n1]; double[] scoresJ1 = new double[n1]; double[] scoresC1 = new double[n1]; for (int i1 = 0; i1 < n1; i1++) { Attrib.Var(i1, new Sequential()); scores1[i1] = Factor.Gaussian(scoreMean, scorePrec); // click-based score scoresC1[i1] = Factor.Gaussian(scores1[i1], clickPrec); Constrain.EqualRandom(scoresC1[i1], clickObservations[0][i1]); // judged score scoresJ1[i1] = Factor.Gaussian(scores1[i1], judgePrec); bool h1 = Factor.IsBetween(scoresJ1[i1], thresh0, thresh1); Constrain.Equal(true, h1); } // Plate 2 int n2 = clickObservations[1].Length; double[] scores2 = new double[n2]; double[] scoresJ2 = new double[n2]; double[] scoresC2 = new double[n2]; for (int i2 = 0; i2 < n2; i2++) { Attrib.Var(i2, new Sequential()); scores2[i2] = Factor.Gaussian(scoreMean, scorePrec); // click-based score scoresC2[i2] = Factor.Gaussian(scores2[i2], clickPrec); Constrain.EqualRandom(scoresC2[i2], clickObservations[1][i2]); // judged score scoresJ2[i2] = Factor.Gaussian(scores2[i2], judgePrec); bool h2 = Factor.IsBetween(scoresJ2[i2], thresh1, thresh2); Constrain.Equal(true, h2); } // Plate 3 int n3 = clickObservations[2].Length; double[] scores3 = new double[n3]; double[] scoresJ3 = new double[n3]; double[] scoresC3 = new double[n3]; for (int i3 = 0; i3 < n3; i3++) { Attrib.Var(i3, new Sequential()); scores3[i3] = Factor.Gaussian(scoreMean, scorePrec); // click-based score scoresC3[i3] = Factor.Gaussian(scores3[i3], clickPrec); Constrain.EqualRandom(scoresC3[i3], clickObservations[2][i3]); // judged score scoresJ3[i3] = Factor.Gaussian(scores3[i3], judgePrec); bool h3 = Factor.IsBetween(scoresJ3[i3], thresh2, thresh3); Constrain.Equal(true, h3); } // Plate 4 int n4 = clickObservations[3].Length; double[] scores4 = new double[n4]; double[] scoresJ4 = new double[n4]; double[] scoresC4 = new double[n4]; for (int i4 = 0; i4 < n4; i4++) { Attrib.Var(i4, new Sequential()); scores4[i4] = Factor.Gaussian(scoreMean, scorePrec); // click-based score scoresC4[i4] = Factor.Gaussian(scores4[i4], clickPrec); Constrain.EqualRandom(scoresC4[i4], clickObservations[3][i4]); // judged score scoresJ4[i4] = Factor.Gaussian(scores4[i4], judgePrec); bool h4 = Factor.IsBetween(scoresJ4[i4], thresh3, thresh4); Constrain.Equal(true, h4); } // Plate 5 int n5 = clickObservations[4].Length; double[] scores5 = new double[n5]; double[] scoresJ5 = new double[n5]; double[] scoresC5 = new double[n5]; for (int i5 = 0; i5 < n5; i5++) { Attrib.Var(i5, new Sequential()); scores5[i5] = Factor.Gaussian(scoreMean, scorePrec); // click-based score scoresC5[i5] = Factor.Gaussian(scores5[i5], clickPrec); Constrain.EqualRandom(scoresC5[i5], clickObservations[4][i5]); // judged score scoresJ5[i5] = Factor.Gaussian(scores5[i5], judgePrec); bool h5 = Factor.IsBetween(scoresJ5[i5], thresh4, thresh5); Constrain.Equal(true, h5); } //Attrib.AllVars(new DivideMessages(false), scores1, scores2, scores3, scores4, scores5); //Attrib.AllVars(new DivideMessages(false), scoresC1, scoresC2, scoresC3, scoresC4, scoresC5); //Attrib.AllVars(new DivideMessages(false), scoresJ1, scoresJ2, scoresJ3, scoresJ4, scoresJ5); InferNet.Infer(scoreMean, nameof(scoreMean)); InferNet.Infer(scorePrec, nameof(scorePrec)); InferNet.Infer(judgePrec, nameof(judgePrec)); InferNet.Infer(clickPrec, nameof(clickPrec)); InferNet.Infer(thresh0, nameof(thresh0)); InferNet.Infer(thresh1, nameof(thresh1)); InferNet.Infer(thresh2, nameof(thresh2)); InferNet.Infer(thresh3, nameof(thresh3)); InferNet.Infer(thresh4, nameof(thresh4)); InferNet.Infer(thresh5, nameof(thresh5)); }