Skip to content

Commit fb57d74

Browse files
committed
Working on some stuff
1 parent 12c8b65 commit fb57d74

14 files changed

+3424
-2514
lines changed

.gitignore

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
.ipynb_checkpoints
2-
*.swp
31
*.dat
4-
.map
52
*.dot
63
*.dot.pdf
4+
*.fits
5+
*.ipynb_checkpoints
6+
*.jpg
7+
*.map
8+
*.swp
9+
*.tar.gz
710

DifferentiatingPerceptron.ipynb

+677
Large diffs are not rendered by default.

EllipsoidEstimation.ipynb

+131-3
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,14 @@
267267
"source": [
268268
"### Quadratic form\n",
269269
"\n",
270-
"The matrix definition of an ellipsoid : $x^{\\intercal}Mx$ can obviously be developped, and give a polynomial of degree 2 of the form\n",
270+
"The matrix definition of an ellipsoid : $x^{\\intercal}Mx$ can obviously be developped, and give a multivariate polynomial of degree 2 of the form\n",
271271
"$$\n",
272272
"\\sum_{i=0, j=0}^{n-1, n-1} M_{ij} x_i x_j\n",
273273
"$$\n",
274274
"\n",
275-
"This sum has $n^2$ terms, but, as all $M_{ij}$ and $M_{ji}$ terms can be factorized, the underlying quadratic form actually has $\\frac{n \\times (n-1)}{2}$ terms. Unfortunately, we won't talk much about quadratic forms here."
275+
"This sum has $n^2$ terms, but, as all $M_{ij}$ and $M_{ji}$ terms can be factorized, the underlying quadratic form actually has $\\frac{n \\times (n-1)}{2}$ terms. Unfortunately, we won't talk much about quadratic forms here.\n",
276+
"\n",
277+
"More on quadratic forms in the notebook QuadraticFormsForFun"
276278
]
277279
},
278280
{
@@ -457,6 +459,132 @@
457459
"plt.axis('equal')"
458460
]
459461
},
462+
{
463+
"cell_type": "markdown",
464+
"metadata": {},
465+
"source": [
466+
"## Ellipsoid estimation from boundary points\n",
467+
"\n",
468+
"In the field of image processing, it might sometimes be needed to estimate an ellipse, not from a a set of points pertaining to that geometric objects, but directly to a set of points that are supposed to lie on the edge of the ellipsoid.\n",
469+
"\n",
470+
"### Origin centered ellipsoid\n",
471+
"\n",
472+
"Lets recall that a origin centered ellipsoid E equation can be written as:\n",
473+
"\n",
474+
"\\begin{align*}\n",
475+
" E &= x \\quad \\text{s.t.} \\sqrt{x^t M x} = r \\\\\n",
476+
" &= x \\quad \\text{s.t.} \\sqrt{x^t M x} - r = 0 \\\\\n",
477+
"\\end{align*}\n",
478+
"\n",
479+
"In 2d, given we can also write this more explicitly as:\n",
480+
"\n",
481+
"\\begin{align*}\n",
482+
" (x_0, x_1) \\quad \\text{s.t.} \\sqrt{\n",
483+
" \\begin{pmatrix}\n",
484+
" x_0\\\\\n",
485+
" x_1\n",
486+
" \\end{pmatrix} ^t\n",
487+
" \\begin{pmatrix}\n",
488+
" M_a & M_b\\\\\n",
489+
" M_c & M_d\\\\\n",
490+
" \\end{pmatrix}\n",
491+
" \\begin{pmatrix}\n",
492+
" x_0\\\\\n",
493+
" x_1\n",
494+
" \\end{pmatrix}} - r = 0 \\\\\n",
495+
" \\sqrt{\n",
496+
" \\begin{pmatrix}\n",
497+
" x_0\\\\\n",
498+
" x_1\n",
499+
" \\end{pmatrix} ^t\n",
500+
" \\begin{pmatrix}\n",
501+
" M_a x_0 + M_b x_1\\\\\n",
502+
" M_c x_0 + M_d x_1\\\\\n",
503+
" \\end{pmatrix}} - r = 0 \\\\\n",
504+
" \\sqrt{M_a x_0^2 + M_d x_1^2 + M_b M_c x_0 x_1} - r = 0\n",
505+
"\\end{align*}\n",
506+
"\n",
507+
"Lets take a closer look at the resulting multivariate polynomial:\n",
508+
"\\begin{align*}\n",
509+
" \\sqrt{M_a x_0^2 + M_d x_1^2 + M_b M_c x_0 x_1} - r = 0 \\\\\n",
510+
" \\Leftrightarrow M_a x_0^2 + M_d x_1^2 + M_b M_c x_0 x_1 - r^2 = 0\n",
511+
"\\end{align*}\n",
512+
"\n",
513+
"Given multiple instances of $(x_{0,i}, x_{1,i})$ pairs, we can easily setup a least square problem, in order to find an optimally fitting ellipsoid, in the least square sense:\n",
514+
"\n",
515+
"\\begin{align*}\n",
516+
" \\underset{{M_a, M_b, M_c, M_d, r} \\in \\mathbb{R}^5}{argmin} &\\|\\begin{pmatrix}\n",
517+
" x_{0,0}^2 & x_{1,0}^2 & x_{0,0} x_{1,0} & -1\\\\\n",
518+
" x_{0,0}^2 & x_{1,0}^2 & x_{0,0} x_{1,0} & -1\\\\\n",
519+
" \\vdots & \\vdots & \\vdots & -1\\\\\n",
520+
" x_{0,n-1}^2 & x_{1,n-1}^2 & x_{0,n-1} x_{1,n-1} & -1\\\\\n",
521+
" \\end{pmatrix}\n",
522+
" \\begin{pmatrix}\n",
523+
" M_a \\\\ M_d \\\\ M_b M_c \\\\ r^2\n",
524+
" \\end{pmatrix} - \\vec{0}\\|_2^2 \\\\\n",
525+
" \\Leftrightarrow\n",
526+
" \\underset{{M_a, M_b, M_c, M_d, r} \\in \\mathbb{R}^5}{argmin} &\\|\\begin{pmatrix}\n",
527+
" x_{0,0}^2 & x_{1,0}^2 & x_{0,0} x_{1,0} & -1\\\\\n",
528+
" x_{0,0}^2 & x_{1,0}^2 & x_{0,0} x_{1,0} & -1\\\\\n",
529+
" \\vdots & \\vdots & \\vdots & -1\\\\\n",
530+
" x_{0,n-1}^2 & x_{1,n-1}^2 & x_{0,n-1} x_{1,n-1} & -1\\\\\n",
531+
" \\end{pmatrix}\n",
532+
" \\begin{pmatrix}\n",
533+
" a \\\\ b \\\\ c \\\\ d\n",
534+
" \\end{pmatrix}\\|_2^2 \\\\\n",
535+
" \\Leftrightarrow\n",
536+
" \\underset{{M_a, M_b, M_c, M_d, r} \\in \\mathbb{R}^5}{argmin} &M_2\n",
537+
" \\begin{pmatrix}\n",
538+
" a \\\\ b \\\\ c \\\\ d\n",
539+
" \\end{pmatrix}\\|_2^2 \n",
540+
"\\end{align*}\n",
541+
"\n",
542+
"On can easily see that this problem is equivalent to finding the kernel of matrix $M_2$ or $M_2^t M_2$.\n",
543+
"\n",
544+
"Of course, the zero vector is a trivial solution. This is why it is usually better to formulate the problem with the builtin constraint that the zero solution is excluded (that project the problem from $\\mathbb{R}^5$ onto the lower dimensional $\\mathbb{R}^{4*}$ space):\n",
545+
"\n",
546+
"\\begin{align*}\n",
547+
" \\sqrt{M_a x_0^2 + M_d x_1^2 + M_b M_c x_0 x_1} &= r \\\\\n",
548+
" \\Leftrightarrow M_a x_0^2 + M_d x_1^2 + M_b M_c x_0 x_1 - r^2 &= 0\\\\\n",
549+
" \\Leftrightarrow \\frac{M_a}{r^2} x_0^2 + \\frac{M_d}{r^2} x_1^2 + \\frac{M_b M_c}{r^2} x_0 x_1 - 1 &= 0 \\quad \\text{with } r\\neq 0\\\\\n",
550+
"\\end{align*}"
551+
]
552+
},
553+
{
554+
"cell_type": "markdown",
555+
"metadata": {},
556+
"source": [
557+
"### Arbitrary ellipsoid\n",
558+
"\n",
559+
"Lets now assume that the unknown ellipsoid can be arbitrary centered at $$c=\\begin{pmatrix}c_0\\\\c_1end{pmatrix}$$\n",
560+
"\n",
561+
"\\begin{align*}\n",
562+
" (x_0, x_1-c_1) \\quad \\text{s.t.} \\sqrt{\n",
563+
" \\begin{pmatrix}\n",
564+
" x_0 - c_0\\\\\n",
565+
" x_1 - c_1\n",
566+
" \\end{pmatrix} ^t\n",
567+
" \\begin{pmatrix}\n",
568+
" M_a & M_b\\\\\n",
569+
" M_c & M_d\\\\\n",
570+
" \\end{pmatrix}\n",
571+
" \\begin{pmatrix}\n",
572+
" x_0 - c_0\\\\\n",
573+
" x_1 - c_1\n",
574+
" \\end{pmatrix}} - r = 0 \\\\\n",
575+
" \\sqrt{\n",
576+
" \\begin{pmatrix}\n",
577+
" x_0\\\\\n",
578+
" x_1\n",
579+
" \\end{pmatrix} ^t\n",
580+
" \\begin{pmatrix}\n",
581+
" M_a x_0 + M_b x_1\\\\\n",
582+
" M_c x_0 + M_d x_1\\\\\n",
583+
" \\end{pmatrix}} - r = 0 \\\\\n",
584+
" \\left(M_a \\right) x_0^2 + \\left(M_a M_b \\right) x_1^2 + \\left(M_a M_b \\right) x_0 + \\left(M_a M_b \\right) x_1 + \\left(M_a M_b \\right) x_0 x_1 + \\left(M_a M_b \\right)\n",
585+
"\\end{align*}\n"
586+
]
587+
},
460588
{
461589
"cell_type": "markdown",
462590
"metadata": {},
@@ -963,7 +1091,7 @@
9631091
"name": "python",
9641092
"nbconvert_exporter": "python",
9651093
"pygments_lexer": "ipython3",
966-
"version": "3.6.6"
1094+
"version": "3.6.7"
9671095
}
9681096
},
9691097
"nbformat": 4,

