#31 -- Add horizon for inference
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 2m13s
All checks were successful
CI fuzzy controller / container-test-job (push) Successful in 2m13s
This commit is contained in:
parent
784bc57aa5
commit
de63be3014
@ -3,6 +3,7 @@ package ru.ulstu.fc.rule.model.dto;
|
|||||||
public class FuzzyRuleDataDto {
|
public class FuzzyRuleDataDto {
|
||||||
private String[] fuzzyTerms;
|
private String[] fuzzyTerms;
|
||||||
private int window = 3;
|
private int window = 3;
|
||||||
|
private int horizon = 1;
|
||||||
|
|
||||||
public String[] getFuzzyTerms() {
|
public String[] getFuzzyTerms() {
|
||||||
return fuzzyTerms;
|
return fuzzyTerms;
|
||||||
@ -19,4 +20,12 @@ public class FuzzyRuleDataDto {
|
|||||||
public void setWindow(int window) {
|
public void setWindow(int window) {
|
||||||
this.window = window;
|
this.window = window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getHorizon() {
|
||||||
|
return horizon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHorizon(int horizon) {
|
||||||
|
this.horizon = horizon;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import ru.ulstu.fc.rule.model.Variable;
|
|||||||
import ru.ulstu.fc.rule.model.dto.FuzzyRuleDataDto;
|
import ru.ulstu.fc.rule.model.dto.FuzzyRuleDataDto;
|
||||||
import ru.ulstu.fc.rule.model.dto.VariableValueDto;
|
import ru.ulstu.fc.rule.model.dto.VariableValueDto;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -216,7 +217,12 @@ public class FuzzyInferenceService {
|
|||||||
ProjectDto projectDto = projectService.save(new ProjectDto(new Date().toString()));
|
ProjectDto projectDto = projectService.save(new ProjectDto(new Date().toString()));
|
||||||
fuzzyRuleParseService.generateRules(projectDto.getId(), fuzzyRuleDataDto);
|
fuzzyRuleParseService.generateRules(projectDto.getId(), fuzzyRuleDataDto);
|
||||||
Map<String, Double> variableValues = new HashMap<>();
|
Map<String, Double> variableValues = new HashMap<>();
|
||||||
|
|
||||||
|
List<OutputValue> result = new ArrayList<>();
|
||||||
|
for (int h = 0; h < fuzzyRuleDataDto.getHorizon(); h++) {
|
||||||
List<String> labels = new LinkedList<>(Arrays.asList(fuzzyRuleDataDto.getFuzzyTerms()));
|
List<String> labels = new LinkedList<>(Arrays.asList(fuzzyRuleDataDto.getFuzzyTerms()));
|
||||||
|
labels.addAll(result.stream().map(OutputValue::getFuzzyTerm).toList());
|
||||||
|
|
||||||
while (labels.size() > fuzzyRuleDataDto.getWindow()) {
|
while (labels.size() > fuzzyRuleDataDto.getWindow()) {
|
||||||
labels.removeFirst();
|
labels.removeFirst();
|
||||||
}
|
}
|
||||||
@ -229,6 +235,20 @@ public class FuzzyInferenceService {
|
|||||||
.filter(ft -> ft.getDescription().equals(label))
|
.filter(ft -> ft.getDescription().equals(label))
|
||||||
.mapToDouble(FuzzyTerm::getCrispValue).findAny().getAsDouble());
|
.mapToDouble(FuzzyTerm::getCrispValue).findAny().getAsDouble());
|
||||||
}
|
}
|
||||||
return getProjectFuzzyInference(projectDto.getId(), variableValues);
|
List<OutputValue> onePointResult = getProjectFuzzyInference(projectDto.getId(), variableValues);
|
||||||
|
if (onePointResult.isEmpty()) {
|
||||||
|
onePointResult = new ArrayList<>();
|
||||||
|
if (result.isEmpty()) {
|
||||||
|
onePointResult.add(
|
||||||
|
new OutputValue("someVar",
|
||||||
|
fuzzyRuleDataDto.getFuzzyTerms()[fuzzyRuleDataDto.getFuzzyTerms().length - 1],
|
||||||
|
1.0));
|
||||||
|
} else {
|
||||||
|
onePointResult.add(result.getLast());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result.add(onePointResult.getFirst());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user