📄 bayesianlogisticregression.java
字号:
if (Thres.length() != 0) { Threshold = Double.parseDouble(Thres); } //Set Hyperparameter Type String Hype = Utils.getOption('H', options); if (Hype.length() != 0) { HyperparameterSelection = Integer.parseInt(Hype); } //Set Hyperparameter Value String HyperValue = Utils.getOption('V', options); if (HyperValue.length() != 0) { HyperparameterValue = Double.parseDouble(HyperValue); } // Set hyper parameter range or list. String HyperparameterRange = Utils.getOption("R", options); //Set Prior class. String strPrior = Utils.getOption('P', options); if (strPrior.length() != 0) { PriorClass = Integer.parseInt(strPrior); } String folds = Utils.getOption('F', options); if (folds.length() != 0) { NumFolds = Integer.parseInt(folds); } String iterations = Utils.getOption('I', options); if (iterations.length() != 0) { maxIterations = Integer.parseInt(iterations); } NormalizeData = Utils.getFlag('N', options); //TODO: Implement this method for other options. Utils.checkForRemainingOptions(options); } /** * */ public String[] getOptions() { Vector result = new Vector(); //Add Debug Mode to options. result.add("-D"); //Add Tolerance value to options result.add("-Tl"); result.add("" + Tolerance); //Add Threshold value to options result.add("-S"); result.add("" + Threshold); //Add Hyperparameter value to options result.add("-H"); result.add("" + HyperparameterSelection); result.add("-V"); result.add("" + HyperparameterValue); result.add("-R"); result.add("" + HyperparameterRange); //Add Prior Class to options result.add("-P"); result.add("" + PriorClass); result.add("-F"); result.add("" + NumFolds); result.add("-I"); result.add("" + maxIterations); result.add("-N"); return (String[]) result.toArray(new String[result.size()]); } /** * Main method for testing this class. * * @param argv the options */ public static void main(String[] argv) { runClassifier(new BayesianLogisticRegression(), argv); } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String debugTipText() { return "Turns on debugging mode."; } /** * */ public void setDebug(boolean debugMode) { debug = debugMode; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String hyperparameterSelectionTipText() { return "Select the type of Hyperparameter to be used."; } /** * Get the method used to select the hyperparameter * * @return the method used to select the hyperparameter */ public SelectedTag getHyperparameterSelection() { return new SelectedTag(HyperparameterSelection, TAGS_HYPER_METHOD); } /** * Set the method used to select the hyperparameter * * @param newMethod the method used to set the hyperparameter */ public void setHyperparameterSelection(SelectedTag newMethod) { if (newMethod.getTags() == TAGS_HYPER_METHOD) { int c = newMethod.getSelectedTag().getID(); if (c >= 1 && c <= 3) { HyperparameterSelection = c; } else { throw new IllegalArgumentException("Wrong selection type, -H value should be: " + "1 for norm-based, 2 for CV-based and " + "3 for specific value"); } } } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String priorClassTipText() { return "The type of prior to be used."; } /** * Set the type of prior to use. * * @param newMethod the type of prior to use. */ public void setPriorClass(SelectedTag newMethod) { if (newMethod.getTags() == TAGS_PRIOR) { int c = newMethod.getSelectedTag().getID(); if (c == GAUSSIAN || c == LAPLACIAN) { PriorClass = c; } else { throw new IllegalArgumentException("Wrong selection type, -P value should be: " + "1 for Gaussian or 2 for Laplacian"); } } } /** * Get the type of prior to use. * * @return the type of prior to use */ public SelectedTag getPriorClass() { return new SelectedTag(PriorClass, TAGS_PRIOR); } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String thresholdTipText() { return "Set the threshold for classifiction. The logistic function doesn't " + "return a class label but an estimate of p(y=+1|B,x(i)). " + "These estimates need to be converted to binary class label predictions. " + "values above the threshold are assigned class +1."; } /** * Return the threshold being used. * * @return the threshold */ public double getThreshold() { return Threshold; } /** * Set the threshold to use. * * @param threshold the threshold to use */ public void setThreshold(double threshold) { Threshold = threshold; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String toleranceTipText() { return "This value decides the stopping criterion."; } /** * Get the tolerance value * * @return the tolerance value */ public double getTolerance() { return Tolerance; } /** * Set the tolerance value * * @param tolerance the tolerance value to use */ public void setTolerance(double tolerance) { Tolerance = tolerance; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String hyperparameterValueTipText() { return "Specific hyperparameter value. Used when the hyperparameter " + "selection method is set to specific value"; } /** * Get the hyperparameter value. Used when the hyperparameter * selection method is set to specific value * * @return the hyperparameter value */ public double getHyperparameterValue() { return HyperparameterValue; } /** * Set the hyperparameter value. Used when the hyperparameter * selection method is set to specific value * * @param hyperparameterValue the value of the hyperparameter */ public void setHyperparameterValue(double hyperparameterValue) { HyperparameterValue = hyperparameterValue; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String numFoldsTipText() { return "The number of folds to use for CV-based hyperparameter selection."; } /** * Return the number of folds for CV-based hyperparameter selection * * @return the number of CV folds */ public int getNumFolds() { return NumFolds; } /** * Set the number of folds to use for CV-based hyperparameter * selection * * @param numFolds number of folds to select */ public void setNumFolds(int numFolds) { NumFolds = numFolds; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String maxIterationsTipText() { return "The maximum number of iterations to perform."; } /** * Get the maximum number of iterations to perform * * @return the maximum number of iterations */ public int getMaxIterations() { return maxIterations; } /** * Set the maximum number of iterations to perform * * @param maxIterations maximum number of iterations */ public void setMaxIterations(int maxIterations) { this.maxIterations = maxIterations; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String normalizeDataTipText() { return "Normalize the data."; } /** * Returns true if the data is to be normalized first * * @return true if the data is to be normalized */ public boolean isNormalizeData() { return NormalizeData; } /** * Set whether to normalize the data or not * * @param normalizeData true if data is to be normalized */ public void setNormalizeData(boolean normalizeData) { NormalizeData = normalizeData; } /** * Returns the tip text for this property * * @return tip text for this property suitable for * displaying in the explorer/experimenter gui */ public String hyperparameterRangeTipText() { return "Hyperparameter value range. In case of CV-based Hyperparameters, " + "you can specify the range in two ways: \n" + "Comma-Separated: L: 3,5,6 (This will be a list of possible values.)\n" + "Range: R:0.01-316,3.16 (This will take values from 0.01-316 (inclusive) " + "in multiplications of 3.16"; } /** * Get the range of hyperparameter values to consider * during CV-based selection. * * @return the range of hyperparameters as a Stringe */ public String getHyperparameterRange() { return HyperparameterRange; } /** * Set the range of hyperparameter values to consider * during CV-based selection * * @param hyperparameterRange the range of hyperparameter values */ public void setHyperparameterRange(String hyperparameterRange) { HyperparameterRange = hyperparameterRange; } /** * Returns true if debug is turned on. * * @return true if debug is turned on */ public boolean isDebug() { return debug; } /** * Returns the revision string. * * @return the revision */ public String getRevision() { return RevisionUtils.extract("$Revision: 1.3 $"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -