In [46]:
function shannonentropy{T}(V::AbstractVector{T})
    H = zero(T)
    for i=1:length(V)
        V[i]==0 && continue
        H -= V[i]*log2(V[i])
    end
    H
end


Out[46]:
shannonentropy (generic function with 1 method)

In [125]:
function symKL{T}(p::AbstractMatrix{T}, q::AbstractMatrix{T})
    C = zero(T)
    m, n = size(p)
    @assert (m, n) == size(q)
    for i=1:m, j=1:n
        #i==j && continue
        p[i,j]==0 && continue
        q[i,j]==0 && continue
        C += p[i,j] * log(p[i,j]/q[i,j])
    end
    C
end


Out[125]:
symKL (generic function with 1 method)

In [48]:
#Jacobs' learning rate updating rule
function learnupdate(ϵ, δ, δ̄ , θ=0.2, ϕ=0.5, κ=0.5)
    test = δ̄ *δ
    δ̄ = (1-θ)*δ + θ*δ̄ 
    Δϵ = if test > 0
            κ
        elseif test < 0
            -ϕ*ϵ
        else
            0.0
        end
    Δϵ, δ̄ 
end


Out[48]:
learnupdate (generic function with 4 methods)

In [49]:
function tsne{S<:Real}(X::Matrix{S}, σ::Vector{S},
        Y=randn(k, size(X, 2))*1e-4, k::Int=2, T::Int=1000, η=100)
    
    m, n = size(X)
    @assert length(σ) == n
    #Compute pairwise affinities
    p = zeros(S, n, n)
    psum = zero(S)
    for i=1:n, j=1:n
        thisp = exp(-norm(slice(X, :, i) - slice(X, :, j))^2/(2σ[i]^2))
        p[j, i] = thisp
        psum += thisp
    end
    scale!(p, 1/psum)
    #Compute Shannon entropy
    for i=1:n
        H = shannonentropy(slice(p, :, i))
        info("Entropy_i = $H, perplexity = $(2^H) (5--50 recommended)")
    end
    #Symmetrize
    p = (p + p')/(2n)
    #Sample initial solution
    Y₋= zeros(k, n)
    δ̄ = zeros(k, n) #Used for weighted update
    ηs= fill(float(η), k, n)
    cost = Inf
    for t=1:T
        #Compute low-dimensional affinities
        q = zeros(n, n)
        qsum = 0.0
        for i=1:n, j=1:n
            δy = slice(Y, :, i) - slice(Y, :, j)
            thisq = 1/(1 + δy⋅δy)
            q[i,j] = thisq
            i==j || (qsum += thisq)
        end
        scale!(q, 1/qsum)
        #Compute δC_δy
        δC_δy = zeros(k, n)
        exag = t<50 ? 4.0 : 1.0 #"early exaggeration" 
        for i=1:n, j=1:n
            j==i && continue
            δC_δy[:, i] += 4*(exag*p[i,j] - q[i,j])*
            (Y[:, i] - Y[:, j])/
            (1 + norm(slice(Y, :, i) - slice(Y, :, j))^2)
        end
        α = t<250 ? 0.5 : 0.8
        #Update Y
        Y, Y₋ = Y + η.*δC_δy + α*(Y-Y₋), Y
        #Update η (Jacobs, 1988)
        for i=1:n, j=1:k
            Δϵ, δ̄ [j, i] = learnupdate(ηs[j, i], δC_δy[j, i], δ̄ [j, i])
            ηs[j, i] += Δϵ
        end
        #Print cost function
        cost, oldcost = symKL(p, q), cost
        info("Iteration $t: cost = $cost")
        abs(cost - oldcost) <= 1e-9*abs(cost) && break
    end
    Y
end


Out[49]:
tsne (generic function with 5 methods)

In [50]:
#Do t-SNE with quasi-Newton

In [51]:
function backtracklinesearch(p, x, f, df_dx, α=1.0, c=0.5, τ=0.5, maxiter::Int=10)
    m = p⋅df_dx
    t = -c*m
    for j = 1:maxiter
        f(x) - f(x+α*p)  α*t && break 
        α *= τ
        j==maxiter && (warn("Maxiter reached"); return 0.0)
    end
    α
end


Out[51]:
backtracklinesearch (generic function with 5 methods)

In [139]:
function compute_dC_dq(Y, p, q)
    k, n = size(Y)
    δC_δy = zeros(k, n)
    for i=1:n, j=1:n
        #i==j && continue
        d = norm(slice(Y, :, i) - slice(Y, :, j))
        δC_δy[:, i] += 4*(p[i,j] - q[i,j])*
        (Y[:, i] - Y[:, j])*
        1/(1 + d^2) #Factor of d is absent in papar
        @show i, j, δC_δy[:, i]
    end
    δC_δy
end


Out[139]:
compute_dC_dq (generic function with 1 method)

In [162]:
function g_tsne!(
	gr::Matrix{Float64},
	P::Matrix{Float64},
	Q::Matrix{Float64},
	Y::Matrix{Float64},
)
	k, n = size(Y)
	fill!(gr, 0.0)
	for dim in 1:k
		for i in 1:n
			for j in 1:n
				if i != j
                    prdiff = (P[i, j] - Q[i, j])
                    D2_Y = norm(Y[:, i] - Y[:, j])^2
					tkern = 1 / (1 + D2_Y)
					gr[dim, i] += 4 * prdiff * (Y[dim, i] - Y[dim, j]) * tkern
				end
			end
		end
	end
    gr
end


Out[162]:
g_tsne! (generic function with 2 methods)

In [ ]:


In [164]:
let #Check derivative by finite central difference
Y=[1. 2.1; 13 4];#zeros(2,4)#randn(2,4)
q=computeq(Y)
@assert q==[0 0.5; 0.5 0]
p=ones(2,2)-eye(2,2)

@show g_tsne!(zeros(2,2), p, q, Y)    
C=symKL(p, q)
@assert C==2log(2)
dC_dq = compute_dC_dq(Y, p, q)
dC_dq_f = similar(dC_dq)
ϵ = 1e-6
for i=1:size(Y,1), j=1:size(Y,2)
    Y[i,j] += ϵ
    q2=computeq(Y)
    @show C2=symKL(p,q2)
    Y[i,j] -= 2ϵ
    q3=computeq(Y)
    @show C3=symKL(p,q3)
    Y[i,j] += ϵ
    dC_dq_f[i,j] = (C2 - C3)/(2ϵ)
end
[dC_dq[:] dC_dq_f[:]]
end


g_tsne!(zeros(2,2),p,q,Y) => [-0.026439129912270157 0.026439129912270157
 0.2163201538276649 -0.2163201538276649]
(i,j,δC_δy[:,i]) => (1,1,[0.0,0.0])
(i,j,δC_δy[:,i]) => (1,2,[-0.026439129912270154,0.2163201538276649])
(i,j,δC_δy[:,i]) => (2,1,[0.026439129912270154,-0.2163201538276649])
(i,j,δC_δy[:,i]) => (2,2,[0.026439129912270154,-0.2163201538276649])
C2 = symKL(p,q2) => 1.3862943611198906
C3 = symKL(p,q3) => 1.3862943611198906
C2 = symKL(p,q2) => 1.3862943611198906
C3 = symKL(p,q3) => 1.3862943611198906
C2 = symKL(p,q2) => 1.3862943611198906
C3 = symKL(p,q3) => 1.3862943611198906
C2 = symKL(p,q2) => 1.3862943611198906
C3 = symKL(p,q3) => 1.3862943611198906
Out[164]:
4x2 Array{Float64,2}:
 -0.0264391  0.0
  0.21632    0.0
  0.0264391  0.0
 -0.21632    0.0

In [ ]:


In [151]:
function computeq(Y)
    n = size(Y, 2)
    q = zeros(n, n)
    qsum = 0.0
    for i=1:n, j=1:n
        i==j && continue
        δy = slice(Y, :, i) - slice(Y, :, j)
        thisq = 1/(1 + δy⋅δy)
        q[i,j] = thisq
        qsum += thisq
    end
    scale!(q, 1/qsum)
end


Out[151]:
computeq (generic function with 1 method)

In [86]:
function tsne_bfgs{S<:Real}(X::Matrix{S}, σ::Vector{S},
        Y=randn(k, size(X, 2))*1e-4, k::Int=2, T::Int=1000, η=100)
    
    m, n = size(X)
    @assert length(σ) == n
    #Compute pairwise affinities
    p = zeros(S, n, n)
    psum = zero(S)
    for i=1:n, j=1:n
        p[j, i] = thisp = exp(-norm(slice(X, :, i) - slice(X, :, j))^2/(2σ[i]^2))
        psum += thisp
    end
    scale!(p, 1/psum)

    #Compute Shannon entropy
#      for i=1:n
#          H = shannonentropy(slice(p, :, i))
#          info("Entropy_i = $H, perplexity = $(2^H) (5--50 recommended)")
#      end
    #Symmetrize
    p = (p + p')/(2n)
        
    cost = Inf
    computeHessian=true
    for t=1:T
        #Compute low-dimensional affinities
        q = computeq(Y)
        #Compute δC_δy
        δC_δy = compute_dC_dq(Y, p, q)

        #Compute Hessian
        #Initialize pseudo-Hessian
        if computeHessian
            B = spzeros(k*n, k*n)
            #B = zeros(k*n, k*n)
            q = computeq(Y)
            for i=1:n, kk=1:n
                d = norm(slice(Y,:,i)-slice(Y,:,kk))
                for l=1:k
                    B[(i-1)*k+l,(i-1)*k+l] += 4*(p[i,kk]-q[i,kk])*d/(1+d^2)
                end
            end
            computeHessian = false
        end
            
        #Search direction
        px = -B\δC_δy[:]
        
        #Backtracking line search
        α = backtracklinesearch(px, Y[:], y->symKL(p, computeq(reshape(y,k,n))), δC_δy[:])
        computeHessian = α==0
        
        sx = α*px
        Y=Y+reshape(sx, k, n)
        yx = compute_dC_dq(Y, p, computeq(Y))[:] - δC_δy[:]
        
        tx = B*sx
        B = B + yx*yx'/(yx⋅sx) - tx*tx'/(sx⋅tx)

        #Print cost function
        cost, oldcost = symKL(p, q), cost
        info("Iteration $t: cost = $cost")
        abs(cost - oldcost) <= 1e-9*abs(cost) && break
    end
    Y
end


Out[86]:
tsne_bfgs (generic function with 5 methods)

In [55]:
using MNIST
n=100
X = testdata()[1][:,1:n]
digitid = int(testdata()[2][1:n])


Out[55]:
100-element Array{Int64,1}:
 7
 2
 1
 0
 4
 1
 4
 9
 5
 9
 0
 6
 9
 ⋮
 6
 1
 3
 6
 9
 3
 1
 4
 1
 7
 6
 9

In [89]:
Y = std(X, 1)[:]
Y0 = randn(2,n)
@time Y1 = tsne(X, Y, Y0)


INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Entropy_i = 0.06643856189774724, perplexity = 1.0471285480508996 (5--50 recommended)
INFO: Iteration 1: cost = -1.1248281842246866e-37
INFO: Iteration 2: cost = -1.1167814536587343e-37
INFO: Iteration 3: cost = -1.1173227943684136e-37
INFO: Iteration 4: cost = -1.1093520495905828e-37
INFO: Iteration 5: cost = -1.1155672401893126e-37
INFO: Iteration 6: cost = -1.1102862989009728e-37
INFO: Iteration 7: cost = -1.115243997752116e-37
INFO: Iteration 8: cost = -1.1119396009023614e-37
INFO: Iteration 9: cost = -1.1182289505991747e-37
INFO: Iteration 10: cost = -1.1150528066797724e-37
INFO: Iteration 11: cost = -1.1219342032257265e-37
INFO: Iteration 12: cost = -1.1200359397249265e-37
INFO: Iteration 13: cost = -1.1306063453610187e-37
INFO: Iteration 14: cost = -1.132244227965578e-37
INFO: Iteration 15: cost = -1.1455242116338842e-37
INFO: Iteration 16: cost = -1.1460075060788645e-37
INFO: Iteration 17: cost = -1.1457573377114104e-37
INFO: Iteration 18: cost = -1.146651895453002e-37
INFO: Iteration 19: cost = -1.146941678182044e-37
INFO: Iteration 20: cost = -1.1459652962175876e-37
INFO: Iteration 21: cost = -1.1469398392288653e-37
INFO: Iteration 22: cost = -1.1464883610547125e-37
INFO: Iteration 23: cost = -1.147047551289788e-37
INFO: Iteration 24: cost = -1.1465444775542458e-37
INFO: Iteration 25: cost = -1.1473496020213722e-37
INFO: Iteration 26: cost = -1.1467123488154025e-37
INFO: Iteration 27: cost = -1.1472638737658667e-37
INFO: Iteration 28: cost = -1.1466712770214278e-37
INFO: Iteration 29: cost = -1.1473306380083259e-37
INFO: Iteration 30: cost = -1.1466953768605e-37
INFO: Iteration 31: cost = -1.147289801195552e-37
INFO: Iteration 32: cost = -1.1466799189522927e-37
INFO: Iteration 33: cost = -1.147308092865299e-37
INFO: Iteration 34: cost = -1.1466817085506297e-37
INFO: Iteration 35: cost = -1.1472922855852015e-37
INFO: Iteration 36: cost = -1.146672496089605e-37
INFO: Iteration 37: cost = -1.147289997818322e-37
INFO: Iteration 38: cost = -1.1466639546963011e-37
INFO: Iteration 39: cost = -1.1472737729685135e-37
INFO: Iteration 40: cost = -1.146646393865489e-37
INFO: Iteration 41: cost = -1.1472530044717593e-37
INFO: Iteration 42: cost = -1.1466155515848628e-37
INFO: Iteration 43: cost = -1.147200991534617e-37
INFO: Iteration 44: cost = -1.1465271491877598e-37
INFO: Iteration 45: cost = -1.1469710889666993e-37
INFO: Iteration 46: cost = -1.1459704414345975e-37
INFO: Iteration 47: cost = -1.1466348130180933e-37
INFO: Iteration 48: cost = -1.1461241993617227e-37
INFO: Iteration 49: cost = -1.1465772353184492e-37
INFO: Iteration 50: cost = -1.145929446649985e-37
INFO: Iteration 51: cost = -1.146573557522461e-37
INFO: Iteration 52: cost = -1.1457843132736755e-37
INFO: Iteration 53: cost = -1.1464284626761375e-37
INFO: Iteration 54: cost = -1.1458326344646242e-37
INFO: Iteration 55: cost = -1.1463483932890837e-37
INFO: Iteration 56: cost = -1.1458256389653704e-37
INFO: Iteration 57: cost = -1.1462784491421463e-37
INFO: Iteration 58: cost = -1.1457362096733168e-37
INFO: Iteration 59: cost = -1.1463739879912605e-37
INFO: Iteration 60: cost = -1.1456970894715627e-37
INFO: Iteration 61: cost = -1.146322161438659e-37
INFO: Iteration 62: cost = -1.1457444261471949e-37
INFO: Iteration 63: cost = -1.1463303911902542e-37
INFO: Iteration 64: cost = -1.1457085126409157e-37
INFO: Iteration 65: cost = -1.146337020461545e-37
INFO: Iteration 66: cost = -1.1457330831421879e-37
INFO: Iteration 67: cost = -1.1463354207679127e-37
INFO: Iteration 68: cost = -1.145721440936928e-37
INFO: Iteration 69: cost = -1.146334771615259e-37
INFO: Iteration 70: cost = -1.1457279362990393e-37
INFO: Iteration 71: cost = -1.1463366084988784e-37
INFO: Iteration 72: cost = -1.1457237419676542e-37
INFO: Iteration 73: cost = -1.1463350979700818e-37
INFO: Iteration 74: cost = -1.14572786522953e-37
INFO: Iteration 75: cost = -1.1463369185770594e-37
INFO: Iteration 76: cost = -1.1457243607671739e-37
INFO: Iteration 77: cost = -1.1463354932032067e-37
INFO: Iteration 78: cost = -1.145728046783183e-37
INFO: Iteration 79: cost = -1.1463370689162352e-37
INFO: Iteration 80: cost = -1.1457246676541503e-37
INFO: Iteration 81: cost = -1.1463357184996224e-37
INFO: Iteration 82: cost = -1.1457283456888154e-37
INFO: Iteration 83: cost = -1.1463371625915049e-37
INFO: Iteration 84: cost = -1.145724802767782e-37
INFO: Iteration 85: cost = -1.1463358620599619e-37
INFO: Iteration 86: cost = -1.1457285951427305e-37
INFO: Iteration 87: cost = -1.1463372083682263e-37
INFO: Iteration 88: cost = -1.1457249111278679e-37
INFO: Iteration 89: cost = -1.1463359262573292e-37
INFO: Iteration 90: cost = -1.1457287802106453e-37
INFO: Iteration 91: cost = -1.1463372321725382e-37
INFO: Iteration 92: cost = -1.1457249957328875e-37
INFO: Iteration 93: cost = -1.146335935885075e-37
INFO: Iteration 94: cost = -1.1457289231365446e-37
INFO: Iteration 95: cost = -1.1463372359824618e-37
INFO: Iteration 96: cost = -1.1457250592612694e-37
INFO: Iteration 97: cost = -1.1463359074952376e-37
INFO: Iteration 98: cost = -1.1457290309697207e-37
INFO: Iteration 99: cost = -1.1463372214482125e-37
INFO: Iteration 100: cost = -1.1457251054532113e-37
INFO: Iteration 101: cost = -1.1463358522367994e-37
INFO: Iteration 102: cost = -1.1457291098701644e-37
INFO: Iteration 103: cost = -1.1463371907001966e-37
INFO: Iteration 104: cost = -1.1457251363040012e-37
INFO: Iteration 105: cost = -1.1463357771945126e-37
INFO: Iteration 106: cost = -1.1457291638793578e-37
INFO: Iteration 107: cost = -1.1463371453998106e-37
INFO: Iteration 108: cost = -1.1457251535149229e-37
INFO: Iteration 109: cost = -1.146335687422449e-37
INFO: Iteration 110: cost = -1.1457291961499808e-37
INFO: Iteration 111: cost = -1.1463370871049484e-37
INFO: Iteration 112: cost = -1.14572515849373e-37
INFO: Iteration 113: cost = -1.1463355863974485e-37
INFO: Iteration 114: cost = -1.1457292091221487e-37
INFO: Iteration 115: cost = -1.1463370173134847e-37
INFO: Iteration 116: cost = -1.1457251525283221e-37
INFO: Iteration 117: cost = -1.1463354766476837e-37
INFO: Iteration 118: cost = -1.145729204855734e-37
INFO: Iteration 119: cost = -1.14633693743625e-37
INFO: Iteration 120: cost = -1.1457251367928918e-37
INFO: Iteration 121: cost = -1.1463353600802128e-37
INFO: Iteration 122: cost = -1.1457291851636387e-37
INFO: Iteration 123: cost = -1.1463368488008564e-37
INFO: Iteration 124: cost = -1.145725112374377e-37
INFO: Iteration 125: cost = -1.1463352381888544e-37
INFO: Iteration 126: cost = -1.1457291516910556e-37
INFO: Iteration 127: cost = -1.1463367526474955e-37
INFO: Iteration 128: cost = -1.1457250802799614e-37
INFO: Iteration 129: cost = -1.1463351121819752e-37
INFO: Iteration 130: cost = -1.1457291059529431e-37
INFO: Iteration 131: cost = -1.1463366501256792e-37
INFO: Iteration 132: cost = -1.1457250414415303e-37
INFO: Iteration 133: cost = -1.146334983061415e-37
INFO: Iteration 134: cost = -1.1457290493509742e-37
INFO: Iteration 135: cost = -1.1463365422919979e-37
INFO: Iteration 136: cost = -1.1457249967176696e-37
INFO: Iteration 137: cost = -1.1463348516716925e-37
INFO: Iteration 138: cost = -1.145728983180643e-37
INFO: Iteration 139: cost = -1.14633643010927e-37
INFO: Iteration 140: cost = -1.1457249468948535e-37
INFO: Iteration 141: cost = -1.1463347187314758e-37
INFO: Iteration 142: cost = -1.14572890863426e-37
INFO: Iteration 143: cost = -1.1463363144472709e-37
INFO: Iteration 144: cost = -1.1457248926889214e-37
INFO: Iteration 145: cost = -1.1463345848544283e-37
INFO: Iteration 146: cost = -1.1457288268027905e-37
INFO: Iteration 147: cost = -1.1463361960850348e-37
INFO: Iteration 148: cost = -1.145724834747256e-37
INFO: Iteration 149: cost = -1.1463344505638014e-37
INFO: Iteration 150: cost = -1.1457287386779899e-37
INFO: Iteration 151: cost = -1.1463360757145096e-37
INFO: Iteration 152: cost = -1.1457247736517582e-37
INFO: Iteration 153: cost = -1.1463343163034014e-37
INFO: Iteration 154: cost = -1.1457286451554231e-37
INFO: Iteration 155: cost = -1.1463359539452696e-37
INFO: Iteration 156: cost = -1.1457247099225293e-37
INFO: Iteration 157: cost = -1.1463341824464544e-37
INFO: Iteration 158: cost = -1.1457285470384806e-37
INFO: Iteration 159: cost = -1.1463358313099793e-37
INFO: Iteration 160: cost = -1.1457246440220838e-37
INFO: Iteration 161: cost = -1.1463340493032492e-37
INFO: Iteration 162: cost = -1.1457284450432896e-37
INFO: Iteration 163: cost = -1.1463357082703145e-37
INFO: Iteration 164: cost = -1.145724576359894e-37
INFO: Iteration 165: cost = -1.1463339171280203e-37
INFO: Iteration 166: cost = -1.1457283398043105e-37
INFO: Iteration 167: cost = -1.14633558522309e-37
INFO: Iteration 168: cost = -1.145724507297074e-37
INFO: Iteration 169: cost = -1.1463337861253133e-37
INFO: Iteration 170: cost = -1.1457282318803795e-37
INFO: Iteration 171: cost = -1.1463354625063875e-37
INFO: Iteration 172: cost = -1.1457244371510503e-37
INFO: Iteration 173: cost = -1.1463336564559217e-37
INFO: Iteration 174: cost = -1.1457281217609806e-37
INFO: Iteration 175: cost = -1.1463353404055305e-37
INFO: Iteration 176: cost = -1.145724366200086e-37
INFO: Iteration 177: cost = -1.1463335282424405e-37
INFO: Iteration 178: cost = -1.1457280098725542e-37
INFO: Iteration 179: cost = -1.1463352191587902e-37
INFO: Iteration 180: cost = -1.1457242946875763e-37
INFO: Iteration 181: cost = -1.1463334015744198e-37
INFO: Iteration 182: cost = -1.1457278965846803e-37
INFO: Iteration 183: cost = -1.14633509896274e-37
INFO: Iteration 184: cost = -1.1457242228260465e-37
INFO: Iteration 185: cost = -1.1463332765131194e-37
INFO: Iteration 186: cost = -1.1457277822160257e-37
INFO: Iteration 187: cost = -1.146334979977222e-37
INFO: Iteration 188: cost = -1.1457241508008227e-37
INFO: Iteration 189: cost = -1.1463331530958436e-37
INFO: Iteration 190: cost = -1.1457276670399686e-37
INFO: Iteration 191: cost = -1.1463348623298871e-37
INFO: Iteration 192: cost = -1.1457240787733535e-37
INFO: Iteration 193: cost = -1.1463330313398555e-37
INFO: Iteration 194: cost = -1.1457275512898382e-37
INFO: Iteration 195: cost = -1.1463347461203143e-37
INFO: Iteration 196: cost = -1.1457240068841875e-37
INFO: Iteration 197: cost = -1.1463329112458794e-37
INFO: Iteration 198: cost = -1.1457274351637496e-37
INFO: Iteration 199: cost = -1.1463346314237057e-37
INFO: Iteration 200: cost = -1.1457239352556105e-37
INFO: Iteration 201: cost = -1.146332792801198e-37
INFO: Iteration 202: cost = -1.145727318829009e-37
INFO: Iteration 203: cost = -1.1463345182941818e-37
INFO: Iteration 204: cost = -1.1457238639939598e-37
INFO: Iteration 205: cost = -1.146332675982368e-37
INFO: Iteration 206: cost = -1.145727202426106e-37
INFO: Iteration 207: cost = -1.1463344067676939e-37
INFO: Iteration 208: cost = -1.1457237931916417e-37
INFO: Iteration 209: cost = -1.146332560757577e-37
INFO: Iteration 210: cost = -1.1457270860722927e-37
INFO: Iteration 211: cost = -1.1463342968645804e-37
INFO: Iteration 212: cost = -1.1457237229288702e-37
INFO: Iteration 213: cost = -1.1463324470886733e-37
INFO: Iteration 214: cost = -1.1457269698647793e-37
INFO: Iteration 215: cost = -1.1463341885918e-37
INFO: Iteration 216: cost = -1.1457236532751537e-37
INFO: Iteration 217: cost = -1.146332334932896e-37
INFO: Iteration 218: cost = -1.1457268538835709e-37
INFO: Iteration 219: cost = -1.1463340819448618e-37
INFO: Iteration 220: cost = -1.1457235842905568e-37
INFO: Iteration 221: cost = -1.1463322242443355e-37
INFO: Iteration 222: cost = -1.14572673819397e-37
INFO: Iteration 223: cost = -1.1463339769094955e-37
INFO: Iteration 224: cost = -1.1457235160267585e-37
INFO: Iteration 225: cost = -1.14633211497516e-37
INFO: Iteration 226: cost = -1.145726622848782e-37
INFO: Iteration 227: cost = -1.146333873463076e-37
INFO: Iteration 228: cost = -1.1457234485279337e-37
INFO: Iteration 229: cost = -1.1463320070766284e-37
INFO: Iteration 230: cost = -1.1457265078902433e-37
INFO: Iteration 231: cost = -1.1463337715758372e-37
INFO: Iteration 232: cost = -1.1457233818314777e-37
INFO: Iteration 233: cost = -1.146331900499928e-37
INFO: Iteration 234: cost = -1.1457263933517107e-37
INFO: Iteration 235: cost = -1.1463336712119024e-37
INFO: Iteration 236: cost = -1.1457233159685923e-37
INFO: Iteration 237: cost = -1.1463317951968485e-37
INFO: Iteration 238: cost = -1.1457262792591346e-37
INFO: Iteration 239: cost = -1.1463335723301455e-37
INFO: Iteration 240: cost = -1.1457232509647597e-37
INFO: Iteration 241: cost = -1.146331691120328e-37
INFO: Iteration 242: cost = -1.1457261656323395e-37
INFO: Iteration 243: cost = -1.1463334748849182e-37
INFO: Iteration 244: cost = -1.1457231868401106e-37
INFO: Iteration 245: cost = -1.146331588224879e-37
INFO: Iteration 246: cost = -1.1457260524861372e-37
INFO: Iteration 247: cost = -1.1463333788266517e-37
INFO: Iteration 248: cost = -1.1457231236097109e-37
INFO: Iteration 249: cost = -1.1463314864669232e-37
INFO: Iteration 250: cost = -1.145725939831298e-37
INFO: Iteration 251: cost = -1.1453195798314151e-37
INFO: Iteration 252: cost = -1.1452123418737032e-37
INFO: Iteration 253: cost = -1.1448430465643812e-37
INFO: Iteration 254: cost = -1.144938665056851e-37
INFO: Iteration 255: cost = -1.1453154422720625e-37
INFO: Iteration 256: cost = -1.145200550937387e-37
INFO: Iteration 257: cost = -1.1449220749752638e-37
INFO: Iteration 258: cost = -1.1449537052336513e-37
INFO: Iteration 259: cost = -1.144693265120112e-37
INFO: Iteration 260: cost = -1.14407668390443e-37
INFO: Iteration 261: cost = -1.144672562016231e-37
INFO: Iteration 262: cost = -1.1445474276800533e-37
INFO: Iteration 263: cost = -1.1445171854264098e-37
INFO: Iteration 264: cost = -1.1447711946418143e-37
INFO: Iteration 265: cost = -1.1445190299258238e-37
INFO: Iteration 266: cost = -1.1447180008599532e-37
INFO: Iteration 267: cost = -1.1449327806572518e-37
INFO: Iteration 268: cost = -1.1451627632894894e-37
INFO: Iteration 269: cost = -1.1447537643267295e-37
INFO: Iteration 270: cost = -1.1444216830765433e-37
INFO: Iteration 271: cost = -1.1443685081033626e-37
INFO: Iteration 272: cost = -1.1444729339441986e-37
INFO: Iteration 273: cost = -1.1443962083943372e-37
INFO: Iteration 274: cost = -1.1445800721866027e-37
INFO: Iteration 275: cost = -1.1445886466802485e-37
INFO: Iteration 276: cost = -1.144209219929514e-37
INFO: Iteration 277: cost = -1.1446181482095549e-37
INFO: Iteration 278: cost = -1.144325105917769e-37
INFO: Iteration 279: cost = -1.144672803244732e-37
INFO: Iteration 280: cost = -1.144685547031517e-37
INFO: Iteration 281: cost = -1.1443452605564488e-37
INFO: Iteration 282: cost = -1.144790108428309e-37
INFO: Iteration 283: cost = -1.1449998936065543e-37
INFO: Iteration 284: cost = -1.1451476790737145e-37
INFO: Iteration 285: cost = -1.1452398152858523e-37
INFO: Iteration 286: cost = -1.1452068063286368e-37
INFO: Iteration 287: cost = -1.1450819081987987e-37
INFO: Iteration 288: cost = -1.1449189380995488e-37
INFO: Iteration 289: cost = -1.1445037922833793e-37
INFO: Iteration 290: cost = -1.14475570202611e-37
INFO: Iteration 291: cost = -1.1449360773623693e-37
INFO: Iteration 292: cost = -1.145119372381401e-37
INFO: Iteration 293: cost = -1.1453089009930714e-37
INFO: Iteration 294: cost = -1.1453467176473094e-37
INFO: Iteration 295: cost = -1.1452293377860102e-37
INFO: Iteration 296: cost = -1.145123107718547e-37
INFO: Iteration 297: cost = -1.1451146214288014e-37
INFO: Iteration 298: cost = -1.145182691246245e-37
INFO: Iteration 299: cost = -1.1452447963934388e-37
INFO: Iteration 300: cost = -1.145219481790474e-37
INFO: Iteration 301: cost = -1.1451084207046305e-37
INFO: Iteration 302: cost = -1.1449411178829863e-37
INFO: Iteration 303: cost = -1.144499936558352e-37
INFO: Iteration 304: cost = -1.1447735580694004e-37
INFO: Iteration 305: cost = -1.1449568240614009e-37
INFO: Iteration 306: cost = -1.145148969696938e-37
INFO: Iteration 307: cost = -1.1453403586005765e-37
INFO: Iteration 308: cost = -1.145372198603427e-37
INFO: Iteration 309: cost = -1.1452506169165244e-37
INFO: Iteration 310: cost = -1.1451478537837732e-37
INFO: Iteration 311: cost = -1.1451499414195877e-37
INFO: Iteration 312: cost = -1.1452308582057827e-37
INFO: Iteration 313: cost = -1.1453028450574736e-37
INFO: Iteration 314: cost = -1.145291308016679e-37
INFO: Iteration 315: cost = -1.1452196318182374e-37
INFO: Iteration 316: cost = -1.145163492296482e-37
INFO: Iteration 317: cost = -1.145158650343069e-37
INFO: Iteration 318: cost = -1.1451825121695407e-37
INFO: Iteration 319: cost = -1.145179402413923e-37
INFO: Iteration 320: cost = -1.145101393734654e-37
INFO: Iteration 321: cost = -1.1448858501898393e-37
INFO: Iteration 322: cost = -1.1442414626916916e-37
INFO: Iteration 323: cost = -1.1446482284697645e-37
INFO: Iteration 324: cost = -1.1446179909528617e-37
INFO: Iteration 325: cost = -1.1442305429581999e-37
INFO: Iteration 326: cost = -1.1445300779193139e-37
INFO: Iteration 327: cost = -1.1442906920757525e-37
INFO: Iteration 328: cost = -1.1442609984523587e-37
INFO: Iteration 329: cost = -1.1443795963573573e-37
INFO: Iteration 330: cost = -1.1442529832542465e-37
INFO: Iteration 331: cost = -1.1442145658334624e-37
INFO: Iteration 332: cost = -1.144274662012669e-37
INFO: Iteration 333: cost = -1.1443533796741582e-37
INFO: Iteration 334: cost = -1.1443395529517783e-37
INFO: Iteration 335: cost = -1.1442528490245234e-37
INFO: Iteration 336: cost = -1.1442113326893008e-37
INFO: Iteration 337: cost = -1.144228160045616e-37
INFO: Iteration 338: cost = -1.144269727221046e-37
INFO: Iteration 339: cost = -1.144295690577662e-37
INFO: Iteration 340: cost = -1.1442872928808773e-37
INFO: Iteration 341: cost = -1.1442605941974213e-37
INFO: Iteration 342: cost = -1.1442436229231969e-37
INFO: Iteration 343: cost = -1.1442499464972677e-37
INFO: Iteration 344: cost = -1.1442725535293999e-37
INFO: Iteration 345: cost = -1.1442911469241802e-37
INFO: Iteration 346: cost = -1.144289671265317e-37
INFO: Iteration 347: cost = -1.1442733394192454e-37
INFO: Iteration 348: cost = -1.1442601562067257e-37
INFO: Iteration 349: cost = -1.1442602233721858e-37
INFO: Iteration 350: cost = -1.144270135825941e-37
INFO: Iteration 351: cost = -1.1442796768072177e-37
INFO: Iteration 352: cost = -1.1442813003515633e-37
INFO: Iteration 353: cost = -1.1442755812259178e-37
INFO: Iteration 354: cost = -1.1442687755682223e-37
INFO: Iteration 355: cost = -1.1442663439795536e-37
INFO: Iteration 356: cost = -1.1442690894093754e-37
INFO: Iteration 357: cost = -1.144273795852253e-37
INFO: Iteration 358: cost = -1.1442764157271409e-37
INFO: Iteration 359: cost = -1.1442752234969028e-37
INFO: Iteration 360: cost = -1.1442717473552097e-37
INFO: Iteration 361: cost = -1.1442690024316673e-37
INFO: Iteration 362: cost = -1.144268861486791e-37
INFO: Iteration 363: cost = -1.1442708132609379e-37
INFO: Iteration 364: cost = -1.144272810406916e-37
INFO: Iteration 365: cost = -1.1442731945187562e-37
INFO: Iteration 366: cost = -1.1442719766775068e-37
INFO: Iteration 367: cost = -1.1442704983012023e-37
INFO: Iteration 368: cost = -1.14427005725018e-37
INFO: Iteration 369: cost = -1.1442708604435862e-37
INFO: Iteration 370: cost = -1.1442720729183458e-37
INFO: Iteration 371: cost = -1.144272683108718e-37
INFO: Iteration 372: cost = -1.1442723359209746e-37
INFO: Iteration 373: cost = -1.1442714796327732e-37
INFO: Iteration 374: cost = -1.1442708500092255e-37
INFO: Iteration 375: cost = -1.1442708418306365e-37
INFO: Iteration 376: cost = -1.1442712807774818e-37
INFO: Iteration 377: cost = -1.1442716822034678e-37
INFO: Iteration 378: cost = -1.1442716964552999e-37
INFO: Iteration 379: cost = -1.1442713587543582e-37
INFO: Iteration 380: cost = -1.1442709852529678e-37
INFO: Iteration 381: cost = -1.1442708663076127e-37
INFO: Iteration 382: cost = -1.1442710398265188e-37
INFO: Iteration 383: cost = -1.1442713079524128e-37
INFO: Iteration 384: cost = -1.1442714368354136e-37
INFO: Iteration 385: cost = -1.1442713469512468e-37
INFO: Iteration 386: cost = -1.1442711450597377e-37
INFO: Iteration 387: cost = -1.1442710029881133e-37
INFO: Iteration 388: cost = -1.1442710094192844e-37
INFO: Iteration 389: cost = -1.1442711170198061e-37
INFO: Iteration 390: cost = -1.1442712072705075e-37
INFO: Iteration 391: cost = -1.1442711984229935e-37
INFO: Iteration 392: cost = -1.14427110300489e-37
INFO: Iteration 393: cost = -1.1442709995388152e-37
INFO: Iteration 394: cost = -1.1442709577867763e-37
INFO: Iteration 395: cost = -1.1442709855685493e-37
INFO: Iteration 396: cost = -1.1442710346270482e-37
INFO: Iteration 397: cost = -1.144271049314654e-37
INFO: Iteration 398: cost = -1.1442710115723196e-37
INFO: Iteration 399: cost = -1.14427094768299e-37
INFO: Iteration 400: cost = -1.1442708990161092e-37
INFO: Iteration 401: cost = -1.1442708867974761e-37
INFO: Iteration 402: cost = -1.1442708996679247e-37
INFO: Iteration 403: cost = -1.14427090922003e-37
INFO: Iteration 404: cost = -1.1442708957593802e-37
INFO: Iteration 405: cost = -1.1442708620429613e-37
INFO: Iteration 406: cost = -1.1442708265903987e-37
INFO: Iteration 407: cost = -1.14427080588257e-37
INFO: Iteration 408: cost = -1.1442708016512114e-37
INFO: Iteration 409: cost = -1.1442708022533197e-37
elapsed time: 81.504547474 seconds (14369878948 bytes allocated, 19.63% gc time)
Out[89]:
2x100 Array{Float64,2}:
 0.0790086    0.209798  -0.0102022  …  -0.0460909  -0.0860516   0.145683 
 0.00217198  -0.197192  -0.337029      -0.0135674  -0.293154   -0.0305904

In [90]:
@time Y2 = tsne_bfgs(X, Y, Y0)


INFO: Iteration 1: cost = -1.1248281842246866e-37
INFO: Iteration 2: cost = -1.1409852302274642e-37
INFO: Iteration 3: cost = -1.110581962064449e-37
INFO: Iteration 4: cost = -1.11800255148206e-37
INFO: Iteration 5: cost = -1.145794100130612e-37
INFO: Iteration 6: cost = -1.1446848702216755e-37
INFO: Iteration 7: cost = -1.1371102832021675e-37
INFO: Iteration 8: cost = -1.1379582603826318e-37
INFO: Iteration 9: cost = -1.143230834946396e-37
INFO: Iteration 10: cost = -1.1423311064246564e-37
INFO: Iteration 11: cost = -1.1476321803026102e-37
INFO: Iteration 12: cost = -1.1449882206711082e-37
INFO: Iteration 13: cost = -1.1471932324478668e-37
INFO: Iteration 14: cost = -1.1445976871319893e-37
INFO: Iteration 15: cost = -1.0851920554664283e-37
INFO: Iteration 16: cost = -1.0817489309008143e-37
INFO: Iteration 17: cost = -1.093603749782947e-37
INFO: Iteration 18: cost = -1.136308576474094e-37
INFO: Iteration 19: cost = -1.0933797440570725e-37
INFO: Iteration 20: cost = -1.0924300385906113e-37
INFO: Iteration 21: cost = -1.0888929450859436e-37
INFO: Iteration 22: cost = -1.0906311176866623e-37
INFO: Iteration 23: cost = -1.0966879874827661e-37
INFO: Iteration 24: cost = -1.0965149160613322e-37
INFO: Iteration 25: cost = -1.096769068588241e-37
WARNING: Maxiter reached
INFO: Iteration 26: cost = -1.0967696888500103e-37
INFO: Iteration 27: cost = -1.0967696888500103e-37
elapsed time: 16.64410318 seconds (3168868744 bytes allocated, 19.36% gc time)
Out[90]:
2x100 Array{Float64,2}:
 -8852.92  -14918.4   76523.6  -111491.0  …  -23455.8   7470.82  11023.7
 -4940.85    7457.33  55375.5   -21020.0     -41786.7  45960.7   35710.1

In [58]:
#using Gadfly
#spy(X)

In [59]:
# hstack(
# plot(x=Y1[1,:], y=Y1[2,:], color=cm),
# plot(x=Y2[1,:], y=Y2[2,:], color=cm)
# )

In [60]:
using Color
using Compose
using Gadfly
using Interact

In [61]:
@manipulate for i=1:size(X, 2)
    map(x->Color.RGB(fill(1-x/255, 3)...), reshape(sub(X, :, i), 28, 28))
end


Out[61]:

In [73]:
function simpleplot(Y2, fillcolors=fill("black", size(Y2, 2)))
    pixels = Any[]
    x₋ = Y2[1, 1]
    x₊ = Y2[1, 1]
    y₋ = Y2[2, 1]
    y₊ = Y2[2, 1]
    for i=1:size(Y2, 2)
        x = Y2[1, i]
        y = Y2[2, i]
        x₋ = min(x, x₋)
        x₊ = max(x, x₊)
        y₋ = min(y, y₋)
        y₊ = max(y, y₊)
    end
    r = 0.02*(x₊-x₋)
    for i=1:size(Y2, 2)
        x = Y2[1, i]
        y = Y2[2, i]
        push!(pixels,
            compose(context(), circle(x, y, r), fill(fillcolors[i]))
        )
    end
    compose(context(units=UnitBox(x₋-r, y₋-r, x₊-x₋+2r, y₊-y₋+2r)),
       pixels...)
end


Out[73]:
simpleplot (generic function with 2 methods)

In [88]:
using ColorBrewer
cmap = palette("Paired", 10)
ycm = map(x->cmap[x+1], digitid)
draw(SVG(800px,400px),
    hstack(simpleplot(Y1, ycm), simpleplot(Y2, ycm))
)



In [72]:
Y2


Out[72]:
2x100 Array{Float64,2}:
 -0.121941   -0.122116   -0.12341    …  -0.122962   -0.122696   -0.12481 
  0.0275557   0.0298718   0.0322706      0.0320158   0.0311131   0.029159

In [64]:
function hessian(Y, p, q)
    n = size(Y, 2)
    H = zeros(n, n)

    #Term 1
    #for i=1:n, j=1:n
    #    H[i, j] -= 4*(p[i,j]-q[i,j])*d/(1+d^2)#*(y[i]-y[j])
    #end
    #Term 2
    #for i=1:n, j=1:n
    #    H[i, j] += 4*(p[i,j]-q[i,j])*d/(1+d^2)#*(y[i]-y[j])
    #end
    #Term 3
    for i=1:n, j=1:n
        if i==j
            for k=1:n
                d = norm(slice(Y,:,i)-slice(Y,:,k))
                H[i,j] += 4*(p[i,k]-q[i,k])*d/(1+d^2)
            end
        end
        d = norm(slice(Y,:,j)-slice(Y,:,j))
        H[i,j] -= 4*(p[i,j]-q[i,j])*d/(1+d^2)
    end
    H
end


Out[64]:
hessian (generic function with 2 methods)

In [ ]: