/** * Gets the index of an option or flag indicated by a flag "-Char" from the * given array of strings. Stops searching at the first marker "--". * * @param flag the character indicating the option. * @param options the array of strings containing all the options. * @return the position if found, or -1 otherwise */ public static int getOptionPos(char flag, String[] options) { return getOptionPos("" + flag, options); }
/** * Gets the index of an option or flag indicated by a flag "-Char" from the * given array of strings. Stops searching at the first marker "--". * * @param flag the character indicating the option. * @param options the array of strings containing all the options. * @return the position if found, or -1 otherwise */ public static int getOptionPos(char flag, String[] options) { return getOptionPos("" + flag, options); }
/** * Checks if the given array contains the flag "-String". Stops searching at * the first marker "--". If the flag is found, it is replaced with the empty * string. * * @param flag the String indicating the flag. * @param options the array of strings containing all the options. * @return true if the flag was found * @exception Exception if an illegal option was found */ public static boolean getFlag(String flag, String[] options) throws Exception { int pos = getOptionPos(flag, options); if (pos > -1) { options[pos] = ""; } return (pos > -1); }
/** * Checks if the given array contains the flag "-String". Stops searching at * the first marker "--". If the flag is found, it is replaced with the empty * string. * * @param flag the String indicating the flag. * @param options the array of strings containing all the options. * @return true if the flag was found * @exception Exception if an illegal option was found */ public static boolean getFlag(String flag, String[] options) throws Exception { int pos = getOptionPos(flag, options); if (pos > -1) { options[pos] = ""; } return (pos > -1); }
/** * Parses an array option, returns all the occurrences of the option as a string array. * * @param options the option array to use * @param option the option to look for in the options array (no leading dash) * @return the parsed value (or default value if option not present) * @throws Exception if parsing of value fails */ public static String[] parse(String[] options, String option) throws Exception { List<String> result = new ArrayList<>(); while (Utils.getOptionPos(option, options) > -1) result.add(Utils.getOption(option, options)); return result.toArray(new String[result.size()]); }
/** * Parses an array option, returns all the occurrences of the option as a string array. * * @param options the option array to use * @param option the option to look for in the options array (no leading dash) * @return the parsed value (or default value if option not present) * @throws Exception if parsing of value fails */ public static String[] parse(String[] options, String option) throws Exception { List<String> result = new ArrayList<>(); while (Utils.getOptionPos(option, options) > -1) result.add(Utils.getOption(option, options)); return result.toArray(new String[result.size()]); }
@Override public void setOptions(String[] options) throws Exception { m_Is = (Utils.getOptionPos("Is",options) >= 0) ? Integer.parseInt(Utils.getOption("Is", options)) : m_Is; m_Iy = (Utils.getOptionPos("Iy",options) >= 0) ? Integer.parseInt(Utils.getOption("Iy", options)) : m_Iy; m_Payoff = (Utils.getOptionPos('P',options) >= 0) ? Integer.parseInt(Utils.getOption('P', options)) : m_Payoff; super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); super.setOptions(options); }
@Override public void setOptions(String[] options) throws Exception { m_I = (Utils.getOptionPos('I',options) >= 0) ? Integer.parseInt(Utils.getOption('I',options)) : m_I; super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); super.setOptions(options); }
/** * Parses a given list of options. Valid options are:<p> * * -K <br> * Use kernel estimation for modelling numeric attributes rather than * a single normal distribution.<p> * * -D <br> * Use supervised discretization to process numeric attributes. * * @param options the list of options as an array of strings * @exception Exception if an option is not supported */ public void setOptions(String[] options) throws Exception { //These are just examples, modify to suit your algorithm // boolean k = Utils.getFlag('K', options); // boolean d = Utils.getFlag('D', options); // if (k && d) { // throw new IllegalArgumentException( // "Can't use both kernel density estimation and discretization!"); // } // setUseSupervisedDiscretization(d); // setUseKernelEstimator(k); roa = (Utils.getOptionPos("P",options) >= 0) ? Double.parseDouble(Utils.getOption("P", options)) : roa; m_userankstoclass= (Utils.getOptionPos("K",options) >= 0); activity_report = (Utils.getOptionPos("Rt",options) >= 0) ? Utils.getOption("Rt", options) : ""; super.setOptions(options); }
/** * SetClassesFromOptions. * @note: there is a similar function in Exlorer.prepareData(D) but that function can only take -C from the dataset options. */ public static void setClassesFromOptions(Instances D, String options[]) throws Exception { try { // get L int L = (Utils.getOptionPos('C', options) >= 0) ? Integer.parseInt(Utils.getOption('C',options)) : Integer.parseInt(Utils.getOption('c',options)); // if negative, then invert first if ( L < 0) { L = -L; D = MLUtils.switchAttributes(D,L); } // set L D.setClassIndex(L); } catch(Exception e) { e.printStackTrace(); //System.err.println("[Error] Failed to Set Options from Command Line -- Check\n\t the spelling of the base classifier;\n \t that options are specified in the correct order (respective to the '--' divider); and\n\t that the class index is set properly."); //System.exit(1); throw new Exception ("Error] Failed to Set Classes from options."); } }
/** * Prepares the class index of the data. * * @param data the data to prepare * @throws Exception if preparation fails */ public static void prepareData(Instances data) throws Exception { String doptions[] = null; try { doptions = MLUtils.getDatasetOptions(data); } catch(Exception e) { throw new Exception("[Error] Failed to Get Options from @Relation Name", e); } int c = (Utils.getOptionPos('C', doptions) >= 0) ? Integer.parseInt(Utils.getOption('C',doptions)) : Integer.parseInt(Utils.getOption('c',doptions)); // if negative, then invert if ( c < 0) { c = -c; data = MLUtils.switchAttributes(data,c); } // set c data.setClassIndex(c); }