<commit_before>"""None"""

import time
import os

import numpy as np

from sklearn.grid_search import ParameterGrid
from sklearn.base import clone

from sklearn.gaussian_process import GaussianProcess

from scipy.stats import norm
from joblib import Parallel, delayed

from utils.state import _save
from utils.functions_2d import f2, f5

from utils.conformal import RRCM, CRR
from utils.KRR import KRR_AB

np.seterr(all="ignore")
BASE_PATH = os.path.join(".", "exp_nongauss_2d")
if not os.path.exists(BASE_PATH):
    os.mkdir(BASE_PATH)

n_jobs, verbose = -1, 0
parallel_ = Parallel(n_jobs=n_jobs, verbose=verbose)

## The levels and the random state
seeds_ = [0xB5066DBC, 0x98E8576F, 0x3161F88E, 0x08CCA9D9,]
random_state = np.random.RandomState(seeds_[2])

levels = np.asanyarray([0.01, 0.05, 0.10, 0.25])[::-1]

## helpers
def _helper(y, A, B, proc=RRCM, levels=levels, parallel=None, n_jobs=1, verbose=0):
    if not isinstance(parallel, Parallel):
        parallel = Parallel(n_jobs=n_jobs, verbose=verbose)

    regions = parallel(delayed(proc)(A[k], B[k], levels=levels)
                       for k in xrange(y.shape[0]))

    hits_ = np.asarray(
        [[np.any(((int_[:, 0] <= target) & (target <= int_[:, 1]))).astype(float)
          for int_ in region]
         for target, region in zip(y, regions)])

    width_ = np.asarray(
        [[np.sum(int_[:, 1] - int_[:, 0]) for int_ in region] for region in regions])
    
    bounds_ = np.asarray(
        [[[int_[:, 0].min(), int_[:, 1].max()] for int_ in region] for region in regions])

    return hits_, width_, bounds_

## Define the grid

true_nugget = [1e-6, 1e-1,]
test_functions = [f2, f5]

grid_ = ParameterGrid(dict(func=test_functions,
                           size=[150, 1500,],
                           nugget=true_nugget,
                           noise=true_nugget,
                           theta0=[1e+1, 1e+2, 1e+3, "auto"]))
## Initialize
kernel = 'rbf' # 'laplacian'
gp = GaussianProcess(beta0=0, normalize=False, corr='squared_exponential')

# Generate input
nd = 2
mesh_ = np.meshgrid(*nd*[np.linspace(0, 1, num=51)])<commit_msg>Critical bugfix<commit_after>"""None"""

import time
import os

import numpy as np

from sklearn.grid_search import ParameterGrid
from sklearn.base import clone

from sklearn.gaussian_process import GaussianProcess

from scipy.stats import norm
from joblib import Parallel, delayed

from utils.state import _save
from utils.functions_2d import f2, f5

from utils.conformal import RRCM, CRR
from utils.KRR import KRR_AB

np.seterr(all="ignore")
BASE_PATH = os.path.join(".", "exp_nongauss_2d_25")
if not os.path.exists(BASE_PATH):
    os.mkdir(BASE_PATH)

n_jobs, verbose = -1, 0
parallel_ = Parallel(n_jobs=n_jobs, verbose=verbose)

## The levels and the random state
seeds_ = [0xB5066DBC, 0x98E8576F, 0x3161F88E, 0x08CCA9D9,]
random_state = np.random.RandomState(seeds_[2])

levels = np.asanyarray([0.01, 0.05, 0.10, 0.25])[::-1]

## helpers
def _helper(y, A, B, proc=RRCM, levels=levels, parallel=None, n_jobs=1, verbose=0):
    if not isinstance(parallel, Parallel):
        parallel = Parallel(n_jobs=n_jobs, verbose=verbose)

    regions = parallel(delayed(proc)(A[k], B[k], levels=levels)
                       for k in xrange(y.shape[0]))

    hits_ = np.asarray(
        [[np.any(((int_[:, 0] <= target) & (target <= int_[:, 1]))).astype(float)
          for int_ in region]
         for target, region in zip(y, regions)])

    width_ = np.asarray(
        [[np.sum(int_[:, 1] - int_[:, 0]) for int_ in region] for region in regions])
    
    bounds_ = np.asarray(
        [[[int_[:, 0].min(), int_[:, 1].max()] for int_ in region] for region in regions])

    return hits_, width_, bounds_

## Define the grid

true_nugget = [1e-6, 1e-1,]
test_functions = [f2, f5]

grid_ = ParameterGrid(dict(func=test_functions,
                           size=[150, 1500,],
                           nugget=true_nugget,
                           noise=true_nugget,
                           theta0=[1e+1, 1e+2, 1e+3, "auto"]))
## Initialize
kernel = 'rbf' # 'laplacian'
gp = GaussianProcess(beta0=0, normalize=False, corr='squared_exponential')

# Generate input
nd = 2
mesh_ = np.meshgrid(*nd*[np.linspace(-1, 1, num=51)])
{'fraction_non_alphanumeric': 0.13884959924563886, 'fraction_numerical': 0.03818953323903819, 'mean_word_length': 3.3076142131979696, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3012727', 'n_tokens_mistral': 1640, 'n_tokens_neox': 1526, 'n_words': 382}