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/data_generation.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
71 lines (52 sloc)
2.24 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 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, 9, 0, 0), np.zeros((20000, 1))), axis=1) | |
file = 'synthetic_10d_parity_problem.csv' | |
if os.path.isfile(file): | |
raise ValueError | |
pd.DataFrame(data__).to_csv(file, sep=';', header=False, index=False, float_format='%.2f') |