forked from fair-acc/chart-fx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDataSetIntegrateDifferentiateSample.java
70 lines (58 loc) · 2.55 KB
/
DataSetIntegrateDifferentiateSample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package de.gsi.math.samples;
import de.gsi.chart.renderer.ErrorStyle;
import de.gsi.dataset.DataSet;
import de.gsi.dataset.spi.DefaultErrorDataSet;
import de.gsi.math.DataSetMath;
import de.gsi.math.functions.GaussianFunction;
import de.gsi.math.samples.utils.AbstractDemoApplication;
import de.gsi.math.samples.utils.DemoChart;
import javafx.application.Application;
import javafx.scene.Node;
/**
* Sample to illustrate integral and differentiation of data sets low-pass filter
*
* @author rstein
*/
public class DataSetIntegrateDifferentiateSample extends AbstractDemoApplication {
private static final int N_SAMPLES = 100;
@Override
public Node getContent() {
final DemoChart chart = new DemoChart();
chart.getRenderer(0).setDrawMarker(false);
chart.getRenderer(0).setErrorType(ErrorStyle.ERRORSURFACE);
GaussianFunction gaussFunction = new GaussianFunction("gauss") {
@Override
public double getValue(final double x) {
return super.getValue(x) + 0 * 0.005 * RANDOM.nextGaussian();
}
};
gaussFunction.setParameterValue(0, 0.0); // mean
gaussFunction.setParameterValue(1, 0.8); // sigma
gaussFunction.setParameterValue(2, 1.0); // scale
DataSet dataSet = gaussFunction.getDataSetEstimate(-10.0, +10.0, N_SAMPLES);
dataSet.setStyle("strokeColor=darkblue;fillColor=darkblue;strokeWidth=0.5");
// add some errors
if (dataSet instanceof DefaultErrorDataSet) {
DefaultErrorDataSet ds = (DefaultErrorDataSet) dataSet;
for (int i = 0; i < ds.getDataCount(); i++) {
final double x = ds.getX(i);
final double y = ds.getY(i);
ds.set(i, x, y, 0.05, 0.05);
}
}
chart.getRenderer(0).getDatasets().add(dataSet);
DataSet integral = DataSetMath.integrateFunction(dataSet);
integral.setStyle("strokeColor=red;fillColor=red;strokeWidth=1");
chart.getRenderer(0).getDatasets().addAll(integral);
DataSet derivative = DataSetMath.derivativeFunction(dataSet);
derivative.setStyle("strokeColor=darkgreen;fillColor=darkgreen;strokeWidth=1");
chart.getRenderer(0).getDatasets().addAll(derivative);
DataSet control = DataSetMath.integrateFunction(derivative);
control.setStyle("strokeColor=cyan;fillColor=cyan;strokeWidth=1");
// renderer1.getDatasets().addAll(control);
return chart;
}
public static void main(final String[] args) {
Application.launch(args);
}
}