Exemplo n.º 1
0
 def __init__(self, netWork_id = None, *argin):
     NetWork.__init__(self)
     self.__id = netWork_id
     self.initialize(argin)
Exemplo n.º 2
0
                    self.__synapse[ self.__connection[i][j] ].weight += learningRate * delta_cur[jn] * self.__neuron[i].output
                delta_pre[-1] *= self.__neuron[i].output * (1 - self.__neuron[i].output)
            delta_cur = delta_pre
            delta_pre = []

    def epochBatch(self, inputSet, outputSet, learningRate):
        pass

    def epochOnLine(self, inputValue, outputValue, learningRate):
        if (len(inputValue) != len(self.__inputNeuron) or len(outputValue) != len(self.__outputNeuron)):
            raise Exception('number of trainning data is not fit to network')
        self.probagate(*inputValue)
        error = []
        for i in range(len(outputValue)):
            error.append(outputValue[i] - self.__neuron[-len(self.__outputNeuron) + i])
        self.__backprobagate(error, learningRate)
        return sum([0.5 * e * e for e in error])

    def train(self, inputSet, outputSet, trainType = 'OnLine', learningRate = 0.1, maxIteration = 200, errorLimit = 0):
        for epoch in range(maxIteration):
            error = 0
            if trainType = 'OnLine':
                for i in range(len(inputSet)):
                    error += epochOnLine(inputSet[i], outputSet[i], learningRate)
                error /= len(inputSet)

            if error <= errorLimit:
                return

NetWork.register(MLP)