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

[#23] - Feature/methods describer #31

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 5 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
83 changes: 83 additions & 0 deletions src/descriptor.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
mutable struct MethodDescriber
name::String
n_features::Union{Symbol, Int, Nothing}
Conradox marked this conversation as resolved.
Show resolved Hide resolved
n_samples::Union{Symbol, Int, Nothing}
problem_type::Union{Symbol, Nothing}

MethodDescriber() = new()

end

function MethodDescriber( method_name::String;
n_features = nothing,
n_samples = nothing,
problem_type = nothing)

method = MethodDescriber()

method.name = method_name
method.n_features = n_features
method.n_samples = n_samples
method.problem_type = problem_type

return method
end

function Base.show(io::IO, method::MethodDescriber)
println("# $(method.name)")
Conradox marked this conversation as resolved.
Show resolved Hide resolved
method.n_features !== nothing && println("number of features: " * string(method.n_features))
method.n_samples !== nothing && println("amount of samples: " * string(method.n_samples))
method.problem_type !== nothing && println("problem type: " * string(method.problem_type))
end

mutable struct MethodDescriberSet
describers::Array{MethodDescriber, 1}
end

MethodDescriberSet(args...) = MethodDescriberSet([args...])

function methodsFilter(methods::MethodDescriberSet, parameters::Union{Pair, Array{Pair}})
if !(parameters isa Array)
parameters = [parameters]
end

filtered_methods = Set()

for parameter in parameters
if !(parameter[1] in fieldnames(MethodDescriber))
filipebraida marked this conversation as resolved.
Show resolved Hide resolved
@warn "$(parameter[1]) isn't a property of MethodDescriber"
continue
end
for method in methods.describers
property = getfield(method, parameter[1])
if property == parameter[2]
push!(filtered_methods, method)
end
end
end

return MethodDescriberSet(collect(filtered_methods))
end

methodsFilter(parameters::Union{Pair, Array{Pair}}) = methodsFilter(METHODS, parameters)
Conradox marked this conversation as resolved.
Show resolved Hide resolved

function Base.show(io::IO, methods::MethodDescriberSet)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eu percebi que está imprimindo com vários \n no final.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isso deve ser por causa dos println. Mas fiz isso pra separar em linhas distintas as características.

for method in methods.describers
println(method)
end
end

const METHODS = MethodDescriberSet(
MethodDescriber(
"Generate_blobs",
n_features = :Dynamic,
n_samples = :Dynamic,
problem_type = :Classification),
MethodDescriber(
"Generate_s_curve",
n_features = 2,
n_samples = :Dynamic,
problem_type = :Regression),
)

methods() = println(METHODS)
Conradox marked this conversation as resolved.
Show resolved Hide resolved