In [1]:
import itertools
import openturns as ot
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from depimpact.tests import func_sum
from depimpact.tests.test_functions import func_cum_sum_weight, func_spec
from depimpact import ConservativeEstimate
from dependence import quantile_func
from dependence import iterative_vine_minimize
from depimpact.dependence_plot import matrix_plot_input, matrix_plot_quantities
from depimpact.dependence_plot import plot_iterative_results
from depimpact.dependence_plot import set_style_paper

%matplotlib inline
%load_ext autoreload
%autoreload 2

random_state = 12
np.random.seed(random_state)

In [2]:
dim = 11
margins = []
for i in range(dim):
    margins.append(ot.Uniform(0, 1.))
    
margins[0] = ot.Uniform(0, 1.)
alpha = 0.1
q_func = quantile_func(alpha)
families = np.tril(np.ones((dim, dim)), k=1)

In [3]:
n_influencial_pairs = 2
val_influencial = 1.
val_non_influencial = 0.0
corr_dim = int(dim * (dim-1)/2)

all_pairs = np.asarray(list(itertools.combinations(range(dim), 2)))
selected_pairs = all_pairs[np.random.choice(range(corr_dim), size=n_influencial_pairs, replace=False)]
selected_pairs = np.asarray([[0, dim-2], [1, dim-2], [2, dim-2]])
# selected_pairs = all_pairs

power = np.zeros((dim, dim))
for i in range(1, dim):
    for j in range(i):
        if [j, i] in selected_pairs.tolist():
            print([i, j])
            power[i, j] = val_influencial
        else:
            power[i, j] = val_non_influencial
test_func = lambda x: func_cum_sum_weight(x, power)
print(power)


[9, 0]
[9, 1]
[9, 2]
[[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 1.  1.  1.  0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.]]

In [4]:
n = 30000
quant_estimate = ConservativeEstimate(model_func=test_func, margins=margins, families=families)
indep_result = quant_estimate.independence(n_input_sample=n, q_func=q_func, random_state=random_state)
print(indep_result.quantity)


3.6642255623937565

In [5]:
algorithm_parameters = {
    "n_input_sample": 2000,
    "n_dep_param_init": 10,
    "max_n_pairs": 4,
    "grid_type": 'vertices',
    "q_func": q_func,
    "delta": 0.1,
    "n_add_pairs": 1,
    "n_remove_pairs": 0,
    "adapt_vine_structure": True,
    "with_bootstrap": False,
    "verbose": True,
    "iterative_save": False,
    "iterative_load": False,
    "load_input_samples": False,
    "keep_input_samples": True
}

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

iterative_results = iterative_vine_minimize(estimate_object=quant_estimate, **algorithm_parameters)


n=1000. Worst quantile of [(1, 0)] at 3.5331324220892055
n=1000. Worst quantile of [(2, 0)] at 3.2299335175929267
n=1000. Worst quantile of [(2, 1)] at 3.137913973982039
n=1000. Worst quantile of [(3, 0)] at 3.57961593175833
n=1000. Worst quantile of [(3, 1)] at 3.4526632880349792
n=1000. Worst quantile of [(3, 2)] at 3.595911799895477
n=1000. Worst quantile of [(4, 0)] at 3.623211730440386
n=1000. Worst quantile of [(4, 1)] at 3.6153632839879033
n=1000. Worst quantile of [(4, 2)] at 3.546685582320432
n=1000. Worst quantile of [(4, 3)] at 3.546622534976465
n=1000. Worst quantile of [(5, 0)] at 3.54835143548676
n=1000. Worst quantile of [(5, 1)] at 3.6337044455129535
n=1000. Worst quantile of [(5, 2)] at 3.5607412569957915
n=1000. Worst quantile of [(5, 3)] at 3.657958199495497
n=1000. Worst quantile of [(5, 4)] at 3.697558807825415
n=1000. Worst quantile of [(6, 0)] at 3.492616956594038
n=1000. Worst quantile of [(6, 1)] at 3.612020045113228
n=1000. Worst quantile of [(6, 2)] at 3.5647168105887244
n=1000. Worst quantile of [(6, 3)] at 3.726695951129894
n=1000. Worst quantile of [(6, 4)] at 3.6388532805692373
n=1000. Worst quantile of [(6, 5)] at 3.5125765671123395
n=1000. Worst quantile of [(7, 0)] at 3.563924426744744
n=1000. Worst quantile of [(7, 1)] at 3.452179431531678
n=1000. Worst quantile of [(7, 2)] at 3.666785485647172
n=1000. Worst quantile of [(7, 3)] at 3.6477375442143205
n=1000. Worst quantile of [(7, 4)] at 3.503212478972783
n=1000. Worst quantile of [(7, 5)] at 3.4725929296395077
n=1000. Worst quantile of [(7, 6)] at 3.5192669484921795
n=1000. Worst quantile of [(8, 0)] at 3.6023028364887764
n=1000. Worst quantile of [(8, 1)] at 3.563616685602323
n=1000. Worst quantile of [(8, 2)] at 3.4909301450789356
n=1000. Worst quantile of [(8, 3)] at 3.672657792345465
n=1000. Worst quantile of [(8, 4)] at 3.5843939641046214
n=1000. Worst quantile of [(8, 5)] at 3.594774372858575
n=1000. Worst quantile of [(8, 6)] at 3.525711884861244
n=1000. Worst quantile of [(8, 7)] at 3.511302899391533
n=1000. Worst quantile of [(9, 0)] at 2.9161396229012424
n=1000. Worst quantile of [(9, 1)] at 2.996950391019082
n=1000. Worst quantile of [(9, 2)] at 2.8313852930366066
n=1000. Worst quantile of [(9, 3)] at 3.473445445865253
n=1000. Worst quantile of [(9, 4)] at 3.5256145807396333
n=1000. Worst quantile of [(9, 5)] at 3.5864323326876137
n=1000. Worst quantile of [(9, 6)] at 3.500552157224889
n=1000. Worst quantile of [(9, 7)] at 3.456120834863631
n=1000. Worst quantile of [(9, 8)] at 3.519749859018176
n=1000. Worst quantile of [(10, 0)] at 3.5626968703502935
n=1000. Worst quantile of [(10, 1)] at 3.4890629014790626
n=1000. Worst quantile of [(10, 2)] at 3.6033035352400677
n=1000. Worst quantile of [(10, 3)] at 3.548586673059786
n=1000. Worst quantile of [(10, 4)] at 3.4974955121677676
n=1000. Worst quantile of [(10, 5)] at 3.6271109080328925
n=1000. Worst quantile of [(10, 6)] at 3.45294942932229
n=1000. Worst quantile of [(10, 7)] at 3.40302990827647
n=1000. Worst quantile of [(10, 8)] at 3.478793346910467
n=1000. Worst quantile of [(10, 9)] at 3.5994144960322147

Iteration 1: selected pair: (9, 2)
Total number of evaluations = 165000. Minimum quantity at 2.83.

