Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
synthetic cases reproduction
- Loading branch information
Tatiana Dembelova
committed
Jun 7, 2017
1 parent
7cd91e1
commit 7168cf4
Showing
8 changed files
with
348 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
.idea/* | ||
*.iml | ||
|
||
logs/* | ||
|
||
# Mobile Tools for Java (J2ME) | ||
.mtj.tmp/ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from enum import Enum | ||
|
||
class Method(Enum): | ||
ORIGINAL = 1 | ||
EXTENDED = 2 | ||
|
||
class Correlation_measure(Enum): | ||
UDS = 1 | ||
CMI = 2 | ||
MAC = 3 | ||
|
||
ID_THRESHOLD_QUANTILE = 0.8 | ||
|
||
NORMALIZATION_RADIUS = 1 | ||
|
||
FILE_DATA_OUTPUT = "out.txt" | ||
FILE_DATA_CUTS = 'cut.txt' | ||
|
||
MAX_SUBSPACE_SIZE = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import numpy as np | ||
import pandas as pd | ||
import os.path | ||
|
||
|
||
def correlated_data(m, n, sigma, f): | ||
l = int(n / 2) | ||
Z = np.random.normal(0, 1, (m, l)) | ||
A = np.matrix(np.random.uniform(0, 1, (l, l))) | ||
X1 = Z * A | ||
B = np.matrix(np.random.uniform(0, 0.5, (l, l))) | ||
W = X1 * B | ||
E = np.random.normal(0, sigma, (m, l)) | ||
X2 = f(W) + E | ||
result = np.append(X1, X2, axis=1) | ||
print(result) | ||
return result | ||
|
||
|
||
def generate_uncorrelated_data(m, n): | ||
return np.random.normal(0, 1, (m, n)) | ||
|
||
|
||
def func1(X): | ||
return 2 * X + 1 | ||
|
||
|
||
def func2(X): | ||
return np.log2(np.abs(X) + 1) | ||
|
||
|
||
def synthetic_data_1(m, r, s, sigma=0.1): | ||
r_dims = np.random.uniform(-0.5, 0.5, (m, r)) | ||
parity_dim = -(np.count_nonzero(r_dims > 0, axis=1) % 2 * 2 - 1).reshape(m, 1) * np.random.uniform(0, 0.5, | ||
(m, 1)) | ||
s_dims = np.random.normal(0, 1, (m, s)) | ||
data = np.concatenate((r_dims, parity_dim, s_dims), axis=1) | ||
if sigma: | ||
e = np.random.normal(0, sigma, (m, r + s + 1)) | ||
data = data + e | ||
|
||
return data | ||
|
||
|
||
def synthetic_data_gauss(m, r, s, sigma=0.1): | ||
r_dims = np.random.normal(0, 1, (m, r)) | ||
parity_dim = -(np.count_nonzero(r_dims > 0, axis=1) % 2 * 2 - 1).reshape(m, 1) * np.abs(np.random.normal(0, 1, | ||
(m, 1))) | ||
s_dims = np.random.normal(0, 1, (m, s)) | ||
data = np.concatenate((r_dims, parity_dim, s_dims), axis=1) | ||
if sigma: | ||
e = np.random.normal(0, sigma, (m, r + s + 1)) | ||
data = data + e | ||
|
||
return data | ||
|
||
|
||
def synthetic_data_0(m): | ||
l = int(m / 2) | ||
first = np.concatenate((np.random.uniform(-1, 0, (l, 1)), np.random.uniform(0, 1, (l, 1))), axis=1) | ||
sec = np.concatenate((np.random.uniform(0, 1, (m - l, 1)), np.random.uniform(-1, 0, (m - l, 1))), axis=1) | ||
return np.concatenate((first, sec), axis=0) | ||
|
||
|
||
if __name__ == '__main__': | ||
data__ = np.concatenate((synthetic_data_1(20000, 2, 0, 0), np.zeros((20000, 1))), axis=1) | ||
file = 'synthetic_data_example_20000.csv' | ||
|
||
if os.path.isfile(file): | ||
raise ValueError | ||
pd.DataFrame(data__).to_csv(file, sep=';', header=False, index=False, float_format='%.2f') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from mpl_toolkits.mplot3d import Axes3D | ||
|
||
def plot_data_3d(data): | ||
fig = plt.figure() | ||
ax = fig.add_subplot(111, projection='3d') | ||
|
||
color_cond = {'b': np.logical_and(data[0] < 0, data[1] > 0), | ||
'g': np.logical_and(data[0] > 0, data[1] < 0), | ||
'r': np.logical_and(data[0] < 0, data[1] < 0), | ||
'c': np.logical_and(data[0] > 0, data[1] > 0), | ||
} | ||
for c in color_cond: | ||
ax.scatter(data[0][color_cond[c]], data[1][color_cond[c]], data[2][color_cond[c]], c=c) | ||
|
||
ax.set_xlabel('X0') | ||
ax.set_ylabel('X1') | ||
ax.set_zlabel('X2') | ||
|
||
plt.show() | ||
|
||
|
||
def write_out_file(name, disc_intervals, disc_points, class_labels): | ||
with open(name, 'w') as out: | ||
out.write('@relation DB\n\n') | ||
counter = [1] | ||
for i in range(len(disc_intervals)): | ||
out.write( | ||
'@attribute dim' + str(i) + ' {' + ','.join([str(j + counter[-1]) for j in disc_intervals[i]]) + '}\n') | ||
counter.append(counter[-1] + len(disc_intervals[i])) | ||
out.write('@attribute class {' + ','.join(['"' + str(i) + '"' for i in class_labels.unique()]) + '}\n\n') | ||
out.write('@data\n') | ||
|
||
for i in range(len(disc_points[0])): | ||
for j in range(len(disc_points)): | ||
out.write(str(disc_points[j][i] + counter[j])) | ||
out.write(',') | ||
out.write('"' + str(class_labels[i]) + '"\n') | ||
|
||
|
||
def write_cut_file(name, disc_intervals): | ||
with open(name, 'w') as out: | ||
for i in range(len(disc_intervals)): | ||
out.write('dimension ' + str(i) + ' (' + str(len(disc_intervals[i])) + ' bins)\n') | ||
for bin in disc_intervals[i]: | ||
out.write(str(disc_intervals[i][bin][1]) + '\n') | ||
out.write('-------------------------------------\n') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.