# Iterative statistics update - \[breaking change\]

**URL:** <https://melissa.discourse.group/t/iterative-statistics-update-breaking-change/30>\
**Category:** Software Updates\
**Created:** [June 29, 2023, 12:22pm UTC](https://melissa.discourse.group/t/iterative-statistics-update-breaking-change/30 "2023-06-29T12:22:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rob](https://avatars.discourse-cdn.com/v4/letter/r/838e76/32.png) [@rob](https://melissa.discourse.group/u/rob)\
**Post date:** [June 29, 2023, 12:22pm UTC](https://melissa.discourse.group/t/iterative-statistics-update-breaking-change/30/1 "2023-06-29T12:22:18Z")

</div>

The latest `develop` version of Melissa has transitioned to using the [IterativeStatistics](https://github.com/IterativeStatistics/BasicIterativeStatistics/) 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:

```python
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):

```python
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.
