Ejemplo n.º 1
0
def unroll_network(network):
    '''
    Takes a pre-trained network and treats it as an encoder network. The decoder
    network is constructed by inverting the encoder. The decoder is then appended
    to the input network to produce an autoencoder.
    '''
    decoder = []
    encoder = []
    for i in range(len(network)):
        elayer = backprop.Layer(network[i].W.T, network[i].hbias,
                                network[i].n_hidden, network[i].hidtype)
        dlayer = backprop.Layer(network[i].W, network[i].vbias,
                                network[i].n_visible, network[i].vistype)
        encoder.append(elayer)
        decoder.append(dlayer)
    decoder.reverse()
    encoder.extend(decoder)
    return encoder
Ejemplo n.º 2
0
def to_feed_forward_network(dbn, top_layers):
    network = dbn.network
    '''
    Takes a pre-trained network and treats it as an top_layers network. The decoder
    network is constructed by inverting the top_layers. The decoder is then appended
    to the input network to produce an autoencoder.
    '''
    import backprop
    layers = []
    for i in range(len(network)):
        layer = backprop.Layer(network[i].W.T, network[i].hbias,
                               network[i].n_hidden, network[i].hidtype)
        layers.append(layer)

    net = layers + top_layers
    mlp = backprop.NeuralNet(network=net)
    return mlp