2
我正在第一次嘗試Julia中的JuMP.jl,似乎無法解決錯誤。這是我的設置。JuMP.jl中的Cox比例危險
使用DataFrames,DataFramesMeta,跳躍,Ipopt
#time to event
times = [143,164,188,189,190,192,206,209,213,216,220,227,230,234,246,265,304,216,244,
142,156,163,198,205,232,232,233,233,233,233,239,240,261,280,280,296,296,232,204,344];
#make censored data
is_censored = zeros(Int32, 40);
is_censored[18]=1
is_censored[19]=1
is_censored[39]=1
is_censored[40]=1
#treatment vs control
x1=ones(Int32,19)
x2=zeros(Int32,21)
x=append!(x1,x2)
#build DataFrame
using DataFrames
df = DataFrame();
df[:times]=times;
df[:is_censored]= is_censored;
df[:x]=x;
df
#sort df
df_sorted = sort!(df, cols = [order(:times)])
#make df_risk and df_uncensored
df_uncensored = @where(df_sorted, :is_censored .== 0)
df_risk = df_sorted
#cox partial likelihood
#use JuMP
##convert df to array
uncensored = convert(Array,df_uncensored[:x])
risk_set = convert(Array,df_risk[:x])
m = Model(solver=IpoptSolver(print_level=0))
@variable(m, β, start = 0.0)
@NLobjective(m, Max, sum(uncensored[i]*β-log*sum(exp(risk_set[j]*β) for j=1:length(risk_set)) for i=1:length(uncensored)))
最後一行就是我所有的問題都
@NLobjective(m, Max, sum(uncensored[i]*β-log*sum(exp(risk_set[j]*β) for j=1:length(risk_set)) for i=1:length(uncensored)))
我得到的錯誤
ERROR: MethodError: no method matching parseNLExpr_runtime(::JuMP.Model, ::Base.#log, ::Array{ReverseDiffSparse.NodeData,1}, ::Int64, ::Array{Float64,1})
Closest candidates are:
parseNLExpr_runtime(::JuMP.Model, ::Number, ::Any, ::Any, ::Any) at /home/icarus/.julia/v0.6/JuMP/src/parsenlp.jl:196
parseNLExpr_runtime(::JuMP.Model, ::JuMP.Variable, ::Any, ::Any, ::Any) at /home/icarus/.julia/v0.6/JuMP/src/parsenlp.jl:202
parseNLExpr_runtime(::JuMP.Model, ::JuMP.NonlinearExpression, ::Any, ::Any, ::Any) at /home/icarus/.julia/v0.6/JuMP/src/parsenlp.jl:208
...
Stacktrace:
[1] macro expansion at /home/icarus/.julia/v0.6/JuMP/src/parseExpr_staged.jl:489 [inlined]
[2] macro expansion at /home/icarus/.julia/v0.6/JuMP/src/parsenlp.jl:226 [inlined]
[3] macro expansion at /home/icarus/.julia/v0.6/JuMP/src/macros.jl:1086 [inlined]
[4] anonymous at ./<missing>:?
例子我有一直試圖使用maximum likelihood example和optimal control
大包! JuMP非常強大!我打算繼續使用它。 – Alex