本文整理汇总了Java中org.apache.commons.math3.linear.DiagonalMatrix类的典型用法代码示例。如果您正苦于以下问题:Java DiagonalMatrix类的具体用法?Java DiagonalMatrix怎么用?Java DiagonalMatrix使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DiagonalMatrix类属于org.apache.commons.math3.linear包,在下文中一共展示了DiagonalMatrix类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getProblem
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
protected LeastSquaresProblem getProblem(Collection<WeightedObservedPoint> points) {
final int len = points.size();
final double[] target = new double[len];
final double[] weights = new double[len];
final double[] initialGuess = { 1.0, 1.0 };
int i = 0;
for(WeightedObservedPoint point : points) {
target[i] = point.getY();
weights[i] = point.getWeight();
i += 1;
}
AbstractCurveFitter.TheoreticalValuesFunction model = new AbstractCurveFitter.TheoreticalValuesFunction(func, points);
return new LeastSquaresBuilder().
maxEvaluations(Integer.MAX_VALUE).
maxIterations(Integer.MAX_VALUE).
start(initialGuess).
target(target).
weight(new DiagonalMatrix(weights)).
model(model.getModelFunction(), model.getModelFunctionJacobian()).
build();
}
示例2: testInconsistentSizes1
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testInconsistentSizes1() {
try {
LinearProblem problem
= new LinearProblem(new double[][]{{1, 0},
{0, 1}},
new double[]{-1, 1});
//TODO why is this part here? hasn't it been tested already?
Optimum optimum = optimizer.optimize(problem.getBuilder().build());
Assert.assertEquals(0, optimum.getRMS(), TOl);
assertEquals(TOl, optimum.getPoint(), -1, 1);
//TODO move to builder test
optimizer.optimize(
problem.getBuilder().weight(new DiagonalMatrix(new double[]{1})).build());
fail(optimizer);
} catch (DimensionMismatchException e) {
//expected
}
}
示例3: testInconsistentSizes2
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testInconsistentSizes2() {
try {
LinearProblem problem
= new LinearProblem(new double[][]{{1, 0}, {0, 1}},
new double[]{-1, 1});
Optimum optimum = optimizer.optimize(problem.getBuilder().build());
Assert.assertEquals(0, optimum.getRMS(), TOl);
assertEquals(TOl, optimum.getPoint(), -1, 1);
//TODO move to builder test
optimizer.optimize(
problem.getBuilder()
.target(new double[]{1})
.weight(new DiagonalMatrix(new double[]{1}))
.build()
);
fail(optimizer);
} catch (DimensionMismatchException e) {
//expected
}
}
示例4: testCircleFittingBadInit
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testCircleFittingBadInit() {
CircleVectorial circle = new CircleVectorial();
double[][] points = circlePoints;
double[] weights = new double[points.length];
final double[] start = {-12, -12};
Arrays.fill(weights, 2);
for (int i = 0; i < points.length; ++i) {
circle.addPoint(points[i][0], points[i][1]);
}
Optimum optimum = optimizer.optimize(builder(circle).weight(new DiagonalMatrix(weights)).start(start).build());
Vector2D center = new Vector2D(optimum.getPoint().getEntry(0), optimum.getPoint().getEntry(1));
Assert.assertTrue(optimum.getEvaluations() < 25);
Assert.assertEquals(0.043, optimum.getRMS(), 1e-3);
Assert.assertEquals(0.292235, circle.getRadius(center), 1e-6);
Assert.assertEquals(-0.151738, center.getX(), 1e-6);
Assert.assertEquals(0.2075001, center.getY(), 1e-6);
}
示例5: testCircleFittingGoodInit
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testCircleFittingGoodInit() {
CircleVectorial circle = new CircleVectorial();
double[][] points = circlePoints;
double[] weights = new double[points.length];
Arrays.fill(weights, 2);
for (int i = 0; i < points.length; ++i) {
circle.addPoint(points[i][0], points[i][1]);
}
final double[] start = {0, 0};
Optimum optimum = optimizer.optimize(
builder(circle).weight(new DiagonalMatrix(weights)).start(start).build());
assertEquals(1e-6, optimum.getPoint(), -0.1517383071957963, 0.2074999736353867);
Assert.assertEquals(0.04268731682389561, optimum.getRMS(), 1e-8);
}
示例6: assertSVDValues
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
private void assertSVDValues(final File outputFileV, final File outputFileS, final File outputFileU) {
try {
final ReadCountCollection rcc = ReadCountCollectionUtils.parse(CONTROL_PCOV_FULL_FILE);
final SVD svd = SVDFactory.createSVD(rcc.counts());
final RealMatrix sDiag = new DiagonalMatrix(svd.getSingularValues());
assertOutputFileValues(outputFileU, svd.getU());
assertOutputFileValues(outputFileS, sDiag);
assertOutputFileValues(outputFileV, svd.getV());
assertUnitaryMatrix(svd.getV());
assertUnitaryMatrix(svd.getU());
Assert.assertTrue(MatrixUtils.isSymmetric(sDiag, 1e-32));
} catch (final IOException ioe) {
Assert.fail("Could not open test file: " + CONTROL_PCOV_FULL_FILE, ioe);
}
}
示例7: testComputeCost
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testComputeCost() throws IOException {
final StatisticalReferenceDataset dataset
= StatisticalReferenceDatasetFactory.createKirby2();
final double[] a = dataset.getParameters();
final double[] y = dataset.getData()[1];
final double[] w = new double[y.length];
Arrays.fill(w, 1d);
StatisticalReferenceDataset.LeastSquaresProblem problem
= dataset.getLeastSquaresProblem();
final LevenbergMarquardtOptimizer optim = LevenbergMarquardtOptimizer.create()
.withModelAndJacobian(problem.getModelFunction(),
problem.getModelFunctionJacobian())
.withTarget(y)
.withWeight(new DiagonalMatrix(w))
.withStartPoint(a);
final double expected = dataset.getResidualSumOfSquares();
final double cost = optim.computeCost(optim.computeResiduals(optim.getModel().value(optim.getStart())));
final double actual = cost * cost;
Assert.assertEquals(dataset.getName(), expected, actual, 1e-11 * expected);
}
示例8: testComputeRMS
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testComputeRMS() throws IOException {
final StatisticalReferenceDataset dataset
= StatisticalReferenceDatasetFactory.createKirby2();
final double[] a = dataset.getParameters();
final double[] y = dataset.getData()[1];
final double[] w = new double[y.length];
Arrays.fill(w, 1d);
StatisticalReferenceDataset.LeastSquaresProblem problem
= dataset.getLeastSquaresProblem();
final LevenbergMarquardtOptimizer optim = LevenbergMarquardtOptimizer.create()
.withModelAndJacobian(problem.getModelFunction(),
problem.getModelFunctionJacobian())
.withTarget(y)
.withWeight(new DiagonalMatrix(w))
.withStartPoint(a);
final double expected = FastMath.sqrt(dataset.getResidualSumOfSquares() /
dataset.getNumObservations());
final double actual = optim.computeRMS(optim.getStart());
Assert.assertEquals(dataset.getName(), expected, actual, 1e-11 * expected);
}
示例9: testTrivial
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testTrivial() {
LinearProblem problem
= new LinearProblem(new double[][] { { 2 } },
new double[] { 3 });
T optimizer = createOptimizer()
.withMaxEvaluations(100)
.withMaxIterations(getMaxIterations())
.withModelAndJacobian(problem.getModelFunction(),
problem.getModelFunctionJacobian())
.withTarget(problem.getTarget())
.withWeight(new DiagonalMatrix(new double[] { 1 }))
.withStartPoint(new double[] { 0 });
PointVectorValuePair optimum = optimizer.optimize();
Assert.assertEquals(0, optimizer.computeRMS(optimum.getPoint()), 1e-10);
Assert.assertEquals(1.5, optimum.getPoint()[0], 1e-10);
Assert.assertEquals(3.0, optimum.getValue()[0], 1e-10);
}
示例10: testQRColumnsPermutation
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testQRColumnsPermutation() {
LinearProblem problem
= new LinearProblem(new double[][] { { 1, -1 }, { 0, 2 }, { 1, -2 } },
new double[] { 4, 6, 1 });
T optimizer = createOptimizer()
.withMaxEvaluations(100)
.withMaxIterations(getMaxIterations())
.withModelAndJacobian(problem.getModelFunction(),
problem.getModelFunctionJacobian())
.withTarget(problem.getTarget())
.withWeight(new DiagonalMatrix(new double[] { 1, 1, 1 }))
.withStartPoint(new double[] { 0, 0 });
PointVectorValuePair optimum = optimizer.optimize();
Assert.assertEquals(0, optimizer.computeRMS(optimum.getPoint()), 1e-10);
Assert.assertEquals(7, optimum.getPoint()[0], 1e-10);
Assert.assertEquals(3, optimum.getPoint()[1], 1e-10);
Assert.assertEquals(4, optimum.getValue()[0], 1e-10);
Assert.assertEquals(6, optimum.getValue()[1], 1e-10);
Assert.assertEquals(1, optimum.getValue()[2], 1e-10);
}
示例11: testNoDependency
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testNoDependency() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 2, 0, 0, 0, 0, 0 },
{ 0, 2, 0, 0, 0, 0 },
{ 0, 0, 2, 0, 0, 0 },
{ 0, 0, 0, 2, 0, 0 },
{ 0, 0, 0, 0, 2, 0 },
{ 0, 0, 0, 0, 0, 2 }
}, new double[] { 0, 1.1, 2.2, 3.3, 4.4, 5.5 });
T optimizer = createOptimizer()
.withMaxEvaluations(100)
.withMaxIterations(getMaxIterations())
.withModelAndJacobian(problem.getModelFunction(),
problem.getModelFunctionJacobian())
.withTarget(problem.getTarget())
.withWeight(new DiagonalMatrix(new double[] { 1, 1, 1, 1, 1, 1 }))
.withStartPoint(new double[] { 0, 0, 0, 0, 0, 0 });
double[] optimum = optimizer.optimize().getPoint();
Assert.assertEquals(0, optimizer.computeRMS(optimum), 1e-10);
for (int i = 0; i < problem.target.length; ++i) {
Assert.assertEquals(0.55 * i, optimum[i], 1e-10);
}
}
示例12: testOneSet
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testOneSet() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 1, 0, 0 },
{ -1, 1, 0 },
{ 0, -1, 1 }
}, new double[] { 1, 1, 1});
T optimizer = createOptimizer()
.withMaxEvaluations(100)
.withMaxIterations(getMaxIterations())
.withModelAndJacobian(problem.getModelFunction(),
problem.getModelFunctionJacobian())
.withTarget(problem.getTarget())
.withWeight(new DiagonalMatrix(new double[] { 1, 1, 1 }))
.withStartPoint(new double[] { 0, 0, 0 });
double[] optimum = optimizer.optimize().getPoint();
Assert.assertEquals(0, optimizer.computeRMS(optimum), 1e-10);
Assert.assertEquals(1, optimum[0], 1e-10);
Assert.assertEquals(2, optimum[1], 1e-10);
Assert.assertEquals(3, optimum[2], 1e-10);
}
示例13: testNonInvertible
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test(expected=ConvergenceException.class)
public void testNonInvertible() throws Exception {
LinearProblem problem = new LinearProblem(new double[][] {
{ 1, 2, -3 },
{ 2, 1, 3 },
{ -3, 0, -9 }
}, new double[] { 1, 1, 1 });
T optimizer = createOptimizer()
.withMaxEvaluations(100)
.withMaxIterations(getMaxIterations())
.withModelAndJacobian(problem.getModelFunction(),
problem.getModelFunctionJacobian())
.withTarget(problem.getTarget())
.withWeight(new DiagonalMatrix(new double[] { 1, 1, 1 }))
.withStartPoint(new double[] { 0, 0, 0 });
optimizer.optimize();
}
示例14: testMoreEstimatedParametersSimple
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testMoreEstimatedParametersSimple() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 3, 2, 0, 0 },
{ 0, 1, -1, 1 },
{ 2, 0, 1, 0 }
}, new double[] { 7, 3, 5 });
T optimizer = createOptimizer()
.withMaxEvaluations(100)
.withMaxIterations(getMaxIterations())
.withModelAndJacobian(problem.getModelFunction(),
problem.getModelFunctionJacobian())
.withTarget(problem.getTarget())
.withWeight(new DiagonalMatrix(new double[] { 1, 1, 1 }))
.withStartPoint(new double[] { 7, 6, 5, 4 });
double[] optimum = optimizer.optimize().getPoint();
Assert.assertEquals(0, optimizer.computeRMS(optimum), 1e-10);
}
示例15: testRedundantEquations
import org.apache.commons.math3.linear.DiagonalMatrix; //导入依赖的package包/类
@Test
public void testRedundantEquations() {
LinearProblem problem = new LinearProblem(new double[][] {
{ 1, 1 },
{ 1, -1 },
{ 1, 3 }
}, new double[] { 3, 1, 5 });
T optimizer = createOptimizer()
.withMaxEvaluations(100)
.withMaxIterations(getMaxIterations())
.withModelAndJacobian(problem.getModelFunction(),
problem.getModelFunctionJacobian())
.withTarget(problem.getTarget())
.withWeight(new DiagonalMatrix(new double[] { 1, 1, 1 }))
.withStartPoint(new double[] { 1, 1 });
double[] optimum = optimizer.optimize().getPoint();
Assert.assertEquals(0, optimizer.computeRMS(optimum), 1e-10);
Assert.assertEquals(2, optimum[0], 1e-10);
Assert.assertEquals(1, optimum[1], 1e-10);
}