#23 -- Fix inference
Some checks failed
CI fuzzy controller / container-test-job (push) Failing after 8s

This commit is contained in:
Anton Romanov 2025-03-04 11:18:42 +04:00
parent 3dc85d247b
commit 2a978bab5f
4 changed files with 14 additions and 9 deletions

View File

@ -31,7 +31,7 @@ public class SecurityConfiguration {
.headers(headers -> headers.frameOptions(HeadersConfigurer.FrameOptionsConfig::sameOrigin))
.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(auth ->
auth.requestMatchers("/").permitAll()
auth.requestMatchers("/", "get-inference").permitAll()
.requestMatchers(permittedUrls).permitAll()
.requestMatchers("/swagger-ui.html").hasAuthority(UserRoleConstants.ADMIN)
.anyRequest().authenticated())

View File

@ -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.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
@ -52,7 +53,7 @@ public class FuzzyInferenceService {
}
private List<String> getDemoRules() {
return List.of(
return Arrays.asList(
String.format(RULE_TEMPLATE, "возраст", "молодой", "доход", "высокий", "средний"),
String.format(RULE_TEMPLATE, "возраст", "средний", "доход", "высокий", "большой"),
String.format(RULE_TEMPLATE, "возраст", "старый", "доход", "средний", "средний")
@ -64,7 +65,7 @@ public class FuzzyInferenceService {
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.setRange(0, variable.getFuzzyTerms().getLast().getCrispValue());
input.setEnabled(true);
input.setLockValueInRange(false);
double prev = 0;
@ -83,7 +84,7 @@ public class FuzzyInferenceService {
final OutputVariable output = new OutputVariable();
output.setName(variable.getName());
output.setDescription("");
output.setRange(0, variable.getFuzzyTerms().get(variable.getFuzzyTerms().size() - 1).getCrispValue());
output.setRange(0, variable.getFuzzyTerms().getLast().getCrispValue());
output.setEnabled(true);
output.setAggregation(new Maximum());
output.setDefuzzifier(new WeightedAverage());
@ -117,7 +118,6 @@ public class FuzzyInferenceService {
mamdani.setImplication(new AlgebraicProduct());
mamdani.setActivation(new General());
rules.forEach(r -> mamdani.addRule(Rule.parse(r, engine)));
mamdani.addRule(new Rule());
return mamdani;
}
@ -141,18 +141,18 @@ public class FuzzyInferenceService {
public List<OutputValue> getFuzzyInference(Map<String, Double> vals) {
return getFuzzyInference(getDemoRules(), vals,
List.of(new Variable("возраст", List.of(
Arrays.asList(new Variable("возраст", Arrays.asList(
new FuzzyTerm("молодой", 35.0),
new FuzzyTerm("средний", 60.0),
new FuzzyTerm("старый", 100.0))
),
new Variable("доход", List.of(
new Variable("доход", Arrays.asList(
new FuzzyTerm("небольшой", 35000.0),
new FuzzyTerm("средний", 100000.0),
new FuzzyTerm("высокий", 500000.0))
)
),
List.of(new Variable("кредит", List.of(
Arrays.asList(new Variable("кредит", Arrays.asList(
new FuzzyTerm("небольшой", 20000.0),
new FuzzyTerm("средний", 100000.0),
new FuzzyTerm("большой", 1000000.0))))

View File

@ -0,0 +1,2 @@
org.apache.tomcat.level=INFO
org.apache.tomcat.util.net.level=WARNING

View File

@ -50,12 +50,15 @@
</div>
</div>
<input type="submit" class="btn btn-outline-success m-2" value="Получить результат вывода"/>
<div class="row" th:each="out : ${response}">
<div class="row" th:each="out : ${response}" th:if="${not #lists.isEmpty(response)}">
<div class="col-md-2"> Размер кредита:</div>
<div class="col-md-4" th:text="${out.fuzzyTerm}"></div>
<div class="col-md-3"> Степень принадлежности:</div>
<div class="col-md-1" th:text="${out.degree}"></div>
</div>
<div class="row" th:if="${response != null && #lists.isEmpty(response)}">
Нет результата
</div>
</form>
</div>
</html>