You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Consider minimizing the negative entropy function 
17
16
17
+
Create `entropy.sp`:
18
18
```haskell
19
19
variables:
20
-
x[128][128] =0
20
+
p[10][10]
21
21
22
-
constants:
23
-
im[128][128] =Dataset("data.h5", "im")
24
-
re[128][128] =Dataset("data.h5", "re")
25
-
signal[128][128] =Dataset("data.h5", "signal")
26
-
xLowerBound[128][128] =Dataset("data.h5", "x_lb")
27
-
xUpperBound[128][128] =Dataset("data.h5", "x_ub")
22
+
constraints:
23
+
p >=0.1
28
24
29
-
constraints:
30
-
x >= xLowerBound, x <= xUpperBound
25
+
minimize:
26
+
p <.>log (p)
31
27
32
-
let:
33
-
smootherX = rotate (0, 1) x + rotate (0, -1) x -2*. x
34
-
smootherY = rotate (1, 0) x + rotate (-1, 0) x -2*. x
Symphony will generate code and download the solver (L-BFGS-B in this case) to current working directory.
38
+
Then simply compile the code and run:
42
39
```terminal
43
-
$ symphony mri.sp
40
+
$ make
44
41
```
45
-
Will generate `problem.c` with the following interface:
42
+
(Note that we use [HDF5](https://www.hdfgroup.org/solutions/hdf5/) for reading and writing dataset)
46
43
47
-
```c++
48
-
#defineNUM_VARIABLES 1
49
-
#define NUM_ACTUAL_VARIABLES 16384
50
-
#define MEM_SIZE 671774
44
+
```terminal
45
+
$ ./lbfgs-b
46
+
....
47
+
....
48
+
F = final function value
49
+
* * *
50
+
N Tit Tnf Tnint Skip Nact Projg F
51
+
100 7 8 45 0 0 4.36e-06 -3.67879e+01
52
+
21
53
+
Total User time 2.470e-04 seconds.
54
+
Writing p to p_out.h5...
55
+
```
56
+
Which is what we expected, and the output value of `p` is written in HDF5 file `p_out.h5`.
51
57
52
-
// all the actual double variables are allocated
53
-
// one after another, starts from here
54
-
#defineVARS_START_OFFSET 0
55
58
59
+
For more, checkout `examples/Brain/brain.sp` example which solves an optimization problem to reconstruct image from loss MRI signal, details about the problem can be found at [MRI-Image-Reconstruction](examples/MRI-Image-Reconstruction.pdf).
60
+
```haskell
61
+
variables:
62
+
x[128][128] =0
56
63
57
-
constchar* var_name[NUM_VARIABLES] = {"x"};
58
-
const int var_num_dim[NUM_VARIABLES] = {2};
59
-
const int var_shape[NUM_VARIABLES][3] = {{128, 128, 1}};
60
-
const int var_size[NUM_VARIABLES] = {16384};
61
-
const int var_offset[NUM_VARIABLES] = {0};
62
-
const int partial_derivative_offset[NUM_VARIABLES] = {65543};
63
-
const int objective_offset = 81927;
64
-
double ptr[MEM_SIZE];
64
+
constants:
65
+
im[128][128] =Dataset("kspace.h5", "im")
66
+
re[128][128] =Dataset("kspace.h5", "re")
67
+
mask[128][128] =Dataset("mask.h5", "mask")
68
+
xLowerBound[128][128] =Dataset("bound.h5", "lb")
69
+
xUpperBound[128][128] =Dataset("bound.h5", "ub")
65
70
71
+
constraints:
72
+
x >= xLowerBound, x <= xUpperBound
66
73
67
-
const int bound_pos[NUM_VARIABLES] = {0};
68
-
double lower_bound[NUM_ACTUAL_VARIABLES];
69
-
double upper_bound[NUM_ACTUAL_VARIABLES];
74
+
let:
75
+
smootherX = rotate (0, 1) x + rotate (0, -1) x -2*. x
76
+
smootherY = rotate (1, 0) x + rotate (-1, 0) x -2*. x
0 commit comments