/** * Returns the logs of the joint densities for a given instance. * * @param inst the instance * @return the array of values * @exception Exception if values could not be computed */ public double[] logJointDensitiesForInstance(Instance inst) throws Exception { double[] weights = logDensityPerClusterForInstance(inst); double[] priors = clusterPriors(); for (int i = 0; i < weights.length; i++) { if (priors[i] > 0) { weights[i] += Math.log(priors[i]); } else { throw new IllegalArgumentException("Cluster empty!"); } } return weights; }
/** * 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()]); }
/** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration<Option> listOptions() { Vector<Option> result = new Vector<Option>(); result.addElement(new Option("\tRandom number seed.\n" + "\t(default " + m_SeedDefault + ")", "S", 1, "-S <num>")); result.addAll(Collections.list(super.listOptions())); return result.elements(); }
/** * Returns the cluster probability distribution for an instance. * * @param instance the instance to be clustered * @return the probability distribution * @throws Exception if computation fails */ public double[] distributionForInstance(Instance instance) throws Exception { return Utils.logs2probs(logJointDensitiesForInstance(instance)); }
/** * 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; tmpStr = Utils.getOption('S', options); if (tmpStr.length() != 0) { setSeed(Integer.parseInt(tmpStr)); } else { setSeed(m_SeedDefault); } super.setOptions(options); }
/** * Returns default capabilities of the clusterer (i.e., of the wrapper * clusterer). * * @return the capabilities of this clusterer */ @Override public Capabilities getCapabilities() { if (m_wrappedClusterer != null) { return m_wrappedClusterer.getCapabilities(); } Capabilities result = super.getCapabilities(); result.disableAll(); result.enable(Capability.NO_CLASS); return result; }
m_clusterers = AbstractDensityBasedClusterer.makeCopies(m_clusterer, 1); m_clusterers[0].buildClusterer(toFilterIgnoringAttributes[0]); } else { m_clusterers = AbstractDensityBasedClusterer.makeCopies(m_clusterer, toFilter.numClasses()); for (int i = 0; i < m_clusterers.length; i++) {
/** * Returns the cluster probability distribution for an instance. * * @param instance the instance to be clustered * @return the probability distribution * @throws Exception if computation fails */ public double[] distributionForInstance(Instance instance) throws Exception { return Utils.logs2probs(logJointDensitiesForInstance(instance)); }
/** * 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; tmpStr = Utils.getOption('S', options); if (tmpStr.length() != 0) { setSeed(Integer.parseInt(tmpStr)); } else { setSeed(m_SeedDefault); } super.setOptions(options); }
/** * Returns default capabilities of the clusterer (i.e., of the wrapper * clusterer). * * @return the capabilities of this clusterer */ @Override public Capabilities getCapabilities() { if (m_wrappedClusterer != null) { return m_wrappedClusterer.getCapabilities(); } Capabilities result = super.getCapabilities(); result.disableAll(); result.enable(Capability.NO_CLASS); return result; }
m_clusterers = AbstractDensityBasedClusterer.makeCopies(m_clusterer, 1); m_clusterers[0].buildClusterer(toFilterIgnoringAttributes[0]); } else { m_clusterers = AbstractDensityBasedClusterer.makeCopies(m_clusterer, toFilter.numClasses()); for (int i = 0; i < m_clusterers.length; i++) {
/** * Returns the logs of the joint densities for a given instance. * * @param inst the instance * @return the array of values * @exception Exception if values could not be computed */ public double[] logJointDensitiesForInstance(Instance inst) throws Exception { double[] weights = logDensityPerClusterForInstance(inst); double[] priors = clusterPriors(); for (int i = 0; i < weights.length; i++) { if (priors[i] > 0) { weights[i] += Math.log(priors[i]); } else { throw new IllegalArgumentException("Cluster empty!"); } } return weights; }
/** * Computes the density for a given instance. * * @param instance the instance to compute the density for * @return the density. * @exception Exception if the density could not be computed successfully */ public double logDensityForInstance(Instance instance) throws Exception { double[] a = logJointDensitiesForInstance(instance); double max = a[Utils.maxIndex(a)]; double sum = 0.0; for(int i = 0; i < a.length; i++) { sum += Math.exp(a[i] - max); } return max + Math.log(sum); }
/** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ @Override public Enumeration<Option> listOptions() { Vector<Option> result = new Vector<Option>(); result.addElement(new Option("\tRandom number seed.\n" + "\t(default " + m_SeedDefault + ")", "S", 1, "-S <num>")); result.addAll(Collections.list(super.listOptions())); return result.elements(); }
/** * 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()]); }
Utils.partitionOptions(options))); super.setOptions(options);
/** * Computes the density for a given instance. * * @param instance the instance to compute the density for * @return the density. * @exception Exception if the density could not be computed successfully */ public double logDensityForInstance(Instance instance) throws Exception { double[] a = logJointDensitiesForInstance(instance); double max = a[Utils.maxIndex(a)]; double sum = 0.0; for(int i = 0; i < a.length; i++) { sum += Math.exp(a[i] - max); } return max + Math.log(sum); }
/** * Returns an enumeration describing the available options.. * * @return an enumeration of all the available options. */ @Override public Enumeration<Option> listOptions() { Vector<Option> result = new Vector<Option>(); result.addElement(new Option( "\tminimum allowable standard deviation for normal density computation " + "\n\t(default 1e-6)", "M", 1, "-M <num>")); result.addElement(new Option("\tClusterer to wrap.\n" + "\t(default " + defaultClustererString() + ")", "W", 1, "-W <clusterer name>")); result.addAll(Collections.list(super.listOptions())); if ((m_wrappedClusterer != null) && (m_wrappedClusterer instanceof OptionHandler)) { result.addElement(new Option("", "", 0, "\nOptions specific to clusterer " + m_wrappedClusterer.getClass().getName() + ":")); result.addAll(Collections.list(((OptionHandler) m_wrappedClusterer) .listOptions())); } return result.elements(); }
/** * 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>(); options.add("-M"); options.add("" + getMinStdDev()); if (getClusterer() != null) { options.add("-W"); options.add(getClusterer().getClass().getName()); if (m_wrappedClusterer instanceof OptionHandler) { String[] clustererOptions = ((OptionHandler) m_wrappedClusterer) .getOptions(); if (clustererOptions.length > 0) { options.add("--"); Collections.addAll(options, clustererOptions); } } } Collections.addAll(options, super.getOptions()); return options.toArray(new String[0]); }
Utils.partitionOptions(options))); super.setOptions(options);