/** * Predicts the cluster memberships for a given instance. Either this or * clusterInstance() needs to be implemented by subclasses. * * @param instance the instance to be assigned a cluster. * @return an array containing the estimated membership probabilities of the * test instance in each cluster (this should sum to at most 1) * @exception Exception if distribution could not be computed successfully */ @Override public double[] distributionForInstance(Instance instance) throws Exception { double[] d = new double[numberOfClusters()]; d[clusterInstance(instance)] = 1.0; return d; }
/** * Classifies a given instance. Either this or distributionForInstance() needs * to be implemented by subclasses. * * @param instance the instance to be assigned to a cluster * @return the number of the assigned cluster as an integer * @exception Exception if instance could not be clustered successfully */ @Override public int clusterInstance(Instance instance) throws Exception { double[] dist = distributionForInstance(instance); if (dist == null) { throw new Exception("Null distribution predicted"); } if (Utils.sum(dist) <= 0) { throw new Exception("Unable to cluster instance"); } return Utils.maxIndex(dist); }
/** * Gets the current settings of the classifier. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> result = new Vector<String>(); result.add("-S"); result.add("" + getSeed()); Collections.addAll(result, super.getOptions()); return result.toArray(new String[result.size()]); }
/** * Gets the current settings of the clusterer. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); for (String s : Option.getOptionsForHierarchy(this, AbstractClusterer.class)) { options.add(s); } if (getDebug()) { options.add("-output-debug-info"); } if (getDoNotCheckCapabilities()) { options.add("-do-not-check-capabilities"); } return options.toArray(new String[0]); }
/** * Parses a given list of options. * * @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 tmpStr; tmpStr = Utils.getOption('W', options); super.setOptions(options); if (tmpStr.length() > 0) { setClusterer(AbstractClusterer.forName(tmpStr, null)); setClusterer(AbstractClusterer.forName(tmpStr, Utils.partitionOptions(options))); } else { setClusterer(AbstractClusterer.forName(defaultClustererString(), null)); setClusterer(AbstractClusterer.forName(defaultClustererString(), Utils.partitionOptions(options))); } }
if (SSE < minSSE) { minSSE = SSE; bestClusterer = (SimpleKMeans) AbstractClusterer.makeCopy(clusterer);
public Clustering getClusteringResult() { Clustering clustering = null; weka.core.Instances wekaInstances= this.instanceConverter.wekaInstances(instances); try { clusterer.buildClusterer(wekaInstances); int numClusters = clusterer.numberOfClusters(); Instances dataset = getDataset(instances.numAttributes(), numClusters); List<Instance> newInstances = new ArrayList<Instance>() ; //Instances(dataset); for (int i = 0; i < wekaInstances.numInstances(); i++) { weka.core.Instance inst = wekaInstances.get(i); int cnum = clusterer.clusterInstance(inst); Instance newInst = new DenseInstance(instances.instance(cnum)); newInst.insertAttributeAt(inst.numAttributes()); newInst.setDataset(dataset); newInst.setClassValue(cnum); newInstances.add(newInst); } clustering = new Clustering(newInstances); } catch (Exception e) { e.printStackTrace(); } instances = null; return clustering; }
toTrainClusterer = (DensityBasedClusterer) weka.clusterers.AbstractClusterer .makeCopy((weka.clusterers.Clusterer) clust); toTrainClusterer.buildClusterer(trainingData); trainingData.setClassIndex(tempClassIndex); } else { m_threadClusterers = AbstractClusterer.makeCopies(toTrainClusterer, m_maxRowsInParallel);
String[] prevOptions = clusterer.getOptions(); clusterer.setOptions(optionsArray);
int numClusters=0; try { numClusters = theClusterer.numberOfClusters(); } catch (Exception e) { e.printStackTrace(); features.setInstance(x,y,ins,values); try { double[] prob = theClusterer.distributionForInstance( ins ); for(int k = 0 ; k < numClusters; k++) clusterArray[k][x+y*width] = prob[k];
/** * Parses a given list of options. Valid options are: * <p> * * @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 tmpStr = Utils.getOption('S', options); if (tmpStr.length() != 0) { setSeed(Integer.parseInt(tmpStr)); } else { setSeed(m_SeedDefault); } super.setOptions(options); }
/** * Main method for testing this class. * * @param args the options */ public static void main(String[] args) { try { if (args.length == 0) { throw new Exception("The first argument must be the name of a " + "clusterer"); } String ClustererString = args[0]; args[0] = ""; Clusterer newClusterer = AbstractClusterer.forName(ClustererString, null); System.out.println(evaluateClusterer(newClusterer, args)); } catch (Exception e) { System.out.println(e.getMessage()); } } }
/** * Returns default capabilities of the clusterer. * * @return the capabilities of this clusterer */ @Override public Capabilities getCapabilities() { Capabilities result; if (getClusterer() == null) { result = super.getCapabilities(); } else { result = getClusterer().getCapabilities(); } // set dependencies for (Capability cap : Capability.values()) { result.enableDependency(cap); } return result; }
/** * Build current clusterer based on the current instances */ public void buildClusterer(){ try { selectedClusterer.buildClusterer(featuresInstances); } catch (InterruptedException ie) { IJ.log("Clusterer building was interrupted"); } catch (Exception e) { IJ.log(e.getMessage()); e.printStackTrace(); } }
m_ActualClusterer = AbstractClusterer.makeCopy(m_Clusterer); m_ActualClusterer.buildClusterer(toFilterIgnoringAttributes);
toTrainClusterer = (DensityBasedClusterer) weka.clusterers.AbstractClusterer .makeCopy((weka.clusterers.Clusterer) clust); toTrainClusterer.buildClusterer(trainingData); trainingData.setClassIndex(tempClassIndex); } else { m_threadClusterers = AbstractClusterer.makeCopies(toTrainClusterer, m_maxRowsInParallel);
/** * Parses a given list of options. Valid options are: * <p> * * @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 tmpStr = Utils.getOption('S', options); if (tmpStr.length() != 0) { setSeed(Integer.parseInt(tmpStr)); } else { setSeed(m_SeedDefault); } super.setOptions(options); }
/** * Parses a given list of options. * * @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 tmpStr; tmpStr = Utils.getOption('W', options); super.setOptions(options); if (tmpStr.length() > 0) { setClusterer(AbstractClusterer.forName(tmpStr, null)); setClusterer(AbstractClusterer.forName(tmpStr, Utils.partitionOptions(options))); } else { setClusterer(AbstractClusterer.forName(defaultClustererString(), null)); setClusterer(AbstractClusterer.forName(defaultClustererString(), Utils.partitionOptions(options))); } }
/** * Main method for testing this class. * * @param args the options */ public static void main(String[] args) { try { if (args.length == 0) { throw new Exception("The first argument must be the name of a " + "clusterer"); } String ClustererString = args[0]; args[0] = ""; Clusterer newClusterer = AbstractClusterer.forName(ClustererString, null); System.out.println(evaluateClusterer(newClusterer, args)); } catch (Exception e) { System.out.println(e.getMessage()); } } }
/** * Gets the current settings of the clusterer. * * @return an array of strings suitable for passing to setOptions */ @Override public String[] getOptions() { Vector<String> options = new Vector<String>(); for (String s : Option.getOptionsForHierarchy(this, AbstractClusterer.class)) { options.add(s); } if (getDebug()) { options.add("-output-debug-info"); } if (getDoNotCheckCapabilities()) { options.add("-do-not-check-capabilities"); } return options.toArray(new String[0]); }