コード例 #1
0
 /**
  * Compare the target segments to the 'otherSegments', and update the classifier by sum_x
  * [delta*x], for each example x corresponding to a target segment that's not in otherSegments.
  */
 private int compareSegmentsAndIncrement(
     ExampleSchema schema,
     Segmentation segments,
     Segmentation otherSegments,
     Hyperplane[] accum,
     double delta,
     CandidateSegmentGroup g) {
   int errors = 0;
   // first, work out the name of the previous class for each segment
   Map<Segment, String> map = previousClassMap(segments, schema);
   Map<Segment, String> otherMap = previousClassMap(otherSegments, schema);
   String[] history = new String[1];
   for (Iterator<Segment> j = segments.iterator(); j.hasNext(); ) {
     Segmentation.Segment seg = j.next();
     String previousClass = map.get(seg);
     if (seg.lo >= 0
         && (!otherSegments.contains(seg) || !otherMap.get(seg).equals(previousClass))) {
       errors++;
       history[0] = previousClass;
       Instance instance =
           new InstanceFromSequence(g.getSubsequenceExample(seg.lo, seg.hi), history);
       if (DEBUG)
         log.debug(
             "class "
                 + schema.getClassName(seg.y)
                 + " update "
                 + delta
                 + " for: "
                 + instance.getSource());
       accum[seg.y].increment(instance, delta);
     }
   }
   return errors;
 }
コード例 #2
0
 /** Analogous to binaryFeatureSet */
 private Set<Feature> numericFeatureSet(int start, int end, Instance otherInstance) {
   Set<Feature> s = new HashSet<Feature>();
   for (int i = start; i < end; i++) {
     addAll(s, unitInstance[i].numericFeatureIterator());
   }
   if (otherInstance != null) addAll(s, otherInstance.numericFeatureIterator());
   return s;
 }
コード例 #3
0
 @Override
 public Explanation getExplanation(Instance instance) {
   Explanation.Node top = new Explanation.Node("DecisionTree Explanation");
   if (instance.getWeight(test) >= threshold) {
     Explanation.Node node =
         new Explanation.Node(test + "=" + instance.getWeight(test) + ">=" + threshold);
     Explanation.Node childEx = ifTrue.getExplanation(instance).getTopNode();
     node.add(childEx);
     top.add(node);
   } else {
     Explanation.Node node =
         new Explanation.Node(test + "=" + instance.getWeight(test) + "<" + threshold);
     Explanation.Node childEx = ifFalse.getExplanation(instance).getTopNode();
     node.add(childEx);
     top.add(node);
   }
   Explanation ex = new Explanation(top);
   return ex;
 }
コード例 #4
0
 @Override
 public String explain(Instance instance) {
   if (instance.getWeight(test) >= threshold) {
     return test
         + "="
         + instance.getWeight(test)
         + ">="
         + threshold
         + "\n"
         + ifTrue.explain(instance);
   } else {
     return test
         + "="
         + instance.getWeight(test)
         + "<"
         + threshold
         + "\n"
         + ifFalse.explain(instance);
   }
 }
コード例 #5
0
 public Delta(FeatureFactory factory, int start, int end, Instance segmentInstance) {
   for (Iterator<Feature> i = featureSet(start, end, segmentInstance).iterator();
       i.hasNext(); ) {
     Feature f = i.next();
     // replace the feature with its canonical version, so
     // that variant versions are not stored in the
     // deltaWeight, zeroWeights hash tables
     f = factory.getFeature(f);
     double segmentWeight = segmentInstance.getWeight(f);
     if (segmentWeight == 0) zeroWeights.add(f);
     else {
       double sumWeight = getSumWeight(start, end, f);
       if (segmentWeight != sumWeight) deltaWeight.put(f, segmentWeight - sumWeight);
     }
   }
   /*
    System.out.println("segmentInstance: "+segmentInstance);
    System.out.println("deltaInstance:   "+new DeltaInstance(start,end,this,
    segmentInstance.getSource(),
    segmentInstance.getSubpopulationId()));
   */
 }
コード例 #6
0
 @Override
 public double score(Instance instance) {
   if (instance.getWeight(test) >= threshold) return ifTrue.score(instance);
   else return ifFalse.score(instance);
 }