ForwardBackwardDual.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@
649649
"name": "python",
650650
"nbconvert_exporter": "python",
651651
"pygments_lexer": "ipython3",
652-
"version": "3.6.3"
652+
"version": "3.6.7"
653653
}
654654
},
655655
"nbformat": 4,

ForwardBackwardSparseL1.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@
878878
"name": "python",
879879
"nbconvert_exporter": "python",
880880
"pygments_lexer": "ipython3",
881-
"version": "3.6.6"
881+
"version": "3.6.7"
882882
}
883883
},
884884
"nbformat": 4,

GradientDescentDifferentiable.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,7 @@
13291329
"name": "python",
13301330
"nbconvert_exporter": "python",
13311331
"pygments_lexer": "ipython3",
1332-
"version": "3.6.3"
1332+
"version": "3.6.7"
13331333
}
13341334
},
13351335
"nbformat": 4,

HilbertTransform.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1135,7 +1135,7 @@
11351135
"name": "python",
11361136
"nbconvert_exporter": "python",
11371137
"pygments_lexer": "ipython3",
1138-
"version": "3.6.6"
1138+
"version": "3.6.7"
11391139
}
11401140
},
11411141
"nbformat": 4,

LeastSquareWithOptimalityCertificate.ipynb

+18-18
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@
652652
"source": [
653653
"### Recall on Strong duality\n",
654654
"\n",
655-
"We recall that strong duality holds for non constrained quadratic programs like the on we are studying, such that the optimal primal and dual costs satisfy\n",
655+
"We recall that strong duality holds for non constrained quadratic programs like the one we are studying, such that the optimal primal and dual costs satisfy\n",
656656
"\n",
657657
"\\begin{align*}\n",
658658
"E^\\star= F(x^\\star) + G(Lx^\\star) = - F^*( -L^* u^\\star ) - G^*(u^\\star)\n",
@@ -707,24 +707,24 @@
707707
"\n",
708708
"\\begin{align*}\n",
709709
" c(z) &= \\quad \\langle u,z \\rangle - \\frac{1}{2}\\|Az-y\\|_2^2 \\\\\n",
710-
" &= \\quad \\langle u,z \\rangle - \\frac{1}{2} \\left( \\| Az,Az \\|_2^2 +\n",
711-
" \\|y\\|_2^2 + \\langle Az,y rangle \\right)\n",
710+
" &= \\quad \\langle u,z \\rangle - \\frac{1}{2} \\left( \\| Az \\|_2^2 +\n",
711+
" \\|y\\|_2^2 - 2 \\langle Az,y \\rangle \\right)\n",
712712
"\\end{align*}\n",
713713
"\n",
714714
"This nice concave function can be derived in order to find its critical point:\n",
715715
"\n",
716716
"\\begin{align*}\n",
717717
" \\frac{\\partial c}{\\partial z} &= 0 \\\\\n",
718-
" u - A^t A z - A^t y &= 0 \\\\\n",
719-
" A^t A z &= u - A^t y \\\\\n",
720-
" z &= (A^t A)^{-1} \\left( u - A^t y \\right)\n",
718+
" u - A^t A z + A^t y &= 0 \\\\\n",
719+
" A^t A z &= u + A^t y \\\\\n",
720+
" z &= (A^t A)^{-1} \\left( u + A^t y \\right)\n",
721721
"\\end{align*}\n",
722722
"\n",
723723
"Reinjecting this expression in $ F^*(u)$ gives:\n",
724724
"\n",
725725
"\\begin{align*}\n",
726726
" F^*(u) &= \\langle u,(A^t A)^{-1} \\left( u - A^t y \\right) \\rangle -\n",
727-
" \\frac{1}{2}\\|A \\left(A^t A\\right)^{-1} \\left( u - A^t y \\right) -y\\|_2^2\n",
727+
" \\frac{1}{2}\\|A \\left(A^t A\\right)^{-1} \\left( u + A^t y \\right) -y\\|_2^2\n",
728728
"\\end{align*}"
729729
]
730730
},
@@ -740,14 +740,14 @@
740740
"Lets use these shorthand to express $F^*$:\n",
741741
"\n",
742742
"\\begin{align*}\n",
743-
" F^*(u) &= \\langle u,P ( u - A^t y ) \\rangle - \\frac{1}{2}\\|A P ( u - A^t y ) -y\\|_2^2 \\\\\n",
744-
" &= \\langle u,Pu \\rangle - \\langle u,\\lambda \\rangle - \\frac{1}{2} \\| APu - A\\lambda - y\\|_2^2 \\\\\n",
743+
" F^*(u) &= \\langle u,P ( u - A^t y ) \\rangle - \\frac{1}{2}\\|A P ( u + A^t y ) -y\\|_2^2 \\\\\n",
744+
" &= \\langle u,Pu \\rangle - \\langle u,\\lambda \\rangle - \\frac{1}{2} \\| APu + A\\lambda - y\\|_2^2 \\\\\n",
745745
"\\end{align*}\n",
746746
"\n",
747747
"So that the derivative gives:\n",
748748
"\n",
749749
"\\begin{align*}\n",
750-
" \\frac{\\partial F^*}{\\partial u} &= - \\lambda - \\left( P^t A^t APu - P^t A^t (A\\lambda+y) \\right) \\\\\n",
750+
" \\frac{\\partial F^*}{\\partial u} &= Pu - \\lambda - \\left( P^t A^t APu - P^t A^t (A\\lambda-y) \\right) \\\\\n",
751751
"\\end{align*}"
752752
]
753753
},
@@ -757,7 +757,7 @@
757757
"source": [
758758
"### Convex conjugate of $g$\n",
759759
"\n",
760-
"As seen previously, $g$ is the trivial function $g(x)=0$, its proximity operator is the identity: $\\mathrm{prox}_{\\gamma g}(x) = x$. Its convex conjugate reads $G^*(u)= \\underset{z}{max} \\quad \\langle u, z \\rangle_{\\mathbb{R}^n}$ which reduces to the constraint $u=0$ that translate into the indicator function of 0 : $\\delta_0(u)$ \\\\\n",
760+
"As seen previously, $g$ is the trivial function $g(x)=0$, its proximity operator is the identity: $\\mathrm{prox}_{\\gamma g}(x) = x$. Its convex conjugate reads $G^*(u)= \\underset{z}{max} \\quad \\langle u, z \\rangle_{\\mathbb{R}^n}$ which reduces to the constraint $u=0$ that translate into the indicator function of 0 : $\\delta_0(u)$\n",
761761
"\n",
762762
"Thanks to Moreau identity, we can esily derive the proximity operator of $G^*$:\n",
763763
"\n",
@@ -787,7 +787,7 @@
787787
"\\begin{align*}\n",
788788
" & F^*( -L^* u ) + G^*(u)\\\\\n",
789789
" =& F^*( -u ) + \\delta_0(u)\\\\\n",
790-
" =& \\langle u,Pu \\rangle + \\langle u,\\lambda \\rangle - \\frac{1}{2} \\| APu + A\\lambda + y\\|_2^2 + \\delta_0(u)\n",
790+
" =& \\langle u,Pu \\rangle + \\langle u,\\lambda \\rangle - \\frac{1}{2} \\| APu + A\\lambda - y\\|_2^2 + \\delta_0(u)\n",
791791
"\\end{align*}\n",
792792
"\n",
793793
"With $P = \\left(A^t A\\right)^{-1}$ and $\\lambda = \\left(A^t A\\right)^{-1}A^t y$\n",
@@ -796,7 +796,7 @@
796796
"\n",
797797
"\\begin{align*}\n",
798798
" x^{k} &= \\nabla f^*( -L^* u^{k} )\\\\\n",
799-
" x^{k} &= - \\lambda - \\left( -P^t A^t APu^{k} - P^t A^t (A\\lambda+y) \\right)\n",
799+
" x^{k} &= Pu^{k} - \\lambda - \\left( -P^t A^t APu^{k} - P^t A^t (A\\lambda-y) \\right)\n",
800800
"\\end{align*}\n",
801801
"\n",
802802
"And the dual update\n",
@@ -809,14 +809,14 @@
809809
"\n",
810810
"The dual objective now reads\n",
811811
"\\begin{align*}\n",
812-
" &= \\langle u,Pu \\rangle + \\langle u,\\lambda \\rangle - \\frac{1}{2} \\| APu + A\\lambda + y\\|_2^2 + \\delta_0(u) \\\\\n",
813-
" &= - \\frac{1}{2} \\| A \\lambda + y\\|_2^2 \\\\\n",
814-
" &= - \\frac{1}{2} \\| A \\left(A^t A\\right)^{-1}A^t y + y\\|_2^2\n",
812+
" &= \\langle u,Pu \\rangle + \\langle u,\\lambda \\rangle - \\frac{1}{2} \\| APu + A\\lambda - y\\|_2^2 + \\delta_0(u) \\\\\n",
813+
" &= - \\frac{1}{2} \\| A \\lambda - y\\|_2^2 \\\\\n",
814+
" &= - \\frac{1}{2} \\| A \\left(A^t A\\right)^{-1}A^t y - y\\|_2^2\n",
815815
"\\end{align*}\n",
816816
"\n",
817817
"and the forward backward algorithm reads\n",
818818
"\\begin{align*}\n",
819-
" x^{k} &= - \\lambda + P^t A^t (A\\lambda+y)\\\\\n",
819+
" x^{k} &= - \\lambda + P^t A^t (A\\lambda-y)\\\\\n",
820820
" u^{k+1} &= 0\n",
821821
"\\end{align*}"
822822
]
@@ -847,7 +847,7 @@
847847
"name": "python",
848848
"nbconvert_exporter": "python",
849849
"pygments_lexer": "ipython3",
850-
"version": "3.6.3"
850+
"version": "3.6.7"
851851
}
852852
},
853853
"nbformat": 4,

