Better repost this to julia-opt list.  Mauro

On Mon, 2016-06-13 at 04:27, JC <iky...@gmail.com> wrote:
> I have been trying to use JuMP for an optimization problem and ran into
> many issues.
>
> 1. I made my own function called myf and try to register that so that I can
> read it into my objective function but am getting error message saying
> "Unrecognized function :myf used in nonlinear expression".
>
> 2. my input is a vector and I am having hard time reading vector into the
> objective function.
>
> My code is below where x1 and y1 is 3 by 50 matrix and alpha beta are
> projection matrix :
>
> ---------
> using JuMP
> m = Model(solver=NLoptSolver(algorithm=:SLSQP))
>
> #- define variables
> @variable(m, alpha)
> @variable(m, beta)
>
> function myf(x,y,a,b)
>   # apply projection
>   w1 = a * x
>   w2 = b * x
>   z1 = a * y
>   z2 = b * y
>
>   # calculate covariance matrix
>   S1 = [var(w1) cov(w1',w2'); cov(w2',w1') var(w2)]
>   S2 = [var(z1) cov(z1',z2'); cov(z2',z1') var(z2)]
>   S0 = ((nperdimension-1)*S1 + (nperdimension-1)*S2)/(ntotal-2)
>
>   S1d = abs(S1[1,1]*S1[2,2] - S1[1,2]*S1[2,1])
>   S2d = abs(S2[1,1]*S2[2,2] - S2[1,2]*S1[2,1])
>   S0d = abs(S0[1,1]*S0[2,2] - S0[1,2]*S0[2,1])
>
>   test = - log(S1d) - log(S2d) + log(S0d)
>
>   return test
> end
>
> JuMP.register(:myf, 1, myf, autodiff = true)
>
> @NLobjective(m, Max, myf(x1,y1,alpha,beta))
>
> setvalue(alpha, [1 0 0])
> setvalue(beta, [0 0 1])
>
> status = solve(m)
> -----------
>
> My objective is to start with two projection vector [1 0 0] and [0 0 1] and
> find the projection vector that gives max of test values.
> Can someone please help me to get this working?
> Thank you.

Reply via email to