Created
November 30, 2018 22:53
-
-
Save syadlowsky/dd1d95e1754f3760f3d989e36c7c1e70 to your computer and use it in GitHub Desktop.
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
SIGMA = args.sigma | |
NUM_RAND_FEATURES = args.num_rand_features | |
data_hdf5 = h5py.File(args.filename,'r+') | |
d = data_hdf5['train']['x'][0].shape[0] | |
n = len(data_hdf5['train']['x']) | |
train_y = np.array(data_hdf5['train']['t']) | |
features = np.array(data_hdf5['train']['x']) | |
scaler_raw = preprocessing.StandardScaler().fit(features) | |
features = scaler_raw.transform(features) | |
rand_featurizer = np.random.randn(d, NUM_RAND_FEATURES) | |
rand_offsetter = 2*np.pi*np.random.rand(NUM_RAND_FEATURES) | |
print(np.histogram(np.abs(SIGMA * features.dot(rand_featurizer)))) | |
features = np.sin(SIGMA * features.dot(rand_featurizer) + rand_offsetter[np.newaxis,:]) | |
train_x = features | |
print(train_y.shape) | |
soln = train_x.T.dot(scipy.linalg.solve(train_x.dot(train_x.T), train_y, sym_pos=True)) | |
print(np.mean(np.abs(train_x.dot(soln) - train_y))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment