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


Java RealVector.setEntry方法代码示例

本文整理汇总了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);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:30,代码来源:SimplexSolverTest.java

示例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;
}
 
开发者ID:apache,项目名称:incubator-datafu,代码行数:11,代码来源:LSHTest.java

示例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);
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:67,代码来源:KalmanFilterTest.java


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