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:rcdemo.math.ClosedHermiteSpline.java

public static RealMatrix generate(RealVector p) {
    int n = p.getDimension();
    RealMatrix A = MatrixUtils.createRealMatrix(n, n);
    RealMatrix B = MatrixUtils.createRealMatrix(n, n);
    for (int i = 0; i < n; i++) {
        int ip = (i + 1) % n;
        int im = (i - 1 + n) % n;
        A.setEntry(i, im, 2);/* w w  w . j a va2s  . c o  m*/
        A.setEntry(i, i, 8);
        A.setEntry(i, ip, 2);
        B.setEntry(i, im, -6);
        B.setEntry(i, ip, 6);
    }
    RealVector Bp = B.operate(p);
    DecompositionSolver solver = new CholeskyDecomposition(A).getSolver();
    RealVector m = solver.solve(Bp);
    RealMatrix a = MatrixUtils.createRealMatrix(4, n);
    for (int i = 0; i < n; i++) {
        int ip = (i + 1) % n;
        a.setEntry(0, i, p.getEntry(i));
        a.setEntry(1, i, m.getEntry(i));
        a.setEntry(2, i, p.getEntry(ip));
        a.setEntry(3, i, m.getEntry(ip));
    }
    return a;
}

From source file:scorePairing.ScorePairingWithStaticMethods.java

public static void translateBarycenterListOfPointToOrigin(RealMatrix matrix, RealVector barycenter) {

    int countOfPoint = matrix.getColumnDimension();

    for (int i = 0; i < countOfPoint; i++) {
        matrix.addToEntry(0, i, -1.0 * barycenter.getEntry(0));
        matrix.addToEntry(1, i, -1.0 * barycenter.getEntry(1));
        matrix.addToEntry(2, i, -1.0 * barycenter.getEntry(2));
    }//from   w  w w .j  a  va2  s .  co m
}

From source file:se.toxbee.sleepfighter.challenge.math.LinearEquationProblem.java

private void generateProblem() {

    this.A = createCoefficients();

    int attempts = 0;
    RealVector solution;
    boolean foundb = false;
    do {/*from   w w w  .  j a  v a2  s.  c  om*/

        Debug.d("try again");

        // if after 40 attempts we still can't find a good constants vector, we should give up on this 
        // coefficient matrix and try creating a new one.
        if (attempts == 40) {
            Debug.d("new coefficients matrix");

            this.A = createCoefficients();
            attempts = 0;
        }

        // Generate a solution.
        solution = this.createSolutionVector();

        // Now compute Ax = b(where x is the solution)
        this.b = multiply(this.A, solution);

        // does b satisfy our requirements?
        if (isGoodb(b)) {
            foundb = true;
        }

        attempts++;

    } while (!foundb);

    Debug.d("solution: " + solution.toString());

    // solve for either x1 or x2
    this.variableToSolveFor = rng.nextBoolean() ? 0 : 1;
    this.solution = (int) solution.getEntry(this.variableToSolveFor);
}

From source file:se.toxbee.sleepfighter.challenge.math.LinearEquationProblem.java

private static boolean isGoodb(RealVector b) {
    final int MIN = -20;
    final int MAX = 59;

    return ((int) b.getEntry(0) > MIN && (int) b.getEntry(0) < MAX)
            && ((int) b.getEntry(1) > MIN && (int) b.getEntry(1) < MAX)
            && ((int) b.getEntry(2) > MIN && (int) b.getEntry(2) < MAX);
}

From source file:se.toxbee.sleepfighter.challenge.math.LinearEquationProblem.java

private static boolean isBoringSolution(RealVector v) {
    return isBoringSolution((int) v.getEntry(0)) || isBoringSolution((int) v.getEntry(1))
            || isBoringSolution((int) v.getEntry(2));
}

From source file:shapeCompare.ResultsFromEvaluateCost.java

@Override
public int hashCode() {

    float unit = 3 * algoParameters.getCELL_DIMENSION_OF_THE_PROBABILITY_MAP_ANGSTROM();

    RealVector trans = this.getTranslationVector();
    double x = trans.getEntry(0);
    double y = trans.getEntry(1);
    double z = trans.getEntry(2);
    int xInt = (int) Math.round(x / unit);
    int yInt = (int) Math.round(y / unit);
    int zInt = (int) Math.round(z / unit);

    RealMatrix rotMat = this.getRotationMatrix();
    Rotation rotation = new Rotation(rotMat.getData(), 0.01);

    int unitAngleDegrees = 8;
    double angle = rotation.getAngle();
    int angleInt = (int) Math.round((angle * 180 / Math.PI) / unitAngleDegrees);

    int hashcode = xInt;
    hashcode = hashcode * 71 + yInt;// w  w  w.ja va2  s.co  m
    hashcode = hashcode * 71 + zInt;
    hashcode = hashcode * 71 + angleInt;
    return hashcode;
}

From source file:syncleus.gremlann.model.som.SOM.java

private void updateBounds(final RealVector position) {
    //make sure we have the proper dimentionality
    if (position.getDimension() != getDimension())
        throw new IllegalArgumentException("Dimentionality mismatch");

    for (int dimensionIndex = 0; dimensionIndex < position.getDimension(); dimensionIndex++) {
        final double v = position.getEntry(dimensionIndex);

        if (this.getUpperBounds().getEntry(dimensionIndex) < v)
            this.getUpperBounds().setEntry(dimensionIndex, v);
        if (this.getLowerBounds().getEntry(dimensionIndex) > v)
            this.getLowerBounds().setEntry(dimensionIndex, v);
    }/*  w  w w  . j a va2s . c om*/
}

