Skip to content

Commit 4134ee0

Browse files
committed
added comments and changed names so test refers to code tests and experiments refers to numerical experiments
1 parent 38593fe commit 4134ee0

11 files changed

+97
-199
lines changed

example1.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
from solvers import *
22
from plots import *
33

4-
5-
s = Solver([0, 1, 2], 2, SignalPolynomial)
4+
# Example how to use Solver class
5+
s = Solver(samples=[0, 1, 2], model_size=2, model_type=SignalPolynomial)
66
print(s.position_estimate)
77

8+
print("Ordinary Least Squares")
89
s = OrdinaryLS([0, 1, 2], 2, SignalPolynomial)
910
s.solve()
1011
print(s.position_estimate)
1112

13+
print("Alternating Least Squares")
1214
s = AlternatingLS([0, 1, 2], 2, SignalPolynomial, hold_edges=False)
1315
s.solve()
1416
print(s.position_estimate)
15-
print(s.hold_edges)
16-
17-
try:
18-
s = ConstrainedALS([0, 1, 2], 2, ConstrainedPolynomial, [1, 2, 3])
19-
s.solve()
20-
print(s.position_estimate)
21-
except NotImplementedError:
22-
print("ConstrainedPolynomial is an abstract class!")
2317

18+
print("Constrained Alternating Least Squares")
2419
u = ConstrainedALS([0, 1, 2], 2, SurfacePolynomial, [1, 2, 3])
2520
u.solve()
21+
print(s.position_estimate)

tests-results.ipynb renamed to experiments-results.ipynb

