#96 -- Fix time series generation

This commit is contained in:
Anton Romanov 2024-05-13 00:52:04 +04:00
parent 8bcdff3ba1
commit 1192201a69
3 changed files with 40 additions and 22 deletions

View File

@ -2,11 +2,12 @@ package ru.ulstu.extractor.generation.model;
public class GenerationForm { public class GenerationForm {
private int tsLength; private int tsLength;
private int min; private double min;
private int max; private double max;
private int base; private double base;
private int baseTendency; private double baseTendency;
private int tendencyDynamic; private double tendencyDynamic;
private double randomWeight;
public int getTsLength() { public int getTsLength() {
return tsLength; return tsLength;
@ -16,43 +17,51 @@ public class GenerationForm {
this.tsLength = tsLength; this.tsLength = tsLength;
} }
public int getMin() { public double getMin() {
return min; return min;
} }
public void setMin(int min) { public void setMin(double min) {
this.min = min; this.min = min;
} }
public int getMax() { public double getMax() {
return max; return max;
} }
public void setMax(int max) { public void setMax(double max) {
this.max = max; this.max = max;
} }
public int getBase() { public double getBase() {
return base; return base;
} }
public void setBase(int base) { public void setBase(double base) {
this.base = base; this.base = base;
} }
public int getBaseTendency() { public double getBaseTendency() {
return baseTendency; return baseTendency;
} }
public void setBaseTendency(int baseTendency) { public void setBaseTendency(double baseTendency) {
this.baseTendency = baseTendency; this.baseTendency = baseTendency;
} }
public int getTendencyDynamic() { public double getTendencyDynamic() {
return tendencyDynamic; return tendencyDynamic;
} }
public void setTendencyDynamic(int tendencyDynamic) { public void setTendencyDynamic(double tendencyDynamic) {
this.tendencyDynamic = tendencyDynamic; this.tendencyDynamic = tendencyDynamic;
} }
public double getRandomWeight() {
return randomWeight;
}
public void setRandomWeight(double randomWeight) {
this.randomWeight = randomWeight;
}
} }

View File

@ -18,7 +18,6 @@ import java.util.List;
public class GenerationService { public class GenerationService {
private final TimeSeriesService timeSeriesService; private final TimeSeriesService timeSeriesService;
private final BranchService branchService; private final BranchService branchService;
private final static double RANDOM_WEIGHT = 0.1;
public GenerationService(TimeSeriesService timeSeriesService, public GenerationService(TimeSeriesService timeSeriesService,
BranchService branchService) { BranchService branchService) {
@ -44,18 +43,20 @@ public class GenerationService {
double newValue; double newValue;
int maxTryCount = 10; int maxTryCount = 10;
do { do {
double oneStepDiff = generationForm.getRandomWeight() * (Math.random() - 0.5) * (generationForm.getMax() - generationForm.getMin()) / (generationForm.getTsLength() + 10);
if (timeSeriesValues.isEmpty()) { if (timeSeriesValues.isEmpty()) {
if (generationForm.getBaseTendency() > 0) { 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 { } else {
newValue = generationForm.getMax() - 0.1 * Math.random() * (generationForm.getMax() - generationForm.getMin()); newValue = generationForm.getBase();
} }
} else { } else {
newValue = timeSeriesValues.get(timeSeriesValues.size() - 1).getValue() newValue = timeSeriesValues.get(timeSeriesValues.size() - 1).getValue()
+ Math.random() * generationForm.getBaseTendency() + (generationForm.getRandomWeight() > 0.0 ? oneStepDiff : 1.0) * generationForm.getBaseTendency()
* ((generationForm.getMax() - generationForm.getMin()) / generationForm.getTsLength()) * ((generationForm.getMax() - generationForm.getMin()) / (generationForm.getTsLength() + 10))
* generationForm.getTendencyDynamic() * generationForm.getTendencyDynamic();
+ RANDOM_WEIGHT * (Math.random() - 0.5) * (generationForm.getMax() - generationForm.getMin());
} }
maxTryCount--; maxTryCount--;
} while (((newValue <= generationForm.getMin()) } while (((newValue <= generationForm.getMin())

View File

@ -56,6 +56,14 @@
<input type="text" class="form-control m-1" th:field="*{tendencyDynamic}"> <input type="text" class="form-control m-1" th:field="*{tendencyDynamic}">
</div> </div>
</div> </div>
<div class="row">
<div class="col-md-4 col-sm-12">
Величина шума
</div>
<div class="col-md-6 col-sm-12">
<input type="text" class="form-control m-1" th:field="*{randomWeight}">
</div>
</div>
<div class="row"> <div class="row">
<div class="col-md-4 col-sm-12"> <div class="col-md-4 col-sm-12">
<input type="submit" class="btn btn-outline-success form-control" value="Сгенерировать временные ряды"/> <input type="submit" class="btn btn-outline-success form-control" value="Сгенерировать временные ряды"/>