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.build — Functionfunction build(type::Type{MyAdjacencyRecombiningCommodityPriceTree}, data::NamedTuple) -> MyAdjacencyRecombiningCommodityPriceTreeBuilds 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.
function build(modeltype::Type{MyFullGeneralAdjacencyTree}, data::NamedTuple) -> MyFullGeneralAdjacencyTreeThis 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.
function build(modeltype::Type{MyOneDimensionalElementaryWolframRuleModel}, data::NamedTuple) -> MyOneDimensionalElementarWolframRuleModelThis build method constructs an instance of the MyOneDimensionalElementaryWolframRuleModel type using the data in a NamedTuple.
Arguments
modeltype::Type{MyOneDimensionalElementaryWolframRuleModel}: The type of model to build, in this case, theMyOneDimensionalElementaryWolframRuleModeltype.data::NamedTuple: The data to use to build the model.
The data::NamedTuple must contain the following keys:
index::Int64: The index of the Wolfram rulecolors::Int64: The number of colors in the ruleradius::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.
function build(model::Type{T}, edgemodels::Dict{Int64, MyGraphEdgeModel}) where T <: AbstractGraphModelThis function builds a graph model from a dictionary of edge models.
Arguments
model::Type{T}: The type of graph model to build, whereTis a subtype ofAbstractGraphModel.edgemodels::Dict{Int64, MyGraphEdgeModel}: A dictionary of edge models to use for building the graph.
Returns
T: The constructed graph model, whereTis a subtype ofAbstractGraphModel.
VLDataScienceMachineLearningPackage.populate! — Functionpopulate!(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.
function populate!(model::MyFullGeneralAdjacencyTree, configuration::Function)::MyFullGeneralAdjacencyTreePopulates 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.