protected Score MaximizeLikelihoodInternal(MessageInitializer messageInitializer) { OptimizationParameterList paramsToOptimize = messageInitializer.GetOptimizationParameters(); int functionEvaluationCount = 0; bool useLogMethod = false; Converter <OptimizationParameterList, double> functionToOptimize = delegate(OptimizationParameterList paramList) { FuncCalls++; ++functionEvaluationCount; //Debug.WriteLine("EvalCount " + functionEvaluationCount.ToString()); double loglikelihood = ComputeLogLikelihoodModelGivenData(messageInitializer, paramList, useLogMethod); if (!useLogMethod && double.IsNegativeInfinity(loglikelihood)) { useLogMethod = true; loglikelihood = ComputeLogLikelihoodModelGivenData(messageInitializer, paramList, useLogMethod); } //SpecialFunctions.CheckCondition(!double.IsNaN(loglikelihood), "for debugging: got a NaN from ComputeLogLikelihoodModelGivenData"); //if (double.IsNaN(loglikelihood)) //{ // return double.NegativeInfinity; //} return(loglikelihood); }; double loglikelihoodExternal = GridSearch.Optimize(functionToOptimize, paramsToOptimize, 10, 5); Score score = Score.GetInstance(loglikelihoodExternal, paramsToOptimize, messageInitializer.PropogationDistribution); Debug.WriteLine(SpecialFunctions.CreateTabString(GridSearch.DebugCount, score, functionEvaluationCount)); return(score); }