Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Evaluating the Morris test function is very slow #37

Open
mbaudin47 opened this issue Nov 22, 2019 · 3 comments
Open

Evaluating the Morris test function is very slow #37

mbaudin47 opened this issue Nov 22, 2019 · 3 comments

Comments

@mbaudin47
Copy link
Contributor

mbaudin47 commented Nov 22, 2019

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.

@sofianehaddad
Copy link
Member

sofianehaddad commented Nov 22, 2019

Refer to #7
I do not remember exactly why we decide to drop numpy dependency

I think for unitary tests it is useless to get this vectorized implementation.

@mbaudin47
Copy link
Contributor Author

mbaudin47 commented Feb 23, 2020

  • The performance issue make it useless for use-cases where we need lots of evaluations. This is for example the situation where we want to benchmark the Morris method on the Morris function... This is why when we really need to evaluate the Morris function, we finally have to reimplement it.

  • Removing numpy because of numpy seems strange: there is no way to use OpenTURNS in Python without having numpy anyway. The correct way to remove numpy would be to implement the code in C++.

  • The old implementation relying on numpy was much less efficient than the one I provide.

Please find below a sample working implementation. It is not as fast as I thought.

bench-Morris-function.ipynb.txt

@mbaudin47
Copy link
Contributor Author

Would a SymbolicFunction be faster ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants