Upload files to "/"

This commit is contained in:
marcinsz 2024-05-29 11:30:12 +02:00
parent 2bcbaa0031
commit c052827a8d
2 changed files with 322 additions and 0 deletions

49
disengagement.fcl Normal file
View File

@ -0,0 +1,49 @@
FUNCTION_BLOCK disengagement_FCL
VAR_INPUT
learning_quality : REAL;
remaining_time : REAL;
END_VAR
VAR_OUTPUT
disengagement : REAL;
END_VAR
FUZZIFY learning_quality
TERM low := (0, 1) (0.2, 1) (0.4, 0);
TERM medium := (0.2, 0) (0.4, 1) (0.6, 1) (0.8, 0);
TERM high := (0.6, 0) (0.8, 1) (1, 1);
END_FUZZIFY
FUZZIFY remaining_time
TERM low := (0, 1) (0.2, 1) (0.4, 0);
TERM medium := (0.2, 0) (0.4, 1) (0.6, 1) (0.8, 0);
TERM high := (0.6, 0) (0.8, 1) (1, 1);
END_FUZZIFY
DEFUZZIFY disengagement
TERM low := (0, 1) (0.2, 1) (0.4, 0);
TERM medium := (0.2, 0) (0.4, 1) (0.6, 1) (0.8, 0);
TERM high := (0.6, 0) (0.8, 1) (1, 1);
METHOD : COG;
DEFAULT := 0.5;
END_DEFUZZIFY
RULEBLOCK No1
AND : MIN;
ACT : MIN;
ACCU : MAX;
RULE 1 : IF learning_quality IS low AND remaining_time IS low THEN disengagement IS high;
RULE 2 : IF learning_quality IS low AND remaining_time IS medium THEN disengagement IS medium;
RULE 3 : IF learning_quality IS low AND remaining_time IS high THEN disengagement IS medium;
RULE 4 : IF learning_quality IS medium AND remaining_time IS low THEN disengagement IS medium;
RULE 5 : IF learning_quality IS medium AND remaining_time IS medium THEN disengagement IS medium;
RULE 6 : IF learning_quality IS medium AND remaining_time IS high THEN disengagement IS low;
RULE 7 : IF learning_quality IS high AND remaining_time IS low THEN disengagement IS medium;
RULE 8 : IF learning_quality IS high AND remaining_time IS medium THEN disengagement IS low;
RULE 9 : IF learning_quality IS high AND remaining_time IS high THEN disengagement IS low;
END_RULEBLOCK
END_FUNCTION_BLOCK

273
disengagement.js Normal file
View File

