📄 xmeans.java
字号:
* @param distanceF the distance function with all options set */ public void setDistanceF(DistanceFunction distanceF) { m_DistanceF = distanceF; } /** * Gets the distance function. * @return the distance function */ public DistanceFunction getDistanceF() { return m_DistanceF; } /** * Gets the distance function specification string, which contains the * class name of the distance function class and any options to it. * * @return the distance function specification string */ protected String getDistanceFSpec() { DistanceFunction d = getDistanceF(); if (d instanceof OptionHandler) { return d.getClass().getName() + " " + Utils.joinOptions(((OptionHandler) d).getOptions()); } return d.getClass().getName(); } /** * Returns the tip text for this property. * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String debugVectorsFileTipText() { return "The file containing the debug vectors (only for debugging!)."; } /** * Sets the file that has the random vectors stored. * Only used for debugging reasons. * @param value the file to read the random vectors from */ public void setDebugVectorsFile(File value) { m_DebugVectorsFile = value; } /** * Gets the file name for a file that has the random vectors stored. * Only used for debugging purposes. * @return the file to read the vectors from */ public File getDebugVectorsFile() { return m_DebugVectorsFile; } /** * Initialises the debug vector input. * @throws Exception if there is error * opening the debug input file. */ public void initDebugVectorsInput() throws Exception { m_DebugVectorsInput = new BufferedReader(new FileReader(m_DebugVectorsFile)); m_DebugVectors = new Instances(m_DebugVectorsInput); m_DebugVectorsIndex = 0; } /** * Read an instance from debug vectors file. * @param model the data model for the instance. * @throws Exception if there are no debug vector * in m_DebugVectors. * @return the next debug vector. */ public Instance getNextDebugVectorsInstance(Instances model) throws Exception { if (m_DebugVectorsIndex >= m_DebugVectors.numInstances()) throw new Exception("no more prefabricated Vectors"); Instance nex = m_DebugVectors.instance(m_DebugVectorsIndex); nex.setDataset(model); m_DebugVectorsIndex++; return nex; } /** * Returns the tip text for this property. * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String inputCenterFileTipText() { return "The file to read the list of centers from."; } /** * Sets the file to read the list of centers from. * * @param value the file to read centers from */ public void setInputCenterFile(File value) { m_InputCenterFile = value; } /** * Gets the file to read the list of centers from. * * @return the file to read the centers from */ public File getInputCenterFile() { return m_InputCenterFile; } /** * Returns the tip text for this property. * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String outputCenterFileTipText() { return "The file to write the list of centers to."; } /** * Sets file to write the list of centers to. * * @param value file to write centers to */ public void setOutputCenterFile(File value) { m_OutputCenterFile = value; } /** * Gets the file to write the list of centers to. * * @return filename of the file to write centers to */ public File getOutputCenterFile() { return m_OutputCenterFile; } /** * Returns the tip text for this property. * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String KDTreeTipText() { return "The KDTree to use."; } /** * Sets the KDTree class. * @param k a KDTree object with all options set */ public void setKDTree(KDTree k) { m_KDTree = k; } /** * Gets the KDTree class. * * @return the configured KDTree */ public KDTree getKDTree() { return m_KDTree; } /** * Returns the tip text for this property. * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String useKDTreeTipText() { return "Whether to use the KDTree."; } /** * Sets whether to use the KDTree or not. * * @param value if true the KDTree is used */ public void setUseKDTree(boolean value) { m_UseKDTree = value; } /** * Gets whether the KDTree is used or not. * * @return true if KDTrees are used */ public boolean getUseKDTree() { return m_UseKDTree; } /** * Gets the KDTree specification string, which contains the class name of * the KDTree class and any options to the KDTree. * * @return the KDTree string. */ protected String getKDTreeSpec() { KDTree c = getKDTree(); if (c instanceof OptionHandler) { return c.getClass().getName() + " " + Utils.joinOptions(((OptionHandler)c).getOptions()); } return c.getClass().getName(); } /** * Returns the tip text for this property. * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String debugLevelTipText() { return "The debug level to use."; } /** * Sets the debug level. * debug level = 0, means no output * @param d debuglevel */ public void setDebugLevel(int d) { m_DebugLevel = d; } /** * Gets the debug level. * @return debug level */ public int getDebugLevel() { return m_DebugLevel; } /** * Checks the instances. * No checks in this KDTree but it calls the check of the distance function. */ protected void checkInstances () { // m_DistanceF.checkInstances(); } /** * Parses a given list of options. <p/> * <!-- options-start --> * Valid options are: <p/> * * <pre> -I <num> * maximum number of overall iterations * (default 1).</pre> * * <pre> -M <num> * maximum number of iterations in the kMeans loop in * the Improve-Parameter part * (default 1000).</pre> * * <pre> -J <num> * maximum number of iterations in the kMeans loop * for the splitted centroids in the Improve-Structure part * (default 1000).</pre> * * <pre> -L <num> * minimum number of clusters * (default 2).</pre> * * <pre> -H <num> * maximum number of clusters * (default 4).</pre> * * <pre> -B <value> * distance value for binary attributes * (default 1.0).</pre> * * <pre> -use-kdtree * Uses the KDTree internally * (default no).</pre> * * <pre> -K <KDTree class specification> * Full class name of KDTree class to use, followed * by scheme options. * eg: "weka.core.neighboursearch.kdtrees.KDTree -P" * (default no KDTree class used).</pre> * * <pre> -C <value> * cutoff factor, takes the given percentage of the splitted * centroids if none of the children win * (default 0.0).</pre> * * <pre> -D <distance function class specification> * Full class name of Distance function class to use, followed * by scheme options. * (default weka.core.EuclideanDistance).</pre> * * <pre> -N <file name> * file to read starting centers from (ARFF format).</pre> * * <pre> -O <file name> * file to write centers to (ARFF format).</pre> * * <pre> -U <int> * The debug level. * (default 0)</pre> * * <pre> -Y <file name> * The debug vectors file.</pre> * * <pre> -S <num> * Random number seed. * (default 10)</pre> * <!-- options-end --> * * @param options the list of options as an array of strings * @throws Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { String optionString; String funcString; optionString = Utils.getOption('I', options); if (optionString.length() != 0) setMaxIterations(Integer.parseInt(optionString)); else setMaxIterations(1); optionString = Utils.getOption('M', options); if (optionString.length() != 0) setMaxKMeans(Integer.parseInt(optionString)); else setMaxKMeans(1000); optionString = Utils.getOption('J', options); if (optionString.length() != 0) setMaxKMeansForChildren(Integer.parseInt(optionString)); else setMaxKMeansForChildren(1000); optionString = Utils.getOption('L', options); if (optionString.length() != 0) setMinNumClusters(Integer.parseInt(optionString)); else setMinNumClusters(2); optionString = Utils.getOption('H', options); if (optionString.length() != 0) setMaxNumClusters(Integer.parseInt(optionString)); else setMaxNumClusters(4); optionString = Utils.getOption('B', options); if (optionString.length() != 0) setBinValue(Double.parseDouble(optionString)); else setBinValue(1.0); setUseKDTree(Utils.getFlag("use-kdtree", options)); if (getUseKDTree()) { funcString = Utils.getOption('K', options); if (funcString.length() != 0) { String[] funcSpec = Utils.splitOptions(funcString); if (funcSpec.length == 0) { throw new Exception("Invalid function specification string"); } String funcName = funcSpec[0]; funcSpec[0] = ""; setKDTree((KDTree) Utils.forName(KDTree.class, funcName, funcSpec)); } else { setKDTree(new KDTree()); } } else { setKDTree(new KDTree()); } optionString = Utils.getOption('C', options); if (optionString.length() != 0) setCutOffFactor(Double.parseDouble(optionString)); else setCutOffFactor(0.0); funcString = Utils.getOption('D', options); if (funcString.length() != 0) { String[] funcSpec = Utils.splitOptions(funcString); if (funcSpec.length == 0) { throw new Exception("Invalid function specification string"); } String funcName = funcSpec[0]; funcSpec[0] = ""; setDistanceF((DistanceFunction) Utils.forName(DistanceFunction.class, funcName, funcSpec)); } else { setDistanceF(new EuclideanDistance()); } optionString = Utils.getOption('N', options); if (optionString.length() != 0) { setInputCenterFile(new File(optionString)); m_CenterInput = new BufferedReader(new FileReader(optionString)); } else { setInputCenterFile(new File(System.getProperty("user.dir"))); m_CenterInput = null; } optionString = Utils.getOption('O', options); if (optionString.length() != 0) { setOutputCenterFile(new File(optionString)); m_CenterOutput = new PrintWriter(new FileOutputStream(optionString)); } else { setOutputCenterFile(new File(System.getProperty("user.dir"))); m_CenterOutput = null; } optionString = Utils.getOption('U', options); int debugLevel = 0; if (optionString.length() != 0) { try { debugLevel = Integer.parseInt(optionString); } catch (NumberFormatException e) { throw new Exception(optionString + "is an illegal value for option -U"); } } setDebugLevel(debugLevel); optionString = Utils.getOption('Y', options); if (optionStri
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -