Ejemplo n.º 1
0
Archivo: C45.java Proyecto: alei76/tctm
 public void split() {
   if (m_ilist == null) throw new IllegalStateException("Frozen.  Cannot split.");
   int numLeftChildren = 0;
   boolean[] toLeftChild = new boolean[m_instIndices.length];
   for (int i = 0; i < m_instIndices.length; i++) {
     Instance instance = m_ilist.get(m_instIndices[i]);
     FeatureVector fv = (FeatureVector) instance.getData();
     if (fv.value(m_gainRatio.getMaxValuedIndex()) <= m_gainRatio.getMaxValuedThreshold()) {
       toLeftChild[i] = true;
       numLeftChildren++;
     } else toLeftChild[i] = false;
   }
   logger.info(
       "leftChild.size="
           + numLeftChildren
           + " rightChild.size="
           + (m_instIndices.length - numLeftChildren));
   int[] leftIndices = new int[numLeftChildren];
   int[] rightIndices = new int[m_instIndices.length - numLeftChildren];
   int li = 0, ri = 0;
   for (int i = 0; i < m_instIndices.length; i++) {
     if (toLeftChild[i]) leftIndices[li++] = m_instIndices[i];
     else rightIndices[ri++] = m_instIndices[i];
   }
   m_leftChild = new Node(m_ilist, this, m_minNumInsts, leftIndices);
   m_rightChild = new Node(m_ilist, this, m_minNumInsts, rightIndices);
 }
 protected List<Double> serializeFv(FeatureVector fv) {
   List<Double> features = new ArrayList<>();
   int numLocations = fv.numLocations();
   int[] indices = fv.getIndices();
   for (int index = 0; index < numLocations; index++) {
     int featureIndex = indices[index];
     double value = fv.value(featureIndex);
     features.add(value);
   }
   return features;
 }
Ejemplo n.º 3
0
Archivo: C45.java Proyecto: alei76/tctm
 private Node getLeaf(Node node, FeatureVector fv) {
   if (node.getLeftChild() == null && node.getRightChild() == null) return node;
   else if (fv.value(node.getGainRatio().getMaxValuedIndex())
       <= node.getGainRatio().getMaxValuedThreshold()) return getLeaf(node.getLeftChild(), fv);
   else return getLeaf(node.getRightChild(), fv);
 }