Tabnine Logo
RealPointValuePair
Code IndexAdd Tabnine to your IDE (free)

How to use
RealPointValuePair
in
org.apache.commons.math.optimization

Best Java code snippets using org.apache.commons.math.optimization.RealPointValuePair (Showing top 20 results out of 315)

origin: org.apache.commons/math

/** {@inheritDoc} */
public boolean converged(final int iteration,
             final RealPointValuePair previous,
             final RealPointValuePair current) {
  final double[] p        = previous.getPoint();
  final double[] c        = current.getPoint();
  for (int i = 0; i < p.length; ++i) {
    final double difference = Math.abs(p[i] - c[i]);
    final double size       = Math.max(Math.abs(p[i]), Math.abs(c[i]));
    if ((difference > (size * relativeThreshold)) && (difference > absoluteThreshold)) {
      return false;
    }
  }
  return true;
}
origin: org.apache.commons/commons-math

/** Evaluate all the non-evaluated points of the simplex.
 * @param comparator comparator to use to sort simplex vertices from best to worst
 * @exception FunctionEvaluationException if no value can be computed for the parameters
 * @exception OptimizationException if the maximal number of evaluations is exceeded
 */
protected void evaluateSimplex(final Comparator<RealPointValuePair> comparator)
  throws FunctionEvaluationException, OptimizationException {
  // evaluate the objective function at all non-evaluated simplex points
  for (int i = 0; i < simplex.length; ++i) {
    final RealPointValuePair vertex = simplex[i];
    final double[] point = vertex.getPointRef();
    if (Double.isNaN(vertex.getValue())) {
      simplex[i] = new RealPointValuePair(point, evaluate(point), false);
    }
  }
  // sort the simplex from best to worst
  Arrays.sort(simplex, comparator);
}
origin: org.apache.commons/commons-math

/** Compute and evaluate a new simplex.
 * @param original original simplex (to be preserved)
 * @param coeff linear coefficient
 * @param comparator comparator to use to sort simplex vertices from best to poorest
 * @return best point in the transformed simplex
 * @exception FunctionEvaluationException if the function cannot be evaluated at some point
 * @exception OptimizationException if the maximal number of evaluations is exceeded
 */
private RealPointValuePair evaluateNewSimplex(final RealPointValuePair[] original,
                     final double coeff,
                     final Comparator<RealPointValuePair> comparator)
  throws FunctionEvaluationException, OptimizationException {
  final double[] xSmallest = original[0].getPointRef();
  final int n = xSmallest.length;
  // create the linearly transformed simplex
  simplex = new RealPointValuePair[n + 1];
  simplex[0] = original[0];
  for (int i = 1; i <= n; ++i) {
    final double[] xOriginal    = original[i].getPointRef();
    final double[] xTransformed = new double[n];
    for (int j = 0; j < n; ++j) {
      xTransformed[j] = xSmallest[j] + coeff * (xSmallest[j] - xOriginal[j]);
    }
    simplex[i] = new RealPointValuePair(xTransformed, Double.NaN, false);
  }
  // evaluate it
  evaluateSimplex(comparator);
  return simplex[0];
}
origin: org.apache.commons/commons-math

final RealPointValuePair secondBest = simplex[n-1];
final RealPointValuePair worst      = simplex[n];
final double[] xWorst = worst.getPointRef();
  final double[] x = simplex[i].getPointRef();
  for (int j = 0; j < n; ++j) {
    centroid[j] += x[j];
  xR[j] = centroid[j] + rho * (centroid[j] - xWorst[j]);
final RealPointValuePair reflected = new RealPointValuePair(xR, evaluate(xR), false);
    xE[j] = centroid[j] + khi * (xR[j] - centroid[j]);
  final RealPointValuePair expanded = new RealPointValuePair(xE, evaluate(xE), false);
    final RealPointValuePair outContracted = new RealPointValuePair(xC, evaluate(xC), false);
    final RealPointValuePair inContracted = new RealPointValuePair(xC, evaluate(xC), false);
  final double[] xSmallest = simplex[0].getPointRef();
  for (int i = 1; i < simplex.length; ++i) {
    final double[] x = simplex[i].getPoint();
    for (int j = 0; j < n; ++j) {
      x[j] = xSmallest[j] + sigma * (x[j] - xSmallest[j]);
    simplex[i] = new RealPointValuePair(x, Double.NaN, false);
origin: usethesource/rascal

  public IValue llOptimize(IBool minimize, IBool nonNegative, ISet constraints, IConstructor f) {
    SimplexSolver solver = new SimplexSolver();
    ArrayList<LinearConstraint> constraintsJ =
        new ArrayList<LinearConstraint>(constraints.size());
    for(IValue v : constraints ){
      constraintsJ.add(convertConstraint((IConstructor)v));
    }
    LinearObjectiveFunction fJ = convertLinObjFun(f);
    GoalType goal = minimize.getValue() ? 
            GoalType.MINIMIZE : GoalType.MAXIMIZE;
    IValueFactory vf = values;
    boolean nonNegativeJ =  nonNegative.getValue();
    try {
      RealPointValuePair res = 
          solver.optimize(fJ, constraintsJ, goal,nonNegativeJ);
      return vf.constructor(Maybe_just, 
          vf.constructor(
              LLSolution_llSolution, convertToRealList(res.getPoint(), vf), 
              vf.real(res.getValue()) )
          );
    } catch (Exception e) {
      return  vf.constructor(Maybe_nothing); 
    }

  }
}
origin: org.apache.commons/commons-math

  public int compare(final RealPointValuePair o1, final RealPointValuePair o2) {
    if (o1 == null) {
      return (o2 == null) ? 0 : +1;
    } else if (o2 == null) {
      return -1;
    }
    final double v1 = o1.getValue();
    final double v2 = o2.getValue();
    return (goalType == GoalType.MINIMIZE) ?
        Double.compare(v1, v2) : Double.compare(v2, v1);
  }
});
origin: org.apache.commons/commons-math

