Package edu.ucla.sspace.matrix

Examples of edu.ucla.sspace.matrix.Matrix


                    for (CandidateCluster fac : facilities) {
                        facilityCentroids.add(fac.centerOfMass());
                        weights[i++] = fac.size();
                    }
                    // Wrap the facilities centroids in a matrix for convenience
                    Matrix m = Matrices.asMatrix(facilityCentroids);

                    // Select the initial seed points for reducing the kappa
                    // clusters to k using the generalized ORSS selection
                    // process, which supports data comparisons other than
                    // Euclidean distance
View Full Code Here


        }

        final int numEdges = edgeList.size();
        LOGGER.fine("Number of edges to cluster: " + numEdges);
       
        Matrix edgeSimMatrix =
            getEdgeSimMatrix(edgeList, sm, keepSimMatrixInMem);
       
        LOGGER.fine("Computing single linkage link clustering");

        final List<Merge> mergeOrder =
View Full Code Here

     */
    private Matrix calculateEdgeSimMatrix(
            final List<Edge> edgeList, final SparseMatrix sm) {

        final int numEdges = edgeList.size();
        final Matrix edgeSimMatrix =
            new SparseSymmetricMatrix(
                new SparseHashMatrix(numEdges, numEdges));

        Object key = workQueue.registerTaskGroup(numEdges);
        for (int i = 0; i < numEdges; ++i) {
            final int row = i;
            workQueue.add(key, new Runnable() {
                    public void run() {
                        for (int j = row; j < numEdges; ++j) {
                            Edge e1 = edgeList.get(row);
                            Edge e2 = edgeList.get(j);
                           
                            double sim = getEdgeSimilarity(sm, e1, e2);
               
                            if (sim > 0) {
                                // The symmetric matrix handles the (j,i) case
                                edgeSimMatrix.set(row, j, sim);
                            }
                        }
                    }
                });           
        }
View Full Code Here

        }

        // Create the sorted matrix based on the reordering.  Note that both row
        // masked matrices internally handle masking a masked matrix to avoid
        // recursive calls to the index lookups.
        Matrix sortedMatrix;
        if (matrix instanceof SparseMatrix)
            sortedMatrix = new SparseRowMaskedMatrix(
                    (SparseMatrix) matrix, reordering);
        else
            sortedMatrix = new RowMaskedMatrix(matrix, reordering);
View Full Code Here

     *
     * @return the sparse Matrix.
     **/
    public Matrix createSparseMatrix() {

        Matrix m = Matrices.create(matrix_row_map.size(), matrix_column_map.size(), false);
        for (int row_num = 0; row_num < matrix_row_map.size(); row_num++) { // for each pattern
            String p = matrix_row_map.get(new Integer(row_num));
            String[] p_sp = p.split(":");
            String a = p_sp[0];
            String b = p_sp[1];
            for (int col_num = 0; col_num < matrix_column_map.size(); col_num++) { // for each phrase
                InterveningWordsPattern col_pattern = matrix_column_map.get(new Integer(col_num));
                String pattern = col_pattern.getPattern();
                String comb_patterns;
                if (col_pattern.getReverse()) { //if the column is a reverse pattern...word2 P word1
                    comb_patterns = ".*\\s" + b + pattern + a + "\\s.*";
                } else {
                    comb_patterns = ".*\\s" + a + pattern + b + "\\s.*";
                }
                try {
                    m.set(row_num, col_num, (double)countWildcardPhraseFrequencies(new File(DATA_DIR), comb_patterns));
                } catch (Exception e) {
                    System.err.println("could not perform wildcard search");
                }
            }
        }
View Full Code Here

                    SVD.getFastestAvailableFactorization());

            //Steps 1-2. Load analogy input
            lra.loadAnalogiesFromFile(analogyFile);

            Matrix projection;

            // if we load a projection matrix from file, we can skip all the
            // preprocessing
            String readProjectionFile = props.getProperty(
                    LatentRelationalAnalysis.LRA_READ_MATRIX_FILE);
            if (readProjectionFile != null) {
                File readFile = new File(readProjectionFile);
                if (readFile.exists()) {
                    projection =
                        MatrixIO.readMatrix(new File(readProjectionFile),
                                            MatrixIO.Format.SVDLIBC_SPARSE_TEXT,
                                            Matrix.Type.SPARSE_IN_MEMORY);
                } else {
                    throw new IllegalArgumentException(
                        "specified projection file does not exist");
                }
            } else { //do normal LRA preprocessing...


                //Step 3. Get patterns Step 4. Filter top NUM_PATTERNS
                lra.findPatterns();

                //Step 5. Map phrases to rows
                lra.mapRows();
                //Step 6. Map patterns to columns
                lra.mapColumns();

                //Step 7. Create sparse matrix
                Matrix sparse_matrix = lra.createSparseMatrix();

                //Step 8. Calculate entropy
                sparse_matrix = lra.applyEntropyTransformations(sparse_matrix);

                //Step 9. Compute SVD on the pre-processed matrix.
View Full Code Here

            {7, 8, 5, 0},
            {3, 8, 0, 0},
            {7, 2, 9, 2},
        };

        Matrix matrix = new ArrayMatrix(values);
        Assignment[] as = new Assignment[] {
            new HardAssignment(0),
            new HardAssignment(0),
            new HardAssignment(1),
            new HardAssignment(1),
View Full Code Here

            {7, 8, 5, 0},
            {3, 8, 0, 0},
            {7, 2, 9, 2},
        };

        Matrix matrix = new ArrayMatrix(values);
        Assignment[] as = new Assignment[] {
            new HardAssignment(0),
            new HardAssignment(0),
            new HardAssignment(1),
            new HardAssignment(1),
View Full Code Here

            {7, 8, 5, 0},
            {3, 8, 0, 0},
            {7, 2, 9, 2},
        };

        Matrix matrix = new ArrayMatrix(values);
        Assignment[] as = new Assignment[] {
            new HardAssignment(0),
            new HardAssignment(0),
            new HardAssignment(1),
            new HardAssignment(1),
View Full Code Here

        reducer.factorize(matrix, 2);
        validateResults(reducer);
    }

    public static void validateResults(MatrixFactorization reducer) {
        Matrix U = reducer.dataClasses();
        assertEquals(matrix.rows(), U.rows());
        assertEquals(2, U.columns());

        for (int r = 0; r < matrix.rows(); ++r)
            for (int c = 0; c < 2; ++c)
                assertEquals(Math.abs(EXPECTED_U[r][c] * EXPECTED_S[c]),Math.abs(U.get(r,c)),.001);

        Matrix V = reducer.classFeatures();
        assertEquals(2, V.rows());
        assertEquals(matrix.columns(), V.columns());

        for (int r = 0; r < 2; ++r)
            for (int c = 0; c < matrix.columns(); ++c)
                assertEquals(Math.abs(EXPECTED_V[r][c] * EXPECTED_S[r]),Math.abs(V.get(r,c)),.001);
    }
View Full Code Here

TOP

Related Classes of edu.ucla.sspace.matrix.Matrix

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.