Examples of NCRPNode


Examples of cc.mallet.topics.HierarchicalLDA.NCRPNode

    //check instance
    if (! (instance.getData() instanceof FeatureSequence)) {
      throw new IllegalArgumentException("Input must be a FeatureSequence");
    }   
   
    NCRPNode node;
    fs = (FeatureSequence) instance.getData();
    int docLength = fs.size();
   
    localLevels = new int[docLength];
    NCRPNode[] path = new NCRPNode[numLevels];
View Full Code Here

Examples of cc.mallet.topics.HierarchicalLDA.NCRPNode

  }
 
   public void samplePath(){
    
     int level, token, type;
     NCRPNode node;
     NCRPNode[] path = new NCRPNode[numLevels];
     //1.get current path
     node = leaveNode;
       for (level = numLevels - 1; level >= 0; level--) {
      path[level] = node;
      node = node.parent;
     }
      
       TObjectDoubleHashMap<NCRPNode> nodeWeights = new TObjectDoubleHashMap<NCRPNode>();
    
      // Calculate p(c_m | c_{-m})
      calculateNCRP(nodeWeights, getRootNode(), 0.0);
     
     TIntIntHashMap[] typeCounts = new TIntIntHashMap[numLevels];
     int[] docLevels;

    for (level = 0; level < numLevels; level++) {
      typeCounts[level] = new TIntIntHashMap();
    }
    docLevels = localLevels;
   
    // Save the counts of every word at each level, and remove
    //  counts from the current path
      for (token = 0; token < docLevels.length; token++) {
       level = docLevels[token];
       type = fs.getIndexAtPosition(token);
      
       //ignore words outside dictionary
       if (type < numTypes){
      
         if (! typeCounts[level].containsKey(type)) {
          typeCounts[level].put(type, 1);
         }
         else {
          typeCounts[level].increment(type);
         }
        
         path[level].typeCounts[type]--;
         assert(path[level].typeCounts[type] >= 0);
           
         path[level].totalTokens--;     
         assert(path[level].totalTokens >= 0);
       }
     
    }
     
      double[] newTopicWeights = new double[numLevels];
    for (level = 1; level < numLevels; level++) {  // Skip the root...
      int[] types = typeCounts[level].keys();
      int totalTokens = 0;

      for (int t: types) {
        for (int i=0; i<typeCounts[level].get(t); i++) {
          newTopicWeights[level] +=
            Math.log((eta + i) / (etaSum + totalTokens));
          totalTokens++;
        }
      }

      //if (iteration > 1) { System.out.println(newTopicWeights[level]); }
    }
     
    calculateWordLikelihood(nodeWeights, getRootNode(), 0.0, typeCounts, newTopicWeights, 0);
   
    NCRPNode[] nodes = nodeWeights.keys(new NCRPNode[] {});
    double[] weights = new double[nodes.length];
    double sum = 0.0;
    double max = Double.NEGATIVE_INFINITY;

    // To avoid underflow, we're using log weights and normalizing the node weights so that
    //  the largest weight is always 1.
    for (int i=0; i<nodes.length; i++) {
      if (nodeWeights.get(nodes[i]) > max) {
        max = nodeWeights.get(nodes[i]);
      }
    }

    for (int i=0; i<nodes.length; i++) {
      weights[i] = Math.exp(nodeWeights.get(nodes[i]) - max);

      /*
        if (iteration > 1) {
        if (nodes[i] == documentLeaves[doc]) {
        System.out.print("* ");
        }
        System.out.println(((NCRPNode) nodes[i]).level + "\t" + weights[i] +
        "\t" + nodeWeights.get(nodes[i]));
        }
      */

      sum += weights[i];
    }

    //if (iteration > 1) {System.out.println();}
    node = nodes[ random.nextDiscrete(weights, sum) ];

    // If we have picked an internal node, we need to
    //  add a new path.
    while (! node.isLeaf()) {
      node = node.selectExisting();
      //node = nodes[ random.nextDiscrete(weights, sum) ];
    }
 
    //node.addPath();
    leaveNode = node;

    NCRPNode node2 = node;
    for (level = numLevels - 1; level >= 0; level--) {
      int[] types = typeCounts[level].keys();

      for (int t: types) {
        if (t < numTypes){
View Full Code Here

Examples of cc.mallet.topics.HierarchicalLDA.NCRPNode

   public void sampleTopics() {
    
      int seqLen = fs.getLength();
      int[] docLevels = localLevels;
      NCRPNode[] path = new NCRPNode[numLevels];
      NCRPNode node;
      int[] levelCounts = new int[numLevels];
      int type, token, level;
      double sum;

      // Get the leaf
View Full Code Here

Examples of cc.mallet.topics.HierarchicalLDA.NCRPNode

        nodeWeights.adjustValue(node, nodeWeight);
     }
  
   public StringBuffer printTopicDistribution(NCRPNode leave, int[] levels){
     NCRPNode node =leave;
     NCRPNode[] path = new NCRPNode[numLevels];
        for (int level = numLevels - 1; level >= 0; level--) {
       path[level] = node;
         node = node.parent;
    }
View Full Code Here

Examples of cc.mallet.topics.HierarchicalLDA.NCRPNode

     return printTopicDistribution(golbalDocumentLeaves[doc], globalLevels[doc]);
   }
    
   public void getTopicDistribution(NCRPNode leave, int[] levels){
    
     NCRPNode node =leave;
     NCRPNode[] path = new NCRPNode[numLevels];
        for (int level = numLevels - 1; level >= 0; level--) {
       path[level] = node;
         node = node.parent;
    }
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.