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


Java MultivariateVectorFunction类代码示例

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


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

示例1: getModelFunction

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
/**
 * @return the model function values.
 */
public ModelFunction getModelFunction() {
    return new ModelFunction(new MultivariateVectorFunction() {
            /** {@inheritDoc} */
            public double[] value(double[] point) {
                // compute the residuals
                final double[] values = new double[observations.size()];
                int i = 0;
                for (WeightedObservedPoint observed : observations) {
                    values[i++] = f.value(observed.getX(), point);
                }

                return values;
            }
        });
}
 
开发者ID:biocompibens,项目名称:SME,代码行数:19,代码来源:CurveFitter.java

示例2: getNumericJacobianFunction

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
public MultivariateMatrixFunction getNumericJacobianFunction(final double[] xgrid, final double[] ygrid) {
    final MultivariateVectorFunction valueFunction = getValueFunction(xgrid, ygrid);
    return new MultivariateMatrixFunction() {
        static final double step = 0.01;

        @Override
        public double[][] value(double[] point) throws IllegalArgumentException {
            double[][] retVal = new double[xgrid.length][point.length];

            for(int i = 0; i < point.length; i++) {
                double[] newPoint = point.clone();
                newPoint[i] = newPoint[i] + step;
                double[] f1 = valueFunction.value(newPoint);
                double[] f2 = valueFunction.value(point);
                for(int j = 0; j < f1.length; j++) {
                    retVal[j][i] = (f1[j] - f2[j]) / step;
                }
            }
            return retVal;
        }
    };
}
 
开发者ID:zitmen,项目名称:thunderstorm,代码行数:23,代码来源:PSFModel.java

示例3: getLikelihoodFunction

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
public MultivariateFunction getLikelihoodFunction(final double[] xgrid, final double[] ygrid, final double[] imageValues) {
        final MultivariateVectorFunction valueFunction = this.getValueFunction(xgrid, ygrid);
        return new MultivariateFunction() {
            @Override
            public double value(double[] point) {

                double[] expectedValues = valueFunction.value(point);
                double logLikelihood = 0;
                for(int i = 0; i < expectedValues.length; i++) {
                    double expectedValue = expectedValues[i];
                    double log = log(expectedValue);
                    if(log < -1e6) {
                        log = -1e6;
                    }
                    logLikelihood += imageValues[i] * log - expectedValue;
                }
//        IJ.log("likelihood:" + logLikelihood);
//        IJ.log("point: " + Arrays.toString(point));
                return logLikelihood;
            }
        };
    }
 
开发者ID:zitmen,项目名称:thunderstorm,代码行数:23,代码来源:PSFModel.java

示例4: getNumericJacobianFunction

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
private MultivariateMatrixFunction getNumericJacobianFunction(final double[] xgrid1, final double[] ygrid1, final double[] xgrid2, final double[] ygrid2) {
    final MultivariateVectorFunction valueFunction = getValueFunction(xgrid1, ygrid1, xgrid2, ygrid2);
    return new MultivariateMatrixFunction() {
        static final double step = 0.01;

        @Override
        public double[][] value(double[] point) throws IllegalArgumentException {
            double[][] retVal = new double[xgrid1.length + xgrid2.length][point.length];

            for(int i = 0; i < point.length; i++) {
                double[] newPoint = point.clone();
                newPoint[i] = newPoint[i] + step;
                double[] f1 = valueFunction.value(newPoint);
                double[] f2 = valueFunction.value(point);
                for(int j = 0; j < f1.length; j++) {
                    retVal[j][i] = (f1[j] - f2[j]) / step;
                }
            }
            return retVal;
        }
    };
}
 
开发者ID:zitmen,项目名称:thunderstorm,代码行数:23,代码来源:BiplaneEllipticGaussianPSF.java

示例5: getLikelihoodFunction

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
public MultivariateFunction getLikelihoodFunction(double[] xgrid1, double[] ygrid1, final double[] values1, double[] xgrid2, double[] ygrid2, final double[] values2) {
    final MultivariateVectorFunction valueFunction = getValueFunction(xgrid1, ygrid1, xgrid2, ygrid2);
    return new MultivariateFunction() {
        @Override
        public double value(double[] point) {
            double[] expectedValues = valueFunction.value(point);
            double logLikelihood = 0;
            int index = 0;
            for(int i = 0; i < values1.length; i++, index++) {
                logLikelihood += values1[i] * Math.max(-1e6, log(expectedValues[index])) - expectedValues[index];
            }
            for(int i = 0; i < values2.length; i++, index++) {
                logLikelihood += values2[i] * Math.max(-1e6, log(expectedValues[index])) - expectedValues[index];
            }
            return logLikelihood;
        }
    };
}
 
