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 b4d8cb4

Browse filesBrowse files
committed
add CoordVarInfo for domain: step
1 parent 9aa5067 commit b4d8cb4
Copy full SHA for b4d8cb4

File tree

Expand file treeCollapse file tree

12 files changed

+95
-50
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

12 files changed

+95
-50
lines changed
Open diff view settings
Collapse file

‎src/symjava/domains/Domain.java‎

Copy file name to clipboardExpand all lines: src/symjava/domains/Domain.java
+43-6Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package symjava.domains;
22

33
import java.util.ArrayList;
4+
import java.util.HashMap;
45
import java.util.List;
6+
import java.util.Map;
57

68
import symjava.math.Transformation;
79
import symjava.numeric.NumFunc;
@@ -14,7 +16,15 @@
1416
public abstract class Domain {
1517
protected String label;
1618
protected Expr[] coordVars;
17-
Double step = null;
19+
20+
public static class CoordVarInfo {
21+
double stepSize;
22+
double minBound;
23+
double maxBound;
24+
}
25+
26+
protected Map<Expr, CoordVarInfo> infoMap = new HashMap<Expr, CoordVarInfo>();
27+
1828

1929
/**
2030
* Return a (n-1) dim domain that represents the boundary of the domain
@@ -79,17 +89,44 @@ public double[][] getIntWeightAndPoints(int order) {
7989
}
8090

8191
/**
82-
* Split the domain evenly with size step in each direction
92+
* Split the domain evenly with size step in the given direction
8393
* @param step
8494
* @return
8595
*/
86-
public Domain setStep(double step) {
87-
this.step = step;
96+
public Domain setStepSize(Expr x, double stepSize) {
97+
CoordVarInfo info = infoMap.get(x);
98+
if(info == null) {
99+
info = new CoordVarInfo();
100+
infoMap.put(x, info);
101+
}
102+
info.stepSize = stepSize;
88103
return this;
89104
}
90105

91-
public Double getStep() {
92-
return step;
106+
/**
107+
* Get the step size of the given direction
108+
* @param x
109+
* @return
110+
*/
111+
public Double getStepSize(Expr x) {
112+
CoordVarInfo info = infoMap.get(x);
113+
if(info == null)
114+
return null;
115+
return info.stepSize;
116+
}
117+
118+
public Domain setStepSize(double stepSize) {
119+
for(Expr x : this.coordVars) {
120+
setStepSize(x, stepSize);
121+
}
122+
return this;
123+
}
124+
125+
public Double getStepSize() {
126+
for(Expr x : this.coordVars) {
127+
return getStepSize(x);
128+
}
129+
return null;
93130
}
94131

95132
/**
Collapse file

‎src/symjava/domains/Interval.java‎

Copy file name to clipboardExpand all lines: src/symjava/domains/Interval.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static <T1, T2> Domain apply(T1 start, T2 end) {
5050
return new Interval(s, e);
5151
}
5252

53-
public static <T1, T2> Domain apply(T1 start, T2 end, Expr coordVar) {
53+
public static <T1, T2> Interval apply(T1 start, T2 end, Expr coordVar) {
5454
Expr s = null, e = null;
5555
if(start instanceof Number) {
5656
s = new SymDouble(((Number)start).doubleValue());
Collapse file

‎src/symjava/examples/BlackScholes.java‎

Copy file name to clipboardExpand all lines: src/symjava/examples/BlackScholes.java
+6-10Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@ public static void test1() {
4242
Expr dm = (log(fwd/strike)-0.5*pow(stdDev,2))/stdDev;
4343

4444
//we use -10 instead of -oo for numerical computation
45-
Domain I1 = Interval.apply(-10, phi*dp, z);
46-
Domain I2 = Interval.apply(-10, phi*dm, z);
47-
double stepSize = 1e-3;
48-
I1.setStep(stepSize);
49-
I2.setStep(stepSize);
45+
double step = 1e-3;
46+
Domain I1 = Interval.apply(-10, phi*dp, z).setStepSize(step);
47+
Domain I2 = Interval.apply(-10, phi*dm, z).setStepSize(step);
5048
Expr cdf1 = Integrate.apply(exp(-0.5*pow(z,2)), I1)/sqrt(PI2);
5149
Expr cdf2 = Integrate.apply(exp(-0.5*pow(z,2)), I2)/sqrt(PI2);
5250

@@ -126,11 +124,9 @@ public static void test2() {
126124
Expr d2 = d1-sigma*sqrt(t);
127125

128126
//we use -10 instead of -oo for numerical computation
129-
Domain I1 = Interval.apply(-10, d1, z);
130-
Domain I2 = Interval.apply(-10, d2, z);
131-
double stepSize = 1e-3;
132-
I1.setStep(stepSize);
133-
I2.setStep(stepSize);
127+
double step = 1e-3;
128+
Domain I1 = Interval.apply(-10, d1, z).setStepSize(step);
129+
Domain I2 = Interval.apply(-10, d2, z).setStepSize(step);
134130
Expr cdf1 = Integrate.apply(exp(-0.5*pow(z,2)), I1)/sqrt(PI2);
135131
Expr cdf2 = Integrate.apply(exp(-0.5*pow(z,2)), I2)/sqrt(PI2);
136132
Expr f = s0*cdf1-E*exp(-r*t)*cdf2-c;
Collapse file

‎src/symjava/examples/NumericalIntegration.java‎

Copy file name to clipboardExpand all lines: src/symjava/examples/NumericalIntegration.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static void main(String[] args) {
1818

1919
public static void test_1D() {
2020
//Define the interal
21-
Domain I = Interval.apply(-10, 0).setStep(0.01);
21+
Domain I = Interval.apply(-10, 0).setStepSize(0.01);
2222
//Define the integral: cumulative distribution function
2323
Expr cdf = Integrate.apply(exp(-0.5*pow(x,2))/sqrt(2*PI), I);
2424
System.out.println(cdf); //\int_{-10.0}^{10.0}{1/\sqrt{2*\pi}*e^{-0.5*x^2}}dx
Collapse file

‎src/symjava/relational/Eq.java‎

Copy file name to clipboardExpand all lines: src/symjava/relational/Eq.java
+2-4Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public class Eq extends BinaryOp implements Relation {
2828
*/
2929
public Eq(Expr lhs, Expr rhs) {
3030
super(lhs, rhs);
31+
this.label = arg1 + " = " + arg2;
32+
this.sortKey = this.label;
3133
this.freeVars = Utils.extractSymbols(rhs).toArray(new Expr[0]);
3234
this.params = new Expr[0];
3335
this.dependentVars = Utils.extractSymbols(lhs).toArray(new Expr[0]);
@@ -247,10 +249,6 @@ public Expr[] getDependentVars() {
247249
public Expr solve(Expr var) {
248250
return null;
249251
}
250-
251-
public String toString() {
252-
return arg1 + " = " + arg2;
253-
}
254252

255253
@Override
256254
public Expr simplify() {
Collapse file

‎src/symjava/relational/Ge.java‎

Copy file name to clipboardExpand all lines: src/symjava/relational/Ge.java
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ public class Ge extends BinaryOp implements Relation {
77

88
public Ge(Expr arg1, Expr arg2) {
99
super(arg1, arg2);
10-
// TODO Auto-generated constructor stub
10+
this.label = arg1 + " >= " + arg2;
11+
this.sortKey = this.label;
12+
1113
}
1214

1315
@Override
1416
public Expr simplify() {
15-
// TODO Auto-generated method stub
16-
return null;
17+
return this;
1718
}
1819

1920
@Override
2021
public boolean symEquals(Expr other) {
21-
// TODO Auto-generated method stub
2222
return false;
2323
}
2424

@@ -27,4 +27,8 @@ public Expr diff(Expr expr) {
2727
// TODO Auto-generated method stub
2828
return null;
2929
}
30+
31+
public static Ge apply(Expr lhs, Expr rhs) {
32+
return new Ge(lhs, rhs);
33+
}
3034
}
Collapse file

‎src/symjava/relational/Gt.java‎

Copy file name to clipboardExpand all lines: src/symjava/relational/Gt.java
+8-5Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ public class Gt extends BinaryOp implements Relation {
77

88
public Gt(Expr arg1, Expr arg2) {
99
super(arg1, arg2);
10-
// TODO Auto-generated constructor stub
10+
this.label = arg1 + " > " + arg2;
11+
this.sortKey = this.label;
12+
1113
}
1214

1315
@Override
1416
public Expr simplify() {
15-
// TODO Auto-generated method stub
16-
return null;
17+
return this;
1718
}
1819

1920
@Override
2021
public boolean symEquals(Expr other) {
21-
// TODO Auto-generated method stub
2222
return false;
2323
}
2424

@@ -27,5 +27,8 @@ public Expr diff(Expr expr) {
2727
// TODO Auto-generated method stub
2828
return null;
2929
}
30-
30+
31+
public static Gt apply(Expr lhs, Expr rhs) {
32+
return new Gt(lhs, rhs);
33+
}
3134
}
Collapse file

‎src/symjava/relational/Le.java‎

Copy file name to clipboardExpand all lines: src/symjava/relational/Le.java
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ public class Le extends BinaryOp implements Relation {
77

88
public Le(Expr arg1, Expr arg2) {
99
super(arg1, arg2);
10-
// TODO Auto-generated constructor stub
10+
this.label = arg1 + " <= " + arg2;
11+
this.sortKey = this.label;
12+
1113
}
1214

1315
@Override
1416
public Expr simplify() {
15-
// TODO Auto-generated method stub
16-
return null;
17+
return this;
1718
}
1819

1920
@Override
2021
public boolean symEquals(Expr other) {
21-
// TODO Auto-generated method stub
2222
return false;
2323
}
2424

@@ -27,5 +27,7 @@ public Expr diff(Expr expr) {
2727
// TODO Auto-generated method stub
2828
return null;
2929
}
30-
30+
public static Le apply(Expr lhs, Expr rhs) {
31+
return new Le(lhs, rhs);
32+
}
3133
}
Collapse file

‎src/symjava/relational/Lt.java‎

Copy file name to clipboardExpand all lines: src/symjava/relational/Lt.java
+7-5Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,18 @@ public class Lt extends BinaryOp implements Relation {
77

88
public Lt(Expr arg1, Expr arg2) {
99
super(arg1, arg2);
10-
// TODO Auto-generated constructor stub
10+
this.label = arg1 + " < " + arg2;
11+
this.sortKey = this.label;
12+
1113
}
1214

1315
@Override
1416
public Expr simplify() {
15-
// TODO Auto-generated method stub
16-
return null;
17+
return this;
1718
}
1819

1920
@Override
2021
public boolean symEquals(Expr other) {
21-
// TODO Auto-generated method stub
2222
return false;
2323
}
2424

@@ -27,5 +27,7 @@ public Expr diff(Expr expr) {
2727
// TODO Auto-generated method stub
2828
return null;
2929
}
30-
30+
public static Lt apply(Expr lhs, Expr rhs) {
31+
return new Lt(lhs, rhs);
32+
}
3133
}
Collapse file

‎src/symjava/relational/Neq.java‎

Copy file name to clipboardExpand all lines: src/symjava/relational/Neq.java
+6-5Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,17 @@ public class Neq extends BinaryOp implements Relation {
77

88
public Neq(Expr arg1, Expr arg2) {
99
super(arg1, arg2);
10-
// TODO Auto-generated constructor stub
10+
this.label = arg1 + " != " + arg2;
11+
this.sortKey = this.label;
1112
}
1213

1314
@Override
1415
public Expr simplify() {
15-
// TODO Auto-generated method stub
16-
return null;
16+
return this;
1717
}
1818

1919
@Override
2020
public boolean symEquals(Expr other) {
21-
// TODO Auto-generated method stub
2221
return false;
2322
}
2423

@@ -27,5 +26,7 @@ public Expr diff(Expr expr) {
2726
// TODO Auto-generated method stub
2827
return null;
2928
}
30-
29+
public static Neq apply(Expr lhs, Expr rhs) {
30+
return new Neq(lhs, rhs);
31+
}
3132
}

0 commit comments

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