📄 flr.java
字号:
if (m_BoundsFile.toString() != "") {
options[current++] = "-B";
options[current++] = "" + getBoundsFile();
}
while (current < options.length) {
options[current++] = "";
}
return options;
} // getOptions
/**
* Get rhoa
* @return the value of this parameter
*/
public double getRhoa() {
return m_Rhoa;
}
/**
* Get boundaries File
* @return the value of this parameter
*/
public String getBoundsFile() {
return m_BoundsFile.toString();
}
/**
* Get ShowRules parameter
* @return the value of this parameter
*/
public boolean getShowRules() {
return m_showRules;
}
/**
* Set rhoa
* @param newRhoa sets the rhoa value
* @throws Exception if rhoa is not in range [0,1]
*/
public void setRhoa(double newRhoa) throws Exception {
if (newRhoa < 0 || newRhoa > 1) {
throw new Exception(
"Vigilance parameter (rhoa) should be a real number in range [0,1]!!!");
}
m_Rhoa = newRhoa;
}
/**
* Set Boundaries File
* @param newBoundsFile a new file containing the boundaries
* @throws Exception if the Bounds file is incompatible with the training set
* or missing
*/
public void setBoundsFile(String newBoundsFile) {
m_BoundsFile = new File(newBoundsFile);
}
/**
* Set ShowRules flag
* @param flag the new value of this parameter
*/
public void setShowRules(boolean flag) {
m_showRules = flag;
}
/**
* Sets the metric space from the training set using the min-max stats, in case -B option is not used.
* @param data is the training set
*/
public void setBounds(Instances data) {
// Initialize minmax stats
bounds = new FuzzyLattice(data.numAttributes() - 1);
int k = 0;
for (int i = 0; i < data.numAttributes(); i++) {
if (i != data.classIndex()) {
AttributeStats stats = data.attributeStats(i);
bounds.setMin(k, stats.numericStats.min);
bounds.setMax(k, stats.numericStats.max);
k = k + 1;
} //if
} //for
} //setBounds
/**
* Checks the metric space
*/
public void checkBounds() {
for (int i = 0; i < bounds.length(); i++) {
if (bounds.getMin(i) == bounds.getMax(i))
bounds.setMax(i, bounds.getMax(i) + EPSILON);
}
}
/**
* Returns the tip text for this property
* @return tip text for this property suitable for
* displaying in the explorer/experimenter gui
*/
public String rhoaTipText() {
return " The vigilance parameter value" + " (default = 0.75)";
}
/**
* Returns the tip text for this property
* @return tip text for this property suitable for
* displaying in the explorer/experimenter gui
*/
public String boundsFileTipText() {
return " Point the filename containing the metric space";
}
/**
* Returns the tip text for this property
* @return tip text for this property suitable for
* displaying in the explorer/experimenter gui
*/
public String showRulesTipText() {
return " If true, displays the ruleset.";
}
/**
* Returns the value of the named measure
* @param additionalMeasureName the name of the measure to query for its value
* @return the value of the named measure
* @exception IllegalArgumentException if the named measure is not supported
*/
public double getMeasure(String additionalMeasureName) {
if (additionalMeasureName.compareToIgnoreCase("measureNumRules") == 0) {
return measureNumRules();
}
else {
throw new IllegalArgumentException(additionalMeasureName +
" not supported (FLR)");
}
}
/**
* Returns an enumeration of the additional measure names
* @return an enumeration of the measure names
*/
public Enumeration emerateMeasures() {
Vector newVector = new Vector(1);
newVector.addElement("measureNumRules");
return newVector.elements();
}
/**
* Additional measure Number of Rules
* @return the number of rules induced
*/
public double measureNumRules() {
if (learnedCode == null)
return 0.0;
else
return (double) learnedCode.size();
}
/**
* Returns a description of the classifier suitable for
* displaying in the explorer/experimenter gui
* @return the description
*/
public String globalInfo() {
return "Fuzzy Lattice Reasoning Classifier (FLR) v5.0"
+
"The current version can be used for classification using numeric predictors.";
}
/**
* Main method for testing this class.
*
* @param args should contain command line arguments for evaluation
* (see Evaluation).
*/
public static void main(String[] args) {
try {
System.out.println(Evaluation.evaluateModel(new FLR(), args));
}
catch (Exception e) {
System.out.println(e.getMessage());
}
}
/**
* <p>Fuzzy Lattice implementation in WEKA </p>
*
* @author Ioannis N. Athanasiadis
* email: ionathan@iti.gr
* alias: ionathan@ieee.org
* @version 5.0
*/
private class FuzzyLattice
implements Serializable {
private double min[];
private double max[];
private int categ;
private String className;
//Constructors
/**
* Constructs a Fuzzy Lattice from a instance
* @param dR the instance
* @param bounds the boundaries file
*/
public FuzzyLattice(Instance dR, FuzzyLattice bounds) {
min = new double[dR.numAttributes() - 1];
max = new double[dR.numAttributes() - 1];
int k = 0;
for (int i = 0; i < dR.numAttributes(); i++) {
if (i != dR.classIndex()) {
if (!dR.isMissing(i)) {
min[k] = (dR.value(i) > bounds.getMin(k)) ? dR.value(i) :
bounds.getMin(k);
max[k] = (dR.value(i) < bounds.getMax(k)) ? dR.value(i) :
bounds.getMax(k);
k = k + 1;
} //if(!dR.isMissing(i))
else {
min[k] = bounds.getMax(k);
max[k] = bounds.getMin(k);
k = k + 1;
} //else
} //if(i!=dR.classIndex())
} //for (int i=0; i<dR.numAttributes();i++)
categ = (int) dR.value(dR.classIndex());
className = dR.stringValue(dR.classIndex());
} //FuzzyLattice
/**
* Constructs an empty Fuzzy Lattice of a specific dimension pointing
* in Class "Metric Space" (-1)
* @param length the dimention of the Lattice
*/
public FuzzyLattice(int length) {
min = new double[length];
max = new double[length];
for (int i = 0; i < length; i++) {
min[i] = 0;
max[i] = 0;
}
categ = -1;
className = "Metric Space";
}
/**
* Converts a String to a Fuzzy Lattice pointing in Class "Metric Space" (-1)
* Note that the input String should be compatible with the toString() method.
* @param rule the input String.
*/
public FuzzyLattice(String rule) {
int size = 0;
for (int i = 0; i < rule.length(); i++) {
String s = rule.substring(i, i + 1);
if (s.equalsIgnoreCase("[")) {
size++;
}
}
min = new double[size];
max = new double[size];
int i = 0;
int k = 0;
String temp = "";
Vector v = new Vector();
int s = 0;
do {
String character = rule.substring(s, s + 1);
temp = temp + character;
if (character.equalsIgnoreCase(" ")) {
if (!temp.equalsIgnoreCase(" ")) {
k = k + 1;
if (k % 4 == 2) {
min[i] = Double.parseDouble(temp);
} //if
else if (k % 4 == 3) {
max[i] = Double.parseDouble(temp);
i = i + 1;
} //else
} // if (!temp.equalsIgnoreCase(" ") ){
temp = "";
} //if (character.equalsIgnoreCase(seperator)){
s = s + 1;
}
while (i < size);
categ = -1;
className = "Metric Space";
}
// Functions
/**
* Calculates the valuation function of the FuzzyLattice
* @param bounds corresponding boundaries
* @return the value of the valuation function
*/
public double valuation(FuzzyLattice bounds) {
double resp = 0.0;
for (int i = 0; i < min.length; i++) {
resp += 1 -
(min[i] - bounds.getMin(i)) / (bounds.getMax(i) - bounds.getMin(i));
resp += (max[i] - bounds.getMin(i)) /
(bounds.getMax(i) - bounds.getMin(i));
}
return resp;
}
/**
* Calcualtes the length of the FuzzyLattice
* @return the length
*/
public int length() {
return min.length;
}
/**
* Implements the Join Function
* @param lattice the second fuzzy lattice
* @return the joint lattice
*/
public FuzzyLattice join(FuzzyLattice lattice) { // Lattice Join
FuzzyLattice b = new FuzzyLattice(lattice.length());
int i;
for (i = 0; i < lattice.min.length; i++) {
b.min[i] = (lattice.min[i] < min[i]) ? lattice.min[i] :
min[i];
b.max[i] = (lattice.max[i] > max[i]) ? lattice.max[i] :
max[i];
}
b.categ = categ;
b.className = className;
return b;
}
// Get-Set Functions
public int getCateg() {
return categ;
}
public void setCateg(int i) {
categ = i;
}
public String getClassName() {
return className;
}
public void setClassName(String s) {
className = s;
}
public double getMin(int i) {
return min[i];
}
public double getMax(int i) {
return max[i];
}
public void setMin(int i, double val) {
min[i] = val;
}
public void setMax(int i, double val) {
max[i] = val;
}
/**
* Returns a description of the Fuzzy Lattice
* @return the Fuzzy Lattice and the corresponding Class
*/
public String toString() {
String rule = "";
for (int i = 0; i < min.length; i++) {
rule = rule + "[ " + min[i] + " " + max[i] + " ] ";
}
rule = rule + "in Class: " + className + " \n";
return rule;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -