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

Reorganize codebase #130

Merged
merged 25 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
19 changes: 8 additions & 11 deletions src/LossFunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,20 @@ export
ZeroOneLoss,

OrdinalMarginLoss,
OrdinalHingeLoss,

weightedloss,

AggMode

# for maintainers
include("devutils.jl")
include("aggregatemode.jl")

include("supervised/supervised.jl")
include("supervised/sparse.jl")
include("supervised/distance.jl")
include("supervised/margin.jl")
include("supervised/scaledloss.jl")
include("supervised/weightedbinary.jl")
include("supervised/other.jl")
include("supervised/ordinal.jl")
include("supervised/io.jl")
# loss and aggregation
include("aggmode.jl")
include("supervised.jl")

# IO functionality
include("printing.jl")
include("plotrecipes.jl")

end # module
File renamed without changes.
11 changes: 11 additions & 0 deletions src/plotrecipes.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
_loss_xguide(loss::MarginLoss) = "y * h(x)"
_loss_xguide(loss::DistanceLoss) = "h(x) - y"
_loss_yguide(loss::SupervisedLoss) = "L("*_loss_xguide(loss)*")"

@recipe function plot(loss::SupervisedLoss, range=-2:0.05:2; fun=value)
xguide --> _loss_xguide(loss)
yguide --> _loss_yguide(loss)
label --> string(loss)
l(a) = fun(loss, a)
l, range
end
18 changes: 0 additions & 18 deletions src/supervised/io.jl → src/printing.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Base.print(io::IO, loss::SupervisedLoss, args...) = print(io, typeof(loss).name.name, args...)
Base.print(io::IO, loss::L1DistLoss, args...) = print(io, "L1DistLoss", args...)
Base.print(io::IO, loss::L2DistLoss, args...) = print(io, "L2DistLoss", args...)
Expand All @@ -12,7 +11,6 @@ Base.print(io::IO, loss::DWDMarginLoss, args...) = print(io, typeof(loss).name.n
Base.print(io::IO, loss::PeriodicLoss, args...) = print(io, typeof(loss).name.name, " with c = $(round(2π / loss.k, digits=1))", args...)
Base.print(io::IO, loss::ScaledLoss{T,K}, args...) where {T,K} = print(io, "$(K) * ($(loss.loss))", args...)

# Pretty print weighted loss
_round(num) = round(num) == round(num, digits=1) ? round(Int, num) : round(num, digits=1)
function _relation(num)
if num <= 0
Expand All @@ -25,20 +23,4 @@ function _relation(num)
"$(_round(num/(1-num))):1 weighted"
end
end

Base.print(io::IO, loss::WeightedBinaryLoss{T,W}, args...) where {T,W} = print(io, "$(_relation(W)) $(loss.loss)", args...)

# -------------------------------------------------------------
# Plot Recipes

_loss_xguide(loss::MarginLoss) = "y * h(x)"
_loss_xguide(loss::DistanceLoss) = "h(x) - y"
_loss_yguide(loss::SupervisedLoss) = "L("*_loss_xguide(loss)*")"

@recipe function plot(loss::SupervisedLoss, range=-2:0.05:2; fun=value)
xguide --> _loss_xguide(loss)
yguide --> _loss_yguide(loss)
label --> string(loss)
l(a) = fun(loss, a)
l, range
end
11 changes: 11 additions & 0 deletions src/supervised/supervised.jl → src/supervised.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1467,3 +1467,14 @@ true
issymmetric(::SupervisedLoss) = false

isminimizable(l::SupervisedLoss) = isconvex(l)

# -----------------
# IMPLEMENTATIONS
# -----------------
include("supervised/sparse.jl")
include("supervised/distance.jl")
include("supervised/margin.jl")
include("supervised/scaled.jl")
include("supervised/weightedbinary.jl")
include("supervised/other.jl")
include("supervised/ordinal.jl")
6 changes: 0 additions & 6 deletions src/supervised/margin.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
# Note: agreement = output * target
# Agreement is high when output and target are the same sign and |output| is large.
# It is an indication that the output represents the correct class in a margin-based model.

# ============================================================

@doc doc"""
ZeroOneLoss <: MarginLoss

Expand Down
3 changes: 0 additions & 3 deletions src/supervised/ordinal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,3 @@ for fun in (:isdifferentiable, :istwicedifferentiable)
return true
end
end

const OrdinalHingeLoss = OrdinalMarginLoss{HingeLoss}
# const OrdinalSmoothedHingeLoss = OrdinalMarginLoss{<:SmoothedL1HingeLoss}
File renamed without changes.
2 changes: 0 additions & 2 deletions test/tst_loss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ end
@test L2DistLoss === LPDistLoss{2}
@test HingeLoss === L1HingeLoss
@test EpsilonInsLoss === L1EpsilonInsLoss
@test OrdinalHingeLoss === OrdinalMarginLoss{HingeLoss}
end

@testset "Test typestable supervised loss for type stability" begin
Expand Down Expand Up @@ -430,7 +429,6 @@ const OrdinalSmoothedHingeLoss = OrdinalMarginLoss{<:SmoothedL1HingeLoss}
val
end
y = rand(1:5, 10); t = randn(10) .+ 3
@test OrdinalHingeLoss(5) === OrdinalMarginLoss(HingeLoss(), 5)
test_value(OrdinalMarginLoss(HingeLoss(), 5), _ordinalhingeloss, y, t)
end

Expand Down