本文整理汇总了Java中org.apache.commons.math.linear.RealVector.setEntry方法的典型用法代码示例。如果您正苦于以下问题:Java RealVector.setEntry方法的具体用法?Java RealVector.setEntry怎么用?Java RealVector.setEntry使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math.linear.RealVector
的用法示例。
在下文中一共展示了RealVector.setEntry方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: equationFromString
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
/**
* Converts a test string to a {@link LinearConstraint}.
* Ex: x0 + x1 + x2 + x3 - x12 = 0
*/
private LinearConstraint equationFromString(int numCoefficients, String s) {
Relationship relationship;
if (s.contains(">=")) {
relationship = Relationship.GEQ;
} else if (s.contains("<=")) {
relationship = Relationship.LEQ;
} else if (s.contains("=")) {
relationship = Relationship.EQ;
} else {
throw new IllegalArgumentException();
}
String[] equationParts = s.split("[>|<]?=");
double rhs = Double.parseDouble(equationParts[1].trim());
RealVector lhs = new ArrayRealVector(numCoefficients);
String left = equationParts[0].replaceAll(" ?x", "");
String[] coefficients = left.split(" ");
for (String coefficient : coefficients) {
double value = coefficient.charAt(0) == '-' ? -1 : 1;
int index = Integer.parseInt(coefficient.replaceFirst("[+|-]", "").trim());
lhs.setEntry(index, value);
}
return new LinearConstraint(lhs, relationship, rhs);
}
示例2: getRandomVector
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
static RealVector getRandomVector(RandomData rd, double stddev, int dim)
{
RealVector vec = new ArrayRealVector(dim);
for(int i =0;i < dim;++i)
{
vec.setEntry(i, rd.nextGaussian(0, stddev));
}
return vec;
}
示例3: testConstant
import org.apache.commons.math.linear.RealVector; //导入方法依赖的package包/类
@Test
public void testConstant() {
double constantValue = 10d;
double measurementNoise = 0.1d;
double processNoise = 1e-5d;
// A = [ 1 ]
RealMatrix A = new Array2DRowRealMatrix(new double[] { 1d });
// no control input
RealMatrix B = null;
// H = [ 1 ]
RealMatrix H = new Array2DRowRealMatrix(new double[] { 1d });
// x = [ 10 ]
RealVector x = new ArrayRealVector(new double[] { constantValue });
// Q = [ 1e-5 ]
RealMatrix Q = new Array2DRowRealMatrix(new double[] { processNoise });
// R = [ 0.1 ]
RealMatrix R = new Array2DRowRealMatrix(new double[] { measurementNoise });
ProcessModel pm
= new DefaultProcessModel(A, B, Q,
new ArrayRealVector(new double[] { constantValue }), null);
MeasurementModel mm = new DefaultMeasurementModel(H, R);
KalmanFilter filter = new KalmanFilter(pm, mm);
Assert.assertEquals(1, filter.getMeasurementDimension());
Assert.assertEquals(1, filter.getStateDimension());
assertMatrixEquals(Q.getData(), filter.getErrorCovariance());
// check the initial state
double[] expectedInitialState = new double[] { constantValue };
assertVectorEquals(expectedInitialState, filter.getStateEstimation());
RealVector pNoise = new ArrayRealVector(1);
RealVector mNoise = new ArrayRealVector(1);
RandomGenerator rand = new JDKRandomGenerator();
// iterate 60 steps
for (int i = 0; i < 60; i++) {
filter.predict();
// Simulate the process
pNoise.setEntry(0, processNoise * rand.nextGaussian());
// x = A * x + p_noise
x = A.operate(x).add(pNoise);
// Simulate the measurement
mNoise.setEntry(0, measurementNoise * rand.nextGaussian());
// z = H * x + m_noise
RealVector z = H.operate(x).add(mNoise);
filter.correct(z);
// state estimate should be larger than measurement noise
double diff = Math.abs(constantValue - filter.getStateEstimation()[0]);
// System.out.println(diff);
Assert.assertTrue(MathUtils.compareTo(diff, measurementNoise, 1e-6) < 0);
}
// error covariance should be already very low (< 0.02)
Assert.assertTrue(MathUtils.compareTo(filter.getErrorCovariance()[0][0],
0.02d, 1e-6) < 0);
}