当前位置: 首页>>代码示例>>Java>>正文


Java NelderMead类代码示例

本文整理汇总了Java中org.apache.commons.math.optimization.direct.NelderMead的典型用法代码示例。如果您正苦于以下问题:Java NelderMead类的具体用法?Java NelderMead怎么用?Java NelderMead使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


NelderMead类属于org.apache.commons.math.optimization.direct包,在下文中一共展示了NelderMead类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testRosenbrock

import org.apache.commons.math.optimization.direct.NelderMead; //导入依赖的package包/类
@Test
public void testRosenbrock()
  throws FunctionEvaluationException, ConvergenceException {

  Rosenbrock rosenbrock = new Rosenbrock();
  NelderMead underlying = new NelderMead();
  underlying.setStartConfiguration(new double[][] {
                                       { -1.2,  1.0 }, { 0.9, 1.2 } , {  3.5, -2.3 }
                                   });
  JDKRandomGenerator g = new JDKRandomGenerator();
  g.setSeed(16069223052l);
  RandomVectorGenerator generator =
      new UncorrelatedRandomVectorGenerator(2, new GaussianRandomGenerator(g));
  MultiStartMultivariateRealOptimizer optimizer =
      new MultiStartMultivariateRealOptimizer(underlying, 10, generator);
  optimizer.setConvergenceChecker(new SimpleScalarValueChecker(-1, 1.0e-3));
  optimizer.setMaxIterations(100);
  RealPointValuePair optimum =
      optimizer.optimize(rosenbrock, GoalType.MINIMIZE, new double[] { -1.2, 1.0 });

  assertEquals(rosenbrock.getCount(), optimizer.getEvaluations());
  assertTrue(optimizer.getEvaluations() > 20);
  assertTrue(optimizer.getEvaluations() < 250);
  assertTrue(optimum.getValue() < 8.0e-4);

}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:27,代码来源:MultiStartMultivariateRealOptimizerTest.java

示例2: detect

import org.apache.commons.math.optimization.direct.NelderMead; //导入依赖的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


注:本文中的org.apache.commons.math.optimization.direct.NelderMead类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。