Examples of TObjectDoubleHashMap


Examples of gnu.trove.TObjectDoubleHashMap

   
    if (label != null && !label.equals(Constants.GetDummyLabel())) {
        SetGoldLabel(label, weight);
    }
   
    this.neighbors_ = new TObjectDoubleHashMap();
    this.isSeedNode_ = false;
    this.isTestNode_ = false;
    this.features_ = new RyanFeatureVector(-1, -1, null);

    // initialize the estimated labels with dummy label
View Full Code Here

Examples of gnu.trove.TObjectDoubleHashMap

    // TODO(partha): temporarily commented for working with WebKB data
    // on 03/26/2009. need to decide whether to make it permanent.
    //    if (!isTransitionNormalized) {
    //      NormalizeTransitionProbability();
    //    }
    TObjectDoubleHashMap neighborClone = this.neighbors_.clone();
    Normalize(neighborClone);
   
    double ent = GetNeighborhoodEntropy(neighborClone);
    double cv = Math.log(beta) / Math.log(beta + ent);
   
View Full Code Here

Examples of gnu.trove.TObjectDoubleHashMap

  }

  public static TObjectDoubleHashMap String2Map(TObjectDoubleHashMap retMap,
                                                String inp) {
    if (retMap == null) {
      retMap = new TObjectDoubleHashMap();
    }

    if (inp.length() > 0) {
      String[] fields = inp.split(" ");
      for (int i = 0; i < fields.length; i += 2) {
View Full Code Here

Examples of gnu.trove.TObjectDoubleHashMap

    res.table = inp.table.clone();   
    return res;
  }
 
  public TObjectDoubleHashMap getLabelScores(CountMinSketchLabel labelScores) {
    TObjectDoubleHashMap ret = new TObjectDoubleHashMap();
   
    if (labelScores != null) {
      Iterator labIter = la.iterator();
      while (labIter.hasNext()) {
        String lab = (String) labIter.next();

        float score = getScore(labelScores, getLabelHash(lab));
        if (score > 0) {
          ret.put(lab, score);
        }
      }
    }
    return (ret);
  }
View Full Code Here

Examples of gnu.trove.TObjectDoubleHashMap

    Iterator<String> vIter = _vertices.keySet().iterator();
    while (vIter.hasNext()) {
      Vertex2 v = _vertices.get(vIter.next());
     
      Object[] neighNames = v.GetNeighborNames();
      TObjectDoubleHashMap neighWeights = new TObjectDoubleHashMap();
      int totalNeighbors = neighNames.length;
      for (int ni = 0; ni < totalNeighbors; ++ni) {
        neighWeights.put(neighNames[ni], v.GetNeighborWeight((String) neighNames[ni]));
      }
      // now sort the neighbors
      ArrayList<ObjectDoublePair> sortedNeighList = CollectionUtil2.ReverseSortMap(neighWeights);
     
      // Since the array is reverse sorted, the highest scoring
View Full Code Here

Examples of gnu.trove.TObjectDoubleHashMap

  //
  // CPN is different from Class Mass Normalization (CMN) as CMN is used post
  // classification, while CPN is used before the classification process is
  // started.
  public void ClassPriorNormalization() {
    TObjectDoubleHashMap labels = new TObjectDoubleHashMap();
   
    // compute class weight sum
    TObjectDoubleHashMap classSeedSum = new TObjectDoubleHashMap();
    Iterator<String> viter0 = this._vertices.keySet().iterator();
    while (viter0.hasNext()) {
      String vName = viter0.next();
      Vertex2 v = _vertices.get(vName);
      if (v.IsSeedNode()) {
        TObjectDoubleIterator injLabIter =
            this._labelManager.getLabelScores(v.GetInjectedLabelScores()).iterator();
        while (injLabIter.hasNext()) {
          injLabIter.advance();
          double currVal = classSeedSum.containsKey(injLabIter.key()) ?
            classSeedSum.get(injLabIter.key()) : 0;
          classSeedSum.put(injLabIter.key(), currVal + injLabIter.value());
         
          // add the label to the list of labels
          if (!labels.containsKey(injLabIter.key())) {
            labels.put(injLabIter.key(), 1.0);
          }
        }
      }
    }
   
    double[] seedWeightSums = classSeedSum.getValues();
    double maxSum = -1;
    for (int wsi = 0; wsi < seedWeightSums.length; ++wsi) {
      if (seedWeightSums[wsi] > maxSum) {
        maxSum = seedWeightSums[wsi];
      }
    }
   
    TObjectDoubleHashMap seedAmpliFactor = new TObjectDoubleHashMap();
    TObjectDoubleIterator wIter = classSeedSum.iterator();
    while (wIter.hasNext()) {
      wIter.advance();
      seedAmpliFactor.put(wIter.key(), maxSum / wIter.value());
      System.out.println("Label: " + wIter.key() +
                         " ampli_factor: " + seedAmpliFactor.get(wIter.key()));
    }
   
    // now multiply injected scores with amplification factors
    Iterator<String> viter = this._vertices.keySet().iterator();
    while (viter.hasNext()) {
      String vName = viter.next();
      Vertex2 v = _vertices.get(vName);
      if (v.IsSeedNode()) {       
        TObjectDoubleIterator injLabIter =
            this._labelManager.getLabelScores(v.GetInjectedLabelScores()).iterator();
        while (injLabIter.hasNext()) {
          injLabIter.advance();
         
          double currVal = injLabIter.value();
          injLabIter.setValue(currVal * seedAmpliFactor.get(injLabIter.key()));
        }
      }
    }
  }
View Full Code Here

Examples of gnu.trove.TObjectDoubleHashMap

      newDist.clear();
     
      int totalNodes = g._vertices.size();
//      double deltaLabelDiffPerNode = (1.0 * deltaLabelDiff) / totalNodes;

      TObjectDoubleHashMap res = new TObjectDoubleHashMap();
      res.put(Constants.GetMRRString(), Graph2.GetAverageTestMRR(g));
      res.put(Constants.GetPrecisionString(), Graph2.GetAccuracy(g));
      resultList.add(res);
//      if (verbose) {
//        System.out.println("after_iteration " + iter +
//                           " objective: " + GetObjective(g, mu1, mu2, mu3) +
//                           " accuracy: " + res.get(Constants.GetPrecisionString()) +
//                           " rmse: " + GraphEval.GetRMSE(g) +
//                           " time: " + (endTime - startTime) +
//                           " label_diff_per_node: " + deltaLabelDiffPerNode +
//                           " mrr_train: " + GraphEval.GetAverageTrainMRR(g) +
//                           " mrr_test: " + res.get(Constants.GetMRRString()) +
//                           " column_updates: " + totalColumnUpdates +
//                           " entity_updates: " + totalEntityUpdates + "\n");
//      }
     
//      if (false && deltaLabelDiffPerNode <= Constants.GetStoppingThreshold()) {
//        if (useBipartitieOptimization) {
//          if (iter > 1 && iter % 2 == 1) {
//            MessagePrinter.Print("Convergence reached!!");
//            break;
//          }
//        } else {
//          MessagePrinter.Print("Convergence reached!!");
//          break;
//        }
//      }
    }
   
    if (resultList.size() > 0) {
      TObjectDoubleHashMap res =
        (TObjectDoubleHashMap) resultList.get(resultList.size() - 1);
      MessagePrinter.Print(Constants.GetPrecisionString() + " " +
                           res.get(Constants.GetPrecisionString()));
      MessagePrinter.Print(Constants.GetMRRString() + " " +
                           res.get(Constants.GetMRRString()));
    }
  }
View Full Code Here

Examples of gnu.trove.map.hash.TObjectDoubleHashMap

       /////
       String line = value.toString();
       // id gold_label injected_labels estimated_labels neighbors rw_probabilities
       String[] fields = line.split(_kDelim);      
       TObjectDoubleHashMap neighbors = CollectionUtil.String2Map(fields[4]);
             
       boolean isSeedNode = fields[2].length() > 0 ? true : false;
      
       // If the current node is a seed node but there is no
       // estimate label information yet, then transfer the seed label
       // to the estimated label distribution. Ideally, this is likely
       // to be used in the map of the very first iteration.
       if (isSeedNode && fields[3].length() == 0) {
         fields[3] = fields[2];
       }

       // Send two types of messages:
       //   -- self messages which will store the injection labels and
       //        random walk probabilities.
       //   -- messages to neighbors about current estimated scores
       //        of the node.
       //
       // message to self
       output.collect(new Text(fields[0]), new Text(line));

       // message to neighbors
       TObjectDoubleIterator neighIterator = neighbors.iterator();
       while (neighIterator.hasNext()) {
         neighIterator.advance();
        
         // message (neighbor_node, current_node + DELIM + curr_node_label_scores
         output.collect(new Text((String) neighIterator.key()),
View Full Code Here

Examples of gnu.trove.map.hash.TObjectDoubleHashMap

 
  public static void Split(Graph g, double trainFract) {   
    Random r = new Random(_kDeterministicSeed);
    // Random r = new Random();
   
    TObjectDoubleHashMap instanceVertices = new TObjectDoubleHashMap();
    Iterator vIter = g.vertices().keySet().iterator();
    while (vIter.hasNext()) {
      Vertex v = g.vertices().get(vIter.next());
     
      // nodes without feature prefix and those with at least one
      // gold labels are considered valid instances
      if (!v.name().startsWith(Constants.GetFeatPrefix()) &&
          v.goldLabels().size() > 0) {
        instanceVertices.put(v, r.nextDouble());
      }
    }
   
    ArrayList<ObjectDoublePair> sortedRandomInstances =
      CollectionUtil.ReverseSortMap(instanceVertices);
View Full Code Here

Examples of gnu.trove.map.hash.TObjectDoubleHashMap

   }
  
     public void reduce(Text key, Iterator<Text> values,
               OutputCollector<Text, Text> output, Reporter reporter) throws IOException {      
       // new scores estimated for the current node
       TObjectDoubleHashMap newEstimatedScores = new TObjectDoubleHashMap();
      
       // set to true only if the message sent to itself is found.
       boolean isSelfMessageFound = false;
      
       String vertexId = key.toString();
       String vertexString = "";
      
       TObjectDoubleHashMap neighbors = null;
       TObjectDoubleHashMap randWalkProbs = null;
      
       HashMap<String, String> neighScores =
                 new HashMap<String, String>();
      
       int totalMessagesReceived = 0;
      
       // iterate over all the messages received at the node
       while (values.hasNext()) {
         ++totalMessagesReceived;

         String val = values.next().toString();
         String[] fields = val.split(_kDelim);
        
         // System.out.println("src: " + fields[0] + " dest: " + vertexId +
         //       "MESSAGE>>" + val + "<<");

         // self-message check
         if (vertexId.equals(fields[0])) {
           isSelfMessageFound = true;
           vertexString = val;
          
           // System.out.println("Reduce: " + vertexId + " " + val + " " + fields.length);

           TObjectDoubleHashMap injLabels = CollectionUtil.String2Map(fields[2]);
           neighbors = CollectionUtil.String2Map(neighbors, fields[4]);
           randWalkProbs = CollectionUtil.String2Map(fields[5]);
          
           if (injLabels.size() > 0) {          
             // add injected labels to the estimated scores.
             ProbUtil.AddScores(newEstimatedScores,
                        mu1 * randWalkProbs.get(Constants._kInjProb),
                        injLabels);
           }
         } else {
           // an empty second field represents that the
           // neighbor has no valid label assignment yet.
           if (fields.length > 1) {
             neighScores.put(fields[0], fields[1]);
           }
         }
       }

       // terminate if message from self is not received.
       if (!isSelfMessageFound) {
         throw new RuntimeException("Self message not received for node " + vertexId);
       }
      
       // collect neighbors label distributions and create one single
       // label distribution
       TObjectDoubleHashMap weightedNeigLablDist = new TObjectDoubleHashMap();
       Iterator<String> neighIter = neighScores.keySet().iterator();
       while (neighIter.hasNext()) {
         String neighName = neighIter.next();
         ProbUtil.AddScores(weightedNeigLablDist, // newEstimatedScores,
                   mu2 * randWalkProbs.get(Constants._kContProb) * neighbors.get(neighName),
 
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.