-
Notifications
You must be signed in to change notification settings - Fork 0
/
labErrors.jl
37 lines (31 loc) · 999 Bytes
/
labErrors.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using JuMP, JuMPeR, Gurobi, DataFrames, Distributions
using MLDataUtils
function solveLab(c, df, rho)
model = Model(solver=GurobiSolver(OutputFlag=0))
n = size(df,1)
y = df[:,16]
x = df[:,1:15]
p = size(x,2)
@variable(model, b)
@variable(model, w[1:p])
@variable(model, xsi[1:n] >= 0)
srand(1)
r = rand(1,n)
for i in 1:n
x_ = convert(Array, x[i,:])[1,:]
@constraint(model, y[i]*(sum(w .* x_) - b) - rho*norm(w,2) >= 1 - xsi[i])
end
@objective(model, Min, sum(c.*xsi))
solve(model)
b = getvalue(b)
w = getvalue(w)
objective = getobjectivevalue(model)
@show objective
return b, w, objective
end
function runLabModel(ctrain, train, test, measures, rho)
b, w, objective = solveLab(cTrain, train, rho)
measures = evaluate(w, b, train, "train", measures, "labErrors_$rho",rho, objective)
measures = evaluate(w, b, test, "test", measures, "labErrors_$rho",rho, objective)
return measures
end