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);
        }
        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);
        }
コード例 #4
0
        private static Question GetNextQuestion(string line)
        {
            string[] words          = line.Split(' ');
            string   questionNumber = Convert.ToString(words[0]);

            IModelParameters modelParameters;

            if (words.Length == 4)
            {
                double alpha = Convert.ToDouble(words[1]);
                double delta = Convert.ToDouble(words[2]);
                double chi   = Convert.ToDouble(words[3]);
                modelParameters = new ThreeParamModelParameters(alpha, delta, chi);
            }
            else if (words.Length == 3)
            {
                double alpha = Convert.ToDouble(words[1]);
                double delta = Convert.ToDouble(words[2]);
                modelParameters = new TwoParamModelParameters(alpha, delta);
            }
            else
            {
                throw new NotImplementedException();
            }

            Question question = new Question()
            {
                ModelParameters = modelParameters,
                QuestionLabel   = questionNumber
            };

            return(question);
        }
コード例 #5
0
        public ThreeParamItemInformationFunction(ThreeParamModelParameters modelParameters)
        {
            _alpha = modelParameters.Alpha;
            _chi   = modelParameters.Chi;

            _probabilityFunction = new ThreeParamProbabilityFunction(modelParameters);
        }
        // Second line of the table on page 379 of Ayala.  The three parameter model matches two parameter model when chi = 0
        public void GetInformation_SecondValueLineFromAyala_ReturnsCorrectInfo()
        {
            ThreeParamModelParameters         modelParameters     = new ThreeParamModelParameters(2.954, .560, 0);
            ThreeParamItemInformationFunction informationFunction = new ThreeParamItemInformationFunction(modelParameters);
            const double theta = .3;
            var          calculatedInformation = informationFunction.GetInformation(theta);

            const double expectedInfo = 1.889;

            Assert.AreEqual(expectedInfo, calculatedInformation, Tolerance);
        }
        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 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);
        }
        // In this case the exponent is zero
        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 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 ThreeParamProbabilityFunction(ThreeParamModelParameters parameters)
 {
     _alpha = parameters.Alpha;
     _delta = parameters.Delta;
     _chi   = parameters.Chi;
 }