Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fbf3c6d

Browse filesBrowse files
committed
v1.97
1 parent 94e2018 commit fbf3c6d
Copy full SHA for fbf3c6d

File tree

Expand file treeCollapse file tree

147 files changed

+4497
-1989
lines changed
Filter options

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Dismiss banner
Expand file treeCollapse file tree

147 files changed

+4497
-1989
lines changed

‎src/main/java/pulse/AbstractData.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/AbstractData.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,4 +306,4 @@ public boolean equals(Object o) {
306306

307307
}
308308

309-
}
309+
}
+45Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package pulse;
2+
3+
import java.awt.geom.Point2D;
4+
import java.util.ArrayList;
5+
import java.util.List;
6+
import pulse.input.IndexRange;
7+
import pulse.math.Segment;
8+
9+
public interface DiscreteInput {
10+
11+
public List<Double> getX();
12+
public List<Double> getY();
13+
public IndexRange getIndexRange();
14+
15+
public static List<Point2D> convert(double[] x, double[] y) {
16+
17+
var ps = new ArrayList<Point2D>();
18+
19+
for(int i = 0, size = x.length; i < size; i++) {
20+
ps.add(new Point2D.Double(x[i], y[i]));
21+
}
22+
23+
return ps;
24+
25+
}
26+
27+
public static List<Point2D> convert(List<Double> x, List<Double> y) {
28+
29+
var ps = new ArrayList<Point2D>();
30+
31+
for(int i = 0, size = x.size(); i < size; i++) {
32+
ps.add(new Point2D.Double(x.get(i), y.get(i)));
33+
}
34+
35+
return ps;
36+
37+
}
38+
39+
public default Segment bounds() {
40+
var ir = getIndexRange();
41+
var x = getX();
42+
return new Segment(x.get(ir.getLowerBound()), x.get(ir.getUpperBound()));
43+
}
44+
45+
}

‎src/main/java/pulse/HeatingCurve.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/HeatingCurve.java
+20-11Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import static pulse.properties.NumericPropertyKeyword.TIME_SHIFT;
1111

1212
import java.util.ArrayList;
13+
import static java.util.Collections.max;
1314
import java.util.List;
1415
import java.util.Set;
1516

