Skip to content

Commit f55d100

Browse files
committed
model trait rename: methods -> functions
1 parent fac3863 commit f55d100

File tree

8 files changed

+44
-22
lines changed

8 files changed

+44
-22
lines changed

docs/src/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ probability distributions". There is no abstract type model hierarchy.
3636

3737
Our preceding remarks notwithstanding, there is, for certain applications involving a
3838
"target" variable (understood in a rather general way - see below) a clear-cut distinction
39-
between models, based on the proxy for the target as actually output by the
39+
between models, based on the proxy for the target that is actually output by the
4040
model. Probability distributions, confidence intervals and survival functions are examples
4141
of [Target proxies](@ref). LearnAPI provides a trait for distinguishing such models based
4242
on the target proxy.
@@ -65,8 +65,8 @@ The following methods, dispatched on model type, are provided:
6565
- **model traits**, such as `target_proxy(model)`, for promising specific behaviour
6666

6767
There is flexibility about how much of the interface is implemented by a given model
68-
object `model`. A special trait `methods(model)` declares what has been
69-
explicitly implemented or overloaded to work with `model`.
68+
object `model`. A special trait `functions(model)` declares what has been explicitly
69+
implemented or overloaded to work with `model`, excluding traits.
7070

7171
Since this is a functional-style interface, `fit` returns model `state`, in addition to
7272
learned parameters, for passing to the optional `update!` and `ingest!` methods. These

docs/src/model_traits.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@ In this table, `Table` and `Continuous` are names owned by the package
55

66
| trait | fallback value | return value | example |
77
|:-------------------------------------------------|:----------------------|:--------------|:--------|
8-
| [`LearnAPI.ismodel`](@ref)`(model)` | `false` | is `true` for any model, as defined in [Models](@ref) | `true` |
9-
| [`LearnAPI.methods`](@ref)`(model)` | `()` | lists of all overloaded/implemented methods (traits excluded) | `(:fit, :predict)` |
8+
| [`LearnAPI.functions`](@ref)`(model)` | `()` | implemented LearnAPI functions (traits excluded) | `(:fit, :predict)` |
109
| [`LearnAPI.target_proxy`](@ref)`(model)` | `NamedTuple()` | details form of target proxy output | `(; predict=LearnAPI.Distribution()` |
1110
| [`LearnAPI.position_of_target`](@ref)`(model)` | `0` | † the positional index of the **target** in `data` in `fit(..., data...; metadata)` calls | 2 |
1211
| [`LearnAPI.position_of_weights`](@ref)`(model)` | `0` | † the positional index of **observation weights** in `data` in `fit(..., data...; metadata)` | 3 |
1312
| [`LearnAPI.descriptors`](@ref)`(model)` | `()` | lists one or more suggestive model descriptors from `LearnAPI.descriptors()` | (:classifier, :probabilistic) |
1413
| [`LearnAPI.is_pure_julia`](@ref)`(model)` | `false` | is `true` if implementation is 100% Julia code | `true` |
1514
| [`LearnAPI.pkg_name`](@ref)`(model)` | "unknown" | name of package providing core algorithm (may be different from package providing LearnAPI.jl implementation) | "DecisionTree" |
16-
| [`LearnAPI.doc_url`](@ref)`(model)` | "unknown" | url providing documentation of the core algorithm | "https://en.wikipedia.org/wiki/Decision_tree_learning" |
1715
| [`LearnAPI.pkg_license`](@ref)`(model)` | "unknown" | name of license of package providing core algorithm | "MIT" |
16+
| [`LearnAPI.doc_url`](@ref)`(model)` | "unknown" | url providing documentation of the core algorithm | "https://en.wikipedia.org/wiki/Decision_tree_learning" |
1817
| [`LearnAPI.load_path`](@ref)`(model)` | "unknown" | a string indicating where the struct `typeof(model)` is defined, beginning with name of package providing implementation | `FastTrees.LearnAPI.DecisionTreeClassifier` |
19-
| [`LearnAPI.is_wrapper`](@ref)`(model)` | `false` | is `true` if one or more hyperparameters are themselves models | `true` |
18+
| [`LearnAPI.is_wrapper`](@ref)`(model)` | `false` | is `true` if one or more properties (fields) are themselves models | `true` |
2019
| [`LearnAPI.fit_keywords`](@ref)`(model)` | `()` | tuple of symbols for keyword arguments accepted by `fit` (metadata) | `(:class_weights,)` |
2120
| [`LearnAPI.human_name`](@ref)`(model)` | type name with spaces | human name for the model; should be a noun | "elastic net regressor" |
2221
| [`LearnAPI.iteration_parameter`](@ref)`(model)` | nothing | symbolic name of an iteration parameter | :epochs |

docs/src/operations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ŷ, predict_report = LearnAPI.predict(some_model, fitted_params, Xnew)
3737
[`LearnAPI.predict_joint`](@ref).
3838

3939
- Each operation explicitly implemented or overloaded must be included in the return value
40-
of [`LearnAPI.methods`](@ref).
40+
of [`LearnAPI.functions`](@ref).
4141

