parent
12a24eb086
commit
f9e642987f
@ -0,0 +1,85 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
parent_dir_name = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
sys.path.append(parent_dir_name + "/3nar/code")
|
||||||
|
|
||||||
|
from nnnar import *
|
||||||
|
from knn import *
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
|
# initialisation du modèle
|
||||||
|
comp = False
|
||||||
|
if (sys.argv[1] == "comp"):
|
||||||
|
model1 = Knn()
|
||||||
|
model2 = Nnnar(1, 0, 1, 50)
|
||||||
|
comp = True
|
||||||
|
if (sys.argv[1] == "knn"):
|
||||||
|
model = Knn()
|
||||||
|
else:
|
||||||
|
model = Nnnar(1, 0, 1, 50)
|
||||||
|
|
||||||
|
maxVal = 20_000
|
||||||
|
nbTest = 100
|
||||||
|
nbPts = 10
|
||||||
|
|
||||||
|
# Création des données d'entrainement
|
||||||
|
train = []
|
||||||
|
test = []
|
||||||
|
for i in range(maxVal):
|
||||||
|
x = np.random.rand()
|
||||||
|
y = np.random.rand()
|
||||||
|
train.append([x,y])
|
||||||
|
for i in range(nbTest):
|
||||||
|
x = np.random.rand()
|
||||||
|
test.append(x)
|
||||||
|
train = np.array(train)
|
||||||
|
test = np.array(test)
|
||||||
|
|
||||||
|
def testModel(model, train ,test):
|
||||||
|
model.reset()
|
||||||
|
t = time()
|
||||||
|
# Entrainement du modèle
|
||||||
|
for i in range(len(train)):
|
||||||
|
model.addPoint(np.array([train[i,0]]), np.array([train[i,1]]))
|
||||||
|
# Test du modèles
|
||||||
|
for i in range(len(test)):
|
||||||
|
model.getValueOfPoint(np.array([test[i]]), 5)[0]
|
||||||
|
return time() - t
|
||||||
|
|
||||||
|
if comp:
|
||||||
|
res1 = []
|
||||||
|
res2 = []
|
||||||
|
idxs = []
|
||||||
|
for i in range(1,nbPts):
|
||||||
|
idx = round((i*maxVal)/nbPts)
|
||||||
|
print(idx)
|
||||||
|
idxs.append(idx)
|
||||||
|
res1.append(testModel(model1, train[:idx], test))
|
||||||
|
res2.append(testModel(model2, train[:idx], test))
|
||||||
|
|
||||||
|
plt.xlabel('Number of training points')
|
||||||
|
plt.ylabel('Time (s)')
|
||||||
|
plt.xticks(range(len(idxs)), idxs)
|
||||||
|
|
||||||
|
plt.plot(res1,label='KNN')
|
||||||
|
plt.plot(res2,label='3NAR')
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
||||||
|
else:
|
||||||
|
res = []
|
||||||
|
idxs = []
|
||||||
|
for i in range(1,nbPts):
|
||||||
|
idx = round((i*maxVal)/nbPts)
|
||||||
|
print(idx)
|
||||||
|
idxs.append(idx)
|
||||||
|
res.append(testModel(model, train[:round((i*maxVal)/nbPts)], test))
|
||||||
|
|
||||||
|
plt.xlabel('Number of training points')
|
||||||
|
plt.ylabel('Time (s)')
|
||||||
|
plt.xticks(range(len(idxs)), idxs)
|
||||||
|
plt.plot(res)
|
||||||
|
plt.show()
|
@ -0,0 +1,71 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
parent_dir_name = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
sys.path.append(parent_dir_name + "/3nar/code")
|
||||||
|
|
||||||
|
from nnnar import *
|
||||||
|
from knn import *
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
|
# initialisation du modèle
|
||||||
|
comp = False
|
||||||
|
if (sys.argv[1] == "comp"):
|
||||||
|
model1 = Knn()
|
||||||
|
model2 = Nnnar(1, 0, 1, 100)
|
||||||
|
comp = True
|
||||||
|
if (sys.argv[1] == "knn"):
|
||||||
|
model = Knn()
|
||||||
|
else:
|
||||||
|
model = Nnnar(1, 0, 1, 100)
|
||||||
|
|
||||||
|
maxVal = 1_000
|
||||||
|
nbTest = 1_000
|
||||||
|
nbPts = 10
|
||||||
|
|
||||||
|
# Création des données d'entrainement
|
||||||
|
train = []
|
||||||
|
test = []
|
||||||
|
for i in range(maxVal):
|
||||||
|
x = np.random.rand()
|
||||||
|
y = np.random.rand()
|
||||||
|
train.append([x,y])
|
||||||
|
for i in range(nbTest):
|
||||||
|
x = np.random.rand()
|
||||||
|
test.append(x)
|
||||||
|
train = np.array(train)
|
||||||
|
test = np.array(test)
|
||||||
|
|
||||||
|
def testModel(model, train ,test):
|
||||||
|
model.reset()
|
||||||
|
t = time()
|
||||||
|
# Entrainement du modèle
|
||||||
|
for i in range(len(train)):
|
||||||
|
model.addPoint(np.array([train[i,0]]), np.array([train[i,1]]))
|
||||||
|
# Test du modèles
|
||||||
|
for i in range(len(test)):
|
||||||
|
model.getValueOfPoint(np.array([test[i]]), 5)[0]
|
||||||
|
return time() - t
|
||||||
|
|
||||||
|
if comp:
|
||||||
|
res1 = []
|
||||||
|
res2 = []
|
||||||
|
idxs = []
|
||||||
|
for i in range(1,nbPts):
|
||||||
|
idx = round((i*nbTest)/nbPts)
|
||||||
|
print(idx)
|
||||||
|
idxs.append(idx)
|
||||||
|
res1.append(testModel(model1, train, test[:idx]))
|
||||||
|
res2.append(testModel(model2, train, test[:idx]))
|
||||||
|
|
||||||
|
plt.xlabel('Number of points infered')
|
||||||
|
plt.ylabel('Time (s)')
|
||||||
|
plt.xticks(range(len(idxs)), idxs)
|
||||||
|
|
||||||
|
plt.plot(res1,label='KNN')
|
||||||
|
plt.plot(res2,label='3NAR')
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
@ -0,0 +1,61 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
parent_dir_name = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
|
||||||
|
sys.path.append(parent_dir_name + "/3nar/code")
|
||||||
|
|
||||||
|
from nnnar import *
|
||||||
|
|
||||||
|
import matplotlib.pyplot as plt
|
||||||
|
import numpy as np
|
||||||
|
from time import time
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
maxVal = 1_000
|
||||||
|
nbTest = 1000
|
||||||
|
nbPts = 10
|
||||||
|
nbModel = 10
|
||||||
|
nbMaxSubDiv = 100
|
||||||
|
|
||||||
|
# Création des données d'entrainement
|
||||||
|
train = []
|
||||||
|
test = []
|
||||||
|
for i in range(maxVal):
|
||||||
|
x = np.random.rand()
|
||||||
|
y = np.random.rand()
|
||||||
|
train.append([x,y])
|
||||||
|
for i in range(nbTest):
|
||||||
|
x = np.random.rand()
|
||||||
|
test.append(x)
|
||||||
|
train = np.array(train)
|
||||||
|
test = np.array(test)
|
||||||
|
|
||||||
|
def testModel(model, train ,test):
|
||||||
|
model.reset()
|
||||||
|
t = time()
|
||||||
|
# Entrainement du modèle
|
||||||
|
for i in range(len(train)):
|
||||||
|
model.addPoint(np.array([train[i,0]]), np.array([train[i,1]]))
|
||||||
|
# Test du modèles
|
||||||
|
for i in range(len(test)):
|
||||||
|
model.getValueOfPoint(np.array([test[i]]), 5)[0]
|
||||||
|
return time() - t
|
||||||
|
|
||||||
|
|
||||||
|
for i in range(1,nbModel):
|
||||||
|
nbSub = round(i*nbMaxSubDiv/nbModel)
|
||||||
|
print(nbSub)
|
||||||
|
model = Nnnar(1,0,1,nbSub)
|
||||||
|
res = []
|
||||||
|
idxs = []
|
||||||
|
for i in range(1,nbPts):
|
||||||
|
idx = round((i*nbTest)/nbPts)
|
||||||
|
idxs.append(idx)
|
||||||
|
res.append(testModel(model, train, test[:idx]))
|
||||||
|
plt.plot(res,label='NNNAR('+str(nbSub)+')')
|
||||||
|
|
||||||
|
plt.xlabel('Number of points infered')
|
||||||
|
plt.ylabel('Time (s)')
|
||||||
|
plt.xticks(range(len(idxs)), idxs)
|
||||||
|
plt.legend()
|
||||||
|
plt.show()
|
After Width: | Height: | Size: 98 KiB |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 38 KiB |
Loading…
Reference in new issue