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.offset = self._network.offset
        self.backprojectionFactor = 0.01
Beispiel #2
0
    def __init__(self, boardSize, convSize, numFeatureMaps, **args):
        inputdim = 2
        FeedForwardNetwork.__init__(self, **args)
        inlayer = LinearLayer(inputdim * boardSize * boardSize, name='in')
        self.addInputModule(inlayer)

        # we need some treatment of the border too - thus we pad the direct board input.
        x = convSize / 2
        insize = boardSize + 2 * x
        if convSize % 2 == 0:
            insize -= 1
        paddedlayer = LinearLayer(inputdim * insize * insize, name='pad')
        self.addModule(paddedlayer)

        # we connect a bias to the padded-parts (with shared but trainable weights).
        bias = BiasUnit()
        self.addModule(bias)
        biasConn = MotherConnection(inputdim)

        paddable = []
        if convSize % 2 == 0:
            xs = range(x) + range(insize - x + 1, insize)
        else:
            xs = range(x) + range(insize - x, insize)
        paddable.extend(crossproduct([range(insize), xs]))
        paddable.extend(crossproduct([xs, range(x, boardSize + x)]))

        for (i, j) in paddable:
            self.addConnection(
                SharedFullConnection(biasConn,
                                     bias,
                                     paddedlayer,
                                     outSliceFrom=(i * insize + j) * inputdim,
                                     outSliceTo=(i * insize + j + 1) *
                                     inputdim))

        for i in range(boardSize):
            inmod = ModuleSlice(inlayer,
                                outSliceFrom=i * boardSize * inputdim,
                                outSliceTo=(i + 1) * boardSize * inputdim)
            outmod = ModuleSlice(paddedlayer,
                                 inSliceFrom=((i + x) * insize + x) * inputdim,
                                 inSliceTo=((i + x) * insize + x + boardSize) *
                                 inputdim)
            self.addConnection(IdentityConnection(inmod, outmod))

        self._buildStructure(inputdim, insize, paddedlayer, convSize,
                             numFeatureMaps)
        self.sortModules()
Beispiel #3
0
def build_ann(indim, outdim):
    ann = FeedForwardNetwork()

    ann.addInputModule(LinearLayer(indim, name='in'))
    ann.addModule(SigmoidLayer(5, name='hidden'))
    #    ann.addModule(Normal(2,name='hidden'))
    ann.addOutputModule(SoftmaxLayer(outdim, name='out'))
    ann.addModule(BiasUnit(name='bias'))

    ann.addConnection(FullConnection(ann['in'], ann['hidden']))
    ann.addConnection(FullConnection(ann['hidden'], ann['out']))
    #    ann.addConnection(FullConnection(ann['in'], ann['out']))
    ann.addConnection(FullConnection(ann['bias'], ann['out']))
    ann.addConnection(FullConnection(ann['bias'], ann['hidden']))

    ann.sortModules()

    #    ann = buildNetwork(indim, outdim, outclass=SoftmaxLayer)
    return ann
Beispiel #4
0
    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
aramdata = open("ARAMData.txt","r")

#ChampionDictionary holds all the riot static data about each champion. The Riot IDs are the keys of the dictionary
championdictionary = DatabaseActions.CreateChampionDictionary()

#Creates a Neural Network of Appropriate size
predictionNet = FeedForwardNetwork()

inLayer = LinearLayer(len(championdictionary))
hiddenLayer = SigmoidLayer(5)
outLayer = SigmoidLayer(1)

predictionNet.addInputModule(inLayer)
predictionNet.addModule(hiddenLayer)
predictionNet.addOutputModule(outLayer)
predictionNet.addModule(BiasUnit(name = 'bias'))

in_to_hidden = FullConnection(inLayer,hiddenLayer)
hidden_to_out = FullConnection(hiddenLayer,outLayer)