开发者ID:zitmen,项目名称:thunderstorm,代码行数:19,代码来源:BiplaneEllipticGaussianPSF.java

示例6: getValueFunction

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
/**
 * Value function overriden for speed. When calculating for the whole
 * subimage, some values can be reused. But can only be used for a square
 * grid where xgrid values are same in each column and ygrid values are the
 * same in each row.
 *
 * @param xgrid
 * @param ygrid
 * @return
 */
@Override
public MultivariateVectorFunction getValueFunction(final double[] xgrid, final double[] ygrid) {
    return new MultivariateVectorFunction() {
        @Override
        public double[] value(double[] point) throws IllegalArgumentException {
            fixParams(point);
            //
            double[] retVal = new double[xgrid.length];
            Arrays.fill(retVal, 0.0);
            for(int i = 0; i < nmol; i++) {
                double [] tmp = Arrays.copyOfRange(point, i*Params.PARAMS_LENGTH, (i+1)*Params.PARAMS_LENGTH);
                double [] values = psf.getValueFunction(xgrid, ygrid).value(tmp);
                for(int j = 0; j < values.length; j++) {
                    retVal[j] += values[j];
                }
            }
            return retVal;
        }
    };
}
 
开发者ID:zitmen,项目名称:thunderstorm,代码行数:31,代码来源:MultiPSF.java

示例7: testLeastSquares1

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
@Test
public void testLeastSquares1() {

    final RealMatrix factors =
        new Array2DRowRealMatrix(new double[][] {
                { 1, 0 },
                { 0, 1 }
            }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                return factors.operate(variables);
            }
        }, new double[] { 2.0, -3.0 });
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
    optimizer.setSimplex(new NelderMeadSimplex(2));
    PointValuePair optimum =
        optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
    Assert.assertEquals( 2, optimum.getPointRef()[0], 3e-5);
    Assert.assertEquals(-3, optimum.getPointRef()[1], 4e-4);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 80);
    Assert.assertTrue(optimum.getValue() < 1.0e-6);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:SimplexOptimizerNelderMeadTest.java

示例8: testLeastSquares2

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
@Test
public void testLeastSquares2() {

    final RealMatrix factors =
        new Array2DRowRealMatrix(new double[][] {
                { 1, 0 },
                { 0, 1 }
            }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                return factors.operate(variables);
            }
        }, new double[] { 2, -3 }, new double[] { 10, 0.1 });
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
    optimizer.setSimplex(new NelderMeadSimplex(2));
    PointValuePair optimum =
        optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
    Assert.assertEquals( 2, optimum.getPointRef()[0], 5e-5);
    Assert.assertEquals(-3, optimum.getPointRef()[1], 8e-4);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 80);
    Assert.assertTrue(optimum.getValue() < 1e-6);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:24,代码来源:SimplexOptimizerNelderMeadTest.java

示例9: testLeastSquares3

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
@Test
public void testLeastSquares3() {

    final RealMatrix factors =
        new Array2DRowRealMatrix(new double[][] {
                { 1, 0 },
                { 0, 1 }
            }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                return factors.operate(variables);
            }
        }, new double[] { 2, -3 }, new Array2DRowRealMatrix(new double [][] {
                { 1, 1.2 }, { 1.2, 2 }
            }));
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
    optimizer.setSimplex(new NelderMeadSimplex(2));
    PointValuePair optimum =
        optimizer.optimize(200, ls, GoalType.MINIMIZE, new double[] { 10, 10 });
    Assert.assertEquals( 2, optimum.getPointRef()[0], 2e-3);
    Assert.assertEquals(-3, optimum.getPointRef()[1], 8e-4);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 80);
    Assert.assertTrue(optimum.getValue() < 1e-6);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:SimplexOptimizerNelderMeadTest.java

示例10: testNoOptimum

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
/**
 * Test demonstrating that the user exception is finally thrown if none
 * of the runs succeed.
 */
