Example usage for org.apache.commons.math3.linear RealMatrix setEntry

List of usage examples for org.apache.commons.math3.linear RealMatrix setEntry

Introduction

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

Prototype

void setEntry(int row, int column, double value) throws OutOfRangeException;

Source Link

Document

Set the entry in the specified row and column.

Usage

From source file:edu.oregonstate.eecs.mcplan.ml.SequentialProjectionHashLearner.java

private void T(final RealMatrix S_tilde, final RealMatrix S) {
    for (int i = 0; i < S_tilde.getRowDimension(); ++i) {
        for (int j = 0; j < S_tilde.getColumnDimension(); ++j) {
            final double st = S_tilde.getEntry(i, j);
            S_tilde.setEntry(i, j, st * S.getEntry(i, j) < 0 ? st : 0);
        }//from  ww  w . ja  v  a  2 s  .  co m
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.RotationMatrixBuilder.java

/**
 * Returns a rotation matrix for rotating about the 2D plane defined by
 * the specified axes./*from  w ww.j a v  a  2 s . co m*/
 * 
 * @param i the first axis
 * @param j the second axis
 * @param theta the rotation angle in radians
 * @return a rotation matrix for rotating about the 2D plane defined by
 *         the specified axes
 */
private RealMatrix newRotationMatrix(int i, int j, double theta) {
    RealMatrix rotation = newIdentityMatrix();

    rotation.setEntry(i, i, Math.cos(theta));
    rotation.setEntry(i, j, -Math.sin(theta));
    rotation.setEntry(j, i, Math.sin(theta));
    rotation.setEntry(j, j, Math.cos(theta));

    return rotation;
}

From source file:hivemall.utils.math.MatrixUtilsTest.java

@Test
public void testTridiagonalEigen() {
    // Tridiagonal Matrix
    RealMatrix T = new Array2DRowRealMatrix(
            new double[][] { new double[] { 40, 60, 0, 0 }, new double[] { 60, 10, 120, 0 },
                    new double[] { 0, 120, 10, 120 }, new double[] { 0, 0, 120, 10 } });

    double[] eigvals = new double[4];
    RealMatrix eigvecs = new Array2DRowRealMatrix(new double[4][4]);

    MatrixUtils.tridiagonalEigen(T, 2, eigvals, eigvecs);

    RealMatrix actual = eigvecs.multiply(eigvecs.transpose());

    RealMatrix expected = new Array2DRowRealMatrix(new double[4][4]);
    for (int i = 0; i < 4; i++) {
        expected.setEntry(i, i, 1);
    }//from www  .  ja v  a  2s. c  o  m

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 4; j++) {
            Assert.assertEquals(expected.getEntry(i, j), actual.getEntry(i, j), 0.001d);
        }
    }
}

From source file:mase.spec.SilhouetteDistanceCalculator.java

private RealMatrix computeDistanceMatrix(List<BehaviourResult> brs) {
    RealMatrix mat = new BlockRealMatrix(brs.size(), brs.size());
    for (int i = 0; i < brs.size(); i++) {
        for (int j = i + 1; j < brs.size(); j++) {
            double d = brs.get(i).distanceTo(brs.get(j));
            mat.setEntry(i, j, d);
            mat.setEntry(j, i, d);/*from w  w  w .  ja  va  2 s  . c  o  m*/
        }
    }
    return mat;
}

From source file:edu.ucdenver.bios.power.ConditionalOrthogonalPolynomial3FactorTest.java

/**
 * Sets up the basic X, beta matrices for each of the tests.  The individual
 * tests create different contrast matrices
 * @return/*from  ww w  .  jav a2  s  .  co m*/
 */
