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.
92 lines (68 sloc)
3.18 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 | |
# synthetic case from uds | |
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_uni(m, r, s, sigma=0.1): | |
r_dims = np.random.uniform(-0.5, 0.5, (m, r)) if r > 0 else np.empty((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)) if r > 0 else np.empty((m, r)) | |
s_dims = np.random.uniform(-0.5, 0.5, (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_uni_negative(m, r, s, sigma=0.1): | |
r_dims = np.random.uniform(-0.5, 0.5, (m, r)) if r > 0 else np.empty((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)) if r > 0 else np.empty((m, r)) | |
s_dims = np.random.uniform(-0.5, 0.5, (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)) if r > 0 else np.empty((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))) if r > 0 else np.empty((m, r)) | |
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_with_nearcopies(m, k, l, sigma=0.1): | |
k_dims = np.repeat(np.random.uniform(-0.5, 0, (m, 1)), k, axis=1) if k > 0 else np.empty((m, k)) | |
l_dims = np.repeat(np.random.uniform(0, 0.5, (m, 1)), l, axis=1) if l > 0 else np.empty((m, l)) | |
data = np.concatenate((k_dims, l_dims), axis=1) | |
if sigma: | |
e = np.random.normal(0, sigma, (m, k + l)) | |
data = data + e | |
return data | |
if __name__ == '__main__': | |
rows = 20000 | |
data__ = np.concatenate((synthetic_with_nearcopies(rows, 2, 0, 0), np.zeros((rows, 1))), axis=1) | |
# file = 'synthetic_cases/synthetic_3d_gauss2.csv' | |
file = 'synthetic_cases/synthetic_exact_copies2_2.csv' | |
if os.path.isfile(file): | |
raise ValueError | |
pd.DataFrame(data__).to_csv(file, sep=';', header=False, index=False, float_format='%.2f') |