-
Notifications
You must be signed in to change notification settings - Fork 19
/
Test_on_Playground_TensorFlow_Datasets
62 lines (44 loc) · 1.83 KB
/
Test_on_Playground_TensorFlow_Datasets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import print_function
import plygdata as pg
import pprint
import matplotlib.pyplot as plt
import numpy as np
from math import log
from math import sqrt
from math import pow
from numpy.linalg import det
from numpy import transpose
from numpy.linalg import inv
from numpy import array
data_noise=0.0
validation_data_ratio = 0.7
# Generate data
data_array = pg.generate_data(pg.DatasetType.ClassifyCircleData, data_noise)
# data_array = pg.generate_data(pg.DatasetType.ClassifyXORData, data_noise)
# data_array = pg.generate_data(pg.DatasetType.ClassifyTwoGaussData, data_noise)
# data_array = pg.generate_data(pg.DatasetType.ClassifySpiralData, data_noise)
# data_array = pg.generate_data(pg.DatasetType.RegressPlane, data_noise)
# data_array = pg.generate_data(pg.DatasetType.RegressGaussian, data_noise)
# Divide the data for training and validating at a specified ratio
X_train, y_train, X_valid, y_valid = pg.split_data(data_array, validation_size=validation_data_ratio)
# Plot Data
fig, ax = pg.plot_points_with_playground_style(X_train, y_train,X_valid , y_valid, figsize = (6, 6), dpi = 100)
plt.show()
from pandas import DataFrame
train_D = np.concatenate([X_train, y_train] ,axis = 1)
test_D = np.concatenate([X_valid, y_valid],axis = 1)
df = DataFrame(train_D)
# export_csv = df.to_csv (r'C:/Users/Koorosh/Desktop/Paper_Joyjit/PlayD_Circle.csv', index = None, header= None)
td1 = X_train[np.where(y_train[:,0] == 1)]
td2 = X_train[np.where(y_train[:,0] == -1)]
mean1 = np.mean(td1, axis = 0)
cov1 = np.cov(td1.T)
mean2 = np.mean(td2, axis = 0)
cov2 = np.cov(td2.T)
s = 0.5
mean_diff = mean2 - mean1
var_avg = (cov1 + cov2) * 0.5
ln_coeff = 0.5 * log(det(var_avg) / sqrt(det(cov1) * det(cov2)))
dist2 = 0.125 * np.matmul(np.matmul(mean_diff.T,inv(var_avg)), mean_diff) + ln_coeff
from numpy import exp
print('Error', exp(-dist2))