diff --git a/dev/api.html b/dev/api.html index faf0a50..629d04d 100644 --- a/dev/api.html +++ b/dev/api.html @@ -1,3 +1,3 @@ API · Models.jl

API

Abstract Types

Common API

StatsAPI.fitFunction

fit(::Template, output::AbstractMatrix, input::AbstractMatrix, [weights]) -> Model

Fit the Template to the output and input data and return a trained Model. Convention is that weights defaults to StatsBase.uweights(Float32, size(outputs, 2))

source
StatsAPI.predictFunction
predict(model::Model, inputs::AbstractMatrix)
-predict(model::Model, inputs::AbstractVector{<:AbstractVector})

Predict targets for the provided the collection of inputs and Model.

A Model subtype for which the predict_input_type(model) is PointPredictInput will only need to implement a predict function that operates on an AbstractMatrix of inputs.

If the estimate_type(model) is PointEstimate then this function should return another AbstractMatrix in which each column contains the prediction for a single input.

If the estimate_type(model) is DistributionEstimate then this function should return a AbstractVector{<:Distribution}.

source
Models.submodelsFunction
submodels(::Union{Template, Model})

Return all submodels within a multistage model/template.

Submodels are models within a model that have their own inputs (which may or may not be combined with outputs of earlier submodels, before actually being passed as input to the submodel). Such multistage models take a tuple of inputs (which may be nested if the submodel itself has submodels). The order of submodels returned by submodels is as per the order of the inputs in the tuple.

For single-stage models, (i.e. ones that simply take a matrix as input), this returns an empty tuple. Wrapper models which do not expose their inner models to seperate inputs, including ones that only wrap a single model, should not define submodels as they are (from the outside API perspective) single-stage models.

source

Traits

+predict(model::Model, inputs::AbstractVector{<:AbstractVector})

Predict targets for the provided the collection of inputs and Model.

A Model subtype for which the predict_input_type(model) is PointPredictInput will only need to implement a predict function that operates on an AbstractMatrix of inputs.

If the estimate_type(model) is PointEstimate then this function should return another AbstractMatrix in which each column contains the prediction for a single input.

If the estimate_type(model) is DistributionEstimate then this function should return a AbstractVector{<:Distribution}.

source
Models.submodelsFunction
submodels(::Union{Template, Model})

Return all submodels within a multistage model/template.

Submodels are models within a model that have their own inputs (which may or may not be combined with outputs of earlier submodels, before actually being passed as input to the submodel). Such multistage models take a tuple of inputs (which may be nested if the submodel itself has submodels). The order of submodels returned by submodels is as per the order of the inputs in the tuple.

For single-stage models, (i.e. ones that simply take a matrix as input), this returns an empty tuple. Wrapper models which do not expose their inner models to seperate inputs, including ones that only wrap a single model, should not define submodels as they are (from the outside API perspective) single-stage models.

source
Models.estimate_typeFunction
estimate_type(::T) where T = output_type(T)

Return the [EstimateTrait] of the Model or Template.

source
Models.output_typeFunction
output_type(::T) where T = output_type(T)

Return the [OutputTrait] of the Model or Template.

source
Models.predict_input_typeFunction
predict_input_type(::T) where T = predict_input_type(T)

Return the [PredictInputTrait] of the Model or Template.

source

Traits

Models.EstimateTraitType
EstimateTrait

The EstimateTrait specifies if the model outputs a point or distribution estimate, denoted by PointEstimate or DistributionEstimate, respectively.

source
Models.PointEstimateType
PointEstimate <: EstimateTrait

Specifies that the Model returns real-valued response variables.

source
Models.DistributionEstimateType
DistributionEstimate <: EstimateTrait

Specifies that the Model returns a distribution over the response variables.

source
Models.OutputTraitType
OutputTrait

The OutputTrait specifies if the model supports single or multiple response variables, denoted by SingleOutput or MultiOutput, respectively.

source
Models.SingleOutputType
SingleOutput <: OutputTrait

Specifies that the Model returns a single, univariate response variable.

source
Models.MultiOutputType
MultiOutput <: OutputTrait

Specifies that the Model returns a multivariate response variable.

source
Models.PredictInputTraitType
PredictInputTrait

The PredictInputTrait specifies if the model supports point or distribution inputs to predict, denoted by PointPredictInput or PointOrDistributionPredictInput.

source
Models.PointPredictInputType
PointPredictInput <: PredictInputTrait

Specifies that the Model accepts real-valued input variables to predict.

source
Models.PointOrDistributionPredictInputType
PointOrDistributionPredictInput <: PredictInputTrait

Specifies that the Model accepts real-values or a joint distribution over the input variables to predict.

source
diff --git a/dev/design.html b/dev/design.html index ea2a0c9..8926e7d 100644 --- a/dev/design.html +++ b/dev/design.html @@ -14,4 +14,4 @@ outputs = StatsBase.predict( model::Model, inputs::AbstractMatrix # always Features x Observations -)::AbstractVector{<:Distribution} # length Observations

fit takes in a Template and some data and returns a Model that has been fit to the data. predict takes a Model (that has been fit from a Template) and produces a predicted output.

Important facts about fit and predict:

Traits

This package largely avoids using complicated abstract types, or relying on a Model having a particular abstract type. Instead we use traits to determine Model behavior.

Here are the current Model traits in use and their possible values:

The traits always agree between the Model and the Template. Every Model and Template should define all the listed traits. If left undefined, the PredictInputTrait will have the default value of PointPredictInput.

This package uses traits implemented such that the trait function returns an abstract type (rather than an instance). That means to check a trait one uses:

if estimate_type(model) isa DistributionEstimate

and to dispatch on a trait one uses:

foo(::Type{<:DistributionEstimate}, ...)
+)::AbstractVector{<:Distribution} # length Observations

