當前位置: 首頁>>代碼示例>>Python>>正文


Python FeedForwardNetwork.addOutputModule方法代碼示例

本文整理匯總了Python中pybrain.structure.networks.feedforward.FeedForwardNetwork.addOutputModule方法的典型用法代碼示例。如果您正苦於以下問題:Python FeedForwardNetwork.addOutputModule方法的具體用法?Python FeedForwardNetwork.addOutputModule怎麽用?Python FeedForwardNetwork.addOutputModule使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pybrain.structure.networks.feedforward.FeedForwardNetwork的用法示例。


在下文中一共展示了FeedForwardNetwork.addOutputModule方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
def main():
    a = 0
    for i in range(0,100):
        inLayer = SigmoidLayer(2)
        hiddenLayer = SigmoidLayer(3)
        outLayer = SigmoidLayer(1)
        
        net = FeedForwardNetwork()
        net.addInputModule(inLayer)
        net.addModule(hiddenLayer)
        net.addOutputModule(outLayer)
        
        in_to_hidden = FullConnection(inLayer,hiddenLayer)
        hidden_to_out = FullConnection(hiddenLayer,outLayer)
        
        net.addConnection(in_to_hidden)
        net.addConnection(hidden_to_out)
        
        net.sortModules()
        
        ds = SupervisedDataSet(2,1)
        ds.addSample((1,1), (0))
        ds.addSample((1,0), (1))
        ds.addSample((0,1), (1))
        ds.addSample((0,0), (0))
        
        trainer = BackpropTrainer(net,ds)
        trainer.trainUntilConvergence()
        
        out = net.activate((1,1))
        if (out < 0.5):
            a = a + 1
    print(str(a) + "/100")
開發者ID:Kerzak1408,項目名稱:HearthstoneAI,代碼行數:35,代碼來源:neural_network.py

示例2: __init__

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
    def __init__(self, states, verbose=False, max_epochs=None):
        '''Create a NeuralNetwork instance.

        `states` is a tuple of tuples of ints, representing the discovered subnetworks'
        entrez ids.
        '''
        self.verbose         = verbose
        self.max_epochs      = max_epochs
        self.num_features    = sum(map(lambda tup: len(tup), states))
        self.states          = states

        n = FeedForwardNetwork()
        n.addOutputModule(TanhLayer(1, name='out'))
        n.addModule(BiasUnit(name='bias out'))
        n.addConnection(FullConnection(n['bias out'], n['out']))

        for i, state in enumerate(states):
            dim = len(state)
            n.addInputModule(TanhLayer(dim, name='input %s' % i))
            n.addModule(BiasUnit(name='bias input %s' % i))
            n.addConnection(FullConnection(n['bias input %s' % i], n['input %s' % i]))
            n.addConnection(FullConnection(n['input %s' % i], n['out']))

        n.sortModules()
        self.n = n
開發者ID:mrorii,項目名稱:crane,代碼行數:27,代碼來源:neural_network.py

示例3: buildSharedCrossedNetwork

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
def buildSharedCrossedNetwork():
    """ build a network with shared connections. Two hidden modules are
    symmetrically linked, but to a different input neuron than the
    output neuron. The weights are random. """
    N = FeedForwardNetwork('shared-crossed')
    h = 1
    a = LinearLayer(2, name = 'a')
    b = LinearLayer(h, name = 'b')
    c = LinearLayer(h, name = 'c')
    d = LinearLayer(2, name = 'd')
    N.addInputModule(a)
    N.addModule(b)
    N.addModule(c)
    N.addOutputModule(d)

    m1 = MotherConnection(h)
    m1.params[:] = scipy.array((1,))

    m2 = MotherConnection(h)
    m2.params[:] = scipy.array((2,))

    N.addConnection(SharedFullConnection(m1, a, b, inSliceTo = 1))
    N.addConnection(SharedFullConnection(m1, a, c, inSliceFrom = 1))
    N.addConnection(SharedFullConnection(m2, b, d, outSliceFrom = 1))
    N.addConnection(SharedFullConnection(m2, c, d, outSliceTo = 1))
    N.sortModules()
    return N
開發者ID:kortschak,項目名稱:pybrain,代碼行數:29,代碼來源:test_shared_connections.py

