Zadeh.NET 1.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Zadeh.NET --version 1.0.0
                    
NuGet\Install-Package Zadeh.NET -Version 1.0.0
                    
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="Zadeh.NET" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Zadeh.NET" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Zadeh.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Zadeh.NET --version 1.0.0
                    
#r "nuget: Zadeh.NET, 1.0.0"
                    
#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.
#:package Zadeh.NET@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Zadeh.NET&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Zadeh.NET&version=1.0.0
                    
Install as a Cake Tool

๐Ÿ”ฎ Zadeh.NET

Kill your if/else chains. Embrace fuzzy decisions.

NuGet License .NET Tests

Lightweight, zero-dependency Mamdani fuzzy logic inference engine for .NET.
Smooth, human-like decisions in < 1ms.

Named after Lรผtfi Zadeh (1921โ€“2017), the founder of fuzzy set theory.


The Problem

Traditional software makes binary decisions. But the real world isn't binary.

โŒ Traditional:   29.9ยฐC โ†’ Fan OFF   |   30.1ยฐC โ†’ Fan ON      โ† Abrupt jump
โœ… Zadeh.NET:     29.9ยฐC โ†’ Fan 48%   |   30.1ยฐC โ†’ Fan 52%     โ† Smooth transition

Every time you write if (value > threshold), you create a cliff edge in your logic. Zadeh.NET replaces cliffs with slopes.


Install

dotnet add package Zadeh.NET

Real-World Examples: Before & After

๐Ÿค– Example 1: AI Confidence Scoring

You have an AI that returns a confidence score. Is 0.68 good enough? Depends on context.

<details> <summary>โŒ Before โ€” fragile if/else chain</summary>

// This grows into unmaintainable spaghetti
double GetFinalScore(double aiConfidence, double userHistory, double context)
{
    if (aiConfidence > 0.8)
    {
        if (userHistory > 0.5) return 0.95;
        if (context > 0.6) return 0.90;
        return 0.85;
    }
    else if (aiConfidence > 0.5)
    {
        if (userHistory > 0.7) return 0.75;
        if (context > 0.7) return 0.70;
        if (userHistory < 0.2 && context < 0.3) return 0.30;
        return 0.55;
    }
    else
    {
        if (userHistory > 0.8) return 0.50; // frequent user, trust more
        if (context > 0.8) return 0.45;
        return 0.20;
    }
    // ๐Ÿคฏ What happens at 0.799 vs 0.801? Completely different paths.
    // ๐Ÿคฏ Adding a 4th factor? Rewrite everything.
}

</details>

โœ… After โ€” with Zadeh.NET

var aiConf = new FuzzyVariable("AIConfidence", 0, 1);
aiConf.Set(FuzzySet.LeftShoulder("Low", 0.2, 0.4));
aiConf.Set(FuzzySet.Triangle("Medium", 0.3, 0.55, 0.75));
aiConf.Set(FuzzySet.RightShoulder("High", 0.65, 0.85));

var history = new FuzzyVariable("UserHistory", 0, 1);
history.Set(FuzzySet.LeftShoulder("Rare", 0.1, 0.3));
history.Set(FuzzySet.Triangle("Occasional", 0.2, 0.5, 0.7));
history.Set(FuzzySet.RightShoulder("Frequent", 0.5, 0.8));

var score = new FuzzyVariable("FinalScore", 0, 1);
score.Set(FuzzySet.LeftShoulder("Low", 0.1, 0.3));
score.Set(FuzzySet.Triangle("Medium", 0.3, 0.5, 0.7));
score.Set(FuzzySet.RightShoulder("High", 0.6, 0.85));

var engine = new MamdaniEngine()
    .Input(aiConf).Input(history).Output(score)
    .Rule(FuzzyRule.If(aiConf.Is("High")).And(history.Is("Frequent")).Then(score.Is("High")))
    .Rule(FuzzyRule.If(aiConf.Is("Medium")).And(history.Is("Frequent")).Then(score.Is("High")))
    .Rule(FuzzyRule.If(aiConf.Is("Medium")).And(history.Is("Rare")).Then(score.Is("Low")))
    .Rule(FuzzyRule.If(aiConf.Is("Low")).And(history.Is("Frequent")).Then(score.Is("Medium")))
    .Rule(FuzzyRule.If(aiConf.Is("Low")).And(history.Is("Rare")).Then(score.Is("Low")));

// Smooth decisions โ€” no cliff edges
var result = engine.EvaluateSingle(new() { ["AIConfidence"] = 0.68, ["UserHistory"] = 0.72 });
// โ†’ 0.73 โ€” naturally high because both inputs lean positive