@ -0,0 +1,273 @@
//--------------------------------------------------------------------------------
// Code generated by jFuzzyLogic
//--------------------------------------------------------------------------------
function ruleAccumulationMethod_max(defuzzifierValue, valueToAggregate) {
return (defuzzifierValue > valueToAggregate ? defuzzifierValue : valueToAggregate);
}
function ruleActivationMethod_min(degreeOfSupport, membership) {
return (degreeOfSupport < membership ? degreeOfSupport : membership);
}
function ruleConnectionMethod_and(antecedent1, antecedent2) {
return (antecedent1 < antecedent2 ? antecedent1 : antecedent2);
}
class FunctionBlock_disengagement_FCL {
// VAR_INPUT
learning_quality;
remaining_time;
// VAR_OUTPUT
disengagement;
// FUZZIFY learning_quality
learning_quality_high;
learning_quality_low;
learning_quality_medium;
// FUZZIFY remaining_time
remaining_time_high;
remaining_time_low;
remaining_time_medium;
// DEFUZZIFY disengagement
defuzzify_disengagement;
// Constructor
constructor() {
this.disengagement = 0.5;
this.defuzzify_disengagement = new Array(1000);
}
// Calculate function block
calc() {
this.reset();
this.fuzzify();
this.calc_No1();
this.defuzzify();
}
// RULEBLOCK No1
calc_No1() {
// RULE 1 : IF (learning_quality IS low) AND (remaining_time IS low) THEN disengagement IS high;
let degreeOfSupport_1 = 1.0 * (ruleConnectionMethod_and(this.learning_quality_low, this.remaining_time_low));
if (degreeOfSupport_1 > 0) {
for (let i = 0; i < 1000; i++) {
let x = 0.0 + i * 0.001;
let membership = this.membership_disengagement_high(x);
let y = ruleActivationMethod_min(degreeOfSupport_1 , membership);
this.defuzzify_disengagement[i] = ruleAccumulationMethod_max(this.defuzzify_disengagement[i], y);
}
}
// RULE 2 : IF (learning_quality IS low) AND (remaining_time IS medium) THEN disengagement IS medium;
let degreeOfSupport_2 = 1.0 * (ruleConnectionMethod_and(this.learning_quality_low, this.remaining_time_medium));
if (degreeOfSupport_2 > 0) {
for (let i = 0; i < 1000; i++) {
let x = 0.0 + i * 0.001;
let membership = this.membership_disengagement_medium(x);
let y = ruleActivationMethod_min(degreeOfSupport_2 , membership);
this.defuzzify_disengagement[i] = ruleAccumulationMethod_max(this.defuzzify_disengagement[i], y);
}
}
// RULE 3 : IF (learning_quality IS low) AND (remaining_time IS high) THEN disengagement IS medium;
let degreeOfSupport_3 = 1.0 * (ruleConnectionMethod_and(this.learning_quality_low, this.remaining_time_high));
if (degreeOfSupport_3 > 0) {
for (let i = 0; i < 1000; i++) {
let x = 0.0 + i * 0.001;
let membership = this.membership_disengagement_medium(x);
let y = ruleActivationMethod_min(degreeOfSupport_3 , membership);
this.defuzzify_disengagement[i] = ruleAccumulationMethod_max(this.defuzzify_disengagement[i], y);
}
}
// RULE 4 : IF (learning_quality IS medium) AND (remaining_time IS low) THEN disengagement IS medium;
let degreeOfSupport_4 = 1.0 * (ruleConnectionMethod_and(this.learning_quality_medium, this.remaining_time_low));
if (degreeOfSupport_4 > 0) {
for (let i = 0; i < 1000; i++) {
let x = 0.0 + i * 0.001;
let membership = this.membership_disengagement_medium(x);
let y = ruleActivationMethod_min(degreeOfSupport_4 , membership);
this.defuzzify_disengagement[i] = ruleAccumulationMethod_max(this.defuzzify_disengagement[i], y);
}
}
// RULE 5 : IF (learning_quality IS medium) AND (remaining_time IS medium) THEN disengagement IS medium;
let degreeOfSupport_5 = 1.0 * (ruleConnectionMethod_and(this.learning_quality_medium, this.remaining_time_medium));
if (degreeOfSupport_5 > 0) {
for (let i = 0; i < 1000; i++) {
let x = 0.0 + i * 0.001;
let membership = this.membership_disengagement_medium(x);
let y = ruleActivationMethod_min(degreeOfSupport_5 , membership);
this.defuzzify_disengagement[i] = ruleAccumulationMethod_max(this.defuzzify_disengagement[i], y);
}
}
// RULE 6 : IF (learning_quality IS medium) AND (remaining_time IS high) THEN disengagement IS low;
let degreeOfSupport_6 = 1.0 * (ruleConnectionMethod_and(this.learning_quality_medium, this.remaining_time_high));
if (degreeOfSupport_6 > 0) {
for (let i = 0; i < 1000; i++) {
let x = 0.0 + i * 0.001;
let membership = this.membership_disengagement_low(x);
let y = ruleActivationMethod_min(degreeOfSupport_6 , membership);
this.defuzzify_disengagement[i] = ruleAccumulationMethod_max(this.defuzzify_disengagement[i], y);
}
}
// RULE 7 : IF (learning_quality IS high) AND (remaining_time IS low) THEN disengagement IS medium;
let degreeOfSupport_7 = 1.0 * (ruleConnectionMethod_and(this.learning_quality_high, this.remaining_time_low));
if (degreeOfSupport_7 > 0) {
for (let i = 0; i < 1000; i++) {
let x = 0.0 + i * 0.001;
let membership = this.membership_disengagement_medium(x);
let y = ruleActivationMethod_min(degreeOfSupport_7 , membership);
this.defuzzify_disengagement[i] = ruleAccumulationMethod_max(this.defuzzify_disengagement[i], y);
}
}
// RULE 8 : IF (learning_quality IS high) AND (remaining_time IS medium) THEN disengagement IS low;
let degreeOfSupport_8 = 1.0 * (ruleConnectionMethod_and(this.learning_quality_high, this.remaining_time_medium));
if (degreeOfSupport_8 > 0) {
for (let i = 0; i < 1000; i++) {
let x = 0.0 + i * 0.001;
let membership = this.membership_disengagement_low(x);
let y = ruleActivationMethod_min(degreeOfSupport_8 , membership);
this.defuzzify_disengagement[i] = ruleAccumulationMethod_max(this.defuzzify_disengagement[i], y);
}
}
// RULE 9 : IF (learning_quality IS high) AND (remaining_time IS high) THEN disengagement IS low;
let degreeOfSupport_9 = 1.0 * (ruleConnectionMethod_and(this.learning_quality_high, this.remaining_time_high));
if (degreeOfSupport_9 > 0) {
for (let i = 0; i < 1000; i++) {
let x = 0.0 + i * 0.001;
let membership = this.membership_disengagement_low(x);
let y = ruleActivationMethod_min(degreeOfSupport_9 , membership);
this.defuzzify_disengagement[i] = ruleAccumulationMethod_max(this.defuzzify_disengagement[i], y);
}
}
}
// Defuzzify
defuzzify() {
let sum_disengagement = 0.0;
let wsum_disengagement = 0.0;
let x;
for (let i = 0; i < 1000; i++) {
x = 0.0 + i * 0.001;
sum_disengagement += this.defuzzify_disengagement[i];
wsum_disengagement += x * this.defuzzify_disengagement[i];
}
if (sum_disengagement == 0) {
sum_disengagement = 1.0;
}
this.disengagement = wsum_disengagement / sum_disengagement;
}
// Fuzzify all variables
fuzzify() {
this.learning_quality_high = this.membership_learning_quality_high(this.learning_quality);
this.learning_quality_low = this.membership_learning_quality_low(this.learning_quality);
this.learning_quality_medium = this.membership_learning_quality_medium(this.learning_quality);
this.remaining_time_high = this.membership_remaining_time_high(this.remaining_time);
this.remaining_time_low = this.membership_remaining_time_low(this.remaining_time);
this.remaining_time_medium = this.membership_remaining_time_medium(this.remaining_time);
}
// Membership functions
membership_disengagement_high(x) {
if (x <= 0.6) return 0.0;
if (x > 1.0) return 1.0;
if (x <= 0.8) return 0.0 + (1.0 - 0.0) * ((x - 0.6) / (0.8 - 0.6));
if (x <= 1.0) return 1.0 + (1.0 - 1.0) * ((x - 0.8) / (1.0 - 0.8));
}
membership_disengagement_low(x) {
if (x <= 0.0) return 1.0;
if (x > 0.4) return 0.0;
if (x <= 0.2) return 1.0 + (1.0 - 1.0) * ((x - 0.0) / (0.2 - 0.0));
if (x <= 0.4) return 1.0 + (0.0 - 1.0) * ((x - 0.2) / (0.4 - 0.2));
}
membership_disengagement_medium(x) {
if (x <= 0.2) return 0.0;
if (x > 0.8) return 0.0;
if (x <= 0.4) return 0.0 + (1.0 - 0.0) * ((x - 0.2) / (0.4 - 0.2));
if (x <= 0.6) return 1.0 + (1.0 - 1.0) * ((x - 0.4) / (0.6 - 0.4));
if (x <= 0.8) return 1.0 + (0.0 - 1.0) * ((x - 0.6) / (0.8 - 0.6));
}
membership_learning_quality_high(x) {
if (x <= 0.6) return 0.0;
if (x > 1.0) return 1.0;
if (x <= 0.8) return 0.0 + (1.0 - 0.0) * ((x - 0.6) / (0.8 - 0.6));
if (x <= 1.0) return 1.0 + (1.0 - 1.0) * ((x - 0.8) / (1.0 - 0.8));
}
membership_learning_quality_low(x) {
if (x <= 0.0) return 1.0;
if (x > 0.4) return 0.0;
if (x <= 0.2) return 1.0 + (1.0 - 1.0) * ((x - 0.0) / (0.2 - 0.0));
if (x <= 0.4) return 1.0 + (0.0 - 1.0) * ((x - 0.2) / (0.4 - 0.2));
}
membership_learning_quality_medium(x) {
if (x <= 0.2) return 0.0;
if (x > 0.8) return 0.0;
if (x <= 0.4) return 0.0 + (1.0 - 0.0) * ((x - 0.2) / (0.4 - 0.2));
if (x <= 0.6) return 1.0 + (1.0 - 1.0) * ((x - 0.4) / (0.6 - 0.4));
if (x <= 0.8) return 1.0 + (0.0 - 1.0) * ((x - 0.6) / (0.8 - 0.6));
}
membership_remaining_time_high(x) {
if (x <= 0.6) return 0.0;
if (x > 1.0) return 1.0;
if (x <= 0.8) return 0.0 + (1.0 - 0.0) * ((x - 0.6) / (0.8 - 0.6));
if (x <= 1.0) return 1.0 + (1.0 - 1.0) * ((x - 0.8) / (1.0 - 0.8));
}
membership_remaining_time_low(x) {
if (x <= 0.0) return 1.0;
if (x > 0.4) return 0.0;
if (x <= 0.2) return 1.0 + (1.0 - 1.0) * ((x - 0.0) / (0.2 - 0.0));
if (x <= 0.4) return 1.0 + (0.0 - 1.0) * ((x - 0.2) / (0.4 - 0.2));
}
membership_remaining_time_medium(x) {
if (x <= 0.2) return 0.0;
if (x > 0.8) return 0.0;
if (x <= 0.4) return 0.0 + (1.0 - 0.0) * ((x - 0.2) / (0.4 - 0.2));
if (x <= 0.6) return 1.0 + (1.0 - 1.0) * ((x - 0.4) / (0.6 - 0.4));
if (x <= 0.8) return 1.0 + (0.0 - 1.0) * ((x - 0.6) / (0.8 - 0.6));
}
// Print
print() {
console.log("Function block disengagement_FCL:\n");
console.log(" Output %s: %f\n", "disengagement" , this.disengagement);
console.log(" Input %s: %f\n", "learning_quality" , this.learning_quality);
console.log(" %s: %f\n", "learning_quality_high" , this.learning_quality_high);
console.log(" %s: %f\n", "learning_quality_low" , this.learning_quality_low);
console.log(" %s: %f\n", "learning_quality_medium" , this.learning_quality_medium);
console.log(" Input %s: %f\n", "remaining_time" , this.remaining_time);
console.log(" %s: %f\n", "remaining_time_high" , this.remaining_time_high);
console.log(" %s: %f\n", "remaining_time_low" , this.remaining_time_low);
console.log(" %s: %f\n", "remaining_time_medium" , this.remaining_time_medium);
}
// Reset output
reset() {
for (let i = 0 ; i < 1000; i++) {
this.defuzzify_disengagement[i] = 0.0;
}
}
};
window.FunctionBlock_disengagement_FCL = FunctionBlock_disengagement_FCL;