defuzzifyCentroid method
Defuzzifies the FLV using the "Centroid" method.
Implementation
double defuzzifyCentroid([int samples = 10 ]) {
final fuzzySets = this.fuzzySets;
final stepSize = ( maxRange - minRange ) / samples;
double totalArea = 0;
double sumOfMoments = 0;
for ( int s = 1; s <= samples; s ++ ) {
final sample = minRange + ( s * stepSize );
for ( int i = 0, l = fuzzySets.length; i < l; i ++ ) {
final fuzzySet = fuzzySets[ i ];
final contribution = math.min( fuzzySet.degreeOfMembership, fuzzySet.computeDegreeOfMembership( sample ) );
totalArea += contribution;
sumOfMoments += ( sample * contribution );
}
}
return ( totalArea == 0 ) ? 0 : ( sumOfMoments / totalArea );
}