davidgrupp / fuzzy-logic-sharp Goto Github PK
View Code? Open in Web Editor NEWFuzzy Logic Sharp for .NET
License: Apache License 2.0
Fuzzy Logic Sharp for .NET
License: Apache License 2.0
I've found out that once a calculation is made the premise is not reset when calculating for another value, thus calculating invalid values.
PremiseModifier value gets a value and it never gets a lower value, even on the Defuzzify method where it says //reset membership functions, it does nothing as the setter filters out setting a lower value.
I've fixed it for myself by adding a reset method which sets the PremiseModifier to zero.
In submited example I added for
loop to iterate through all water temperatures:
var water = new LinguisticVariable("Water");
var cold = water.MembershipFunctions.AddTrapezoid("Cold", 0, 0, 20, 40);
var warm = water.MembershipFunctions.AddTriangle("Warm", 30, 50, 70);
var hot = water.MembershipFunctions.AddTrapezoid("Hot", 50, 80, 100, 100);
var power = new LinguisticVariable("Power");
var low = power.MembershipFunctions.AddTriangle("Low", 0, 25, 50);
var high = power.MembershipFunctions.AddTriangle("High", 25, 50, 75);
IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Default();
var rule1 = Rule.If(water.Is(cold).Or(water.Is(warm))).Then(power.Is(high));
var rule2 = Rule.If(water.Is(hot)).Then(power.Is(low));
fuzzyEngine.Rules.Add(rule1, rule2);
// ------------------------ my edit ------------------------
for (int i = 0; i <= 100; i++)
{
var result = fuzzyEngine.Defuzzify(new { water = i });
Console.WriteLine($"water = {i} result= {result}");
}
// ------------------------ my edit ------------------------
Which give me:
water = 0 result = 50
water = 1 result = 50
water = 2 result = 50
water = 3 result = 50
water = 4 result = 50
water = 5 result = 50
water = 6 result = 50
water = 7 result = 50
water = 8 result = 50
water = 9 result = 50
water = 10 result = 50
water = 11 result = 50
water = 12 result = 50
water = 13 result = 50
water = 14 result = 50
water = 15 result = 50
water = 16 result = 50
water = 17 result = 50
water = 18 result = 50
water = 19 result = 50
water = 20 result = 50
water = 21 result = 50
water = 22 result = 50
water = 23 result = 50
water = 24 result = 50
water = 25 result = 50
water = 26 result = 50
water = 27 result = 50
water = 28 result = 50
water = 29 result = 50
water = 30 result = 50
water = 31 result = 50
water = 32 result = 50
water = 33 result = 50
water = 34 result = 50
water = 35 result = 50
water = 36 result = 50
water = 37 result = 50
water = 38 result = 50
water = 39 result = 50
water = 40 result = 50
water = 41 result = 50
water = 42 result = 50
water = 43 result = 50
water = 44 result = 50
water = 45 result = 50
water = 46 result = 50
water = 47 result = 50
water = 48 result = 50
water = 49 result = 50
water = 50 result = 50
water = 51 result = 49.193548387096776
water = 52 result = 48.4375
water = 53 result = 47.72727272727273
water = 54 result = 47.05882352941176
water = 55 result = 46.42857142857144
water = 56 result = 45.833333333333336
water = 57 result = 45.27027027027027
water = 58 result = 44.73684210526316
water = 59 result = 44.23076923076923
water = 60 result = 43.75000000000001
water = 61 result = 43.29268292682927
water = 62 result = 42.857142857142854
water = 63 result = 42.44186046511628
water = 64 result = 42.04545454545455
water = 65 result = 41.666666666666664
water = 66 result = 41.30434782608696
water = 67 result = 40.95744680851064
water = 68 result = 40.625
water = 69 result = 40.30612244897959
water = 70 result = 40
water = 71 result = 39.705882352941174
water = 72 result = 39.42307692307693
water = 73 result = 39.15094339622641
water = 74 result = 38.888888888888886
water = 75 result = 38.63636363636364
water = 76 result = 38.39285714285714
water = 77 result = 38.1578947368421
water = 78 result = 37.931034482758626
water = 79 result = 37.71186440677966
water = 80 result = 37.5
water = 81 result = 37.5
water = 82 result = 37.5
water = 83 result = 37.5
water = 84 result = 37.5
water = 85 result = 37.5
water = 86 result = 37.5
water = 87 result = 37.5
water = 88 result = 37.5
water = 89 result = 37.5
water = 90 result = 37.5
water = 91 result = 37.5
water = 92 result = 37.5
water = 93 result = 37.5
water = 94 result = 37.5
water = 95 result = 37.5
water = 96 result = 37.5
water = 97 result = 37.5
water = 98 result = 37.5
water = 99 result = 37.5
water = 100 result = 37.5
Why there are no result
between 50
and 75
? Also, there are no result
between 25
and 50
.
I have a question based on the following example:
How is information about the current water temperature received so that it can be assigned to a group (cold, hot).
In this code I have given only the water temperature ranges (hot, cold). And how to send information to this range about the current temperature and start the fuzzy logic process
Thanks in advance
var water = new LinguisticVariable("Water");
var cold = water.MembershipFunctions.AddTrapezoid("Cold", 0, 0, 20, 40);
var warm = water.MembershipFunctions.AddTriangle("Warm", 30, 50, 70);
var hot = water.MembershipFunctions.AddTrapezoid("Hot", 50, 80, 100, 100);
var power = new LinguisticVariable("Power");
var low = power.MembershipFunctions.AddTriangle("Low", 0, 25, 50);
var high = power.MembershipFunctions.AddTriangle("High", 25, 50, 75);
IFuzzyEngine fuzzyEngine = new FuzzyEngineFactory().Default();
var rule1 = Rule.If(water.Is(cold).Or(water.Is(warm))).Then(power.Is(high));
var rule2 = Rule.If(water.Is(hot)).Then(power.Is(low));
fuzzyEngine.Rules.Add(rule1, rule2);
var result = fuzzyEngine.Defuzzify(new { water = 60 });
I don't see a comments section or an email so posting here. In doing my PhD research a while back I created a fuzzy 2 C# library. It's a bit of a mess but I don't mind cleaning it up. Would you be interested in adding it? Email me at kmccarty at nnu dot edu
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.