示例4: buildXor

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
 def buildXor(self):
     self.params['dataset'] = 'XOR'
     d = ClassificationDataSet(2)
     d.addSample([0., 0.], [0.])
     d.addSample([0., 1.], [1.])
     d.addSample([1., 0.], [1.])
     d.addSample([1., 1.], [0.])
     d.setField('class', [[0.], [1.], [1.], [0.]])
     self.trn_data = d
     self.tst_data = d
     global trn_data
     trn_data = self.trn_data
     nn = FeedForwardNetwork()
     inLayer = TanhLayer(2, name='in')
     hiddenLayer = TanhLayer(3, name='hidden0')
     outLayer = ThresholdLayer(1, name='out')
     nn.addInputModule(inLayer)
     nn.addModule(hiddenLayer)
     nn.addOutputModule(outLayer)
     in_to_hidden = FullConnection(inLayer, hiddenLayer)
     hidden_to_out = FullConnection(hiddenLayer, outLayer)
     nn.addConnection(in_to_hidden)
     nn.addConnection(hidden_to_out)
     nn.sortModules()
     nn.randomize()
     self.net_settings = str(nn.connections)
     self.nn = nn
開發者ID:mfbx9da4,項目名稱:neuron-astrocyte-networks,代碼行數:29,代碼來源:pybrain_ga.py

示例5: custom_build_network

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
def custom_build_network(layer_sizes):
    net = FeedForwardNetwork()
    
    layers = []
    inp = SigmoidLayer(layer_sizes[0], name = 'visible')
    h1 = SigmoidLayer(layer_sizes[1], name = 'hidden1')
    h2 = SigmoidLayer(layer_sizes[2], name = 'hidden2')
    out = SigmoidLayer(layer_sizes[3], name = 'out')
    bias = BiasUnit(name = 'bias')
    
    net.addInputModule(inp)
    net.addModule(h1)
    net.addModule(h2)
    net.addOutputModule(out)
    net.addModule(bias)
    
    net.addConnection(FullConnection(inp, h1))
    net.addConnection(FullConnection(h1, h2))
    net.addConnection(FullConnection(h2, out))
    
    net.addConnection(FullConnection(bias, h1))
    net.addConnection(FullConnection(bias, h2))
    net.addConnection(FullConnection(bias, out))
    
    
    net.sortModules()
    return net
開發者ID:simonhughes22,項目名稱:PythonNlpResearch,代碼行數:29,代碼來源:testPyBrain.py

示例6: buildSubsamplingNetwork

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
def buildSubsamplingNetwork():
    """ Builds a network with subsampling connections. """
    n = FeedForwardNetwork()
    n.addInputModule(LinearLayer(6, 'in'))
    n.addOutputModule(LinearLayer(1, 'out'))
    n.addConnection(SubsamplingConnection(n['in'], n['out'], inSliceTo=4))
    n.addConnection(SubsamplingConnection(n['in'], n['out'], inSliceFrom=4))
    n.sortModules()
    return n
開發者ID:davidmiller,項目名稱:pybrain,代碼行數:11,代碼來源:test_subsampling_connection.py

示例7: _buildNetwork

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
def _buildNetwork(*layers, **options):
    """This is a helper function to create different kinds of networks.

    `layers` is a list of tuples. Each tuple can contain an arbitrary number of
    layers, each being connected to the next one with IdentityConnections. Due
    to this, all layers have to have the same dimension. We call these tuples
    'parts.'

    Afterwards, the last layer of one tuple is connected to the first layer of
    the following tuple by a FullConnection.

    If the keyword argument bias is given, BiasUnits are added additionally with
    every FullConnection.

    Example:

        _buildNetwork(
            (LinearLayer(3),),
            (SigmoidLayer(4), GaussianLayer(4)),
            (SigmoidLayer(3),),
        )
    """
    bias = options['bias'] if 'bias' in options else False
    use_random_seed = options['use_random_seed'] if 'use_random_seed' in options else False

    net = FeedForwardNetwork()
    layerParts = iter(layers)
    firstPart = iter(next(layerParts))
    firstLayer = next(firstPart)
    net.addInputModule(firstLayer)

    prevLayer = firstLayer

    for part in chain(firstPart, layerParts):
        new_part = True
        for layer in part:
            net.addModule(layer)
            # Pick class depending on whether we entered a new part
            if new_part:
                ConnectionClass = FullConnection
                if bias:
                    biasUnit = BiasUnit('BiasUnit for %s' % layer.name)
                    net.addModule(biasUnit)
                    net.addConnection(FullConnection(biasUnit, layer, use_random_seed=use_random_seed))
            else:
                ConnectionClass = IdentityConnection
            new_part = False
            conn = ConnectionClass(prevLayer, layer)
            net.addConnection(conn)
            prevLayer = layer
    net.addOutputModule(layer)
    net.sortModules()
    return net
