I am testing how different variables affect a model using a parameter sweep. I am trying to read in parameters from a text file and pass them to a function where the model is calculated and answer returned and output.
For example, if I have an input file with the parameter name as the first row and successive rows as the parameter combinations I would like to compute:
input.txt
param1, param2, param3, ..., paramm
0,0,1
0,0,2
0,1,1
0,1,2
0,2,1
0,2,2
1,0,1
1,0,2
1,1,1
1,1,2
1,2,1
1,2,2
I have a function that computes my model. To keep it simple, I will say the model is the sum of all my parameters:
def model(param1,param2,param3...,paramm):
param1=0
param2=0
param3=0
param4=0
param5=0
.
.
.
paramn=0
answer=parma1+param2+param3+param4+param5
return answer
where setting the parameters=0 is a way of initializing them (I now know it does not work for param1,param2 or param3 because it overwrites what was written to them). I include param4 and param5 to signify that there might be other parameters that are there that I do not vary but take some default value.
How do I read in the file and run all parameter combinations? Should I just create some tuple called params and adjust the values each time after reading in the file or is there a better way?
EDIT1:
I have edited the question to add a higher number of paramemeters that are known in the text file and constants. Would I be better off creating a parameter object and editing the values of the object for each pass to the function.
Please realize that though the function is a sum in this example, it will be much more complicated in the real program, likely calling other functions with only a subset of the parameters. For example
def model1(param1):
a=1
b=2
c=3
return a*param1**2+b*param1+c
def model(param1,param2,param3...,paramm):
param1=0
param2=0
param3=0
param4=0
param5=0
.
.
.
paramn=0
answer=model1(param1)+param2+param3+param4+param5