n=1000. Worst quantile of [(9, 2), (1, 0)] at 2.745134021602488
n=1000. Worst quantile of [(9, 2), (2, 0)] at 2.341872815600428
n=1000. Worst quantile of [(9, 2), (2, 1)] at 2.265515183410408
n=1000. Worst quantile of [(9, 2), (3, 0)] at 2.919110599884667
n=1000. Worst quantile of [(9, 2), (3, 1)] at 2.9371580164968107
n=1000. Worst quantile of [(9, 2), (3, 2)] at 2.878136071626766
n=1000. Worst quantile of [(9, 2), (4, 0)] at 2.813925062665435
n=1000. Worst quantile of [(9, 2), (4, 1)] at 2.9116948080016294
n=1000. Worst quantile of [(9, 2), (4, 2)] at 2.894245880513068
n=1000. Worst quantile of [(9, 2), (4, 3)] at 2.8619611168998547
n=1000. Worst quantile of [(9, 2), (5, 0)] at 2.804511485127277
n=1000. Worst quantile of [(9, 2), (5, 1)] at 2.8100969848051838
n=1000. Worst quantile of [(9, 2), (5, 2)] at 2.7821987413176403
n=1000. Worst quantile of [(9, 2), (5, 3)] at 2.8641253358348138
n=1000. Worst quantile of [(9, 2), (5, 4)] at 2.8779091835499746
n=1000. Worst quantile of [(9, 2), (6, 0)] at 2.8612948146140917
n=1000. Worst quantile of [(9, 2), (6, 1)] at 2.7074192155655057
n=1000. Worst quantile of [(9, 2), (6, 2)] at 2.963405555709257
n=1000. Worst quantile of [(9, 2), (6, 3)] at 2.732880628428821
n=1000. Worst quantile of [(9, 2), (6, 4)] at 2.8720934724767475
n=1000. Worst quantile of [(9, 2), (6, 5)] at 2.8458504286242428
n=1000. Worst quantile of [(9, 2), (7, 0)] at 2.8523986433384563
n=1000. Worst quantile of [(9, 2), (7, 1)] at 2.8743604571323442
n=1000. Worst quantile of [(9, 2), (7, 2)] at 2.983489780224727
n=1000. Worst quantile of [(9, 2), (7, 3)] at 2.9034399991634166
n=1000. Worst quantile of [(9, 2), (7, 4)] at 2.727213530295274
n=1000. Worst quantile of [(9, 2), (7, 5)] at 2.8529012998584573
n=1000. Worst quantile of [(9, 2), (7, 6)] at 2.885740542091375
n=1000. Worst quantile of [(9, 2), (8, 0)] at 2.823995904839974
n=1000. Worst quantile of [(9, 2), (8, 1)] at 2.7956708311436484
n=1000. Worst quantile of [(9, 2), (8, 2)] at 2.7846243090051663
n=1000. Worst quantile of [(9, 2), (8, 3)] at 2.8758111819181047
n=1000. Worst quantile of [(9, 2), (8, 4)] at 2.8225096284876035
n=1000. Worst quantile of [(9, 2), (8, 5)] at 2.7356847939683733
n=1000. Worst quantile of [(9, 2), (8, 6)] at 2.706844649838325
n=1000. Worst quantile of [(9, 2), (8, 7)] at 2.8325978963941605
n=1000. Worst quantile of [(9, 2), (9, 0)] at 2.1888805105187354
n=1000. Worst quantile of [(9, 2), (9, 1)] at 2.271582451803286
n=1000. Worst quantile of [(9, 2), (9, 3)] at 2.821009375644768
n=1000. Worst quantile of [(9, 2), (9, 4)] at 2.955694619891932
n=1000. Worst quantile of [(9, 2), (9, 5)] at 2.8719684203880296
n=1000. Worst quantile of [(9, 2), (9, 6)] at 2.8814635405725735
n=1000. Worst quantile of [(9, 2), (9, 7)] at 2.844781317332844
n=1000. Worst quantile of [(9, 2), (9, 8)] at 2.708764062385319
n=1000. Worst quantile of [(9, 2), (10, 0)] at 2.8929123312579055
n=1000. Worst quantile of [(9, 2), (10, 1)] at 2.9423106692629233
n=1000. Worst quantile of [(9, 2), (10, 2)] at 2.8731197110082816
n=1000. Worst quantile of [(9, 2), (10, 3)] at 2.8908539521264602
n=1000. Worst quantile of [(9, 2), (10, 4)] at 3.007438707701606
n=1000. Worst quantile of [(9, 2), (10, 5)] at 2.8103872337604554
n=1000. Worst quantile of [(9, 2), (10, 6)] at 2.7269320001978574
n=1000. Worst quantile of [(9, 2), (10, 7)] at 2.948857709294291
n=1000. Worst quantile of [(9, 2), (10, 8)] at 2.8923871198337348
n=1000. Worst quantile of [(9, 2), (10, 9)] at 2.725182261673443

Iteration 2: selected pair: (9, 0)
Total number of evaluations = 651000. Minimum quantity at 2.19.

