In [1]:
%matplotlib inline
import pandas as pd
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
from matplotlib import pyplot as plt
import glob
import numba
In [2]:
prototype_indicies = range(65,85)
prototype_indicies
# index 5 - 24 are the activation values
activation_indicies = range(5, 25) # returns 5 - 24
print(list(activation_indicies))
In [3]:
@numba.jit('f8(f8[:])')
def calculate_sse(row_vector):
'''Calculate the sum square error between the activation values and prototype
Parameters
----------
row_vector: pandas series
Returns:
--------
sum_square_error: floating point of sse
'''
assert(len(activation_indicies) == 20)
assert(len(prototype_indicies) == 20)
activation_values = row_vector.iloc[activation_indicies].values
prototype_values = row_vector.iloc[prototype_indicies].values
error_vector = activation_values - prototype_values
square_error_vector = error_vector ** 2
sum_square_error = np.sum(square_error_vector)
return(sum_square_error)
In [4]:
def test_calculate_sse():
pout_files = glob.glob('02-lens_batch_2014-11-14_20:46:22/*/output/*.pout')
pout_file = pout_files[0]
data = pd.read_csv(pout_file, header=None)
data['sse'] = data.apply(calculate_sse, axis=1)
calculated = np.sort(data['sse'].unique())
expected = np.sort(np.array([1.100000e+01, 0.000000e+00, 4.293802e-04, 1.198868e-02,
1.742523e-02, 9.875449e-03, 1.272909e-02, 3.948474e-03,
2.029364e-02, 9.931646e-03, 7.607752e-03, 3.174525e-02,
6.270994e-04, 1.662769e-02, 2.289100e-02, 1.357461e-02,
3.237630e-04, 6.436357e-02, 7.514400e-04, 2.992966e-02,
6.378620e-02, 1.634918e-02, 1.794454e-02, 4.571180e-04,
3.821324e-04, 5.305328e-04, 1.435284e-02, 8.429803e-02,
1.080844e-02, 5.324111e-04, 1.824554e-02, 3.258835e-04,
5.280545e-04, 2.791479e-04]))
assert(calculated.shape == expected.shape)
np.testing.assert_array_almost_equal(calculated, expected)
test_calculate_sse()
In [5]:
def calculate_cosine_sim(row_vector):
'''Calculate the cosine similarity between the activation values and prototype
Parameters
----------
row_vector: pandas series
Returns:
--------
cos_sim: floating point of cosine similarity
'''
assert(len(activation_indicies) == 20)
assert(len(prototype_indicies) == 20)
activation_values = np.array(row_vector.iloc[activation_indicies])
prototype_values = np.array(row_vector.iloc[prototype_indicies])
activation_values_adj = activation_values + 1
prototype_values_adj = prototype_values + 1
cos_sim = cosine_similarity(activation_values_adj, prototype_values_adj)
assert(cos_sim.shape == (1, 1))
return(cos_sim[0][0])
In [6]:
def test_calculate_cosine_sim():
pout_files = glob.glob('02-lens_batch_2014-11-14_20:46:22/*/output/*.pout')
pout_file = pout_files[0]
print(pout_file)
data = pd.read_csv(pout_file, header=None)
data['cos'] = data.apply(calculate_cosine_sim, axis=1)
calculated = data['cos'].values
# above is same as:
# calculated = np.array(data['cos'])
expected = np.array([0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 1.0000000, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9999040, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9521574, 0.9521574, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9521574, 0.9521574, 0.9521574, 0.9998968, 0.9521574, 0.9521574,
0.9521574, 0.9999719, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9521574, 0.9521574, 0.9521574, 0.9998968,
0.9521574, 0.9521574, 0.9998336, 0.9999719, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965,
0.9998430, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9999140, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9999137, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9521574, 0.9521574,
0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999719, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999140, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9999137, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040,
0.9521574, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999719, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999140, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9999040, 0.9521574, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999719, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999140, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9521574, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999719,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999140, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9521574, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574,
0.9998336, 0.9999955, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574,
0.9521574, 0.9998704, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9999140, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9521574, 0.9999503, 0.9521574, 0.9998968,
0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965,
0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9999137, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9521574, 0.9999503,
0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997087, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999040,
0.9521574, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9999040, 0.9999977, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9521574, 0.9994081,
0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9999977, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574,
0.9521574, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9999977, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574,
0.9998336, 0.9999955, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574,
0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983,
0.9999140, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999137, 0.9998956,
0.9521574, 0.9521574, 0.9521574, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9999977, 0.9999503, 0.9521574, 0.9998968,
0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965,
0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9521574, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9999977, 0.9999503,
0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9521574, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999040,
0.9999977, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9998663, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574,
0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9521574, 0.9999937, 0.9521574, 0.9521574,
0.9521574, 0.9999040, 0.9999977, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9998663, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9997936,
0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9994543, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9521574, 0.9999937,
0.9521574, 0.9521574, 0.9521574, 0.9999040, 0.9999977, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955,
0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704,
0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574,
0.9994543, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574,
0.9521574, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9521574, 0.9998968, 0.9521574, 0.9521574,
0.9998336, 0.9999955, 0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999970, 0.9521574, 0.9999965, 0.9998430, 0.9521574,
0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983,
0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956,
0.9521574, 0.9521574, 0.9521574, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9521574, 0.9998968,
0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999970, 0.9521574, 0.9999965,
0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9999956, 0.9521574, 0.9521574, 0.9521574, 0.9998522, 0.9521574,
0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9521574, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503,
0.9521574, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999970,
0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9999956, 0.9521574, 0.9521574, 0.9521574,
0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9521574, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964,
0.9999977, 0.9999503, 0.9998781, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9998663, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9999970, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574,
0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9999956, 0.9521574,
0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9993189, 0.9999937, 0.9521574, 0.9521574,
0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9998781, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9998663, 0.9521574,
0.9521574, 0.9521574, 0.9521574, 0.9999970, 0.9521574, 0.9999965, 0.9998430, 0.9521574, 0.9521574, 0.9998704, 0.9521574, 0.9997936,
0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574, 0.9994543, 0.9521574,
0.9999956, 0.9521574, 0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9993189, 0.9999937,
0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9998781, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955,
0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999970, 0.9521574, 0.9999965, 0.9998430, 0.9999115, 0.9521574, 0.9998704,
0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9997983, 0.9999140, 0.9521574,
0.9994543, 0.9521574, 0.9999956, 0.9521574, 0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574,
0.9993189, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9998781, 0.9998968, 0.9521574, 0.9521574,
0.9998336, 0.9999955, 0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999970, 0.9521574, 0.9999965, 0.9998430, 0.9999115,
0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999956,
0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9999956, 0.9521574, 0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956,
0.9521574, 0.9521574, 0.9993189, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9998781, 0.9998968,
0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999970, 0.9521574, 0.9999965,
0.9998430, 0.9999115, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9998352, 0.9521574,
0.9521574, 0.9999956, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9999956, 0.9521574, 0.9521574, 0.9521574, 0.9998522, 0.9521574,
0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9993189, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503,
0.9998781, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999955, 0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9521574, 0.9999970,
0.9521574, 0.9999965, 0.9998430, 0.9999115, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574,
0.9998352, 0.9521574, 0.9521574, 0.9999956, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9999956, 0.9521574, 0.9521574, 0.9521574,
0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9993189, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964,
0.9999977, 0.9999503, 0.9998781, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999719, 0.9998663, 0.9521574, 0.9521574, 0.9521574,
0.9521574, 0.9999970, 0.9521574, 0.9999965, 0.9998430, 0.9999115, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574,
0.9997087, 0.9521574, 0.9998352, 0.9521574, 0.9521574, 0.9999956, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9999956, 0.9521574,
0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9993189, 0.9999937, 0.9521574, 0.9521574,
0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9998781, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999719, 0.9998663, 0.9521574,
0.9521574, 0.9521574, 0.9999973, 0.9999970, 0.9521574, 0.9999965, 0.9998430, 0.9999115, 0.9521574, 0.9998704, 0.9521574, 0.9997936,
0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9998352, 0.9521574, 0.9521574, 0.9999956, 0.9999140, 0.9521574, 0.9994543, 0.9521574,
0.9999956, 0.9521574, 0.9521574, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9993189, 0.9999937,
0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9998781, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999719,
0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9999973, 0.9999970, 0.9521574, 0.9999965, 0.9998430, 0.9999115, 0.9521574, 0.9998704,
0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9998352, 0.9521574, 0.9521574, 0.9999956, 0.9999140, 0.9521574,
0.9994543, 0.9521574, 0.9999956, 0.9521574, 0.9999964, 0.9521574, 0.9998522, 0.9521574, 0.9999137, 0.9998956, 0.9521574, 0.9521574,
0.9993189, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9998781, 0.9998968, 0.9521574, 0.9521574,
0.9998336, 0.9999719, 0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9999973, 0.9999970, 0.9521574, 0.9999965, 0.9998430, 0.9999115,
0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9998352, 0.9521574, 0.9521574, 0.9999956,
0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9999956, 0.9521574, 0.9999964, 0.9521574, 0.9999977, 0.9521574, 0.9999137, 0.9998956,
0.9521574, 0.9521574, 0.9993189, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503, 0.9998781, 0.9998968,
0.9521574, 0.9521574, 0.9998336, 0.9999719, 0.9998663, 0.9521574, 0.9521574, 0.9521574, 0.9999973, 0.9999970, 0.9521574, 0.9999965,
0.9998430, 0.9999115, 0.9521574, 0.9998704, 0.9521574, 0.9997936, 0.9521574, 0.9521574, 0.9997087, 0.9521574, 0.9998352, 0.9521574,
0.9521574, 0.9999956, 0.9999140, 0.9521574, 0.9994543, 0.9521574, 0.9999956, 0.9521574, 0.9999964, 0.9521574, 0.9999977, 0.9521574,
0.9999137, 0.9998956, 0.9521574, 0.9521574, 0.9993189, 0.9999937, 0.9521574, 0.9521574, 0.9521574, 0.9999964, 0.9999977, 0.9999503,
0.9998781, 0.9998968, 0.9521574, 0.9521574, 0.9998336, 0.9999719, 0.9998663, 0.9521574])
assert(calculated.shape == expected.shape)
np.testing.assert_array_almost_equal(calculated, expected)
test_calculate_cosine_sim()
In [7]:
def create_cosine_sim_cutoffs(dataframe, list_of_values):
assert(isinstance(list_of_values, list))
assert(isinstance(list_of_values[0], float))
for value in list_of_values:
# format the float for 2 decimals, and only keep the decimal portion
new_column_name = 'cos' + ("{0:.2f}".format(value)).split('.')[1]
dataframe[new_column_name] = np.where(dataframe['cos'] >= value, 1, 0)
return dataframe
In [8]:
# pout_files = glob.glob('02-lens_batch_2014-11-14_20:46:22/*/output/*.pout')
pout_files = glob.glob('/home/dchen/Desktop/snowmane_pout/*/output/*.pout')
pout_files
Out[8]:
In [9]:
for pout_file in pout_files:
pass
In [10]:
%%timeit
# 1 loops, best of 3: 28.3 s per loop
pout_file = pout_files[0]
data = pd.read_csv(pout_file, header=None)
In [13]:
data = pd.read_csv(pout_file, header=None)
In [14]:
data.shape
Out[14]:
In [ ]:
%%timeit
data['sse'] = data.apply(calculate_sse, axis=1)
In [ ]:
data
In [ ]:
data['sse'] = data.apply(calculate_sse, axis=1)
In [129]:
# %%timeit
# inside the loop
# rel path of the .pout file
pout_file = pout_files[0]
# print(pout_file)
# name of the folder
folder = pout_file.split('/')[1]
# print(folder)
# load into dataframe
data = pd.read_csv(pout_file, header=None)
# print(data.head())
data['sse'] = data.apply(calculate_sse, axis=1)
data['cos'] = data.apply(calculate_cosine_sim, axis=1)
data['if_ever_updated'] = np.where(data[2] > 0, 1, 0)
cos_sim_thresholds = [0.80, 0.85, 0.90, 0.95, 0.97, 0.99]
assert(isinstance(cos_sim_thresholds, list))
for x in cos_sim_thresholds:
assert(isinstance(x, float))
data = create_cosine_sim_cutoffs(data, list_of_values=cos_sim_thresholds)
# for cos_threshold in cos_sim_thresholds:
# col_value = 'cos' + str(cos_sim_thresholds)
# data.groupby([0])[col_value].
In [102]:
%%timeit
by_time = data.groupby([0])['cos99'].agg({'mean', 'count', 'sum'})
by_time['prop'] = by_time['sum']/by_time['count']
# by_update_status = data.groupby(['if_ever_updated'])['cos0.99'].agg(['mean', 'count', 'sum'])
# by_time.div(by_update_status, level='if_ever_updated')
by_time
In [104]:
%%timeit
plt.plot(by_time['prop'])
In [106]:
by_time_update = data.groupby([0, 'if_ever_updated'])['cos99'].agg({'mean', 'count', 'sum'})
by_time_update['prop'] = by_time_update['sum']/by_time_update['count']
# by_update_status = data.groupby(['if_ever_updated'])['cos0.99'].agg(['mean', 'count', 'sum'])
# by_time.div(by_update_status, level='if_ever_updated')
by_time_update
Out[106]:
In [124]:
plt.plot(by_time_update.reset_index()[by_time_update.reset_index()['if_ever_updated'] == 1]['prop'])
Out[124]:
In [120]:
by_time_update.reset_index().if_ever_updated
Out[120]:
In [100]:
data.columns
Out[100]:
In [101]:
# test calculate_sse
data.loc[0].loc[activation_indicies]
data.iloc[0].iloc[prototype_indicies]
type(data.loc[0].loc[activation_indicies])
diff = data.iloc[0].iloc[activation_indicies].reset_index(drop=True) -\
data.iloc[0].iloc[prototype_indicies].reset_index(drop=True)
assert(np.array_equal(np.array(diff),
np.array([-1, -1, -1, 0, -1, 0, -1, -1, -1, 0, 0, -1, -1, 0, -1, 0, -1, 0, 0, 0])
))
diff = np.array(data.iloc[0].iloc[activation_indicies]) -\
np.array(data.iloc[0].iloc[prototype_indicies])
assert(np.array_equal(np.array(diff),
np.array([-1, -1, -1, 0, -1, 0, -1, -1, -1, 0, 0, -1, -1, 0, -1, 0, -1, 0, 0, 0])
))