N x i 1 u i v i which is convex since the geometric

This preview shows page 31 - 35 out of 45 pages.

1 - 2 n X i =1 u i v i , which is convex since the geometric mean is concave. (c) The problem as given is convex, since d kol ( u, v ) is (jointly) convex. This is because for i = 1 , . . . , n , the function i j =1 u j - i j =1 v j is the composition of a convex function (absolute value) with a linear function of u and v . Since d kol is the maximum of these n functions, it is convex. (d) For each choice of d above, we simply solve minimize N - 1 i =1 d ( p ( i ) , p ( i +1) ) subject to p ( i ) 0 , 1 T p ( i ) = 1 , i = 1 , 2 , . . . N, p (1) = q, p ( N ) = r. Here’s the sequence of distributions obtained by using the Euclidean distance. 20 40 60 80 100 0.00 0.01 0.02 0.03 0.04 0.05 p (1) p (2) p (3) p (4) p (5) p (6) p (7) p (8) p (9) p (10) Here’s the sequence of distributions obtained by using the Hellinger distance. 31
20 40 60 80 100 0.00 0.01 0.02 0.03 0.04 0.05 p (1) p (2) p (3) p (4) p (5) p (6) p (7) p (8) p (9) p (10) Here’s the sequence of distributions obtained by using the Kolmogorov distance. 20 40 60 80 100 0.00 0.01 0.02 0.03 0.04 0.05 p (1) p (2) p (3) p (4) p (5) p (6) p (7) p (8) p (9) p (10) The following Julia code solves the problem. using Convex, ECOS, PSPlot include("morphing_data.jl") # plotting colors cm = ColorMap("coolwarm"); colors = [cm(i) for i in linspace(0, 0.9, N)]; # distance functions euc(a, b) = sumsquares(a - b) hel(a, b) = -sum(geomean(a[i], b[i]) for i in 1:n) kol(a, b) = maximum(abs(sum(a[1:i] - b[1:i])) for i in 1:n) functions = [euc, hel, kol] for d in functions p = Variable(n, N, Positive()) 32
obj = sum(d(p[:, i], p[:, i+1]) for i in 1:(N-1)) prob = minimize(obj, [p[:, 1] == q, p[:, N] == r, p’ * ones(n) == ones(N)]) solve!(prob, ECOSSolver(verbose=false), verbose=false) p = p.value # plot figure() for i in 1:N plot(1:n, p[:, i], label=" ", color=colors[i]) end legend() printfig("../figures/morphing_$(d)") end The following Python code solves the problem. from morphing_data import * import cvxpy as cp import matplotlib.pyplot as plt from matplotlib import cm coolwarm = cm.get_cmap(’coolwarm’) colors = [coolwarm(i) for i in np.linspace(0, 0.9, N)] # distance functions functions = [ lambda a,b : cp.sum_squares(a - b), lambda a,b : -cp.sum([cp.geo_mean(cp.vstack([a[i], b[i]])) for i in range(n)]), lambda a,b : cp.max(cp.vstack([cp.abs(cp.sum(a[:i] - b[:i])) for i in range(1,n)])), ] for d in functions: p = cp.Variable((n, N), nonneg=True) obj = cp.Minimize(cp.sum([d(p[:, i], p[:, i+1]) for i in range(N-1)])) prob = cp.Problem(obj, [p[:, 0] == q, p[:, -1] == r, [email protected](n) == np.ones(N)]) prob.solve(solver="ECOS") p = p.value for i in range(N): plt.plot(p[:, i], label="$p^{(%d)}$"%(i+1), color=colors[i]) plt.legend() plt.show() The following MATLAB code solves the problem. N = 10; n = 100; clf colormap cool; q = [exp(-((1:50) -25).^2 ./ 2) exp(-((51:100) -75).^2 ./ 2)]; r = exp(-((1:100) - 50).^2 ./ 2); q = q/sum(q); r = r/sum(r); fns = {@euc,@hel,@kol} 33
for i = 1:3 cvx_begin variable p(n,N) nonnegative expression x(N-1); for k=1:N-1 x(k) = fns{i}(p(:,k), p(:,k+1)); end minimize(sum(x)) subject to p(:,1) == q’; p(:,end) == r’; p’*ones(n,1) == ones(N,1); cvx_end plot(p) end function r=euc(a,b) r=sum(sum((a-b).^2)); end function r=hel(a,b) r = 0; for j = 1:100 r = r-geo_mean([a(j),b(j)]); end end function r=kol(a,b) m = []; for k = 1:100 m = [m, abs(sum(a(1:k) - b(1:k)))]; end r = max(m); end 34

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture