tomas3svoboda / ChroMo

Chromatography model determination
2 stars 0 forks source link

Sensitivity analysis #24

Closed meloun67 closed 9 months ago

meloun67 commented 2 years ago

We need to design and implement analysis of sensitivity of every optimized parameter. In the other words, quantify how rapidly change in parameter influences the final solution.

svoboad3 commented 2 years ago

I don't really know how to do that. I can print graphs like these if it helps 😄 henryConst disperCoef Porosityx

meloun67 commented 2 years ago

Yeah that looks good. However, it would be better to print 3D surface plots x - DisperCoef (1-5000), y - HenryConst (1-5000), z - LossFuncValue. And plot it for porosity 0.2, 0.3, 0.4, ..., 0.8

svoboad3 commented 2 years ago

ok added code that does this at the end of Start_For_Testing function. You should probably run it for yourself and tweak the sizes and steps of this, with DisperCoef and HenryConst 1-5000 and step 1, graph for one porosity would take me approximately 24 days to run 😄 (x - henryConst, y - disperCoef, ) image

svoboad3 commented 2 years ago

01 02 03 04 05 06 07

svoboad3 commented 2 years ago

Also created function Loss_Function_Analysis to print these, here are all the arguments: image

Here is a example how to use it: image

meloun67 commented 2 years ago

Also created function Loss_Function_Analysis to print these, here are all the arguments: image

Here is a example how to use it: image

Nice! Could you please also print out the coordinates (K, D) where the minimum is. Then ask if you want to print closer location. If yes ask for K interval and D interval and print another surface plot.

svoboad3 commented 2 years ago

Ok should be done. Here is a example how it works:

  1. After the calculation is done, it will print the whole graph with values and indexes where minimum is: image
  2. When you close the graph, function will ask you if you want closeup, if you input Y(yes), it will ask you for indexes of closeup: image (The graphs have large step for faster testing)

I have done it by indexes rather than values because calculating the right indexes from values was hard 😄 Also when I was working on it, I figured maybe you wanted to do new calculation in smaller area but with smaller step to get more detail. It that is the case, I'll do that next.

meloun67 commented 2 years ago

Ok should be done. Here is a example how it works:

  1. After the calculation is done, it will print the whole graph with values and indexes where minimum is: image
  2. When you close the graph, function will ask you if you want closeup, if you input Y(yes), it will ask you for indexes of closeup: image (The graphs have large step for faster testing)

I have done it by indexes rather than values because calculating the right indexes from values was hard 😄 Also when I was working on it, I figured maybe you wanted to do new calculation in smaller area but with smaller step to get more detail. It that is the case, I'll do that next.

Nice job! Yes correct! New calculation is needed, could be same number of nodes as original one, or you can add runtime question for a user. Up to yoi, both is fine for me.

meloun67 commented 2 years ago

Also maybe logaritmic scale option could be included ;-)

svoboad3 commented 2 years ago

Done the closeup as a another calculation, here is example of how to use it: image You go again by value and not index, because for another calculation, going by index doesn't make sense. You also fill up size of step, so you can go as detailed as you want. Also it is done recursively, so you can do multiple closeups on single dataset.

About the logarithmic scale, how would that work? Wouldn't we need exponential step for it to make sense?

meloun67 commented 2 years ago

this looks really good. yes correct. unfortunately, we need also exponential step, otherwise it is nonsence. for the creation of logaritmic scale vector you can use numpy.logspace and then iterate trough it. also you can add question to log base (default 10, but could make sense to use lower base)

svoboad3 commented 2 years ago

Ok done, it works a little bit differently from the original function so I created a new one just for log scale named Loss_Function_Analysis_Log, here is a example of output: image

You now need 4 parameters for x and y axis - start, end, steps and base The axis is then from interval [base**start, base**end] with steps number of steps in between. The closeup will ask you for all those parameters as well. Here are all the parameters (the only difference is in x and y axis parameters): image

Right now, the original function uses itself recursively for the closeup and the log function uses itself for closeup. If you'd like, I can add option to combine them in closeup, for example you could call the original function for the initial analysis and then call log function for closeup of vice versa.

meloun67 commented 2 years ago

Perfect! Yes please, that was the initial idea, that you can switch between them if necessary. Sometimes you could also need to change intervals more than once so it would make sense that program ask you if you want to insert new intervals (ain which scale) after every plot generation... and the last question would be "do you want to save plots in PNG"

meloun67 commented 2 years ago

Ok done, it works a little bit differently from the original function so I created a new one just for log scale named Loss_Function_Analysis_Log, here is a example of output: image

You now need 4 parameters for x and y axis - start, end, steps and base The axis is then from interval [base**start, base**end] with steps number of steps in between. The closeup will ask you for all those parameters as well. Here are all the parameters (the only difference is in x and y axis parameters): image

Right now, the original function uses itself recursively for the closeup and the log function uses itself for closeup. If you'd like, I can add option to combine them in closeup, for example you could call the original function for the initial analysis and then call log function for closeup of vice versa.

Only issue here is that the plot axis does not have log scale... in Matplotlib settings

svoboad3 commented 2 years ago

Ok added choice between logarithmic and linear function. I've put both functions into one file (Loss_Function_Analysis.py) because there was problem with cyclic dependency when they were in separate files and needed to call each other. If you want to import the Loss_Function_Analysis_Log somewhere, just use "from functions.Loss_Function_Analysis import Loss_Function_Analysis_Log".

Please specify what do you mean by "change interval". Right now, you can do as many closeups and changes in intervals as you want, but the "closeup" basically just calculates the whole new graph, but with the new parameters that you input. Generally that would be smaller interval with smaller step for more detail, but you can input larger or just different interval with bigger step and it should work just fine.

Saving to png is tricky, after calling plt.show() the plot is destroyed and you can't save it after. So there are few options which all have some problems:

  1. Ask if you want to save and saving before showing the plot
  2. Recreate the plot the same way and save it after Problem with both of these is if you rotate the graph in the window, it won't show up on the saved png.
  3. The third option is not to do it in code but save if from the plot window, which also saves the rotations you do in the window image You can choose which of these is the least bad 😄

The log scale is also problematic. Just setting xscale or yscale to 'log' plots things like this: image After some googling I found out that its common problem with 3d graphs in matplotlib, that they don't really support log scale or its just buggy. There probably are some workarounds, but they might be more complicated and take longer time to implement.

meloun67 commented 2 years ago

Yeah... so we can leave log scale completely... does not make sense... user will just need to scale it correctly so the actual valley with one minimum will be visible

meloun67 commented 2 years ago

BUG? Step can be less than 1 right? It is not number of steps.

image

svoboad3 commented 2 years ago

Oh yea, for some reason I typed input as int instead of float. Should be fixed now.