This is the API model for algorithms. It consists of core interfaces that all algorithmic implementations
must use. In addition this API uses a ServiceProvider interface that implementations must also
provide a concrete implementation.
This API is designed with SOLID principles in mind, particularly the separation of the logic from the interfaces, and that consuming applications will work against the interface not the concrete implementation.
The model consists of the following key interfaces:
-
Parameter<T>: Represents a parameter that is used by aFunctionorModel. Parameters can have anameand an optionalvariableassigned to it so that the underlying operation can identify the parameter by either or both properties. There are several subinterfaces defined in the model (only a few common ones described below):-
ScalarParameter: Represents a parameter containing aScalarvalue. -
FunctionParameter<T>: contains aFunction<T>as the parameter value. As common sub-subinterface is also provided:ScalarFunctionParameter, which is a parameter that holds aFunctionthat returns aScalarvalue. -
VectorParameter<T>: contains aVector<T>as the parameter value. LikeFunctionParameter<T>, there is a commonly used sub-subinterace forScalarVectorparameters, aptly namedScalarVectorParameter.
-
-
Coefficient<T>: Represents an output value from aModeloperation. -
Function<T>: Represents a function that returns a single result of typeT.Functions can can pass in any number ofParameters as required to perform the operation. A commonly used sub-interface is provided for convenience:ScalarFunction, which is effectively syntactic sugar forFunction<Scalar>. -
Model: Represents an operation that returns one or moreCoefficients -
Vector<T>: Represents a set of values ofTthat can be used by aFunctionorModel -
Matrix: Represents a collection ofVectorobjects. This is still experimental.
There are several factory interfaces that provide methods for creating implementations of the
model above. These factories are accessed from the ModelProvider (discussed below):
-
VectorFactory: contains methods for instantiatingVectorinstances -
ParameterFactory: contains methods for instantiatingParameterinstances -
CoefficientFactory: contains methods for instantiatingCoefficientinstances -
MatrixFactory: contains methods for instantiatingMatrixinstances
The ModelProvider interface serves two purposes:
- It contains accessor methods for the factories above
- It becomes the entry point for consumers to access the implementation model
An implementation jar would include the following file in the jar file:
/META-INF/services/io.xmljim.algorithms.model.provider.ModelProvider
This file would contain the fully qualified class name of the implementation of ModelProvider.
For example, assume there is an implementation called org.acme.algorithms.provider.ModelProviderImpl -
this would be what you would include the file.
Provided that both this jar and the implementation jar on are on the classpath, a consuming class would instantiate the implementation as follows:
Iterable<ModelProvider> modelProviders = ServiceLoader.load(ModelProvider.class);
//depending on whether there are more than one possible instances, you could iterate
//however, we'll assume only one instance here
ModelProvider provider = modelProviders.iterator().next();There are two "reference" implementations that use the Model API: Financial and Statistics.
There is also a default implementation jar that implements this model: "algorithms-model-impl"
(locate the dependency in the maven pom.xml file).