Skip to content
This repository was archived by the owner on May 23, 2022. It is now read-only.

New new interface #53

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 4 additions & 8 deletions src/LearnBase.jl
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
module LearnBase

import StatsBase
using StatsBase: nobs
import StatsBase: nobs

# AGGREGATION MODES
include("aggmode.jl")

# VIEW AND ITERATORS
include("iteration.jl")

# OBSERVATION DIMENSIONS
include("observation.jl")

# LABEL ENCONDINGS
include("labels.jl")

# LEARNING COSTS (e.g. loss & penalty)
include("costs.jl")

# LABELS
include("labels.jl")

# OTHER CONCEPTS
include("other.jl")

Expand Down
82 changes: 0 additions & 82 deletions src/iteration.jl

This file was deleted.

154 changes: 93 additions & 61 deletions src/labels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function neglabel end
"""
labelenc(obj) -> LabelEncoding

Tries to determine the most approriate label-encoding to describe the
Tries to determine the most approriate label-encoding to describe the
given object `obj` based on the result of `label(obj)`. Note that in
most cases this function is not typestable.

Expand Down Expand Up @@ -127,31 +127,42 @@ function classify! end

"""
convertlabel(new_encoding, x, [old_encoding])

Converts the given value/array `x` from the `old_encoding` into the
`new_encoding`. Note that if `old_encoding` is not specified it will
be derived automaticaly using `labelenc`.
julia> convertlabel(LabelEnc.MarginBased, [0, 1, 1, 0, 0])
5-element Array{Int64,1}:
-1
1
1
-1
-1
julia> convertlabel([:yes,:no], [0, 1, 1, 0, 0])
5-element Array{Symbol,1}:
:no
:yes
:yes
:no
:no

```juliarepl
julia> convertlabel(LabelEnc.MarginBased, [0, 1, 1, 0, 0])
5-element Array{Int64,1}:
-1
1
1
-1
-1

julia> convertlabel([:yes,:no], [0, 1, 1, 0, 0])
5-element Array{Symbol,1}:
:no
:yes
:yes
:no
:no
```

For more information on the available encodings, see `?LabelEnc`.

convertlabel(new_encoding, x, [old_encoding], [obsdim])

When working with `OneOfK` one can additionally specifify which
dimension of the array denotes the observations using `obsdim`
julia> convertlabel(LabelEnc.OneOfK, [0, 1, 1, 0, 0], obsdim = 2)
2×5 Array{Int64,2}:
0 1 1 0 0
1 0 0 1 1

```juliarepl
julia> convertlabel(LabelEnc.OneOfK, [0, 1, 1, 0, 0], obsdim = 2)
2×5 Array{Int64,2}:
0 1 1 0 0
1 0 0 1 1
```
"""
function convertlabel end
function convertlabel! end
Expand All @@ -162,6 +173,7 @@ function convertlabel! end
Creates a lazy view into `vec` that makes it look like it is
in the encoding specified by `new_encoding`, while it is actually
preserved as being of `old_encoding`.

This method only works for label-encodings that are vector-based
(i.e. pretty much all but `OneOfK`). The resulting MappedArray
will be writeable unless `old_encoding` is of type `OneVsRest`,
Expand All @@ -174,10 +186,13 @@ function convertlabelview end

Computes a mapping from the labels in `obj` to all the individual
element-indices in `obj` that correspond to that label
julia> labelmap([0, 1, 1, 0, 0])
Dict{Int64,Array{Int64,1}} with 2 entries:
0 => [1,4,5]
1 => [2,3]

```juliarepl
julia> labelmap([0, 1, 1, 0, 0])
Dict{Int64,Array{Int64,1}} with 2 entries:
0 => [1,4,5]
1 => [2,3]
```
"""
function labelmap end

Expand All @@ -186,29 +201,37 @@ function labelmap end

Updates the given label-map `dict` with the new element `elem`,
which is assumed to be associated with the index `idx`.
julia> lm = labelmap([0, 1, 1, 0, 0])
Dict{Int64,Array{Int64,1}} with 2 entries:
0 => [1,4,5]
1 => [2,3]
julia> labelmap!(lm, 6, 0)
Dict{Int64,Array{Int64,1}} with 2 entries:
0 => [1,4,5,6]
1 => [2,3]
julia> labelmap!(lm, 7:8, [1,0])
Dict{Int64,Array{Int64,1}} with 2 entries:
0 => [1,4,5,6,8]
1 => [2,3,7]

```juliarepl
julia> lm = labelmap([0, 1, 1, 0, 0])
Dict{Int64,Array{Int64,1}} with 2 entries:
0 => [1,4,5]
1 => [2,3]

julia> labelmap!(lm, 6, 0)
Dict{Int64,Array{Int64,1}} with 2 entries:
0 => [1,4,5,6]
1 => [2,3]

julia> labelmap!(lm, 7:8, [1,0])
Dict{Int64,Array{Int64,1}} with 2 entries:
0 => [1,4,5,6,8]
1 => [2,3,7]
```
"""
function labelmap! end

"""
labelfreq(obj) -> Dict

Computes the absolute frequencies for each label in `obj`.
julia> labelfreq([0, 1, 1, 0, 0])
Dict{Int64,Int64} with 2 entries:
0 => 3
1 => 2

```juliarepl
julia> labelfreq([0, 1, 1, 0, 0])
Dict{Int64,Int64} with 2 entries:
0 => 3
1 => 2
```
"""
function labelfreq end

Expand All @@ -217,14 +240,18 @@ function labelfreq end

Updates the given label-frequency-map `dict` with the absolute
frequencies for each label in `obj`
julia> ld = labelfreq([0, 1, 1, 0, 0])
Dict{Int64,Int64} with 2 entries:
0 => 3
1 => 2
julia> labelfreq!(ld, [1,0,0])
Dict{Int64,Int64} with 2 entries:
0 => 5
1 => 3

```juliarepl
julia> ld = labelfreq([0, 1, 1, 0, 0])
Dict{Int64,Int64} with 2 entries:
0 => 3
1 => 2

julia> labelfreq!(ld, [1,0,0])
Dict{Int64,Int64} with 2 entries:
0 => 5
1 => 3
```
"""
function labelfreq! end

Expand All @@ -234,17 +261,22 @@ function labelfreq! end
Inverse function of labelmap.
Computes an `array` of labels by element-wise
traversal of the entries in `dict`.
julia> labelvec = [:yes,:no,:no,:yes,:yes]
julia> lm = labelmap(labelvec)
Dict{Symbol,Array{Int64,1}} with 2 entries:
:yes => [1, 4, 5]
:no => [2, 3]
julia> labelmap2vec(lm)
5-element Array{Symbol,1}:
:yes
:no
:no
:yes
:yes
"""
function labelmap2vec end

```juliarepl
julia> labelvec = [:yes,:no,:no,:yes,:yes]

julia> lm = labelmap(labelvec)
Dict{Symbol,Array{Int64,1}} with 2 entries:
:yes => [1, 4, 5]
:no => [2, 3]

julia> labelmap2vec(lm)
5-element Array{Symbol,1}:
:yes
:no
:no
:yes
:yes
```
"""
function labelmap2vec end
Loading