2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-06-27 13:33:13 +00:00

Soft Computing

This commit is contained in:
2022-11-06 13:25:49 +03:00
parent f1d5b0a38b
commit 2844eb60ec
11 changed files with 790 additions and 430 deletions

View File

@ -66,7 +66,11 @@ namespace Esiur.Analysis.Fuzzy
{
var r = vector.Where(x => x.Key >= from && x.Key <= to).ToArray();
return r.Sum(x => x.Key * x.Value ) / r.Sum(x=>x.Value);
var total = r.Sum(x => x.Value);
if (total == 0)
return 0;
else
return r.Sum(x => x.Key * x.Value ) / total;
}
public KeyValuePair<double, double>[] Minimas
@ -78,6 +82,6 @@ namespace Esiur.Analysis.Fuzzy
}
}
public double[] ToArray() => vector.Values.ToArray();
}
}

View File

@ -41,5 +41,42 @@ namespace Esiur.Analysis.Fuzzy
return rt;
}
public static double[] Sample(this INumericalSet<double> set, double[] time)
{
var rt = new double[time.Length];
for (var i = 0; i < time.Length; i++)
rt[i] = set[time[i]];
return rt;
}
public static double[] Sample(this INumericalSet<double> set, double from, double to, double step)
{
var size = (int)((to - from) / step);
var rt = new double[size];
var s = 0;
for (var i = from; i < to && s < size; i+=step)
rt[s++] = set[i];
return rt;
}
public static double[] Range(double from, double to, double step)
{
var size = (int)((to - from) / step);
if (size == 0)
return new double[] { from };
var rt = new double[size];
var s = 0;
for (var i = from; i < to && s < size; i += step)
rt[s++] = i;
return rt;
}
}
}

View File

@ -23,7 +23,7 @@ namespace Esiur.Analysis.Fuzzy
{
return new MembershipFunction(x =>
{
if (x <= peak) return 1;
if (x <= peak) return 0;
if (x > peak && x < end) return (end - x) / (end - peak);
return 0;
});
@ -33,7 +33,7 @@ namespace Esiur.Analysis.Fuzzy
{
return new MembershipFunction(x =>
{
if (x >= peak) return 1;
if (x >= peak) return 0;
if (x < peak && x > start) return (x - start) / (peak - start);
return 0;
});