Yuka js库中模糊变量(FuzzyVariable)的toJSON方法将模糊变量转换为JSON格式,以便将其序列化和存储到数据库中或使用在其他应用程序中。
const jsonFuzzyVariable = fuzzyVariable.toJSON();
jsonFuzzyVariable
是一个JSON化的模糊变量对象。
const FuzzyVariable = Yuka.FuzzyVariable;
const temperature = new FuzzyVariable('Temperature', 0, 100);
temperature.addLeftShoulderSet('Cold', 0, 30, 40);
temperature.addTriangularSet('Good', 30, 50, 80);
temperature.addRightShoulderSet('Hot', 70, 90, 100);
const jsonTemperature = temperature.toJSON();
console.log(jsonTemperature);
{
"name": "Temperature",
"minRange": 0,
"maxRange": 100,
"fuzzySets": [
{
"name": "Cold",
"left": 0,
"peak": 30,
"right": 40
},
{
"name": "Good",
"left": 30,
"peak": 50,
"right": 80
},
{
"name": "Hot",
"left": 70,
"peak": 90,
"right": 100
}
]
}
如果要将JSON格式的模糊变量对象还原为FuzzyVariable对象,请使用以下方法:
const reconstructedFuzzyVariable = FuzzyVariable.fromJSON(jsonFuzzyVariable);