demo #9

Merged
romanov73 merged 5 commits from 8-demo into master 2023-09-07 18:17:10 +04:00
2 changed files with 7 additions and 20 deletions
Showing only changes of commit 93141932d6 - Show all commits

View File

@ -34,7 +34,7 @@ public class InferenceMvcController {
model.addAttribute("ageAntecedents", getAgeAntecedents());
model.addAttribute("incomeAntecedents", getIncomeAntecedents());
model.addAttribute("inferenceForm", inferenceForm);
model.addAttribute("response", fuzzyInferenceService.getFuzzyInference().get(0));
model.addAttribute("response", fuzzyInferenceService.getFuzzyInference());
return "index";
}

View File

@ -17,7 +17,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@ -45,7 +44,7 @@ public class FuzzyInferenceService {
new AbstractMap.SimpleEntry("высокий", 500000)));
private Map<String, List<Entry<String, Integer>>> outputFuzzyTerms = Map.of(
"кредит", List.of(new AbstractMap.SimpleEntry("небольшой", 200000),
"кредит", List.of(new AbstractMap.SimpleEntry("небольшой", 20000),
new AbstractMap.SimpleEntry("средний", 100000),
new AbstractMap.SimpleEntry("большой", 1000000)));
@ -66,6 +65,7 @@ public class FuzzyInferenceService {
final InputVariable input = new InputVariable();
input.setName(name);
input.setDescription("");
input.setRange(0, terms.get(terms.size() - 1).getValue());
input.setEnabled(true);
input.setLockValueInRange(false);
double prev = 0;
@ -81,9 +81,10 @@ public class FuzzyInferenceService {
final OutputVariable output = new OutputVariable();
output.setName(name);
output.setDescription("");
output.setRange(0, terms.get(terms.size() - 1).getValue());
output.setEnabled(true);
output.setAggregation(new Maximum());
output.setDefuzzifier(new Centroid(10));
output.setDefuzzifier(new Centroid(terms.get(terms.size() - 1).getValue()));
output.setDefaultValue(Double.NaN);
output.setLockValueInRange(false);
double prev = 0;
@ -133,24 +134,10 @@ public class FuzzyInferenceService {
: outputVariable.fuzzyOutput().getTerms().stream().collect(Collectors.toMap(t -> t.getTerm().getName(), Activated::getDegree));
}
public List<Double> getFuzzyInference() {
//variableValues.entrySet().forEach(e -> System.out.println(e.getKey() + " " + e.getValue()));
public Map<String, Double> getFuzzyInference() {
Engine engine = getFuzzyEngine();
//List<Integer> consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList());
engine.addRuleBlock(getRuleBlock(engine, getDemoRules()));
Map<String, Double> consequents = getConsequent(engine, Map.of("возраст", 20.0, "доход", 250000.0));
if (consequents.containsKey(NO_RESULT)) {
return new ArrayList<>();
}
/*List<Assessment> assessments = new ArrayList<>();
for (Map.Entry<String, Double> consequent : consequents.entrySet()) {
for (DbRule dbRule : dbRules) {
if (dbRule.getId().equals(Integer.valueOf(consequent.getKey()))) {
assessments.add(new Assessment(dbRule, consequent.getValue()));
}
}
}*/
return List.of(0.0);
return getConsequent(engine, Map.of("возраст", 20.0, "доход", 250000.0));
}
}