@@ -132,3 +132,103 @@ function metadata_model(
132
132
133
133
parentmodule (T). eval (program)
134
134
end
135
+
136
+ # TODO : After `human_name` trait is added as model trait, include in
137
+ # example given in the docstring for `doc_header`.
138
+
139
+ """
140
+ MLJModelInterface.doc_header(SomeModelType)
141
+
142
+ Return a string suitable for interpolation in the document string of
143
+ an MLJ model type. In the example given below, the header expands to
144
+ something like this:
145
+
146
+ > `FooRegressor`
147
+ >
148
+ >Model type for foo regressor, based on [FooRegressorPkg.jl](http://existentialcomics.com/).
149
+ >
150
+ >From MLJ, the type can be imported using
151
+ >
152
+ >
153
+ > `FooRegressor = @load FooRegressor pkg=FooRegressorPkg`
154
+ >
155
+ >Construct an instance with default hyper-parameters using the syntax
156
+ >`model = FooRegressor()`. Provide keyword arguments to override
157
+ >hyper-parameter defaults, as in `FooRegressor(a=...)`.
158
+
159
+ Ordinarily, `doc_header` is used in document strings defined *after*
160
+ the model type definition, as `doc_header` assumes model traits (in
161
+ particular, `package_name` and `package_url`) to be defined; see also
162
+ [`MLJModelInterface.metadata_pkg`](@ref).
163
+
164
+
165
+ ### Example
166
+
167
+ Suppose a model type and traits have been defined by:
168
+
169
+ ```
170
+ mutable struct FooRegressor
171
+ a::Int
172
+ b::Float64
173
+ end
174
+
175
+ metadata_pkg(FooRegressor,
176
+ name="FooRegressorPkg",
177
+ uuid="10745b16-79ce-11e8-11f9-7d13ad32a3b2",
178
+ url="http://existentialcomics.com/",
179
+ )
180
+ metadata_model(FooRegressor,
181
+ input=Table(Continuous),
182
+ target=AbstractVector{Continuous},
183
+ descr="La di da")
184
+ ```
185
+
186
+ Then the docstring is defined post-facto with the following code:
187
+
188
+ ```
189
+ const HEADER = MLJModelInterface.doc_header(FooRegressor)
190
+
191
+ @doc \"\"\"
192
+ \$ HEADER
193
+
194
+ ### Training data
195
+
196
+ In MLJ or MLJBase, bind an instance `model` ...
197
+
198
+ <rest of doc string goes here>
199
+
200
+ \"\"\" FooRegressor
201
+ ```
202
+
203
+ """
204
+ function doc_header (SomeModelType)
205
+ name = MLJModelInterface. name (SomeModelType)
206
+ human_name = MLJModelInterface. human_name (SomeModelType)
207
+ package_name = MLJModelInterface. package_name (SomeModelType)
208
+ package_url = MLJModelInterface. package_url (SomeModelType)
209
+ params = MLJModelInterface. hyperparameters (SomeModelType)
210
+
211
+ ret =
212
+ """
213
+ $name
214
+
215
+ Model type for $human_name , based on [$(package_name) .jl]($package_url ).
216
+
217
+ From MLJ, the type can be imported using
218
+
219
+ $name = @load $name pkg=$package_name
220
+
221
+ Do `model = $name ()` to construct an instance with default hyper-parameters.
222
+ """ |> chomp
223
+
224
+ isempty (params) && return ret
225
+
226
+ p = first (params)
227
+ ret *=
228
+ """
229
+ Provide keyword arguments to override hyper-parameter defaults, as in
230
+ `$name ($p =...)`.
231
+ """ |> chomp
232
+
233
+ return ret
234
+ end
0 commit comments