Skip to content

Commit

Permalink
update FuzzyNumber.GetAlphaCut method
Browse files Browse the repository at this point in the history
  • Loading branch information
dzibma committed Nov 22, 2015
1 parent 33f7ea7 commit b2c8076
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions FuzzyMath/FuzzyNumber/FuzzyNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,23 @@ public Interval GetAlphaCut(double membership)
throw new ArgumentException("Membership degree must be from the interval [0, 1]");
}

var i = membership * (alphaCuts.Length - 1);
if (i - Math.Floor(i) < double.Epsilon)
var pos = membership * (alphaCuts.Length - 1);
var i = (int)Math.Round(pos);
if (Math.Abs(pos - i) < double.Epsilon)
{
return alphaCuts[(int)i];
return alphaCuts[i];
}

var upper = (int)Math.Ceiling(i);
var lower = (int)Math.Floor(i);
var upper = (int)Math.Ceiling(pos);
var lower = (int)Math.Floor(pos);

var a = alphaCuts[lower].A == alphaCuts[upper].A
? alphaCuts[lower].A
: alphaCuts[upper].A - (upper - i) * (alphaCuts[upper].A - alphaCuts[lower].A);
: alphaCuts[upper].A - (upper - pos) * (alphaCuts[upper].A - alphaCuts[lower].A);

var b = alphaCuts[lower].B == alphaCuts[upper].B
? alphaCuts[lower].A
: alphaCuts[upper].B + (upper - i) * (alphaCuts[lower].B - alphaCuts[upper].B);
: alphaCuts[upper].B + (upper - pos) * (alphaCuts[lower].B - alphaCuts[upper].B);

return new Interval(a, b);
}
Expand Down

0 comments on commit b2c8076

Please sign in to comment.