/// <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="outcomeSums"> /// 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 outcomeIndex). /// </returns> public double[] Evaluate(string[] context, double[] outcomeSums) { for (int outcomeIndex = 0; outcomeIndex < _outcomeCount; outcomeIndex++) { outcomeSums[outcomeIndex] = _initialProbability; _featureCounts[outcomeIndex] = 0; } foreach (string con in context) { _reader.GetPredicateData(con, _featureCounts, outcomeSums); } double normal = 0.0; for (int outcomeIndex = 0; outcomeIndex < _outcomeCount; outcomeIndex++) { outcomeSums[outcomeIndex] = Math.Exp((outcomeSums[outcomeIndex] * _correctionConstantInverse) + ((1.0 - (_featureCounts[outcomeIndex] / CorrectionConstant)) * CorrectionParameter)); normal += outcomeSums[outcomeIndex]; } for (int outcomeIndex = 0; outcomeIndex < _outcomeCount; outcomeIndex++) { outcomeSums[outcomeIndex] /= normal; } return(outcomeSums); }
/// <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="outcomeSums"> /// 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 outcomeIndex). /// </returns> public double[] Evaluate(string[] context, double[] outcomeSums) { for (int outcomeIndex = 0; outcomeIndex < mOutcomeCount; outcomeIndex++) { outcomeSums[outcomeIndex] = mInitialProbability; mFeatureCounts[outcomeIndex] = 0; } for (int currentContext = 0; currentContext < context.Length; currentContext++) { mReader.GetPredicateData(context[currentContext], mFeatureCounts, outcomeSums); } double normal = 0.0; for (int outcomeIndex = 0; outcomeIndex < mOutcomeCount; outcomeIndex++) { outcomeSums[outcomeIndex] = System.Math.Exp((outcomeSums[outcomeIndex] * mCorrectionConstantInverse) + ((1.0 - (mFeatureCounts[outcomeIndex] / mCorrectionConstant)) * mCorrectionParameter)); normal += outcomeSums[outcomeIndex]; } for (int outcomeIndex = 0; outcomeIndex < mOutcomeCount; outcomeIndex++) { outcomeSums[outcomeIndex] /= normal; } return(outcomeSums); }