/** Build an initial simplex.
 * @param startPoint the start point for optimization
 * @exception IllegalArgumentException if the start point does not match
 * simplex dimension
 */
private void buildSimplex(final double[] startPoint)
  throws IllegalArgumentException {
  final int n = startPoint.length;
  if (n != startConfiguration.length) {
    throw MathRuntimeException.createIllegalArgumentException(
       LocalizedFormats.DIMENSIONS_MISMATCH_SIMPLE, n, startConfiguration.length);
  }
  // set first vertex
  simplex = new RealPointValuePair[n + 1];
  simplex[0] = new RealPointValuePair(startPoint, Double.NaN);
  // set remaining vertices
  for (int i = 0; i < n; ++i) {
    final double[] confI   = startConfiguration[i];
    final double[] vertexI = new double[n];
    for (int k = 0; k < n; ++k) {
      vertexI[k] = startPoint[k] + confI[k];
    }
    simplex[i + 1] = new RealPointValuePair(vertexI, Double.NaN);
  }
}
origin: org.apache.commons/math

final RealPointValuePair secondBest = simplex[n-1];
final RealPointValuePair worst      = simplex[n];
final double[] xWorst = worst.getPointRef();
  final double[] x = simplex[i].getPointRef();
  for (int j = 0; j < n; ++j) {
    centroid[j] += x[j];
  xR[j] = centroid[j] + rho * (centroid[j] - xWorst[j]);
final RealPointValuePair reflected = new RealPointValuePair(xR, evaluate(xR), false);
    xE[j] = centroid[j] + khi * (xR[j] - centroid[j]);
  final RealPointValuePair expanded = new RealPointValuePair(xE, evaluate(xE), false);
    final RealPointValuePair outContracted = new RealPointValuePair(xC, evaluate(xC), false);
    final RealPointValuePair inContracted = new RealPointValuePair(xC, evaluate(xC), false);
  final double[] xSmallest = simplex[0].getPointRef();
  for (int i = 1; i < simplex.length; ++i) {
    final double[] x = simplex[i].getPoint();
    for (int j = 0; j < n; ++j) {
      x[j] = xSmallest[j] + sigma * (x[j] - xSmallest[j]);
    simplex[i] = new RealPointValuePair(x, Double.NaN, false);
origin: org.apache.commons/math

  public int compare(final RealPointValuePair o1, final RealPointValuePair o2) {
    if (o1 == null) {
      return (o2 == null) ? 0 : +1;
    } else if (o2 == null) {
      return -1;
    }
    final double v1 = o1.getValue();
    final double v2 = o2.getValue();
    return (goalType == GoalType.MINIMIZE) ?
        Double.compare(v1, v2) : Double.compare(v2, v1);
  }
});
origin: org.apache.commons/math

/** Compute and evaluate a new simplex.
 * @param original original simplex (to be preserved)
 * @param coeff linear coefficient
 * @param comparator comparator to use to sort simplex vertices from best to poorest
 * @return best point in the transformed simplex
 * @exception FunctionEvaluationException if the function cannot be evaluated at
 * some point
 * @exception OptimizationException if the maximal number of evaluations is exceeded
 */
private RealPointValuePair evaluateNewSimplex(final RealPointValuePair[] original,
                     final double coeff,
                     final Comparator<RealPointValuePair> comparator)
  throws FunctionEvaluationException, OptimizationException {
  final double[] xSmallest = original[0].getPointRef();
  final int n = xSmallest.length;
  // create the linearly transformed simplex
  simplex = new RealPointValuePair[n + 1];
  simplex[0] = original[0];
  for (int i = 1; i <= n; ++i) {
    final double[] xOriginal    = original[i].getPointRef();
    final double[] xTransformed = new double[n];
    for (int j = 0; j < n; ++j) {
      xTransformed[j] = xSmallest[j] + coeff * (xSmallest[j] - xOriginal[j]);
    }
    simplex[i] = new RealPointValuePair(xTransformed, Double.NaN, false);
  }
  // evaluate it
  evaluateSimplex(comparator);
  return simplex[0];
}
origin: org.apache.commons/math

/** Build an initial simplex.
 * @param startPoint the start point for optimization
 * @exception IllegalArgumentException if the start point does not match
 * simplex dimension
 */
private void buildSimplex(final double[] startPoint)
  throws IllegalArgumentException {
  final int n = startPoint.length;
  if (n != startConfiguration.length) {
    throw MathRuntimeException.createIllegalArgumentException(
       DIMENSION_MISMATCH_MESSAGE, n, startConfiguration.length);
  }
  // set first vertex
  simplex = new RealPointValuePair[n + 1];
  simplex[0] = new RealPointValuePair(startPoint, Double.NaN);
  // set remaining vertices
  for (int i = 0; i < n; ++i) {
    final double[] confI   = startConfiguration[i];
    final double[] vertexI = new double[n];
    for (int k = 0; k < n; ++k) {
      vertexI[k] = startPoint[k] + confI[k];
    }
    simplex[i + 1] = new RealPointValuePair(vertexI, Double.NaN);
  }
}
origin: org.apache.commons/commons-math

/** {@inheritDoc} */
public boolean converged(final int iteration,
             final RealPointValuePair previous,
             final RealPointValuePair current) {
  final double[] p        = previous.getPoint();
  final double[] c        = current.getPoint();
  for (int i = 0; i < p.length; ++i) {
    final double difference = FastMath.abs(p[i] - c[i]);
    final double size       = FastMath.max(FastMath.abs(p[i]), FastMath.abs(c[i]));
    if ((difference > (size * relativeThreshold)) && (difference > absoluteThreshold)) {
      return false;
    }
  }
  return true;
}
origin: org.apache.commons/math

/** Evaluate all the non-evaluated points of the simplex.
 * @param comparator comparator to use to sort simplex vertices from best to worst
 * @exception FunctionEvaluationException if no value can be computed for the parameters
 * @exception OptimizationException if the maximal number of evaluations is exceeded
 */
protected void evaluateSimplex(final Comparator<RealPointValuePair> comparator)
  throws FunctionEvaluationException, OptimizationException {
  // evaluate the objective function at all non-evaluated simplex points
  for (int i = 0; i < simplex.length; ++i) {
    final RealPointValuePair vertex = simplex[i];
    final double[] point = vertex.getPointRef();
    if (Double.isNaN(vertex.getValue())) {
      simplex[i] = new RealPointValuePair(point, evaluate(point), false);
    }
  }
  // sort the simplex from best to worst
  Arrays.sort(simplex, comparator);
}
origin: org.apache.commons/commons-math

  public int compare(final RealPointValuePair o1,
            final RealPointValuePair o2) {
    final double v1 = o1.getValue();
    final double v2 = o2.getValue();
    return (goalType == GoalType.MINIMIZE) ?
        Double.compare(v1, v2) : Double.compare(v2, v1);
  }
};
origin: org.apache.commons/commons-math

return new RealPointValuePair(coefficients, f.getValue(coefficients));
origin: org.openimaj/sandbox

  nelderMead.setConvergenceChecker(new SimpleRealPointChecker(0.0001, -1));
  ret = nelderMead.optimize(func, GoalType.MINIMIZE, t);
  return ret.getPoint()[0];
} catch (Exception e) {
  e.printStackTrace();
origin: org.apache.commons/commons-math

  public int compare(final RealPointValuePair o1, final RealPointValuePair o2) {
    if (o1 == null) {
      return (o2 == null) ? 0 : +1;
    } else if (o2 == null) {
      return -1;
    }
    final double v1 = o1.getValue();
    final double v2 = o2.getValue();
    return (goalType == GoalType.MINIMIZE) ?
        Double.compare(v1, v2) : Double.compare(v2, v1);
  }
});
origin: org.apache.commons/math

return new RealPointValuePair(coefficients, f.getValue(coefficients));
origin: openimaj/openimaj

  nelderMead.setConvergenceChecker(new SimpleRealPointChecker(0.0001, -1));
  ret = nelderMead.optimize(func, GoalType.MINIMIZE, t);
  return ret.getPoint()[0];
} catch (Exception e) {
  e.printStackTrace();
origin: org.apache.commons/math

  public int compare(final RealPointValuePair o1,
            final RealPointValuePair o2) {
    final double v1 = o1.getValue();
    final double v2 = o2.getValue();
    return (goalType == GoalType.MINIMIZE) ?
        Double.compare(v1, v2) : Double.compare(v2, v1);
  }
};
org.apache.commons.math.optimizationRealPointValuePair

Javadoc

This class holds a point and the value of an objective function at this point.

This is a simple immutable container.

Most used methods

  • getPoint
    Get the point.
  • getValue
    Get the value of the objective function.
  • <init>
    Build a point/objective function value pair.
  • getPointRef
    Get a reference to the point.This method is provided as a convenience to avoid copying the array, th

Popular in Java

  • Start an intent from android
  • getApplicationContext (Context)
  • requestLocationUpdates (LocationManager)
  • compareTo (BigDecimal)
  • BorderLayout (java.awt)
    A border layout lays out a container, arranging and resizing its components to fit in five regions:
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • TreeMap (java.util)
    Walk the nodes of the tree left-to-right or right-to-left. Note that in descending iterations, next
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now