-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f09d9ee
commit 6838d29
Showing
8 changed files
with
91 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
# ---------------------------------------------------------------------------- # | ||
# fisher filter # | ||
# ---------------------------------------------------------------------------- # | ||
struct FisherScoreFilter{T <: AbstractLimiter} <: AbstractFisherScore{T} | ||
limiter::T | ||
# parameters | ||
end | ||
|
||
# ======================================================================================== | ||
# TRAITS | ||
|
||
is_supervised(::AbstractFisherScore) = true | ||
|
||
# ======================================================================================== | ||
# SCORE | ||
is_unsupervised(::AbstractFisherScore) = false | ||
|
||
function score( | ||
X::AbstractDataFrame, | ||
X::AbstractMatrix, | ||
y::AbstractVector{<:Class}, | ||
selector::FisherScoreFilter | ||
)::Vector{Float64} | ||
lmy = labelmap(y) | ||
ey = labelencode(lmy, y) | ||
scores = fisher_score.fisher_score(Matrix(X), ey) | ||
scores = fisher_score.fisher_score(X, ey) | ||
return scores | ||
end | ||
score(Xdf::AbstractDataFrame, y::AbstractVector{<:Class}, selector::FisherScoreFilter) = score(Matrix(Xdf), y, selector) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,31 @@ | ||
# ---------------------------------------------------------------------------- # | ||
# pearson filter # | ||
# ---------------------------------------------------------------------------- # | ||
struct PearsonCorFilter{T <: AbstractLimiter} <: AbstractPearsonCorFilter{T} | ||
limiter::T | ||
# parameters | ||
# TODO parameters | ||
end | ||
|
||
# ======================================================================================== | ||
# TRAITS | ||
|
||
is_supervised(::AbstractPearsonCorFilter) = true | ||
|
||
# ======================================================================================== | ||
# SCORE | ||
is_unsupervised(::AbstractPearsonCorFilter) = false | ||
|
||
function score( | ||
X::AbstractDataFrame, | ||
X::AbstractMatrix, | ||
y::AbstractVector{<:Class}, | ||
selector::PearsonCorFilter | ||
)::Vector{Float64} | ||
coltypes = eltype.(eachcol(X)) | ||
uncalcidxes = findall(==(false), coltypes .<: Real) | ||
if (!isempty(uncalcidxes)) | ||
throw(DomainError("Columns must be subtype of Real.\n | ||
The following column indices are not handable: $(uncalcidxes)")) | ||
The following column indices are not handable: $(uncalcidxes)")) | ||
end | ||
scores = cor.(eachcol(X), [y]) | ||
return scores | ||
end | ||
score(Xdf::AbstractDataFrame, y::AbstractVector{<:Class}, selector::PearsonCorFilter)::Vector{Float64} = score(Matrix(Xdf), y, selector) | ||
|
||
# ======================================================================================== | ||
# CUSTOM CONSTRUCTORS | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# custom constructors # | ||
# ---------------------------------------------------------------------------- # | ||
PearsonCorRanking(nbest) = PearsonCorFilter(RankingLimiter(nbest, false)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,26 @@ | ||
# ---------------------------------------------------------------------------- # | ||
# random filter # | ||
# ---------------------------------------------------------------------------- # | ||
struct RandomFilter{T<:AbstractLimiter} <: AbstractRandomFilter{T} | ||
limiter::T | ||
# parameters | ||
seed::Union{Int,Nothing} | ||
end | ||
|
||
# ======================================================================================== | ||
# ACCESSORS | ||
|
||
seed(selector::RandomFilter) = selector.seed | ||
|
||
# ======================================================================================== | ||
# TRAITS | ||
|
||
is_supervised(::AbstractRandomFilter) = false | ||
is_unsupervised(::AbstractRandomFilter) = true | ||
|
||
# ======================================================================================== | ||
# SCORE | ||
|
||
function score( | ||
X::AbstractDataFrame, | ||
selector::RandomFilter | ||
)::Vector{<:Real} | ||
function score(X::AbstractMatrix, selector::RandomFilter)::Vector{Float64} | ||
s = seed(selector) | ||
rng = isnothing(s) ? MersenneTwister() : MersenneTwister(s) | ||
return rand(rng, ncol(X)) | ||
return rand(rng, size(X, 2)) | ||
end | ||
score(Xdf::AbstractDataFrame, selector::RandomFilter)::Vector{Float64} = score(Matrix(Xdf), selector) | ||
|
||
# ======================================================================================== | ||
# CUSTOM CONSTRUCTORS | ||
|
||
# ---------------------------------------------------------------------------- # | ||
# custom constructors # | ||
# ---------------------------------------------------------------------------- # | ||
RandomRanking(nbest::Integer, seed::Integer) = RandomFilter(RankingLimiter(nbest), seed) | ||
RandomRanking(nbest::Integer) = RandomFilter(RankingLimiter(nbest), nothing) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters