Successfully reported this slideshow.                         Upcoming SlideShare
×

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

19,676 views

Published on

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

Published in: Data & Analytics
• Full Name
Comment goes here.

Are you sure you want to Yes No • Dating direct: ❶❶❶ http://bit.ly/2F7hN3u ❶❶❶

Are you sure you want to  Yes  No

Are you sure you want to  Yes  No

Are you sure you want to  Yes  No

Are you sure you want to  Yes  No

Are you sure you want to  Yes  No

### 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 : a = fd.oovar() In : f = fd.sin(a) In : f(1) AttributeError In : a, b = fd.oovars(2) In : f = a + b In : p = { a:1, b:10 } In : f(p) Out: array(11.0) • In : a, b = fd.oovars(2) In : f = a + b In : p = { a:1.0, b:np.array([10., 20., 30.]) } In : f(p) Out: array([ 11., 21., 31.])
21. 21. 21 • • In : x = fd.oovar() In : f = fd.sin(x) In : f({x:np.pi}) Out: array(1.2246467991473532e-16) # 0 In : f.D({x:np.pi}) Out: {unnamed_oofun_11: -1.0} # sin'(π) = cos(π) = -1.0 • In : x = fd.oovar() In : f = 2 * x ** 2 In : p = {x:np.array([1., 2., 3.])} In : f(p) Out: array([ 2., 8., 18.]) In : f.D(p) Out: {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