本文整理汇总了Java中org.apache.commons.math.analysis.MultivariateRealFunction类的典型用法代码示例。如果您正苦于以下问题:Java MultivariateRealFunction类的具体用法?Java MultivariateRealFunction怎么用?Java MultivariateRealFunction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MultivariateRealFunction类属于org.apache.commons.math.analysis包,在下文中一共展示了MultivariateRealFunction类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: wrap
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
/**
* @param f An OG n-D function mapping doubles onto doubles, not null
* @return A Commons multivariate real function
*/
public static MultivariateRealFunction wrap(final FunctionND<Double, Double> f) {
Validate.notNull(f);
return new MultivariateRealFunction() {
@Override
public double value(final double[] point) throws FunctionEvaluationException, IllegalArgumentException {
final int n = point.length;
final Double[] coordinate = new Double[n];
for (int i = 0; i < n; i++) {
coordinate[i] = point[i];
}
return f.evaluate(coordinate);
}
};
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:20,代码来源:CommonsMathWrapper.java
示例2: evaluate
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
/**
* Evaluate all the non-evaluated points of the simplex.
*
* @param evaluationFunction Evaluation function.
* @param comparator Comparator to use to sort simplex vertices from best to worst.
* @throws org.apache.commons.math.exception.TooManyEvaluationsException
* if the maximal number of evaluations is exceeded.
* @throws MathUserException if evaluation function throws one
*/
public void evaluate(final MultivariateRealFunction evaluationFunction,
final Comparator<RealPointValuePair> comparator)
throws MathUserException {
// 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, evaluationFunction.value(point), false);
}
}
// Sort the simplex from best to worst.
Arrays.sort(simplex, comparator);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:AbstractSimplex.java
示例3: testRosenbrock
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testRosenbrock() {
MultivariateRealFunction rosenbrock =
new MultivariateRealFunction() {
private static final long serialVersionUID = -9044950469615237490L;
public double value(double[] x) {
++count;
double a = x[1] - x[0] * x[0];
double b = 1.0 - x[0];
return 100 * a * a + b * b;
}
};
count = 0;
SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
optimizer.setSimplex(new MultiDirectionalSimplex(new double[][] {
{ -1.2, 1.0 }, { 0.9, 1.2 } , { 3.5, -2.3 }
}));
RealPointValuePair optimum =
optimizer.optimize(100, rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1 });
Assert.assertEquals(count, optimizer.getEvaluations());
Assert.assertTrue(optimizer.getEvaluations() > 50);
Assert.assertTrue(optimizer.getEvaluations() < 100);
Assert.assertTrue(optimum.getValue() > 1e-2);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:SimplexOptimizerMultiDirectionalTest.java
示例4: testPowell
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testPowell() {
MultivariateRealFunction powell =
new MultivariateRealFunction() {
private static final long serialVersionUID = -832162886102041840L;
public double value(double[] x) {
++count;
double a = x[0] + 10 * x[1];
double b = x[2] - x[3];
double c = x[1] - 2 * x[2];
double d = x[0] - x[3];
return a * a + 5 * b * b + c * c * c * c + 10 * d * d * d * d;
}
};
count = 0;
SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
optimizer.setSimplex(new MultiDirectionalSimplex(4));
RealPointValuePair optimum =
optimizer.optimize(1000, powell, GoalType.MINIMIZE, new double[] { 3, -1, 0, 1 });
Assert.assertEquals(count, optimizer.getEvaluations());
Assert.assertTrue(optimizer.getEvaluations() > 800);
Assert.assertTrue(optimizer.getEvaluations() < 900);
Assert.assertTrue(optimum.getValue() > 1e-2);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:SimplexOptimizerMultiDirectionalTest.java
示例5: testSumSinc
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testSumSinc() {
final MultivariateRealFunction func = new SumSincFunction(-1);
int dim = 2;
final double[] minPoint = new double[dim];
for (int i = 0; i < dim; i++) {
minPoint[i] = 0;
}
double[] init = new double[dim];
// Initial is minimum.
for (int i = 0; i < dim; i++) {
init[i] = minPoint[i];
}
doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-9, 1e-7);
// Initial is far from minimum.
for (int i = 0; i < dim; i++) {
init[i] = minPoint[i] + 3;
}
doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-9, 1e-7);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:PowellOptimizerTest.java
示例6: testCollector
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testCollector() {
BivariateRealFunction bi = new Add();
MultivariateRealFunction coll = FunctionUtils.collector(bi, 0);
Assert.assertEquals(10, coll.value(new double[] {1, 2, 3, 4}), EPS);
bi = new Multiply();
coll = FunctionUtils.collector(bi, 1);
Assert.assertEquals(24, coll.value(new double[] {1, 2, 3, 4}), EPS);
bi = new Max();
coll = FunctionUtils.collector(bi, Double.NEGATIVE_INFINITY);
Assert.assertEquals(10, coll.value(new double[] {1, -2, 7.5, 10, -24, 9.99}), 0);
bi = new Min();
coll = FunctionUtils.collector(bi, Double.POSITIVE_INFINITY);
Assert.assertEquals(-24, coll.value(new double[] {1, -2, 7.5, 10, -24, 9.99}), 0);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:19,代码来源:FunctionUtilsTest.java
示例7: testRosenbrock
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testRosenbrock() {
MultivariateRealFunction rosenbrock =
new MultivariateRealFunction() {
public double value(double[] x) {
++count;
double a = x[1] - x[0] * x[0];
double b = 1.0 - x[0];
return 100 * a * a + b * b;
}
};
count = 0;
SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
optimizer.setSimplex(new MultiDirectionalSimplex(new double[][] {
{ -1.2, 1.0 }, { 0.9, 1.2 } , { 3.5, -2.3 }
}));
RealPointValuePair optimum =
optimizer.optimize(100, rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1 });
Assert.assertEquals(count, optimizer.getEvaluations());
Assert.assertTrue(optimizer.getEvaluations() > 50);
Assert.assertTrue(optimizer.getEvaluations() < 100);
Assert.assertTrue(optimum.getValue() > 1e-2);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:26,代码来源:SimplexOptimizerMultiDirectionalTest.java
示例8: testPowell
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testPowell() {
MultivariateRealFunction powell =
new MultivariateRealFunction() {
public double value(double[] x) {
++count;
double a = x[0] + 10 * x[1];
double b = x[2] - x[3];
double c = x[1] - 2 * x[2];
double d = x[0] - x[3];
return a * a + 5 * b * b + c * c * c * c + 10 * d * d * d * d;
}
};
count = 0;
SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-3);
optimizer.setSimplex(new MultiDirectionalSimplex(4));
RealPointValuePair optimum =
optimizer.optimize(1000, powell, GoalType.MINIMIZE, new double[] { 3, -1, 0, 1 });
Assert.assertEquals(count, optimizer.getEvaluations());
Assert.assertTrue(optimizer.getEvaluations() > 800);
Assert.assertTrue(optimizer.getEvaluations() < 900);
Assert.assertTrue(optimum.getValue() > 1e-2);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:25,代码来源:SimplexOptimizerMultiDirectionalTest.java
示例9: wrapMultivariate
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
/**
* @param f An OG 1-D function mapping vectors of doubles onto doubles, not null
* @return A Commons multivariate real function
*/
public static MultivariateRealFunction wrapMultivariate(final Function1D<DoubleMatrix1D, Double> f) {
Validate.notNull(f);
return new MultivariateRealFunction() {
@Override
public double value(final double[] point) throws FunctionEvaluationException, IllegalArgumentException {
return f.evaluate(new DoubleMatrix1D(point));
}
};
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:16,代码来源:CommonsMathWrapper.java
示例10: testNDFunction
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testNDFunction() throws FunctionEvaluationException {
final Double[] x1 = new Double[4];
final double[] x2 = new double[4];
final MultivariateRealFunction commons = CommonsMathWrapper.wrap(OG_FUNCTION_ND);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 4; j++) {
x1[j] = (double) i;
x2[j] = x1[j];
}
assertEquals(OG_FUNCTION_ND.evaluate(x1), commons.value(x2), 1e-15);
}
}
开发者ID:DevStreet,项目名称:FinanceAnalytics,代码行数:14,代码来源:CommonsMathWrapperTest.java
示例11: detect
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Override
public double detect(final double[] vec) {
double[] t = {this.mean.detect(vec)};
MultivariateRealFunction func = new MultivariateRealFunction() {
@Override
public double value(double[] x) throws FunctionEvaluationException {
ObjectDoublePair<double[]> ind = indicator(vec,x[0]);
double sumd = MatlibMatrixUtils.sum(D);
double k = ind.second / sumd;
double b = k / (1-k);
double[][] y = new double[1][vec.length];
for (int i = 0; i < vec.length; i++) {
y[0][i] = ind.first[i] + 1 - b * (1 - ind.first[i]);
}
SparseMatrix dmw = MatlibMatrixUtils.minusInplace(D, W);
Vector yv = Vector.wrap(y[0]);
double nom = new DenseMatrix(y).mult(dmw.transposeMultiply(yv)).get(0); // y' * ( (D-W) * y)
double denom = new DenseMatrix(y).mult(D.transposeMultiply(yv)).get(0);
return nom/denom;
}
};
//
RealPointValuePair ret;
try {
NelderMead nelderMead = new NelderMead();
nelderMead.setConvergenceChecker(new SimpleRealPointChecker(0.0001, -1));
ret = nelderMead.optimize(func, GoalType.MINIMIZE, t);
return ret.getPoint()[0];
} catch (Exception e) {
e.printStackTrace();
System.err.println("Reverting to mean");
}
return t[0];
}
开发者ID:openimaj,项目名称:openimaj,代码行数:37,代码来源:SplitDetectionMode.java
示例12: interpolate
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public MultivariateRealFunction interpolate(final double[][] xval,
final double[] yval)
throws MathException, IllegalArgumentException {
final UnitSphereRandomVectorGenerator rand
= new UnitSphereRandomVectorGenerator(xval[0].length);
return new MicrosphereInterpolatingFunction(xval, yval,
brightnessExponent,
microsphereElements,
rand);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:14,代码来源:MicrosphereInterpolator.java
示例13: partialDerivative
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
public MultivariateRealFunction partialDerivative(final int k) {
return new MultivariateRealFunction() {
private static final long serialVersionUID = 3073956364104833888L;
public double value(double[] point) {
return gradient(point)[k];
}
};
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:9,代码来源:NonLinearConjugateGradientOptimizerTest.java
示例14: testRosenbrock
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testRosenbrock()
throws FunctionEvaluationException, ConvergenceException {
MultivariateRealFunction rosenbrock =
new MultivariateRealFunction() {
private static final long serialVersionUID = -9044950469615237490L;
public double value(double[] x) throws FunctionEvaluationException {
++count;
double a = x[1] - x[0] * x[0];
double b = 1.0 - x[0];
return 100 * a * a + b * b;
}
};
count = 0;
MultiDirectional optimizer = new MultiDirectional();
optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1, 1.0e-3));
optimizer.setMaxIterations(100);
optimizer.setStartConfiguration(new double[][] {
{ -1.2, 1.0 }, { 0.9, 1.2 } , { 3.5, -2.3 }
});
RealPointValuePair optimum =
optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 });
Assert.assertEquals(count, optimizer.getEvaluations());
Assert.assertTrue(optimizer.getEvaluations() > 50);
Assert.assertTrue(optimizer.getEvaluations() < 100);
Assert.assertTrue(optimum.getValue() > 1.0e-2);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:32,代码来源:MultiDirectionalTest.java
示例15: testPowell
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testPowell()
throws FunctionEvaluationException, ConvergenceException {
MultivariateRealFunction powell =
new MultivariateRealFunction() {
private static final long serialVersionUID = -832162886102041840L;
public double value(double[] x) throws FunctionEvaluationException {
++count;
double a = x[0] + 10 * x[1];
double b = x[2] - x[3];
double c = x[1] - 2 * x[2];
double d = x[0] - x[3];
return a * a + 5 * b * b + c * c * c * c + 10 * d * d * d * d;
}
};
count = 0;
MultiDirectional optimizer = new MultiDirectional();
optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1.0, 1.0e-3));
optimizer.setMaxIterations(1000);
RealPointValuePair optimum =
optimizer.optimize(powell, GoalType.MINIMIZE, new double[] { 3.0, -1.0, 0.0, 1.0 });
Assert.assertEquals(count, optimizer.getEvaluations());
Assert.assertTrue(optimizer.getEvaluations() > 800);
Assert.assertTrue(optimizer.getEvaluations() < 900);
Assert.assertTrue(optimum.getValue() > 1.0e-2);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:MultiDirectionalTest.java
示例16: partialDerivative
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
public MultivariateRealFunction partialDerivative(final int k) {
return new MultivariateRealFunction() {
public double value(double[] point) {
return gradient(point)[k];
}
};
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:MultiStartDifferentiableMultivariateRealOptimizerTest.java
示例17: iterate
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void iterate(final MultivariateRealFunction evaluationFunction,
final Comparator<RealPointValuePair> comparator)
throws MathUserException {
// Save the original simplex.
final RealPointValuePair[] original = getPoints();
final RealPointValuePair best = original[0];
// Perform a reflection step.
final RealPointValuePair reflected = evaluateNewSimplex(evaluationFunction,
original, 1, comparator);
if (comparator.compare(reflected, best) < 0) {
// Compute the expanded simplex.
final RealPointValuePair[] reflectedSimplex = getPoints();
final RealPointValuePair expanded = evaluateNewSimplex(evaluationFunction,
original, khi, comparator);
if (comparator.compare(reflected, expanded) <= 0) {
// Keep the reflected simplex.
setPoints(reflectedSimplex);
}
// Keep the expanded simplex.
return;
}
// Compute the contracted simplex.
evaluateNewSimplex(evaluationFunction, original, gamma, comparator);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:MultiDirectionalSimplex.java
示例18: partialDerivative
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
public MultivariateRealFunction partialDerivative(final int k) {
return new MultivariateRealFunction() {
private static final long serialVersionUID = -6186178619133562011L;
public double value(double[] point) {
return gradient(point)[k];
}
};
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:9,代码来源:NonLinearConjugateGradientOptimizerTest.java
示例19: testQuadratic
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
@Test
public void testQuadratic() {
final MultivariateRealFunction func = new MultivariateRealFunction() {
public double value(double[] x) {
final double a = x[0] - 1;
final double b = x[1] - 1;
return a * a + b * b + 1;
}
};
int dim = 2;
final double[] minPoint = new double[dim];
for (int i = 0; i < dim; i++) {
minPoint[i] = 1;
}
double[] init = new double[dim];
// Initial is minimum.
for (int i = 0; i < dim; i++) {
init[i] = minPoint[i];
}
doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-9, 1e-8);
// Initial is far from minimum.
for (int i = 0; i < dim; i++) {
init[i] = minPoint[i] - 20;
}
doTest(func, minPoint, init, GoalType.MINIMIZE, 1e-9, 1e-8);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:31,代码来源:PowellOptimizerTest.java
示例20: testPowell
import org.apache.commons.math.analysis.MultivariateRealFunction; //导入依赖的package包/类
public void testPowell()
throws FunctionEvaluationException, ConvergenceException {
MultivariateRealFunction powell =
new MultivariateRealFunction() {
private static final long serialVersionUID = -832162886102041840L;
public double value(double[] x) throws FunctionEvaluationException {
++count;
double a = x[0] + 10 * x[1];
double b = x[2] - x[3];
double c = x[1] - 2 * x[2];
double d = x[0] - x[3];
return a * a + 5 * b * b + c * c * c * c + 10 * d * d * d * d;
}
};
count = 0;
MultiDirectional optimizer = new MultiDirectional();
optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1.0, 1.0e-3));
optimizer.setMaxIterations(1000);
RealPointValuePair optimum =
optimizer.optimize(powell, GoalType.MINIMIZE, new double[] { 3.0, -1.0, 0.0, 1.0 });
assertEquals(count, optimizer.getEvaluations());
assertTrue(optimizer.getEvaluations() > 800);
assertTrue(optimizer.getEvaluations() < 900);
assertTrue(optimum.getValue() > 1.0e-2);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:29,代码来源:MultiDirectionalTest.java
注:本文中的org.apache.commons.math.analysis.MultivariateRealFunction类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论