Example usage for org.apache.commons.math3.linear Array2DRowRealMatrix setSubMatrix

List of usage examples for org.apache.commons.math3.linear Array2DRowRealMatrix setSubMatrix

Introduction

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

Prototype

@Override
public void setSubMatrix(final double[][] subMatrix, final int row, final int column)
        throws NoDataException, OutOfRangeException, DimensionMismatchException, NullArgumentException 

Source Link

Usage

From source file:edu.cmu.sphinx.speakerid.SpeakerCluster.java

public void mergeWith(SpeakerCluster target) throws NullPointerException {
    if (target == null)
        throw new NullPointerException();
    Iterator<Segment> it = target.segmentSet.iterator();
    while (it.hasNext()) {
        if (!this.addSegment(it.next()))
            System.out.println("Something doesn't work in mergeWith method, Cluster class");
    }/* w  w w . j a  v  a 2 s  .c om*/
    int rowDim = featureMatrix.getRowDimension() + target.getFeatureMatrix().getRowDimension();
    int colDim = featureMatrix.getColumnDimension();
    Array2DRowRealMatrix combinedFeatures = new Array2DRowRealMatrix(rowDim, colDim);
    combinedFeatures.setSubMatrix(featureMatrix.getData(), 0, 0);
    combinedFeatures.setSubMatrix(target.getFeatureMatrix().getData(), featureMatrix.getRowDimension(), 0);
    bicValue = SpeakerIdentification.getBICValue(combinedFeatures);
    featureMatrix = new Array2DRowRealMatrix(combinedFeatures.getData());
}

From source file:edu.cmu.sphinx.speakerid.SpeakerIdentification.java

double computeDistance(SpeakerCluster c1, SpeakerCluster c2) {
    int rowDim = c1.getFeatureMatrix().getRowDimension() + c2.getFeatureMatrix().getRowDimension();
    int colDim = c1.getFeatureMatrix().getColumnDimension();
    Array2DRowRealMatrix combinedFeatures = new Array2DRowRealMatrix(rowDim, colDim);
    combinedFeatures.setSubMatrix(c1.getFeatureMatrix().getData(), 0, 0);
    combinedFeatures.setSubMatrix(c2.getFeatureMatrix().getData(), c1.getFeatureMatrix().getRowDimension(), 0);
    double bicValue = getBICValue(combinedFeatures);
    double d = Segment.FEATURES_SIZE;
    double penalty = 0.5 * (d + 0.5 * d * (d + 1)) * Math.log(combinedFeatures.getRowDimension()) * 2;
    return bicValue - c1.getBicValue() - c2.getBicValue() - penalty;
}

From source file:org.apache.hadoop.hive.ql.abm.simulation.MCSimNode.java

private Array2DRowRealMatrix concat(Array2DRowRealMatrix A, Array2DRowRealMatrix B, Array2DRowRealMatrix C,
        Array2DRowRealMatrix D) {
    int dim = A.getRowDimension() + D.getRowDimension();
    Array2DRowRealMatrix ret = new Array2DRowRealMatrix(dim, dim);

    ret.setSubMatrix(A.getData(), 0, 0);
    ret.setSubMatrix(B.getData(), 0, A.getColumnDimension());
    ret.setSubMatrix(C.getData(), A.getRowDimension(), 0);
    ret.setSubMatrix(D.getData(), A.getRowDimension(), A.getColumnDimension());

    return ret;/*from   w  w  w . ja v a  2  s.  c  o  m*/
}

From source file:org.interpss.opf.dc.impl.EqIneqMatrixBuilder.java

public Array2DRowRealMatrix formG() {
    RealMatrix U_matrix = formU();//from  w  w w  .  j  a v a 2 s. c  o  m
    ;
    RealMatrix Wrr_matrix = formReducedADWMatrix();
    int gcnt = U_matrix.getRowDimension() + Wrr_matrix.getRowDimension();
    Array2DRowRealMatrix G = new Array2DRowRealMatrix(gcnt, gcnt);
    G.setSubMatrix(U_matrix.getData(), 0, 0);
    G.setSubMatrix(Wrr_matrix.getData(), U_matrix.getRowDimension(), U_matrix.getColumnDimension());
    return G;
}

From source file:org.interpss.opf.dc.impl.EqIneqMatrixBuilder.java