fit takes in a Template and some data and returns a Model that has been fit to the data. predict takes a Model (that has been fit from a Template) and produces a predicted output.

Important facts about fit and predict:

Traits

This package largely avoids using complicated abstract types, or relying on a Model having a particular abstract type. Instead we use traits to determine Model behavior.

Here are the current Model traits in use and their possible values:

The traits always agree between the Model and the Template. Every Model and Template should define all the listed traits. If left undefined, the PredictInputTrait will have the default value of PointPredictInput.

This package uses traits implemented such that the trait function returns an abstract type (rather than an instance). That means to check a trait one uses:

if estimate_type(model) isa DistributionEstimate

and to dispatch on a trait one uses:

foo(::Type{<:DistributionEstimate}, ...)
diff --git a/dev/index.html b/dev/index.html index ffd8f2e..e546bc9 100644 --- a/dev/index.html +++ b/dev/index.html @@ -1,2 +1,2 @@ -Index · Models.jl
+Index · Models.jl
diff --git a/dev/search.html b/dev/search.html index 62ebcf8..3d50e25 100644 --- a/dev/search.html +++ b/dev/search.html @@ -1,2 +1,2 @@ -Search · Models.jl

Loading search...

    +Search · Models.jl

    Loading search...

      diff --git a/dev/testutils.html b/dev/testutils.html index 53bf068..071f5e0 100644 --- a/dev/testutils.html +++ b/dev/testutils.html @@ -6,4 +6,4 @@ test_interface( CustomModelTemplate(); distribution_inputs=[MvNormal(5, 1) for _ in 1:5], -)

      Test Fakes

      Models.TestUtils.FakeModelType
      FakeModel

      A fake Model for testing purposes. See FakeTemplate for details.

      source
      Models.TestUtils.FakeTemplateType
      FakeTemplate{E <: EstimateTrait, O <: OutputTrait} <: Template

      This template is a test double for testing purposes. It should be defined (before fitting) with a predictor, which can be changed by mutating the field.

      Fields

      • predictor::Function: predicts the outputs of the FakeModel. It is (num_variates, inputs) -> outputs, where the num_variates will be memorized during fit.

      Methods

      • fit does not learn anything, it just creates an instance of the corresponding Model.
      • predict applies the predictor to the inputs.
      source
      Models.TestUtils.FakeTemplateMethod
      FakeTemplate{DistributionEstimate, MultiOutput}()

      A Template whose Model will accept real value variables to predict a multivariate normal distribution (with zero-vector mean and identity covariance matrix) for each observation.

      source
      Models.TestUtils.FakeTemplateMethod
      FakeTemplate{PointEstimate, MultiOutput}()

      A Template whose Model will accept real value variables to predict a vector of 0s for each observation. The input and output will have the same dimension.

      source
      Models.TestUtils.FakeTemplateMethod
      FakeTemplate{DistributionEstimate, SingleOutput}()

      A Template whose Model will accept real value variables to predict a univariate normal distribution (with zero mean and unit standard deviation) for each observation.

      source
      Models.TestUtils.FakeTemplateMethod
      FakeTemplate{PointEstimate, SingleOutput}()

      A Template whose Model will accept real value variables to predict 0 for each observation.

      source
      +)

      Test Fakes

      Models.TestUtils.FakeModelType
      FakeModel

      A fake Model for testing purposes. See FakeTemplate for details.

      source
      Models.TestUtils.FakeTemplateType
      FakeTemplate{E <: EstimateTrait, O <: OutputTrait} <: Template

      This template is a test double for testing purposes. It should be defined (before fitting) with a predictor, which can be changed by mutating the field.

      Fields

      • predictor::Function: predicts the outputs of the FakeModel. It is (num_variates, inputs) -> outputs, where the num_variates will be memorized during fit.

      Methods

      • fit does not learn anything, it just creates an instance of the corresponding Model.
      • predict applies the predictor to the inputs.
      source
      Models.TestUtils.FakeTemplateMethod
      FakeTemplate{DistributionEstimate, MultiOutput}()

      A Template whose Model will accept real value variables to predict a multivariate normal distribution (with zero-vector mean and identity covariance matrix) for each observation.

      source
      Models.TestUtils.FakeTemplateMethod
      FakeTemplate{PointEstimate, MultiOutput}()

      A Template whose Model will accept real value variables to predict a vector of 0s for each observation. The input and output will have the same dimension.

      source
      Models.TestUtils.FakeTemplateMethod
      FakeTemplate{DistributionEstimate, SingleOutput}()

      A Template whose Model will accept real value variables to predict a univariate normal distribution (with zero mean and unit standard deviation) for each observation.

      source
      Models.TestUtils.FakeTemplateMethod
      FakeTemplate{PointEstimate, SingleOutput}()

      A Template whose Model will accept real value variables to predict 0 for each observation.

      source