else: # 학습 영역의 크기가 6 미만
                            NN = [tf.keras.layers.Flatten(input_shape=(size*size,)),
                                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.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]) # 테스트 결과
示例#2
0
                               keras.layers.Conv2D(32, kernel_size=(3, 3), input_shape=(size, size, 1), activation='elu'),
                               keras.layers.MaxPooling2D(pool_size=2),
                               keras.layers.Dropout(drop),
                               keras.layers.Conv2D(32, (3, 3), activation='elu'),
                               keras.layers.Flatten(),
                               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()
示例#3
0
                charValue=50,
                randomProb_=randomProb,
                feasible_=feasible,
                getNextState_=None)

            ## 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)
    ]
    op = tf.keras.optimizers.Adam(0.001)
    Qdiff = [1, 2, 3, 4, 5, 6, 7]

    # apply each option
    for i in range(6):
        states = [[2, 1], [3, 2], [5, 3], [8, 5], [13, 8], [21, 13], [34, 21]]
        outputs = [[0.2, 0.5], [0.4, 0.6], [0.5, 0.7], [0.7, 0.75],
                   [0.8, 0.77], [0.85, 0.8], [0.9, 0.85]]

        # learning
        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')