predictionNet.addConnection(in_to_hidden)
predictionNet.addConnection(hidden_to_out)
predictionNet.addConnection(FullConnection(predictionNet['bias'],hiddenLayer))
predictionNet.addConnection(FullConnection(predictionNet['bias'],outLayer))
predictionNet.sortModules()


trainingSet = SupervisedDataSet(len(championdictionary),1)

#Takes each game and turns it into a vector. -1 is stored if the champion is on the opposing team, 1 if the champion is on the player's team
#and 0 if it wasn't played. The vector is then fed into the Neural Network's Training Set
Beispiel #6
0
from pybrain.structure import FeedForwardNetwork
from pybrain.structure.modules.sigmoidlayer import SigmoidLayer
from pybrain.structure.modules.linearlayer import LinearLayer
from pybrain.structure.modules.biasunit import BiasUnit
from pybrain.structure.connections.full import FullConnection

rede = FeedForwardNetwork()
camadaEntrada = LinearLayer(2)
camadaOculta = SigmoidLayer(3)
camadaSaida = SigmoidLayer(1)
bias1 = BiasUnit()
bias2 = BiasUnit()

rede.addModule(camadaEntrada)
rede.addModule(camadaOculta)
rede.addModule(camadaSaida)
rede.addModule(bias1)
rede.addModule(bias2)

entradaOculta = FullConnection(camadaEntrada, camadaOculta)
ocultaSaida = FullConnection(camadaOculta, camadaSaida)
biasOculta = FullConnection(bias1,camadaOculta)
biasSaida = FullConnection(bias2,camadaSaida)

rede.sortModules()

print(rede)
print(entradaOculta.params)
print(ocultaSaida.params)
print(biasOculta.params)
print(biasSaida.params)
Beispiel #7
0
def build_exp_ann(indim, outdim):
    ann = FeedForwardNetwork()
    ann.addInputModule(LinearLayer(indim, name='in'))
    ann.addModule(SigmoidLayer(24, name='hidden'))
    ann.addOutputModule(SigmoidLayer(outdim, name='out'))
    ann.addModule(BiasUnit(name='bias'))

    hidd_neur_i = 0
    for cols, rows in ((1, 8), (4, 4)):  #(2,2), (4,4),
        height = int(32 / rows)
        width = int(32 / cols)
        for col in range(cols):
            for row in range(rows):
                if width < 32:
                    for line in range(height):
                        fr = col * width + line * 32 + row * 32 * height
                        to = fr + width

                        slices = {
                            'inSliceFrom':
                            fr,
                            'inSliceTo':
                            to,
                            'outSliceFrom':
                            hidd_neur_i,
                            'outSliceTo':
                            hidd_neur_i + 1,
                            'name':
                            "%dx%d group (%dx%d) %d line Input(%d-%d) -> Hidden(%d-%d)"
                            % (cols, rows, col + 1, row + 1, line, fr, to,
                               hidd_neur_i, hidd_neur_i + 1)
                        }

                        ann.addConnection(
                            FullConnection(ann['in'], ann['hidden'], **slices))
                else:
                    fr = row * width * height
                    to = fr + width * height

                    slices = {
                        'inSliceFrom':
                        fr,
                        'inSliceTo':
                        to,
                        'outSliceFrom':
                        hidd_neur_i,
                        'outSliceTo':
                        hidd_neur_i + 1,
                        'name':
                        "%dx%d group (%dx%d) %d line Input(%d-%d) -> Hidden(%d-%d)"
                        % (cols, rows, col + 1, row + 1, 0, fr, to,
                           hidd_neur_i, hidd_neur_i + 1)
                    }

                    ann.addConnection(
                        FullConnection(ann['in'], ann['hidden'], **slices))
                hidd_neur_i += 1

    ann.addConnection(FullConnection(ann['hidden'], ann['out']))
    ann.addConnection(FullConnection(ann['bias'], ann['out']))
    ann.addConnection(FullConnection(ann['bias'], ann['hidden']))

    ann.sortModules()
    return ann