Ejemplo n.º 1
0
def getModelScore(model, trainIterations, trainMaxTime, testsMaxTime,
                  **modelParams):
    """
    @param model
    @param trainIterations: Number of iterations the model is
        going to be trained.
    @param trainMaxTime: Training stops if maxTime (in minutes) is
        exceeded. Note that this may interrupt an ongoing train
        ireration. -1 is no time restrictions.
    @param testsMaxTime: If maxTime (in minutes) is exceeded, the tests
        will end. Note that this won't interrupt an ongoing test.
        The TestSuite will wait until the sequence is passed to
        the model and the corresponding result is processed.
    @param modelParams
    """

    paramsByModule = organizeParamsByModule(modelParams)
    tempModel = copy.deepcopy(model)
    tempModel.iterationsTrained = 0

    for moduleName in paramsByModule:
        tempModel.modules[moduleName] = tempModel.modules[
            moduleName].__class__(**paramsByModule[moduleName])

    print('\n-----------------------------\n')

    print(tempModel.spParametersStr())
    print(tempModel.tmParametersStr())

    print('Training...')

    tempModel.train(trainIterations, maxTime=trainMaxTime, verbosity=0)
    results = TestSuite.testModel(tempModel,
                                  testSet.trainingData,
                                  maxTime=testsMaxTime,
                                  saveResults=False)

    print("Success: {}%".format(results['successPercent']))

    return results['successPercent']
Ejemplo n.º 2
0
def getModelScore(model, trainIterations, trainMaxTime, testsMaxTime,
        **modelParams):
    """
    @param model
    @param trainIterations: Number of iterations the model is
        going to be trained.
    @param trainMaxTime: Training stops if maxTime (in minutes) is
        exceeded. Note that this may interrupt an ongoing train
        ireration. -1 is no time restrictions.
    @param testsMaxTime: If maxTime (in minutes) is exceeded, the tests
        will end. Note that this won't interrupt an ongoing test.
        The TestSuite will wait until the sequence is passed to
        the model and the corresponding result is processed.
    @param modelParams
    """

    paramsByModule = organizeParamsByModule(modelParams)
    tempModel = copy.deepcopy(model)
    tempModel.iterationsTrained = 0

    for moduleName in paramsByModule:
        tempModel.modules[moduleName] = tempModel.modules[moduleName].__class__(
            **paramsByModule[moduleName])

    print('\n-----------------------------\n')

    print(tempModel.spParametersStr())
    print(tempModel.tmParametersStr())

    print('Training...')

    tempModel.train(trainIterations, maxTime=trainMaxTime, verbosity=0)
    results = TestSuite.testModel(tempModel, testSet.trainingData,
        maxTime=testsMaxTime, saveResults=False)

    print("Success: {}%".format(results['successPercent']))

    return results['successPercent']
Ejemplo n.º 3
0
            encoderName = wordEncoder.__class__.__name__

            model = CurrentModel(wordEncoder, actionEncoder, trainingSet,
                BestResults.bestFindings[0])
            modelName = model.__class__.__name__

            print(modelName)
            print(encoderName)
            model.train(30, maxTime=-1, verbosity=1)

            fileName = 'Results/'
            # Strips the 'Model' fron the name
            fileName += modelName[:-5] + setsName + '-'
            # Appends only the Capital letters
            fileName += ''.join(cap for cap in encoderName if cap.isupper())
            #fileName += 'OneRegionExp32'

            TestSuite.testModel(model, testSet.trainingData,
                fileName=(fileName + '_Results'))

            #print("Saving the model...")
            #with open((fileName + '.pck'), 'wb') as modelFile:
            #    cPickle.dump(model, modelFile, -1)
            #print("Done!")

            #app = QApplication([])
            #window = MainWindow(model)
            #app.exec_()
            #sys.exit(app.exec_())
Ejemplo n.º 4
0
    model = CurrentModel(wordEncoder, actionEncoder, trainingSet,
                         BestParameters.bestFindings[0])
    modelName = model.__class__.__name__

    print(modelName)
    print(encoderName)
    model.train(iterations, maxTime=-1, verbosity=1)

    fileName = 'Results/'
    # Strips the 'Model' fron the name
    fileName += modelName[:-5] + setsName + '-'
    # Appends only the Capital letters
    fileName += ''.join(cap for cap in encoderName if cap.isupper())
    #fileName += 'OneRegionExp32'

    if whether_tests:
        TestSuite.testModel(model,
                            testSet.trainingData,
                            fileName=(fileName + '_Results'))

    if whether_save:
        print("Saving the model...")
        with open((fileName + '.pck'), 'wb') as modelFile:
            cPickle.dump(model, modelFile, -1)
        print("Done!")

    if whether_gui:
        app = QApplication([])
        window = MainWindow(model)
        sys.exit(app.exec_())