本文整理匯總了Python中pybrain.structure.modules.module.Module類的典型用法代碼示例。如果您正苦於以下問題:Python Module類的具體用法?Python Module怎麽用?Python Module使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Module類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
def __init__(self, dim, nNeurons, name=None, outputFullMap=False):
if outputFullMap:
outdim = nNeurons ** 2
else:
outdim = 2
Module.__init__(self, dim, outdim, name)
# switch modes
self.outputFullMap = outputFullMap
# create neurons
self.neurons = random.random((nNeurons, nNeurons, dim))
self.difference = zeros(self.neurons.shape)
self.winner = zeros(2)
self.nInput = dim
self.nNeurons = nNeurons
self.neighbours = nNeurons
self.learningrate = 0.01
self.neighbourdecay = 0.9999
# distance matrix
distx, disty = mgrid[0:self.nNeurons, 0:self.nNeurons]
self.distmatrix = zeros((self.nNeurons, self.nNeurons, 2))
self.distmatrix[:, :, 0] = distx
self.distmatrix[:, :, 1] = disty
示例2: __init__
def __init__(self, dim, peepholes = False, name = None):
"""
:arg dim: number of cells
:key peepholes: enable peephole connections (from state to gates)? """
self.setArgs(dim = dim, peepholes = peepholes)
# Internal buffers, created dynamically:
self.bufferlist = [
('ingate', dim),
('outgate', dim),
('forgetgate', dim),
('ingatex', dim),
('outgatex', dim),
('forgetgatex', dim),
('state', dim),
('ingateError', dim),
('outgateError', dim),
('forgetgateError', dim),
('stateError', dim),
]
Module.__init__(self, 4*dim, dim, name)
if self.peepholes:
ParameterContainer.__init__(self, dim*3)
self._setParameters(self.params)
self._setDerivatives(self.derivs)
示例3: __init__
def __init__(self, dim, oscParams=None, freqDist=None, name=None):
"""Create a layer with dim number of units."""
Module.__init__(self, dim*2, dim, name=name)
if oscParams is None:
oscParams = { 'a': 0, 'b1': -1, 'b2': -1, 'd1': 0, 'd2': 0, 'e': 1 }
if freqDist is None:
freqDist = {
'fspac': 'log',
'min': .5,
'max': 8
}
freqDist['min_r'] = freqDist['min'] * TWO_PI
freqDist['max_r'] = freqDist['max'] * TWO_PI
self.conns = []
self.setArgs(dim=dim, oscParams=oscParams, freqDist=freqDist)
self.setFreqs(freqDist)
self.z0 = np.zeros(dim, dtype=np.complex64)
self._ranomiseOscs()
self.kSteps = np.zeros((4, dim), dtype=np.complex64)
self.t = np.float32(0.)
示例4: __init__
def __init__(self, indim, outdim, hiddim=6):
Module.__init__(self, indim, outdim)
self._network = Network()
self._in_layer = LinearLayer(indim + outdim)
self._hid_layer = LSTMLayer(hiddim)
self._out_layer = LinearLayer(outdim)
self._bias = BiasUnit()
self._network.addInputModule(self._in_layer)
self._network.addModule(self._hid_layer)
self._network.addModule(self._bias)
self._network.addOutputModule(self._out_layer)
self._hid_to_out_connection = FullConnection(self._hid_layer , self._out_layer)
self._in_to_hid_connection = FullConnection(self._in_layer , self._hid_layer)
self._network.addConnection(self._hid_to_out_connection)
self._network.addConnection(self._in_to_hid_connection)
self._network.addConnection(FullConnection(self._bias, self._hid_layer))
self._network.sortModules()
self.time = self._network.time
self.backprojectionFactor = 0.01
示例5: __init__
def __init__(self, numRows, numColumns, name=None):
""" initialize with the number of rows and columns. the table
values are all set to zero.
"""
Module.__init__(self, 2, 1, name)
ParameterContainer.__init__(self, numRows*numColumns)
self.numRows = numRows
self.numColumns = numColumns
示例6: __init__
def __init__(self, actionnum, T, theta, **args):
self.feadim = len(theta)
Module.__init__(self, self.feadim * actionnum, 1, **args)
ParameterContainer.__init__(self, self.feadim)
self.T = T
self.g = None
self.bf = None
# feadimx1 vector.
self.theta = theta
self.actionnum = actionnum
self.cachedActionProb = None
示例7: activate
def activate(self, state, action):
""" The super class commonly ignores the state and simply passes the
action through the module. implement _forwardImplementation()
in subclasses.
"""
self.state = state
return Module.activate(self, action)
示例8: sortModules
def sortModules(self):
"""Prepare the network for activation by sorting the internal
datastructure.
Needs to be called before activation."""
if self.sorted:
return
# Sort the modules.
self._topologicalSort()
# Sort the connections by name.
for m in self.modules:
self.connections[m].sort(key=lambda x: x.name)
self.motherconnections.sort(key=lambda x: x.name)
# Create a single array with all parameters.
tmp = [pc.params for pc in self._containerIterator()]
total_size = sum(scipy.size(i) for i in tmp)
ParameterContainer.__init__(self, total_size)
if total_size > 0:
self.params[:] = scipy.concatenate(tmp)
self._setParameters(self.params)
# Create a single array with all derivatives.
tmp = [pc.derivs for pc in self._containerIterator()]
self.resetDerivatives()
self.derivs[:] = scipy.concatenate(tmp)
self._setDerivatives(self.derivs)
# TODO: make this a property; indim and outdim are invalid before
# .sortModules is called!
# Determine the input and output dimensions of the network.
self.indim = sum(m.indim for m in self.inmodules)
self.outdim = sum(m.outdim for m in self.outmodules)
self.indim = 0
for m in self.inmodules:
self.indim += m.indim
self.outdim = 0
for m in self.outmodules:
self.outdim += m.outdim
# Initialize the network buffers.
self.bufferlist = []
Module.__init__(self, self.indim, self.outdim, name=self.name)
self.sorted = True
示例9: __init__
def __init__(self, dim, dimensions=1, peepholes=False, name=None):
self.setArgs(dim=dim, peepholes=peepholes, dimensions=dimensions)
# Internal buffers:
self.bufferlist = [
('ingate', dim),
('outgate', dim),
('forgetgate', dim * dimensions),
('ingatex', dim),
('outgatex', dim),
('forgetgatex', dim * dimensions),
('state', dim),
('ingateError', dim),
('outgateError', dim),
('forgetgateError', dim * dimensions),
('stateError', dim),
]
Module.__init__(self, (3 + 2 * dimensions) * dim, dim * 2, name)
if self.peepholes:
ParameterContainer.__init__(self, dim * (2 + dimensions))
self._setParameters(self.params)
self._setDerivatives(self.derivs)
示例10: __init__
def __init__(self, outdim, hiddim=15):
""" Create an EvolinoNetwork with for sequences of dimension outdim and
hiddim dimension of the RNN Layer."""
indim = 0
Module.__init__(self, indim, outdim)
self._network = RecurrentNetwork()
self._in_layer = LinearLayer(indim + outdim)
self._hid_layer = LSTMLayer(hiddim)
self._out_layer = LinearLayer(outdim)
self._bias = BiasUnit()
self._network.addInputModule(self._in_layer)
self._network.addModule(self._hid_layer)
self._network.addModule(self._bias)
self._network.addOutputModule(self._out_layer)
self._in_to_hid_connection = FullConnection(self._in_layer,
self._hid_layer)
self._bias_to_hid_connection = FullConnection(self._bias,
self._hid_layer)
self._hid_to_out_connection = FullConnection(self._hid_layer,
self._out_layer)
self._network.addConnection(self._in_to_hid_connection)
self._network.addConnection(self._bias_to_hid_connection)
self._network.addConnection(self._hid_to_out_connection)
self._recurrent_connection = FullConnection(self._hid_layer,
self._hid_layer)
self._network.addRecurrentConnection(self._recurrent_connection)
self._network.sortModules()
self._network.reset()
self.offset = self._network.offset
self.backprojectionFactor = 0.01
示例11: __init__
def __init__(self, timedim, shape,
hiddendim, outsize, blockshape=None, name=None):
"""Initialize an MdrnnLayer.
The dimensionality of the sequence - for example 2 for a
picture or 3 for a video - is given by `timedim`, while the sidelengths
along each dimension are given by the tuple `shape`.
The layer will have `hiddendim` hidden units per swiping direction. The
number of swiping directions is given by 2**timedim, which corresponds
to one swipe from each corner to its opposing corner and back.
To indicate how many outputs per timesteps are used, you have to specify
`outsize`.
In order to treat blocks of the input and not single voxels, you can
also specify `blockshape`. For example the layer will then feed (2, 2)
chunks into the network at each timestep which correspond to the (2, 2)
rectangles that the input can be split into.
"""
self.timedim = timedim
self.shape = shape
blockshape = tuple([1] * timedim) if blockshape is None else blockshape
self.blockshape = shape
self.hiddendim = hiddendim
self.outsize = outsize
self.indim = reduce(operator.mul, shape, 1)
self.blocksize = reduce(operator.mul, blockshape, 1)
self.sequenceLength = self.indim / self.blocksize
self.outdim = self.sequenceLength * self.outsize
self.bufferlist = [('cellStates', self.sequenceLength * self.hiddendim)]
Module.__init__(self, self.indim, self.outdim, name=name)
# Amount of parameters that are required for the input to the hidden
self.num_in_params = self.blocksize * self.hiddendim * (3 + self.timedim)
# Amount of parameters that are needed for the recurrent connections.
# There is one of the parameter for every time dimension.
self.num_rec_params = outsize * hiddendim * (3 + self.timedim)
# Amount of parameters that are needed for the output.
self.num_out_params = outsize * hiddendim
# Amount of parameters that are needed from the bias to the hidden and
# the output
self.num_bias_params = (3 + self.timedim) * self.hiddendim + self.outsize
# Total list of parameters.
self.num_params = sum((self.num_in_params,
self.timedim * self.num_rec_params,
self.num_out_params,
self.num_bias_params))
ParameterContainer.__init__(self, self.num_params)
# Some layers for internal use.
self.hiddenlayer = MDLSTMLayer(self.hiddendim, self.timedim)
# Every point in the sequence has timedim predecessors.
self.predlayers = [LinearLayer(self.outsize) for _ in range(timedim)]
# We need a single layer to hold the input. We will swipe a connection
# over the corrects part of it, in order to feed the correct input in.
self.inlayer = LinearLayer(self.indim)
# Make some layers the same to save memory.
self.inlayer.inputbuffer = self.inlayer.outputbuffer = self.inputbuffer
# In order to allocate not too much memory, we just set the size of the
# layer to 1 and correct it afterwards.
self.outlayer = LinearLayer(self.outdim)
self.outlayer.inputbuffer = self.outlayer.outputbuffer = self.outputbuffer
self.bias = BiasUnit()
示例12: __init__
def __init__(self, dim, name=None):
Module.__init__(self, dim, dim * 2, name)
self.setArgs(dim=dim, name=self.name)
示例13: reset
def reset(self):
"""Reset all component modules and the network."""
Module.reset(self)
for m in self.modules:
m.reset()
示例14: __init__
def __init__(self, name=None):
Module.__init__(self, 0, 1, name = name)
示例15: __init__
def __init__(self, dim, name=None):
"""Create a layer with dim number of units."""
Module.__init__(self, dim, dim, name=name)
self.setArgs(dim=dim)