Example #1
0
        private ActionResult plot(IFunctionWithDerivative f, PlotViewModel model)
        {
            List <Tuple <Color, List <Vector <double> > > > points = new List <Tuple <Color, List <Vector <double> > > >();
            double minDeriv = model.MinDerivCompMaxMagn;
            var    result   = new DenseVector(f.DimensionsCount);
            {
                result[0] = model.InitialX;
                result[1] = model.InitialY;
                var ps = new List <Vector <double> >();
                points.Add(new Tuple <Color, List <Vector <double> > >(Color.Lime, ps));
                var sdImpl = new SteepestDescentBasicOptmizer(model.BasicStep, model.MaxIters);
                sdImpl.Optimize(result, f, model.MinDerivCompMaxMagn, (i, pFunc) => ps.Add(pFunc()), CancellationToken.None);
            }
            {
                result[0] = model.InitialX;
                result[1] = model.InitialY;
                var ps = new List <Vector <double> >();
                points.Add(new Tuple <Color, List <Vector <double> > >(Color.Red, ps));
                var sdImpl = new SteepestDescentBasicOptmizer(model.MomentumStep,
                                                              model.MomentumStart, model.MomentumEnd, model.MaxIters);
                sdImpl.Optimize(result, f, model.MinDerivCompMaxMagn, (i, pFunc) => ps.Add(pFunc()), CancellationToken.None);
            }
            {
                result[0] = model.InitialX;
                result[1] = model.InitialY;
                var ps = new List <Vector <double> >();
                points.Add(new Tuple <Color, List <Vector <double> > >(Color.Blue, ps));
                var sdImpl = new SteepestDescentAdvancedOptmizer(model.MomentumStep,
                                                                 model.MomentumStart, model.MomentumEnd, model.MaxIters);
                sdImpl.Optimize(result, f, model.MinDerivCompMaxMagn, (i, pFunc) => ps.Add(pFunc()), CancellationToken.None);
            }
            {
                result[0] = model.InitialX;
                result[1] = model.InitialY;
                var ps = new List <Vector <double> >();
                points.Add(new Tuple <Color, List <Vector <double> > >(Color.Magenta, ps));
                var sdImpl = new RpropPlusOptmizer(model.BasicStep, 10, 1.2, 0.5, model.MaxIters);
                sdImpl.Optimize(result, f, model.MinDerivCompMaxMagn, (i, pFunc) => ps.Add(pFunc()), CancellationToken.None);
            }
            {
                result[0] = model.InitialX;
                result[1] = model.InitialY;
                var ps = new List <Vector <double> >();
                points.Add(new Tuple <Color, List <Vector <double> > >(Color.Cyan, ps));
                var sdImpl = new ImprovedRpropMinusOptmizer(model.BasicStep, 10, 1.2, 0.5, model.MaxIters);
                sdImpl.Optimize(result, f, model.MinDerivCompMaxMagn, (i, pFunc) => ps.Add(pFunc()), CancellationToken.None);
            }

            var fp = new FunctionPlotter();

            var img = fp.AutoContourPlot(f, points, 0.1f, 0, 1, model.Width, model.Height,
                                         model.ContoursCount, model.ScalePower);
            var ms = new MemoryStream();

            img.Save(ms, ImageFormat.Png);
            ms.Seek(0, SeekOrigin.Begin);

            return(File(ms, "image/png"));
        }
Example #2
0
        public void OptimizeTest()
        {
            var instance = new RpropPlusOptmizer(0.05, 10, 1.2, 0.5, 256);

            OptimizerTestsHelper.PerformOptimizerTestOnSinCosCrazyFunction(instance);
        }