Skip to content

Commit

Permalink
New activation functions added, unit tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan authored and Jan committed Jan 18, 2018
1 parent 70ed480 commit fc5c419
Show file tree
Hide file tree
Showing 10 changed files with 571 additions and 407 deletions.
576 changes: 366 additions & 210 deletions pydeep/base/activationfunction.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pydeep/base/basicstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def _add_visible_units(self,
initial_bias='AUTO',
initial_offsets='AUTO',
data=None):
""" This function adds new visible units at the given position to the model. \
""" This function adds new visible units at the given position to the model.
.. Warning:: If the parameters are changed. the trainer needs to be reinitialized.
:param num_new_visibles: The number of new hidden units to add
Expand Down Expand Up @@ -434,7 +434,7 @@ def _add_visible_units(self,
self.input_dim = self.w.shape[0]

def _remove_visible_units(self, indices):
""" This function removes the visible units whose indices are given. \
""" This function removes the visible units whose indices are given.
.. Warning:: If the parameters are changed. the trainer needs to be reinitialized.
:param indices: Indices of units to be remove.
Expand Down
36 changes: 18 additions & 18 deletions pydeep/base/corruptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
:Implemented:
- Identity
- Sampling Binary
- Additive Gauss Noise
- Multiplicative Gauss Noise
- Dropout
- Random Permutation
- Sampling Binary
- KeepKWinner
- KWinnerTakesAll
Expand Down Expand Up @@ -65,23 +65,6 @@ def corrupt(cls, data):
return data


class SamplingBinary(object):
""" Sample binary states (zero out) corruption.
"""

@classmethod
def corrupt(cls, data):
""" The function corrupts the data.
:param data: Input of the layer.
:type data: numpy array [num samples, layer dim]
:return: Corrupted data.
:rtype: numpy array [num samples, layer dim]
"""
return data > numx.random.random(data.shape)


class AdditiveGaussNoise(object):
""" An object that corrupts data by adding Gauss noise.
"""
Expand Down Expand Up @@ -138,6 +121,23 @@ def corrupt(self, data):
return data * (self.mean + numx.random.standard_normal(data.shape) * self.std)


class SamplingBinary(object):
""" Sample binary states (zero out) corruption.
"""

@classmethod
def corrupt(cls, data):
""" The function corrupts the data.
:param data: Input of the layer.
:type data: numpy array [num samples, layer dim]
:return: Corrupted data.
:rtype: numpy array [num samples, layer dim]
"""
return data > numx.random.random(data.shape)


class Dropout(object):
""" Dropout (zero out) corruption.
"""
Expand Down
43 changes: 2 additions & 41 deletions pydeep/misc/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
- Save/Load arbitrary objects.
- Save/Load images.
- Load MNIST.
- Load Caltech.
- Load CIFAR.
- load Natural image patches
- load olivetti face images
- Load Caltech.
:Version:
1.1.0
Expand Down Expand Up @@ -328,7 +326,7 @@ def load_cifar(path, grayscale=True):

def load_natural_image_patches(path):
""" Loads the natural image patches used in the publication 'Gaussian-binary restricted Boltzmann machines for \
modeling natural image statistics'. \
modeling natural image statistics'.
.. seealso:: http://journals.plos.org/plosone/article/authors?id=10.1371/journal.pone.0171015
:param path: Path and name of the file to load.
Expand All @@ -352,40 +350,3 @@ def load_natural_image_patches(path):
raise Exception('-> File reading Error: ')
data = numx.array(data, dtype=numx.double)
return data

def load_olivetti_faces(path, correct_orientation=True):
""" Loads the Olivetti face dataset 400 images, size 64x64
:param path: Path and name of the file to load.
:type path: string
:param correct_orientation: Corrects the orientation of the images.
:type correct_orientation: bool
:return: Olivetti face dataset
:rtype: numpy array
"""
if not os.path.isfile(path):
print('-> File not existing: ' + path)
try:
download_file('http://www.cs.nyu.edu/~roweis/data/olivettifaces.mat', path, buffer_size=10 * 1024 ** 2)
except:
try:
download_file('https://github.com/probml/pmtk3/tree/master/bigData/facesOlivetti/facesOlivetti.mat',
path, buffer_size=10 * 1024 ** 2)
except:
raise Exception('Download failed, make sure you have internet connection!')
print('-> loading data ... ')
try:
data = scipy.io.loadmat(path)['faces'].T
if correct_orientation:
import pydeep.base.numpyextension as npext
for i in range(data.shape[0]):
data[i] = npext.rotate(data[i].reshape(64,64),270).reshape(64*64)
print('-> orientation corrected!')
print('-> done!')
except:
raise Exception('-> File reading Error: ')
data = numx.array(data, dtype=numx.double)
return data

3 changes: 2 additions & 1 deletion pydeep/misc/sshthreadpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ def execute_command(self, command):

def execute_command_in_screen(self, command):
""" Executes a command in a screen on the server which is automatically detached and returns stdin, stdout, \
and stderr. Screen closes automatically when the job is done.
and stderr. Screen closes automatically when the job is
done.
:param command: Command to be executed.
:type command: string
Expand Down

0 comments on commit fc5c419

Please sign in to comment.