private Node getLeaf (Node node, FeatureVector fv) { if (node.child0 == null) return node; else if (fv.value (node.featureIndex) != 0) return getLeaf (node.child1, fv); else return getLeaf (node.child0, fv); }
private Node getLeaf (Node node, FeatureVector fv) { if (node.child0 == null) return node; else if (fv.value (node.featureIndex) != 0) return getLeaf (node.child1, fv); else return getLeaf (node.child0, fv); }
private Node getLeaf (Node node, FeatureVector fv) { if (node.child0 == null) return node; else if (fv.value (node.featureIndex) != 0) return getLeaf (node.child1, fv); else return getLeaf (node.child0, fv); }
public void testSingleValueFromFeatureSequence () { assertTrue (fv.value (dict.lookupIndex ("n")) == 1.0); }
public void testSingleValueFromFeatureSequence () { assertTrue (fv.value (dict.lookupIndex ("n")) == 1.0); }
public void testDuplicateValueFromFeatureSequence () { assertTrue (fv.value (dict.lookupIndex ("a")) == 2.0); }
public void testDuplicateValueFromFeatureSequence () { assertTrue (fv.value (dict.lookupIndex ("a")) == 2.0); }
public static int[] sortInstances(InstanceList ilist, int[] instIndices, int featureIndex) { ArrayList list = new ArrayList(); for (int ii = 0; ii < instIndices.length; ii++) { Instance inst = ilist.get(instIndices[ii]); FeatureVector fv = (FeatureVector) inst.getData(); list.add(new Point2D.Double(instIndices[ii], fv.value(featureIndex))); } Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { Point2D.Double p1 = (Point2D.Double) o1; Point2D.Double p2 = (Point2D.Double) o2; if (p1.y == p2.y) { assert(p1.x != p2.x); return p1.x > p2.x ? 1 : -1; } else return p1.y > p2.y ? 1 : -1; } }); int[] sorted = new int[instIndices.length]; for (int i = 0; i < list.size(); i++) sorted[i] = (int) ((Point2D.Double) list.get(i)).getX(); return sorted; }
public static int[] sortInstances(InstanceList ilist, int[] instIndices, int featureIndex) { ArrayList list = new ArrayList(); for (int ii = 0; ii < instIndices.length; ii++) { Instance inst = ilist.get(instIndices[ii]); FeatureVector fv = (FeatureVector) inst.getData(); list.add(new Point2D.Double(instIndices[ii], fv.value(featureIndex))); } Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { Point2D.Double p1 = (Point2D.Double) o1; Point2D.Double p2 = (Point2D.Double) o2; if (p1.y == p2.y) { assert(p1.x != p2.x); return p1.x > p2.x ? 1 : -1; } else return p1.y > p2.y ? 1 : -1; } }); int[] sorted = new int[instIndices.length]; for (int i = 0; i < list.size(); i++) sorted[i] = (int) ((Point2D.Double) list.get(i)).getX(); return sorted; }
public static int[] sortInstances(InstanceList ilist, int[] instIndices, int featureIndex) { ArrayList list = new ArrayList(); for (int ii = 0; ii < instIndices.length; ii++) { Instance inst = ilist.get(instIndices[ii]); FeatureVector fv = (FeatureVector) inst.getData(); list.add(new Point2D.Double(instIndices[ii], fv.value(featureIndex))); } Collections.sort(list, new Comparator() { public int compare(Object o1, Object o2) { Point2D.Double p1 = (Point2D.Double) o1; Point2D.Double p2 = (Point2D.Double) o2; if (p1.y == p2.y) { assert(p1.x != p2.x); return p1.x > p2.x ? 1 : -1; } else return p1.y > p2.y ? 1 : -1; } }); int[] sorted = new int[instIndices.length]; for (int i = 0; i < list.size(); i++) sorted[i] = (int) ((Point2D.Double) list.get(i)).getX(); return sorted; }
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++;
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++;
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); }
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); }
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); }
public void split (FeatureSelection fs) { if (ilist == null) throw new IllegalStateException ("Frozen. Cannot split."); InstanceList ilist0 = new InstanceList (ilist.getPipe()); InstanceList ilist1 = new InstanceList (ilist.getPipe()); for (int i = 0; i < ilist.size(); i++) { Instance instance = ilist.get(i); FeatureVector fv = (FeatureVector) instance.getData (); // xxx What test should this be? What to do with negative values? // Whatever is decided here should also go in InfoGain.calcInfoGains() if (fv.value (featureIndex) != 0) { //System.out.println ("list1 add "+instance.getUri()+" weight="+ilist.getInstanceWeight(i)); ilist1.add (instance, ilist.getInstanceWeight(i)); } else { //System.out.println ("list0 add "+instance.getUri()+" weight="+ilist.getInstanceWeight(i)); ilist0.add (instance, ilist.getInstanceWeight(i)); } } logger.info("child0="+ilist0.size()+" child1="+ilist1.size()); child0 = new Node (ilist0, this, fs); child1 = new Node (ilist1, this, fs); }
public void split (FeatureSelection fs) { if (ilist == null) throw new IllegalStateException ("Frozen. Cannot split."); InstanceList ilist0 = new InstanceList (ilist.getPipe()); InstanceList ilist1 = new InstanceList (ilist.getPipe()); for (int i = 0; i < ilist.size(); i++) { Instance instance = ilist.get(i); FeatureVector fv = (FeatureVector) instance.getData (); // xxx What test should this be? What to do with negative values? // Whatever is decided here should also go in InfoGain.calcInfoGains() if (fv.value (featureIndex) != 0) { //System.out.println ("list1 add "+instance.getUri()+" weight="+ilist.getInstanceWeight(i)); ilist1.add (instance, ilist.getInstanceWeight(i)); } else { //System.out.println ("list0 add "+instance.getUri()+" weight="+ilist.getInstanceWeight(i)); ilist0.add (instance, ilist.getInstanceWeight(i)); } } logger.info("child0="+ilist0.size()+" child1="+ilist1.size()); child0 = new Node (ilist0, this, fs); child1 = new Node (ilist1, this, fs); }
public void split (FeatureSelection fs) { if (ilist == null) throw new IllegalStateException ("Frozen. Cannot split."); InstanceList ilist0 = new InstanceList (ilist.getPipe()); InstanceList ilist1 = new InstanceList (ilist.getPipe()); for (int i = 0; i < ilist.size(); i++) { Instance instance = ilist.get(i); FeatureVector fv = (FeatureVector) instance.getData (); // xxx What test should this be? What to do with negative values? // Whatever is decided here should also go in InfoGain.calcInfoGains() if (fv.value (featureIndex) != 0) { //System.out.println ("list1 add "+instance.getUri()+" weight="+ilist.getInstanceWeight(i)); ilist1.add (instance, ilist.getInstanceWeight(i)); } else { //System.out.println ("list0 add "+instance.getUri()+" weight="+ilist.getInstanceWeight(i)); ilist0.add (instance, ilist.getInstanceWeight(i)); } } logger.info("child0="+ilist0.size()+" child1="+ilist1.size()); child0 = new Node (ilist0, this, fs); child1 = new Node (ilist1, this, fs); }
public void testOne () { Token t = new Token ("foo"); t.setProperty ("color", "red"); t.setProperty ("font", "TimesRoman"); t.setFeatureValue ("length", 3); t.setFeatureValue ("containsVowel", 1); t.setFeatureValue ("in /usr/dict/words", 0); Alphabet dict = new Alphabet(); FeatureVector fv = t.toFeatureVector (dict, false); assertTrue (fv.numLocations() == 2); assertTrue (fv.value (dict.lookupIndex("length")) == 3); }
public void testOne () { Token t = new Token ("foo"); t.setProperty ("color", "red"); t.setProperty ("font", "TimesRoman"); t.setFeatureValue ("length", 3); t.setFeatureValue ("containsVowel", 1); t.setFeatureValue ("in /usr/dict/words", 0); Alphabet dict = new Alphabet(); FeatureVector fv = t.toFeatureVector (dict, false); assertTrue (fv.numLocations() == 2); assertTrue (fv.value (dict.lookupIndex("length")) == 3); }