Skip to content

Nonuniform distributions for Morris sampling returns inf #515

Closed

Description

@willu47

Thanks to @jyangfsu for the issue submission.

When the parameters follows norm, lognorm and truncnorm distributions, nonuniform_scale_samples function would returns inf.
As suggested by Saltelli et al. (2010), this can be avoid by cutting the tails of , for example, the normal distributions, at quantiles 5 and 95%.
Code in current nonuniform_scale_samples function:

elif dists[i] == 'norm':
    if b2 <= 0:
        raise ValueError("""Normal distribution: stdev must be > 0""")
    else:
        conv_params[:, i] = sp.stats.norm.ppf(params[:, i], loc=b1, scale=b2))

Suggest modifying to:

elif dists[i] == 'norm':
    if b2 <= 0:
        raise ValueError('''Normal distribution: stdev must be > 0''')
    else:
        conv_params[:, i] = scipy.stats.truncnorm.ppf(
            params[:, i], scipy.stats.norm.ppf(0.05, loc=b1, scale=b2), scipy.stats.norm.ppf(0.95, loc=b1, scale=b2), loc=b1, scale=b2)

Activity

  1. ConnectedSystems commented on Aug 21, 2022

    @ConnectedSystems
    Member

    Hi @jyangfsu

    Is the reference below the one you are referring to? I had a quick scan over it but could not see exactly where your suggestion is mentioned so I think you are referring to a different paper.

    Saltelli, A., P. Annoni, I. Azzini, F. Campolongo, M. Ratto, and S. Tarantola (2010).
    "Variance based sensitivity analysis of model output. Design and estimator for the total sensitivity index."
    Computer Physics Communications, 181(2):259-270,
    doi:10.1016/j.cpc.2009.09.018.

  2. jyangfsu commented on Oct 11, 2022

    @jyangfsu
  3. sitadrost commented on Oct 11, 2022

    @sitadrost

    Sorry, bit late to the party, but I just installed SALib (version 1.4.5, which is the newest available through conda) because I was looking for a package to do Morris screening in Python. As my variables are normally distributed, I stumbled into this issue straight off.
    The suggested modification is to use a truncated normal distribution, which sounds sensible, but I don't think the suggested code is quite correct.
    From the truncnorm docs: The standard form of this distribution is a standard normal truncated to the range [a, b], where a and b are user-provided shape parameters. The parameter loc shifts the mean of the underlying normal distribution, and scale controls the standard deviation of the underlying normal, but a and b are still defined with respect to the standard normal.
    So I think the modified code should simply be:

    elif dists[i] == 'norm':
        if b2 <= 0:
            raise ValueError('''Normal distribution: stdev must be > 0''')
        else:
            conv_params[:, i] = scipy.stats.truncnorm.ppf(
                params[:, i], 0.05, 0.95, loc=b1, scale=b2)
    

    Or, to capture 95% of the normal distribution in the truncated version (instead of 90%, like in the code above):

    elif dists[i] == 'norm':
        if b2 <= 0:
            raise ValueError('''Normal distribution: stdev must be > 0''')
        else:
            conv_params[:, i] = scipy.stats.truncnorm.ppf(
                params[:, i], 0.025, 0.975, loc=b1, scale=b2)
    
  4. tupui commented on Oct 11, 2022

    @tupui
    Member

    (version 1.4.5, which is the newest available through conda)

    Thanks for pointing this out. It's surprising to me, the system should have noticed the update on PyPi and make a PR to update to 1.4.6. I will make a PR to update.

  5. ConnectedSystems commented on Oct 11, 2022

    @ConnectedSystems
    Member

    Thanks @tupui - I made a mental note to check on the conda feedstock after the 1.4.6 release but obviously it had left my mind when I woke in the morning.

  6. tupui commented on Oct 11, 2022

    @tupui
    Member
  7. sitadrost commented on Oct 18, 2022

    @sitadrost

    Woops, I just noticed that the modified code that I proposed last week doesn't give the results you'd expect: it returns values between the mean (b1) and the mean + 1x standard deviation (b2), instead of values ranging from (b1 - 2 x b2) to (b1 + 2 x b2), like you'd expect for a normal distribution. Not quite sure yet where exactly this goes wrong, have you looked at this in the meantime?

  8. ConnectedSystems commented on Oct 18, 2022

    @ConnectedSystems
    Member

    Thanks @sitadrost , I'll try to make some time to have a look this weekend.

  9. sitadrost commented on Oct 18, 2022

    @sitadrost

    Ah, of course, so silly of me: truncnorm works with a standard normal distribution, so the code to capture 95% of the desired normal distribution (mean plus/minus 2 x standard deviation) should be:

    elif dists[i] == 'norm':
        if b2 <= 0:
            raise ValueError('''Normal distribution: stdev must be > 0''')
        else:
            conv_params[:, i] = scipy.stats.truncnorm.ppf(
                params[:, i], -2, 2, loc=b1, scale=b2)
    
  10. ConnectedSystems commented on Dec 3, 2022

    @ConnectedSystems
    Member

    Apologies for the long silence on this issue, short on time these days.

    I suspect that the suggested code will have implications for other sampling approaches, as the scaling is not used for just the Morris method. The suggested changes cause the test for the Oakley function to fail, as an example. This test uses LHS and expects all parameters to be normally distributed.

    I think in this case, would it be advisable to just direct users to specify truncnorm rather than norm with whatever tail cut-off is desired.

    That said, I'm not sure this is the "best" solution. For example, where to signpost not to use norm for normally distributed factors in the case of Morris? I could put in a warning/error for users of the ProblemSpec interface, and assume those using the functions directly are power users who know what they're doing...

    Any thoughts here @willu47 @tupui ?

  11. khairulislam commented on Sep 2, 2023

    @khairulislam

    Hi, I am facing the same issue in the latest version. Has it been solved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions