Esempio n. 1
0
def DisplayResults(aramgame):
    aramgame = json.loads(aramgame)
    teammates, opponents, gameWin = DatabaseActions.GetResults(aramgame)
    if gameWin == False:
        print "---------------------\nTEAM ONE\n---------------------"
    else:
        print "---------------------\nTEAM ONE -- WINNERS\n---------------------"
    for champion in teammates:
        print championdictionary[str(champion)]["championName"]
    if gameWin == False:
        print "---------------------\nTEAM TWO -- WINNERS\n---------------------"
    else:
        print "---------------------\nTEAM TWO\n---------------------"
    for champion in opponents:
        print championdictionary[str(champion)]["championName"]
    print "\n\n\n"
Esempio n. 2
0
def PredictGame(wizard, aramgame):
    aramgame = json.loads(aramgame)
    teammates, opponents, gameWin = DatabaseActions.GetResults(aramgame)

    #writes a vector of which champions were on which team followed by the result
    gamevector = [0] * len(championdictionary)
    for champion in teammates:
        gamevector[championdictionary[str(champion)]["Id"] - 1] = 1
    for champion in opponents:
        gamevector[championdictionary[str(champion)]["Id"] - 1] = -1

    prediction = wizard.activate(gamevector)[0]

    #Check to see if we were correct
    correct = (True if int(round(prediction)) == gameWin else False)

    #For data sorting we will describe all our certainties as affirmative cases (over 50%)
    if prediction < 0.5:
        prediction = 1 - prediction

    return prediction, correct
predictionNet.addConnection(in_to_hidden)
predictionNet.addConnection(hidden_to_out)
predictionNet.addConnection(FullConnection(predictionNet['bias'],hiddenLayer))
predictionNet.addConnection(FullConnection(predictionNet['bias'],outLayer))
predictionNet.sortModules()


trainingSet = SupervisedDataSet(len(championdictionary),1)

#Takes each game and turns it into a vector. -1 is stored if the champion is on the opposing team, 1 if the champion is on the player's team
#and 0 if it wasn't played. The vector is then fed into the Neural Network's Training Set
print "Adding Games to NN"
for game in aramdata.readlines():
 
    aramgame = json.loads(game)
    teammates,opponents, gameWin = DatabaseActions.GetResults(aramgame)
    
    #writes a vector of which champions were on which team followed by the result
    gamevector = [0]*len(championdictionary)
    for champion in teammates:
        gamevector[championdictionary[str(champion)]["Id"]-1] = 1
    for champion in opponents:
        gamevector[championdictionary[str(champion)]["Id"]-1] = -1
    
    #Feeds that result into our Neural Network's training set
    trainingSet.appendLinked(gamevector,int(gameWin))
    
#Creates a Backpropagation trainer and proceeds to train on our set. This step can take a while due to the volume of our data.
print "Training NN"
trainer = BackpropTrainer(predictionNet,trainingSet)
trainer.trainUntilConvergence(dataset = trainingSet, maxEpochs = 300, verbose = True, continueEpochs = 10, validationProportion=0.1)