Well the short story is:
- I’m building a library of different parameter calculators.
- Each parameter can be calculated by a number of different models, sometimes multiple model specifications.
- My implementation would like to take advantage of the optimisation capabilities of the language I’m using.
As an example of both a multi-model parameter and its implementation,
stringer(::Val{:square}, ::Val{:one}, x, y) = x^2 + 1y
stringer(::Val{:square}, ::Val{:two}, x, y) = x^2 + 2y
stringer(::Val{:cube}, ::Val{:one}, x, y) = x^3 + 1y
stringer(::Val{:cube}, ::Val{two}, x) = x^3 + 2y
A poor example, given there are better ways to specify the multiplication factor than Val(:one)
and Val(:two)
and better ways to specify the power than Val(:square)
and Val(:cube)
, but there are contexts for implementation where a string (or symbol) is properly needed:
- The model’s author(s) name(s) need to be dispatched on.
- An automatically generated list of models*.
*As a sidenote on this, and extra motivation for my modelling goal, consider this poorly designed function of mine:
function models(func::Function)
subject_methods = methods(func)
subject_method_signatures = [
subject_method.sig
for subject_method in subject_methods
]
subject_method_signature_types = [
subject_signature.types
for subject_signature in subject_method_signatures
]
subject_method_symbols = [
[
sig_type.parameters[1]
for sig_type in subject_type
if sig_type <: Val
]
for subject_type in subject_method_signature_types
]
num_method_categories = subject_method_symbols .|> length |> unique
@assert length(num_method_categories) == 1 "All methods of $(string(func)) must have the same number of model specifications."
num_model_categories = num_method_categories[1]
return Tuple(
[subject_symbol[n]
for subject_symbol in subject_method_symbols
] |> sort |> unique for n in 1:num_model_categories
)
end
As a poor summary, it outputs a list of model names as symbols. It would assist with automated documentation, test loops, general investigations of parameter behaviour, and many others. My boss is patient enough to manually change lists of models each time he changes the subject’s implementation - I’m not!
I’ve tried many different options in many different languages:
- MATLAB: Classes; functions; packages; combinations/different utilisations of classes and/or functions and/or packages
- C++: Yeah, definitely not.
- Odin: lacks many scientific programming capabilities, but has binary generation out-of-the-box!
- Julia: To sub-module or not to sub-module (getting model lists via
names
, parameter models implemented as functions with model names); function dispatches; figuring out how/if to involve struct
s throughout it all.
- Python: Definitely not. Not properly/simply/easily scalable.
Many other programming languages to try, but Julia seems best for my use case.
And as you said, I may be doing something in an impractical and discouraged way. It’s been a little bit of a chicken-and-egg problem, not knowing exactly how to ask this question, yet I need to play around and experiment with what’s available to formulate a proper question to demonstrate my needs - the latter of which I’ve been at for a while.
This response blew up in length, and it’s scope is extending beyond the original post, but this response isn’t sufficient, nor concise, in explaining my situation, so I’m going to keep it here and postpone making a new post for this question.