Skip to content

Commit

Permalink
Merge pull request #134 from JuliaML/sparse
Browse files Browse the repository at this point in the history
Deprecate MarginLoss + SparseArray in favour of CategoricalArray
  • Loading branch information
juliohm committed Jun 1, 2020
2 parents a0a2fa0 + a6746ab commit 672d97b
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 99 deletions.
1 change: 0 additions & 1 deletion Project.toml
Expand Up @@ -6,7 +6,6 @@ version = "0.6.2"
LearnBase = "7f8f8fb0-2700-5f03-b4bd-41f8cfc144b6"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
Expand Down
39 changes: 14 additions & 25 deletions docs/Manifest.toml
Expand Up @@ -3,22 +3,16 @@
[[Base64]]
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

[[CategoricalArrays]]
deps = ["DataAPI", "Future", "JSON", "Missings", "Printf", "Statistics", "Unicode"]
git-tree-sha1 = "df774d7e905ca391178f0abc67f4fa5d3ff4ef12"
uuid = "324d7699-5711-5eae-9e2f-1d82baa6b597"
version = "0.8.0"

[[DataAPI]]
git-tree-sha1 = "00612b2fbe534a539dc7f70106c71e3a943d9b98"
git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
version = "1.2.0"
version = "1.3.0"

[[DataStructures]]
deps = ["InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "9faa13be79557bf4c5713fb912b0e3c5aa33d046"
git-tree-sha1 = "af6d9c86e191c917c2276fbede1137e8ea20157f"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.17.13"
version = "0.17.17"

[[Dates]]
deps = ["Printf"]
Expand All @@ -40,10 +34,6 @@ git-tree-sha1 = "d45c163c7a3ae293c15361acc52882c0f853f97c"
uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
version = "0.23.4"

[[Future]]
deps = ["Random"]
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"

[[InteractiveUtils]]
deps = ["Markdown"]
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Expand All @@ -55,9 +45,9 @@ uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
version = "0.21.0"

[[LearnBase]]
git-tree-sha1 = "a9bd0fb1b2774939400e5e604f94aa3ae070cdf1"
git-tree-sha1 = "a0d90569edd490b82fdc4dc078ea54a5a800d30a"
uuid = "7f8f8fb0-2700-5f03-b4bd-41f8cfc144b6"
version = "0.4.0"
version = "0.4.1"

[[LibGit2]]
deps = ["Printf"]
Expand All @@ -74,10 +64,10 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"

[[LossFunctions]]
deps = ["CategoricalArrays", "LearnBase", "Markdown", "RecipesBase", "SparseArrays", "StatsBase"]
deps = ["LearnBase", "Markdown", "RecipesBase", "StatsBase"]
path = ".."
uuid = "30fc2ffe-d236-52d8-8643-a9d8f7c094a7"
version = "0.6.0"
version = "0.6.2"

[[Markdown]]
deps = ["Base64"]
Expand All @@ -93,16 +83,15 @@ version = "0.4.3"
uuid = "a63ad114-7e13-5084-954f-fe012c677804"

[[OrderedCollections]]
deps = ["Random", "Serialization", "Test"]
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3"
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
version = "1.1.0"
version = "1.2.0"

[[Parsers]]
deps = ["Dates", "Test"]
git-tree-sha1 = "f8f5d2d4b4b07342e5811d2b6428e45524e241df"
git-tree-sha1 = "f0abb338b4d00306500056a3fd44c221b8473ef2"
uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0"
version = "1.0.2"
version = "1.0.4"

[[Pkg]]
deps = ["Dates", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
Expand All @@ -121,9 +110,9 @@ deps = ["Serialization"]
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[RecipesBase]]
git-tree-sha1 = "d352369b00094cadb43d694333b051b3d55abaf2"
git-tree-sha1 = "54f8ceb165a0f6d083f0d12cb4996f5367c6edbc"
uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
version = "1.0.0"
version = "1.0.1"

[[SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Expand Down
1 change: 0 additions & 1 deletion src/LossFunctions.jl
Expand Up @@ -3,7 +3,6 @@ module LossFunctions
import Base.*
using Base.Cartesian
using Markdown
using SparseArrays
using RecipesBase

import LearnBase.AggMode
Expand Down
23 changes: 0 additions & 23 deletions src/sparse.jl

This file was deleted.

8 changes: 2 additions & 6 deletions src/supervised.jl
Expand Up @@ -92,7 +92,7 @@ for FUN in (:value, :deriv, :deriv2)
loss::SupervisedLoss,
target::AbstractArray{Q,N},
output::AbstractArray{T,N},
avg::AggMode.Sum,
agg::AggMode.Sum,
obsdim::ObsDim.Constant{O}) where {Q,T,N,O}
N == 1 && throw(ArgumentError("Sum per observation non sensible for two Vectors. Try omitting the obsdim"))
O > N && throw(ArgumentError("The specified obsdim is larger as the available dimensions."))
Expand Down Expand Up @@ -131,7 +131,7 @@ for FUN in (:value, :deriv, :deriv2)
loss::SupervisedLoss,
target::AbstractArray{Q,N},
output::AbstractArray{T,N},
avg::AggMode.Mean,
agg::AggMode.Mean,
obsdim::ObsDim.Constant{O}) where {Q,T,N,O}
N == 1 && throw(ArgumentError("Mean per observation non sensible for two Vectors. Try omitting the obsdim"))
O > N && throw(ArgumentError("The specified obsdim is larger as the available dimensions."))
Expand Down Expand Up @@ -187,7 +187,3 @@ for FUN in (:value, :deriv, :deriv2)
end
end
end

# TODO: find way to use normal broadcast for this
# probably with the new changes in MLMetric and compare modes
include("sparse.jl")
1 change: 0 additions & 1 deletion test/runtests.jl
Expand Up @@ -2,7 +2,6 @@ module LossFunctionsTests

using LossFunctions
using CategoricalArrays
using SparseArrays
using DualNumbers
using Statistics
using Random
Expand Down
42 changes: 0 additions & 42 deletions test/tst_loss.jl
Expand Up @@ -487,45 +487,3 @@ end
@test value(lf, c[1], c[1]) isa Float32
@test value(lf, c, c) isa Vector{Float32}
end

# --------------------------------------------------------------

@testset "Test sparse array conventions for margin-based losses" begin
@testset "sparse vector target, vector output" begin
N = 50

# sparse vector of {0,1}
sparse_target = sprand(N,0.5)
nz = sparse_target .> 0.0
sparse_target[nz] .= 1.0
@test typeof(sparse_target) <: AbstractSparseArray

# dense vector of {-1,1}
target = [ t == 0.0 ? -1.0 : 1.0 for t in sparse_target ]

output = randn(N)

for loss in margin_losses
@test isapprox(@inferred(value(loss,sparse_target,output)), value.(Ref(loss),target,output))
end
end

@testset "sparse vector target, matrix output" begin
N = 50

# sparse vector of {0,1}
sparse_target = sprand(N,0.5)
nz = sparse_target .> 0.0
sparse_target[nz] .= 1.0
@test typeof(sparse_target) <: AbstractSparseArray

# dense vector of {-1,1}
target = [ t == 0.0 ? -1.0 : 1.0 for t in sparse_target ]

output = randn(N,N)

for loss in margin_losses
@test isapprox(@inferred(value(loss,sparse_target,output)), value.(Ref(loss),target,output))
end
end
end

0 comments on commit 672d97b

Please sign in to comment.