Hello Xiaoxu, If I understand how the 'scaling' is supposed to work then you have accomplished your goal correctly. But it might be that you don't need to use a large number of extra rules to do it. Consider the example included below.
;;;;;;;;;;;;;;;;;;;;;;;;;; code start ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Test of the FuzzyJess extensions and introducing a 'rule scaling' ;; concept as per example of Xiaoxu Ren on Jess Users list ;; ;; The idea is to scale the output fuzzy values (given a rule scaling ;; factor) before they are used in the global contribution ;; ;; Simple example measures temperature and pressure and based on the ;; values sets a single valve to some position ;; (import nrc.fuzzy.*) (load-package nrc.fuzzy.jess.FuzzyFunctions) (deftemplate tempFact (slot val)) (deftemplate flowFact (slot val)) (deftemplate valveFact (slot val)) (deftemplate aFact (slot val)) (defglobal ?*tempFvar* = (new FuzzyVariable "Temperature" -30.0 100.0 "degrees C")) (defglobal ?*flowFvar* = (new FuzzyVariable "Flow" 0.0 100.0 "litres/minute")) (defglobal ?*valveFvar* = (new FuzzyVariable "ValvePosition" 0.0 1.0 "")) (defrule init => (?*tempFvar* addTerm "cold" (new ZFuzzySet 5.0 15.0)) (?*tempFvar* addTerm "warm" (new PIFuzzySet 15.0 7.5)) (?*tempFvar* addTerm "hot" (new SFuzzySet 15.0 25.0)) (?*flowFvar* addTerm "weak" (new ZFuzzySet 25.0 50.0)) (?*flowFvar* addTerm "normal" (new PIFuzzySet 50.0 25.0)) (?*flowFvar* addTerm "high" (new SFuzzySet 50.0 75.0)) (?*valveFvar* addTerm "low" (new ZFuzzySet 0.25 0.50)) (?*valveFvar* addTerm "medium" (new PIFuzzySet 0.50 0.25)) (?*valveFvar* addTerm "high" (new SFuzzySet 0.50 0.75)) ;; current temp is 10.0 +/- 1.0 (bind ?tempFval (new TriangleFuzzySet 9.0 10.0 11.0)) (assert (tempFact (val (new FuzzyValue ?*tempFvar* ?tempFval)))) ;; current flow is 35.0 +/- 2.0 (bind ?flowFval (new TriangleFuzzySet 33.0 35.0 37.0)) (assert (flowFact (val (new FuzzyValue ?*flowFvar* ?flowFval)))) ) (defrule ColdAndWeakThenSetValveHigh (tempFact (val ?t&:(fuzzy-match ?t "cold"))) (flowFact (val ?p&:(fuzzy-match ?p "weak"))) => (bind ?valveFval (new FuzzyValue ?*valveFvar* "high")) (bind ?a (assert (aFact (val ?valveFval)))) (bind ?val (fact-slot-value ?a val)) (bind ?valveFval (?val fuzzyScale (* 0.8 (?val getMaxY)))) (retract ?a) (assert (valveFact (val ?valveFval))) ) (defrule WarmAndNormalThenSetValveMedium (tempFact (val ?t&:(fuzzy-match ?t "cold"))) (flowFact (val ?p&:(fuzzy-match ?p "weak"))) => (bind ?valveFval (new FuzzyValue ?*valveFvar* "medium")) (bind ?a (assert (aFact (val ?valveFval)))) (bind ?val (fact-slot-value ?a val)) (bind ?valveFval (?val fuzzyScale (* 0.6 (?val getMaxY)))) (retract ?a) (assert (valveFact (val ?valveFval))) ) (defrule SetValvePosition (declare (salience -100)) (valveFact (val ?valveFval)) => (bind ?valvePos (?valveFval momentDefuzzify)) (printout t "The valve should be set to position: " ?valvePos crlf) ) ;;;;;;;;;;;;;;;;;;;;;;;;;; code end ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; The change from you example is to do everything in the rule. The code on the RHS of the two fuzzy rules is: (bind ?valveFval (new FuzzyValue ?*valveFvar* "high")) (bind ?a (assert (aFact (val ?valveFval)))) (bind ?val (fact-slot-value ?a val)) (bind ?valveFval (?val fuzzyScale (* 0.8 (?val getMaxY)))) (retract ?a) (assert (valveFact (val ?valveFval))) The asserted aFact fuzzy value has its value 'clipped' based on the fuzzy matching on the LHS of the rule. Then it is scaled and used as the 'actual' output of the rule. This second asserted fact will be 'clipped' again but will have no impact. You could even create a function to do something like: (deffunction scaleFuzzyValue (?Fval ?scaleFactor) (bind ?a (assert (aFact (val ?Fval)))) (bind ?val (fact-slot-value ?a val)) (retract ?a) (?val fuzzyScale (* ?scaleFactor (?val getMaxY))) ) and the rule is transformed to: (defrule ColdAndWeakThenSetValveHigh (tempFact (val ?t&:(fuzzy-match ?t "cold"))) (flowFact (val ?p&:(fuzzy-match ?p "weak"))) => (assert (valveFact (val (scaleFuzzyValue (new FuzzyValue ?*valveFvar* "high") 0.8)))) ) My testing of this isn't exhaustive but it seems to be a sound approach. I've attached this working example using the scaleFuzzyValue function approach. The output I get from running this example is: The valve should be set to position: 0.6896655074222234 If I set the scaling to 1.0 and 1.0 for the 2 rules then this is similar to no scaling and the result is: The valve should be set to position: 0.6666652367481181 and is the same as you get if the call to scale the value is not in the program. The effect of the scaling is that the first rule ColdAndWeakThenSetValveHigh has more effect on the 'globally' computed value for the valve position and thus it shifts the result more towards a "high" result. I hope this makes sense to you. Cheers, Bob. Bob Orchard National Research Council of Canada Institute for Information Technology Ottawa, ON Canada ----- Original Message ----- From: "Xiaoxu Ren" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Wednesday, January 16, 2002 12:06 PM Subject: Re: JESS: Re: Any tools for converting Matlab FIS file to FuzzyJess? > Hi All, > > I am writing a Matlab function to convert the Matlab FIS file into Java. My > plan is to gererate a Jess batch file for the fuzzy rules and gererate a > Java file to run this batch file. When I finish, I will share it with JESS > users. Now I have a question. When using Matlab Fuzzy Logic Toolbox, the > generated fuzzy rule has a weight between 0 and 1. But I can not find this > feature in FuzzyJess. If I only use FuzzyJ, I think I can scale the output > FuzzyValue with the weight before doing the 'global contribution' by using > fuzzy union. But if I use FuzzyJess, according to the manual, "this global > contribution is done for the user automatically as part of the rule's > execution". I am wondering if the following rules can do the weighting > properly? > > > ;;the fuzzy rule 1 > (defrule rule1 "fuzzy rule 1" > (temp ?inputFval1&:(fuzzy-match ?inputFval1 "cold")) > (flow ?inputFval2&:(fuzzy-match ?inputFval2 "weak")) > => > (assert (hotValve_rule1 (new FuzzyValue > ?*output_hotValve_Fvar*"positive"))) ;temporary fact > (assert (coldValve_rule1 (new FuzzyValue ?*output_coldValve_Fvar* "zero"))) > ) > > ;;weighting rule 1 with weight 0.8 > (defrule weighting_rule1 "weighting fuzzy rule 1" > ?outRef1 <- (hotValve_rule1 ?outFVal1) > ?outRef2 <- (coldValve_rule1 ?outFVal2) > => > (assert (hotValve (?outFVal1 fuzzyScale (* 0.8 (?outFVal1 > getMaxY)))));scale the temporary fact with 0.8 > (assert (coldValve (?outFVal2 fuzzyScale (* 0.8 (?outFVal2 getMaxY))))) > (retract ?outRef1 ?outRef2 ) > ) > > > ... > > ;;the defuzzify procedure with low salience > (defrule defuzzify "the defuzzify rule" > (declare (salience -100)) > ?outRef1 <- (hotValve ?outFVal1) > ?outRef2 <- (coldValve ?outFVal2) > ?inRef1 <- (temp ?inFVal1) > ?inRef2 <- (flow ?inFVal2) > => > (bind ?hotValve-crist-output (?outFVal1 momentDefuzzify)) ;;defuzzify > theoutput Fuzzy Value > (store CRISP_HOTVALVE ?hotValve-crist-output);;store the crisp output > forJava > (store FUZZY_HOTVALVE ?outFVal1) > > (bind ?coldValve-crist-output (?outFVal2 momentDefuzzify));;defuzzify the > output Fuzzy Value > (store CRISP_COLDVALVE ?coldValve-crist-output);;store the crisp output for > Java > (store FUZZY_COLDVALVE ?outFVal2);;store the Fuzzy Value of output for Java > > (retract ?outRef1 ?outRef2 ?inRef1 ?inRef2 ) ;;clear the input and > outputFuzzyValue > ) > > > Thanks, > > Xiaoxu > ---------------------------------------- > Xiaoxu Ren > Dept. of ACSE > University of Sheffield > Mappin Street > Sheffield, S1 3JD, UK > Email: [EMAIL PROTECTED] > ---------------------------------------- > > ----- Original Message ----- > From: "Orchard, Bob" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Tuesday, January 08, 2002 11:33 PM > Subject: RE: JESS: Re: Any tools for converting Matlab FIS file to > FuzzyJess? > > > > Sione, > > > > The answer to all of your questions in 'no'. It might make an > > intersting project but there are no plans that I know of to > > do this. > > > > Bob. > > > > > > -----Original Message----- > > From: S F Palu [mailto:[EMAIL PROTECTED]] > > Sent: January 8, 2002 5:55 PM > > To: [EMAIL PROTECTED] > > Subject: JESS: Re: Any tools for converting Matlab FIS file to > > FuzzyJess? > > > > > > Hi All, > > > > Currently I am not aware of any tool that does this but there is one > called > > F.I.D.E (Fuzzy Inference Development Environment) > > from Aptronix, I have not used this tool before, but from their website , > it > > can generate M-files (MatLab) , Java , etc... . > > I do not know whether it works the other way round as you wanted , but it > is > > worth and inquiry. > > > > A question for Bob Orchard (FuzzyJ Author) , is if : > > - he is aware of anybody developing such tool . > > - Bob (and NRC) is working on such tool . > > - Any plan by (NRC) to develop such tool . > > - Has MathWorks (MatLab owner) ever approach Bob (and NRC), to co-develop > > such tool. > > > > I too work with MatLab-11 (5) with FuzzyLogic Toolbox, for simulation > > purposes, because it is quite fast to drag & drop > > Simulink blocks and Fuzzy Logic controller and you can see live result > > instantly. Once I am satisfied with the simulation results, > > then I try to write the instruction flow of this Simulink block diagrams > in > > JAVA. It has never occurred to me to find out if there is > > a tool that convert MatLab F.I.S to Java, FuzzyJ and JESS . I do my > learning > > in Java using JESS and FuzzyJ Toolkit. I know that > > the new version of MatLab-12 (6) has Java support , but I don't know if it > > has a tool to convert F.I.S into Java , perhaps if someone in > > this forum has version-12 (6) can tell us. It will be excellent for Java > > developers if any such tool is available. > > > > Thanks, > > Sione. Palu. > > > > > > > > > > > > ----- Original Message ----- > > From: "Xiaoxu Ren" <[EMAIL PROTECTED]> > > To: <[EMAIL PROTECTED]> > > Sent: Wednesday, January 09, 2002 6:35 AM > > Subject: JESS: Any tools for converting Matlab FIS file to FuzzyJess? > > > > > > > Hi Folks, > > > > > > I build a fuzzy system in Matlab by using Fuzzy Logic Toolbox. The fuzzy > > > rules are generated from the training data. Now I want to implement this > > > fuzzy system in Java and the FuzzyJ Toolkit seems the first choice. Does > > > anybody know any tools that I can use to convert the Matlab *.fis file > to > > > the FuzzyJess *.clp batch file? > > > > > > Regards, > > > > > > Xiaoxu > > > > > -------------------------------------------------------------------- > To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]' > in the BODY of a message to [EMAIL PROTECTED], NOT to the list > (use your own address!) List problems? Notify [EMAIL PROTECTED] > --------------------------------------------------------------------
scalingTest.clp
Description: Binary data
