Examples of SparseVector


Examples of com.googlecode.gaal.data.impl.SparseVector

            }
        }
    }

    public static <S> Vector toVector(Interval interval, Corpus<S> corpus) {
        Vector vector = new SparseVector();
        IntSequence indices = interval.indices();
        for (int i = 0; i < indices.size(); i++) {
            int start = indices.get(i);
            int documentId = corpus.getDocumentId(start);
            vector.add(documentId, 1);
        }
        return vector;
    }
View Full Code Here

Examples of com.googlecode.gaal.data.impl.SparseVector

        };
    }

    public static Vector toVector(Interval interval, Corpus<String> corpus) {
        Vector vector = new SparseVector();
        IntSequence indices = interval.indices();
        for (int i = 0; i < indices.size(); i++) {
            int start = indices.get(i);
            int documentId = corpus.getDocumentId(start);
            vector.add(documentId, 1);
        }
        return vector;
    }
View Full Code Here

Examples of cz.zcu.fav.liks.math.SparseVector

    tokenLabelCounts = new HashMap<Integer, HashMap<Integer, Integer>>();

    tfvl.reset();
    while (tfvl.hasNext()) {

      SparseVector vector = tfvl.next();
      int label = tfvl.getLabel(0);

      double[] values = vector.getNonZeroValues();
      int[] indicies = vector.getNonZeroIndeces();

      if (labelCounts.get(label) != null) {
        labelCounts.put(label, labelCounts.get(label) + 1);
      } else {
        labelCounts.put(label, 1);
View Full Code Here

Examples of dmt.tools.SparseVector

      if (no_instances == k) break;
    }
  }

  public TextInstance(Object[] bagOfWordsTfIdf, String id) {
    this.bagOfWordsTfIdf = new SparseVector(bagOfWordsTfIdf.length);
    for (int i = 0; i < bagOfWordsTfIdf.length; i++)
    {
      try
      {
        this.bagOfWordsTfIdf.put(i, Double
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

                // once to save cost.
                int length = sumVector.length();
                double d = 1d / indices.size();
                if (sumVector instanceof SparseVector) {
                    centroid = new SparseHashDoubleVector(length);
                    SparseVector sv = (SparseVector)sumVector;
                    for (int nz : sv.getNonZeroIndices())
                        centroid.set(nz, sumVector.get(nz) * d);
                }
                else {
                    centroid = new DenseVector(length);
                    for (int i = 0; i < length; ++i)
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

    public void setColumn(int column, DoubleVector values) {
        if (values.length() != rows)
            throw new IllegalArgumentException("cannot set a column " +
                "whose dimensions are different than the matrix");
        if (values instanceof SparseVector) {
            SparseVector sv = (SparseVector)values;
            for (int nz : sv.getNonZeroIndices())
                backingMatrix.set(getRealRow(nz), nz, values.get(nz));
        }
        else {
            for (int i = 0; i < rowToReal.length; ++i)
                backingMatrix.set(rowToReal[i], i, values.get(i));
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

        DoubleVector column = Vectors.asDouble(col);
        if (isFinished)
            throw new IllegalStateException(
                "Cannot add columns to a MatrixBuilder that is finished");
        if (column instanceof SparseVector) {
            SparseVector s = (SparseVector)column;
            for (int r : s.getNonZeroIndices()) {
                // NB: Matlab sparse format is in [row col val] format
                //
                // NOTE: Matlab indices start at 1, not 0, so update all the
                // column and column values to be Matlab formatted.
                addEntry(r + 1, curColumn + 1, column.get(r));
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

    public void setRow(int row, DoubleVector values) {
        if (values.length() != columns)
            throw new IllegalArgumentException("cannot set a row " +
                "whose dimensions are different than the matrix");
        if (values instanceof SparseVector) {
            SparseVector sv = (SparseVector)values;
            for (int nz : sv.getNonZeroIndices())
                backingMatrix.set(nz, getRealColumn(nz), values.get(nz));
        }
        else {
            for (int i = 0; i < columnToReal.length; ++i)
                backingMatrix.set(i, columnToReal[i], values.get(i));
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

        if (values.length() != cols)
            throw new IllegalArgumentException(
                "The number of values does not match the number of columns");

        if (values instanceof SparseVector) {
            SparseVector sv = (SparseVector)values;
            for (int i : sv.getNonZeroIndices())
                set(row, i, values.get(i));
        }
        else {
            for (int i = 0; i < values.length(); ++i)
                set(row, i, values.get(i));
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

        }

        // Check whether both vectors are sparse.  If so, use only the non-zero
        // indices to speed up the computation by avoiding zero multiplications
        else if (a instanceof SparseVector && b instanceof SparseVector) {
            SparseVector svA = (SparseVector)a;
            SparseVector svB = (SparseVector)b;
            int[] nzA = svA.getNonZeroIndices();
            int[] nzB = svB.getNonZeroIndices();

            // Choose the smaller of the two to use in computing the dot
            // product.  Because it would be more expensive to compute the
            // intersection of the two sets, we assume that any potential
            // misses would be less of a performance hit.
            if (a.length() < b.length() ||
                nzA.length < nzB.length) {
                DoubleVector t = a;
                a = b;
                b = t;
            }

            for (int nz : nzB) {
                double aValue = a.get(nz);
                double bValue = b.get(nz);
                dotProduct += aValue * bValue;
            }
        }

        // Check if the second vector is sparse.  If so, use only the non-zero
        // indices of b to speed up the computation by avoiding zero
        // multiplications.
        else if (b instanceof SparseVector) {
            SparseVector svB = (SparseVector)b;
            for (int nz : svB.getNonZeroIndices())
                dotProduct += b.get(nz) * a.get(nz);
        }

        // Check if the first vector is sparse.  If so, use only the non-zero
        // indices of a to speed up the computation by avoiding zero
        // multiplications.
        else if (a instanceof SparseVector) {
            SparseVector svA = (SparseVector)a;
            for (int nz : svA.getNonZeroIndices())
                dotProduct += b.get(nz) * a.get(nz);
        }

        // Otherwise, just assume both are dense and compute the full amount
        else {
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.