desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'.. todo::
WRITEME'
| def get_design_matrix(self):
| return self.X
|
'.. todo::
WRITEME
Parameters
dataset : Dataset
The dataset to act on.
can_fit : bool
If True, the Preprocessor can adapt internal parameters
based on the contents of dataset. Otherwise it must not
fit any parameters, or must re-use old ones.
Subclasses should still have this default to False, so
that the behavior of t... | def apply(self, dataset, can_fit=False):
| raise NotImplementedError((str(type(self)) + ' does not implement an apply method.'))
|
'Do any necessary prep work to be able to support the "inverse" method
later. Default implementation is no-op.'
| def invert(self):
| pass
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| assert (not can_fit)
dataset.X = self.block.perform(dataset.X)
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| for item in self.items:
item.apply(dataset, can_fit)
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| X = dataset.get_topological_view()
num_topological_dimensions = (len(X.shape) - 2)
if (num_topological_dimensions != len(self.patch_shape)):
raise ValueError(((((('ExtractGridPatches with ' + str(len(self.patch_shape))) + ' topological dimensions called on') + ' dataset with ... |
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| patches = dataset.get_topological_view()
num_topological_dimensions = (len(patches.shape) - 2)
if (num_topological_dimensions != len(self.patch_shape)):
raise ValueError(((((('ReassembleGridPatches with ' + str(len(self.patch_shape))) + ' topological dimensions called on dataset... |
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| rng = copy.copy(self.start_rng)
X = dataset.get_topological_view()
num_topological_dimensions = (len(X.shape) - 2)
if (num_topological_dimensions != len(self.patch_shape)):
raise ValueError(((((('ExtractPatches with ' + str(len(self.patch_shape))) + ' topological dimensions called... |
'.. todo::
WRITEME'
| def __call__(self, batch):
| if self.input_space:
self.input_space.validate(batch)
squared_batch = (batch ** 2)
squared_norm = squared_batch.sum(axis=1)
norm = tensor.sqrt(squared_norm)
return (batch / norm)
|
'.. todo::
WRITEME'
| def set_input_space(self, space):
| self.input_space = space
|
'.. todo::
WRITEME'
| def get_input_space(self):
| if (self.input_space is not None):
return self.input_space
raise ValueError(('No input space was specified for this Block (%s). You can call set_input_space to correct that.' % str(self)))
|
'.. todo::
WRITEME'
| def get_output_space(self):
| return self.get_input_space()
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| X = dataset.get_design_matrix()
X_norm = numpy.sqrt(numpy.sum((X ** 2), axis=1))
X /= X_norm[:, None]
dataset.set_design_matrix(X)
|
'.. todo::
WRITEME'
| def as_block(self):
| return ExamplewiseUnitNormBlock()
|
'.. todo::
WRITEME'
| def _multiply(self, batch):
| if (self.multiply is not None):
batch *= self.multiply
return batch
|
'.. todo::
WRITEME'
| def _add(self, batch):
| if (self.add is not None):
batch += self.add
return batch
|
'.. todo::
WRITEME'
| def __call__(self, batch):
| if self.input_space:
self.input_space.validate(batch)
cur = batch
if self._multiply_first:
batch = self._add(self._multiply(batch))
else:
batch = self._multiply(self._add(batch))
return batch
|
'.. todo::
WRITEME'
| def inverse(self):
| if ((self._multiply is not None) and self._has_zeros):
raise ZeroDivisionError(('%s transformation not invertible due to (near-) zeros in multiplicand' % self.__class__.__name__))
else:
mult_inverse = (self._multiply ** (-1.0))
return self.__class__(add=(- self... |
'.. todo::
WRITEME'
| def set_input_space(self, space):
| self.input_space = space
|
'.. todo::
WRITEME'
| def get_input_space(self):
| if (self.input_space is not None):
return self.input_space
raise ValueError(('No input space was specified for this Block (%s). You can call set_input_space to correct that.' % str(self)))
|
'.. todo::
WRITEME'
| def get_output_space(self):
| return self.get_input_space()
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=True):
| X = dataset.get_design_matrix()
if can_fit:
self._mean = X.mean(axis=self._axis)
elif (self._mean is None):
raise ValueError('can_fit is False, but RemoveMean object has no stored mean or standard deviation')
X -= self._mean
dataset.set_design_matr... |
'.. todo::
WRITEME'
| def as_block(self):
| if (self._mean is None):
raise ValueError(("can't convert %s to block without fitting" % self.__class__.__name__))
return ExamplewiseAddScaleTransform(add=(- self._mean))
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| X = dataset.get_design_matrix()
if can_fit:
self._mean = (X.mean() if self._global_mean else X.mean(axis=0))
self._std = (X.std() if self._global_std else X.std(axis=0))
elif ((self._mean is None) or (self._std is None)):
raise ValueError('can_fit is False, but Standardiz... |
'.. todo::
WRITEME'
| def as_block(self):
| if ((self._mean is None) or (self._std is None)):
raise ValueError(("can't convert %s to block without fitting" % self.__class__.__name__))
return ExamplewiseAddScaleTransform(add=(- self._mean), multiply=(self._std ** (-1)))
|
'.. todo::
WRITEME'
| def __call__(self, batch):
| if (batch.ndim != 2):
raise ValueError('Only two-dimensional tensors are supported')
return batch.dimshuffle(1, 0)[self._columns].dimshuffle(1, 0)
|
'.. todo::
WRITEME'
| def inverse(self):
| return ZeroColumnInsertBlock(self._columns, self._total)
|
'.. todo::
WRITEME'
| def get_input_space(self):
| return VectorSpace(dim=self._total)
|
'.. todo::
WRITEME'
| def get_output_space(self):
| return VectorSpace(dim=self._columns)
|
'.. todo::
WRITEME'
| def __init__(self, columns, total):
| self._columns = columns
self._total = total
|
'.. todo::
WRITEME'
| def __call__(self, batch):
| if (batch.ndim != 2):
raise ValueError('Only two-dimensional tensors are supported')
return insert_columns(batch, self._total, self._columns)
|
'.. todo::
WRITEME'
| def inverse(self):
| return ColumnSubsetBlock(self._columns, self._total)
|
'.. todo::
WRITEME'
| def get_input_space(self):
| return VectorSpace(dim=self._columns)
|
'.. todo::
WRITEME'
| def get_output_space(self):
| return VectorSpace(dim=self._total)
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| design_matrix = dataset.get_design_matrix()
mean = design_matrix.mean(axis=0)
var = design_matrix.var(axis=0)
(columns,) = numpy.where(((var < self._eps) & (mean < self._eps)))
self._block = ColumnSubsetBlock
|
'.. todo::
WRITEME'
| def as_block(self):
| if (self._block is None):
raise ValueError(("can't convert %s to block without fitting" % self.__class__.__name__))
return self._block
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| X = dataset.get_design_matrix()
X = ((X - self.map_from[0]) / numpy.diff(self.map_from))
X = ((X * numpy.diff(self.map_to)) + self.map_to[0])
dataset.set_design_matrix(X)
|
'.. todo::
WRITEME'
| def view_shape(self):
| return self.orig_view_converter.shape
|
'.. todo::
WRITEME'
| def design_mat_to_topo_view(self, X):
| to_input = self.to_input(X)
return self.orig_view_converter.design_mat_to_topo_view(to_input)
|
'.. todo::
WRITEME'
| def design_mat_to_weights_view(self, X):
| to_weights = self.to_weights(X)
return self.orig_view_converter.design_mat_to_weights_view(to_weights)
|
'.. todo::
WRITEME'
| def topo_view_to_design_mat(self, V):
| return self.to_pca(self.orig_view_converter.topo_view_to_design_mat(V))
|
'.. todo::
WRITEME'
| def get_formatted_batch(self, batch, dspace):
| if isinstance(dspace, VectorSpace):
dspace.np_validate(batch)
return batch
else:
to_input = self.to_input(batch)
return self.orig_view_converter.get_formatted_batch(to_input, dspace)
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| if (self._pca is None):
if (not can_fit):
raise ValueError('can_fit is False, but PCA preprocessor object has no fitted model stored')
from pylearn2.models import pca
self._pca = pca.CovEigPCA(num_components=self._num_components, whiten=self._whit... |
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| X = dataset.get_topological_view()
d = (len(X.shape) - 2)
assert (d in [2, 3])
assert ((X.dtype == 'float32') or (X.dtype == 'float64'))
if (d == 2):
X = X.reshape([X.shape[0], X.shape[1], X.shape[2], 1, X.shape[3]])
kernel_size = 1
kernel_shape = [X.shape[(-1)]]
for factor in se... |
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| if (self._batch_size is None):
X = global_contrast_normalize(dataset.get_design_matrix(), scale=self._scale, subtract_mean=self._subtract_mean, use_std=self._use_std, sqrt_bias=self._sqrt_bias, min_divisor=self._min_divisor)
dataset.set_design_matrix(X)
else:
data = dataset.get_design_ma... |
'Performs matrix multiplication.
Attempts to use the GPU if it\'s available. If the matrix multiplication
is too big to fit on the GPU, this falls back to the CPU after throwing
a warning.
Parameters
matrix_a : WRITEME
matrix_b : WRITEME
matrix_c : WRITEME'
| @staticmethod
def _gpu_matrix_dot(matrix_a, matrix_b, matrix_c=None):
| if (not hasattr(ZCA._gpu_matrix_dot, 'theano_func')):
(ma, mb) = theano.tensor.matrices('A', 'B')
mc = theano.tensor.dot(ma, mb)
ZCA._gpu_matrix_dot.theano_func = theano.function([ma, mb], mc, allow_input_downcast=True)
theano_func = ZCA._gpu_matrix_dot.theano_func
try:
if (m... |
'Performs the matrix multiplication M * D * M^T.
First tries to do this on the GPU. If this throws a MemoryError, it
falls back to the CPU, with a warning message.
Parameters
mat : WRITEME
diags : WRITEME'
| @staticmethod
def _gpu_mdmt(mat, diags):
| floatX = theano.config.floatX
if (not hasattr(ZCA._gpu_mdmt, 'theano_func')):
t_mat = theano.tensor.matrix('M')
t_diags = theano.tensor.vector('D')
result = theano.tensor.dot((t_mat * t_diags), t_mat.T)
ZCA._gpu_mdmt.theano_func = theano.function([t_mat, t_diags], result, allow_i... |
'Analogous to DenseDesignMatrix.use_design_loc().
If a matrices_save_path is set, when this ZCA is pickled, the internal
parameter matrices will be saved separately to `matrices_save_path`, as
a numpy .npz archive. This uses half the memory that a normal pickling
does.
Parameters
matrices_save_path : WRITEME'
| def set_matrices_save_path(self, matrices_save_path):
| if (matrices_save_path is not None):
assert isinstance(matrices_save_path, str)
matrices_save_path = os.path.abspath(matrices_save_path)
if os.path.isdir(matrices_save_path):
raise IOError('Matrix save path "%s" must not be an existing directory.')
... |
'Used by pickle. Returns a dictionary to pickle in place of
self.__dict__.
If self.matrices_save_path is set, this saves the matrices P_ and
inv_P_ separately in matrices_save_path as a .npz archive, which uses
much less space & memory than letting pickle handle them.'
| def __getstate__(self):
| result = copy.copy(self.__dict__)
if (self.matrices_save_path is not None):
matrices = {'P_': self.P_}
if (self.inv_P_ is not None):
matrices['inv_P_'] = self.inv_P_
numpy.savez(self.matrices_save_path, **matrices)
for (key, matrix) in matrices.items():
de... |
'Used to unpickle.
Parameters
state : dict
The dictionary created by __setstate__, presumably unpickled
from disk.'
| def __setstate__(self, state):
| if ('matrices_save_path' not in state):
state['matrices_save_path'] = None
if (state['matrices_save_path'] is not None):
matrices = numpy.load(state['matrices_save_path'])
state = dict((state.items() + matrices.items()))
del matrices
self.__dict__.update(state)
if (not ha... |
'Fits this `ZCA` instance to a design matrix `X`.
Parameters
X : ndarray
A matrix where each row is a datum.
Notes
Implementation details:
Stores result as `self.P_`.
If self.store_inverse is true, this also computes `self.inv_P_`.'
| def fit(self, X):
| assert (X.dtype in ['float32', 'float64'])
assert (not contains_nan(X))
assert (len(X.shape) == 2)
n_samples = X.shape[0]
if self.copy:
X = X.copy()
self.mean_ = numpy.mean(X, axis=0)
X -= self.mean_
log.info('computing zca of a {0} matrix'.format(X.shape))
t1 ... |
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| if (not hasattr(ZCA, '_x_minus_mean_times_p')):
x_symbol = tensor.matrix('X')
mean_symbol = tensor.vector('mean')
p_symbol = tensor.matrix('P_')
new_x_symbol = tensor.dot((x_symbol - mean_symbol), p_symbol)
ZCA._x_minus_mean_times_p = theano.function([x_symbol, mean_symbol, p... |
'.. todo::
WRITEME'
| def inverse(self, X):
| assert (X.ndim == 2)
if (self.inv_P_ is None):
warnings.warn('inv_P_ was None. Computing inverse of P_ now. This will take some time. For efficiency, it is recommended that in the future you compute the inverse in ZCA.fit()... |
'.. todo::
WRITEME properly
Parameters
X : WRITEME
data with axis [b, 0, 1, c]'
| def transform(self, x):
| for i in self._channels:
assert isinstance(i, int)
assert ((i >= 0) and (i <= x.shape[3]))
x[:, :, :, i] = lecun_lcn(x[:, :, :, i], self._img_shape, self._kernel_size, self._threshold)
return x
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| axes = ['b', 0, 1, 'c']
data_size = dataset.X.shape[0]
if (self._channels is None):
self._channels
last = (numpy.floor((data_size / float(self._batch_size))) * self._batch_size)
for i in xrange(0, data_size, self._batch_size):
stop = ((i + numpy.mod(data_size, self._batch_size)) if (... |
'.. todo::
WRITEME'
| def yuv_rgb(self, x):
| y = x[:, :, :, 0]
u = x[:, :, :, 1]
v = x[:, :, :, 2]
r = (y + (1.13983 * v))
g = ((y - (0.39465 * u)) - (0.5806 * v))
b = (y + (2.03211 * u))
x[:, :, :, 0] = r
x[:, :, :, 1] = g
x[:, :, :, 2] = b
return x
|
'.. todo::
WRITEME'
| def rgb_yuv(self, x):
| r = x[:, :, :, 0]
g = x[:, :, :, 1]
b = x[:, :, :, 2]
y = (((0.299 * r) + (0.587 * g)) + (0.114 * b))
u = ((((-0.14713) * r) - (0.28886 * g)) + (0.436 * b))
v = (((0.615 * r) - (0.51499 * g)) - (0.10001 * b))
x[:, :, :, 0] = y
x[:, :, :, 1] = u
x[:, :, :, 2] = v
return x
|
'.. todo::
WRITEME'
| def transform(self, x, dataset_axes):
| axes = ['b', 0, 1, 'c']
x = convert_axes(x, dataset_axes, axes)
if self._rgb_yuv:
x = self.rgb_yuv(x)
else:
x = self.yuv_rgb(x)
x = convert_axes(x, axes, dataset_axes)
return x
|
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| X = dataset.X
data_size = X.shape[0]
last = (numpy.floor((data_size / float(self._batch_size))) * self._batch_size)
for i in xrange(0, data_size, self._batch_size):
stop = ((i + numpy.mod(data_size, self._batch_size)) if (i >= last) else (i + self._batch_size))
log.info('RGB_YUV proce... |
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| (w_rows, w_cols) = self.window_shape
arr = dataset.get_topological_view()
try:
axes = dataset.view_converter.axes
except AttributeError:
reraise_as(NotImplementedError("I don't know how to tell what the axes of this kind of dataset are."))
ne... |
'.. todo::
WRITEME'
| def apply(self, dataset, can_fit=False):
| start = self.start
stop = self.stop
rng = make_np_rng(self.seed, which_method='randint')
X = dataset.X
y = dataset.y
if (y is not None):
assert (X.shape[0] == y.shape[0])
for i in xrange(X.shape[0]):
j = rng.randint(X.shape[0])
tmp = X[i, :].copy()
X[i, :] = X... |
'.. todo::
WRITEME'
| def __init__(self, path, which_set):
| Xs = io.loadmat(path)
X = Xs[which_set]
super(MatlabDataset, self).__init__(X=N.cast[config.floatX](X))
assert (not N.any(N.isnan(self.X)))
|
'.. todo::
WRITEME'
| def get_design_matrix(self, topo=None):
| if (topo is not None):
return self.raw.get_design_matrix(topo)
X = self.raw.get_design_matrix()
return self.transformer.perform(X)
|
'Caches a file locally if possible. If caching was succesfull, or if
the file was previously successfully cached, this method returns the
path to the local copy of the file. If not, it returns the path to
the original file.
Parameters
filename : string
Remote file to cache locally
Returns
output : string
Updated (if ne... | def cache_file(self, filename):
| remote_name = string_utils.preprocess(filename)
if (self.dataset_local_dir == ''):
return filename
common_msg = 'Message from Pylearn2 local cache of dataset(specified by the environment variable PYLEARN2_LOCAL_DATA_PATH): '
if (not os.path.exists(remote_name)... |
'Copies a remote file locally
Parameters
remote_fname : string
Remote file to copy
local_fname : string
Path and name of the local copy to be made of the remote
file.'
| def copy_from_server_to_local(self, remote_fname, local_fname):
| (head, tail) = os.path.split(local_fname)
head += os.path.sep
if (not os.path.exists(head)):
os.makedirs(os.path.dirname(head))
command = ((('cp ' + remote_fname) + ' ') + local_fname)
os.system(command)
st = os.stat(remote_fname)
os.chmod(local_fname, st.st_mode)
try:
... |
'Return free usage about the given path, in bytes
Parameters
path : string
Folder for which to return disk usage
Returns
output : tuple
Tuple containing total space in the folder and currently
used space in the folder'
| def disk_usage(self, path):
| st = os.statvfs(path)
total = (st.f_blocks * st.f_frsize)
used = ((st.f_blocks - st.f_bfree) * st.f_frsize)
return (total, used)
|
'Check if the given local folder has enough space to store
the specified remote file
Parameters
remote_fname : string
Path to the remote file
remote_fname : string
Path to the local folder
max_disk_usage : float
Fraction indicating how much of the total space in the
local folder can be used before the local cache must ... | def check_enough_space(self, remote_fname, local_fname, max_disk_usage=0.9):
| storage_need = os.path.getsize(remote_fname)
(storage_total, storage_used) = self.disk_usage(self.dataset_local_dir)
return ((storage_used + storage_need) < (storage_total * max_disk_usage))
|
'Create the specified folder. If the parent folders do not
exist, they are also created. If the folder already exists,
nothing is done.
Parameters
folderName : string
Name of the folder to create
force_perm : mode to use for folder creation'
| def safe_mkdir(self, folderName, force_perm=None):
| if os.path.exists(folderName):
return
intermediaryFolders = folderName.split(os.path.sep)
if (intermediaryFolders[(-1)] == ''):
intermediaryFolders = intermediaryFolders[:(-1)]
if force_perm:
force_perm_path = folderName.split(os.path.sep)
if (force_perm_path[(-1)] == '')... |
'Obtain a readlock on a file
Parameters
path : string
Name of the file on which to obtain a readlock'
| def get_readlock(self, path):
| timestamp = int((time.time() * 1000000.0))
lockdirName = ('%s.readlock.%i.%i' % (path, self.pid, timestamp))
os.mkdir(lockdirName)
atexit.register(self.release_readlock, lockdirName=lockdirName)
|
'Release a previously obtained readlock
Parameters
lockdirName : string
Name of the previously obtained readlock'
| def release_readlock(self, lockdirName):
| if (os.path.exists(lockdirName) and os.path.isdir(lockdirName)):
os.rmdir(lockdirName)
|
'Obtain a writelock on a file.
Only one write lock may be held at any given time.
Parameters
filename : string
Name of the file on which to obtain a writelock'
| def get_writelock(self, filename):
| compilelock.get_lock((filename + '.writelock'))
|
'Release the previously obtained writelock'
| def release_writelock(self):
| compilelock.release_lock()
|
'Partition the dataset according to cross-validation subsets and
return the raw data in each subset.'
| def get_data_subsets(self):
| for subsets in self.subset_iterator:
labels = None
if (len(subsets) == 3):
labels = ['train', 'valid', 'test']
elif (len(subsets) == 2):
labels = ['train', 'test']
data_subsets = OrderedDict()
for (i, subset) in enumerate(subsets):
subset_d... |
'Create a DenseDesignMatrix for each dataset subset and apply any
preprocessing to the child datasets.'
| def __iter__(self):
| for data_subsets in self.get_data_subsets():
datasets = {}
for (label, data) in data_subsets.items():
(X, y) = data
datasets[label] = DenseDesignMatrix(X=X, y=y)
if (self.preprocessor is not None):
self.preprocessor.apply(datasets['train'], can_fit=self.fi... |
'Stratified cross-validation requires label information for
examples. This function gets target values for a dataset,
converting from one-hot encoding to a 1D array as needed.
Parameters
dataset : object
Dataset containing target values for examples.'
| @staticmethod
def get_y(dataset):
| y = np.asarray(dataset.y)
if (y.ndim > 1):
assert np.array_equal(np.unique(y), [0, 1])
y = np.argmax(y, axis=1)
return y
|
'Construct a Transformer dataset for each partition.'
| def __iter__(self):
| for (k, datasets) in enumerate(self.dataset_iterator):
if isinstance(self.transformers, list):
transformer = self.transformers[k]
elif isinstance(self.transformers, StackedBlocksCV):
transformer = self.transformers.select_fold(k)
else:
transformer = self.t... |
'Add tracking to all trainers.
Parameters
trainers : list
List of Train objects belonging to the parent TrainCV object.'
| def setup(self, trainers):
| for (k, trainer) in enumerate(trainers):
if ((self.save_path is not None) and self.save_folds):
(path, ext) = os.path.splitext(self.save_path)
save_path = ((path + '-{}'.format(k)) + ext)
else:
save_path = None
if (self.tag_key is not None):
ta... |
'Save best model from each cross-validation fold.
Parameters
trainers : list
List of Train objects belonging to the parent TrainCV object.'
| def on_save(self, trainers):
| if (self.save_path is None):
return
models = []
for trainer in trainers:
for extension in trainer.extensions:
if isinstance(extension, MonitorBasedSaveBest):
models.append(extension.best_model)
break
assert (len(models) == len(trainers))
tr... |
'Choose a single cross-validation fold to represent.
Parameters
k : int
Index of selected fold.'
| def select_fold(self, k):
| return self._folds[k]
|
'Get input space.'
| def get_input_space(self):
| return self._folds[0][0].get_input_space()
|
'Get output space.'
| def get_output_space(self):
| return self._folds[0][(-1)].get_output_space()
|
'Set input space.
Parameters
space : WRITEME
Input space.'
| def set_input_space(self, space):
| for fold in self._folds:
this_space = space
for layer in fold._layers:
layer.set_input_space(this_space)
this_space = layer.get_output_space()
|
'Set up the main loop.'
| def setup(self):
| self.setup_extensions()
|
'Set up extensions.'
| def setup_extensions(self):
| for extension in self.cv_extensions:
extension.setup(self.trainers)
|
'Run main_loop of each trainer.
Note: if you get PickleErrors when running in parallel, make sure
you have `dill` installed.
Parameters
time_budget : int, optional
The maximum number of seconds before interrupting
training. Default is `None`, no time limit.
parallel : bool, optional
Whether to train subtrainers in para... | def main_loop(self, time_budget=None, parallel=False, client_kwargs=None, view_flags=None):
| self.setup()
if parallel:
from IPython.parallel import Client
def _train(trainer, time_budget=None):
'\n Run main_loop of this trainer.\n\n Parame... |
'Call on_save for Train and TrainCV extensions and serialize trained
models if save_path is set.'
| def save(self):
| for trainer in self.trainers:
for extension in trainer.extensions:
extension.on_save(trainer.model, trainer.dataset, trainer.algorithm)
for extension in self.cv_extensions:
extension.on_save(self.trainers)
if (self.save_path is not None):
models = [trainer.model for train... |
'Yield train/valid/test splits.'
| def __iter__(self):
| cv = list(super(ValidationKFold, self).__iter__())
for (train, valid, test) in get_k_fold_splits(cv):
(yield (train, valid, test))
|
'Yield train/valid/test splits.'
| def __iter__(self):
| cv = list(super(StratifiedValidationKFold, self).__iter__())
for (train, valid, test) in get_k_fold_splits(cv):
(yield (train, valid, test))
|
'Return train/valid/test splits. The validation set is generated by
splitting the training set.'
| def __iter__(self):
| for (train, test) in super(ValidationShuffleSplit, self).__iter__():
n = len(np.arange(self.n)[train])
train_cv = ShuffleSplit(n, test_size=self.valid_size, random_state=self.random_state)
(train, valid) = get_validation_set_from_train(train, train_cv)
(yield (train, valid, test))
|
'Return train/valid/test splits. The validation set is generated by
a stratified split of the training set.'
| def __iter__(self):
| for (train, test) in super(StratifiedValidationShuffleSplit, self).__iter__():
y = self.y[train]
train_cv = StratifiedShuffleSplit(y, test_size=self.valid_size, random_state=self.random_state)
(train, valid) = get_validation_set_from_train(train, train_cv)
(yield (train, valid, test)... |
'Choose a single cross-validation fold to represent.
Parameters
k : int
Index of selected fold.'
| def select_fold(self, k):
| return self._folds[k]
|
'Set input space.
Parameters
space : Space
The input space for this layer.'
| def set_input_space(self, space):
| return [fold.set_input_space(space) for fold in self._folds]
|
'Get parameters.'
| def get_params(self):
| return self._folds[0].get_params()
|
'Get input space.'
| def get_input_space(self):
| return self._folds[0].get_input_space()
|
'Get output space.'
| def get_output_space(self):
| return self._folds[0].get_output_space()
|
'Get monitoring channels.'
| def get_monitoring_channels(self):
| return self._folds[0].get_monitoring_channels()
|
'Store state of parameters, ensure that parameters are the same
as when the model was last monitored'
| def on_save(self, model, dataset, algorithm):
| self.params_on_save = np.asarray(model.get_param_values())
param_pairs = zip(self.params_on_save, self.params_on_monitor)
for (save_params, monitor_params) in param_pairs:
assert np.array_equal(save_params, monitor_params)
|
'Store state of parameters'
| def on_monitor(self, model, dataset, algorithm):
| self.params_on_monitor = np.asarray(model.get_param_values())
|
'Return a hash based on the object ID (to avoid hashing unhashable
namedtuple elements).'
| def __hash__(self):
| return hash(id(self))
|
'Modifies the parameters before a learning update is applied.
This method acts *after* the model subclass\' _modify_updates
method and any ModelExtensions that come earlier in the
extensions list.
Parameters
updates : dict
A dictionary mapping shared variables to symbolic values they
will be updated to.
model : Model
T... | def post_modify_updates(self, updates, model):
| pass
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.