Examples of SparseVector


Examples of edu.ucla.sspace.vector.SparseVector

        // Special case when both vectors are sparse vectors.
        if (a instanceof SparseVector &&
            b instanceof SparseVector) {
            // Convert both vectors to sparse vectors.
            SparseVector sa = (SparseVector) a;
            int[] aNonZeros = sa.getNonZeroIndices();

            SparseVector sb = (SparseVector) b;
            int[] bNonZeros = sb.getNonZeroIndices();

            // If b is the smaller vector swap it with a.  This allows the dot
            // product to work over the vector with the smallest number of non
            // zero values.
            if (bNonZeros.length < aNonZeros.length) {
                SparseVector temp = sa;
                int[] tempNonZeros = aNonZeros;
                sa = sb;
                aNonZeros = bNonZeros;
                sb = temp;
                bNonZeros = tempNonZeros;
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

        double divergence = 0;

        // Iterate over just the non zero values of a if it is a sparse vector.
        if (a instanceof SparseVector) {
            SparseVector sa = (SparseVector) a;
            int[] aNonZeros = sa.getNonZeroIndices();

            for (int index : aNonZeros) {
                double aValue = a.get(index);
                double bValue = b.get(index);
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

        double divergence = 0;

        // Iterate over just the non zero values of a if it is a sparse vector.
        if (a instanceof SparseVector) {
            SparseVector sa = (SparseVector) a;
            int[] aNonZeros = sa.getNonZeroIndices();

            for (int index : aNonZeros) {
                double aValue = a.get(index);
                double bValue = b.get(index);
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

        double divergence = 0;

        // Iterate over just the non zero values of a if it is a sparse vector.
        if (a instanceof SparseVector) {
            SparseVector sa = (SparseVector) a;
            int[] aNonZeros = sa.getNonZeroIndices();

            for (int index : aNonZeros) {
                double aValue = a.getValue(index).doubleValue();
                double bValue = b.getValue(index).doubleValue();
View Full Code Here

Examples of edu.ucla.sspace.vector.SparseVector

            " constructor).";

        // Special case for sparse Vectors, for which we already know the
        // non-zero indices for the column
        if (column instanceof SparseVector) {
            SparseVector s = (SparseVector)column;
            int[] nonZero = s.getNonZeroIndices();
            nonZeroValues += nonZero.length;
            System.out.println(nonZero.length);
            try {
                matrixDos.writeInt(nonZero.length);
                for (int i : nonZero) {
View Full Code Here

Examples of no.uib.cipr.matrix.sparse.SparseVector

  @Override
  public Vector getVector(String aTerm)
    throws SimilarityException
  {
    Vector vec1 = new SparseVector(getConceptCount());
    builder.buildVector(asList(aTerm), VectorAdapter.create(vec1));
    return vec1;
  }
View Full Code Here

Examples of org.apache.mahout.matrix.SparseVector

   * Compute the centroid by averaging the pointTotals
   *
   * @return a point which is the new centroid
   */
  public Vector computeCentroid() {
    Vector result = new SparseVector(pointTotal.cardinality());
    for (int i = 0; i < pointTotal.cardinality(); i++)
      result.set(i, pointTotal.get(i) / numPoints);
    return result;
  }
View Full Code Here

Examples of org.ar.redoexperiments.tools.SparseVector

    final int n = v.size();

//    System.out.println("Sunt " + n + " concepte.");

    // vectors to hold intermediate rank-score approximations
    I1 = new SparseVector(n);
    I2 = new SparseVector(n);

    // / The input to I1 is 1 on the first position, 0 for the rest
    // The final rank-scores should also sum to 1.
    I1.put(0, 1.0);

    /*
     * Constant matrix, holding on column j the credit fraction each
     * superConcept of concept j gets from j, namely 1 / Lj, where Lj is the
     * total number of superConcepts of j; this means that concept j splits
     * its score equally amongst all its superConcepts.
     */
    S = new SparseMatrix(n);

    // assign a temporary unique id to each concept, for the purpose of
    // handling matrix h with appropriate indices
    int index = 0;
    for (OWLClass concept : v) {
      conceptIndex.put(concept, index++);
    }
    assert (index == n);

    // // compute matrix S = H + A

    // Compute the ordered list of classes
    OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

    OWLOntology tbox = null;
    try {
      tbox = manager.loadOntology(tboxURI);

      // Compute the number of direct subclasses of each class
      for (OWLClass owlClass : v) {
        Set<OWLDescription> superClasses = owlClass
            .getSuperClasses(tbox);

        if (superClasses == null || superClasses.size() == 0) {

//          System.out.println("Concept with NO superClass");

          // add A, hence make the appropriate column equal to 1.0/n
          // for all rows;
          final int j = conceptIndex.get(owlClass);
          final double fraction = 1.0 / n;
          for (int i = 0; i < n; i++)
            S.put(i, j, fraction);

//          System.out.println("Conceptul " + owlClass.getURI()
//              + " nu are superclase.");
//          System.out.println("Ok.");
        } else {

//          System.out.println("Concept with superClass");
          final int j = conceptIndex.get(owlClass);

          // only give credit to superConcepts
          int superClassCount = 0;
          for (OWLDescription superClass : superClasses) {
            if (superClass instanceof OWLClass
                && conceptIndex.get(superClass) != null)
              superClassCount++;
          }

          if (superClassCount > 0) {

            final double fraction = 1.0 / superClassCount;

            for (OWLDescription superClass : superClasses) {
              if (superClass instanceof OWLClass
                  && conceptIndex.get(superClass) != null) {

                S.put(conceptIndex.get(superClass), j,fraction);
              }
            }
          } else {
//            System.out.println("No real superClass.");
            final double fraction = 1.0 / n;
            for (int i = 0; i < n; i++)
              S.put(i, j, fraction);

//            System.out.println("Conceptul " + owlClass.getURI()
//                + " nu are superclase.");
          }
//          System.out.println("Ok.");

        }
      }

      manager.removeOntology(tboxURI);
    } catch (OWLOntologyCreationException e) {
      e.printStackTrace();
    }

    // check property of having each column sum to exactly 1
//    double sum;
//    for (int j = 0; j < n; j++) {
//      sum = 0;
//      for (int i = 0; i < n; i++) {
//        sum += S.get(i, j);
//      }
//      System.out.println("Column " + j + " sums to " + sum);
//    }

//    System.out.println(S.toString());

   
   

//    printVector(I1);
//    sum = 0;
//    for (int i = 0; i < n; i++) {
//      sum += I1.get(i);
//    }
//    System.out.println("I1 sums to " + sum);

    I2 = S.times(I1).scale(ALPHA).plus(I1.scale((1.0 - ALPHA)));
//    printVector(I2);

//    sum = 0;
//    for (int i = 0; i < n; i++) {
//      sum += I2.get(i);
//    }
//    System.out.println("I2 sums to " + sum);

   
    while (!converged()) {
      I1 = new SparseVector(I2);

//      sum = 0;
//      for (int i = 0; i < n; i++) {
//        sum += I1.get(i);
//      }
View Full Code Here

Examples of org.data2semantics.proppred.learners.SparseVector

    // List<UTGraph<StringLabel,?>> graphs = copyGraphs(trainGraphs);
    List<UTGraph<StringLabel,Object>> graphs = copyGraphs(trainGraphs);

    SparseVector[] featureVectors = new SparseVector[graphs.size()];
    for (int i = 0; i < featureVectors.length; i++) {
      featureVectors[i] = new SparseVector();
   
    //double[][] featureVectors = new double[graphs.size()][];
    Map<String, String> labelDict = new HashMap<String,String>();

    int startLabel = 1;
View Full Code Here

Examples of org.fnlp.ml.types.sv.SparseVector

  private static final long serialVersionUID = -4740915822925015609L;

  @Override
  public void addThruPipe(Instance instance) {
    SparseVector data = (SparseVector) instance.getData();
    data.normalize();
  }
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.