Class AbstractSimplex

    • Constructor Detail

      • AbstractSimplex

        protected AbstractSimplex​(int n)
        Build a unit hypercube simplex.
        Parameters:
        n - Dimension of the simplex.
      • AbstractSimplex

        protected AbstractSimplex​(int n,
                                  double sideLength)
        Build a hypercube simplex with the given side length.
        Parameters:
        n - Dimension of the simplex.
        sideLength - Length of the sides of the hypercube.
      • AbstractSimplex

        protected AbstractSimplex​(double[] steps)
        The start configuration for simplex is built from a box parallel to the canonical axes of the space. The simplex is the subset of vertices of a box parallel to the canonical axes. It is built as the path followed while traveling from one vertex of the box to the diagonally opposite vertex moving only along the box edges. The first vertex of the box will be located at the start point of the optimization. As an example, in dimension 3 a simplex has 4 vertices. Setting the steps to (1, 10, 2) and the start point to (1, 1, 1) would imply the start simplex would be: { (1, 1, 1), (2, 1, 1), (2, 11, 1), (2, 11, 3) }. The first vertex would be set to the start point at (1, 1, 1) and the last vertex would be set to the diagonally opposite vertex at (2, 11, 3).
        Parameters:
        steps - Steps along the canonical axes representing box edges. They may be negative but not zero.
        Throws:
        NullArgumentException - if steps is null.
        MathIllegalArgumentException - if one of the steps is zero.
      • AbstractSimplex

        protected AbstractSimplex​(double[][] referenceSimplex)
        The real initial simplex will be set up by moving the reference simplex such that its first point is located at the start point of the optimization.
        Parameters:
        referenceSimplex - Reference simplex.
        Throws:
        MathIllegalArgumentException - if the reference simplex does not contain at least one point.
        MathIllegalArgumentException - if there is a dimension mismatch in the reference simplex.
        IllegalArgumentException - if one of its vertices is duplicated.
    • Method Detail

      • getDimension

        public int getDimension()
        Get simplex dimension.
        Returns:
        the dimension of the simplex.
      • getSize

        public int getSize()
        Get simplex size. After calling the build method, this method will will be equivalent to getDimension() + 1.
        Returns:
        the size of the simplex.
      • iterate

        public abstract void iterate​(MultivariateFunction evaluationFunction,
                                     Comparator<PointValuePair> comparator)
        Compute the next simplex of the algorithm.
        Parameters:
        evaluationFunction - Evaluation function.
        comparator - Comparator to use to sort simplex vertices from best to worst.
        Throws:
        MathIllegalStateException - if the algorithm fails to converge.
      • build

        public void build​(double[] startPoint)
        Build an initial simplex.
        Parameters:
        startPoint - First point of the simplex.
        Throws:
        MathIllegalArgumentException - if the start point does not match simplex dimension.
      • evaluate

        public void evaluate​(MultivariateFunction evaluationFunction,
                             Comparator<PointValuePair> comparator)
        Evaluate all the non-evaluated points of the simplex.
        Parameters:
        evaluationFunction - Evaluation function.
        comparator - Comparator to use to sort simplex vertices from best to worst.
        Throws:
        MathIllegalStateException - if the maximal number of evaluations is exceeded.
      • replaceWorstPoint

        protected void replaceWorstPoint​(PointValuePair pointValuePair,
                                         Comparator<PointValuePair> comparator)
        Replace the worst point of the simplex by a new point.
        Parameters:
        pointValuePair - Point to insert.
        comparator - Comparator to use for sorting the simplex vertices from best to worst.
      • getPoints

        public PointValuePair[] getPoints()
        Get the points of the simplex.
        Returns:
        all the simplex points.
      • getPoint

        public PointValuePair getPoint​(int index)
        Get the simplex point stored at the requested index.
        Parameters:
        index - Location.
        Returns:
        the point at location index.
      • setPoint

        protected void setPoint​(int index,
                                PointValuePair point)
        Store a new point at location index. Note that no deep-copy of point is performed.
        Parameters:
        index - Location.
        point - New value.
      • setPoints

        protected void setPoints​(PointValuePair[] points)
        Replace all points. Note that no deep-copy of points is performed.
        Parameters:
        points - New Points.