Lines changed: 22 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Sumarised results from numerical experiments"
8+
]
9+
},
310
{
411
"cell_type": "code",
5-
"execution_count": 95,
12+
"execution_count": 2,
613
"metadata": {
714
"collapsed": false
815
},
@@ -18,15 +25,19 @@
1825
]
1926
},
2027
{
21-
"cell_type": "raw",
28+
"cell_type": "markdown",
2229
"metadata": {},
2330
"source": [
24-
"exec(open(\"surface-tests.py\").read())"
31+
"To generate experiment results, run for example:\n",
32+
"\n",
33+
"`exec(open(\"surface-tests.py\").read())`\n",
34+
"\n",
35+
"This notebook only reads the results from files and generates plots."
2536
]
2637
},
2738
{
2839
"cell_type": "code",
29-
"execution_count": 103,
40+
"execution_count": 3,
3041
"metadata": {
3142
"collapsed": false
3243
},
@@ -40,124 +51,9 @@
4051
" '.idea',\n",
4152
" '.ipynb_checkpoints',\n",
4253
" '__pycache__',\n",
43-
" 'errors_3_10_1.npy',\n",
44-
" 'errors_3_1_0.npy',\n",
45-
" 'errors_3_1_1.npy',\n",
46-
" 'errors_3_1_2.npy',\n",
47-
" 'errors_3_1_3.npy',\n",
48-
" 'errors_3_2_0.npy',\n",
49-
" 'errors_3_2_1.npy',\n",
50-
" 'errors_3_2_2.npy',\n",
51-
" 'errors_3_2_3.npy',\n",
52-
" 'errors_3_3_0.npy',\n",
53-
" 'errors_3_3_1.npy',\n",
54-
" 'errors_3_3_2.npy',\n",
55-
" 'errors_3_3_3.npy',\n",
56-
" 'errors_4_1_0.npy',\n",
57-
" 'errors_4_1_1.npy',\n",
58-
" 'errors_4_1_2.npy',\n",
59-
" 'errors_4_1_3.npy',\n",
60-
" 'errors_4_1_4.npy',\n",
61-
" 'errors_4_2_0.npy',\n",
62-
" 'errors_4_2_1.npy',\n",
63-
" 'errors_4_2_2.npy',\n",
64-
" 'errors_4_2_3.npy',\n",
65-
" 'errors_4_2_4.npy',\n",
66-
" 'errors_4_3_0.npy',\n",
67-
" 'errors_4_3_1.npy',\n",
68-
" 'errors_4_3_2.npy',\n",
69-
" 'errors_4_3_3.npy',\n",
70-
" 'errors_4_3_4.npy',\n",
71-
" 'errors_4_4_3.npy',\n",
72-
" 'errors_5_1_0.npy',\n",
73-
" 'errors_5_1_3.npy',\n",
74-
" 'errors_6_1_0.npy',\n",
75-
" 'errors_6_1_3.npy',\n",
76-
" 'errors_7_1_0.npy',\n",
77-
" 'errors_7_1_3.npy',\n",
78-
" 'errors_8_1_0.npy',\n",
79-
" 'errors_8_1_3.npy',\n",
80-
" 'errors_9_1_0.npy',\n",
81-
" 'errors_9_1_3.npy',\n",
8254
" 'example1.py',\n",
83-
" 'nsr_3_10_1.npy',\n",
84-
" 'nsr_3_1_0.npy',\n",
85-
" 'nsr_3_1_1.npy',\n",
86-
" 'nsr_3_1_2.npy',\n",
87-
" 'nsr_3_1_3.npy',\n",
88-
" 'nsr_3_2_0.npy',\n",
89-
" 'nsr_3_2_1.npy',\n",
90-
" 'nsr_3_2_2.npy',\n",
91-
" 'nsr_3_2_3.npy',\n",
92-
" 'nsr_3_3_0.npy',\n",
93-
" 'nsr_3_3_1.npy',\n",
94-
" 'nsr_3_3_2.npy',\n",
95-
" 'nsr_3_3_3.npy',\n",
96-
" 'nsr_4_1_0.npy',\n",
97-
" 'nsr_4_1_1.npy',\n",
98-
" 'nsr_4_1_2.npy',\n",
99-
" 'nsr_4_1_3.npy',\n",
100-
" 'nsr_4_1_4.npy',\n",
101-
" 'nsr_4_2_0.npy',\n",
102-
" 'nsr_4_2_1.npy',\n",
103-
" 'nsr_4_2_2.npy',\n",
104-
" 'nsr_4_2_3.npy',\n",
105-
" 'nsr_4_2_4.npy',\n",
106-
" 'nsr_4_3_0.npy',\n",
107-
" 'nsr_4_3_1.npy',\n",
108-
" 'nsr_4_3_2.npy',\n",
109-
" 'nsr_4_3_3.npy',\n",
110-
" 'nsr_4_3_4.npy',\n",
111-
" 'nsr_4_4_3.npy',\n",
112-
" 'nsr_5_1_0.npy',\n",
113-
" 'nsr_5_1_3.npy',\n",
114-
" 'nsr_6_1_0.npy',\n",
115-
" 'nsr_6_1_3.npy',\n",
116-
" 'nsr_7_1_0.npy',\n",
117-
" 'nsr_7_1_3.npy',\n",
118-
" 'nsr_8_1_0.npy',\n",
119-
" 'nsr_8_1_3.npy',\n",
120-
" 'nsr_9_1_0.npy',\n",
121-
" 'nsr_9_1_3.npy',\n",
122-
" 'params_3_10_1.npy',\n",
123-
" 'params_3_1_0.npy',\n",
124-
" 'params_3_1_1.npy',\n",
125-
" 'params_3_1_2.npy',\n",
126-
" 'params_3_1_3.npy',\n",
127-
" 'params_3_2_0.npy',\n",
128-
" 'params_3_2_1.npy',\n",
129-
" 'params_3_2_2.npy',\n",
130-
" 'params_3_2_3.npy',\n",
131-
" 'params_3_3_0.npy',\n",
132-
" 'params_3_3_1.npy',\n",
133-
" 'params_3_3_2.npy',\n",
134-
" 'params_3_3_3.npy',\n",
135-
" 'params_4_1_0.npy',\n",
136-
" 'params_4_1_1.npy',\n",
137-
" 'params_4_1_2.npy',\n",
138-
" 'params_4_1_3.npy',\n",
139-
" 'params_4_1_4.npy',\n",
140-
" 'params_4_2_0.npy',\n",
141-
" 'params_4_2_1.npy',\n",
142-
" 'params_4_2_2.npy',\n",
143-
" 'params_4_2_3.npy',\n",
144-
" 'params_4_2_4.npy',\n",
145-
" 'params_4_3_0.npy',\n",
146-
" 'params_4_3_1.npy',\n",
147-
" 'params_4_3_2.npy',\n",
148-
" 'params_4_3_3.npy',\n",
149-
" 'params_4_3_4.npy',\n",
150-
" 'params_4_4_3.npy',\n",
151-
" 'params_5_1_0.npy',\n",
152-
" 'params_5_1_3.npy',\n",
153-
" 'params_6_1_0.npy',\n",
154-
" 'params_6_1_3.npy',\n",
155-
" 'params_7_1_0.npy',\n",
156-
" 'params_7_1_3.npy',\n",
157-
" 'params_8_1_0.npy',\n",
158-
" 'params_8_1_3.npy',\n",
159-
" 'params_9_1_0.npy',\n",
160-
" 'params_9_1_3.npy',\n",
55+
" 'experiments-results.ipynb',\n",
56+
" 'num-results',\n",
16157
" 'pattern.ipynb',\n",
16258
" 'plots.py',\n",
16359
" 'results.ipynb',\n",
@@ -169,13 +65,11 @@
16965
" 'solvers.py',\n",
17066
" 'surface-images',\n",
17167
" 'surface-reconstruction.ipynb',\n",
172-
" 'surface-tests.py',\n",
173-
" 'testfile.txt.npy',\n",
174-
" 'tests-results.ipynb',\n",
68+
" 'surface_experiments.py',\n",
17569
" 'unknown-locations.ipynb']"
17670
]
17771
},
178-
"execution_count": 103,
72+
"execution_count": 3,
17973
"metadata": {},
18074
"output_type": "execute_result"
18175
}
@@ -213,7 +107,7 @@
213107
" results[0,nl,n] = np.degrees(np.percentile(errors, q=50))\n",
214108
" results[1,nl,n] = np.degrees(np.percentile(errors, q=95))\n",
215109
" \n",
216-
" all_errors[nl,n,:] = errors.flatten()\n"
110+
" all_errors[nl,n,:] = errors.flatten()"
217111
]
218112
},
219113
{
@@ -297,7 +191,7 @@
297191
" results[0,overs,nl,n] = np.degrees(np.percentile(errors, q=50))\n",
298192
" results[1,overs,nl,n] = np.degrees(np.mean(errors.flatten()))\n",
299193
"\n",
300-
" all_errors[overs,nl,n,:] = errors.flatten()\n"
194+
" all_errors[overs,nl,n,:] = errors.flatten()"
301195
]
302196
},
303197
{
@@ -379,5 +273,5 @@
379273
}
380274
},
381275
"nbformat": 4,
382-
"nbformat_minor": 2
276+
"nbformat_minor": 0
383277
}