開發者ID:theoryno3,項目名稱:pybrain,代碼行數:55,代碼來源:shortcuts.py

示例8: buildSlicedNetwork

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
def buildSlicedNetwork():
    """ build a network with shared connections. Two hiddne modules are symetrically linked, but to a different 
    input neuron than the output neuron. The weights are random. """
    N = FeedForwardNetwork('sliced')
    a = LinearLayer(2, name = 'a')
    b = LinearLayer(2, name = 'b')
    N.addInputModule(a)
    N.addOutputModule(b)
    
    N.addConnection(FullConnection(a, b, inSliceTo=1, outSliceFrom=1))
    N.addConnection(FullConnection(a, b, inSliceFrom=1, outSliceTo=1))
    N.sortModules()
    return N
開發者ID:HKou,項目名稱:pybrain,代碼行數:15,代碼來源:test_sliced_connections.py

示例9: __init__

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
class PyBrainANNs:
    def __init__(self, x_dim, y_dim, hidden_size, s_id):
        self.serialize_id = s_id
        self.net = FeedForwardNetwork()

        in_layer = LinearLayer(x_dim)
        hidden_layer = SigmoidLayer(hidden_size)
        out_layer = LinearLayer(y_dim)
        self.net.addInputModule(in_layer)
        self.net.addModule(hidden_layer)
        self.net.addOutputModule(out_layer)

        in_to_hidden = FullConnection(in_layer, hidden_layer)
        hidden_to_out = FullConnection(hidden_layer, out_layer)
        self.net.addConnection(in_to_hidden)
        self.net.addConnection(hidden_to_out)

        self.net.sortModules()

    def _prepare_dataset(self, x_data, y_data):
        assert x_data.shape[0] == y_data.shape[0]

        if len(y_data.shape) == 1:
            y_matrix = np.matrix(y_data).T
        else:
            y_matrix = y_data.values

        assert x_data.shape[1] == self.net.indim
        assert y_matrix.shape[1] == self.net.outdim

        data_set = SupervisedDataSet(self.net.indim, self.net.outdim)
        data_set.setField("input", x_data)
        data_set.setField("target", y_matrix)

        return data_set

    def train(self, x_data, y_data):
        trainer = BackpropTrainer(self.net, self._prepare_dataset(x_data, y_data))
        trainer.train()

    def score(self, x_data, y_datas):
        return ModuleValidator.validate(regression_score, self.net, self._prepare_dataset(x_data, y_datas))

    def predict(self, x_data):
        return np.array([self.net.activate(sample) for sample in x_data])

    def save(self, path):
        joblib.dump(self.net, path)

    def load(self, path):
        self.net = joblib.load(path)
開發者ID:erdincay,項目名稱:ScoreGrass,代碼行數:53,代碼來源:PyBrainANNs.py

示例10: createNN

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
def createNN():
	nn = FeedForwardNetwork()
	inLayer = TanhLayer(4, name='in')
	hiddenLayer = TanhLayer(6, name='hidden0')
	outLayer = ThresholdLayer(3)
	nn.addInputModule(inLayer)
	nn.addModule(hiddenLayer)
	nn.addOutputModule(outLayer)
	in_to_hidden = FullConnection(inLayer, hiddenLayer)
	hidden_to_out = FullConnection(hiddenLayer, outLayer)
	nn.addConnection(in_to_hidden)
	nn.addConnection(hidden_to_out)
	nn.sortModules()
	return nn
開發者ID:mfbx9da4,項目名稱:neuron-astrocyte-networks,代碼行數:16,代碼來源:testmain.py

