예제 #1
0
        public void ParameterTest1()
        {
            LbfgsbComparer cmp = new LbfgsbComparer()
            {
                factr = 1.0e+7,
                l = null,
                u = null,
                pgtol = 1e-5,
                m = 10,
            };

            compute(problems, cmp);
        }
예제 #2
0
        public void InvalidLineSearchTest()
        {
            double t = 0;
            double s = 0;
            int n = 10;

            Func<double[], double> function = (parameters) =>
            {
                t = parameters[0];
                s = parameters[1];

                return -(n * Math.Log(s) - n * Math.Log(Math.PI));
            };

            Func<double[], double[]> gradient = (parameters) =>
            {
                t = parameters[0];
                s = parameters[1];

                double dt = -2.0;
                double ds = +2.0 - n / s;

                return new[] { dt, ds };
            };

            double[] start = { 0, 0 };


            Specification problem = new Specification(2, function, gradient, start);
            LbfgsbComparer cmp = new LbfgsbComparer();

            compute(new List<Specification>() { problem }, cmp);
        }
예제 #3
0
        public void DefaultBatchTest()
        {
            foreach (var problem in problems)
            {
                LbfgsbComparer cmp = new LbfgsbComparer();

                var expected = cmp.Expected(problem);
                var actual = cmp.Actual(problem);

                check(actual, expected);
            }
        }
예제 #4
0
        private static void compute(List<Specification> problems, LbfgsbComparer cmp)
        {
            foreach (var problem in problems)
            {
                string actualStr = String.Empty;
                string expectedStr = String.Empty;

                cmp.l = null;
                cmp.u = null;

                OptimizationProgressEventArgs[] actual = null;

                try { actual = cmp.Actual(problem); }
                catch (Exception ex)
                {
                    actualStr = ex.Data["Code"] as string;
                    if (actualStr == null)
                        throw;
                }

                var expected = cmp.Expected(problem);
                expectedStr = cmp.NativeCode;

                if (actualStr == String.Empty)
                    actualStr = cmp.ActualMessage;

                Assert.AreEqual(expectedStr, actualStr);


                check(actual, expected);
            }
        }