Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing fields to Parameter #29

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/LIBLINEAR.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ struct Parameter
weight_label :: Ptr{Cint}
weight :: Ptr{Float64}
p :: Float64
nu :: Float64
init_sol :: Ptr{Float64} # Initial-solution specification supported only for solver L2R_LR and L2R_L2LOSS_SVC
regularize_bias :: Cint
end

struct Model
Expand Down Expand Up @@ -210,9 +212,12 @@ function linear_train(
(idx, reverse_labels, weights, weight_labels) =
indices_and_weights(labels, instances, weights)

param = Array{Parameter}(undef, 1)
param[1] = Parameter(solver_type, eps, C, Cint(length(weights)),
pointer(weight_labels), pointer(weights), p, init_sol)
# TODO: add these as function arguments
nu = 0.5
regularize_bias = 1
param = Parameter(solver_type, eps, C, Cint(length(weights)),
pointer(weight_labels), pointer(weights), p, nu,
C_NULL, regularize_bias)

# construct problem
(nodes, nodeptrs) = instances2nodes(instances)
Expand All @@ -221,14 +226,14 @@ function linear_train(
Cint(size(instances, 1)), pointer(idx), pointer(nodeptrs), bias)]

chk = ccall((:check_parameter, liblinear), Ptr{UInt8},
(Ptr{Problem}, Ptr{Parameter}),
(Ref{Problem}, Ref{Parameter}),
problem, param)

chk != convert(Ptr{UInt8}, C_NULL) &&
error("Please check your parameters: $(unsafe_string(chk))")

ptr = ccall((:train, liblinear), Ptr{Model},
(Ptr{Problem}, Ptr{Parameter}),
(Ref{Problem}, Ref{Parameter}),
problem, param)
m = unsafe_wrap(Array, ptr, 1)[1]

Expand Down