The latest develop
version of Melissa has transitioned to using the IterativeStatistics library. This transition comes with an improvement to how the parameter generator is initialized and how parameters are drawn on the backend. As a user, the new parameter generator is defined in the server initializer. So the old code looks like this:
import logging
import random
from melissa.server.sensitivity_analysis import SensitivityAnalysisServer
logger = logging.getLogger("melissa")
random.seed(123)
class HeatPDEServerSA(SensitivityAnalysisServer):
"""
Use-case specific server
"""
def draw_parameters(self):
Tmin, Tmax = self.study_options['parameter_range']
param_set = []
for _ in range(self.study_options['nb_parameters']):
param_set.append(random.uniform(Tmin, Tmax))
return param_set
Which is converted now to the new interface, which easily lets you select any of the generators offered by melissa (or you could attach your own):
import random
from melissa.server.sensitivity_analysis import SensitivityAnalysisServer
from melissa.server.parameters import RandomUniform
from typing import Dict, Any
logger = logging.getLogger("melissa")
random.seed(123)
class HeatPDEServerSA(SensitivityAnalysisServer):
"""
Use-case specific server
"""
def __init__(self, config: Dict[str, Any]):
super().__init__(config)
self.nb_parms = self.study_options['nb_parameters']
Tmin, Tmax = self.study_options['parameter_range']
num_samples = self.study_options['num_samples']
# Example of random uniform sampling
self.parameter_generator = RandomUniform(
nb_parms=self.nb_parms, nb_sim=num_samples,
l_bounds=[Tmin], u_bounds=[Tmax],
second_order=False,
apply_pick_freeze=self.sobol_op
).generator()
# Example of Halton sampling
# self.parameter_generator = HaltonGenerator(nb_parms=self.nb_parms, nb_sim=num_samples,
# l_bounds=[Tmin],u_bounds=[Tmax],second_order=False,
# apply_pick_freeze=self.sobol_op).generator()
# Example of Latin Hypercube Sampling
# self.parameter_generator = LHSGenerator(nb_parms=self.nb_parms, nb_sim=num_samples,
# l_bounds=[Tmin],u_bounds=[Tmax],second_order=False,
# apply_pick_freeze=self.sobol_op).generator()
This means the old draw_parameters()
will no longer work.
Additionally, we have fully verified the IterativeMoments
calculations over on the IterativeStatistics library - all users should update to the new algorithm.