O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.
Próximos SlideShares
Carregando em…5
×

# OpenOpt の線形計画で圧縮センシング

19.255 visualizações

Tokyo.Scipy #3 http://partake.in/events/ac0fcc7d-a289-4e2a-bb8e-1965aab8b17b

Sample Code : https://github.com/tokyo-scipy/archive/tree/master/003/shima__shima

• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Seja o primeiro a comentar

### OpenOpt の線形計画で圧縮センシング

1. 1. 1
2. 2. • • • • • 2
3. 3. 3
4. 4. 4 x A y M N N×M
5. 5. 5 A M N
6. 6. 6 N M K K K M
7. 7. 7 0 1 0 0 0 01
8. 8. 8
9. 9. 9 y=A x x ˆx = arg min x kxk0 subject to y = Ax ˆx = arg min x kxk1 subject to y = Ax x t O(K log(M/K)) < N x ˆx = arg min x X ti subject to t  x  t, y = Ax
10. 10. 10 • • • • • • • • •
11. 11. 11 • • • • ※ • •
12. 12. 12 • • • • # objective to minimize: f x^T -> min f = np.zeros((n_inputs * 2), dtype=np.float) f[n_inputs:2 * n_inputs] = 1.0 P i ti ˆx = arg min x X ti subject to t  x  t, y = Ax
13. 13. 13 • • # constraint: a x^T == b a_eq = np.zeros((n_outputs, 2 * n_inputs), dtype=np.float) a_eq[:, 0:n_inputs] = trans b_eq = x1 y = Ax t  x  t • xi ti  0, xi ti  0, for i = 0, . . . , M # constraint: -t <= x <= t a = np.zeros((2 * n_inputs, 2 * n_inputs), dtype=np.float) for i in xrange(n_inputs): a[i, i] = -1.0 a[i, n_inputs + i] = -1.0 a[n_inputs + i, i] = 1.0 a[n_inputs + i, n_inputs + i] = -1.0 b = np.zeros(n_inputs * 2)
14. 14. 14 # solve linear programming prob = openopt.LP(f=f, Aeq=a_eq, beq=b_eq, A=a, b=b) result = prob.minimize('pclp') • • •
15. 15. 15
16. 16. 16
17. 17. 17 • • • • • • • •
18. 18. 18 • • • v = fd.oovar('speed') import FuncDesigner as fd a = fd.oovar() • x = fd.oovar(size=100) • • a, b, c = fd.oovars('a', 'b', 'c') ※
19. 19. 19 ※ ※ • f = a * b + x / y • f = fd.sin(x) g += c g = fd.log(y) • f = fd.dot(a, b) g = fd.sum(x) • • f = 0 for i in xrange(3): f = f + a[i]
20. 20. 20 • • ※ In [10]: a = fd.oovar() In [12]: f = fd.sin(a) In [13]: f(1) AttributeError In [20]: a, b = fd.oovars(2) In [21]: f = a + b In [22]: p = { a:1, b:10 } In [23]: f(p) Out[23]: array(11.0) • In [30]: a, b = fd.oovars(2) In [31]: f = a + b In [32]: p = { a:1.0, b:np.array([10., 20., 30.]) } In [33]: f(p) Out[33]: array([ 11., 21., 31.])
21. 21. 21 • • In [10]: x = fd.oovar() In [11]: f = fd.sin(x) In [12]: f({x:np.pi}) Out[12]: array(1.2246467991473532e-16) # 0 In [13]: f.D({x:np.pi}) Out[13]: {unnamed_oofun_11: -1.0} # sin'(π) = cos(π) = -1.0 • In [20]: x = fd.oovar() In [21]: f = 2 * x ** 2 In [22]: p = {x:np.array([1., 2., 3.])} In [23]: f(p) Out[23]: array([ 2., 8., 18.]) In [24]: f.D(p) Out[24]: {unnamed_oofun_13: array([[ 4., 0., 0.], [ 0., 8., 0.], [ 0., 0., 12.]])}
22. 22. 22 • # define variable t = fd.oovar('t', size=n_inputs) x = fd.oovar('x', size=n_inputs) # objective to minimize: f x^T -> min objective = fd.sum(t) • • • # init constraints constraints = [] • # equality constraint: a_eq x^T = b_eq constraints.append(fd.dot(trans, x) == x1)
23. 23. 23 • # inequality constraint: -t < x < t constraints.append(-t <= x) constraints.append(x <= t) • # start_point start_point = {x:np.zeros(n_inputs), t:np.zeros(n_inputs)} • # solve linear programming prob = LP(objective, start_point, constraints=constraints) result = prob.minimize('pclp') • hat_x = result.xf[x]
24. 24. 24 • • • • easy_install -U openopt • easy_install -U FuncDesigner • •
25. 25. • • • • • • 25