What changed?

  • No magic numbers. Rules read like English.
  • Adding a 3rd input? Add 1 variable + a few rules. No rewrite.
  • 0.68 confidence isn't binary "medium" or "high" โ€” it's partially both.

๐Ÿ’ฐ Example 2: Dynamic Pricing

Your e-commerce needs to adjust prices based on demand and stock levels.

<details> <summary>โŒ Before โ€” rigid tiers</summary>

double GetPriceMultiplier(int demandScore, int stockLevel)
{
    if (demandScore > 80 && stockLevel < 10) return 1.50;  // surge price
    if (demandScore > 80 && stockLevel < 30) return 1.30;
    if (demandScore > 50 && stockLevel < 10) return 1.20;
    if (demandScore > 50 && stockLevel < 30) return 1.10;
    if (demandScore < 20 && stockLevel > 80) return 0.70;  // clearance
    if (demandScore < 20 && stockLevel > 50) return 0.85;
    return 1.00;
    // ๐Ÿ˜ค Stock=31 vs Stock=29: price jumps 20%. Customers notice.
}

</details>

โœ… After โ€” with Zadeh.NET

var demand = new FuzzyVariable("Demand", 0, 100);
demand.Set(FuzzySet.LeftShoulder("Low", 15, 35));
demand.Set(FuzzySet.Triangle("Medium", 25, 50, 75));
demand.Set(FuzzySet.RightShoulder("High", 65, 85));

var stock = new FuzzyVariable("Stock", 0, 100);
stock.Set(FuzzySet.LeftShoulder("Scarce", 10, 25));
stock.Set(FuzzySet.Triangle("Normal", 20, 50, 80));
stock.Set(FuzzySet.RightShoulder("Surplus", 70, 90));

var price = new FuzzyVariable("PriceMultiplier", 50, 150);
price.Set(FuzzySet.LeftShoulder("Discount", 60, 80));
price.Set(FuzzySet.Triangle("Normal", 85, 100, 115));
price.Set(FuzzySet.RightShoulder("Premium", 120, 145));

var engine = new MamdaniEngine()
    .Input(demand).Input(stock).Output(price)
    .Rule(FuzzyRule.If(demand.Is("High")).And(stock.Is("Scarce")).Then(price.Is("Premium")))
    .Rule(FuzzyRule.If(demand.Is("High")).And(stock.Is("Normal")).Then(price.Is("Premium")))
    .Rule(FuzzyRule.If(demand.Is("Medium")).And(stock.Is("Normal")).Then(price.Is("Normal")))
    .Rule(FuzzyRule.If(demand.Is("Low")).And(stock.Is("Surplus")).Then(price.Is("Discount")))
    .Rule(FuzzyRule.If(demand.Is("Low")).And(stock.Is("Normal")).Then(price.Is("Discount")));

var multiplier = engine.EvaluateSingle(new() { ["Demand"] = 72, ["Stock"] = 18 });
// โ†’ 128.4% โ€” smooth premium, not a sudden 50% jump

What changed?

  • Stock=29 and Stock=31 produce nearly identical prices. No customer-shocking jumps.
  • Business team can tweak rules without touching code logic.

๐ŸŽฎ Example 3: Game Difficulty (5 lines of config)

var skill = new FuzzyVariable("PlayerSkill", 0, 100);
skill.Set(FuzzySet.LeftShoulder("Beginner", 20, 40));
skill.Set(FuzzySet.Triangle("Intermediate", 30, 50, 70));
skill.Set(FuzzySet.RightShoulder("Expert", 60, 80));

var difficulty = new FuzzyVariable("Difficulty", 0, 100);
difficulty.Set(FuzzySet.Triangle("Easy", 0, 20, 45));
difficulty.Set(FuzzySet.Triangle("Normal", 30, 50, 70));
difficulty.Set(FuzzySet.Triangle("Hard", 55, 80, 100));

var engine = new MamdaniEngine()
    .Input(skill).Output(difficulty)
    .Rule(FuzzyRule.If(skill.Is("Beginner")).Then(difficulty.Is("Easy")))
    .Rule(FuzzyRule.If(skill.Is("Intermediate")).Then(difficulty.Is("Normal")))
    .Rule(FuzzyRule.If(skill.Is("Expert")).Then(difficulty.Is("Hard")));

// Player with skill 45 โ†’ Difficulty: 47.2 (between easy and normal โ€” smooth)
// Player with skill 65 โ†’ Difficulty: 68.8 (between normal and hard โ€” gradual)

Features

5 Membership Functions

Type Shape Best For
Triangle(name, left, peak, right) /\ General purpose
Trapezoid(name, a, b, c, d) /โ€พ\ "Definitely X" plateau
LeftShoulder(name, mid, edge) โ€พ\ "Low", "Cold", "Cheap"
RightShoulder(name, edge, mid) /โ€พ "High", "Hot", "Expensive"
Gaussian(name, mean, ฯƒ) ๐Ÿ”” Natural distributions

