Package edu.ucla.sspace.matrix

Examples of edu.ucla.sspace.matrix.Matrix


            // pi*D-Inverse.
            DoubleVector v = new DenseVector(vectorLength);
            for (int i = 0; i < v.length(); ++i)
                v.set(i, Math.random());

            Matrix RinvData = (matrix instanceof SparseMatrix)
                ? new RowScaledSparseMatrix((SparseMatrix) matrix, Rinv)
                : new RowScaledMatrix(matrix, Rinv);

            // Make log(matrix.rows()) passes.
            int log = (int) Statistics.log2(vectorLength);
View Full Code Here


            workQueue.offer(new Runnable() {
                    public void run() {
                        try {
                        LOGGER.fine(String.format(
                            "processing term %6d/%d: %s", i, uniqueTerms,term));
                        Matrix contexts = getTermContexts(i, termFeatures[i]);
                        senseInduce(term, contexts);
                        } catch (IOException ioe) {
                            ioe.printStackTrace();
                        } finally {
                            termsProcessed.release();
View Full Code Here

        // Transform the vector according to this instance's transform's state,
        // which should normalize the vector as the original vectors were.
        DoubleVector transformed = transform.transform(docVec);

        // Represent the document as a 1-column matrix       
        Matrix queryAsMatrix = new ArrayMatrix(1, numDims);
        for (int nz : docVec.getNonZeroIndices())
            queryAsMatrix.set(0, nz, transformed.get(nz));
       
        // Project the new document vector, d, by using
        //
        //   d * U_k * Sigma_k^-1
        //
        // where k is the dimensionality of the LSA space
       
        Matrix UtimesSigmaInv = null;
           
        // We cache the reuslts of the U_k * Sigma_k^-1 multiplication since
        // this will be the same for all projections.
        while (UtimesSigmaInv == null) {
            if (UtimesSigmaInvRef != null
                    && ((UtimesSigmaInv = UtimesSigmaInvRef.get()) != null))
                break;
           
            int rows = sigma.rows();
            double[] sigmaInv = new double[rows];
            for (int i = 0; i < rows; ++i)
                sigmaInv[i] = 1d / sigma.get(i, i);
            DiagonalMatrix sigmaInvMatrix = new DiagonalMatrix(sigmaInv);

            UtimesSigmaInv =
                Matrices.multiply(U, sigmaInvMatrix);
            // Update the field with the new reference to the precomputed matrix
            UtimesSigmaInvRef = new WeakReference<Matrix>(UtimesSigmaInv);
        }

        // Compute the resulting projected vector as a matrix
        Matrix result = Matrices.multiply(queryAsMatrix, UtimesSigmaInv);

        // Copy out the vector itself so that we don't retain a reference to the
        // matrix as a result of its getRowVector call, which isn't guaranteed
        // to return a copy.
        int cols = result.columns();
        DoubleVector projected = new DenseVector(result.columns());
        for (int i = 0; i < cols; ++i)
            projected.set(i, result.get(0, i));
        return projected;
    }
View Full Code Here

        // Get a fresh new eigen cutter and compute the specral cut of the
        // matrix.
        EigenCut eigenCutter = cutterGenerator.generate();
        eigenCutter.computeCut(matrix);

        final Matrix leftMatrix = eigenCutter.getLeftCut();
        final Matrix rightMatrix = eigenCutter.getRightCut();

        verbose(String.format("Splitting into two matricies %d-%d",
                              leftMatrix.rows(), rightMatrix.rows()));

        // If the compute decided that the matrix should not be split, short
        // circuit any attempts to further cut the matrix.
        if (leftMatrix.rows() == matrix.rows() ||
            rightMatrix.rows() == matrix.rows())
            return new ClusterResult(new int[matrix.rows()], 1);


        // Do clustering on the left and right branches.  We can do this in
        // parallel because all of the data members in this class are thread
View Full Code Here

        // Get a fresh new eigen cutter and compute the specral cut of the
        // matrix.
        eigenCutter.computeCut(matrix);

        final Matrix leftMatrix = eigenCutter.getLeftCut();
        final Matrix rightMatrix = eigenCutter.getRightCut();

        // If the compute decided that the matrix should not be split, short
        // circuit any attempts to further cut the matrix.
        if (leftMatrix.rows() == matrix.rows() ||
            rightMatrix.rows() == matrix.rows()) {
            eigenCutter.computeRhoSum(matrix);
            LimitedResult result;
            if (useKMeans)
                result = new KMeansLimitedResult(new int[matrix.rows()], 1,
                        eigenCutter.getKMeansObjective());
            else
                // When computing the inter-cluster similarity for the full
                // matrix, this is simply rhowSum with out any self-similarity
                // scores.
                result = new SpectralLimitedResult(new int[matrix.rows()], 1,
                        eigenCutter.getMergedObjective(alpha, beta),
                        eigenCutter.rhoSum() - matrix.rows() / 2.0,
                        (matrix.rows() * (matrix.rows()-1)) / 2);
            return new LimitedResult[] {result};
        }

        verbose(String.format("Splitting into two matricies %d-%d",
                              leftMatrix.rows(), rightMatrix.rows()));

        // Do clustering on the left and right branches.  We can do this in
        // parallel because all of the data members in this class are thread
        // safe, since each call to fullCluster uses a new instance of a
        // EigenCutter which has all of the state for a particular partition.
View Full Code Here

                }
            }

            LoggerUtil.verbose(LOG, "reducing to %d dimensions", dimensions);

            Matrix termDocMatrix = MatrixIO.readMatrix(
                transformedMatrix.getFile(),
                transformedMatrix.getFormat(),
                Matrix.Type.SPARSE_IN_MEMORY, true);

            // Calculate the affinity matrix for the term-doc matrix
View Full Code Here

                                 ClusterLinkage linkage,
                                 SimType similarityFunction,
                                 int maxNumberOfClusters) {
        int rows = m.rows();
        LOGGER.info("Generating similarity matrix for " + rows+ " data points");
        Matrix similarityMatrix =
            computeSimilarityMatrix(m, similarityFunction);

        // Create the initial set of clusters where each row is originally in
        // its own cluster
        Map<Integer,Set<Integer>> clusterAssignment =
View Full Code Here

    public List<Merge> buildDendogram(
            Matrix m, ClusterLinkage linkage, SimType similarityFunction) {

        int rows = m.rows();
        LOGGER.finer("Generating similarity matrix for " + rows+ " data points");
        Matrix similarityMatrix =
            computeSimilarityMatrix(m, similarityFunction);
        return buildDendrogram(similarityMatrix, linkage);
    }
View Full Code Here

     * Computes and returns the similarity matrix for {@code m} using the
     * specified similarity function
     */
    private static Matrix computeSimilarityMatrix(Matrix m,
                                                  SimType similarityFunction) {
        Matrix similarityMatrix =
            Matrices.create(m.rows(), m.rows(), Matrix.Type.DENSE_ON_DISK);
        for (int i = 0; i < m.rows(); ++i) {
            for (int j = i + 1; j < m.rows(); ++j) {
                double similarity =
                    Similarity.getSimilarity(similarityFunction,
                                             m.getRowVector(i),
                                             m.getRowVector(j));
                similarityMatrix.set(i, j, similarity);
                similarityMatrix.set(j, i, similarity);
            }
        }
        return similarityMatrix;
    }
View Full Code Here

            // cluster.
            List<DoubleVector> originalCluster = clusters.get(largestIndex);
            List<DoubleVector> newCluster = clusters.get(k);

            // Split the largest cluster.
            Matrix clusterToSplit = Matrices.asMatrix(originalCluster);
            Assignment[] newAssignments =
                clustering.cluster(clusterToSplit, 2, props).assignments();

            // Clear the lists for cluster being split and the new cluster.
            // Also clear the number of assignments.
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.