n=1000. Worst quantile of [(9, 2), (9, 0), (1, 0)] at 2.3225774738809375
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 0)] at 2.9131226252016345
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1)] at 1.5828822088590453
n=1000. Worst quantile of [(9, 2), (9, 0), (3, 0)] at 2.1568828651717604
n=1000. Worst quantile of [(9, 2), (9, 0), (3, 1)] at 2.936039744554313
n=1000. Worst quantile of [(9, 2), (9, 0), (3, 2)] at 2.251407421263139
n=1000. Worst quantile of [(9, 2), (9, 0), (4, 0)] at 2.805815084263191
n=1000. Worst quantile of [(9, 2), (9, 0), (4, 1)] at 2.2443164742159447
n=1000. Worst quantile of [(9, 2), (9, 0), (4, 2)] at 2.276891018281506
n=1000. Worst quantile of [(9, 2), (9, 0), (4, 3)] at 2.379955213021379
n=1000. Worst quantile of [(9, 2), (9, 0), (5, 0)] at 2.1302614444365564
n=1000. Worst quantile of [(9, 2), (9, 0), (5, 1)] at 2.362159458162522
n=1000. Worst quantile of [(9, 2), (9, 0), (5, 2)] at 2.293289943370735
n=1000. Worst quantile of [(9, 2), (9, 0), (5, 3)] at 2.20293343766491
n=1000. Worst quantile of [(9, 2), (9, 0), (5, 4)] at 2.1611089199384
n=1000. Worst quantile of [(9, 2), (9, 0), (6, 0)] at 2.3370255517880447
n=1000. Worst quantile of [(9, 2), (9, 0), (6, 1)] at 2.958003871555611
n=1000. Worst quantile of [(9, 2), (9, 0), (6, 2)] at 2.4291451529304284
n=1000. Worst quantile of [(9, 2), (9, 0), (6, 3)] at 2.245687789764054
n=1000. Worst quantile of [(9, 2), (9, 0), (6, 4)] at 2.298694656158599
n=1000. Worst quantile of [(9, 2), (9, 0), (6, 5)] at 2.2354052980730765
n=1000. Worst quantile of [(9, 2), (9, 0), (7, 0)] at 2.3051348201043336
n=1000. Worst quantile of [(9, 2), (9, 0), (7, 1)] at 2.3306184503034286
n=1000. Worst quantile of [(9, 2), (9, 0), (7, 2)] at 2.4098563550884946
n=1000. Worst quantile of [(9, 2), (9, 0), (7, 3)] at 2.2262911907113807
n=1000. Worst quantile of [(9, 2), (9, 0), (7, 4)] at 2.31869492042032
n=1000. Worst quantile of [(9, 2), (9, 0), (7, 5)] at 2.1831632408657122
n=1000. Worst quantile of [(9, 2), (9, 0), (7, 6)] at 2.296512687480301
n=1000. Worst quantile of [(9, 2), (9, 0), (8, 0)] at 2.2189854891689484
n=1000. Worst quantile of [(9, 2), (9, 0), (8, 1)] at 2.3382208956041795
n=1000. Worst quantile of [(9, 2), (9, 0), (8, 2)] at 2.8402321856917534
n=1000. Worst quantile of [(9, 2), (9, 0), (8, 3)] at 2.3016311544004244
n=1000. Worst quantile of [(9, 2), (9, 0), (8, 4)] at 2.235069107597012
n=1000. Worst quantile of [(9, 2), (9, 0), (8, 5)] at 2.3828225781864742
n=1000. Worst quantile of [(9, 2), (9, 0), (8, 6)] at 2.2422294486988172
n=1000. Worst quantile of [(9, 2), (9, 0), (8, 7)] at 2.857699154520396
n=1000. Worst quantile of [(9, 2), (9, 0), (9, 1)] at 1.728997308407373
n=1000. Worst quantile of [(9, 2), (9, 0), (9, 3)] at 2.223164599638314
n=1000. Worst quantile of [(9, 2), (9, 0), (9, 4)] at 2.129190755734873
n=1000. Worst quantile of [(9, 2), (9, 0), (9, 5)] at 2.3056760308094812
n=1000. Worst quantile of [(9, 2), (9, 0), (9, 6)] at 2.136449209391537
n=1000. Worst quantile of [(9, 2), (9, 0), (9, 7)] at 2.1985413043270454
n=1000. Worst quantile of [(9, 2), (9, 0), (9, 8)] at 3.0383349686102123
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 0)] at 2.2974703811414363
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 1)] at 2.2345444109966994
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 2)] at 2.205565204189023
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 3)] at 2.9286279117166356
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 4)] at 2.995781697361597
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 5)] at 2.9627777808779028
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 6)] at 2.330327469819232
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 7)] at 2.345967327992018
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 8)] at 2.323272158376063
n=1000. Worst quantile of [(9, 2), (9, 0), (10, 9)] at 2.8602702554940733

Iteration 3: selected pair: (2, 1)
Total number of evaluations = 1181000. Minimum quantity at 1.58.

