Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ipd_extended/experiments_logging.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
70 lines (56 sloc)
2.7 KB
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
import matplotlib.pyplot as plt | |
import numpy as np | |
from mpl_toolkits.mplot3d import Axes3D | |
import pandas as pd | |
import data_generation as dg | |
from data_generation import synthetic_cube_in_cube | |
def plot_data_3d(data): | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
# data = data[np.logical_and(data[0] < 0, data[1] > 0)] | |
## 3d parity problem | |
# color_cond = {'b': np.logical_and(data[0] < 0, np.logical_and(data[1] > 0, data[2] < 0)), | |
# 'k': np.logical_and(data[0] < 0, np.logical_and(data[1] > 0, data[2] > 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, s=1) | |
## without coloring | |
ax.scatter(data[0], data[1], data[2], c='k', s=1) | |
ax.set_xlabel('X0') | |
ax.set_ylabel('X1') | |
ax.set_zlabel('X2') | |
plt.show() | |
def plot_data_2d(data): | |
plt.scatter(data[0], data[1], s=1, c='k') | |
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') | |
if __name__ == '__main__': | |
# rows = 20000 | |
# data = np.concatenate((synthetic_cube_in_cube(rows, 2, 0), np.zeros((rows, 1))), axis=1) | |
# data = pd.read_csv("synthetic_cases/synthetic_cube_in_sparse_cube_3_0.csv", delimiter=";", header=None, na_values='?') | |
data = pd.read_csv("synthetic_cases/3d_4_blobs_1_aligned_xor.csv", delimiter=";", header=None, na_values='?') | |
plot_data_3d(data) |