Example usage for org.apache.commons.math3.linear RealVector getEntry

List of usage examples for org.apache.commons.math3.linear RealVector getEntry

Introduction

In this page you can find the example usage for org.apache.commons.math3.linear RealVector getEntry.

Prototype

public abstract double getEntry(int index) throws OutOfRangeException;

Source Link

Document

Return the entry at the specified index.

Usage

From source file:edu.oregonstate.eecs.mcplan.util.VectorMeanVarianceAccumulator.java

public void add(final RealVector x) {
    for (int i = 0; i < Ndim; ++i) {
        mv_[i].add(x.getEntry(i));
    }/*  ww  w. j a  va 2  s  .  c o  m*/
}

From source file:com.cloudera.oryx.common.math.VectorsTest.java

@Test
public void testOf() {
    RealVector of = Vectors.of(1.0, -2.0, 7.0);
    assertEquals(3, of.getDimension());/*from   ww  w .  j a va 2 s.  c  o  m*/
    assertEquals(1.0, of.getEntry(0));
    assertEquals(-2.0, of.getEntry(1));
    assertEquals(7.0, of.getEntry(2));
}

From source file:com.cloudera.oryx.common.math.VectorsTest.java

@Test
public void testLike() {
    RealVector of = Vectors.of(1.0, -2.0, 7.0);
    RealVector like = Vectors.like(of);
    assertEquals(of.getDimension(), like.getDimension());
    assertEquals(0.0, like.getEntry(0));
    assertSame(of.getClass(), like.getClass());
}

From source file:com.cloudera.oryx.common.math.VectorsTest.java

@Test
public void testSparse() {
    RealVector sparse = Vectors.sparse(Integer.MAX_VALUE);
    assertEquals(Integer.MAX_VALUE, sparse.getDimension());
    assertEquals(0.0, sparse.getEntry(0));
}

From source file:com.cloudera.oryx.common.math.CommonsMathSolver.java

@Override
public double[] solveFToD(float[] b) {
    RealVector bVec = Vectors.dense(b.length);
    for (int i = 0; i < b.length; i++) {
        bVec.setEntry(i, b[i]);//from   w w w.j  av a 2  s . com
    }
    RealVector vec = solver.solve(bVec);
    double[] result = new double[b.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = vec.getEntry(i);
    }
    return result;
}

From source file:net.myrrix.common.math.CommonsMathSolver.java

@Override
public double[] solveFToD(float[] b) {
    ArrayRealVector bVec = new ArrayRealVector(b.length);
    for (int i = 0; i < b.length; i++) {
        bVec.setEntry(i, b[i]);//  w w  w. jav  a 2s. com
    }
    RealVector vec = solver.solve(bVec);
    double[] result = new double[b.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = vec.getEntry(i);
    }
    return result;
}

From source file:com.cloudera.oryx.common.math.CommonsMathSolver.java

@Override
public float[] solveDToF(double[] b) {
    RealVector vec = solver.solve(Vectors.of(b));
    float[] result = new float[b.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = (float) vec.getEntry(i);
    }/*from  ww w .  ja  v a 2 s.  co m*/
    return result;
}

From source file:net.myrrix.common.math.CommonsMathSolver.java

@Override
public float[] solveDToF(double[] b) {
    RealVector vec = solver.solve(new ArrayRealVector(b, false));
    float[] result = new float[b.length];
    for (int i = 0; i < result.length; i++) {
        result[i] = (float) vec.getEntry(i);
    }/*  w  w  w .ja va  2s . c om*/
    return result;
}

From source file:io.warp10.script.functions.VECTO.java

@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {

    Object o = stack.pop();//  w w w.  j  a  v  a2s.c o m

    if (!(o instanceof RealVector)) {
        throw new WarpScriptException(getName() + " expects a vector on top of the stack.");
    }

    RealVector vector = (RealVector) o;

    List<Object> elts = new ArrayList<Object>(vector.getDimension());

    for (int i = 0; i < vector.getDimension(); i++) {
        elts.add(vector.getEntry(i));
    }

    stack.push(elts);

    return stack;
}

From source file:com.gordoni.opal.UtilityJoinSlope.java

public UtilityJoinSlope(Config config, String join_function, Utility utility1, Utility utility2, double c1,
        double c2) {
    this.config = config;
    this.utility1 = utility1;
    this.utility2 = utility2;

    this.c1 = c1;
    this.c2 = c2;

    if (c1 < c2) {
        if (join_function.equals("slope-cubic-monotone") || join_function.equals("slope-cubic-smooth")) {
            RealMatrix a = new Array2DRowRealMatrix(
                    new double[][] { { c1 * c1 * c1, c1 * c1, c1, 1 }, { c2 * c2 * c2, c2 * c2, c2, 1 },
                            { 3 * c1 * c1, 2 * c1, 1, 0 }, { 3 * c2 * c2, 2 * c2, 1, 0 } });
            double s1 = utility1.slope(c1);
            double s2 = utility2.slope(c2);
            double s2_1 = utility1.slope2(c1);
            double s2_2 = utility2.slope2(c2);
            double secant = (s2 - s1) / (c2 - c1);
            assert (secant < 0);
            double alpha = s2_1 / secant;
            double beta = s2_2 / secant;
            if (!monotone(alpha, beta)) {
                assert (!join_function.equals("slope-cubic-smooth"));
                // Guarantee monotonicity at the cost of a discontinuity in slope2 space.
                s2_1 = Math.max(s2_1, 3 * secant); // Can do better (see paper), but this is good enough.
                alpha = s2_1 / secant;//from  www  .  ja v  a 2s  . co  m
                if (!monotone(alpha, beta)) {
                    s2_2 = 3 * secant;
                    beta = s2_2 / secant;
                }
            }
            RealVector b = new ArrayRealVector(new double[] { s1, s2, s2_1, s2_2 });
            DecompositionSolver solver = new LUDecomposition(a).getSolver();
            RealVector solution = solver.solve(b);
            this.w = solution.getEntry(0);
            this.x = solution.getEntry(1);
            this.y = solution.getEntry(2);
            this.z = solution.getEntry(3);
        } else if (join_function.equals("slope-linear")) {
            this.w = 0;
            this.x = 0;
            this.y = (utility2.slope(c2) - utility1.slope(c1)) / (c2 - c1);
            this.z = utility1.slope(c1) - this.y * c1;
        } else
            assert (false);
    } else {
        this.w = 0;
        this.x = 0;
        this.y = 0;
        this.z = 0;
    }

    this.zero1 = utility(c1) - utility1.utility(c1);
    this.zero2 = utility2.utility(c2) - utility(c2);

    this.u1 = utility(c1);
    this.u2 = utility(c2);

    set_constants();
}