n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (1, 0)] at 1.7447936976204539
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (2, 0)] at 2.770344458499416
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (3, 0)] at 2.2722007499231585
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (3, 1)] at 2.806492185353645
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (3, 2)] at 1.8052400090590544
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (4, 0)] at 2.2494015198643345
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (4, 1)] at 2.292495763734562
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (4, 2)] at 2.2171397688938255
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (4, 3)] at 2.1998658080744735
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (5, 0)] at 2.3681344620133795
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (5, 1)] at 2.190695049293955
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (5, 2)] at 2.140860996134704
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (5, 3)] at 1.6234480844509138
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (5, 4)] at 1.8328701363454645
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (6, 0)] at 1.6307043537266976
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (6, 1)] at 1.7847779519365572
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (6, 2)] at 1.8315851275211832
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (6, 3)] at 1.7058184776526402
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (6, 4)] at 2.2028577476430624
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (6, 5)] at 1.702506313221308
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (7, 0)] at 1.8617061488365476
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (7, 1)] at 1.816278883565112
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (7, 2)] at 1.7071746971754982
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (7, 3)] at 2.0999148674243537
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (7, 4)] at 1.6965152017715819
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (7, 5)] at 1.6873194509713145
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (7, 6)] at 2.2940049227739596
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (8, 0)] at 2.254137713001235
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (8, 1)] at 2.2102633522883757
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (8, 2)] at 1.8384478276213334
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (8, 3)] at 2.2835508988784055
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (8, 4)] at 2.1818776698713123
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (8, 5)] at 1.7535472542340722
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (8, 6)] at 1.7623912504066814
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (8, 7)] at 2.202924653535151
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (9, 1)] at 2.1789164121931504
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (9, 3)] at 1.827480164883992
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (9, 4)] at 2.358501038970729
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (9, 5)] at 1.7010131080378366
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (9, 6)] at 1.651011861431182
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (9, 7)] at 1.6725236299750277
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (9, 8)] at 2.150842516382113
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 0)] at 2.197532171675464
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 1)] at 1.5739273171437411
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 2)] at 2.0840186185529403
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 3)] at 2.2786529388002443
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 4)] at 1.794461058783647
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 5)] at 1.705295664371869
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 6)] at 2.226402165111347
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 7)] at 1.9108600952592778
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 8)] at 2.3479660994883202
n=1000. Worst quantile of [(9, 2), (9, 0), (2, 1), (10, 9)] at 2.742233220136978

Iteration 4: selected pair: (10, 1)
Total number of evaluations = 2221000. Minimum quantity at 1.57.

Max number of pairs reached
Minimum_variation not fulfiled: 0.01 <= 0.09

In [6]:
K = 1500
n = 10000

In [7]:
grid_type = 'lhs'
grid_result_lhs = quant_estimate.gridsearch(K, n, q_func=q_func, grid_type='lhs', keep_input_samples=True)
print('Cost: {0}, \nMin quantile: {1}\nMean Min Kendall: {2}'.format(K*n, grid_result_lhs.min_result.quantity, np.mean(grid_result_lhs.min_result.kendall_tau)))


Cost: 10000000, 
Min quantile: 1.7533352199454768
Mean Min Kendall: 0.11547000000000002

In [8]:
grid_result_vertices = quant_estimate.gridsearch(K, n, q_func=q_func, grid_type='vertices', keep_input_samples=True)
print('Cost: {0}, \nMin quantile: {1}\nMean Min Kendall: {2}'.format(K*n, grid_result_vertices.min_result.quantity, np.mean(grid_result_vertices.min_result.kendall_tau)))


Cost: 10000000, 
Min quantile: 1.6837098603067162
Mean Min Kendall: 0.12599999999999997

In [9]:
kendalls_lhs = grid_result_lhs.kendalls
kendalls_vertices = grid_result_vertices.kendalls
dev_kendall_lhs = abs(kendalls_lhs).mean(axis=1)
dev_kendall_vertices = abs(kendalls_vertices).mean(axis=1)
quantities_lhs = grid_result_lhs.quantities
quantities_vertices = grid_result_vertices.quantities
quantity_indep = indep_result.quantity

In [10]:
min_kendall_lhs = grid_result_lhs.min_result.kendall_tau
min_kendall_vertices = grid_result_vertices.min_result.kendall_tau
min_dev_kendall_lhs = np.abs(min_kendall_lhs).mean()
min_dev_kendall_vertices = np.abs(min_kendall_vertices).mean()
min_quantity_lhs = grid_result_lhs.min_result.quantity
min_quantity_vertices = grid_result_vertices.min_result.quantity

