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

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

Introduction

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

Prototype

public Array2DRowRealMatrix() 

Source Link

Document

Creates a matrix with no data

Usage

From source file:edu.cmu.tetrad.util.ApacheTetradMatrix.java

private ApacheTetradMatrix(double[][] apacheData) {
    if (apacheData.length == 0) {
        this.apacheData = new Array2DRowRealMatrix();
    } else {/*w  w w . j a  va 2 s.co  m*/
        this.apacheData = new BlockRealMatrix(apacheData);
    }
}

From source file:edu.cmu.tetrad.util.TetradMatrix.java

public TetradMatrix(double[][] data) {
    if (data.length == 0) {
        this.apacheData = new Array2DRowRealMatrix();
    } else {/*from   w  ww .j av  a  2s  .c o m*/
        //            this.apacheData = new OpenMapRealMatrix(data.length, data[0].length);
        //
        //            for (int i = 0; i < data.length; i++) {
        //                for (int j = 0; j < data[0].length; j++) {
        //                    apacheData.setEntry(i, j, data[i][j]);
        //                }
        //            }
        this.apacheData = new BlockRealMatrix(data);
    }

    this.m = data.length;
    this.n = m == 0 ? 0 : data[0].length;
}

From source file:edu.cmu.tetrad.util.ApacheTetradMatrix.java

private ApacheTetradMatrix(int m, int n) {
    if (m == 0) {
        this.apacheData = new Array2DRowRealMatrix();
    } else {/*from  w w w.  j  a  va 2s .c om*/
        this.apacheData = new BlockRealMatrix(m, n);
    }
}

From source file:edu.cmu.tetrad.util.TetradMatrix1.java

public TetradMatrix1(double[][] data) {
    if (data.length == 0) {
        this.apacheData = new Array2DRowRealMatrix();
    } else {/*from   w  w w  . ja  v  a 2 s  .  c o m*/
        //            this.apacheData = new OpenMapRealMatrix(data.length, data[0].length);
        //
        //            for (int i = 0; i < data.length; i++) {
        //                for (int j = 0; j < data[0].length; j++) {
        //                    apacheData.setEntry(i, j, data[i][j]);
        //                }
        //            }
        this.apacheData = new BlockRealMatrix(data);
    }

    this.m = data.length;
    this.n = m == 0 ? 0 : data[0].length;
}

From source file:edu.stanford.cfuller.imageanalysistools.clustering.GaussianLikelihoodObjectiveFunction.java

/**
 * Constructs a new GaussianLikelihoodObjectiveFunction that will determine the likelihood of having observed the
 * supplied ClusterObjects at their locations.
 *
 * @param objects   A Vector containing the observed ClusterObjects (with locations already determined and assigned).
 *///from   ww w  .ja v a 2 s  .  co m
public GaussianLikelihoodObjectiveFunction(java.util.Vector<ClusterObject> objects) {
    mean = new ArrayRealVector(numDim);
    x = new ArrayRealVector(numDim);
    pk = new ArrayRealVector();
    clusterProbs = new Array2DRowRealMatrix();
    abdMatrices = new java.util.Vector<RealMatrix>();
    det = new ArrayRealVector();
    this.objects = objects;

}

From source file:edu.cmu.tetrad.util.TetradMatrix.java

public TetradMatrix(int m, int n) {
    if (m == 0 || n == 0) {
        this.apacheData = new Array2DRowRealMatrix();
    } else {// ww w. jav  a  2 s  .  c o  m
        //            this.apacheData = new OpenMapRealMatrix(m, n);
        this.apacheData = new BlockRealMatrix(m, n);
    }

    this.m = m;
    this.n = n;
}

From source file:edu.cmu.tetrad.util.TetradMatrix1.java

public TetradMatrix1(int m, int n) {
    if (m == 0 || n == 0) {
        this.apacheData = new Array2DRowRealMatrix();
    } else {/*ww w.j  av a2 s  .  c  o  m*/
        //            this.apacheData = new OpenMapRealMatrix(m, n);
        this.apacheData = new BlockRealMatrix(m, n);
    }

    this.m = m;
    this.n = n;
}

