/** * Computes an array that indicates leaf membership */ @Override public double[] getMembershipValues(Instance inst) throws Exception { if (m_Classifier instanceof PartitionGenerator) { ArrayList<double[]> al = new ArrayList<double[]>(); int size = 0; for (int i = 0; i < m_Classifiers.length; i++) { double[] r = ((PartitionGenerator)m_Classifiers[i]). getMembershipValues(inst); size += r.length; al.add(r); } double[] values = new double[size]; int pos = 0; for (double[] v: al) { System.arraycopy(v, 0, values, pos, v.length); pos += v.length; } return values; } else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Computes an array that indicates leaf membership */ public double[] getMembershipValues(Instance inst) throws Exception { if (m_Classifier instanceof PartitionGenerator) { ArrayList<double[]> al = new ArrayList<double[]>(); int size = 0; for (int i = 0; i < m_Classifiers.length; i++) { double[] r = ((PartitionGenerator)m_Classifiers[i]). getMembershipValues(inst); size += r.length; al.add(r); } double[] values = new double[size]; int pos = 0; for (double[] v: al) { System.arraycopy(v, 0, values, pos, v.length); pos += v.length; } return values; } else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Computes an array that has a value for each element in the partition. (If * the base classifier supports this.) */ public double[] getMembershipValues(Instance inst) throws Exception { if (m_Classifier instanceof PartitionGenerator) { Instance newInstance = filterInstance(inst); if (newInstance == null) { double[] unclassified = new double[numElements()]; for (int i = 0; i < unclassified.length; i++) { unclassified[i] = Utils.missingValue(); } return unclassified; } else { return ((PartitionGenerator) m_Classifier) .getMembershipValues(newInstance); } } else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Computes an array that has a value for each element in the partition. * (If the base classifier supports this.) */ public double[] getMembershipValues(Instance inst) throws Exception { if (m_Classifier instanceof PartitionGenerator) { Instance newInstance = filterInstance(inst); if (newInstance == null) { double[] unclassified = new double[numElements()]; for (int i = 0; i < unclassified.length; i++) { unclassified[i] = Utils.missingValue(); } return unclassified; } else { return ((PartitionGenerator)m_Classifier).getMembershipValues(newInstance); } } else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Builds the classifier to generate a partition. */ @Override public void generatePartition(Instances data) throws Exception { if (m_Classifier instanceof PartitionGenerator) buildClassifier(data); else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Returns the number of elements in the partition. */ @Override public int numElements() throws Exception { if (m_Classifier instanceof PartitionGenerator) { int size = 0; for (int i = 0; i < m_Classifiers.length; i++) { size += ((PartitionGenerator)m_Classifiers[i]).numElements(); } return size; } else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Builds the classifier to generate a partition. */ public void generatePartition(Instances data) throws Exception { if (m_Classifier instanceof PartitionGenerator) buildClassifier(data); else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Returns the number of elements in the partition. */ public int numElements() throws Exception { if (m_Classifier instanceof PartitionGenerator) { int size = 0; for (int i = 0; i < m_Classifiers.length; i++) { size += ((PartitionGenerator)m_Classifiers[i]).numElements(); } return size; } else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Builds the classifier to generate a partition. (If the base classifier * supports this.) */ public void generatePartition(Instances data) throws Exception { if (m_Classifier instanceof PartitionGenerator) buildClassifier(data); else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Returns the number of elements in the partition. (If the base classifier * supports this.) */ public int numElements() throws Exception { if (m_Classifier instanceof PartitionGenerator) return ((PartitionGenerator) m_Classifier).numElements(); else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Builds the classifier to generate a partition. * (If the base classifier supports this.) */ public void generatePartition(Instances data) throws Exception { if (m_Classifier instanceof PartitionGenerator) buildClassifier(data); else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Returns the number of elements in the partition. * (If the base classifier supports this.) */ public int numElements() throws Exception { if (m_Classifier instanceof PartitionGenerator) return ((PartitionGenerator)m_Classifier).numElements(); else throw new Exception("Classifier: " + getClassifierSpec() + " cannot generate a partition"); }
/** * Parses a given list of options. * <p/> * * <!-- options-start --> Valid options are: * <p/> * * <pre> * -W <name of partition generator> * Full name of partition generator to use, e.g.: * weka.classifiers.trees.J48 * Additional options after the '--'. * (default: weka.classifiers.trees.J48) * </pre> * * <!-- options-end --> * * Options after the -- are passed on to the clusterer. * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ @Override public void setOptions(String[] options) throws Exception { String generatorString = Utils.getOption('W', options); if (generatorString.length() == 0) { generatorString = J48.class.getName(); } setPartitionGenerator((PartitionGenerator) Utils.forName( PartitionGenerator.class, generatorString, Utils.partitionOptions(options))); Utils.checkForRemainingOptions(options); }
/** * Set the generator for use in filtering * * @param newPartitionGenerator the generator to use */ public void setPartitionGenerator(PartitionGenerator newPartitionGenerator) { m_partitionGenerator = newPartitionGenerator; }
/** * Get the generator used by this filter * * @return the generator used */ public PartitionGenerator getPartitionGenerator() { return m_partitionGenerator; }