/* * FuzzyRule.java * * Created on July 5, 2002, 7:11 PM */ package uk.ac.leeds.ccg.projects.MedAction.FuzzyInference; /** * FuzzyRule is corresponding to fuzzy rule in Fuzzy Logic definition * * @author jianhui jin */ public class FuzzyRule implements java.io.Serializable{ // variable name in this rule private String[] variableName = {"","","","",""}; // fuzzy set name in this rule corresponding to the variable names' position above private String[] memberName = {"","","",""}; // fuzzification result for the fuzzy set corresponding to the fuzzy set position above private double[] memberDegree = null; // logic operator name definition private String[] operatorName = {"AND","OR","AND NOT","OR NOT"}; // output variable fuzzy set's name private String outMember = ""; // output degree private double outDegree; // confidence value in the range of 1 - 10 // the confidence of this rule, the result will time this value show it is // more important than others private int confidence = 1; /** Creates a new instance of FuzzyRule */ public FuzzyRule() { } /** * * @param vName varaible name * @param mName fuzzy set name corresponding to variable name above * @param opName operator name corresponding to member name above * @param outM output fuzzy set name * @param confidence confidence of this rule, 1 <= confidence <= 10 */ public FuzzyRule(String[] vName, String[] mName, String[] opName,String outM,int confidence) { this.setVariableName(vName); this.setMemberName(mName); this.setOutMember(outM); this.setOperatorName(opName); this.setConfidence(confidence); } // a set of input will result in a set of fuzzification // a rule may take of them, may only some of them into logic operation // since a fuzzificationResult object will contain all degrees for all members in a variable // for only one input value x. private void setDegree( FuzzificationResult[] f ) { Double[] temp = new Double[ variableName.length ]; String[] tempMember = null; Double[] tempDegree = null; for ( int i = 0; i < temp.length; i ++ ) { // from a variable, take out all fuzzy set name, and degrees for ( int j = 0; j < f.length; j ++ ) { if ( f[j].getVariableName().equalsIgnoreCase( this.variableName[i] ) ) { tempMember = f[j].getMemberName(); tempDegree = f[j].getMemberDegree(); break; } } // get the fuzzy set name and degree required for index i, for ( int m = 0; m < tempMember.length; m ++ ) { if( tempMember[m].equalsIgnoreCase( this.memberName[i] ) ) { temp[i] = tempDegree[m]; } } } // get double value memberDegree = new double[ temp.length ]; for ( int i = 0; i < temp.length; i ++ ) { memberDegree[ i ] = temp[ i ].doubleValue();} } // do logic operation private void doFuzzyOperation(){ outDegree=memberDegree[0]; for(int i=0;i 10) this.confidence = 10; else if (confidence < 1) this.confidence = 1; else this.confidence = confidence; } /** * * @return */ public int getConfidence() { return confidence; } }