Beispiel #1
0
    def __init__(self, params, population):
        # Copy params.
        if params is not None:
            self.__dict__ = params.copy()

        # Set another params
        self.area = self.cols * self.rows
        self.popsize = population
        self.functionCnt = len(
            self.functionSet) - 1  # Last idx, because of rand_int(a,b)
        self.graphInputCnt = len(self.dataInput)
        self.graphOutputCnt = len(self.dataOutput)
        self.maxFitness = 0
        self.bestFitness = float("inf")
        CgpEquation.run = CgpCore.runDescending

        self.c = cgp.Cgp()

        self.arrayTypecode = CgpEquation.ARRAY_TYPECODE

        self.trainingVectors = len(self.dataInput[0])

        self.__convertData()
        self._initOutputBuff()
        self._initUsedNodes(population)
        self.__initByteCodes(population)
        # Becouse we are using float we need to divide it 2
        if sys.maxsize > 2**32:
            self.bufferUsedNodes = self.bufferUsedNodes >> 1
            self.buffOffsetSize = self.buffOffsetSize >> 1
Beispiel #2
0
    def __init__(self, params, population):
        # Copy params.
        if params is not None:
            self.__dict__ = params.copy()

        # Set another params
        self.area = self.cols * self.rows
        self.popsize = population
        self.functionCnt = len(
            self.functionSet) - 1  # Last idx, because of rand_int(a,b)
        self.graphInputCnt = len(self.dataInput)
        self.graphOutputCnt = len(self.dataOutput)
        self.maxFitness = 2**self.graphInputCnt * self.graphOutputCnt
        self.bestFitness = 0
        CgpCircuit.run = CgpCore.runAscending  # Type of selecting parent.

        self.c = cgp.Cgp()  #$%^& hack

        self.arrayTypecode = CgpCircuit.ARRAY_TYPECODE

        self.trainingVectors = 1
        if sys.maxsize > 2**32:
            if self.graphInputCnt > 6:
                self.trainingVectors = int((2**self.graphInputCnt) / 64)
        else:
            if self.graphInputCnt > 5:
                self.trainingVectors = int((2**self.graphInputCnt) / 32)
        self.__convertData()
        self._initOutputBuff()
        self._initUsedNodes(population)
        self.__initLookUp()
        self.__initByteCodes(population)
        if sys.maxsize > 2**32:
            CgpCircuit.bitMax = 2**64
            self.mask = 2**64 - 1
        else:
            CgpCircuit.bitMax = 2**32
            self.mask = 2**32 - 1