#8 -- final of the demo
This commit is contained in:
parent
ab9a60cdd2
commit
93141932d6
@ -34,7 +34,7 @@ public class InferenceMvcController {
|
|||||||
model.addAttribute("ageAntecedents", getAgeAntecedents());
|
model.addAttribute("ageAntecedents", getAgeAntecedents());
|
||||||
model.addAttribute("incomeAntecedents", getIncomeAntecedents());
|
model.addAttribute("incomeAntecedents", getIncomeAntecedents());
|
||||||
model.addAttribute("inferenceForm", inferenceForm);
|
model.addAttribute("inferenceForm", inferenceForm);
|
||||||
model.addAttribute("response", fuzzyInferenceService.getFuzzyInference().get(0));
|
model.addAttribute("response", fuzzyInferenceService.getFuzzyInference());
|
||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@ import org.slf4j.LoggerFactory;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -45,7 +44,7 @@ public class FuzzyInferenceService {
|
|||||||
new AbstractMap.SimpleEntry("высокий", 500000)));
|
new AbstractMap.SimpleEntry("высокий", 500000)));
|
||||||
|
|
||||||
private Map<String, List<Entry<String, Integer>>> outputFuzzyTerms = Map.of(
|
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("средний", 100000),
|
||||||
new AbstractMap.SimpleEntry("большой", 1000000)));
|
new AbstractMap.SimpleEntry("большой", 1000000)));
|
||||||
|
|
||||||
@ -66,6 +65,7 @@ public class FuzzyInferenceService {
|
|||||||
final InputVariable input = new InputVariable();
|
final InputVariable input = new InputVariable();
|
||||||
input.setName(name);
|
input.setName(name);
|
||||||
input.setDescription("");
|
input.setDescription("");
|
||||||
|
input.setRange(0, terms.get(terms.size() - 1).getValue());
|
||||||
input.setEnabled(true);
|
input.setEnabled(true);
|
||||||
input.setLockValueInRange(false);
|
input.setLockValueInRange(false);
|
||||||
double prev = 0;
|
double prev = 0;
|
||||||
@ -81,9 +81,10 @@ public class FuzzyInferenceService {
|
|||||||
final OutputVariable output = new OutputVariable();
|
final OutputVariable output = new OutputVariable();
|
||||||
output.setName(name);
|
output.setName(name);
|
||||||
output.setDescription("");
|
output.setDescription("");
|
||||||
|
output.setRange(0, terms.get(terms.size() - 1).getValue());
|
||||||
output.setEnabled(true);
|
output.setEnabled(true);
|
||||||
output.setAggregation(new Maximum());
|
output.setAggregation(new Maximum());
|
||||||
output.setDefuzzifier(new Centroid(10));
|
output.setDefuzzifier(new Centroid(terms.get(terms.size() - 1).getValue()));
|
||||||
output.setDefaultValue(Double.NaN);
|
output.setDefaultValue(Double.NaN);
|
||||||
output.setLockValueInRange(false);
|
output.setLockValueInRange(false);
|
||||||
double prev = 0;
|
double prev = 0;
|
||||||
@ -133,24 +134,10 @@ public class FuzzyInferenceService {
|
|||||||
: outputVariable.fuzzyOutput().getTerms().stream().collect(Collectors.toMap(t -> t.getTerm().getName(), Activated::getDegree));
|
: outputVariable.fuzzyOutput().getTerms().stream().collect(Collectors.toMap(t -> t.getTerm().getName(), Activated::getDegree));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Double> getFuzzyInference() {
|
public Map<String, Double> getFuzzyInference() {
|
||||||
//variableValues.entrySet().forEach(e -> System.out.println(e.getKey() + " " + e.getValue()));
|
|
||||||
Engine engine = getFuzzyEngine();
|
Engine engine = getFuzzyEngine();
|
||||||
//List<Integer> consequentValues = dbRules.stream().map(DbRule::getId).collect(Collectors.toList());
|
|
||||||
engine.addRuleBlock(getRuleBlock(engine, getDemoRules()));
|
engine.addRuleBlock(getRuleBlock(engine, getDemoRules()));
|
||||||
Map<String, Double> consequents = getConsequent(engine, Map.of("возраст", 20.0, "доход", 250000.0));
|
return 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user