Exemplo n.º 1
0
from compare_true_coefs import get_true_coefs as gtc
from compare_true_coefs import get_computed_coefs as gcc

import numpy as np

true_coefs, J = gtc("smallTestsPoisson", None)
print type(J)
estimations, other_J = gcc("smallTestsPoisson", None, J) # other_J should be the same as J itself
sorted_true = np.sort(np.abs(true_coefs))[::-1]
sorted_estimations = np.sort(np.abs(estimations.tolist()))[::-1]
print sorted_true[0:10]
print sorted_estimations[0:10]

J = np.asarray(J)
other_J = np.asarray(other_J)

d = 10
a_nu = [0,0,0,0,0,0,0,0,0,0]
another_nu = [1,0,0,0,0,0,0,0,0,0]
find_idx = np.array(np.sum(J == a_nu, axis = 1))
cur_idx_true = find_idx.tolist().index(d)
find_idx = np.array(np.sum(other_J == a_nu, axis = 1))
cur_idx_estimations = find_idx.tolist().index(d)
# print("First coefficient estimated as position {0} and with value {1} in the true coefficients, while it has position {2} and value {3} in the estimated coefficients".format(cur_idx_true, sorted_true[cur_idx_true], cur_idx_estimations, sorted_estimations[cur_idx_estimations]))

find_idx = np.array(np.sum(J == another_nu, axis = 1))
cur_idx_true = find_idx.tolist().index(d)
find_idx = np.array(np.sum(other_J == another_nu, axis = 1))
cur_idx_estimations = find_idx.tolist().index(d)
# print("Second coefficient estimated as position {0} and with value {1} in the true coefficients, while it has position {2} and value {3} in the estimated coefficients".format(cur_idx_true, sorted_true[cur_idx_true], cur_idx_estimations, sorted_estimations[cur_idx_estimations]))
import time

import os.path

import scipy.integrate as spi

from compare_true_coefs import get_computed_coefs as gcc
from iterative_solution import compute_true_avg_alternate as cta
from multivariate_chebpoly import multi_var_chebpoly as mvc


# sp.integrate.quad(f,a,b)
# cta(ys, rhs, variability, mean_field)

# first get the computed coefficients as well as the set of all potential candidate coefficients
computed_coefs, other_J = gcc(infile, None, J) # other_J should be the same as J.

# For every multi index in J,
# Compute (numerical integration) the estimated coefficient
# Compare! 
c_nus = np.zeros(len(other_J))
for idx, one_nu in enumerate(other_J):
    # Construct the current Chebychef polynomial with the associated weight
    for nu_j in one_nu:
        if nu_j

spi.nquad(lambda x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12: cta(np.array([x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12]), 1.0, 1.0/13, 5.0 )*mvc([x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12],a_nu),[[-1,1]]*13)
# compute_true_avg(ys, rhs, variability, mean_field):

spi.nquad(lambda x0, x1: cta(np.array([x0,x1,0.01,-0.1,-0.02,0,0,0.02,0,0,0,0,0]).transpose(), 1.0, 1.0/13, 5.0 )*mvc([x0,x1,0.01,-0.1,-0.02,0,0,0.02,0,0,0,0,0],a_nu),[[-1,1]]*2)
Exemplo n.º 3
0
from compare_true_coefs import get_computed_coefs as gcc
from num_int import coefs_MC_wrapper as cmw
import numpy as np
import math 

infile = 'smallDim6_PWLD_whtp_var_small_grid2000_L3_g105_datconstant20'
outfile = 'testingMCint_smallvar_datconstant20'

estimated_coefs, J = gcc(infile,outfile, J = None)

nb_tests = [10000, 100000, 1000000, 10000000]

print '\t\t Comparison MC vs l1 recovery\n'
print '\t nu \t\tMC 10000 \t\tMC 100000\t\tMC 1000000\t\tMC 10000000\t\tl1value \t\t Abs error'

for idx_nu, one_nu in enumerate(J): 
    if np.sum(one_nu) < 4: # We'll display only the nus with relatively low degrees
        values = np.zeros(len(nb_tests))
        for idx, nmc in enumerate(nb_tests):
            values[idx] = cmw(nmc, one_nu, False, 1.0, 1./6., 5.)
        print '{}\t\t {:.5f}\t\t {:.5f}\t\t {:.5f}\t\t {:.5f}\t\t {:.5f}\t\t {}'.format(one_nu,values[0], values[1], values[2], values[3], estimated_coefs[idx_nu], abs(values[3]-estimated_coefs[idx_nu]))