Exemplo n.º 1
0
            ## 1-4. lastScreen, lastDecision, lastPoint 갱신 ##
            for j in range(size):
                for k in range(size):
                    lastScreen[j][k] = screen[j][k]
            lastDecision = decision
            lastPoint = [point[0], point[1]]

        ### 2. 게임 종료 후 딥러닝 실행 ###
        if len(states) < 1000:  # 1000개 미만이면 모두 학습
            Qlearning_deep_GPU.deepQlearning(
                option, NN, op, 'mean_squared_error', states, outputs, Qdiffs,
                25, 'basket', [20, 25], [8, 'sigmoid', 'sigmoid'],
                [6, 'sigmoid', 'sigmoid'], False, False, True, deviceName)
        else:  # 1000개 이상이면 마지막 1000개만 학습
            Qlearning_deep_GPU.deepQlearning(
                option, NN, op, 'mean_squared_error',
                states[len(states) - 1000:], outputs[len(states) - 1000:],
                Qdiffs[len(states) - 1000:], 25, 'basket', [20, 25],
                [8, 'sigmoid', 'sigmoid'], [6, 'sigmoid', 'sigmoid'], False,
                False, True, deviceName)
        isFile = True

        if option % 3 == 0 or option % 3 == 1:
            model0 = Qlearning_deep_GPU.deepLearningModel('basket_0', False)
        if option % 3 == 1 or option % 3 == 2:
            model1 = Qlearning_deep_GPU.deepLearningModel('basket_1', False)

        print('\n\n << 점수 목록 >>')
        print(scores)
        print('')
                                keras.layers.Dropout(drop),
                                keras.layers.Dense(32, activation='relu'),
                                keras.layers.Dropout(drop),
                                keras.layers.Dense(32, activation='relu'),
                                keras.layers.Dropout(drop),
                                keras.layers.Dense(32, activation='relu'),
                                keras.layers.Dense(2, activation='sigmoid')]

                        # 5. 옵티마이저
                        op = tf.keras.optimizers.Adam(0.001)
                        
                        print('training...')
                        Qlearning_deep_GPU.deepQlearning(0, NN, op, lc, inputs, outputs, None, None, 'WPCNdeep', [epoc, None], None, None, False, False, True, deviceName)

                        # 6. 테스트 결과 확인하고 정답과 비교하기
                        newModel = Qlearning_deep_GPU.deepLearningModel('WPCNdeep_0', False)
                        sumTestThroughput = 0.0 # test throughput의 합계
                        sumCorrectMaxThroughput = 0.0 # 정답의 throughput의 합계 (training data를 생성할 때와 같은 방법으로 최대 throughput 확인)

                        optiInfo = open('optiInfo_' + str(problemNo) + '.txt', 'r')
                        optiInformation = optiInfo.readlines()
                        optiInfo.close()

                        print('testing...')
                        
                        for i in range(numTest):
                            testScreen = originalScreen[numTrain + i] # 테스트할 스크린
                            testOutput = Qlearning_deep_GPU.modelOutput(newModel, [testScreen]) # 테스트 결과
                            testOutputLayer = testOutput[len(testOutput)-1] # 테스트 결과의 output layer의 값

                            # 6-0. 테스트 결과 확인
            ## 1-4. lastScreen, lastDecision, lastPoint 갱신 ##
            for j in range(size):
                for k in range(size):
                    lastScreen[j][k] = screen[j][k]
            lastDecision = decision
            lastPoint = [point[0], point[1]]

        ### 2. 게임 종료 후 딥러닝 실행 ###
        if len(states) < 1000:  # 1000개 미만이면 모두 학습
            Qlearning_deep_GPU.deepQlearning(
                option, NN, op, 'mean_squared_error', states, outputs, Qdiffs,
                25, 'vectorCar', [20, 25], [8, 'sigmoid', 'sigmoid'],
                [6, 'sigmoid', 'sigmoid'], False, False, True, deviceName)
        else:  # 1000개 이상이면 마지막 1000개만 학습
            Qlearning_deep_GPU.deepQlearning(
                option, NN, op, 'mean_squared_error',
                states[len(states) - 1000:], outputs[len(states) - 1000:],
                Qdiffs[len(states) - 1000:], 25, 'vectorCar', [20, 25],
                [8, 'sigmoid', 'sigmoid'], [6, 'sigmoid', 'sigmoid'], False,
                False, True, deviceName)
        isFile = True

        if option % 3 == 0 or option % 3 == 1:
            model0 = Qlearning_deep_GPU.deepLearningModel('vectorCar_0', False)
        if option % 3 == 1 or option % 3 == 2:
            model1 = Qlearning_deep_GPU.deepLearningModel('vectorCar_1', False)

        print('\n\n << 점수 목록 >>')
        print(scores)
        print('')
            ## 1-4. lastScreen, lastDecision, lastPoint 갱신 ##
            for j in range(size):
                for k in range(size):
                    lastScreen[j][k] = screen[j][k]
            lastDecision = decision
            lastPoint = [point[0], point[1]]

        ### 2. 게임 종료 후 딥러닝 실행 ###
        if len(states) < 1000:  # 1000개 미만이면 모두 학습
            Qlearning_deep_GPU.deepQlearning(
                option, NN, op, 'mean_squared_error', states, outputs, Qdiffs,
                25, 'valueMaze', [20, 25], [8, 'sigmoid', 'sigmoid'],
                [6, 'sigmoid', 'sigmoid'], False, False, True, deviceName)
        else:  # 1000개 이상이면 마지막 1000개만 학습
            Qlearning_deep_GPU.deepQlearning(
                option, NN, op, 'mean_squared_error',
                states[len(states) - 1000:], outputs[len(states) - 1000:],
                Qdiffs[len(states) - 1000:], 25, 'valueMaze', [20, 25],
                [8, 'sigmoid', 'sigmoid'], [6, 'sigmoid', 'sigmoid'], False,
                False, True, deviceName)
        isFile = True

        if option % 3 == 0 or option % 3 == 1:
            model0 = Qlearning_deep_GPU.deepLearningModel('valueMaze_0', False)
        if option % 3 == 1 or option % 3 == 2:
            model1 = Qlearning_deep_GPU.deepLearningModel('valueMaze_1', False)

        print('\n\n << 점수 목록 >>')
        print(scores)
        print('')
Exemplo n.º 5
0
                               keras.layers.Dropout(drop),
                               keras.layers.Dense(40, activation='elu'),
                               keras.layers.Dense(2, activation='sigmoid')]

                        # 5. 옵티마이저
                        op0 = tf.keras.optimizers.Adam(0.001)
                        op1 = tf.keras.optimizers.Adam(0.001)
                        op2 = tf.keras.optimizers.Adam(0.001)
                        
                        print('training...')
                        Qlearning_deep_GPU.deepQlearning(0, NN2, op0, lc, inputs, outputs, None, None, 'WPCNdeepNN2', [epoc, None], None, None, False, False, True, deviceName)
                        Qlearning_deep_GPU.deepQlearning(0, NN1, op1, lc, inputs, outputs, None, None, 'WPCNdeepNN1', [epoc, None], None, None, False, False, True, deviceName)
                        Qlearning_deep_GPU.deepQlearning(0, NN0, op2, lc, inputs, outputs, None, None, 'WPCNdeepNN0', [epoc, None], None, None, False, False, True, deviceName)

                        # 6. 테스트 결과 확인하고 정답과 비교하기
                        newModel0 = Qlearning_deep_GPU.deepLearningModel('WPCNdeepNN0_0', False)
                        newModel1 = Qlearning_deep_GPU.deepLearningModel('WPCNdeepNN1_0', False)
                        newModel2 = Qlearning_deep_GPU.deepLearningModel('WPCNdeepNN2_0', False)
                        
                        sumTestThroughput = 0.0 # test throughput의 합계
                        sumCorrectMaxThroughput = 0.0 # 정답의 throughput의 합계 (training data를 생성할 때와 같은 방법으로 최대 throughput 확인)

                        optiInfo = open('optiInfo_' + str(problemNo) + '.txt', 'r')
                        optiInformation = optiInfo.readlines()
                        optiInfo.close()

                        print('testing...')
                        
                        for i in range(numTest):
                            testScreen = originalScreen[numTrain + i] # 테스트할 스크린
                            
Exemplo n.º 6
0
            ## 1-4. lastScreen, lastDecision, lastPoint 갱신 ##
            for j in range(size):
                for k in range(size):
                    lastScreen[j][k] = screen[j][k]
            lastDecision = decision
            lastPoint = [point[0], point[1]]

        ### 2. 게임 종료 후 딥러닝 실행 ###
        if len(states) < 1000:  # 1000개 미만이면 모두 학습
            Qlearning_deep_GPU.deepQlearning(
                option, NN, op, 'mean_squared_error', states, outputs, Qdiffs,
                25, 'snake', [20, 25], [8, 'sigmoid', 'sigmoid'],
                [6, 'sigmoid', 'sigmoid'], False, False, True, deviceName)
        else:  # 1000개 이상이면 마지막 1000개만 학습
            Qlearning_deep_GPU.deepQlearning(
                option, NN, op, 'mean_squared_error',
                states[len(states) - 1000:], outputs[len(states) - 1000:],
                Qdiffs[len(states) - 1000:], 25, 'valueMaze', [20, 25],
                [8, 'sigmoid', 'sigmoid'], [6, 'sigmoid', 'sigmoid'], False,
                False, True, deviceName)
        isFile = True

        if option % 3 == 0 or option % 3 == 1:
            model0 = Qlearning_deep_GPU.deepLearningModel('snake_0', False)
        if option % 3 == 1 or option % 3 == 2:
            model1 = Qlearning_deep_GPU.deepLearningModel('snake_1', False)

        print('\n\n << 점수 목록 >>')
        print(scores)
        print('')
        print('\n ' + ('#===' * 16) + ' <<<< option:' + str(i) +
              ' LEARNING >>>> ' + ('===#' * 16) + '\n')
        Qlearning_deep_GPU.deepQlearning(i, NN, op, 'mean_squared_error',
                                         states, outputs, Qdiff, 25,
                                         'test' + str(i), [20, 25],
                                         [8, 'sigmoid', 'sigmoid'],
                                         [6, 'sigmoid', 'sigmoid'], True, True,
                                         False, deviceName)

        # test
        print('\n ' + ('#===' * 16) + ' <<<< option:' + str(i) +
              ' TEST >>>> ' + ('===#' * 16) + '\n')

        if i % 3 == 0 or i % 3 == 1:
            print('\n << test output (첫번째 Neural Network) >>\n')
            newModel = Qlearning_deep_GPU.deepLearningModel(
                'test' + str(i) + '_0', False)
            testOutput = Qlearning_deep_GPU.modelOutput(
                newModel, [[4, 2.5], [6, 3.5], [7, 4.5]])
            print('\n[[4, 2.5], [6, 3.5], [7, 4.5]]에 대한 학습 결과:\n')

            for j in range(len(testOutput)):
                print(' << layer No: ' + str(j) + ' >>')
                print(str(testOutput[j]))

        if i % 3 == 1 or i % 3 == 2:
            print('\n << test output (두번째(또는 Dueling) Neural Network) >>\n')
            newModel = Qlearning_deep_GPU.deepLearningModel(
                'test' + str(i) + '_1', False)
            testOutput = Qlearning_deep_GPU.modelOutput(
                newModel, [[4, 2.5], [6, 3.5], [7, 4.5]])
            print('\n[[4, 2.5], [6, 3.5], [7, 4.5]]에 대한 학습 결과:\n')