From source file:syncleus.gremlann.train.Backprop.java

/**
 * /*  w  w  w  .ja  v a  2  s.  com*/
 * @param input
 * @param expectedOutput
 * @param train
 * @return error rate
 */
public double associate(RealVector input, RealVector expectedOutput, boolean train) {

    brain.input(true, array(input));

    ArrayRealVector o = brain.outputSignals();
    double distance = o.getDistance(expectedOutput);

    if (train) {
        Set<Vertex> outputs = brain.traverseOutputNeurons().toSet();

        int j = 0;
        for (Vertex outputNeuron : outputs) {
            double expected = expectedOutput.getEntry(j);
            double outputSignal = signal(outputNeuron);
            double dt = (expected - outputSignal)
                    * getActivationFunction().activateDerivative(activity(outputNeuron));

            set(outputNeuron, "deltaTrain", dt);
            j++;
        }

        brain.iterateNeuronsBackward(outputs, new Function<Vertex, Boolean>() {
            @Override
            public Boolean apply(Vertex f) {
                //if (isTrue(f,"input")) return false;
                backpropagate(f);
                return true;
            }
        });

    }

    return distance;
}

From source file:ummisco.gama.opengl.vaoGenerator.GeomMathUtils.java

public static Matrix4d getHomography3(final double[][] srcPoints, final double[][] dstPoints) {

    // see :/*from   ww w  . j a va 2 s .  co  m*/
    // http://math.stackexchange.com/questions/494238/how-to-compute-homography-matrix-h-from-corresponding-points-2d-2d-planar-homog

    final double sx1 = srcPoints[0][0];
    final double sy1 = srcPoints[0][1];
    final double sx2 = srcPoints[1][0];
    final double sy2 = srcPoints[1][1];
    final double sx3 = srcPoints[2][0];
    final double sy3 = srcPoints[2][1];
    final double sx4 = srcPoints[3][0];
    final double sy4 = srcPoints[3][1];

    final double dx1 = dstPoints[0][0];
    final double dy1 = dstPoints[0][1];
    final double dx2 = dstPoints[1][0];
    final double dy2 = dstPoints[1][1];
    final double dx3 = dstPoints[2][0];
    final double dy3 = dstPoints[2][1];
    final double dx4 = dstPoints[3][0];
    final double dy4 = dstPoints[3][1];

    final RealMatrix coefficients = new Array2DRowRealMatrix(
            new double[][] { { -sx1, -sy1, -1, 0, 0, 0, sx1 * dx1, sy1 * dx1 },
                    { 0, 0, 0, -dx1, -dy1, -1, sx1 * dy1, sy1 * dy1 },
                    { -sx2, -sy2, -1, 0, 0, 0, sx2 * dx2, sy2 * dx2 },
                    { 0, 0, 0, -dx2, -dy2, -1, sx2 * dy2, sy2 * dy2 },
                    { -sx3, -sy3, -1, 0, 0, 0, sx3 * dx3, sy3 * dx3 },
                    { 0, 0, 0, -dx3, -dy3, -1, sx3 * dy3, sy3 * dy3 },
                    { -sx4, -sy4, -1, 0, 0, 0, sx4 * dx4, sy4 * dx4 },
                    { 0, 0, 0, -dx4, -dy4, -1, sx4 * dy4, sy4 * dy4 } },
            false);
    final DecompositionSolver solver = new LUDecomposition(coefficients).getSolver();

    final RealVector constants = new ArrayRealVector(new double[] { dx1, dy1, dx2, dy2, dx3, dy3, dx4, dy4 },
            false);
    final RealVector solution = solver.solve(constants);

    final Matrix4d Result = new Matrix4d();
    Result.m00 = solution.getEntry(0);
    Result.m01 = solution.getEntry(1);
    Result.m02 = 0;
    Result.m03 = solution.getEntry(2);
    Result.m10 = solution.getEntry(3);
    Result.m11 = solution.getEntry(4);
    Result.m12 = 0;
    Result.m13 = solution.getEntry(5);
    Result.m20 = 0;
    Result.m21 = 0;
    Result.m22 = 1;
    Result.m23 = 0;
    Result.m30 = solution.getEntry(6);
    Result.m31 = solution.getEntry(7);
    Result.m32 = 0;
    Result.m33 = 1;

    return Result;

}

From source file:universal.Calc.java

private boolean Divisible(RealVector v, RealVector v2) {
    for (int i = 0; i < 6; i++) {
        System.out//from  w  w w .ja va2  s .  c o  m
                .println("div: " + v.getEntry(i) / v2.getEntry(i) + ", mod: " + v.getEntry(i) % v2.getEntry(i));
    }
    if (v.getEntry(0) % v2.getEntry(0) == 0) {
        System.out.print("y,");
        if (v.getEntry(1) % v2.getEntry(1) == 0) {
            System.out.print("y,");
            if (v.getEntry(2) % v2.getEntry(2) == 0) {
                System.out.print("y,");
                if (v.getEntry(3) % v2.getEntry(3) == 0) {
                    System.out.print("y,");
                    if (v.getEntry(4) % v2.getEntry(4) == 0) {
                        System.out.print("y,");
                        if (v.getEntry(5) % v2.getEntry(5) == 0) {
                            System.out.print("y,");
                            if (v.getEntry(6) % v2.getEntry(6) == 0) {
                                System.out.print("y,");
                                return true;
                            }
                        }
                    }
                }
            }
        }
    }
    return false;
}