How to read and understand Julia documentation

1. Example:

I tried to use Optim package to implement MATLAB fminsearch I have found it in the Optim documentation and I tried to follow it:

using Optim

struct MatlabSimplexer <: Optim.Simplexer
    a::Float64
    b::Float64
end
MatlabSimplexer(;a = 0.00025, b = 0.05) = MatlabSimplexer(a, b)

function Optim.simplexer{T, N}(A::MatlabSimplexer, initial_x::Array{T, N})
    n = length(initial_x)
    initial_simplex = Array{T, N}[initial_x for i = 1:n+1]
    for j = 1:n
        initial_simplex[j+1][j] += initial_simplex[j+1][j] == zero(T) ? S.b * initial_simplex[j+1][j] : S.a
    end
    initial_simplex
end

and I got this ERROR: UndefVarError: T not defined

How to read and understand this Optim.simplexer{T, N}?
How to do it properly?

2. Example:

LIBSVM.jl package ask you to follow ?svmtrain for options, which is:

svmtrain{T, U<:Real}(X::AbstractMatrix{U}, y::AbstractVector{T}=[];
      svmtype::Type=SVC, kernel::Kernel.KERNEL=Kernel.RadialBasis, degree::Integer=3,
      gamma::Float64=1.0/size(X, 1), coef0::Float64=0.0,
      cost::Float64=1.0, nu::Float64=0.5, epsilon::Float64=0.1,
      tolerance::Float64=0.001, shrinking::Bool=true,
      probability::Bool=false, weights::Union{Dict{T, Float64}, Compat.Nothing}=nothing,
      cachesize::Float64=200.0, verbose::Bool=false)

and a lot of listed parameters, e.g.

•    svmtype::Type=LIBSVM.SVC: Type of SVM to train SVC (for C-SVM), NuSVC OneClassSVM, EpsilonSVR or NuSVR. Defaults to
    OneClassSVM if y is not used.

•    kernel::Kernels.KERNEL=Kernel.RadialBasis: Model kernel Linear, polynomial, RadialBasis, Sigmoid or Precomputed.

•    degree::Integer=3: Kernel degree. Used for polynomial kernel

•    gamma::Float64=1.0/size(X, 1) : γ for kernels

Could you please explain to me how to set svmtype and kernel? And what is svmtrain{T, U<:Real}?

I don’t know Optim, but for the error change:

function Optim.simplexer{T, N}(A::MatlabSimplexer, initial_x::Array{T, N})

to:

function Optim.simplexer(A::MatlabSimplexer, initial_x::Array{T, N}) where {T, N}

Those are very old & outdated Optim documentation pages. Recommended procedure is to go to the GitHub page (https://github.com/JuliaNLSolvers/Optim.jl) and click on the blue documentation badge.

2 Likes

Thank you for answer. I will pay more attention to documentation version:-)

1 Like