@Test(expected=TestException.class)
public void testNoOptimum() {
    JacobianMultivariateVectorOptimizer underlyingOptimizer
        = new GaussNewtonOptimizer(true, new SimpleVectorValueChecker(1e-6, 1e-6));
    JDKRandomGenerator g = new JDKRandomGenerator();
    g.setSeed(12373523445l);
    RandomVectorGenerator generator
        = new UncorrelatedRandomVectorGenerator(1, new GaussianRandomGenerator(g));
    MultiStartMultivariateVectorOptimizer optimizer
        = new MultiStartMultivariateVectorOptimizer(underlyingOptimizer, 10, generator);
    optimizer.optimize(new MaxEval(100),
                       new Target(new double[] { 0 }),
                       new Weight(new double[] { 1 }),
                       new InitialGuess(new double[] { 0 }),
                       new ModelFunction(new MultivariateVectorFunction() {
                               public double[] value(double[] point) {
                                   throw new TestException();
                               }
                           }));
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:25,代码来源:MultiStartMultivariateVectorOptimizerTest.java

示例11: getObjectiveFunctionGradient

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
public ObjectiveFunctionGradient getObjectiveFunctionGradient() {
    return new ObjectiveFunctionGradient(new MultivariateVectorFunction() {
            public double[] value(double[] params) {
                Vector2D center = new Vector2D(params[0], params[1]);
                double radius = getRadius(center);
                // gradient of the sum of squared residuals
                double dJdX = 0;
                double dJdY = 0;
                for (Vector2D pk : points) {
                    double dk = pk.distance(center);
                    dJdX += (center.getX() - pk.getX()) * (dk - radius) / dk;
                    dJdY += (center.getY() - pk.getY()) * (dk - radius) / dk;
                }
                dJdX *= 2;
                dJdY *= 2;

                return new double[] { dJdX, dJdY };
            }
        });
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:21,代码来源:CircleScalar.java

示例12: testLeastSquares1

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
@Test
public void testLeastSquares1() {
    final RealMatrix factors
        = new Array2DRowRealMatrix(new double[][] {
                { 1, 0 },
                { 0, 1 }
            }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                return factors.operate(variables);
            }
        }, new double[] { 2.0, -3.0 });
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
    PointValuePair optimum =
        optimizer.optimize(new MaxEval(200),
                           new ObjectiveFunction(ls),
                           GoalType.MINIMIZE,
                           new InitialGuess(new double[] { 10, 10 }),
                           new NelderMeadSimplex(2));
    Assert.assertEquals( 2, optimum.getPointRef()[0], 3e-5);
    Assert.assertEquals(-3, optimum.getPointRef()[1], 4e-4);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 80);
    Assert.assertTrue(optimum.getValue() < 1.0e-6);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:SimplexOptimizerNelderMeadTest.java

示例13: testLeastSquares2

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
@Test
public void testLeastSquares2() {
    final RealMatrix factors
        = new Array2DRowRealMatrix(new double[][] {
                { 1, 0 },
                { 0, 1 }
            }, false);
    LeastSquaresConverter ls = new LeastSquaresConverter(new MultivariateVectorFunction() {
            public double[] value(double[] variables) {
                return factors.operate(variables);
            }
        }, new double[] { 2, -3 }, new double[] { 10, 0.1 });
    SimplexOptimizer optimizer = new SimplexOptimizer(-1, 1e-6);
    PointValuePair optimum =
        optimizer.optimize(new MaxEval(200),
                           new ObjectiveFunction(ls),
                           GoalType.MINIMIZE,
                           new InitialGuess(new double[] { 10, 10 }),
                           new NelderMeadSimplex(2));
    Assert.assertEquals( 2, optimum.getPointRef()[0], 5e-5);
    Assert.assertEquals(-3, optimum.getPointRef()[1], 8e-4);
    Assert.assertTrue(optimizer.getEvaluations() > 60);
    Assert.assertTrue(optimizer.getEvaluations() < 80);
    Assert.assertTrue(optimum.getValue() < 1e-6);
}
 
开发者ID:Quanticol,项目名称:CARMA,代码行数:26,代码来源:SimplexOptimizerNelderMeadTest.java

示例14: refine

import org.apache.commons.math3.analysis.MultivariateVectorFunction; //导入依赖的package包/类
/**
 * Perform Levenburg-Marquardt non-linear optimisation to get better
 * estimates of the parameters
 */
private void refine()
{
	final LevenbergMarquardtOptimizer lm = new LevenbergMarquardtOptimizer();
	final RealVector start = buildInitialVector();
	final RealVector observed = buildObservedVector();
	final int maxEvaluations = 1000;
	final int maxIterations = 1000;

	final MultivariateVectorFunction value = new Value();
	final MultivariateMatrixFunction jacobian = new Jacobian();
	final MultivariateJacobianFunction model = LeastSquaresFactory.model(value, jacobian);

	final Optimum result = lm.optimize(LeastSquaresFactory.create(model,
			observed, start, null, maxEvaluations, maxIterations));

	updateEstimates(result.getPoint());
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:22,代码来源:CameraCalibrationZhang.java


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