Examples of SparseDoubleVector


Examples of de.jungblut.math.sparse.SparseDoubleVector

  }

  @Override
  public DoubleVector predict(DoubleVector features) {
    if (features.isSparse()) {
      SparseDoubleVector tmp = new SparseDoubleVector(
          features.getDimension() + 1);
      tmp.set(0, 1d);
      Iterator<DoubleVectorElement> iterateNonZero = features.iterateNonZero();
      while (iterateNonZero.hasNext()) {
        DoubleVectorElement next = iterateNonZero.next();
        tmp.set(next.getIndex() + 1, next.getValue());
      }
      features = tmp;
    } else {
      features = new DenseDoubleVector(1d, features.toArray());
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

            lockRow(row, c);
        // Ensure that the column data is up to date
        while (lastVectorCacheUpdate.get() != modifications.get())
            updateVectorCache();
        int[] colArr = rowToColsCache[row];
        SparseDoubleVector rowVec = new SparseHashDoubleVector(c);
        for (int column : colArr)
            rowVec.set(column, matrixEntries.get(new Entry(row, column)));
        if (shouldLock)
            unlockRow(row, c);
        return rowVec;
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

            if (tokens.length < 10)
                return;

            // Compute the vector length and create the context vector.
            vectorLength = (tokens.length - 1) / 2;
            SparseDoubleVector vector = new CompactSparseVector(
                  (tokens.length - 1) / 2);

            // Read each feature index and value.
            for (int i = 1; i < tokens.length; i+=2) {
                int index = Integer.parseInt(tokens[i]);
                double value = Double.parseDouble(tokens[i+1]);
                vector.set(index, value);
            }

            wordsi.handleContextVector(termSplit[0], tokens[0], vector);
        } catch (IOException ioe) {
            throw new IOError(ioe);
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

       
        // Reject any words not accepted by wordsi.
        if (!wordsi.acceptWord(headerRest[0]))
            return;

        SparseDoubleVector context = new CompactSparseVector();

        // Iterate through each feature and convert it to a dimension for the
        // context vector.
        for (String item : headerRest[1].split("\\|")) {
            String[] featureScore = item.split(",", 2);
            double score = Double.parseDouble(featureScore[0]);
            int dimension = basis.getDimension(featureScore[1]);
            if (dimension >= 0)
                context.set(dimension, score);
        }
        wordsi.handleContextVector(headerRest[0], headerRest[0], context);
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

            this.rows = rows;
            // Compute the centroid
            centroid = new CompactSparseVector(sm.columns());
            double simSum = 0d;
            for (int r : rows) {
                SparseDoubleVector row = sm.getRowVector(r);
                VectorMath.add(centroid, row);

                for (int r2 : rows) {
                    if (r == r2)
                        continue;
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

            centroids[c] = new DenseDynamicMagnitudeVector(
                    centroids[c].toArray());

        subSetup(m);

        SparseDoubleVector empty = new CompactSparseVector(m.columns());
        for (int c = 0; c < numClusters; ++c)
            if (clusterSizes[c] != 0)
                costs[c] = getOldCentroidScore(empty, c, clusterSizes[c]);
    }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

        // Special case sparse double vectors so that we don't incure a possibly
        // log n get operation for each zero value, as that's the common case
        // for CompactSparseVector.
        if (v instanceof SparseDoubleVector) {
            SparseDoubleVector sv = (SparseDoubleVector) v;
            int[] nonZeros = sv.getNonZeroIndices();
            int sparseIndex = 0;
            for (int i = 0; i < c.length(); ++i) {
                double value = c.get(i);
                if (sparseIndex < nonZeros.length &&
                    i == nonZeros[sparseIndex])
                    value -= sv.get(nonZeros[sparseIndex++]);

                newCentroid.set(i, value);
            }
        } else
            for (int i = 0; i < c.length(); ++i)
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

        else if (reduced == null) {
            // NOTE: the matrix could be asymmetric if the a word has only
            // appeared on one side of a context (its row or column vector would
            // never have been set).  Therefore, check the index with the matrix
            // size first.
            SparseDoubleVector rowVec = (index < cooccurrenceMatrix.rows())
                ? cooccurrenceMatrix.getRowVectorUnsafe(index)
                : new CompactSparseVector(termToIndex.numDimensions());
            SparseDoubleVector colVec = (index < cooccurrenceMatrix.columns())
                ? cooccurrenceMatrix.getColumnVectorUnsafe(index)
                : new CompactSparseVector(termToIndex.numDimensions());

            return new ConcatenatedSparseDoubleVector(rowVec, colVec);
        }
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

     * then throw away all but one of them.
     */
    protected static double modifiedMagnitudeSqrd(DoubleVector c,
                                                  DoubleVector v) {
        if (v instanceof SparseDoubleVector) {
            SparseDoubleVector sv = (SparseDoubleVector) v;
            int[] nonZeros = sv.getNonZeroIndices();

            double magnitude = Math.pow(c.magnitude(), 2);
            for (int i : nonZeros) {
                double value = c.get(i);
                magnitude -= Math.pow(value, 2);
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseDoubleVector

        SparseMatrix reduced = new YaleSparseMatrix(
                words, indicesToKeep.size());

        // Iterate over the sparse values in the matrix for added efficiency.
        for (int row = 0; row < words; ++ row) {
            SparseDoubleVector sv = cooccurrenceMatrix.getRowVector(row);
            for (int col : sv.getNonZeroIndices()) {
                double v = cooccurrenceMatrix.get(row, col);

                // If the original column was retained, get it's new index
                // value and add it to the reduced matrix.
                Integer newColIndex = indexMap.get(col);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.