This file contains hidden or 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 math | |
| import torch | |
| from torch.distributions import Normal | |
| # standard univariate Gaussian (Normal) | |
| mean = torch.zeros(1) | |
| std = torch.ones(1) | |
| # evaluate from -0.5 to 0.5 | |
| x_min = -0.5 * torch.ones(1) |
This file contains hidden or 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 math | |
| import torch | |
| from torch.distributions import Normal | |
| # standard univariate Gaussian (Normal) | |
| mean = torch.zeros(1) | |
| std = torch.ones(1) | |
| # evaluate at the origin | |
| value = torch.zeros(1) |
This file contains hidden or 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 | |
| def whiten(X, method='zca'): | |
| """ | |
| Whitens the input matrix X using specified whitening method. | |
| Inputs: | |
| X: Input data matrix with data examples along the first dimension | |
| method: Whitening method. Must be one of 'zca', 'zca_cor', 'pca', |
This file contains hidden or 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 | |
| n_samples = 500 | |
| mean_1 = 15 | |
| std_dev_1 = 5 | |
| mean_2 = -20 | |
| std_dev_2 = 3 | |
| X = np.concatenate([np.random.normal(mean_1, std_dev_1, n_samples / 2), | |
| np.random.normal(mean_2, std_dev_2, n_samples / 2)], axis=0) |
This file contains hidden or 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 | |
| n_samples = 500 | |
| mean = 15 | |
| std_dev = 5 | |
| X = np.random.normal(mean, std_dev, n_samples) | |
| Z = (X - np.mean(X)) / np.std(X) |
This file contains hidden or 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
| keras_top_inds = keras_act[0].argsort()[::-1][:5] | |
| zip(keras_act[0][keras_top_inds], labels[keras_top_inds]) |
This file contains hidden or 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
| labels_file = caffe_root + 'data/ilsvrc12/synset_words.txt' | |
| labels = np.loadtxt(labels_file, str, delimiter='\t') | |
| caffe_top_inds = caffe_act[0].argsort()[::-1][:5] | |
| zip(caffe_act[0][caffe_top_inds], labels[caffe_top_inds]) |
This file contains hidden or 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
| caffe_act = net.blobs[layer_name].data | |
| layer = googlenet.get_layer(name=layer_name) | |
| keras_act = get_activations(googlenet, layer, img) |
This file contains hidden or 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 theano | |
| def get_activations(model, layer, X_batch): | |
| get_activations = theano.function([model.layers[0].input,K.learning_phase()], layer.output, allow_input_downcast=True) | |
| activations = get_activations(X_batch,0) | |
| return activations |
This file contains hidden or 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
| net.blobs['data'].reshape(1, 3, 224, 224) | |
| net.blobs['data'].data = img | |
| output = net.forward() |
NewerOlder