Example #1
0
        public void DefaultBatchTest()
        {
            foreach (var problem in problems)
            {
                LBFGSComparer cmp = new LBFGSComparer();

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

                Assert.AreEqual(expected.Length, actual.Length);
                for (int i = 0; i < expected.Length; i++)
                {
                    var a = actual[i];
                    var e = expected[i];

                    Assert.AreEqual(e.fx, a.Value);

                    for (int j = 0; j < e.g.Length; j++)
                    {
                        Assert.AreEqual(e.g[j], a.Gradient[j]);
                    }
                    Assert.AreEqual(e.gnorm, a.GradientNorm);
                    Assert.AreEqual(e.step, a.Step);
                }
            }
        }
Example #2
0
        private static void compute(List <Specification> problems, LBFGSComparer cmp)
        {
            foreach (var problem in problems)
            {
                string actualStr   = String.Empty;
                string expectedStr = String.Empty;

                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);

                if (expectedStr != "LBFGS_SUCCESS")
                {
                    continue;
                }

                Assert.AreEqual(expected.Length, actual.Length);
                for (int i = 0; i < expected.Length; i++)
                {
                    var a = actual[i];
                    var e = expected[i];

                    Assert.AreEqual(e.fx, a.Value);

                    for (int j = 0; j < e.g.Length; j++)
                    {
                        Assert.AreEqual(e.g[j], a.Gradient[j]);
                    }
                    Assert.AreEqual(e.gnorm, a.GradientNorm);
                    Assert.AreEqual(e.step, a.Step);
                }
            }
        }