public Array2DRowRealMatrix formCeq() {
    int numOfBus = opfNet.getNoActiveBus();
    int numOfGen = opfNet.getNoOfGen();

    Array2DRowRealMatrix genBusAdjacent = new Array2DRowRealMatrix(numOfBus, numOfGen);
    int genCount = 0;
    for (Bus b : opfNet.getBusList()) {
        // set the elements in genBusAdjacent matrix to ONE if there is a
        // generator ;
        /*/*from  w w w .  java  2s.c o m*/
         * in the case of multi-gen ,all are treated as a union;
         * not suitable for a case with multi-generators connected to one
         * bus;
         */
        if (opfNet.isOpfGenBus(b)) {
            genBusAdjacent.setEntry(b.getSortNumber(), genCount, 1);
            genCount++;
        }
    }
    Array2DRowRealMatrix BrTranspose = (Array2DRowRealMatrix) this.getReducedBusAdmittance().transpose();

    Array2DRowRealMatrix CeqTranspose = new Array2DRowRealMatrix(numOfBus, numOfBus + numOfGen - 1);
    CeqTranspose.setSubMatrix(genBusAdjacent.getData(), 0, 0); // Ceq'={genBusAdjacent,BrTranspose}
    CeqTranspose.setSubMatrix(BrTranspose.scalarMultiply(-1).getData(), 0, numOfGen);
    return (Array2DRowRealMatrix) CeqTranspose.transpose();
}

From source file:org.interpss.opf.dc.impl.EqIneqMatrixBuilder.java

public Array2DRowRealMatrix formCiq() {
    int numOfBranch = opfNet.getNoActiveBranch();
    int numOfBus = opfNet.getNoActiveBus();
    int numOfGen = opfNet.getNoOfGen();

    double bij = DEFAULT_BIJ;

    int braIndex = 0;
    Array2DRowRealMatrix braAdmDiag = new Array2DRowRealMatrix(numOfBranch, numOfBranch);
    Array2DRowRealMatrix braBusAdjacent = new Array2DRowRealMatrix(numOfBranch, numOfBus - 1);
    int swingIndex = this.getSwingBusIndex();
    for (Branch bra : opfNet.getBranchList()) {
        //if (bra.isAclfBranch()) {
        DclfOpfBranch aclfBra = (DclfOpfBranch) bra;
        // create branch admittance matrix
        bij = (aclfBra.getZ().getImaginary() > 0.00001) ? 1 / aclfBra.getZ().getImaginary() : DEFAULT_BIJ; // in case x=0;
        braAdmDiag.setEntry(braIndex, braIndex, bij);

        // create branch-bus connected or adjacent matrix;
        if (!((DclfOpfBus) bra.getFromBus()).isSwing()) {
            int fromBusIndex = bra.getFromBus().getSortNumber();
            fromBusIndex = (fromBusIndex < swingIndex) ? fromBusIndex : fromBusIndex - 1; // insure nonswing bus;
            braBusAdjacent.setEntry(braIndex, fromBusIndex, 1);
        }/*from w w w . ja va  2s  .  c o  m*/
        if (!((DclfOpfBus) bra.getToBus()).isSwing()) {
            int toBusIndex = bra.getToBus().getSortNumber();
            toBusIndex = (toBusIndex < swingIndex) ? toBusIndex : toBusIndex - 1;
            braBusAdjacent.setEntry(braIndex, toBusIndex, -1);
        }
        braIndex++;
        //}
    }

    int genIndex = 0;
    Array2DRowRealMatrix eyeGenP = new Array2DRowRealMatrix(numOfGen, numOfGen);
    for (Bus bus : opfNet.getBusList()) {
        if (opfNet.isOpfGenBus(bus)) {
            eyeGenP.setEntry(genIndex, genIndex, 1);
            genIndex++;
        }
    }
    Array2DRowRealMatrix DAr = braAdmDiag.multiply(braBusAdjacent);
    // Ciq'={Ot,-braAdmDiag*braBusAdjacent;
    //     -Ot,braAdmDiag*braBusAdjacent;
    //      eyeGenP,Op;
    //      -eyeGenP,-Op}

    Array2DRowRealMatrix CiqTranspose = new Array2DRowRealMatrix(numOfBranch * 2 + numOfGen * 2,
            numOfGen + numOfBus - 1);
    CiqTranspose.setSubMatrix(DAr.scalarMultiply(-1).getData(), 0, numOfGen);
    CiqTranspose.setSubMatrix(DAr.getData(), numOfBranch, numOfGen);
    CiqTranspose.setSubMatrix(eyeGenP.getData(), 2 * numOfBranch, 0);
    CiqTranspose.setSubMatrix(eyeGenP.scalarMultiply(-1).getData(), 2 * numOfBranch + numOfGen, 0);
    // Ciq=CiqTranspose'
    return (Array2DRowRealMatrix) CiqTranspose.transpose();
}