QuadraticFormsForFun.ipynb

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# Numerical stuff\n",
10+
"import numpy as np"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"metadata": {},
16+
"source": [
17+
"# Quadratic forms for fun\n",
18+
"\n",
19+
"## Introduction\n",
20+
"This notebook is a kind of follow up on the EllipsoidEstimation notebook."
21+
]
22+
}
23+
],
24+
"metadata": {
25+
"kernelspec": {
26+
"display_name": "Python 3",
27+
"language": "python",
28+
"name": "python3"
29+
},
30+
"language_info": {
31+
"codemirror_mode": {
32+
"name": "ipython",
33+
"version": 3
34+
},
35+
"file_extension": ".py",
36+
"mimetype": "text/x-python",
37+
"name": "python",
38+
"nbconvert_exporter": "python",
39+
"pygments_lexer": "ipython3",
40+
"version": "3.6.7"
41+
}
42+
},
43+
"nbformat": 4,
44+
"nbformat_minor": 2
45+
}

SpatiallyVariantDeconvolution.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -6023,7 +6023,7 @@
60236023
"name": "python",
60246024
"nbconvert_exporter": "python",
60256025
"pygments_lexer": "ipython3",
6026-
"version": "3.6.6"
6026+
"version": "3.6.7"
60276027
}
60286028
},
60296029
"nbformat": 4,

0 commit comments

Comments
 (0)