In [11]:
min_dev_kendalls_iterative = []
min_quantities_iterative = []
min_results_iterative = []
for results_i in iterative_results:
    min_quantity_i = np.inf
    min_dev_kendalls_i = None
    min_result_i = None
    for key in results_i:
        min_quantity = results_i[key].min_quantity
        if min_quantity < min_quantity_i:
            min_quantity_i = min_quantity
            min_dev_kendalls_i = np.mean(results_i[key].min_result.kendall_tau)
            min_result_i = results_i[key].min_result
    min_quantities_iterative.append(min_quantity_i)
    min_dev_kendalls_iterative.append(min_dev_kendalls_i)
    min_results_iterative.append(min_result_i)

In [12]:
set_style_paper()
colors = ['k', 'm', 'c', 'y']
fig, ax = plt.subplots(figsize=(7, 4))    
ax.plot(dev_kendall_lhs, quantities_lhs, 'g.', label='EGS K=%d' % (K))
ax.plot(min_dev_kendall_lhs, min_quantity_lhs, 'go', label='Min EGS')
ax.plot(dev_kendall_vertices, quantities_vertices, 'r.', label='BEGS K=%d' % (min(K, 3**dim-1)))
ax.plot(min_dev_kendall_vertices, min_quantity_vertices, 'ro', label='Min BEGS')
for i in range(len(min_dev_kendalls_iterative)):
    ax.plot(min_dev_kendalls_iterative[i], min_quantities_iterative[i], 'o', color=colors[i], label='Min iteration %d' % (i+1))
ax.plot(0., quantity_indep, 'bo', label='Independence')
ax.legend(loc=0)
ax.set_xlabel('Kendall coefficient deviation')
ax.set_ylabel('Quantile at $\\alpha = %.2f$' % (alpha))
fig.tight_layout()
fig.savefig('./output/few-pairs/multidim_test_quantile_dim_%d_K_%d.pdf' % (dim, K))



In [13]:
plot_iterative_results(iterative_results, indep_result=indep_result, grid_results=grid_result_lhs, q_func=q_func)
plt.savefig('./output/few-pairs/iterative_result_with_grid_%d.pdf' % (K))



In [59]:
fig, ax = plt.subplots(figsize=(7, 4))
sns.distplot(indep_result.output_sample, norm_hist=True, kde=False, bins=80, label='Independence', ax=ax, color='blue')
sns.distplot(min_results_iterative[3].output_sample, norm_hist=True, kde=False, bins=80, label='Worst case iterative', ax=ax, color='red')
ax.legend(loc=0)
ax.set_xlim(0.8, 25)
ax.set_xlabel('$y$')
ax.set_ylabel('$g(y)$')
fig.tight_layout()
fig.savefig('output/few-pairs/histograms.pdf')



In [25]:
matrix_plot_input(grid_result_vertices.min_result)


Out[25]:
<seaborn.axisgrid.PairGrid at 0x7efe40acef98>

In [27]:
matrix_plot_input(min_results_iterative[-1])


Out[27]:
<seaborn.axisgrid.PairGrid at 0x7efe3af83320>

In [ ]:


In [17]:
fig, axes = plt.subplots(dim-1, dim-1, figsize=(3*dim, 2.5*dim), sharex=True, sharey=True)

k = 0
for i in range(dim-1):
    for j in range(i+1):
        ax = axes[i, j] if dim > 2 else axes
        ax.plot(kendalls_lhs[:, k], quantities_lhs, 'g.', label='EGS K=%d' % (K))
        ax.plot(min_kendall_lhs[k], min_quantity_lhs, 'go', label='Min EGS')
        ax.plot(kendalls_vertices[:, k], quantities_vertices, 'r.', label='BEGS K=%d' % (min(K, 3**dim-1)))
        ax.plot(min_kendall_vertices[k], min_quantity_vertices, 'ro', label='Min BEGS')
        ax.plot(0., quantity_indep, 'bo', label='Independence')
        k += 1
        if i == dim-2:
            ax.set_xlabel('Kendall coefficient')
        if j == 0:
            ax.set_ylabel('Quantile at $\\alpha = %.2f$' % (alpha))
        if i == j+1:
            ax.legend(loc=0)
            
fig.tight_layout()
fig.savefig('./output/few-pairs/matrix_plot_multidim_test_quantile_dim_%d_K_%d.pdf' % (dim, K))