public void ProbabilityOfCorrectReponse_DeltaNotEqualToTheta_ReturnsCorrectValue()
        {
            double alpha = .2;
            double delta = .3;
            double chi = .4;
            ThreeParamModelParameters parameters = new ThreeParamModelParameters(alpha, delta, chi);
            ThreeParamProbabilityFunction probabilityFunction = new ThreeParamProbabilityFunction(parameters);

            double theta = .1;
            double p = probabilityFunction.ProbabilityOfCorrectResponse(theta);

            double expectedValue = chi + (1 - chi)*Math.Exp(alpha * (theta - delta)) / (1 + Math.Exp(alpha * (theta - delta)));
            Assert.IsTrue(Math.Abs(expectedValue - p) < Tolerance);
        }
        public void ProbabilityOfCorrectReponse_DeltaEqualsTheta_ReturnsOneHalf()
        {
            double alpha = .2;
            double delta = .3;
            double chi = .4;
            ThreeParamModelParameters parameters = new ThreeParamModelParameters(alpha, delta, chi);
            ThreeParamProbabilityFunction probabilityFunction = new ThreeParamProbabilityFunction(parameters);

            double theta = delta;
            double p = probabilityFunction.ProbabilityOfCorrectResponse(theta);

            double expectedProbability = chi + (1 - chi)*.5;
            Assert.AreEqual(expectedProbability, p);
        }
        public void SecondThetaDerivative_NonTrivialInput_CloseToFiniteDifferenceValue()
        {
            double alpha = .2;
            double delta = .3;
            double chi = .4;
            ThreeParamModelParameters parameters = new ThreeParamModelParameters(alpha, delta, chi);
            ThreeParamProbabilityFunction probabilityFunction = new ThreeParamProbabilityFunction(parameters);
            FiniteDifferencer finiteDifferencer = new FiniteDifferencer(x => probabilityFunction.FirstThetaDerivative(x));

            double theta = .1;
            double secondDerivative = probabilityFunction.SecondThetaDerivative(theta);
            double approxSecondDerivative = finiteDifferencer.ApproximateDerivative(theta);

            Assert.IsTrue(Math.Abs(secondDerivative - approxSecondDerivative) < Tolerance);
        }
        public void GetInformation_NonzeroChi_ReturnsCorrectInfo()
        {
            double alpha = 2;
            double chi = .5;
            double delta = 1;
            ThreeParamModelParameters modelParameters = new ThreeParamModelParameters(alpha, delta, chi);
            ThreeParamItemInformationFunction informationFunction = new ThreeParamItemInformationFunction(modelParameters);
            const double theta = .3;

            ThreeParamProbabilityFunction probabilityFunction = new ThreeParamProbabilityFunction(new ThreeParamModelParameters(alpha, delta, chi));
            double p = probabilityFunction.ProbabilityOfCorrectResponse(theta);
            double expectedInfo = alpha*alpha*Math.Pow((p - chi)/(1 - chi), 2)*((1 - p)/p);

            var calculatedInformation = informationFunction.GetInformation(theta);
            Assert.AreEqual(expectedInfo, calculatedInformation, Tolerance);
        }
        public void LogLikelihood_OneIncorrectResponseOneCorrectResponse_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, 0 };
            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(1 - p2);

            Assert.AreEqual(expectedLikelihood, logLikelihood, Tolerance);
        }
        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);
        }