-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from alan-turing-institute/dev
For a 0.5 release
- Loading branch information
Showing
16 changed files
with
602 additions
and
426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
name = "MLJTuning" | ||
uuid = "03970b2e-30c4-11ea-3135-d1576263f10f" | ||
authors = ["Anthony D. Blaom <[email protected]>"] | ||
version = "0.4.3" | ||
version = "0.5.0" | ||
|
||
[deps] | ||
ComputationalResources = "ed09eef8-17a6-5b46-8889-db040fac31e3" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
abstract type SelectionHeuristic end | ||
|
||
## HELPERS | ||
|
||
measure_adjusted_weights(weights, measures) = | ||
if weights isa Nothing | ||
vcat([signature(measures[1]), ], zeros(length(measures) - 1)) | ||
else | ||
length(weights) == length(measures) || | ||
throw(DimensionMismatch( | ||
"`OptimizeAggregatedMeasurement` heuristic "* | ||
"is being applied to a list of measures whose length "* | ||
"differs from that of the specified `weights`. ")) | ||
signature.(measures) .* weights | ||
end | ||
|
||
|
||
## OPTIMIZE AGGREGATED MEASURE | ||
|
||
""" | ||
NaiveSelection(; weights=nothing) | ||
Construct a common selection heuristic for use with `TunedModel` instances | ||
which only considers measurements aggregated over all samples (folds) | ||
in resampling. | ||
For each entry in the tuning history, one defines a penalty equal to | ||
the evaluations of the `measure` specified in the `TunedModel` | ||
instance, aggregated over all samples, and multiplied by `-1` if `measure` | ||
is a `:score`, and `+`` if it is a loss. The heuristic declares as | ||
"best" (optimal) the model whose corresponding entry has the lowest | ||
penalty. | ||
If `measure` is a vector, then the first element is used, unless | ||
per-measure `weights` are explicitly specified. Weights associated | ||
with measures that are neither `:loss` nor `:score` are reset to zero. | ||
""" | ||
struct NaiveSelection <: SelectionHeuristic | ||
weights::Union{Nothing, Vector{Real}} | ||
end | ||
NaiveSelection(; weights=nothing) = | ||
NaiveSelection(weights) | ||
|
||
|
||
function best(heuristic::NaiveSelection, history) | ||
first_entry = history[1] | ||
measures = first_entry.measure | ||
weights = measure_adjusted_weights(heuristic.weights, measures) | ||
measurements = [weights'*(h.measurement) for h in history] | ||
measure = first(history).measure[1] | ||
if orientation(measure) == :score | ||
measurements = -measurements | ||
|
||
end | ||
best_index = argmin(measurements) | ||
return history[best_index] | ||
end | ||
|
||
MLJTuning.supports_heuristic(::Any, ::NaiveSelection) = | ||
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.