From source file:com.bolatu.gezkoncsvlogger.GyroOrientation.RotationKalmanFilter.java

/**
 * Creates a new Kalman filter with the given process and measurement
 * models.//from w ww  . j av a  2  s.  com
 *
 * @param process
 *            the model defining the underlying process dynamics
 * @param measurement
 *            the model defining the given measurement characteristics
 * @throws NullArgumentException
 *             if any of the given inputs is null (except for the control
 *             matrix)
 * @throws NonSquareMatrixException
 *             if the transition matrix is non square
 * @throws DimensionMismatchException
 *             if the column dimension of the transition matrix does not
 *             match the dimension of the initial state estimation vector
 * @throws MatrixDimensionMismatchException
 *             if the matrix dimensions do not fit together
 */
public RotationKalmanFilter(final ProcessModel process, final MeasurementModel measurement)
        throws NullArgumentException, NonSquareMatrixException, DimensionMismatchException,
        MatrixDimensionMismatchException {

    MathUtils.checkNotNull(process);
    MathUtils.checkNotNull(measurement);

    this.processModel = process;
    this.measurementModel = measurement;

    transitionMatrix = processModel.getStateTransitionMatrix();
    MathUtils.checkNotNull(transitionMatrix);
    transitionMatrixT = transitionMatrix.transpose();

    // create an empty matrix if no control matrix was given
    if (processModel.getControlMatrix() == null) {
        controlMatrix = new Array2DRowRealMatrix();
    } else {
        controlMatrix = processModel.getControlMatrix();
    }

    measurementMatrix = measurementModel.getMeasurementMatrix();
    MathUtils.checkNotNull(measurementMatrix);
    measurementMatrixT = measurementMatrix.transpose();

    // check that the process and measurement noise matrices are not null
    // they will be directly accessed from the model as they may change
    // over time
    RealMatrix processNoise = processModel.getProcessNoise();
    MathUtils.checkNotNull(processNoise);
    RealMatrix measNoise = measurementModel.getMeasurementNoise();
    MathUtils.checkNotNull(measNoise);

    // set the initial state estimate to a zero vector if it is not
    // available from the process model
    if (processModel.getInitialStateEstimate() == null) {
        stateEstimation = new ArrayRealVector(transitionMatrix.getColumnDimension());
    } else {
        stateEstimation = processModel.getInitialStateEstimate();
    }

    if (transitionMatrix.getColumnDimension() != stateEstimation.getDimension()) {
        throw new DimensionMismatchException(transitionMatrix.getColumnDimension(),
                stateEstimation.getDimension());
    }

    // initialize the error covariance to the process noise if it is not
    // available from the process model
    if (processModel.getInitialErrorCovariance() == null) {
        errorCovariance = processNoise.copy();
    } else {
        errorCovariance = processModel.getInitialErrorCovariance();
    }

    // sanity checks, the control matrix B may be null

    // A must be a square matrix
    if (!transitionMatrix.isSquare()) {
        throw new NonSquareMatrixException(transitionMatrix.getRowDimension(),
                transitionMatrix.getColumnDimension());
    }

    // row dimension of B must be equal to A
    // if no control matrix is available, the row and column dimension will
    // be 0
    if (controlMatrix != null && controlMatrix.getRowDimension() > 0 && controlMatrix.getColumnDimension() > 0
            && controlMatrix.getRowDimension() != transitionMatrix.getRowDimension()) {
        throw new MatrixDimensionMismatchException(controlMatrix.getRowDimension(),
                controlMatrix.getColumnDimension(), transitionMatrix.getRowDimension(),
                controlMatrix.getColumnDimension());
    }

    // Q must be equal to A
    MatrixUtils.checkAdditionCompatible(transitionMatrix, processNoise);

    // column dimension of H must be equal to row dimension of A
    if (measurementMatrix.getColumnDimension() != transitionMatrix.getRowDimension()) {
        throw new MatrixDimensionMismatchException(measurementMatrix.getRowDimension(),
                measurementMatrix.getColumnDimension(), measurementMatrix.getRowDimension(),
                transitionMatrix.getRowDimension());
    }

    // row dimension of R must be equal to row dimension of H
    if (measNoise.getRowDimension() != measurementMatrix.getRowDimension()) {
        throw new MatrixDimensionMismatchException(measNoise.getRowDimension(), measNoise.getColumnDimension(),
                measurementMatrix.getRowDimension(), measNoise.getColumnDimension());
    }
}

