Code Monkey home page Code Monkey logo

otmorris's Introduction

otmorris's People

Contributors

adumasphi avatar dbarbier avatar jschueller avatar openturns-appveyor avatar sofianehaddad avatar yomgarcia avatar

Watchers

 avatar  avatar  avatar  avatar

otmorris's Issues

Example 1 from OTMorris documentation fails

Here is the problematic example: http://openturns.github.io/otmorris/master/examples/examples.html#example-1-morris-use-case-and-p-level-input-grid

The documentation has two problems. The first problem is that this line in the example:

ee = otmorris.Morris(X, Y)

leads to the following errors:

TypeError: Wrong number or type of arguments for overloaded function 'new_Morris'.
  Possible C/C++ prototypes are:
    OTMORRIS::Morris::Morris()
    OTMORRIS::Morris::Morris(OT::Sample const &,OT::Sample const &,OT::Interval const &)
    OTMORRIS::Morris::Morris(OTMORRIS::MorrisExperiment const &,OT::Function const &)
    OTMORRIS::Morris::Morris(OTMORRIS::Morris const &)

This appears to be fixable by changing the line to the following:

bounds = morris_experiment.getBounds()
ee = otmorris.Morris(X, Y, bounds)

The second problem is discussed in issue #26.

Documentation for Morris is inconsistent about the available constructors

The documentation in question is here: http://openturns.github.io/otmorris/master/user_manual/_generated/otmorris.Morris.html#otmorris.Morris

The top of the documentation indicates that there are two constructors with the following signatures:

Morris(inputSample, outputSample, interval)
Morris(experiment, model)

However, later text indicates that there are five constructors:

With first constructor, we consider that input experiment has been generated thanks to the MorrisExperiment and output is evaluated outside the platform. With second constructor, we consider that initial experiment is a regular grid defined in $[0,1]^d$. With thirds constructor, we consider that initial distribution model is uniform with bounds given by the interval argument. Also, the initial experiment is of type regular. With fourth constructor, we fix the initial design which could be an LHS, an optimal LHS defined in $[0,1]^d$. With fifth constructor, we fix the initial design which could be an LHS, an optimal LHS defined in $[0,1]^d$.

Evaluating the Morris test function is very slow

The following code uses vectorized statements and is much faster:

def Morris_function(x):
    delta=np.zeros((20,20,20)); delta[:5,:5,:5].fill(-10)
    	gamma=np.zeros((20,20,20,20)); gamma[:4,:4,:4,:4].fill(5)
    W=np.sum(alpha.reshape(-1,1)*w(x))
    W1=np.sum(beta*(w(x).reshape(1,-1)*w(x))*(np.arange(20).reshape(-1,1)<np.arange(20)))
    W2=np.sum(delta*(w(x).reshape(-1,1,1)*w(x).reshape(1,-1,1)*w(x).reshape(1,1,-1))*(np.arange(20).reshape(-1,1,1)<np.arange(20).reshape(1,-1,1))*(np.arange(20).reshape(1,-1,1)<np.arange(20).reshape(1,1,-1)))
    W3=np.sum(gamma*(w(x).reshape(-1,1,1,1)*w(x).reshape(1,-1,1,1)*w(x).reshape(1,1,-1,1)*w(x).reshape(1,1,1,-1))*(np.arange(20).reshape(-1,1,1,1)<np.arange(20).reshape(1,-1,1,1))*(np.arange(20).reshape(1,-1,1,1)<np.arange(20).reshape(1,1,-1,1))*(np.arange(20).reshape(1,1,-1,1)<np.arange(20).reshape(1,1,1,-1)))
    y=W+W1+W2+W3+float(b0)
    return y

However, the current implementation has no unit tests. This makes changing the implementation unconformable.

PlotEE generates an error

The script

import openturns as ot
import otmorris

# Define model
ot.RandomGenerator.SetSeed(1)
g = ot.Function(otmorris.MorrisFunction())