示例11: buildnet

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
def buildnet(modules):
    net = FeedForwardNetwork(name='mynet');
    net.addInputModule(modules['in'])
    net.addModule(modules['hidden'])
    net.addOutputModule(modules['out'])
    net.addModule(modules['bias'])
    net.addConnection(modules['in_to_hidden'])
    net.addConnection(modules['bias_to_hidden'])
    net.addConnection(modules['bias_to_out'])
    if ('hidden2' in modules):
        net.addModule(modules['hidden2'])
        net.addConnection(modules['hidden_to_hidden2'])
        net.addConnection(modules['bias_to_hidden2'])
        net.addConnection(modules['hidden2_to_out'])
    else:
        net.addConnection(modules['hidden_to_out'])
    net.sortModules()
    return net
開發者ID:gnrhxni,項目名稱:CS542,代碼行數:20,代碼來源:nettalk_modules.py

示例12: buildIris

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
 def buildIris(self):
     self.params['dataset'] = 'iris'
     self.trn_data, self.tst_data = pybrainData(0.5)
     global trn_data
     trn_data = self.trn_data
     nn = FeedForwardNetwork()
     inLayer = TanhLayer(4, name='in')
     hiddenLayer = TanhLayer(6, name='hidden0')
     outLayer = ThresholdLayer(3, name='out')
     nn.addInputModule(inLayer)
     nn.addModule(hiddenLayer)
     nn.addOutputModule(outLayer)
     in_to_hidden = FullConnection(inLayer, hiddenLayer)
     hidden_to_out = FullConnection(hiddenLayer, outLayer)
     nn.addConnection(in_to_hidden)
     nn.addConnection(hidden_to_out)
     nn.sortModules()
     nn.randomize()
     self.net_settings = str(nn.connections)
     self.nn = nn
開發者ID:mfbx9da4,項目名稱:neuron-astrocyte-networks,代碼行數:22,代碼來源:pybrain_ga.py

示例13: buildParity

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
 def buildParity(self):
     self.params['dataset'] = 'parity'
     self.trn_data = ParityDataSet(nsamples=75)
     self.trn_data.setField('class', self.trn_data['target'])
     self.tst_data = ParityDataSet(nsamples=75)
     global trn_data
     trn_data = self.trn_data
     nn = FeedForwardNetwork()
     inLayer = TanhLayer(4, name='in')
     hiddenLayer = TanhLayer(6, name='hidden0')
     outLayer = ThresholdLayer(1, name='out')
     nn.addInputModule(inLayer)
     nn.addModule(hiddenLayer)
     nn.addOutputModule(outLayer)
     in_to_hidden = FullConnection(inLayer, hiddenLayer)
     hidden_to_out = FullConnection(hiddenLayer, outLayer)
     nn.addConnection(in_to_hidden)
     nn.addConnection(hidden_to_out)
     nn.sortModules()
     nn.randomize()
     self.net_settings = str(nn.connections)
     self.nn = nn
開發者ID:mfbx9da4,項目名稱:neuron-astrocyte-networks,代碼行數:24,代碼來源:pybrain_ga.py

