In [8]:
import openturns as ot
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

%matplotlib inline
%load_ext autoreload
%autoreload 2

random_state = 123
np.random.seed(random_state)

In [9]:
from depimpact.tests import func_sum

In [10]:
import skopt

In [11]:
dim = 2
margins = [ot.Normal()]*dim

In [12]:
families = np.zeros((dim, dim), dtype=np.int)
families[1, 0] = 1

In [13]:
from depimpact import ConservativeEstimate

quant_estimate = ConservativeEstimate(model_func=func_sum, margins=margins, families=families)

In [7]:
y, x = quant_estimate.stochastic_function(0.1)

In [ ]:
f = lambda x: quant_estimate.stochastic_function(x, return_input_sample=False)[0][0]

In [ ]:
res = skopt.gp_minimize(f, [(-0.9, 0.9)])

In [53]:
res.x


Out[53]:
[-0.03227160834720539]

In [ ]:
res = gp_minimize(f,                  # the function to minimize
                  [(-.99, .99)],      # the bounds on each dimension of x
                  acq_func="EI",      # the acquisition function
                  n_calls=15,         # the number of evaluations of f 
                  n_random_starts=5,  # the number of random initialization points
                  noise=0.1**2,       # the noise level (optional)
                  random_state=123)   # the random seed

In [14]:
from depimpact.tests.test_dependence import test_additive_gaussian_gridsearch

In [15]:
QUANTILES_PROB = [0.05, 0.01]
PROB_THRESHOLDS = [1., 2.]
DIMENSIONS = range(2, 4)

In [16]:
test_additive_gaussian_gridsearch()


oui
oui
---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
<ipython-input-16-2058272fb779> in <module>()
----> 1 test_additive_gaussian_gridsearch()

~/git-repo/dep-impact/dependence/tests/test_dependence.py in test_additive_gaussian_gridsearch()
    147                 assert_allclose(empirical_quantiles, true_quantile, rtol=1e-01,
    148                                 err_msg="Failed with alpha = {0}, dim = {1}"\
--> 149                                 .format(alpha, dim))
    150 
    151                 # Probability results

~/anaconda3/lib/python3.6/site-packages/numpy/testing/utils.py in assert_allclose(actual, desired, rtol, atol, equal_nan, err_msg, verbose)
   1409     header = 'Not equal to tolerance rtol=%g, atol=%g' % (rtol, atol)
   1410     assert_array_compare(compare, actual, desired, err_msg=str(err_msg),
-> 1411                          verbose=verbose, header=header, equal_nan=equal_nan)
   1412 
   1413 

~/anaconda3/lib/python3.6/site-packages/numpy/testing/utils.py in assert_array_compare(comparison, x, y, err_msg, verbose, header, precision, equal_nan)
    794                                 names=('x', 'y'), precision=precision)
    795             if not cond:
--> 796                 raise AssertionError(msg)
    797     except ValueError:
    798         import traceback

AssertionError: 
Not equal to tolerance rtol=0.1, atol=0
Failed with alpha = 0.05, dim = 3
(mismatch 40.0%)
 x: array([-3.562561, -1.715965, -2.008657, -1.547489, -4.880618])
 y: array([-3.049226, -1.729682, -2.227923, -1.345605, -4.638888])

In [ ]:


In [18]:
from depimpact.utils import quantile_func
n_params = 5
n_input_sample = 10000
alpha = 0.05
grid = 'lhs'
# Only Gaussian families
families = np.tril(np.ones((dim, dim)), k=1)

impact = ConservativeEstimate(model_func=func_sum,
                          margins=[ot.Normal()]*dim,
                          families=np.ones((dim, dim)))

dep_results = impact.gridsearch_minimize(
n_dep_param=n_params, 
n_input_sample=n_input_sample, 
grid_type=grid, 
random_state=0)

# Quantile results
dep_results.q_func = quantile_func(alpha)
empirical_quantiles = dep_results.quantities

In [19]:
dep_results[0].input_sample.ndim


Out[19]:
2

In [20]:
from scipy.stats import gaussian_kde

In [21]:
y = func_sum(dep_results[0].input_sample)

In [42]:
from statsmodels.distributions import empirical_distribution

In [ ]:
empirical_distribution.

In [23]:
res = dep_results[0]

In [43]:
res.compute_quantity_bootstrap_ci()


Out[43]:
[-0.5319762250253914, -0.5100326594062616]

In [44]:
res.compute_quantity_asymptotic_ci('quantile', alpha)


Out[44]:
[-0.53440826270951625, -0.50856908155630187]

In [45]:
dep_results[0].compute_bootstrap()