4242
## Predict or transform?
4343

docs/src/reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ required. If a model has other models as hyper-parameters, its
5656

5757
None of the methods described in the linked sections below are compulsory, but any
5858
implemented or overloaded method that is not a model trait must be added to the return
59-
value of [`LearnAPI.methods`](@ref), as in
59+
value of [`LearnAPI.functions`](@ref), as in
6060

6161
```julia
62-
LearnAPI.methods(::Type{<SomeModelType}) = (:fit, update!, predict)
62+
LearnAPI.functions(::Type{<SomeModelType}) = (:fit, update!, predict)
6363
```
6464

6565
For examples, see [Anatomy of an Interface](@ref).

src/accessor_functions.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Return the model-specific feature importances of `model`, given `fittted_params`
1515
=> 0.1]`).
1616
1717
The `model` supports feature importances if `:feature_importance in
18-
LearnAPI.methods(model)`.
18+
LearnAPI.functions(model)`.
1919
2020
If for some reason a model is sometimes unable to report feature importances, then
2121
`feature_importances` will return all importances as 0.0, as in `[:gender =>0.0, :height

src/fit_update_ingest.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const DOC_OPERATIONS =
88
function DOC_IMPLEMENTED_METHODS(name; overloaded=false)
99
word = overloaded ? "overloaded" : "implemented"
1010
"If $word, include `:$name` in the tuple returned by the "*
11-
"[`LearnAPI.methods`](@ref) trait. "
11+
"[`LearnAPI.functions`](@ref) trait. "
1212
end
1313

1414
const DOC_WHAT_IS_DATA =

src/model_traits.jl

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,44 @@
11
# There are two types of traits - ordinary traits that an implemenation overloads to make
22
# promises of model behaviour, and derived traits, which are never overloaded.
33

4+
const DERIVED_TRAITS = (:name, :ismodel)
5+
const ORDINARY_TRAITS = (
6+
:functions,
7+
:target_proxy,
8+
:position_of_target,
9+
:position_of_weights,
10+
:descriptors,
11+
:is_pure_julia,
12+
:pkg_name,
13+
:pkg_license,
14+
:doc_url,
15+
:load_path,
16+
:is_wrapper,
17+
:fit_keywords,
18+
:human_name,
19+
:iteration_parameter,
20+
:fit_data_scitype,
21+
:fit_data_type,
22+
:fit_observation_scitypes,
23+
:fit_observation_types,
24+
:input_scitypes,
25+
:input_types,
26+
:output_scitypes,
27+
:output_types,
28+
)
429

530
# # DERIVED TRAITS
631

732
name(M::Type) = string(typename(M))
33+
ismodel(M::Type) = !isempty(functions(M))
834

935

1036
# # ORDINARY TRAITS
1137

12-
methods() = METHODS = (OPERATIONS..., ACCESSOR_FUNCTIONS...)
38+
functions() = METHODS = (OPERATIONS..., ACCESSOR_FUNCTIONS...)
1339

1440
"""
15-
LearnAPI.methods(m)
41+
LearnAPI.functions(m)
1642
1743
Return a tuple of symbols, such as `(:fit, :predict)`, corresponding to LearnAPI.jl
1844
methods implemented for objects having the same type as `m`.
@@ -26,18 +52,15 @@ $DOC_MODEL
2652
2753
# New model implementations
2854
29-
Elements of the returned tuple must come from this list: $(join(string.(methods()), ", ")).
55+
Elements of the returned tuple must come from this list: $(join(string.(functions()), ", ")).
3056
3157
A new type whose instances are intended to be LearnAPI models can guarantee that by
3258
subtyping [`LearnAPI.Model`](@ref).
3359
3460
See also [`LearnAPI.Model`](@ref).
3561
3662
"""
37-
methods(::Type) = ()
38-
39-
ismodel(::Any) = false
40-
ismodel(::Model) = true
63+
functions(::Type) = ()
4164

4265
target_proxy(::Type) = NamedTuple()
4366

@@ -92,7 +115,7 @@ iteration_parameter(::Type) = nothing
92115

93116
fit_data_scitype(::Type) = Union{}
94117

95-
fit_data_types(::Type) = Union{}
118+
fit_data_type(::Type) = Union{}
96119

97120
fit_observation_scitypes(::Type) = Union{}
98121

src/models.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ $DOC_MODEL
2121
2222
# New model implementations
2323
24-
Overloading [`LearnAPI.methods`](@ref) for a given type implies a promise that instances
24+
Overloading [`LearnAPI.functions`](@ref) for a given type implies a promise that instances
2525
of that type are LearnAPI.jl models in the above sense. If one subtypes `LearnAPI.Model`,
2626
then this promise automatically holds true.
2727
28-
See also [`LearnAPI.methods`](@ref).
28+
See also [`LearnAPI.functions`](@ref).
2929
3030
"""
3131
abstract type Model <: MLType end

0 commit comments

Comments
 (0)