Exemplo n.º 1
0
def exo67():
    print("\n\n>>EXERCICE 6 et 7 : Calcul matriciel")
    print(" --- K=1 ---")
    #Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMoonFile()
    Xtrain = [[30, 20, 40, 50], [25, 15, 35, 45]]
    ytrain = [0,0]
    default_h = 2
    nn = NeuralNetwork(len(Xtrain[0]), default_h, utils.getClassCount(ytrain), K=1, wd=0)
    nne = NeuralNetworkEfficient(len(Xtrain[0]), default_h, utils.getClassCount(ytrain), K=1, wd=0)
    nne._w1 = nn._w1 # trick pour que l'aleatoire soit egale
    nne._w2 = nn._w2
    nn.train(Xtrain,ytrain,1)
    nne.train(Xtrain,ytrain,1)
    utils.compareNN(nn,nne)
    print(" --- K=10 ---")
    Xtrain = [[30, 20, 40, 50], [25, 15, 35, 45],[30, 76, 45, 44],[89, 27, 42, 52],[30, 24, 44, 53],[89, 25, 45, 50],[30, 20, 40, 50],[30, 65, 47, 50],[30, 34, 40, 50],[39, 20, 29, 58]]
    ytrain = [0,0,0,0,0,0,0,0,0,0]
    default_h = 2
    nn = NeuralNetwork(len(Xtrain[0]), default_h, utils.getClassCount(ytrain), K=10, wd=0)
    nne = NeuralNetworkEfficient(len(Xtrain[0]), default_h, utils.getClassCount(ytrain), K=10, wd=0)
    nne._w1 = nn._w1 # trick pour que l'aleatoire soit egale
    nne._w2 = nn._w2
    nn.train(Xtrain,ytrain,1)
    nne.train(Xtrain,ytrain,1)
    utils.compareNN(nn,nne,10)
Exemplo n.º 2
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.º 3
0
def exo67():
    print("\n\n>>EXERCICE 6 et 7 : Calcul matriciel")
    print(" --- K=1 ---")
    #Xtrain, ytrain, Xvalid, yvalid, Xtest, ytest = utils.readMoonFile()
    Xtrain = [[30, 20, 40, 50], [25, 15, 35, 45]]
    ytrain = [0, 0]
    default_h = 2
    nn = NeuralNetwork(len(Xtrain[0]),
                       default_h,
                       utils.getClassCount(ytrain),
                       K=1,
                       wd=0)
    nne = NeuralNetworkEfficient(len(Xtrain[0]),
                                 default_h,
                                 utils.getClassCount(ytrain),
                                 K=1,
                                 wd=0)
    nne._w1 = nn._w1  # trick pour que l'aleatoire soit egale
    nne._w2 = nn._w2
    nn.train(Xtrain, ytrain, 1)
    nne.train(Xtrain, ytrain, 1)
    utils.compareNN(nn, nne)
    print(" --- K=10 ---")
    Xtrain = [[30, 20, 40, 50], [25, 15, 35, 45], [30, 76, 45, 44],
              [89, 27, 42, 52], [30, 24, 44, 53], [89, 25, 45, 50],
              [30, 20, 40, 50], [30, 65, 47, 50], [30, 34, 40, 50],
              [39, 20, 29, 58]]
    ytrain = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
    default_h = 2
    nn = NeuralNetwork(len(Xtrain[0]),
                       default_h,
                       utils.getClassCount(ytrain),
                       K=10,
                       wd=0)
    nne = NeuralNetworkEfficient(len(Xtrain[0]),
                                 default_h,
                                 utils.getClassCount(ytrain),
                                 K=10,
                                 wd=0)
    nne._w1 = nn._w1  # trick pour que l'aleatoire soit egale
    nne._w2 = nn._w2
    nn.train(Xtrain, ytrain, 1)
    nne.train(Xtrain, ytrain, 1)
    utils.compareNN(nn, nne, 10)
Exemplo n.º 4
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")