From 1192201a69cfd121d47197fd903b6674695bec71 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Mon, 13 May 2024 00:52:04 +0400 Subject: [PATCH] #96 -- Fix time series generation --- .../generation/model/GenerationForm.java | 39 ++++++++++++------- .../generation/service/GenerationService.java | 15 +++---- src/main/resources/templates/generation.html | 8 ++++ 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java index 8571d6a..e1e2c69 100644 --- a/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java +++ b/src/main/java/ru/ulstu/extractor/generation/model/GenerationForm.java @@ -2,11 +2,12 @@ package ru.ulstu.extractor.generation.model; public class GenerationForm { private int tsLength; - private int min; - private int max; - private int base; - private int baseTendency; - private int tendencyDynamic; + private double min; + private double max; + private double base; + private double baseTendency; + private double tendencyDynamic; + private double randomWeight; public int getTsLength() { return tsLength; @@ -16,43 +17,51 @@ public class GenerationForm { this.tsLength = tsLength; } - public int getMin() { + public double getMin() { return min; } - public void setMin(int min) { + public void setMin(double min) { this.min = min; } - public int getMax() { + public double getMax() { return max; } - public void setMax(int max) { + public void setMax(double max) { this.max = max; } - public int getBase() { + public double getBase() { return base; } - public void setBase(int base) { + public void setBase(double base) { this.base = base; } - public int getBaseTendency() { + public double getBaseTendency() { return baseTendency; } - public void setBaseTendency(int baseTendency) { + public void setBaseTendency(double baseTendency) { this.baseTendency = baseTendency; } - public int getTendencyDynamic() { + public double getTendencyDynamic() { return tendencyDynamic; } - public void setTendencyDynamic(int tendencyDynamic) { + public void setTendencyDynamic(double tendencyDynamic) { this.tendencyDynamic = tendencyDynamic; } + + public double getRandomWeight() { + return randomWeight; + } + + public void setRandomWeight(double randomWeight) { + this.randomWeight = randomWeight; + } } diff --git a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java index 0b168cd..34a160d 100644 --- a/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java +++ b/src/main/java/ru/ulstu/extractor/generation/service/GenerationService.java @@ -18,7 +18,6 @@ import java.util.List; public class GenerationService { private final TimeSeriesService timeSeriesService; private final BranchService branchService; - private final static double RANDOM_WEIGHT = 0.1; public GenerationService(TimeSeriesService timeSeriesService, BranchService branchService) { @@ -44,18 +43,20 @@ public class GenerationService { double newValue; int maxTryCount = 10; do { + double oneStepDiff = generationForm.getRandomWeight() * (Math.random() - 0.5) * (generationForm.getMax() - generationForm.getMin()) / (generationForm.getTsLength() + 10); if (timeSeriesValues.isEmpty()) { if (generationForm.getBaseTendency() > 0) { - newValue = 0.1 * Math.random() * (generationForm.getMax() - generationForm.getMin()); + newValue = 0.1 * (generationForm.getRandomWeight() > 0.0 ? oneStepDiff : 1.0) * (generationForm.getMax() - generationForm.getMin()); + } else if (generationForm.getBaseTendency() < 0) { + newValue = generationForm.getMax() - 0.1 * (generationForm.getRandomWeight() > 0.0 ? oneStepDiff : 1.0) * (generationForm.getMax() - generationForm.getMin()); } else { - newValue = generationForm.getMax() - 0.1 * Math.random() * (generationForm.getMax() - generationForm.getMin()); + newValue = generationForm.getBase(); } } else { newValue = timeSeriesValues.get(timeSeriesValues.size() - 1).getValue() - + Math.random() * generationForm.getBaseTendency() - * ((generationForm.getMax() - generationForm.getMin()) / generationForm.getTsLength()) - * generationForm.getTendencyDynamic() - + RANDOM_WEIGHT * (Math.random() - 0.5) * (generationForm.getMax() - generationForm.getMin()); + + (generationForm.getRandomWeight() > 0.0 ? oneStepDiff : 1.0) * generationForm.getBaseTendency() + * ((generationForm.getMax() - generationForm.getMin()) / (generationForm.getTsLength() + 10)) + * generationForm.getTendencyDynamic(); } maxTryCount--; } while (((newValue <= generationForm.getMin()) diff --git a/src/main/resources/templates/generation.html b/src/main/resources/templates/generation.html index f21f39d..ef7fd1d 100644 --- a/src/main/resources/templates/generation.html +++ b/src/main/resources/templates/generation.html @@ -56,6 +56,14 @@ +
+
+ Величина шума +
+
+ +
+