public void LogLikelihood_SingleIncorrectResponse_ReturnsCorrectValue()
        {
            double alpha = .3;
            double delta = .1;
            double chi   = .2;
            ThreeParamModelParameters modelParameters    = new ThreeParamModelParameters(alpha, delta, chi);
            List <IModelParameters>   modelParameterList = new List <IModelParameters>();

            modelParameterList.Add(modelParameters);

            LogLikelihoodFunction logLikelihoodFunction = new LogLikelihoodFunction(modelParameterList);

            double     theta          = .4;
            List <int> responseVector = new List <int>()
            {
                0
            };
            double logLikelihood = logLikelihoodFunction.LogLikelihood(responseVector, theta);

            IProbabilityFunction probabilityFunction = new ThreeParamProbabilityFunction(modelParameters);
            double p = probabilityFunction.ProbabilityOfCorrectResponse(theta);
            double expectedLikelihood = Math.Log(1 - p);

            Assert.AreEqual(expectedLikelihood, logLikelihood, Tolerance);
        }
        public void LogLikelihood_TwoCorrectResponses_ReturnsCorrectValue()
        {
            double alpha1 = .3;
            double delta1 = .1;
            double chi1   = .2;
            ThreeParamModelParameters modelParameters1 = new ThreeParamModelParameters(alpha1, delta1, chi1);

            double alpha2 = .5;
            double delta2 = .6;
            double chi2   = .7;
            ThreeParamModelParameters modelParameters2 = new ThreeParamModelParameters(alpha2, delta2, chi2);

            List <IModelParameters> modelParameterList = new List <IModelParameters>();

            modelParameterList.Add(modelParameters1);
            modelParameterList.Add(modelParameters2);

            LogLikelihoodFunction logLikelihoodFunction = new LogLikelihoodFunction(modelParameterList);

            double     theta          = .4;
            List <int> responseVector = new List <int>()
            {
                1, 1
            };
            double logLikelihood = logLikelihoodFunction.LogLikelihood(responseVector, theta);

            IProbabilityFunction probabilityFunction1 = new ThreeParamProbabilityFunction(modelParameters1);
            double p1 = probabilityFunction1.ProbabilityOfCorrectResponse(theta);
            IProbabilityFunction probabilityFunction2 = new ThreeParamProbabilityFunction(modelParameters2);
            double p2 = probabilityFunction2.ProbabilityOfCorrectResponse(theta);
            double expectedLikelihood = Math.Log(p1) + Math.Log(p2);

            Assert.AreEqual(expectedLikelihood, logLikelihood, Tolerance);
        }
        public void LogLikelihoodDerivative_MultipleResponses_MatchesFiniteDifferenceDerivative()
        {
            double alpha1 = .3;
            double delta1 = .1;
            double chi1   = .2;
            ThreeParamModelParameters modelParameters1 = new ThreeParamModelParameters(alpha1, delta1, chi1);

            double alpha2 = .5;
            double delta2 = .6;
            double chi2   = .7;
            ThreeParamModelParameters modelParameters2 = new ThreeParamModelParameters(alpha2, delta2, chi2);

            ThreeParamModelParameters modelParameters3 = new ThreeParamModelParameters(alpha2, delta2, chi2);

            List <IModelParameters> modelParameterList = new List <IModelParameters>();

            modelParameterList.Add(modelParameters1);
            modelParameterList.Add(modelParameters2);
            modelParameterList.Add(modelParameters3);

            LogLikelihoodFunction logLikelihoodFunction = new LogLikelihoodFunction(modelParameterList);

            double     theta          = .4;
            List <int> responseVector = new List <int>()
            {
                1, 0, 1
            };
            OneDimensionalFunction function          = x => logLikelihoodFunction.LogLikelihood(responseVector, x);
            FiniteDifferencer      finiteDifferencer = new FiniteDifferencer(function);

            double logLikelihoodDerivative    = logLikelihoodFunction.LogLikelihoodFirstDerivative(responseVector, theta);
            double finiteDifferenceDerivative = finiteDifferencer.ApproximateDerivative(theta);

            Assert.AreEqual(finiteDifferenceDerivative, logLikelihoodDerivative, Tolerance);
        }