示例14: _build_network

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
def _build_network():
    logger.info("Building network...")

    net = FeedForwardNetwork()
    inp = LinearLayer(IMG_WIDTH * IMG_HEIGHT * 2)
    h1_image_width = IMG_WIDTH - FIRST_CONVOLUTION_FILTER + 1
    h1_image_height = IMG_HEIGHT - FIRST_CONVOLUTION_FILTER + 1
    h1_full_width = h1_image_width * CONVOLUTION_MULTIPLIER * NUMBER_OF_IMAGES
    h1_full_height = h1_image_height * CONVOLUTION_MULTIPLIER
    h1 = SigmoidLayer(h1_full_width * h1_full_height)

    h2_width = h1_full_width / 2
    h2_height = h1_full_height / 2
    h2 = LinearLayer(h2_width * h2_height)

    h3_image_width = h2_width / CONVOLUTION_MULTIPLIER / NUMBER_OF_IMAGES - SECOND_CONVOLUTION_FILTER + 1
    h3_image_height = h2_height / CONVOLUTION_MULTIPLIER - SECOND_CONVOLUTION_FILTER + 1
    h3_full_width = h3_image_width * (CONVOLUTION_MULTIPLIER * 2) * NUMBER_OF_IMAGES
    h3_full_height = h3_image_height * (CONVOLUTION_MULTIPLIER * 2)
    h3 = SigmoidLayer(h3_full_width * h3_full_height)

    h4_full_width = h3_image_width - MERGE_FILTER
    h4_full_height = h3_image_height - MERGE_FILTER
    h4 = SigmoidLayer(h4_full_width * h4_full_height)

    logger.info("BASE IMG: %d x %d" % (IMG_WIDTH, IMG_HEIGHT))
    logger.info("First layer IMG: %d x %d" % (h1_image_width, h1_image_height))
    logger.info("First layer FULL: %d x %d" % (h1_full_width, h1_full_height))
    logger.info("Second layer FULL: %d x %d" % (h2_width, h2_height))
    logger.info("Third layer IMG: %d x %d" % (h3_image_width, h3_image_height))
    logger.info("Third layer FULL: %d x %d" % (h3_full_width, h3_full_height))
    logger.info("Forth layer FULL: %d x %d" % (h3_image_width, h3_image_height))
    outp = SoftmaxLayer(2)

    h5 = SigmoidLayer(h4_full_width * h4_full_height)

    # add modules
    net.addOutputModule(outp)
    net.addInputModule(inp)
    net.addModule(h1)
    net.addModule(h2)
    net.addModule(h3)
    net.addModule(h4)
    net.addModule(h5)

    # create connections

    for i in range(NUMBER_OF_IMAGES):
        _add_convolutional_connection(
            net=net,
            h1=inp,
            h2=h1,
            filter_size=FIRST_CONVOLUTION_FILTER,
            multiplier=CONVOLUTION_MULTIPLIER,
            input_width=IMG_WIDTH * 2,
            input_height=IMG_HEIGHT,
            output_width=h1_full_width,
            output_height=h1_full_height,
            offset_x=h1_image_width * i,
            offset_y=0,
            size_x=h1_image_width,
            size_y=h1_image_height
        )

    _add_pool_connection(
        net=net,
        h1=h1,
        h2=h2,
        input_width=h1_full_width,
        input_height=h1_full_height
    )

    for i in range(NUMBER_OF_IMAGES * CONVOLUTION_MULTIPLIER):
        for j in range(CONVOLUTION_MULTIPLIER):
            _add_convolutional_connection(
                net=net,
                h1=h2,
                h2=h3,
                filter_size=SECOND_CONVOLUTION_FILTER,
                multiplier=CONVOLUTION_MULTIPLIER,
                input_width=h2_width,
                input_height=h2_height,
                output_width=h3_full_width,
                output_height=h3_full_height,
                offset_x=h3_image_width * i,
                offset_y=h3_image_height * j,
                size_x=h3_image_width,
                size_y=h3_image_height
            )

    _merge_connection(
        net=net,
        h1=h3,
        h2=h4,
        filter_size=MERGE_FILTER,
        input_width=h3_full_width,
        input_height=h3_full_height,
        output_width=h4_full_width,
        output_height=h4_full_height
    )
#.........這裏部分代碼省略.........
開發者ID:ShadowswordPL,項目名稱:PowerRecruiter,代碼行數:103,代碼來源:neural_network.py

示例15: phoneme_to_layer

