// Testing basic funcionality of fuzzy sets private void runFuzzySetTestButton_Click(object sender, EventArgs e) { ClearDataSeries( ); // create 2 fuzzy sets to represent the Cool and Warm temperatures TrapezoidalFunction function1 = new TrapezoidalFunction(13, 18, 23, 28); FuzzySet fsCool = new FuzzySet("Cool", function1); TrapezoidalFunction function2 = new TrapezoidalFunction(23, 28, 33, 38); FuzzySet fsWarm = new FuzzySet("Warm", function2); double[,] coolValues = new double[20, 2]; for (int i = 10; i < 30; i++) { coolValues[i - 10, 0] = i; coolValues[i - 10, 1] = fsCool.GetMembership(i); } double[,] warmValues = new double[20, 2]; for (int i = 20; i < 40; i++) { warmValues[i - 20, 0] = i; warmValues[i - 20, 1] = fsWarm.GetMembership(i); } chart?.UpdateDataSeries("COOL", coolValues); chart?.UpdateDataSeries("WARM", warmValues); }
// Testing basic functionality of fuzzy sets private void runFuzzySetTestButton_Click(object sender, EventArgs e) { ClearDataSeries(); // create 2 fuzzy sets to represent the Cool and Warm temperatures FuzzySet fsCool = new FuzzySet("Cool", new TrapezoidalFunction(13, 18, 23, 28)); FuzzySet fsWarm = new FuzzySet("Warm", new TrapezoidalFunction(23, 28, 33, 38)); // get membership of some points to the cool fuzzy set double[,] coolValues = new double[20, 2]; for (int i = 10; i < 30; i++) { coolValues[i - 10, 0] = i; coolValues[i - 10, 1] = fsCool.GetMembership(i); } // getting memberships of some points to the warm fuzzy set double[,] warmValues = new double[20, 2]; for (int i = 20; i < 40; i++) { warmValues[i - 20, 0] = i; warmValues[i - 20, 1] = fsWarm.GetMembership(i); } // plot membership to a chart chart.UpdateDataSeries("COOL", coolValues); chart.UpdateDataSeries("WARM", warmValues); }
internal void GetMembership_VariousInputs_ReturnsExpectedResult(double input, double expected) { // Arrange var function = TriangularFunction.Create(2, 3, 4); var fuzzySet = new FuzzySet("some_fuzzy_state", function); // Act var result = fuzzySet.GetMembership(input); // Assert Assert.Equal(UnitInterval.Create(expected), result); Assert.Equal("some_fuzzy_state", fuzzySet.State.Value); }
private void btnFuzzy_Click(object sender, EventArgs e) { RuleInferenceEngine rie = new RuleInferenceEngine(); FuzzySet output = new FuzzySet("Output", -100, 100, 1); output.AddMembership("Cooling", new FuzzyReverseGrade(-50, 0)); output.AddMembership("Zero", new FuzzyTriangle(-50, 0, 50)); output.AddMembership("Heating", new FuzzyGrade(0, 50)); rie.AddFuzzySet(output.Name, output); FuzzySet tempError = new FuzzySet("Temperature Error", -4, 4, 0.05); tempError.AddMembership("Negative", new FuzzyReverseGrade(-2, 0)); tempError.AddMembership("Zero", new FuzzyTriangle(-2, 0, 2)); tempError.AddMembership("Positive", new FuzzyGrade(0, 2)); rie.AddFuzzySet(tempError.Name, tempError); FuzzySet tempErrorDot = new FuzzySet("Temperature Error", -10, 10, 0.1); tempErrorDot.AddMembership("Negative", new FuzzyReverseGrade(-5, 0)); tempErrorDot.AddMembership("Zero", new FuzzyTriangle(-5, 0, 5)); tempErrorDot.AddMembership("Positive", new FuzzyGrade(0, 5)); rie.AddFuzzySet(tempErrorDot.Name, tempErrorDot); /* * 1. If (e < 0) AND (er < 0) then Cool 0.5 & 0.0 = 0.0 * 2. If (e = 0) AND (er < 0) then Heat 0.5 & 0.0 = 0.0 * 3. If (e > 0) AND (er < 0) then Heat 0.0 & 0.0 = 0.0 * 4. If (e < 0) AND (er = 0) then Cool 0.5 & 0.5 = 0.5 * 5. If (e = 0) AND (er = 0) then No_Chng 0.5 & 0.5 = 0.5 * 6. If (e > 0) AND (er = 0) then Heat 0.0 & 0.5 = 0.0 * 7. If (e < 0) AND (er > 0) then Cool 0.5 & 0.5 = 0.5 * 8. If (e = 0) AND (er > 0) then Cool 0.5 & 0.5 = 0.5 * 9. If (e > 0) AND (er > 0) then Heat 0.0 & 0.5 = 0.0 */ Rule rule = new Rule("Rule 1"); rule.AddAntecedent(new Clause(tempError, "Is", "Negative")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative")); rule.Consequent = new Clause(output, "Is", "Cooling"); rie.AddRule(rule); rule = new Rule("Rule 2"); rule.AddAntecedent(new Clause(tempError, "Is", "Zero")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative")); rule.Consequent = new Clause(output, "Is", "Heating"); rie.AddRule(rule); rule = new Fuzzy.Rule("Rule 3"); rule.AddAntecedent(new Clause(tempError, "Is", "Positive")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative")); rule.Consequent = new Clause(output, "Is", "Heating"); rie.AddRule(rule); rule = new Rule("Rule 4"); rule.AddAntecedent(new Clause(tempError, "Is", "Negative")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero")); rule.Consequent = new Clause(output, "Is", "Cooling"); rie.AddRule(rule); rule = new Rule("Rule 5"); rule.AddAntecedent(new Clause(tempError, "Is", "Zero")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero")); rule.Consequent = new Clause(output, "Is", "Zero"); rie.AddRule(rule); rule = new Rule("Rule 6"); rule.AddAntecedent(new Clause(tempError, "Is", "Positive")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero")); rule.Consequent = new Clause(output, "Is", "Heating"); rie.AddRule(rule); rule = new Rule("Rule 7"); rule.AddAntecedent(new Clause(tempError, "Is", "Negative")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive")); rule.Consequent = new Clause(output, "Is", "Cooling"); rie.AddRule(rule); rule = new Rule("Rule 8"); rule.AddAntecedent(new Clause(tempError, "Is", "Zero")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive")); rule.Consequent = new Clause(output, "Is", "Cooling"); rie.AddRule(rule); rule = new Rule("Rule 9"); rule.AddAntecedent(new Clause(tempError, "Is", "Positive")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive")); rule.Consequent = new Clause(output, "Is", "Heating"); rie.AddRule(rule); tempError.X = -1.0; Console.WriteLine("For Temperature Error: {0}", tempError.X); Console.WriteLine("Negative: " + tempError.GetMembership("Negative").degree(-1.0)); Console.WriteLine("Zero: " + tempError.GetMembership("Zero").degree(-1.0)); Console.WriteLine("Positive: " + tempError.GetMembership("Positive").degree(-1.0)); tempErrorDot.X = 2.5; Console.WriteLine("For Temperature Error Dot: {0}", tempErrorDot.X); Console.WriteLine("Negative: " + tempErrorDot.GetMembership("Negative").degree(2.5)); Console.WriteLine("Zero: " + tempErrorDot.GetMembership("Zero").degree(2.5)); Console.WriteLine("Positive: " + tempErrorDot.GetMembership("Positive").degree(2.5)); rie.Infer(output); Console.WriteLine("output: " + output.X); FrmFuzzySet tempCanvas = new FrmFuzzySet("Output", output); FrmFuzzySet tempErrorCanvas = new FrmFuzzySet("Temp Error", tempError); FrmFuzzySet tempErrorDotCanvas = new FrmFuzzySet("Temp Error Dot", tempErrorDot); tempCanvas.Show(); tempErrorCanvas.Show(); tempErrorDotCanvas.Show(); }
public void Run() { RuleInferenceEngine rie = new RuleInferenceEngine(); FuzzySet output = new FuzzySet("Output", -100, 100, 1); output.AddMembership("Cooling", new FuzzyReverseGrade(-50, 0)); output.AddMembership("Zero", new FuzzyTriangle(-50, 0, 50)); output.AddMembership("Heating", new FuzzyGrade(0, 50)); rie.AddFuzzySet(output.Name, output); FuzzySet tempError = new FuzzySet("Temperature Error", -4, 4, 0.05); tempError.AddMembership("Negative", new FuzzyReverseGrade(-2, 0)); tempError.AddMembership("Zero", new FuzzyTriangle(-2, 0, 2)); tempError.AddMembership("Positive", new FuzzyGrade(0, 2)); rie.AddFuzzySet(tempError.Name, tempError); FuzzySet tempErrorDot = new FuzzySet("Temperature Error", -10, 10, 0.1); tempErrorDot.AddMembership("Negative", new FuzzyReverseGrade(-5, 0)); tempErrorDot.AddMembership("Zero", new FuzzyTriangle(-5, 0, 5)); tempErrorDot.AddMembership("Positive", new FuzzyGrade(0, 5)); rie.AddFuzzySet(tempErrorDot.Name, tempErrorDot); /* * 1. If (e < 0) AND (er < 0) then Cool 0.5 & 0.0 = 0.0 * 2. If (e = 0) AND (er < 0) then Heat 0.5 & 0.0 = 0.0 * 3. If (e > 0) AND (er < 0) then Heat 0.0 & 0.0 = 0.0 * 4. If (e < 0) AND (er = 0) then Cool 0.5 & 0.5 = 0.5 * 5. If (e = 0) AND (er = 0) then No_Chng 0.5 & 0.5 = 0.5 * 6. If (e > 0) AND (er = 0) then Heat 0.0 & 0.5 = 0.0 * 7. If (e < 0) AND (er > 0) then Cool 0.5 & 0.5 = 0.5 * 8. If (e = 0) AND (er > 0) then Cool 0.5 & 0.5 = 0.5 * 9. If (e > 0) AND (er > 0) then Heat 0.0 & 0.5 = 0.0 */ Rule rule = new Rule("Rule 1"); rule.AddAntecedent(new Clause(tempError, "Is", "Negative")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative")); rule.Consequent = new Clause(output, "Is", "Cooling"); rie.AddRule(rule); rule = new Rule("Rule 2"); rule.AddAntecedent(new Clause(tempError, "Is", "Zero")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative")); rule.Consequent = new Clause(output, "Is", "Heating"); rie.AddRule(rule); rule = new Rule("Rule 3"); rule.AddAntecedent(new Clause(tempError, "Is", "Positive")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Negative")); rule.Consequent = new Clause(output, "Is", "Heating"); rie.AddRule(rule); rule = new Rule("Rule 4"); rule.AddAntecedent(new Clause(tempError, "Is", "Negative")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero")); rule.Consequent = new Clause(output, "Is", "Cooling"); rie.AddRule(rule); rule = new Rule("Rule 5"); rule.AddAntecedent(new Clause(tempError, "Is", "Zero")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero")); rule.Consequent = new Clause(output, "Is", "Zero"); rie.AddRule(rule); rule = new Rule("Rule 6"); rule.AddAntecedent(new Clause(tempError, "Is", "Positive")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Zero")); rule.Consequent = new Clause(output, "Is", "Heating"); rie.AddRule(rule); rule = new Rule("Rule 7"); rule.AddAntecedent(new Clause(tempError, "Is", "Negative")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive")); rule.Consequent = new Clause(output, "Is", "Cooling"); rie.AddRule(rule); rule = new Rule("Rule 8"); rule.AddAntecedent(new Clause(tempError, "Is", "Zero")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive")); rule.Consequent = new Clause(output, "Is", "Cooling"); rie.AddRule(rule); rule = new Rule("Rule 9"); rule.AddAntecedent(new Clause(tempError, "Is", "Positive")); rule.AddAntecedent(new Clause(tempErrorDot, "Is", "Positive")); rule.Consequent = new Clause(output, "Is", "Heating"); rie.AddRule(rule); tempError.X = -1.0; WriteLine("For Temperature Error: {0}", tempError.X); WriteLine("Negative: " + tempError.GetMembership("Negative").degree(-1.0)); WriteLine("Zero: " + tempError.GetMembership("Zero").degree(-1.0)); WriteLine("Positive: " + tempError.GetMembership("Positive").degree(-1.0)); tempErrorDot.X = 2.5; WriteLine("For Temperature Error Dot: {0}", tempErrorDot.X); WriteLine("Negative: " + tempErrorDot.GetMembership("Negative").degree(2.5)); WriteLine("Zero: " + tempErrorDot.GetMembership("Zero").degree(2.5)); WriteLine("Positive: " + tempErrorDot.GetMembership("Positive").degree(2.5)); rie.Infer(output); WriteLine("output: " + output.X); /* * Application.EnableVisualStyles(); * Application.SetCompatibleTextRenderingDefault(false); * * * FrmFuzzySet tempCanvas = new FrmFuzzySet("Output", output); * FrmFuzzySet tempErrorCanvas = new FrmFuzzySet("Temp Error", tempError); * FrmFuzzySet tempErrorDotCanvas = new FrmFuzzySet("Temp Error Dot", tempErrorDot); * * SimpleUI.Instance.Display(tempCanvas); * SimpleUI.Instance.Display(tempErrorCanvas); * SimpleUI.Instance.Display(tempErrorDotCanvas); * * Application.Run(SimpleUI.Instance.View);*/ }
public override double GetMembership(Player Player) { return(Math.Max(fuzzySet1.GetMembership(Player), fuzzySet2.GetMembership(Player))); }
public double GetMemebership(Player entry) { return(FuzzySet.GetMembership(entry)); }
public float valueMediumStrenghty(float temperature) { return(mediumStrenght.GetMembership(temperature)); }
public float valueVeryHightStrenght(float temperature) { return(veryHightStrenght.GetMembership(temperature)); }
public float valueBigHumidity(float temperature) { return(bigHumidity.GetMembership(temperature)); }
public float valueLowStrenght(float temperature) { return(lowStrenght.GetMembership(temperature)); }
public float valueGoodHumidity(float temperature) { return(goodHumidity.GetMembership(temperature)); }
//funkcje zwracające wartość przynależności do przedziału dla podanej wilgotnosci public float valueSmallHumidity(float temperature) { return(smallHumidity.GetMembership(temperature)); }
public float valueTmpVeryHot(float temperature) { return(tmpVeryHot.GetMembership(temperature)); }
public float valueTmpMedium(float temperature) { return(tmpMedium.GetMembership(temperature)); }
public float valueTmpCold(float temperature) { return(tmpCold.GetMembership(temperature)); }