我正在尝试实施模糊逻辑,将天气分类到不同的气候带。当我在RStudio中调用sets包的fuzzy_inference()函数时,我得到了这个Null异常。以下是我定义集合和模糊规则的代码。
sets_options("universe", seq(1, 200, 0.5))
variables <- set(
rainfall=fuzzy_partition(varnames = c(range1 = 30, range2 = 70, range3 =
90),sd = 5.0),
maxTemp = fuzzy_partition(varnames = c(hot = 30, hotter = 70),sd = 5.0),
humidity = fuzzy_partition(varnames = c(less_humid = 30, humid = 60,
more_humid = 80),sd = 3.0),
soil = fuzzy_partition(varnames=c(Black_soil=10,Mixed_Red_and_Black_soil=20,
Mixed_Red_and_clay_soil=30,
Mixed_red_and_sandy_soil=40,Mixed_Red_Loamy_and_sandy_soil=50,
Mixed_sandy_and_clayey_soil=60,
Red_forest_soil=70,Red_Lateritic_soil=80,Red_Loamy_soil=90,
Red_sandy_soil=100),sd = 3.0),
climate=fuzzy_partition(varnames =
c(Northern_Dry_Zone=10,
Eastern_Dry_Zone=20,
North_Eastern_Transition_Zone=30,
Southern_Dry_Zone=40,Eastern_Dry_Zone=50,Hilly_Zone=60,
Central_Dry_Zone=70,Coastal_Zone=80,Southern_Transition_Zone=90,
Northern_Transition_Zone=100),sd = 3.0),
FUN = fuzzy_cone, radius = 10)
rules <- set(
fuzzy_rule(humidity %is% less_humid && maxTemp %is% hot && rainfall %is%
range2 && soil %is% Black_soil
,climate %is% Northern_Dry_Zone),
fuzzy_rule(humidity %is% humid && maxTemp %is% hot && rainfall %is% range2
&& soil %is% Red_Loamy_soil
,climate %is% Eastern_Dry_Zone),
fuzzy_rule(humidity %is% humid && maxTemp %is% hot && rainfall %is% range2
&& soil %is% Black_soil
,climate %is% Northern_Dry_Zone),
fuzzy_rule(humidity %is% less_humid && maxTemp %is% hotter && rainfall %is%
range1 && soil %is% Mixed_Red_and_Black_soil
,climate %is% Northern_Dry_Zone),
fuzzy_rule(humidity %is% less_humid && maxTemp %is% hot && rainfall %is%
range1 && soil %is% Black_soil
,climate %is% Northern_Transition_Zone),
fuzzy_rule(humidity %is% humid && maxTemp %is% hot && rainfall %is% range3
&& soil %is% Red_forest_soil
,climate %is% Southern_Dry_Zone),
fuzzy_rule(humidity %is% humid && maxTemp %is% hot && rainfall %is% range2
&& soil %is% Mixed_red_and_sandy_soil
,climate %is% Eastern_Dry_Zone),
fuzzy_rule(humidity %is% less_humid && maxTemp %is% hotter && rainfall %is%
range2 && soil %is% Mixed_Red_and_Black_soil
,climate %is% Central_Dry_Zone),
fuzzy_rule(humidity %is% more_humid && maxTemp %is% hot && rainfall %is%
range3 && soil %is% Red_Loamy_soil
,climate %is% Hilly_Zone),
fuzzy_rule(humidity %is% more_humid && maxTemp %is% hotter && rainfall %is%
range3 && soil %is% Red_Lateritic_sandy_soil
,climate %is% Coastal_Zone),
fuzzy_rule(humidity %is% less_humid && maxTemp %is% hotter && rainfall %is%
range3 && soil %is% Black_soil
,climate %is% North_Eastern_Dry_Zone),
fuzzy_rule(humidity %is% more_humid && maxTemp %is% hot && rainfall %is%
range3 && soil %is% Red_Loamy_soil
,climate %is% Southern_Transition_Zone),
fuzzy_rule(humidity %is% humid && maxTemp %is% hot && rainfall %is% range2
&& soil %is% Mixed_Red_Loamy_and_sandy_soil
,climate %is% Eastern_Dry_Zone),
fuzzy_rule(humidity %is% less_humid && maxTemp %is% hotter && rainfall %is%
range2 && soil %is% Black_soil
,climate %is% Northern_Dry_Zone),
fuzzy_rule(humidity %is% humid && maxTemp %is% hot && rainfall %is% range3
&& soil %is% Red_Loamy_soil
,climate %is% Southern_Dry_Zone),
fuzzy_rule(humidity %is% less_humid && maxTemp %is% hot && rainfall %is%
range1 && soil %is% Black_soil
,climate %is% North_Eastern_Dry_Zone),
fuzzy_rule(humidity %is% humid && maxTemp %is% hotter && rainfall %is%
range2 && soil %is% Mixed_Red_Loamy_and_sandy_soil
,climate %is% Eastern_Dry_Zone)
)
model<- fuzzy_system(variables, rules)
### error code ####
example.1 <- fuzzy_inference(model,
list(humidity=63,maxTemp=31,rainfall=72.5,soil=41.5))
以下代码行抛出null错误。
### error code ####
example.1 <- fuzzy_inference(model,
list(humidity=63,maxTemp=31,rainfall=72.5,soil=41.5))
答案 0 :(得分:0)
我没有评估您的代码,但如果问题是您尝试在NULL
上设置属性,那么解决方案很简单。不要那样做。
NULL
对象实际上不是对象。它是对象的缺席。您无法修改它或为其设置属性;你不能拥有不同类别的NULL
个对象; NULL
没什么。
您可以将属性设置为NA
,因为 是一个对象 - 只是一个缺失值,而是一个特定类型。它是缺乏价值的明确表示。但是NULL
是不同的。这是R表示你没有物体的方式。
无法将属性分配给NULL
。如果您想要一个只表示类或属性的值,则需要NA
或其他一些表示。 NULL
无效。
答案 1 :(得分:0)
我遇到了同样的问题,发现这个旧线程没有解决方案。 就我而言,我定义了没有匹配特征的规则作为定义变量。
因此,请检查您的变量和规则。