2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-05-06 11:32:59 +00:00
esiur-dotnet/Esiur.Analysis/Fuzzy/MembershipFunction.cs
2022-10-29 17:53:06 +03:00

44 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace Esiur.Analysis.Fuzzy
{
public delegate double MembershipFunction(double value);
public static class MembershipFunctions
{
public static MembershipFunction Triangular(double start, double peak, double end)
{
return new MembershipFunction(x =>
{
if (x < start || x > end) return 0;
if (x < peak) return (x - start) / (peak - start);
if (x > peak) return (end - x) / (end - peak);
return 1; // x = peak
});
}
public static MembershipFunction Descending(double peak, double end)
{
return new MembershipFunction(x =>
{
if (x <= peak) return 1;
if (x > peak && x < end) return (end - x) / (end - peak);
return 0;
});
}
public static MembershipFunction Ascending(double start, double peak)
{
return new MembershipFunction(x =>
{
if (x >= peak) return 1;
if (x < peak && x > start) return (x - start) / (peak - start);
return 0;
});
}
}
}