correction algo et developpement demo2

demo/2
ludovic.castglia 4 months ago
parent a1473cbcd1
commit 4e31bfd5d5

@ -12,11 +12,10 @@ def getRandomParam():
def applyFunction(x,param):
return pow(x*param[0],2) + x*param[1] + param[2]
param = getRandomParam()
nbPoints = 100
minx = 0
maxx = 10
maxx = 1000
x = []
y = []
@ -26,13 +25,21 @@ for i in [minx + (maxx-minx)*i/nbPoints for i in range(nbPoints)]:
knn.addPoint(np.array([i]),np.array([y[-1]]))
nnnar.addPoint(np.array([i]),np.array([y[-1]]))
error = 0
nbInfer = 20
for i in range(nbInfer):
xt = random()*10
xt = random()*maxx
yt = nnnar.getValueOfPoint(np.array([xt]),2)
yr = applyFunction(xt,param)
error += abs(yt[0]-yr)
ytk = knn.getValueOfPoint(np.array([xt]),2)
plt.plot(xt,yt[0],'xr')
plt.plot(xt,ytk[0],'xg')
print("Error: ",(error/nbInfer)/applyFunction(maxx,param))
plt.plot(x,y)
plt.title("f(x) = "+str(param[0])+"*x^2 + "+str(param[1])+"*x + "+str(param[2]))
plt.xlabel("X")
plt.ylabel("Y")
plt.show()

@ -56,7 +56,7 @@ class Nnnar:
i+=1
maxDistIdx = foundMaxIndex(dist)
maxDist = max(dist)
for i in range(nbNearest, len(selected)):
while i != len(selected):
if (selected[i].getDistFromCoord(coord) < maxDist):
found.pop(maxDistIdx)
dist.pop(maxDistIdx)
@ -64,6 +64,7 @@ class Nnnar:
dist.append(selected[i].getDistFromCoord(coord))
maxDistIdx = foundMaxIndex(dist)
maxDist = max(dist)
i+=1
return found, dist
def getSpaceIdxFromCoord(self,coord):

@ -1,5 +1,6 @@
import numpy as np
from sympy.utilities.iterables import multiset_permutations
import copy
def findCoordAround(center, nbAround):
nbDimention = len(center)
@ -69,14 +70,15 @@ def getPermutationOfCoord(center, find, coord):
def applySapceAroundToCase(center,spaceAround,space):
reelSpaceAround = []
spaceAroundCopy = copy.deepcopy(spaceAround)
for y in range(len(spaceAround)):
estBon = True
for i in range(len(spaceAround[y])):
for i in range(len(spaceAroundCopy[y])):
if not estBon:
continue
else :
spaceAround[y][i] += center[i]
estBon = estBon and 0 <= spaceAround[y][i] <= space.nbSubdivisions-1
spaceAroundCopy[y][i] += center[i]
estBon = estBon and 0 <= spaceAroundCopy[y][i] <= space.nbSubdivisions-1
if estBon:
reelSpaceAround.append(spaceAround[y])
reelSpaceAround.append(spaceAroundCopy[y])
return reelSpaceAround
Loading…
Cancel
Save