pattern.ipynb

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Polynomial pattern to be printed and photographed"
8+
]
9+
},
310
{
411
"cell_type": "code",
5-
"execution_count": 2,
12+
"execution_count": null,
613
"metadata": {
714
"collapsed": true
815
},
@@ -14,7 +21,7 @@
1421
"import matplotlib.pyplot as plt\n",
1522
"from pylab import rcParams\n",
1623
"rcParams['figure.figsize'] = 10, 10\n",
17-
"%matplotlib inline "
24+
"%matplotlib inline"
1825
]
1926
},
2027
{
@@ -107,5 +114,5 @@
107114
}
108115
},
109116
"nbformat": 4,
110-
"nbformat_minor": 1
117+
"nbformat_minor": 0
111118
}

results.ipynb

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
"cell_type": "markdown",
2424
"metadata": {},
2525
"source": [
26-
"## Ideas:\n",
27-
"maybe gradient (or beta) should be weighted by the number of samples?"
26+
"## Results for photoshoped images"
2827
]
2928
},
3029
{
@@ -35,7 +34,6 @@
3534
},
3635
"outputs": [],
3736
"source": [
38-
"\n",
3937
"def todegree(x):\n",
4038
" return x*180/np.pi\n",
4139
"\n",
@@ -112,7 +110,7 @@
112110
"img3 = get_image('surface-images/cheeting/pattern5.png', 180, 220, cut=10)\n",
113111
"img2 = img2[:-60]\n",
114112
"# img3 = img3[40:-30]\n",
115-
"# img4 = get_image('surface-images/cheeting/pattern3.png', 150, 250, cut=10)\n"
113+
"# img4 = get_image('surface-images/cheeting/pattern3.png', 150, 250, cut=10)"
116114
]
117115
},
118116
{
@@ -268,22 +266,6 @@
268266
"pylab.gcf().subplots_adjust(bottom=0.15)\n",
269267
"pylab.show()"
270268
]
271-
},
272-
{
273-
"cell_type": "markdown",
274-
"metadata": {},
275-
"source": [
276-
"## some results:\n",
277-
"### Tuesday1:\n",
278-
"* 125: 5.9 (with 9.1)\n",
279-
"* 160: 1.7 (with 7.1)\n",
280-
"### Cheeting:\n",
281-
"* img1: 0° (correct)\n",
282-
"* img2: -11° \n",
283-
"* img3: 10° \n",
284-
"* img4: 20° \n",
285-
"* img5: 30° "
286-
]
287269
}
288270
],
289271
"metadata": {
@@ -307,5 +289,5 @@
307289
}
308290
},
309291
"nbformat": 4,
310-
"nbformat_minor": 1
292+
"nbformat_minor": 0
311293
}

