Пример #1
0
 private MKT_Point[] GetStartPoints()
 {
     SetupCurrentPoint(startPoint, 0);
     var secondPoint = new MKT_Point(startPoint.x + initialLength, startPoint.y, fn);
     var thirdPoint = new MKT_Point(startPoint.x, startPoint.y + initialLength, fn);
     SetupCurrentPoint(secondPoint, 1);
     SetupCurrentPoint(thirdPoint, 2);
     return currentPoints;
 }
Пример #2
0
 public NelderMid(
     MKT_Point startPoint,
     Func<float, float, float> fn,
     SquarePoint[] bounds,
     MktIterationMode iterationMode)
 {
     this.startPoint = startPoint;
     this.fn = fn;
     _points = new List<MKT_Point>();
     this.bounds = bounds;
     currentPoints = new MKT_Point[3];
     maxPoints = iterationMode == MktIterationMode.Full ? 75 : 6;
 }
Пример #3
0
        private IList<MKT_Point> ShlpFromLambdaPoints(IList<MKT_Point> points, MKT_Point worstPoint)
        {
            var suitablePoints = new List<MKT_Point>();
            var watch2 = Stopwatch.StartNew();
            foreach (var mktPoint in points)
            {
                var shlpValue = Shlp(mktPoint);
                if (shlpValue != null &&  shlpValue.Value < worstPoint.Value)
                {
                    suitablePoints.Add(shlpValue);
                }
            }

            watch2.Stop();

            return suitablePoints;
        }
Пример #4
0
 private MKT_Point Shlp(MKT_Point point)
 {
     var result = shlpWrapper.GetShlpObject(point).Calculate();
     return result != null ? new MKT_Point(result.x, result.y, point) : null;
 }
Пример #5
0
        private SquarePoint Iteration()
        {
            do
            {
                var isComressionNeeded = false;
                currentPoints = currentPoints.OrderByDescending(x => x.Value).ToArray();
                var xh = currentPoints[hi];
                var xg = currentPoints[gi];
                var xl = currentPoints[li];

                if (float.IsInfinity(xl.Value))
                {
                    break;
                }

                var xc = new SquarePoint(
                    (xg.x + xl.x) / 2,
                    (xg.y + xl.y) / 2);
                var xr = new MKT_Point(
                    Xr(xc.x, xh.x),
                    Xr(xc.y, xh.y),
                    fn);

                if (xr.Value < xl.Value)
                {
                    var xe = new MKT_Point(
                        Xe(xc.x, xr.x),
                        Xe(xc.y, xr.y),
                        fn);
                    if (xe.Value <= xr.Value)
                    {
                        SetupCurrentPoint(xe, hi);
                    }
                    else
                    {
                        SetupCurrentPoint(xr, hi);
                    }
                }
                else if (xl.Value < xr.Value && xr.Value < xh.Value)
                {
                    SetupCurrentPoint(xr, hi);
                }
                else if (xg.Value < xr.Value && xr.Value < xh.Value)
                {
                    var buf_xr = xr;
                    xr = xh;
                    xh = buf_xr;
                    isComressionNeeded = true;
                }
                else
                {
                    isComressionNeeded = true;
                }

                if (isComressionNeeded)
                {
                    var xs = new MKT_Point(Xs(xh.x, xc.x), Xs(xh.y, xc.y), fn);
                    if (xs.Value < xh.Value)
                    {
                        SetupCurrentPoint(xs, hi);
                    }
                    else
                    {
                        var xi_xh = new MKT_Point(Xi(xh.x, xl.x), Xi(xh.y, xl.y), fn);
                        SetupCurrentPoint(xi_xh, hi);
                        var xi_xg = new MKT_Point(Xi(xg.x, xl.x), Xi(xg.y, xl.y), fn);
                        SetupCurrentPoint(xi_xg, hi);
                    }
                }

            } while (OneMoreIteration());

            var suitablePoints =
                _points.Where(x => x.x <= bounds[1].x && x.x >= bounds[0].x && x.y >= bounds[0].y && x.y <= bounds[1].y);
            return suitablePoints
                .FirstOrDefault(x => Math.Abs(x.Value - suitablePoints.Min(c => c.Value)) < 0.01);
        }
Пример #6
0
 private void SetupCurrentPoint(MKT_Point point, int index)
 {
     _points.Add(point);
     currentPoints[index] = point;
 }
Пример #7
0
 private float Length(MKT_Point p1, MKT_Point p2)
 {
     return (float)Math.Sqrt(Math.Pow(p1.x - p2.x, 2) + Math.Pow(p1.y - p2.y, 2));
 }
Пример #8
0
 public MKT_Point(float x, float y, MKT_Point shlpFrPoint)
     : this(x, y, shlpFrPoint._fn)
 {
     ShlpFrom = shlpFrPoint;
 }