# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [conda env:py2]
#     language: python
#     name: conda-env-py2-py
# ---

import code.independence_test as it
import code.additive_noise as an
import numpy as np
import numpy.random as rn

import code.hsic as hs

n=200
uni = rn.uniform(0,10,n)
exp = rn.exponential(7,n)
gamma = rn.gamma(10,1,n)
log = rn.logistic(10,0.5,n)
n_Y = np.random.normal(0,0.4,n)
n_L = np.random.normal(0,0.5,n)
#Y = uni + exp + gamma + log + n_Y
Y = gamma + log + n_Y
leak = Y + n_L

X = np.stack([gamma,log, leak],axis=1)

an.ANM_algorithm(X,Y)

hsic = it.HSIC_b(exp,Y)
hsic.empirical_test()

X = np.random.uniform(0,10,1000)
n_Y = np.random.normal(0,1,1000)
#Y= X 
Y = n_Y

hsic = it.HSIC_b(X,Y)

hsic.empirical_test()

hsic.alpha()

hsic.beta()

hsic.p_value

a = {1:'uno', 2:'dos', 3:'tres'}

for i in a:
    print i, a[i]

from sklearn.metrics.pairwise import rbf_kernel, laplacian_kernel

# +
# rbf_kernel?
# -

len(str(20))

range(59,105)

# +
accuracy = list()
for i in range(105):
    pair = str(i+1)
    if len(pair)==1:
        pair = '000'+ pair
    if len(pair)==2:
        pair = '00'+ pair
    if len(pair)==3:
        pair = '0'+ pair
    if pair != '0047' and pair != '0060' and pair != '0061':
        data = np.loadtxt('./data/pair'+pair+'.txt')
        if data.shape[0]>500:
            data = data[0:500]
        print 'pair', pair
        print 'n_columns',data.shape[1]
        if data.shape[1]==2:
            X = data[:,0]
            Y = data[:,1]
            dire = an.ANM_algorithm2(X,Y)
            if dire == directions[i]:
                accuracy.append(1)
            else:
                accuracy.append(0)    
        else:
            continue
        
        
        
    
# -

np.array(accuracy).sum()/float(len(accuracy))

np.array(accuracy).shape

pair = np.loadtxt('./data/pair0006.txt')
pair[:,0][0:500].shape

metadata = np.loadtxt('./pairmeta.txt')

directions = metadata[:,3]-metadata[:,2]

directions.shape

directions.shape

import modshogun



StarcoderdataJupyterScriptsDedupFiltered