# Number of trajectories
r = 10
# Define experiments in [0,1]^20
# p-levels
p = 5
morris_experiment = otmorris.MorrisExperimentGrid([p] * 20, r)
grid_bound = morris_experiment.getBounds()
X = morris_experiment.generate()

n = X.getSize()

Y = g(X)

# Evaluate Elementary effects (ee)
ee = otmorris.Morris(X, Y, grid_bound)

otmorris.plot_sensitivity.PlotEE(ee)

generates the error:

No handles with labels found to put in legend.

This is otmorris '0.5'

fullDesignSize overflow for large dimension

It can happen fullDesignSize gets overflowed when dealing with a large dimension problem
I propose the following simple fix

void MorrisExperimentGrid::setJumpStep(const Indices & jumpStep)
   // Update the jump step and check that we still might generate N_ trajectories
   // Compute step & number of total possibilities
   // Depending on direction
-  UnsignedInteger fullDesignSize = 2;
+  Scalar fullDesignSize = 2.;
   for (UnsignedInteger k = 0; k < jumpStep.getSize(); ++k)
   {
     const UnsignedInteger one = 1;

MorrisFunction undocumented

The MorrisFunction function is used in the examples. It has docstrings, but it does not appear in the Sphynx documentation.

Module installation

Installing the otmorris module is always a nightmare, because there is only a conda package.

  1. Installing it requires to install the openturns version from conda, which is very long.

  2. To make the plots work, another module is required, which is not automatically installed:

sudo apt-get install dvipng
  1. Even with this setup, I have the following error that I do not understand:
$ conda install -c conda-forge otmorris
Collecting package metadata (current_repodata.json): done
Solving environment: done
==> WARNING: A newer version of conda exists. <==
  current version: 4.8.3
  latest version: 4.9.2
Please update conda by running
    $ conda update -n base -c defaults conda
# All requested packages already installed.
$ python
Python 3.8.3 (default, May 19 2020, 18:47:26) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import otmorris
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'otmorris'

My questions:

  • What is the cause of that error?
  • Is there any way to create a pip package? It would be much easier and faster.

MorrisExperimentGrid hangs

Seems the while loop hangs when there are not enough trajectories under certain conditions (dim=1, levels=[5], n_traj=10):

from __future__ import print_function
import openturns as ot
import otmorris

# Use Case 1 : define a k-grid level (so delta = 1/(k-1))
r = 10
morris_experiment = otmorris.MorrisExperimentGrid([5], r)
X = morris_experiment.generate()
print("Morris experiment generated from grid = ", X)

Here we enforce unique trajectories.
solution: compute the number of possible trajectories: (d-1)^d modulo the jumpstep wrt out of bound.

The generate method of MorrisExperimentGrid fails

The following script fails with OT 1.14:

import openturns as ot
import otmorris

# Define model
ot.RandomGenerator.SetSeed(1)
b0 = ot.DistFunc.rNormal()
alpha = ot.DistFunc.rNormal(10)
beta = ot.DistFunc.rNormal(6*14)
gamma = ot.DistFunc.rNormal(20*14)
g = ot.Function(otmorris.MorrisFunction(alpha, beta, gamma, b0))

dim = g.getInputDimension()

# Number of trajectories
r = 10
# Define experiments in [0,1]^20
# p-levels
p = 5
morris_experiment = otmorris.MorrisExperimentGrid([p] * dim, r)
grid_bound = morris_experiment.getBounds()
X = morris_experiment.generate()
print(X)

with

double free or corruption (out)
Aborted (core dumped)

This test is with

  • openturns : 1.14
  • otmorris : 0.7

MorrisExperimentLHS segfaults

The following script segfaults with otmorris 0.7 on OS X installed via conda:

import openturns as ot
import otmorris
X = ot.LHSExperiment(ot.ComposedDistribution([ot.Uniform(0,1)]*4), 50, False, False).generate()
morris_experiment = otmorris.MorrisExperimentLHS(X, 10)
morris_experiment.generate()

The same code using cd0423c has no issue on OS X (compiled on by laptop).

It seems that bug is conda related?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.