I've tried reading this resource on the naming conventions for common Python design patterns, but I can't find a pattern that matches the class I'm creating.
The closest I could find was the Composite Pattern, although I don't feel that matches my use case.
I'm working on a Machine Learning Explainability package. One way of explaining a model is to build a simpler surrogate
model that mimics the behaviour of the complex model.
A common way to implement this is the SHAP algorithm, which requires you to sample the dataset that you used to create the original complex model.
How you sample is dependent on a single row of features, which you build the surrogate
model around. This makes it useful to have a Sampler
object that stores the background dataset and takes a single row as input.
This gives me three strongly related complex objects and one dataset. It makes sense to me to store these in the same place and obfuscate their connections with a simple interface.
However, I don't think this is an interface because the methods won't change to match the objects. The class will not be abstract, and it will hold all the important data.
I'd like to contain the functionality for building the surrogate
model, and Sampler
inside this class too. So it's partially a Factory design pattern.
Is there a pre-existing name for a class like this? Maybe the BORG design pattern? Or should I have rethink before I create something like this?
It is difficult to advice what patterns should be used without being given code snippets.
However, let me give a quick overview of what pattern can be applied:
This gives me three strongly related complex objects and one dataset
Decorator
pattern can be used here. I mean, if you want to build strongly related objects and add them some behavior, then you can try to apply this patternI mean you can compose objects like you want. Let me show an example via C#:
var basicBike = new AluminiumBike();
BikeAccessories upgraded = new SportPackage(basicBike);
upgraded = new SecurityPackage(upgraded);
Console.WriteLine($"Bike: '{upgraded.GetDetails()}'
Cost: {upgraded.GetPrice()}");