FluentFuzzy 0.1.0-d-2023-08-25-18-02-55

This is a prerelease version of FluentFuzzy.
dotnet add package FluentFuzzy --version 0.1.0-d-2023-08-25-18-02-55                
NuGet\Install-Package FluentFuzzy -Version 0.1.0-d-2023-08-25-18-02-55                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FluentFuzzy" Version="0.1.0-d-2023-08-25-18-02-55" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add FluentFuzzy --version 0.1.0-d-2023-08-25-18-02-55                
#r "nuget: FluentFuzzy, 0.1.0-d-2023-08-25-18-02-55"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install FluentFuzzy as a Cake Addin
#addin nuget:?package=FluentFuzzy&version=0.1.0-d-2023-08-25-18-02-55&prerelease

// Install FluentFuzzy as a Cake Tool
#tool nuget:?package=FluentFuzzy&version=0.1.0-d-2023-08-25-18-02-55&prerelease                

FuzzyLogic

FuzzyLogic is a package for doing fuzzy logic in .NET with a natural fluent syntax.

FuzzyLogic is very much WIP and should be expected to be updated with breaking changes.

Contents

FuzzyLogic contains the core fuzzy logic functionality.

FuzzyLogic.Visualization has visualization for some FuzzyLogic classes.

Using

After importing the Nuget package, using FuzzyLogic is a 2-step process.

Setting up input and output

FuzzyInputs and FuzzyOutputs can be set up in the following manner:

// test/FluentFuzzy.Test/Example.cs#L10-L12

var healthValue = 35;
var health = new FuzzyInput(() => healthValue);
var flee = new FuzzyOutput();

FuzzyInput requires a Func<double> to get the current crisp value of the input.

Setting up member functions

The next step is adding member functions to each input:

// test/FluentFuzzy.Test/Example.cs#L14-L20

var low = 0;
var medium = 1;
var high = 2;

health.Set(low, new Trapezoid(0, 0, 25, 50));
health.Set(medium, new Triangle(25, 50, 75));
health.Set(high, new Trapezoid(50, 75, 100, 100));

Currently, the following membership functions have been implemented:

  • Triangle defines a triangle.
  • Trapezoid defines a trapezoid.
  • Line defines a line.
  • Value defines a single value.
  • AtLeast defines a threshold value.

Custom membership functions can be created by implementing the IMembershipFunction interface.

After the input functions, membership functions can be added to the FuzzyOutput

// test/FluentFuzzy.Test/Example.cs#L22-L24

flee.Set(low, new Triangle(-0.5, 0, 0.5));
flee.Set(medium, new Triangle(0, 0.5, 1));
flee.Set(high, new Triangle(0.5, 1, 1.5));

The only currently supported defuzzification method is a version of the centroid method. As some of the membership functions, namely Line, Value and AtLeast do not have useful centroids, these cannot be used as output member functions.

Custom output membership functions can be created by implementing the IHasCentroid interface.

Setting up fuzzy rules

After setting up the fuzzy inputs and outputs, rules can be created to connect them.

Rules are created with a readable fluent syntax:

// test/FluentFuzzy.Test/Example.cs#L26-L28

FuzzyRule.If(health.Is(high)).Then(flee.Is(low));
FuzzyRule.If(health.Is(medium)).Then(flee.Is(medium));
FuzzyRule.If(health.Is(low)).Then(flee.Is(high));

Evaluating an output

After creating the fuzzy ruleset, the output can be evaluated by calling the Evaluate method on the output:

// test/FluentFuzzy.Test/Example.cs#L30-L30

Console.WriteLine($"flee(health: {health.Value}) = {flee.Evaluate()}"); // flee(health: 35) = 0,8
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.