Skip to content

Commit 059a6b4

Browse files
committed
get rid of InteractiveUtils dep
1 parent 28ac859 commit 059a6b4

File tree

7 files changed

+89
-66
lines changed

7 files changed

+89
-66
lines changed

Project.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@ uuid = "92ad9a40-7767-427a-9ee6-6e577f1266cb"
33
authors = ["Anthony D. Blaom <[email protected]>"]
44
version = "0.1.0"
55

6-
[deps]
7-
InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
8-
96
[compat]
107
julia = "1.6"
118

docs/src/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ functionality, such as external performance estimates, hyperparameter optimizati
1717
model composition, provided by ML/statistics toolboxes and other packages. LearnAPI.jl
1818
includes a number of Julia [traits](@ref traits) for promising specific behavior.
1919

20-
LearnAPI.jl's only dependency is the standard library `InteractiveUtils`.
20+
LearnAPI.jl's has no package dependencies.
2121

2222
```@raw html
2323
&#128679;

src/LearnAPI.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module LearnAPI
22

3-
import InteractiveUtils.subtypes
4-
53
include("tools.jl")
64
include("types.jl")
75
include("predict_transform.jl")
@@ -16,7 +14,7 @@ export @trait
1614
export fit, update, update_observations, update_features
1715
export predict, transform, inverse_transform, obs
1816

19-
for name in Symbol.(CONCRETE_TARGET_PROXY_TYPES_SYMBOLS)
17+
for name in CONCRETE_TARGET_PROXY_SYMBOLS
2018
@eval export $name
2119
end
2220

src/predict_transform.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ DOC_DATA_INTERFACE(method) =
4545
case then an implementation must either: (i) overload [`obs`](@ref) to articulate how
4646
provided data can be transformed into a form that does support
4747
[`LearnAPI.RandomAccess`](@ref); or (ii) overload the trait
48-
[`LearnAPI.data_interface`](@ref) to specify a more relaxed data API. Refer to
48+
[`LearnAPI.data_interface`](@ref) to specify a more relaxed data API. Refer tbo
4949
document strings for details.
5050
5151
"""
@@ -91,8 +91,10 @@ If there is no notion of a "target" variable in the LearnAPI.jl sense, or you ne
9191
operation with an inverse, implement [`transform`](@ref) instead.
9292
9393
Implementation is optional. Only the first signature (with or without the `data` argument)
94-
is implemented, but each `kind_of_proxy` that gets an implementation must be added to the
95-
list returned by [`LearnAPI.kinds_of_proxy`](@ref).
94+
is implemented, but each `kind_of_proxy::`[`KindOfProxy`](@ref) that gets an
95+
implementation must be added to the list returned by
96+
[`LearnAPI.kinds_of_proxy(learner)`](@ref). List all available kinds of proxy by doing
97+
`LearnAPI.kinds_of_proxy()`.
9698
9799
If `data` is not present in the implemented signature (eg., for density estimators) then
98100
[`LearnAPI.features(learner, data)`](@ref) must return `nothing`.

src/traits.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,8 @@ See also [`LearnAPI.predict`](@ref), [`LearnAPI.KindOfProxy`](@ref).
135135
136136
Must be overloaded whenever `predict` is implemented.
137137
138-
Elements of the returned tuple must be instances of types in the return value of
139-
`LearnAPI.kinds_of_proxy()`, i.e., one of the following, described further in LearnAPI.jl
140-
documentation: $CONCRETE_TARGET_PROXY_TYPES_LIST.
138+
Elements of the returned tuple must be instances of [`LearnAPI.KindOfProxy`](@ref). List
139+
all possibilities by running `LearnAPI.kinds_of_proxy()`.
141140
142141
Suppose, for example, we have the following implementation of a supervised learner
143142
returning only probabilistic predictions:
@@ -158,7 +157,12 @@ For more on target variables and target proxies, refer to the LearnAPI documenta
158157
159158
"""
160159
kinds_of_proxy(::Any) = ()
161-
kinds_of_proxy() = CONCRETE_TARGET_PROXY_TYPES
160+
kinds_of_proxy() = map(CONCRETE_TARGET_PROXY_SYMBOLS) do ex
161+
quote
162+
$ex()
163+
end |> eval
164+
end
165+
162166

163167

164168
tags() = [

src/types.jl

Lines changed: 73 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -53,27 +53,35 @@ expectiles at 50% will provide `Point` instead.
5353
"""
5454
abstract type IID <: KindOfProxy end
5555

56-
struct Point <: IID end
57-
struct Sampleable <: IID end
58-
struct Distribution <: IID end
59-
struct LogDistribution <: IID end
60-
struct Probability <: IID end
61-
struct LogProbability <: IID end
62-
struct Parametric <: IID end
63-
struct LabelAmbiguous <: IID end
64-
struct LabelAmbiguousSampleable <: IID end
65-
struct LabelAmbiguousDistribution <: IID end
66-
struct LabelAmbiguousFuzzy <: IID end
67-
struct ConfidenceInterval <: IID end
68-
struct Fuzzy <: IID end
69-
struct ProbabilisticFuzzy <: IID end
70-
struct SurvivalFunction <: IID end
71-
struct SurvivalDistribution <: IID end
72-
struct HazardFunction <: IID end
73-
struct OutlierScore <: IID end
74-
struct Continuous <: IID end
75-
struct Quantile <: IID end
76-
struct Expectile <: IID end
56+
const IID_SYMBOLS = [
57+
:Point,
58+
:Sampleable,
59+
:Distribution,
60+
:LogDistribution,
61+
:Probability,
62+
:LogProbability,
63+
:Parametric,
64+
:LabelAmbiguous,
65+
:LabelAmbiguousSampleable,
66+
:LabelAmbiguousDistribution,
67+
:LabelAmbiguousFuzzy,
68+
:ConfidenceInterval,
69+
:Fuzzy,
70+
:ProbabilisticFuzzy,
71+
:SurvivalFunction,
72+
:SurvivalDistribution,
73+
:HazardFunction,
74+
:OutlierScore,
75+
:Continuous,
76+
:Quantile,
77+
:Expectile,
78+
]
79+
80+
for S in IID_SYMBOLS
81+
quote
82+
struct $S <: IID end
83+
end |> eval
84+
end
7785

7886

7987
"""
@@ -92,9 +100,18 @@ space ``Y^n``, where ``Y`` is the space from which the target variable takes its
92100
93101
"""
94102
abstract type Joint <: KindOfProxy end
95-
struct JointSampleable <: Joint end
96-
struct JointDistribution <: Joint end
97-
struct JointLogDistribution <: Joint end
103+
104+
const JOINT_SYMBOLS = [
105+
:JointSampleable,
106+
:JointDistribution,
107+
:JointLogDistribution,
108+
]
109+
110+
for S in JOINT_SYMBOLS
111+
quote
112+
struct $S <: Joint end
113+
end |> eval
114+
end
98115

99116
"""
100117
Single <: KindOfProxy
@@ -114,32 +131,24 @@ single object representing a probability distribution.
114131
115132
"""
116133
abstract type Single <: KindOfProxy end
117-
struct SingleSampeable <: Single end
118-
struct SingleDistribution <: Single end
119-
struct SingleLogDistribution <: Single end
120-
121-
const CONCRETE_TARGET_PROXY_TYPES = [
122-
subtypes(IID)...,
123-
subtypes(Single)...,
124-
subtypes(Joint)...,
134+
135+
const SINGLE_SYMBOLS = [
136+
:SingleSampeable,
137+
:SingleDistribution,
138+
:SingleLogDistribution,
125139
]
126140

127-
const CONCRETE_TARGET_PROXY_TYPES_SYMBOLS = map(CONCRETE_TARGET_PROXY_TYPES) do T
128-
Symbol(last(split(string(T), '.')))
141+
for S in SINGLE_SYMBOLS
142+
quote
143+
struct $S <: Single end
144+
end |> eval
129145
end
130146

131-
const CONCRETE_TARGET_PROXY_TYPES_LIST = join(
132-
map(CONCRETE_TARGET_PROXY_TYPES_SYMBOLS) do s
133-
"`$s()`"
134-
end,
135-
", ",
136-
" and ",
137-
)
138-
139-
const DOC_HOW_TO_LIST_PROXIES =
140-
"The instances of [`LearnAPI.KindOfProxy`](@ref) are: "*
141-
"$(LearnAPI.CONCRETE_TARGET_PROXY_TYPES_LIST). "
142-
147+
const CONCRETE_TARGET_PROXY_SYMBOLS = [
148+
IID_SYMBOLS...,
149+
SINGLE_SYMBOLS...,
150+
JOINT_SYMBOLS...,
151+
]
143152

144153
"""
145154
@@ -151,12 +160,25 @@ the form of target predictions in [`predict`](@ref) calls.
151160
152161
See LearnAPI.jl documentation for an explanation of "targets" and "target proxies".
153162
154-
For example, `Distribution` is a concrete subtype of `LearnAPI.KindOfProxy` and a call
155-
like `predict(model, Distribution(), Xnew)` returns a data object whose observations are
156-
probability density/mass functions, assuming `learner` supports predictions of that
157-
form.
163+
For example, `Distribution` is a concrete subtype of `IID <: LearnAPI.KindOfProxy` and a
164+
call like `predict(model, Distribution(), Xnew)` returns a data object whose observations
165+
are probability density/mass functions, assuming `learner = LearnAPI.learner(model)`
166+
supports predictions of that form, which is true if `Distribution() in`
167+
[`LearnAPI.kinds_of_proxy(learner)`](@ref).
168+
169+
Proxy types are grouped under three abstract subtypes:
170+
171+
- [`LearnAPI.IID`](@ref): The main type, for proxies consisting of uncorrelated individual
172+
components, one for each input observation
173+
174+
- [`LearnAPI.Joint`](@ref): For learners that predict a single probabilistic structure
175+
encapsulating correlations between target predictions for different input observations
176+
177+
- [`LearnAPI.Single`](@ref): For learners, such as density estimators, that are trained on
178+
a target variable only (no features); `predict` consumes no data and the returned target
179+
proxy is a single probabilistic structure.
158180
159-
$DOC_HOW_TO_LIST_PROXIES
181+
For lists of all concrete instances, refer to documentation for the relevant subtype.
160182
161183
"""
162184
KindOfProxy

test/traits.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ LearnAPI.learner(model::SmallLearner) = model
2323
# ZERO ARGUMENT METHODS
2424

2525
@test :(LearnAPI.fit) in LearnAPI.functions()
26-
@test Point in LearnAPI.kinds_of_proxy()
26+
@test Point() in LearnAPI.kinds_of_proxy()
2727
@test "regression" in LearnAPI.tags()
2828

2929
# OVERLOADABLE TRAITS

0 commit comments

Comments
 (0)