📄 stringkernel.java
字号:
*/ public String globalInfo() { return "Implementation of the subsequence kernel (SSK) as described in [1] " + "and of the subsequence kernel with lambda pruning (SSK-LP) as " + "described in [2].\n\n" + "For more information, see\n\n" + getTechnicalInformation().toString(); } /** * Returns an instance of a TechnicalInformation object, containing * detailed information about the technical background of this class, * e.g., paper reference or book this class is based on. * * @return the technical information about this class */ public TechnicalInformation getTechnicalInformation() { TechnicalInformation result; TechnicalInformation additional; result = new TechnicalInformation(Type.ARTICLE); result.setValue(Field.AUTHOR, "Huma Lodhi and Craig Saunders and John Shawe-Taylor and Nello Cristianini and Christopher J. C. H. Watkins"); result.setValue(Field.YEAR, "2002"); result.setValue(Field.TITLE, "Text Classification using String Kernels"); result.setValue(Field.JOURNAL, "Journal of Machine Learning Research"); result.setValue(Field.VOLUME, "2"); result.setValue(Field.PAGES, "419-444"); result.setValue(Field.HTTP, "http://www.jmlr.org/papers/v2/lodhi02a.html"); additional = result.add(Type.TECHREPORT); additional.setValue(Field.AUTHOR, "F. Kleedorfer and A. Seewald"); additional.setValue(Field.YEAR, "2005"); additional.setValue(Field.TITLE, "Implementation of a String Kernel for WEKA"); additional.setValue(Field.INSTITUTION, "Oesterreichisches Forschungsinstitut fuer Artificial Intelligence"); additional.setValue(Field.ADDRESS, "Wien, Austria"); additional.setValue(Field.NUMBER, "TR-2005-13"); return result; } /** * Returns an enumeration describing the available options. * * @return an enumeration of all the available options. */ public Enumeration listOptions() { Vector result; Enumeration en; String desc; String param; int i; SelectedTag tag; result = new Vector(); en = super.listOptions(); while (en.hasMoreElements()) result.addElement(en.nextElement()); desc = ""; param = ""; for (i = 0; i < TAGS_PRUNING.length; i++) { if (i > 0) param += "|"; tag = new SelectedTag(TAGS_PRUNING[i].getID(), TAGS_PRUNING); param += "" + tag.getSelectedTag().getID(); desc += "\t" + tag.getSelectedTag().getID() + " = " + tag.getSelectedTag().getReadable() + "\n"; } result.addElement(new Option( "\tThe pruning method to use:\n" + desc + "\t(default: " + PRUNING_NONE + ")", "P", 1, "-P <" + param + ">")); result.addElement(new Option( "\tThe size of the cache (a prime number).\n" + "\t(default: 250007)", "C", 1, "-C <num>")); result.addElement(new Option( "\tThe size of the internal cache (a prime number).\n" + "\t(default: 200003)", "IC", 1, "-IC <num>")); result.addElement(new Option( "\tThe lambda constant. Penalizes non-continuous subsequence\n" + "\tmatches. Must be in (0,1).\n" + "\t(default: 0.5)", "L", 1, "-L <num>")); result.addElement(new Option( "\tThe length of the subsequence.\n" + "\t(default: 3)", "ssl", 1, "-ssl <num>")); result.addElement(new Option( "\tThe maximum length of the subsequence.\n" + "\t(default: 9)", "ssl-max", 1, "-ssl-max <num>")); result.addElement(new Option( "\tUse normalization.\n" + "\t(default: no)", "N", 0, "-N")); return result.elements(); } /** * Parses a given list of options. <p/> * <!-- options-start --> * Valid options are: <p/> * * <pre> -D * Enables debugging output (if available) to be printed. * (default: off)</pre> * * <pre> -no-checks * Turns off all checks - use with caution! * (default: checks on)</pre> * * <pre> -P <0|1> * The pruning method to use: * 0 = No pruning * 1 = Lambda pruning * (default: 0)</pre> * * <pre> -C <num> * The size of the cache (a prime number). * (default: 250007)</pre> * * <pre> -IC <num> * The size of the internal cache (a prime number). * (default: 200003)</pre> * * <pre> -L <num> * The lambda constant. Penalizes non-continuous subsequence * matches. Must be in (0,1). * (default: 0.5)</pre> * * <pre> -ssl <num> * The length of the subsequence. * (default: 3)</pre> * * <pre> -ssl-max <num> * The maximum length of the subsequence. * (default: 9)</pre> * * <pre> -N * Use normalization. * (default: no)</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 tmpStr; tmpStr = Utils.getOption('P', options); if (tmpStr.length() != 0) setPruningMethod( new SelectedTag(Integer.parseInt(tmpStr), TAGS_PRUNING)); else setPruningMethod( new SelectedTag(PRUNING_NONE, TAGS_PRUNING)); tmpStr = Utils.getOption('C', options); if (tmpStr.length() != 0) setCacheSize(Integer.parseInt(tmpStr)); else setCacheSize(250007); tmpStr = Utils.getOption("IC", options); if (tmpStr.length() != 0) setInternalCacheSize(Integer.parseInt(tmpStr)); else setInternalCacheSize(200003); tmpStr = Utils.getOption('L', options); if (tmpStr.length() != 0) setLambda(Double.parseDouble(tmpStr)); else setLambda(0.5); tmpStr = Utils.getOption("ssl", options); if (tmpStr.length() != 0) setSubsequenceLength(Integer.parseInt(tmpStr)); else setSubsequenceLength(3); tmpStr = Utils.getOption("ssl-max", options); if (tmpStr.length() != 0) setMaxSubsequenceLength(Integer.parseInt(tmpStr)); else setMaxSubsequenceLength(9); setUseNormalization(Utils.getFlag('N', options)); if (getMaxSubsequenceLength()<2*getSubsequenceLength()) { throw new IllegalArgumentException("Lambda Pruning forbids even contiguous substring matches! " + "Use a bigger value for ssl-max (at least 2*ssl)."); } super.setOptions(options); } /** * Gets the current settings of the Kernel. * * @return an array of strings suitable for passing to setOptions */ public String[] getOptions() { int i; Vector result; String[] options; result = new Vector(); options = super.getOptions(); for (i = 0; i < options.length; i++) result.add(options[i]); result.add("-P"); result.add("" + m_PruningMethod); result.add("-C"); result.add("" + getCacheSize()); result.add("-IC"); result.add("" + getInternalCacheSize()); result.add("-L"); result.add("" + getLambda()); result.add("-ssl"); result.add("" + getSubsequenceLength()); result.add("-ssl-max"); result.add("" + getMaxSubsequenceLength()); if (getUseNormalization()) result.add("-L"); return (String[]) result.toArray(new String[result.size()]); } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String pruningMethodTipText() { return "The pruning method."; } /** * Sets the method used to for pruning. * * @param value the pruning method to use. */ public void setPruningMethod(SelectedTag value) { if (value.getTags() == TAGS_PRUNING) m_PruningMethod = value.getSelectedTag().getID(); } /** * Gets the method used for pruning. * * @return the pruning method to use. */ public SelectedTag getPruningMethod() { return new SelectedTag(m_PruningMethod, TAGS_PRUNING); } /** * Sets the size of the cache to use (a prime number) * * @param value the size of the cache */ public void setCacheSize(int value) { if (value >= 0) { m_cacheSize = value; clean(); } else { System.out.println( "Cache size cannot be smaller than 0 (provided: " + value + ")!"); } } /** * Gets the size of the cache * * @return the cache size */ public int getCacheSize() { return m_cacheSize; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String cacheSizeTipText() { return "The size of the cache (a prime number)."; } /** * sets the size of the internal cache for intermediate results. Memory * consumption is about 16x this amount in bytes. Only use when lambda * pruning is switched off. * * @param value the size of the internal cache */ public void setInternalCacheSize(int value) { if (value >= 0) { m_internalCacheSize = value; clean(); } else { System.out.println( "Cache size cannot be smaller than 0 (provided: " + value + ")!"); } } /** * Gets the size of the internal cache * * @return the cache size */ public int getInternalCacheSize() { return m_internalCacheSize; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String internalCacheSizeTipText() { return "The size of the internal cache (a prime number)."; } /** * Sets the length of the subsequence. * * @param value the length */ public void setSubsequenceLength(int value) { m_subsequenceLength = value; } /** * Returns the length of the subsequence * * @return the length */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -