示例#1
0
        private static double BetaLn(double z, double w)
        {
#if NONE
            return(SpecialFunctions.BetaLn(z, w));
#else
            return(Beta.BetaLn(z, w));
#endif
        }
示例#2
0
        public void BetaLnFunctionForZeroSuccesses()
        {
            var delta = 0.05;
            var prior = new EbisuModel(1.0, 34.4, 3.4);

            var updatedModel = prior.UpdateRecall(0, 5, 0.1);

            Assert.AreEqual(3.0652051705190964, updatedModel.Time, delta);
            Assert.AreEqual(8.706432410647471, updatedModel.Beta, delta);
            Assert.AreEqual(8.760308130181903, updatedModel.Alpha, delta);

#if NONE
            double timeNow   = 0.1;
            double timeBack  = prior.Time;
            int    successes = 0;
            int    total     = 5;
            double alpha     = prior.Alpha;
            double beta      = prior.Beta;
            double t         = prior.Time;
            double dt        = timeNow / t;
            double et        = timeBack / timeNow;
            var    failures  = total - successes;

            var binomlns = Enumerable.Range(0, failures + 1)
                           .Select(i => BinomialLn(failures, i)).ToArray();
            var logs1 =
                Enumerable.Range(0, 3)
                .Select(m =>
            {
                var a =
                    Enumerable.Range(0, failures + 1)
                    .Select(i => binomlns[i] + SpecialFunctions.BetaLn(
                                beta,
                                alpha + (dt * (successes + i)) + (m * dt * et)))
                    .ToList();
                var b = Enumerable.Range(0, failures + 1)
                        .Select(i => Math.Pow(-1.0, i))
                        .ToList();
                return(LogSumExp(a, b)[0]);
            })
                .ToArray();
            var logs2 =
                Enumerable.Range(0, 3)
                .Select(m =>
            {
                var a =
                    Enumerable.Range(0, failures + 1)
                    .Select(i => binomlns[i] + Beta.BetaLn(
                                beta,
                                alpha + (dt * (successes + i)) + (m * dt * et)))
                    .ToList();
                var b = Enumerable.Range(0, failures + 1)
                        .Select(i => Math.Pow(-1.0, i))
                        .ToList();
                return(LogSumExp(a, b)[0]);
            })
                .ToArray();

            for (int i = 0; i < logs1.Length; i++)
            {
                Assert.AreEqual(logs1[i], logs2[i], 1e-3);
            }
#endif
        }