3 Defuzzification Methods

new MamdaniEngine(DefuzzificationMethod.Centroid)       // Default โ€” smoothest
new MamdaniEngine(DefuzzificationMethod.Bisector)       // Equal area split
new MamdaniEngine(DefuzzificationMethod.MeanOfMaximum)  // Fastest

Multi-Input Rules with AND

FuzzyRule.If(temperature.Is("Hot"))
         .And(humidity.Is("High"))
         .Then(fanSpeed.Is("Max"))

Weighted Rules

FuzzyRule.If(temperature.Is("Warm"))
         .WithWeight(0.8)  // This rule has less influence
         .Then(fanSpeed.Is("Medium"))

Fluent Builder API

var engine = new MamdaniEngine()
    .Input("Temperature", 0, 100, t => {
        t.Set(FuzzySet.LeftShoulder("Cold", 20, 35));
        t.Set(FuzzySet.RightShoulder("Hot", 45, 60));
    })
    .Output("FanSpeed", 0, 100, f => {
        f.Set(FuzzySet.Triangle("Slow", 0, 25, 50));
        f.Set(FuzzySet.Triangle("Fast", 50, 75, 100));
    })
    .Rule(FuzzyRule.If(temperature.Is("Cold")).Then(fanSpeed.Is("Slow")))
    .Rule(FuzzyRule.If(temperature.Is("Hot")).Then(fanSpeed.Is("Fast")));

Use Cases

Domain Input โ†’ Output
๐Ÿค– AI Post-Processing Confidence ร— History ร— Context โ†’ Reliability Score
๐Ÿ’ฐ Dynamic Pricing Demand ร— Stock ร— Competition โ†’ Price Multiplier
๐Ÿญ Industrial Control Temperature ร— Pressure โ†’ Valve Opening
๐ŸŽฎ Game AI Player Skill ร— Game Time โ†’ Enemy Difficulty
๐Ÿฅ Medical DSS Symptom Severity ร— Age โ†’ Risk Level
๐Ÿ“Š Credit Scoring Income ร— Credit History โ†’ Loan Limit
๐ŸŒก๏ธ IoT / Smart Home Room Temp ร— Humidity ร— Time โ†’ AC Level
๐Ÿ” Search Ranking Relevance ร— Freshness ร— Popularity โ†’ Final Rank

Technical Specs

Spec Value
Dependencies Zero
Code size ~400 lines
Inference time < 1ms (typical)
Thread safety โœ… Immutable after construction
Deterministic โœ… Same inputs โ†’ always same output
Target .NET 8.0+
Tests 43 passing

Roadmap

v1.5 โ€” Developer Experience (Q3 2026)

  • JSON/YAML rule loading (runtime configuration)
  • Rule explainability: "Why did the engine decide this?"
  • ASP.NET Core DI integration package

v2.0 โ€” Advanced Inference (R&D)

  • Takagi-Sugeno inference engine
  • Type-2 Fuzzy Sets (uncertainty of uncertainty)
  • Data-driven dynamic membership function generation
  • Genetic algorithm parameter optimization
  • Visualization package

Academic Foundation

  • L.A. Zadeh (1965) โ€” Fuzzy Sets, Information and Control, 8(3), 338โ€“353
  • E.H. Mamdani & S. Assilian (1975) โ€” An Experiment in Linguistic Synthesis with a Fuzzy Logic Controller

License

Dual licensed under:

For commercial licensing plans, custom integrations, or advanced soft-computing capabilities, contact us at info@deegitech.com.


Made with ๐Ÿ”ฎ by DeegiTech ยท Website ยท NuGet

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Zadeh.NET:

Package Downloads
Zadeh.AI

The AI companion to Zadeh.NET: turn LLM confidence into deterministic Execute/Confirm/Clarify/Reject decisions (ConfidenceGate), generate fuzzy rule sets from plain-language policy via any LLM (RuleSmith), compute adaptive similarity thresholds for RAG/semantic caching (AdaptiveThreshold), and expose fuzzy engines as MCP tools for AI agents. AI designs, fuzzy decides โ€” zero hallucination at runtime. Uses only the .NET base library โ€” no external dependencies. Licensed under AGPL-3.0 / Commercial dual license.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.5.0 663 7/3/2026
1.0.0 136 6/19/2026

Initial stable release. Mamdani inference with 5 MF types, 3 defuzzification methods, fluent API, multi-input rules, weighted rules. 43 unit tests. Dual licensed under AGPL-3.0 and Commercial license.