Package org.ar.redoexperiments.tools

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

TOP

Related Classes of org.ar.redoexperiments.tools.SparseVector

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.