Factory methods

We use a particular pattern to build and configure the various composite types in our system. This pattern involves the use of factory functions that encapsulate the construction logic for each type, ensuring that all necessary dependencies are properly initialized and configured.

VLDataScienceMachineLearningPackage.buildFunction
function build(type::Type{MyAdjacencyRecombiningCommodityPriceTree}, data::NamedTuple) -> MyAdjacencyRecombiningCommodityPriceTree

Builds an MyAdjacencyRecombiningCommodityPriceTree model given the data in the NamedTuple. This method builds the connectivity of the tree. To compute the price at each node, use the populate! method.

Arguments

  • type::Type{MyAdjacencyRecombiningCommodityPriceTree}: The type of the model to build.
  • data::NamedTuple: The data to use to build the model.

The data NamedTuple must contain the following fields:

  • h::Int64: The height of the tree.
  • price::Float64: The price at the root node.
  • u::Float64: The price increase factor.
  • d::Float64: The price decrease factor.

Returns

  • MyAdjacencyRecombiningCommodityPriceTree: the price tree model holding the computed price data.
source
function build(modeltype::Type{MyFullGeneralAdjacencyTree}, data::NamedTuple) -> MyFullGeneralAdjacencyTree

This function builds a MyFullGeneralAdjacencyTree model given the data in the NamedTuple. It populates the connectivity of the tree. However, it does not populate the data for the tree nodes. We populate the data using the populate! method.

Arguments

  • modeltype::Type{MyFullGeneralAdjacencyTree}: The type of the model to build.
  • data::NamedTuple: The data to use to build the model. The NamedTuple must have the following fields:
    • h::Int64: The height of the tree.
    • n::Int64: The branching factor of the tree.

Returns

  • MyFullGeneralAdjacencyTree: The constructed tree model.
source
function build(modeltype::Type{MyOneDimensionalElementaryWolframRuleModel}, data::NamedTuple) -> MyOneDimensionalElementarWolframRuleModel

This build method constructs an instance of the MyOneDimensionalElementaryWolframRuleModel type using the data in a NamedTuple.

Arguments

The data::NamedTuple must contain the following keys:

  • index::Int64: The index of the Wolfram rule
  • colors::Int64: The number of colors in the rule
  • radius::Int64: The radius, i.e., the number of cells to consider in the rule

Return

This function returns a populated instance of the MyOneDimensionalElementaryWolframRuleModel type.

source
function build(model::Type{T}, edgemodels::Dict{Int64, MyGraphEdgeModel}) where T <: AbstractGraphModel

This function builds a graph model from a dictionary of edge models.

Arguments

  • model::Type{T}: The type of graph model to build, where T is a subtype of AbstractGraphModel.
  • edgemodels::Dict{Int64, MyGraphEdgeModel}: A dictionary of edge models to use for building the graph.

Returns

  • T: The constructed graph model, where T is a subtype of AbstractGraphModel.
source
VLDataScienceMachineLearningPackage.populate!Function
populate!(model::MyAdjacencyRecombiningCommodityPriceTree, price::Float64, Δ::Array{Float64,1})

This function populates the price tree model with the given price and price change factors. This method updates the model in place.

Arguments

  • model::MyAdjacencyRecombiningCommodityPriceTree: The price tree model to populate.
  • price::Float64: The initial price to set at the root of the tree.
  • Δ::Array{Float64,1}: The array of price change factors for each level of the tree.
source
function populate!(model::MyFullGeneralAdjacencyTree, configuration::Function)::MyFullGeneralAdjacencyTree

Populates the data for the tree model using the provided configuration function.

Arguments

  • model::MyFullGeneralAdjacencyTree: The tree model instance to populate.
  • configuration::Function: A function that takes four arguments (level, index, offset and parentdatapayload) and returns a NamedTuple with the configuration data for that node.

Returns

  • MyFullGeneralAdjacencyTree: The updated tree model with populated data.
source