Exemplo n.º 1
0
def exo8():
    print("\n\n>>EXERCICE 8 MNIST")
    Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMNISTfile()
    default_h = 30
    maxIter = 1
    neuralNetwork = NeuralNetwork(len(Xtrain[0]),
                                  default_h,
                                  utils.getClassCount(ytrain),
                                  K=100)
    neuralNetworkEfficient = NeuralNetworkEfficient(
        len(Xtrain[0]), default_h, utils.getClassCount(ytrain), K=100)
    neuralNetworkEfficient._w1 = neuralNetwork._w1
    neuralNetworkEfficient._w2 = neuralNetwork._w2
    print("--- Reseau de depart ---")
    t1 = datetime.now()
    neuralNetwork.train(Xtrain, ytrain, maxIter)
    t2 = datetime.now()
    delta = t2 - t1
    print("Cela a mis : " + str(delta.total_seconds()) + " secondes")
    print("--- Reseau optimise ---")
    t1 = datetime.now()
    neuralNetworkEfficient.train(Xtrain, ytrain, maxIter)
    t2 = datetime.now()
    delta = t2 - t1
    print("Cela a mis : " + str(delta.total_seconds()) + " secondes")
Exemplo n.º 2
0
def exo9_10():
    print("\n\n>>EXERCICE 9-10")
    print("Train Err;Valid Err;Test Err;Avg Cost Train;Avg Cost Valid;Avg Cost Test")

    h = 300
    wd = 0.0001
    maxIter = 500
    K = 50

    Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMNISTfile()
    neuralNetwork = NeuralNetworkEfficient(len(Xtrain[0]), h, utils.getClassCount(ytrain), K, wd)
    neuralNetwork.setDataSets(Xtrain, Xvalid, Xtest, ytrain, yvalid, ytest)
    neuralNetwork.train(Xtrain, ytrain, maxIter)

    epochsData = ""
    for d in neuralNetwork.epochData:
        epochsData += d+"\n"

    f = open('no9.txt', 'w')
    f.write(epochsData)
    f.close()

    x = range(1, maxIter+1, 10)
    title = "Taux d'erreur - "+str(maxIter)+" epoques"
    name = str(h) + "_" + str(wd)+ "_" + str(h)+ "_" + "taux_erreur"
    utils.plotCourbeApprentissage(neuralNetwork.trainError, neuralNetwork.validError, neuralNetwork.testError, x, title, name)

    title = "Cout moyen - "+str(maxIter)+" epoques"
    name = str(h) + "_" + str(wd)+ "_" + str(h)+ "_" +"cout_moyen"
    utils.plotCourbeApprentissage(neuralNetwork.trainSumL, neuralNetwork.validSumL, neuralNetwork.testSumL, x, title, name)
Exemplo n.º 3
0
def exo8():
    print("\n\n>>EXERCICE 8 MNIST")
    Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMNISTfile()
    default_h = 30
    maxIter = 1
    neuralNetwork = NeuralNetwork(len(Xtrain[0]), default_h, utils.getClassCount(ytrain),K=100)
    neuralNetworkEfficient = NeuralNetworkEfficient(len(Xtrain[0]), default_h, utils.getClassCount(ytrain),K=100)
    neuralNetworkEfficient._w1 = neuralNetwork._w1
    neuralNetworkEfficient._w2 = neuralNetwork._w2
    print("--- Reseau de depart ---")
    t1 = datetime.now()
    neuralNetwork.train(Xtrain, ytrain, maxIter)
    t2 = datetime.now()
    delta = t2 - t1
    print("Cela a mis : " + str(delta.total_seconds()) + " secondes")
    print("--- Reseau optimise ---")
    t1 = datetime.now()
    neuralNetworkEfficient.train(Xtrain, ytrain, maxIter)
    t2 = datetime.now()
    delta = t2 - t1
    print("Cela a mis : " + str(delta.total_seconds()) + " secondes")
Exemplo n.º 4
0
def exo9_10():
    print("\n\n>>EXERCICE 9-10")
    print(
        "Train Err;Valid Err;Test Err;Avg Cost Train;Avg Cost Valid;Avg Cost Test"
    )

    h = 300
    wd = 0.0001
    maxIter = 500
    K = 50

    Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMNISTfile()
    neuralNetwork = NeuralNetworkEfficient(len(Xtrain[0]), h,
                                           utils.getClassCount(ytrain), K, wd)
    neuralNetwork.setDataSets(Xtrain, Xvalid, Xtest, ytrain, yvalid, ytest)
    neuralNetwork.train(Xtrain, ytrain, maxIter)

    epochsData = ""
    for d in neuralNetwork.epochData:
        epochsData += d + "\n"

    f = open('no9.txt', 'w')
    f.write(epochsData)
    f.close()

    x = range(1, maxIter + 1, 10)
    title = "Taux d'erreur - " + str(maxIter) + " epoques"
    name = str(h) + "_" + str(wd) + "_" + str(h) + "_" + "taux_erreur"
    utils.plotCourbeApprentissage(neuralNetwork.trainError,
                                  neuralNetwork.validError,
                                  neuralNetwork.testError, x, title, name)

    title = "Cout moyen - " + str(maxIter) + " epoques"
    name = str(h) + "_" + str(wd) + "_" + str(h) + "_" + "cout_moyen"
    utils.plotCourbeApprentissage(neuralNetwork.trainSumL,
                                  neuralNetwork.validSumL,
                                  neuralNetwork.testSumL, x, title, name)