@@ -48,8 +49,8 @@ public class HeatingCurve extends AbstractData {
4849
private final List<HeatingCurveListener> listeners
4950
= new ArrayList<>();
5051

51-
private UnivariateInterpolator splineInterpolator;
52-
private UnivariateFunction splineInterpolation;
52+
private UnivariateInterpolator interpolator;
53+
private UnivariateFunction interpolation;
5354

5455
protected HeatingCurve(List<Double> time, List<Double> signal, final double startTime, String name) {
5556
super(time, name);
@@ -64,7 +65,7 @@ protected HeatingCurve(List<Double> time, List<Double> signal, final double star
6465
public HeatingCurve() {
6566
super();
6667
adjustedSignal = new ArrayList<>((int) this.getNumPoints().getValue());
67-
splineInterpolator = new SplineInterpolator();
68+
interpolator = new SplineInterpolator();
6869
}
6970

7071
/**
@@ -78,8 +79,8 @@ public HeatingCurve(HeatingCurve c) {
7879
super(c);
7980
this.adjustedSignal = new ArrayList<>(c.adjustedSignal);
8081
this.startTime = c.startTime;
81-
splineInterpolator = new SplineInterpolator();
82-
if (c.splineInterpolation != null) {
82+
interpolator = new SplineInterpolator();
83+
if (c.interpolation != null) {
8384
this.refreshInterpolation();
8485
}
8586
}
@@ -100,7 +101,7 @@ public HeatingCurve(NumericProperty count) {
100101
adjustedSignal = new ArrayList<>((int) count.getValue());
101102
startTime = (double) def(TIME_SHIFT).getValue();
102103

103-
splineInterpolator = new SplineInterpolator();
104+
interpolator = new SplineInterpolator();
104105
}
105106

106107
//TODO
@@ -163,7 +164,7 @@ public double signalAt(int index) {
163164
*/
164165
public void scale(double scale) {
165166
final int count = this.actualNumPoints();
166-
for (int i = 0; i < count; i++) {
167+
for (int i = 0, max = Math.min(count, signal.size()); i < max; i++) {
167168
signal.set(i, signal.get(i) * scale);
168169
}
169170
var dataEvent = new CurveEvent(RESCALED, this);
@@ -201,7 +202,8 @@ private void refreshInterpolation() {
201202
/*
202203
* Submit to spline interpolation
203204
*/
204-
splineInterpolation = splineInterpolator.interpolate(timeExtended, adjustedSignalExtended);
205+
206+
interpolation = interpolator.interpolate(timeExtended, adjustedSignalExtended);
205207
}
206208

207209
/**
@@ -346,8 +348,8 @@ public void setTimeShift(NumericProperty startTime) {
346348
firePropertyChanged(this, startTime);
347349
}
348350

349-
public UnivariateFunction getSplineInterpolation() {
350-
return splineInterpolation;
351+
public UnivariateFunction getInterpolation() {
352+
return interpolation;
351353
}
352354

353355
public List<Double> getBaselineCorrectedData() {
@@ -377,5 +379,12 @@ public boolean equals(Object o) {
377379

378380
return super.equals(o) && adjustedSignal.containsAll(((HeatingCurve) o).adjustedSignal);
379381
}
382+
383+
public double interpolateSignalAt(double x) {
384+
double min = this.timeAt(0);
385+
double max = timeLimit();
386+
return min < x && max > x ? interpolation.value(x)
387+
: (x < min ? signalAt(0) : signalAt(actualNumPoints() - 1));
388+
}
380389

381-
}
390+
}

‎src/main/java/pulse/Response.java

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package pulse;
2+
3+
import pulse.math.Segment;
4+
import pulse.problem.schemes.solvers.SolverException;
5+
import pulse.search.GeneralTask;
6+
import pulse.search.statistics.OptimiserStatistic;
7+
8+
public interface Response {
9+
10+
public double evaluate(double t);
11+
public Segment accessibleRange();
12+
13+
/**
14+
* Calculates the value of the objective function used to identify
15+
* the current state of the optimiser.
16+
* @param task
17+
* @return the value of the objective function in the current state
18+
* @throws pulse.problem.schemes.solvers.SolverException
19+
*/
20+
21+
public double objectiveFunction(GeneralTask task) throws SolverException;
22+
23+
public OptimiserStatistic getOptimiserStatistic();
24+
25+
}

‎src/main/java/pulse/baseline/AdjustableBaseline.java

Copy file name to clipboardExpand all lines: src/main/java/pulse/baseline/AdjustableBaseline.java
+51-18Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package pulse.baseline;
22

3-
import static pulse.properties.NumericProperties.derive;
4-
import static pulse.properties.NumericProperty.requireType;
5-
import static pulse.properties.NumericPropertyKeyword.BASELINE_INTERCEPT;
63
import java.util.List;
4+
import static pulse.properties.NumericPropertyKeyword.BASELINE_INTERCEPT;
75
import java.util.Set;
6+
import pulse.math.Parameter;
87

98
import pulse.math.ParameterVector;
10-
import pulse.math.Segment;
11-
import pulse.properties.Flag;
9+
import static pulse.properties.NumericProperties.derive;
1210
import pulse.properties.NumericProperty;
11+
import static pulse.properties.NumericProperty.requireType;
1312
import pulse.properties.NumericPropertyKeyword;
13+
import static pulse.properties.NumericPropertyKeyword.BASELINE_SLOPE;
1414
import pulse.util.PropertyHolder;
1515

1616
/**
@@ -21,27 +21,31 @@
2121
public abstract class AdjustableBaseline extends Baseline {
2222

2323
private double intercept;
24+
private double slope;
2425

2526
/**
2627
* Creates a flat baseline equal to the argument.
2728
*
2829
* @param intercept the constant baseline value.
2930
*/
30-
public AdjustableBaseline(double intercept) {
31+
public AdjustableBaseline(double intercept, double slope) {
3132
this.intercept = intercept;
33+
this.slope = slope;
3234
}
3335

3436
/**
35-
* @return the constant value of this {@code FlatBaseline}
37+
* Calculates the linear function {@code g(x) = intercept + slope*time}
38+
*
39+
* @param x the argument of the linear function
40+
* @return the result of this simple calculation
3641
*/
3742
@Override
3843
public double valueAt(double x) {
39-
return intercept;
44+
return intercept + x * slope;
4045
}
4146

4247
protected double mean(List<Double> x) {
43-
double sum = x.stream().reduce((a, b) -> a + b).get();
44-
return sum / x.size();
48+
return x.stream().mapToDouble(d -> d).average().getAsDouble();
4549
}
4650

4751
/**
@@ -69,6 +73,29 @@ public void setIntercept(NumericProperty intercept) {
6973
firePropertyChanged(this, intercept);
7074
}
7175

76+
/**
77+
* Provides getter accessibility to the slope as a NumericProperty
78+
*
79+
* @return a NumericProperty derived from
80+
* NumericPropertyKeyword.BASELINE_SLOPE with a value equal to slop
81+
*/
82+
public NumericProperty getSlope() {
83+
return derive(BASELINE_SLOPE, slope);
84+
}
85+
86+
/**
87+
* Checks whether {@code slope} is a baseline slope property and updates the
88+
* respective value of this baseline.
89+
*
90+
* @param slope a {@code NumericProperty} of the {@code BASELINE_SLOPE} type
91+
* @see set
92+
*/
93+
public void setSlope(NumericProperty slope) {
94+
requireType(slope, BASELINE_SLOPE);
95+
this.slope = (double) slope.getValue();
96+
firePropertyChanged(this, slope);
97+
}
98+
7299
/**
73100
* Lists the {@code intercept} as accessible property for this
74101
* {@code FlatBaseline}.
@@ -91,13 +118,17 @@ public void set(NumericPropertyKeyword type, NumericProperty property) {
91118
}
92119

93120
@Override
94-
public void optimisationVector(ParameterVector output, List<Flag> flags) {
95-
for (int i = 0, size = output.dimension(); i < size; i++) {
121+
public void optimisationVector(ParameterVector output) {
122+
for (Parameter p : output.getParameters()) {
123+
124+
if (p != null) {
125+
126+
var key = p.getIdentifier().getKeyword();
96127

97-
var key = output.getIndex(i);
128+
if (key == BASELINE_INTERCEPT) {
129+
p.setValue(intercept);
130+
}
98131

99-
if (key == BASELINE_INTERCEPT) {
100-
output.set(i, intercept, key);
101132
}
102133

103134
}
@@ -106,10 +137,12 @@ public void optimisationVector(ParameterVector output, List<Flag> flags) {
106137

107138
@Override
108139
public void assign(ParameterVector params) {
109-
for (int i = 0, size = params.dimension(); i < size; i++) {
140+
for (Parameter p : params.getParameters()) {
110141

111-
if (params.getIndex(i) == BASELINE_INTERCEPT) {
112-
setIntercept(derive(BASELINE_INTERCEPT, params.get(i)));
142+
if (p.getIdentifier().getKeyword() == BASELINE_INTERCEPT) {
143+
setIntercept(
144+
derive(BASELINE_INTERCEPT, p.inverseTransform())
145+
);
113146
}
114147

115148
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.