I want to figure out how to generate different version of a function programmatically.
I beleive metaprogramming is what I need but wanted to ask for advice before implementing it.
Apologies if below is a bit confusing and happy to answer any clarifying questions.
Here’s what I want:
I have different versions of a similar function that I fit to data.
I have working code that does the fitting so I don’t need any advice about that.
Each function uses several
inputs, produces one
output depending on several
A very simple example can be a function like this:
function test_fun(input1, input2, parameter1, parameter2) output = input1/parameter1 + input2/parameter2 return output end
The actual function has 5 inputs, 10-25 parameters and produces one output.
I want to be able to generate different versions of this function that contain different number of parameters, make some parameter=1, others =Inf and others =0.
Then I’ll use a loop to generate different version of a function and fit it to data to figure out what is the minimal number of parameters that I need to achieve good fit.
What would be the best approach to do this?
I could be overthinking this but I plan to make a macro that will take a list of symbols of parameters that are undefined (i.e., the parameters that will be modified by fitting algorythm), a list of parameters that =1, a list of parameters that =0 and a list of parameters that =Inf. Then this marco will create a version of the function having undefined parameters as positional arguments and defined parameters as kwargs. Then I’ll use a loop through different lists of parameters to do the function generation + fitting.
Does this sound sensible? If yes, how should I go about writing such a macro?
I have read Julia Manual Metaprogramming and Introducing Julia/Metaprogramming - Wikibooks, open books for an open world and I think I could implement this but want to make sure I’m on the right track as it looks like it’ll take a bunch of hours/maybe days for me to do this as I’m still getting a hang of the metaprograming syntax.