From source file:edu.cmu.tetrad.util.ApacheTetradMatrix.java

/**
 * Adds semantic checks to the default deserialization method. This method
 * must have the standard signature for a readObject method, and the body of
 * the method must begin with "s.defaultReadObject();". Other than that, any
 * semantic checks can be specified and do not need to stay the same from
 * version to version. A readObject method of this form may be added to any
 * class, even if Tetrad sessions were previously saved out using a version
 * of the class that didn't include it. (That's what the
 * "s.defaultReadObject();" is for. See J. Bloch, Effective Java, for help.
 *
 * @throws java.io.IOException/*from w  w w. ja va  2s  . co  m*/
 * @throws ClassNotFoundException
 */
private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
    s.defaultReadObject();

    if (this.data != null) {
        double[][] d = data.toArray();

        if (d.length == 0) {
            this.apacheData = new Array2DRowRealMatrix();
        } else {
            this.apacheData = new BlockRealMatrix(d);
        }

        this.data = null;
    }
}

From source file:i5.las2peer.services.servicePackage.TemplateService.java

@GET
@Path("/graphs/termmatrix")
@Produces(MediaType.APPLICATION_JSON)//from  w w  w.java2 s .c  om
public HttpResponse getTermMatrix() {
    Connection conn = null;
    PreparedStatement stmnt = null;
    ResultSet rs = null;
    JSONArray json = new JSONArray();
    EntityManagement em = new EntityManagement();
    WordConverter wordConv = new WordConverter();
    Array2DRowRealMatrix matrix = new Array2DRowRealMatrix();
    ToJSON converter = new ToJSON();
    Algorithms alg = new Algorithms();

    try {
        // get connection from connection pool
        conn = dbm.getConnection();

        // prepare statement
        stmnt = conn.prepareStatement("SELECT id,content,author FROM urch order by author;");

        // retrieve result set
        rs = stmnt.executeQuery();

        //LinkedList<Node> nodes = em.listNodes(rs);   // listing nodes and textpreprocessing of content
        em.createNodeTable(conn);
        em.createGraphTable(conn);

        //persist graph built form dataset
        Graph graph = em.persistNewGraph(rs, conn);

        Termmatrix termMat = wordConv.convertTFIDF(graph.getNodes());
        //matrix = wordConv.convertTFIDF(nodes);      // creating term matrix, computing tf- idf, converting to json array for visualization   

        Clustering clust = alg.optCosts(termMat, 2);
        em.createCommunityTables(conn);
        em.createCoverTable(conn);
        em.persistCover(clust, conn);
        //json = converter.termmatrixToJson(termMat);
        //json = converter.termmatrixToJson(matrix);
        return new HttpResponse("New Cover created from dataset urch and persisted", HttpURLConnection.HTTP_OK);

    } catch (Exception e) {

        return new HttpResponse("Internal error: " + e.getMessage(), HttpURLConnection.HTTP_INTERNAL_ERROR);

    } finally {
        // free resources if exception or not
        if (rs != null) {
            try {
                rs.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
        if (stmnt != null) {
            try {
                stmnt.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
        if (conn != null) {
            try {
                conn.close();
            } catch (Exception e) {
                Context.logError(this, e.getMessage());

                // return HTTP Response on error
                return new HttpResponse("Internal error: " + e.getMessage(),
                        HttpURLConnection.HTTP_INTERNAL_ERROR);
            }
        }
    }
}