示例#1
0
        /// @return boolean	true if a better point was found
        /// @exception DhbIllegalDimension if dimension of initial value is 0.
        private bool AddReflection(DhbVector centerOfgravity)
        {
            DhbVector reflectedVector = centerOfgravity * 2;

            reflectedVector.AccumulateNegated(
                _simplex[_result.Length].Position);
            OptimizingVector reflectedPoint =
                _pointFactory.CreateVector(reflectedVector, _f);

            if (reflectedPoint.BetterThan(_simplex[0]))
            {
                reflectedVector.ScaledBy(2);
                reflectedVector.AccumulateNegated(centerOfgravity);
                OptimizingVector expandedPoint =
                    _pointFactory.CreateVector(reflectedVector, _f);
                if (expandedPoint.BetterThan(reflectedPoint))
                {
                    AddBestPoint(expandedPoint);
                }
                else
                {
                    AddBestPoint(reflectedPoint);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#2
0
        /// @return DhbVector	center of gravity of best points of simplex,
        ///													except worst one
        private DhbVector CenterOfGravity()
        {
            DhbVector g = new DhbVector(_result.Length);

            for (int i = 0; i < _result.Length; i++)
            {
                g.Accumulate(_simplex[i].Position);
            }
            g.ScaledBy(1.0 / _result.Length);
            return(g);
        }
示例#3
0
        /// @return boolean	true if a better point was found
        /// @param g DhbVector	summit whose median is contracted
        /// @exception DhbIllegalDimension if dimension of initial value is 0.
        private bool AddContraction(DhbVector g)
        {
            g.Accumulate(_simplex[_result.Length].Position);
            g.ScaledBy(0.5);
            OptimizingVector contractedPoint = _pointFactory.CreateVector(g, _f);

            if (contractedPoint.BetterThan(_simplex[0]))
            {
                AddBestPoint(contractedPoint);
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#4
0
 private void AdjustLastDirection(DhbVector start)
 {
     try
     {
         int n = _projections.Length - 1;
         _projections[n].SetOrigin(_result);
         DhbVector newDirection = _projections[n].Origin - start;
         double    norm         = newDirection.Norm;
         if (norm > this.DesiredPrecision)
         {
             newDirection.ScaledBy(1 / norm);
             _projections[n].Direction          = newDirection;
             _unidimensionalFinder.Function     = _projections[n];
             _unidimensionalFinder.InitialValue = 0;
             _unidimensionalFinder.Evaluate();
             _result = _projections[n].ArgumentAt(
                 _unidimensionalFinder.Result).ToComponents();
         }
     }
     catch (DhbIllegalDimension) { };
 }