Skip to content

Commit 8e6f93e

Browse files
committed
added more comments
1 parent 083c9f2 commit 8e6f93e

File tree

6 files changed

+72
-10
lines changed

6 files changed

+72
-10
lines changed

.markdownlint.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"default": true,
3+
"MD003": { "style": "setext_with_atx" },
4+
"MD007": { "indent": 4 },
5+
"MD013": { "line_length": 500 },
6+
"MD026": { "punctuation" : ",;:!" },
7+
"MD030": { "ul_single": 3, "ol_single": 2, "ul_multi": 3, "ol_multi": 2 },
8+
"no-hard-tabs": false
9+
}

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# ellpy
1+
ellpy
2+
=====
23

34
[![Build Status](https://travis-ci.org/luk036/ellpy.svg?branch=master)](https://travis-ci.org/luk036/ellpy)
45
[![Build status](https://ci.appveyor.com/api/projects/status/0v1cf05tcueny7d9?svg=true)](https://ci.appveyor.com/project/luk036/ellpy)
@@ -9,3 +10,22 @@
910
[![BCH compliance](https://bettercodehub.com/edge/badge/luk036/ellpy?branch=master)](https://bettercodehub.com/)
1011

1112
ellipsoid method python code
13+
14+
Features
15+
--------
16+
17+
- At most one square-root per iteration.
18+
- Include oracles for Matrix Inequalities and Network problems.
19+
- Suport Parallel-Cuts.
20+
21+
See also
22+
--------
23+
24+
- [ellcpp](https://github.com/luk036/ellcpp)
25+
- [Presentation Slides](https://luk036.github.io/cvx)
26+
27+
Note
28+
----
29+
30+
This project has been set up using PyScaffold 3.2.1. For details and usage
31+
information on PyScaffold see <https://pyscaffold.org/>.

experiments/corr_fn_cvx.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
import numpy as np
44
from scipy.interpolate import BSpline
55

6-
from ellpy.oracles.corr_oracle import construct_distance_matrix
6+
from ellpy.oracles.corr_oracle import (
7+
construct_distance_matrix,
8+
create_2d_isotropic,
9+
create_2d_sites
10+
)
711

812
# function [sp, tau2, Sig]
913

@@ -92,3 +96,29 @@ def lsq_corr_bspline(Y, s, n):
9296
if prob.status != cvx.OPTIMAL:
9397
raise Exception('CVXPY Error')
9498
return BSpline(t, np.array(c.value).flatten(), k)
99+
100+
101+
if __name__ == "__main__":
102+
import matplotlib.pyplot as plt
103+
# import matplotlib.pylab as lab
104+
s = create_2d_sites(10, 8)
105+
Y = create_2d_isotropic(s, 1000)
106+
# print('start ell...')
107+
# spl, num_iters, _ = lsq_corr_bspline(Y, s, 5)
108+
# pol, num_iters, _ = lsq_corr_poly(Y, s, 5)
109+
# # pol, num_iters, _ = mle_corr_poly(Y, s, 4)
110+
# print(pol)
111+
# print(num_iters)
112+
print('start cvx...')
113+
splcvx = lsq_corr_bspline(Y, s, 5)
114+
polcvx = lsq_corr_poly(Y, s, 5)
115+
116+
# h = s[-1] - s[0]
117+
d = np.sqrt(10**2 + 8**2)
118+
xs = np.linspace(0, d, 100)
119+
# plt.plot(xs, spl(xs), 'g', label='BSpline')
120+
plt.plot(xs, splcvx(xs), 'b', label='BSpline CVX')
121+
# plt.plot(xs, np.polyval(pol, xs), 'r', label='Polynomial')
122+
plt.plot(xs, np.polyval(polcvx, xs), 'r', label='Polynomial CVX')
123+
plt.legend(loc='best')
124+
plt.show()

experiments/exp2d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
for i in range(n):
3232
for j in range(i, n):
3333
d = np.array(s[j]) - np.array(s[i])
34-
Sig[i, j] = np.exp(-sdkern * np.sqrt(np.dot(d, d)))
34+
Sig[i, j] = np.exp(-sdkern * np.dot(d, d))
3535
Sig[j, i] = Sig[i, j]
3636

3737
A = linalg.sqrtm(Sig)

src/ellpy/oracles/lsq_corr_oracle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class lsq_oracle:
2525
where
2626
F(x) = F[1] x[1] + ··· + F[n] x[n]
2727
28-
{Fk}i,j = Ψk(‖sj − si‖^2)
28+
{Fk}i,j = Ψk(‖sj − si‖)
2929
3030
Returns:
3131
[type] -- [description]

src/ellpy/oracles/mle_corr_oracle.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@
1313

1414

1515
class mle_oracle:
16-
def __init__(self, Sig, Y):
17-
"""[summary]
16+
def __init__(self, Sig: Arr, Y: Arr):
17+
"""Maximum likelyhood estimation:
18+
19+
min ​log det Ω(p) + Tr( Ω(p)^{−1} Y )
20+
​s.t.​ 2Y ⪰ Ω(p) ⪰ 0,​
1821
1922
Arguments:
20-
Sig {[type]} -- [description]
21-
Y {[type]} -- [description]
23+
Sig {Arr} -- Covariance matrix
24+
Y {Arr} -- Biased covariance matrix
2225
"""
2326
self.Y = Y
2427
self.Sig = Sig
@@ -30,7 +33,7 @@ def __call__(self, x: Arr, t: float) -> Tuple[Cut, float]:
3033
"""[summary]
3134
3235
Arguments:
33-
x {Arr} -- [description]
36+
x {Arr} -- coefficients of basis functions
3437
t {float} -- the best-so-far optimal value
3538
3639
Returns:
@@ -52,7 +55,7 @@ def __call__(self, x: Arr, t: float) -> Tuple[Cut, float]:
5255
f1 = 2 * np.sum(np.log(diag)) + np.trace(SY)
5356

5457
f = f1 - t
55-
if f < 0:
58+
if f < 0.:
5659
t = f1
5760
f = 0.
5861

0 commit comments

Comments
 (0)