/// <summary> /// Use this model to evaluate a context and return an array of the likelihood /// of each outcome given that context. /// </summary> /// <param name="context"> /// The names of the predicates which have been observed at the /// present decision point. </param> /// <param name="outsums"> /// This is where the distribution is stored. </param> /// <returns> The normalized probabilities for the outcomes given the context. /// The indexes of the double[] are the outcome ids, and the actual /// string representation of the outcomes can be obtained from the /// method getOutcome(int i). </returns> public double[] eval(string[] context, float[] values, double[] outsums) { int[] scontexts = new int[context.Length]; for (int i = 0; i < context.Length; i++) { int?ci = pmap.get(context[i]); scontexts[i] = !ci.HasValue ? -1 : ci.GetValueOrDefault(); } prior.logPrior(outsums, scontexts, values); return(GISModel.eval(scontexts, values, outsums, evalParams)); }
public virtual ModelExpactationComputeTask call() { double[] modelDistribution = new double[outerInstance.numOutcomes]; for (int ei = startIndex; ei < startIndex + length; ei++) { // TODO: check interruption status here, if interrupted set a poisoned flag and return if (outerInstance.values != null) { outerInstance.prior.logPrior(modelDistribution, outerInstance.contexts[ei], outerInstance.values[ei]); GISModel.eval(outerInstance.contexts[ei], outerInstance.values[ei], modelDistribution, outerInstance.evalParams); } else { outerInstance.prior.logPrior(modelDistribution, outerInstance.contexts[ei]); GISModel.eval(outerInstance.contexts[ei], modelDistribution, outerInstance.evalParams); } for (int j = 0; j < outerInstance.contexts[ei].Length; j++) { int pi = outerInstance.contexts[ei][j]; if (outerInstance.predicateCounts[pi] >= outerInstance.cutoff) { int[] activeOutcomes = outerInstance.modelExpects[threadIndex][pi].Outcomes; for (int aoi = 0; aoi < activeOutcomes.Length; aoi++) { int oi = activeOutcomes[aoi]; // numTimesEventsSeen must also be thread safe if (outerInstance.values != null && outerInstance.values[ei] != null) { outerInstance.modelExpects[threadIndex][pi].updateParameter(aoi, modelDistribution[oi] * outerInstance.values[ei][j] * outerInstance.numTimesEventsSeen[ei]); } else { outerInstance.modelExpects[threadIndex][pi].updateParameter(aoi, modelDistribution[oi] * outerInstance.numTimesEventsSeen[ei]); } } } } loglikelihood += Math.Log(modelDistribution[outerInstance.outcomeList[ei]]) * outerInstance.numTimesEventsSeen[ei]; numEvents += outerInstance.numTimesEventsSeen[ei]; if (outerInstance.printMessages) { int max = 0; for (int oi = 1; oi < outerInstance.numOutcomes; oi++) { if (modelDistribution[oi] > modelDistribution[max]) { max = oi; } } if (max == outerInstance.outcomeList[ei]) { numCorrect += outerInstance.numTimesEventsSeen[ei]; } } } return(this); }