samplers.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44

55
class DeterministicSampler(object):
6-
"""general sampler:
6+
"""General sampler:
77
keeps sample positions an compute sample values"""
88

99
def __init__(self, signal, number_samples, interval_length=1):
@@ -20,6 +20,9 @@ def _make_samples(self, signal):
2020

2121

2222
class GaussianSampler(DeterministicSampler):
23+
"""Random sampler:
24+
generates sample positions independently from normal distribution,
25+
with variance sigma and uniform sample positions as a vector of means"""
2326
def __init__(self, signal, number_samples, interval_length=1, hold_edges=True, sigma=None, beg=0):
2427
if sigma is None:
2528
sigma = (1.0*interval_length)/number_samples
@@ -40,6 +43,9 @@ def _make_positions(self):
4043

4144

4245
class SurfaceSampler(GaussianSampler):
46+
"""Deterministic surface sampler:
47+
generates sample positions uniformly from the signal on the surface described by surf_params
48+
the actual sample movement is handled by the Signal model"""
4349
def __init__(self, signal, number_samples, surf_params, interval_length=1, sigma=None, beg=0):
4450
self.surf_params = surf_params
4551
self.beg = beg

shifing-exp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
from signals import *
44
rcParams['figure.figsize'] = 5, 4
55

6+
"""Script generating plots describing the movement of samples for a path in the space of complex exponentials,
7+
not included in the paper. """
8+
69
signal = SignalExp([0, 1, 0])
710

811
change = np.array([0, 1, 0])

shifting.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from pylab import rcParams
55
rcParams['figure.figsize'] = 5, 4
66

7+
"""Script generating plots describing the movement of samples for a path in the space of polynomials,
8+
finaly replaced by the plots form unknown-locations.ipynb """
79

810
pol = SignalPolynomial([2, -1, 1])
911
pylab.show()

0 commit comments

Comments
 (0)