es6-fuzz
es6-fuzz copied to clipboard
Wrong evaluation at limit of trapezoid
Hi, I am trying to use this library, the fuzzification is quite clear but the defuzzification step is not clear to me using this library, anyways, I have this code that gives a wrong evaluation at the upper limit of a trapezoid, It seems to come from this library not from boon-js:
I have this function with two input fuzzy variables (likelihood and impact), the fifth evaluator function is the one that returns True when the input is assess(5, 10), while 10 as a value for impact should trigger the seventh evaluator to return true (securityTest_moderate_restricted ) and this should lead to have the function an output of "high", I tried to slightly modify the trapezoid declaration to make it work by cheating a little bit and pushing the last point of the trapezoid to 11: const restrictedImpact = new fuzzy.Trapezoid(7.5, 8.5, 10, 11); And this gave me a correct result, which makes me think that there is a problem at the higher limit of the trapezoid.
Thanks,
This is the function:
const assess = (likelihood, impact) => {
var logicLikelihood = new fuzzy.Logic();
const lowLikelihood = new fuzzy.Trapezoid(0, 0, 2, 3);
const moderateLikelihood = new fuzzy.Trapezoid(2, 3, 7, 8);
const highLikelihood = new fuzzy.Trapezoid(7, 8, 10, 10);
logicLikelihood.init('low', lowLikelihood)
logicLikelihood.or('moderate', moderateLikelihood)
logicLikelihood.or('high', highLikelihood);
var logicImpact = new fuzzy.Logic();
const publicImpact = new fuzzy.Trapezoid(0, 0, 1.5, 2.5);
const internalImpact = new fuzzy.Trapezoid(1.5, 2.5, 4.5, 5.5);
const confidentialImpact = new fuzzy.Trapezoid(4.5, 5.5, 7.5, 8.5);
const restrictedImpact = new fuzzy.Trapezoid(7.5, 8.5, 10, 10);
logicImpact.init('public', publicImpact)
logicImpact.or('internal', internalImpact)
logicImpact.or('confidential', confidentialImpact);
logicImpact.or('restricted', restrictedImpact);
const tests = [];
// assessment very low
const securityTest_low_public = boon.getEvaluator('likelihood.low AND impact.public');
tests.push(securityTest_low_public);
// assessment low
const securityTest_low_internal = boon.getEvaluator('likelihood.low AND impact.internal');
tests.push(securityTest_low_internal);
// assessment medium
const securityTest_low_confidential = boon.getEvaluator('likelihood.low AND impact.confidential');
tests.push(securityTest_low_confidential);
// assessment high
const securityTest_low_restricted = boon.getEvaluator('likelihood.low AND impact.restricted');
tests.push(securityTest_low_restricted);
// assessment low
const securityTest_moderate_public = boon.getEvaluator('likelihood.moderate AND impact.public');
tests.push(securityTest_moderate_public);
// assessment medium
const securityTest_moderate_internal = boon.getEvaluator('likelihood.moderate AND impact.internal');
tests.push(securityTest_moderate_internal);
// assessment high
const securityTest_moderate_confidential = boon.getEvaluator('likelihood.moderate AND impact.confidential');
tests.push(securityTest_moderate_confidential);
// assessment very high
const securityTest_moderate_restricted = boon.getEvaluator('likelihood.moderate AND impact.restricted');
tests.push(securityTest_moderate_restricted);
// assessment low
const securityTest_high_public = boon.getEvaluator('likelihood.high AND impact.public');
tests.push(securityTest_high_public);
// assessment medium
const securityTest_high_internal = boon.getEvaluator('likelihood.high AND impact.internal');
tests.push(securityTest_high_internal);
// assessment high
const securityTest_high_confidential = boon.getEvaluator('likelihood.high AND impact.confidential');
tests.push(securityTest_high_confidential);
// assessment very high
const securityTest_high_restricted = boon.getEvaluator('likelihood.high AND impact.restricted');
tests.push(securityTest_high_restricted);
const resLikelihood = logicLikelihood.defuzzify(likelihood, 'likelihood');
const resImpact = logicImpact.defuzzify(impact, 'impact');
const jsBoonInput = { ...resLikelihood.boonJsInputs, ...resImpact.boonJsInputs }
const results = [];
for(let i = 0; i < tests.length; i++){
results.push( tests[i](jsBoonInput) );
}
if(results[0]) return "very low";
else if(results[1]) return "low";
else if(results[2]) return "medium";
else if(results[3]) return "high";
else if(results[4]) return "low";
else if(results[5]) return "medium";
else if(results[6]) return "high";
else if(results[7]) return "high";
else if(results[8]) return "low";
else if(results[9]) return "medium";
else if(results[10]) return "high";
else if(results[11]) return "very high";
else return "Unknown";
}