private GLMMPowerParameters buildInputsWithoutContrasts() {
    int Q = dataD.length * dataE.length * dataF.length;
    int P = dataA.length * dataB.length * dataC.length;
    // build the inputs
    GLMMPowerParameters params = new GLMMPowerParameters();

    // add alpha values - bonferroni corrected for 6 comparisons
    params.addAlpha(0.05);

    // build the design matrix
    params.setDesignEssence(org.apache.commons.math3.linear.MatrixUtils.createRealIdentityMatrix(Q));
    // add a concise representation of the design matrix to the alt matrix string
    matrixAltStringBuffer.append("\\begin{eqnarray*}\n");
    matrixAltStringBuffer.append("\\underset{\\left(" + Q + "\\times" + Q
            + "\\right)}{\\text{Es}\\left(\\mathbf{X}\\right)} & = & I_{" + Q + "}\n");
    matrixAltStringBuffer.append("\\end{eqnarray*}\n");
    // build beta matrix
    RealMatrix beta = MatrixUtils.getRealMatrixWithFilledValue(Q, P, 0);
    beta.setEntry(0, 0, 1);
    params.setBeta(new FixedRandomMatrix(beta.getData(), null, false));
    // add latex to represent matrix
    matrixAltStringBuffer.append("\\begin{eqnarray*}\n");
    matrixAltStringBuffer.append("\\underset{\\left(" + Q + "\\times" + P + "\\right)}{\\mathbf{B}} & = & "
            + "\\begin{bmatrix}1 & 0 & \\ldots & 0\\\\\n" + "0 &  &  & \\vdots\\\\\n"
            + "\\vdots &  &  & \\vdots\\\\\n" + "0 & \\ldots & \\ldots & 0\n" + "\\end{bmatrix}\n");
    matrixAltStringBuffer.append("\\end{eqnarray*}\n");
    // add beta scale values
    params.addBetaScale(9);
    params.addBetaScale(18);
    params.addBetaScale(27);

    // build theta null matrix
    double[][] theta0 = { { 0, 0, 0, 0 } };
    params.setTheta(new Array2DRowRealMatrix(theta0));
    matrixAltStringBuffer.append("\\begin{eqnarray*}\n");
    matrixAltStringBuffer
            .append("\\underset{\\left(" + 1 + "\\times" + 4 + "\\right)}{\\mathbf{\\Theta}_{0}} & = & "
                    + "\\begin{bmatrix}0 & 0 & 0 & 0\n" + "\\end{bmatrix}\n");
    matrixAltStringBuffer.append("\\end{eqnarray*}\n");
    // build sigma matrix
    RealMatrix sigma = org.apache.commons.math3.linear.MatrixUtils.createRealIdentityMatrix(P);
    for (int i = 0; i < P; i++)
        sigma.setEntry(i, i, i + 1);
    params.setSigmaError(sigma);
    // add sigma scale values
    params.addSigmaScale(1);
    matrixAltStringBuffer.append("\\begin{eqnarray*}\n");
    matrixAltStringBuffer.append("\\underset{\\left(" + P + "\\times" + P
            + "\\right)}{\\mathbf{\\Sigma}_{E}} & = & " + "\\begin{bmatrix}1 & 2 & 3 & \\ldots & " + P + "\n"
            + "\\end{bmatrix} \\times I_{" + P + "}\n");
    matrixAltStringBuffer.append("\\end{eqnarray*}\n");
    // add sample size multipliers
    for (int perGroupN = 2; perGroupN <= 12; perGroupN += 2)
        params.addSampleSize(perGroupN);
    //params.addSampleSize(2);
    return params;
}

From source file:edu.cudenver.bios.power.test.paper.TestConditionalOrthogonalPolynomial3Factor.java

/**
 * Sets up the basic X, beta matrices for each of the tests.  The individual
 * tests create different contrast matrices
 * @return//from  ww w.jav  a2  s  .  c o m
 */
private GLMMPowerParameters buildInputsWithoutContrasts() {
    int Q = dataD.length * dataE.length * dataF.length;
    int P = dataA.length * dataB.length * dataC.length;
    // build the inputs        
    GLMMPowerParameters params = new GLMMPowerParameters();

    // add alpha values - bonferroni corrected for 6 comparisons
    params.addAlpha(0.05);

    // build the design matrix 
    params.setDesignEssence(org.apache.commons.math3.linear.MatrixUtils.createRealIdentityMatrix(Q));
    // add a concise representation of the design matrix to the alt matrix string
    matrixAltStringBuffer.append("\\begin{eqnarray*}\n");
    matrixAltStringBuffer.append("\\underset{\\left(" + Q + "\\times" + Q
            + "\\right)}{\\text{Es}\\left(\\mathbf{X}\\right)} & = & I_{" + Q + "}\n");
    matrixAltStringBuffer.append("\\end{eqnarray*}\n");
    // build beta matrix
    RealMatrix beta = MatrixUtils.getRealMatrixWithFilledValue(Q, P, 0);
    beta.setEntry(0, 0, 1);
    params.setBeta(new FixedRandomMatrix(beta.getData(), null, false));
    // add latex to represent matrix
    matrixAltStringBuffer.append("\\begin{eqnarray*}\n");
    matrixAltStringBuffer.append("\\underset{\\left(" + Q + "\\times" + P + "\\right)}{\\mathbf{B}} & = & "
            + "\\begin{bmatrix}1 & 0 & \\ldots & 0\\\\\n" + "0 &  &  & \\vdots\\\\\n"
            + "\\vdots &  &  & \\vdots\\\\\n" + "0 & \\ldots & \\ldots & 0\n" + "\\end{bmatrix}\n");
    matrixAltStringBuffer.append("\\end{eqnarray*}\n");
    // add beta scale values
    params.addBetaScale(9);
    params.addBetaScale(18);
    params.addBetaScale(27);

    // build theta null matrix
    double[][] theta0 = { { 0, 0, 0, 0 } };
    params.setTheta(new Array2DRowRealMatrix(theta0));
    matrixAltStringBuffer.append("\\begin{eqnarray*}\n");
    matrixAltStringBuffer
            .append("\\underset{\\left(" + 1 + "\\times" + 4 + "\\right)}{\\mathbf{\\Theta}_{0}} & = & "
                    + "\\begin{bmatrix}0 & 0 & 0 & 0\n" + "\\end{bmatrix}\n");
    matrixAltStringBuffer.append("\\end{eqnarray*}\n");
    // build sigma matrix
    RealMatrix sigma = org.apache.commons.math3.linear.MatrixUtils.createRealIdentityMatrix(P);
    for (int i = 0; i < P; i++)
        sigma.setEntry(i, i, i + 1);
    params.setSigmaError(sigma);
    // add sigma scale values
    params.addSigmaScale(1);
    matrixAltStringBuffer.append("\\begin{eqnarray*}\n");
    matrixAltStringBuffer.append("\\underset{\\left(" + P + "\\times" + P
            + "\\right)}{\\mathbf{\\Sigma}_{E}} & = & " + "\\begin{bmatrix}1 & 2 & 3 & \\ldots & " + P + "\n"
            + "\\end{bmatrix} \\times I_{" + P + "}\n");
    matrixAltStringBuffer.append("\\end{eqnarray*}\n");
    // add sample size multipliers
    for (int perGroupN = 2; perGroupN <= 12; perGroupN += 2)
        params.addSampleSize(perGroupN);
    //params.addSampleSize(2);
    return params;
}

