API
This section documents the ApplicationDrivenLearning API.
Constructors
ApplicationDrivenLearning.Model
— TypeModel <: JuMP.AbstractModel
Create an empty ApplicationDrivenLearning.Model with empty plan and assess models, missing forecast model and default settings.
ApplicationDrivenLearning.PredictiveModel
— TypePredictiveModel(networks, input_output_map, input_size, output_size)
Creates a predictive (forecast) model for the AppDrivenLearning module from Flux models and input/output information.
...
Arguments
networks
: array of Flux models to be used.input_output_map::Vector{Dict{Vector{Int}, Vector{Int}}}
: array in the same ordering as networks of mappings from input indexes to output indexes on which the models should be applied.input_size::Int
: size of the input vector.output_size::Int
: size of the output vector. ...
Example
julia> pred_model = PredictiveModel(
[Flux.Dense(1 => 1), Flux.Dense(3 => 2)],
[
Dict([1] => [1], [1] => [2]),
Dict([1,2,3] => [3,4], [1,4,5] => [5,6])
],
5,
6
);
ApplicationDrivenLearning.Plan
— FunctionUpper(model::ApplicationDrivenLearning.Model)
Create a reference to the plan model of an application driven learning model.
ApplicationDrivenLearning.Assess
— FunctionAssess(model::ApplicationDrivenLearning.Model)
Create a reference to the assess model of an application driven learning model.
JuMP variable types
ApplicationDrivenLearning.Policy
— TypePolicy{T}
Policy variable type that holds plan and assess variables.
ApplicationDrivenLearning.Forecast
— TypeForecast{T}
Forecast variable type that holds plan and assess variables.
Structs
ApplicationDrivenLearning.Options
— TypeOptions(mode; params...)
Options struct to hold optimization mode and mode parameters.
...
Example
options = Options(
GradientMode;
rule = Optim.RMSProp(0.01),
epochs = 100,
batch_size = 10,
)
...
ApplicationDrivenLearning.Solution
— TypeSolution
A struct to store the result of the optimisation process with final cost and solution.
Modes
ApplicationDrivenLearning.NelderMeadMode
— TypeNelderMeadMode <: AbstractOptimizationMode
Used to solve the application driven learning training problem using the Nelder-Mead optimization method implementation from Optim.jl package.
...
Parameters
initial_simplex
is the initial simplex of solutions to be applied.parameters
is the parameters to be applied to the Nelder-Mead optimization method. ...
ApplicationDrivenLearning.GradientMode
— TypeGradientMode <: AbstractOptimizationMode
Used to solve the application driven learning training problem using the gradient optimization method
...
Parameters
rule
is the optimiser object to be used in the gradient optimization process.- 'epochs' is the number of epochs to be used in the gradient optimization process.
- 'batch_size' is the batch size to be used in the gradient optimization process.
- 'verbose' is the flag of whether to print the training process.
- 'computecostevery' is the epoch frequency for computing the cost and evaluating best solution.
- 'time_limit' is the time limit for the training process. ...
ApplicationDrivenLearning.NelderMeadMPIMode
— TypeNelderMeadMPIMode <: AbstractOptimizationMode
MPI implementation of NelderMeadMode.
ApplicationDrivenLearning.GradientMPIMode
— TypeGradientMPIMode <: AbstractOptimizationMode
MPI implementation of GradientMode.
ApplicationDrivenLearning.BilevelMode
— TypeBilevelMode <: AbstractOptimizationMode
Used to solve the application driven learning training problem as a bilevel optimization problem by using the BilevelJuMP.jl package.
...
Parameters
optimizer::Function
is equivalent tosolver
in BilevelJuMP.BilevelModel.silent::Bool
is equivalent tosilent
in BilevelJuMP.BilevelModel.mode::Union{Nothing, BilevelJuMP.BilevelMode}
is equivalent tomode
in BilevelJuMP.BilevelModel. ...
Attributes getters and setters
ApplicationDrivenLearning.plan_policy_vars
— FunctionReturns vector of policy variables from plan model.
ApplicationDrivenLearning.assess_policy_vars
— FunctionReturns vector of policy variables from assess model.
ApplicationDrivenLearning.plan_forecast_vars
— FunctionReturns vector of forecast variables from plan model.
ApplicationDrivenLearning.assess_forecast_vars
— FunctionReturns vector of forecast variables from assess model.
ApplicationDrivenLearning.set_forecast_model
— FunctionSets Chain, Dense or custom PredictiveModel object as forecast model.
ApplicationDrivenLearning.extract_params
— Functionextract_params(model)
Extract the parameters of a PredictiveModel into a single vector.
ApplicationDrivenLearning.apply_params
— Functionapply_params(model, θ)
Return model after fixing the parameters from an adequate vector of parameters.
Flux attributes getters and setters
ApplicationDrivenLearning.extract_flux_params
— Functionextract_flux_params(model)
Extract the parameters of a Flux model (Flux.Chain or Flux.Dense) into a single vector.
ApplicationDrivenLearning.fix_flux_params_single_model
— Functionfix_flux_params_single_model(model, θ)
Return model after fixing the parameters from an adequate vector of parameters.
ApplicationDrivenLearning.fix_flux_params_multi_model
— Functionfix_flux_params_multi_model(models, θ)
Return iterable of models after fixing the parameters from an adequate vector of parameters.
ApplicationDrivenLearning.has_params
— Functionhas_params(layer)
Check if a Flux layer has parameters.
ApplicationDrivenLearning.apply_gradient!
— Functionapply_gradient!(model, dCdy, X, rule)
Apply a gradient vector to the model parameters.
...
Arguments
model::PredictiveModel
: model to be updated.dCdy::Vector{<:Real}
: gradient vector.X::Matrix{<:Real}
: input data.rule
: Optimisation rule. ...
Other functions
ApplicationDrivenLearning.forecast
— Functionforecast(model, X)
Return forecast model output for given input.
ApplicationDrivenLearning.compute_cost
— Functioncompute_cost(model, X, Y, with_gradients=false)
Compute the cost function (C) based on the model predictions and the true values.
...
Arguments
model::ApplicationDrivenLearning.Model
: model to evaluate.X::Matrix{<:Real}
: input data.Y::Matrix{<:Real}
: true values.with_gradients::Bool=false
: flag to compute and return gradients. ...
ApplicationDrivenLearning.train!
— Functiontrain!(model, X, y, options)
Train model using given data and options.
ApplicationDrivenLearning.build_plan_model_forecast_params
— FunctionCreates new forecast variables to plan model using MOI.Parameter and new constraint fixing to original forecast variables.
ApplicationDrivenLearning.build_assess_model_policy_constraint
— FunctionCreates new constraint to assess model that fixes policy variables.
ApplicationDrivenLearning.build
— FunctionCalls functions that set new variables and constraints that are necessary to cost computation.