# 需要導入模塊: from pybrain.structure.networks.feedforward import FeedForwardNetwork [as 別名]
# 或者: from pybrain.structure.networks.feedforward.FeedForwardNetwork import addOutputModule [as 別名]
class Network:
    "NETwhisperer neural network"
        
    def phoneme_to_layer(self, phoneme):
        return self.phonemes_to_layers[phoneme]

    def layer_to_phoneme(self, layer):
        def cos_to_input(item):
            phoneme, phoneme_layer = item
            return _cos(layer,phoneme_layer)
        # minimum angle should be maximum cos    
        return max(self.phonemes_to_layers.iteritems(), key=cos_to_input)[0]    

    def __init__(self, window_size, window_middle, n_hidden_neurons):
        self.window_size = window_size
        self.window_middle = window_middle
        self.n_hidden_neurons = n_hidden_neurons
        self.n_trainings = 0
        self.training_errors = []
        self._init_layers()
        self._generate_pybrain_network()
        
    def _init_layers(self):
        # one neuron for each window/letter combination
        self.letter_neuron_names = list(product(range(self.window_size), corpus.all_letters))
        # one neuron for each phoneme trait
        self.phoneme_trait_neuron_names = list(corpus.all_phoneme_traits)
        # neuron counts
        self.n_input_neurons = len(self.letter_neuron_names)
        self.n_output_neurons = len(self.phoneme_trait_neuron_names)        
        # mapping from (pos, letter) to input neuron index
        self.letters_to_neurons = dict({(pos_and_letter, index) for index, pos_and_letter in enumerate(self.letter_neuron_names)})
        # mapping from trait to neuron
        self.traits_to_neurons = dict({(trait, index) for index, trait in enumerate(self.phoneme_trait_neuron_names)})
        # mapping from phoneme to layer
        self.phonemes_to_layers = {}
        for (phoneme, traits) in corpus.phoneme_traits.iteritems():
            layer = zeros(self.n_output_neurons)
            for trait in traits:
                index = self.traits_to_neurons[trait]
                layer[index] = 1
            self.phonemes_to_layers[phoneme] = layer
            
    def _generate_pybrain_network(self):
        # make network
        self._pybrain_network = FeedForwardNetwork()
        # make layers
        self._in_layer = LinearLayer(self.n_input_neurons, name='in')
        self._hidden_layer = SigmoidLayer(self.n_hidden_neurons, name='hidden')
        self._out_layer = LinearLayer(self.n_output_neurons, name='out')
        self._bias_neuron = BiasUnit(name='bias')
        # make connections between layers
        self._in_hidden_connection = FullConnection(self._in_layer, self._hidden_layer)
        self._hidden_out_connection = FullConnection(self._hidden_layer, self._out_layer)
        self._bias_hidden_connection = FullConnection(self._bias_neuron, self._hidden_layer)
        self._bias_out_connection = FullConnection(self._bias_neuron, self._out_layer)
        # add modules to network
        self._pybrain_network.addInputModule(self._in_layer)
        self._pybrain_network.addModule(self._hidden_layer)
        self._pybrain_network.addOutputModule(self._out_layer)
        self._pybrain_network.addModule(self._bias_neuron)
        # add connections to network
        for c in (self._in_hidden_connection, self._hidden_out_connection, self._bias_hidden_connection, self._bias_out_connection):
            self._pybrain_network.addConnection(c)
        # initialize network with added modules/connections
        self._pybrain_network.sortModules()

    def windowIter(self, letters):
        assert type(letters) == str
        padding_before = ' ' * self.window_middle
        padding_after = ' ' * (self.window_size - self.window_middle - 1)
        padded_letters = padding_before + letters + padding_after
        # for each letter in the sample
        for l_num in range(len(letters)):
            letters_window = padded_letters[l_num:l_num+self.window_size]
            yield letters_window    

    def generateSamples(self, letters, phonemes):
        assert len(letters) == len(phonemes)
        for (letters_window, current_phoneme) in izip(self.windowIter(letters), phonemes):
            yield self.letters_to_layer(letters_window), self.phoneme_to_layer(current_phoneme)

    def letters_to_layer(self, letters):
        assert len(letters) == self.window_size
        # start with empty layer
        layer = zeros(self.n_input_neurons)
        # loop through letters and activate each neuron
        for (pos, letter) in enumerate(letters):
            index = self.letters_to_neurons[(pos, letter)]
            layer[index] = 1
        return layer
        
    def train(self, training_set, n_epochs=1, callback=None):
        # build dataset
        dataset = DataSet(self.n_input_neurons, self.n_output_neurons)
        for (ltr,ph) in training_set:
            for sample in self.generateSamples(ltr,ph):
                dataset.addSample(*sample)
        # build trainer
        trainer = Trainer(self._pybrain_network, dataset, 0.01, 1.0, 0.9)
#.........這裏部分代碼省略.........
開發者ID:LocusCoeruleus,項目名稱:netwhisperer,代碼行數:103,代碼來源:network.py


注:本文中的pybrain.structure.networks.feedforward.FeedForwardNetwork.addOutputModule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。