From source file:io.github.malapert.jwcs.coordsystem.Utility.java

/**
 * Remove the elliptic component of annual aberration when this is included
 * in a catalogue fk4 position.//  w w w.ja v  a  2  s. c om
 * 
 * Notes:
 * ------
 * Return a new position where the elliptic terms of aberration 
 * are removed i.e. convert a apparent position from a catalog to
 * a mean place.
 * The effects of ecliptic aberration were included in the 
 * catalog positions to facilitate telescope pointing.
 * See also notes at 'addEterms'.
 * 
 * @param xyz vector xyz
 * @param eterm E-terms vector (as returned by getEterms()). If input a is 
 * omitted (== *null*), the e-terms for 1950 will be substituted.
 * @return **Mean place**
 */
public final static RealMatrix removeEterms(final RealMatrix xyz, RealMatrix eterm) {
    RealMatrix xyzeterm = xyz.copy();

    if (eterm == null) {
        eterm = FK4.getEterms(1950);
    }
    double x = xyz.getEntry(0, 0);
    double y = xyz.getEntry(1, 0);
    double z = xyz.getEntry(2, 0);
    x -= eterm.getEntry(0, 0);
    y -= eterm.getEntry(0, 1);
    z -= eterm.getEntry(0, 2);
    xyzeterm.setEntry(0, 0, x);
    xyzeterm.setEntry(1, 0, y);
    xyzeterm.setEntry(2, 0, z);

    return xyzeterm;
}

From source file:ffnn.FFNNTubesAI.java

@Override
public double[] distributionForInstance(Instance instance) throws Exception {
    RealMatrix input_matrix = new BlockRealMatrix(1, input_layer + 1);

    instance = filterNominalNumeric(instance);

    for (int k = 0; k < input_layer; k++) {
        input_matrix.setEntry(0, k, instance.value(k));
    }//from   w  w  w  . ja va 2 s .  co m
    input_matrix.setEntry(0, input_layer, 1.0); // bias

    RealMatrix hidden_matrix = input_matrix.multiply(weight1);
    for (int y = 0; y < hidden_layer; ++y) {
        hidden_matrix.setEntry(0, y, sig(hidden_matrix.getEntry(0, y)));
    }
    RealMatrix output_matrix = hidden_matrix.multiply(weight2).add(bias2);
    for (int y = 0; y < output_layer; ++y) {
        output_matrix.setEntry(0, y, sig(output_matrix.getEntry(0, y)));
    }
    double[][] m = output_matrix.getData();

    return m[0];
}

From source file:io.yields.math.concepts.operator.Smoothness.java

private RealMatrix computeDistance(List<Tuple> normalizedData) {
    RealMatrix a = new Array2DRowRealMatrix(normalizedData.size(), order + 1);
    RealMatrix b = new Array2DRowRealMatrix(normalizedData.size(), 1);
    int row = 0;/*  w w  w. j a v  a2  s.com*/
    for (Tuple tuple : normalizedData) {
        final int currentRow = row;
        IntStream.rangeClosed(0, order)
                .forEach(power -> a.setEntry(currentRow, power, Math.pow(tuple.getX(), power)));
        b.setEntry(currentRow, 0, tuple.getY());
        row++;
    }
    DecompositionSolver solver = new QRDecomposition(a, EPS).getSolver();
    if (solver.isNonSingular() && !isConstant(b)) {
        RealMatrix solution = solver.solve(b);
        return a.multiply(solution).subtract(b);
    } else {
        return new Array2DRowRealMatrix(normalizedData.size(), 1);
    }
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.util.RotationMatrixBuilder.java

/**
 * Returns an identity matrix./*  www .  j av  a2 s  . co m*/
 * 
 * @return an identity matrix
 */
private RealMatrix newIdentityMatrix() {
    RealMatrix identity = MatrixUtils.createRealMatrix(dimension, dimension);

    for (int i = 0; i < dimension; i++) {
        identity.setEntry(i, i, 1.0);
    }

    return identity;
}