#2 -- Fix inference
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 2m15s
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 2m15s
This commit is contained in:
parent
76ece94028
commit
67dc9d275d
@ -1,10 +1,12 @@
|
||||
package ru.ulstu.fc.rule.model;
|
||||
|
||||
public class OutputValue {
|
||||
private String variable;
|
||||
private String fuzzyTerm;
|
||||
private Double degree;
|
||||
|
||||
public OutputValue(String fuzzyTerm, Double degree) {
|
||||
public OutputValue(String variable, String fuzzyTerm, Double degree) {
|
||||
this.variable = variable;
|
||||
this.fuzzyTerm = fuzzyTerm;
|
||||
this.degree = degree;
|
||||
}
|
||||
@ -24,4 +26,12 @@ public class OutputValue {
|
||||
public void setDegree(Double degree) {
|
||||
this.degree = degree;
|
||||
}
|
||||
|
||||
public String getVariable() {
|
||||
return variable;
|
||||
}
|
||||
|
||||
public void setVariable(String variable) {
|
||||
this.variable = variable;
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import ru.ulstu.fc.rule.model.ProjectInferenceData;
|
||||
import ru.ulstu.fc.rule.model.Variable;
|
||||
import ru.ulstu.fc.rule.model.dto.VariableValueDto;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@ -62,6 +63,7 @@ public class FuzzyInferenceService {
|
||||
final InputVariable input = new InputVariable();
|
||||
input.setName(variable.getName());
|
||||
input.setDescription("");
|
||||
variable.getFuzzyTerms().sort(Comparator.comparing(FuzzyTerm::getCrispValue));
|
||||
input.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getCrispValue());
|
||||
input.setEnabled(true);
|
||||
input.setLockValueInRange(false);
|
||||
@ -120,22 +122,21 @@ public class FuzzyInferenceService {
|
||||
}
|
||||
|
||||
private List<OutputValue> getConsequent(Engine engine, Map<String, Double> variableValues) {
|
||||
OutputVariable outputVariable = engine.getOutputVariable(OUTPUT_VARIABLE_NAME);
|
||||
List<OutputVariable> outputVariables = engine.getOutputVariables();
|
||||
for (Map.Entry<String, Double> variableValue : variableValues.entrySet()) {
|
||||
InputVariable inputVariable = engine.getInputVariable(variableValue.getKey());
|
||||
inputVariable.setValue(variableValue.getValue());
|
||||
}
|
||||
engine.process();
|
||||
if (outputVariable != null) {
|
||||
LOG.info("Output: {}", outputVariable.getValue());
|
||||
}
|
||||
return Double.isNaN(outputVariable.getValue())
|
||||
? List.of(new OutputValue(NO_RESULT, 0.0))
|
||||
: outputVariable.fuzzyOutput()
|
||||
.getTerms()
|
||||
|
||||
return outputVariables
|
||||
.stream()
|
||||
.map(t -> new OutputValue(t.getTerm().getName(), t.getDegree()))
|
||||
.collect(Collectors.toList());
|
||||
.filter(v -> !Double.isNaN(v.getValue()))
|
||||
.map(OutputVariable::fuzzyOutput)
|
||||
.map(a -> new OutputValue(a.getName(),
|
||||
a.getTerms().getFirst().getTerm().getName(),
|
||||
a.getTerms().getFirst().getDegree()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public List<OutputValue> getFuzzyInference(Map<String, Double> vals) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user