Skip to content

Commit

Permalink
added comments and changed names so test refers to code tests and exp…
Browse files Browse the repository at this point in the history
…eriments refers to numerical experiments
  • Loading branch information
micha7a committed May 5, 2017
1 parent 38593fe commit 4134ee0
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 199 deletions.
16 changes: 6 additions & 10 deletions example1.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
from solvers import *
from plots import *


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

print("Ordinary Least Squares")
s = OrdinaryLS([0, 1, 2], 2, SignalPolynomial)
s.solve()
print(s.position_estimate)

print("Alternating Least Squares")
s = AlternatingLS([0, 1, 2], 2, SignalPolynomial, hold_edges=False)
s.solve()
print(s.position_estimate)
print(s.hold_edges)

try:
s = ConstrainedALS([0, 1, 2], 2, ConstrainedPolynomial, [1, 2, 3])
s.solve()
print(s.position_estimate)
except NotImplementedError:
print("ConstrainedPolynomial is an abstract class!")

print("Constrained Alternating Least Squares")
u = ConstrainedALS([0, 1, 2], 2, SurfacePolynomial, [1, 2, 3])
u.solve()
print(s.position_estimate)
150 changes: 22 additions & 128 deletions tests-results.ipynb → experiments-results.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Sumarised results from numerical experiments"
]
},
{
"cell_type": "code",
"execution_count": 95,
"execution_count": 2,
"metadata": {
"collapsed": false
},
Expand All @@ -18,15 +25,19 @@
]
},
{
"cell_type": "raw",
"cell_type": "markdown",
"metadata": {},
"source": [
"exec(open(\"surface-tests.py\").read())"
"To generate experiment results, run for example:\n",
"\n",
"`exec(open(\"surface-tests.py\").read())`\n",
"\n",
"This notebook only reads the results from files and generates plots."
]
},
{
"cell_type": "code",
"execution_count": 103,
"execution_count": 3,
"metadata": {
"collapsed": false
},
Expand All @@ -40,124 +51,9 @@
" '.idea',\n",
" '.ipynb_checkpoints',\n",
" '__pycache__',\n",
" 'errors_3_10_1.npy',\n",
" 'errors_3_1_0.npy',\n",
" 'errors_3_1_1.npy',\n",
" 'errors_3_1_2.npy',\n",
" 'errors_3_1_3.npy',\n",
" 'errors_3_2_0.npy',\n",
" 'errors_3_2_1.npy',\n",
" 'errors_3_2_2.npy',\n",
" 'errors_3_2_3.npy',\n",
" 'errors_3_3_0.npy',\n",
" 'errors_3_3_1.npy',\n",
" 'errors_3_3_2.npy',\n",
" 'errors_3_3_3.npy',\n",
" 'errors_4_1_0.npy',\n",
" 'errors_4_1_1.npy',\n",
" 'errors_4_1_2.npy',\n",
" 'errors_4_1_3.npy',\n",
" 'errors_4_1_4.npy',\n",
" 'errors_4_2_0.npy',\n",
" 'errors_4_2_1.npy',\n",
" 'errors_4_2_2.npy',\n",
" 'errors_4_2_3.npy',\n",
" 'errors_4_2_4.npy',\n",
" 'errors_4_3_0.npy',\n",
" 'errors_4_3_1.npy',\n",
" 'errors_4_3_2.npy',\n",
" 'errors_4_3_3.npy',\n",
" 'errors_4_3_4.npy',\n",
" 'errors_4_4_3.npy',\n",
" 'errors_5_1_0.npy',\n",
" 'errors_5_1_3.npy',\n",
" 'errors_6_1_0.npy',\n",
" 'errors_6_1_3.npy',\n",
" 'errors_7_1_0.npy',\n",
" 'errors_7_1_3.npy',\n",
" 'errors_8_1_0.npy',\n",
" 'errors_8_1_3.npy',\n",
" 'errors_9_1_0.npy',\n",
" 'errors_9_1_3.npy',\n",
" 'example1.py',\n",
" 'nsr_3_10_1.npy',\n",
" 'nsr_3_1_0.npy',\n",
" 'nsr_3_1_1.npy',\n",
" 'nsr_3_1_2.npy',\n",
" 'nsr_3_1_3.npy',\n",
" 'nsr_3_2_0.npy',\n",
" 'nsr_3_2_1.npy',\n",
" 'nsr_3_2_2.npy',\n",
" 'nsr_3_2_3.npy',\n",
" 'nsr_3_3_0.npy',\n",
" 'nsr_3_3_1.npy',\n",
" 'nsr_3_3_2.npy',\n",
" 'nsr_3_3_3.npy',\n",
" 'nsr_4_1_0.npy',\n",
" 'nsr_4_1_1.npy',\n",
" 'nsr_4_1_2.npy',\n",
" 'nsr_4_1_3.npy',\n",
" 'nsr_4_1_4.npy',\n",
" 'nsr_4_2_0.npy',\n",
" 'nsr_4_2_1.npy',\n",
" 'nsr_4_2_2.npy',\n",
" 'nsr_4_2_3.npy',\n",
" 'nsr_4_2_4.npy',\n",
" 'nsr_4_3_0.npy',\n",
" 'nsr_4_3_1.npy',\n",
" 'nsr_4_3_2.npy',\n",
" 'nsr_4_3_3.npy',\n",
" 'nsr_4_3_4.npy',\n",
" 'nsr_4_4_3.npy',\n",
" 'nsr_5_1_0.npy',\n",
" 'nsr_5_1_3.npy',\n",
" 'nsr_6_1_0.npy',\n",
" 'nsr_6_1_3.npy',\n",
" 'nsr_7_1_0.npy',\n",
" 'nsr_7_1_3.npy',\n",
" 'nsr_8_1_0.npy',\n",
" 'nsr_8_1_3.npy',\n",
" 'nsr_9_1_0.npy',\n",
" 'nsr_9_1_3.npy',\n",
" 'params_3_10_1.npy',\n",
" 'params_3_1_0.npy',\n",
" 'params_3_1_1.npy',\n",
" 'params_3_1_2.npy',\n",
" 'params_3_1_3.npy',\n",
" 'params_3_2_0.npy',\n",
" 'params_3_2_1.npy',\n",
" 'params_3_2_2.npy',\n",
" 'params_3_2_3.npy',\n",
" 'params_3_3_0.npy',\n",
" 'params_3_3_1.npy',\n",
" 'params_3_3_2.npy',\n",
" 'params_3_3_3.npy',\n",
" 'params_4_1_0.npy',\n",
" 'params_4_1_1.npy',\n",
" 'params_4_1_2.npy',\n",
" 'params_4_1_3.npy',\n",
" 'params_4_1_4.npy',\n",
" 'params_4_2_0.npy',\n",
" 'params_4_2_1.npy',\n",
" 'params_4_2_2.npy',\n",
" 'params_4_2_3.npy',\n",
" 'params_4_2_4.npy',\n",
" 'params_4_3_0.npy',\n",
" 'params_4_3_1.npy',\n",
" 'params_4_3_2.npy',\n",
" 'params_4_3_3.npy',\n",
" 'params_4_3_4.npy',\n",
" 'params_4_4_3.npy',\n",
" 'params_5_1_0.npy',\n",
" 'params_5_1_3.npy',\n",
" 'params_6_1_0.npy',\n",
" 'params_6_1_3.npy',\n",
" 'params_7_1_0.npy',\n",
" 'params_7_1_3.npy',\n",
" 'params_8_1_0.npy',\n",
" 'params_8_1_3.npy',\n",
" 'params_9_1_0.npy',\n",
" 'params_9_1_3.npy',\n",
" 'experiments-results.ipynb',\n",
" 'num-results',\n",
" 'pattern.ipynb',\n",
" 'plots.py',\n",
" 'results.ipynb',\n",
Expand All @@ -169,13 +65,11 @@
" 'solvers.py',\n",
" 'surface-images',\n",
" 'surface-reconstruction.ipynb',\n",
" 'surface-tests.py',\n",
" 'testfile.txt.npy',\n",
" 'tests-results.ipynb',\n",
" 'surface_experiments.py',\n",
" 'unknown-locations.ipynb']"
]
},
"execution_count": 103,
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -213,7 +107,7 @@
" results[0,nl,n] = np.degrees(np.percentile(errors, q=50))\n",
" results[1,nl,n] = np.degrees(np.percentile(errors, q=95))\n",
" \n",
" all_errors[nl,n,:] = errors.flatten()\n"
" all_errors[nl,n,:] = errors.flatten()"
]
},
{
Expand Down Expand Up @@ -297,7 +191,7 @@
" results[0,overs,nl,n] = np.degrees(np.percentile(errors, q=50))\n",
" results[1,overs,nl,n] = np.degrees(np.mean(errors.flatten()))\n",
"\n",
" all_errors[overs,nl,n,:] = errors.flatten()\n"
" all_errors[overs,nl,n,:] = errors.flatten()"
]
},
{
Expand Down Expand Up @@ -379,5 +273,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 0
}
13 changes: 10 additions & 3 deletions pattern.ipynb
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Polynomial pattern to be printed and photographed"
]
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {
"collapsed": true
},
Expand All @@ -14,7 +21,7 @@
"import matplotlib.pyplot as plt\n",
"from pylab import rcParams\n",
"rcParams['figure.figsize'] = 10, 10\n",
"%matplotlib inline "
"%matplotlib inline"
]
},
{
Expand Down Expand Up @@ -107,5 +114,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 0
}
24 changes: 3 additions & 21 deletions results.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Ideas:\n",
"maybe gradient (or beta) should be weighted by the number of samples?"
"## Results for photoshoped images"
]
},
{
Expand All @@ -35,7 +34,6 @@
},
"outputs": [],
"source": [
"\n",
"def todegree(x):\n",
" return x*180/np.pi\n",
"\n",
Expand Down Expand Up @@ -112,7 +110,7 @@
"img3 = get_image('surface-images/cheeting/pattern5.png', 180, 220, cut=10)\n",
"img2 = img2[:-60]\n",
"# img3 = img3[40:-30]\n",
"# img4 = get_image('surface-images/cheeting/pattern3.png', 150, 250, cut=10)\n"
"# img4 = get_image('surface-images/cheeting/pattern3.png', 150, 250, cut=10)"
]
},
{
Expand Down Expand Up @@ -268,22 +266,6 @@
"pylab.gcf().subplots_adjust(bottom=0.15)\n",
"pylab.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## some results:\n",
"### Tuesday1:\n",
"* 125: 5.9 (with 9.1)\n",
"* 160: 1.7 (with 7.1)\n",
"### Cheeting:\n",
"* img1: 0° (correct)\n",
"* img2: -11° \n",
"* img3: 10° \n",
"* img4: 20° \n",
"* img5: 30° "
]
}
],
"metadata": {
Expand All @@ -307,5 +289,5 @@
}
},
"nbformat": 4,
"nbformat_minor": 1
"nbformat_minor": 0
}
8 changes: 7 additions & 1 deletion samplers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


class DeterministicSampler(object):
"""general sampler:
"""General sampler:
keeps sample positions an compute sample values"""

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


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


class SurfaceSampler(GaussianSampler):
"""Deterministic surface sampler:
generates sample positions uniformly from the signal on the surface described by surf_params
the actual sample movement is handled by the Signal model"""
def __init__(self, signal, number_samples, surf_params, interval_length=1, sigma=None, beg=0):
self.surf_params = surf_params
self.beg = beg
Expand Down
3 changes: 3 additions & 0 deletions shifing-exp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
from signals import *
rcParams['figure.figsize'] = 5, 4

"""Script generating plots describing the movement of samples for a path in the space of complex exponentials,
not included in the paper. """

signal = SignalExp([0, 1, 0])

change = np.array([0, 1, 0])
Expand Down
2 changes: 2 additions & 0 deletions shifting.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from pylab import rcParams
rcParams['figure.figsize'] = 5, 4

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

pol = SignalPolynomial([2, -1, 1])
pylab.show()
Expand Down
Loading

0 comments on commit 4134ee0

Please sign in to comment.