- Joined
- Mar 31, 2023
- Messages
- 95
- Reaction score
- 8
Hello everyone! I've recently started working on a code, and I've encountered a typical and rather simple error that I'm unable to resolve.
I would appreciate help as soon as possible.
Apologies, the terms are in French.
Here is the error I'm encountering.
Here the code:
Thank you for any possible response.
I would appreciate help as soon as possible.
Apologies, the terms are in French.
Here is the error I'm encountering.
Code:
Traceback (most recent call last):
File ~\Nouveau dossier\pkgs\spyder_kernels\py3compat.py:356 in compat_exec
exec(code, globals, locals)
File c:\users\-----\documents\spyder\----------\---------\-------\untitled1.py:118
neurone(x1[i], x2[i], x3[i], x4[i], x5[i], x6[i], x7[i], x8[i], weights_, biases_)
File c:\users\-----\documents\spyder\----------\---------\-------\untitled1.py:38 in neurone
f[j] = sum(entrée[k][0] * weights_[0][j + k * nombre_neurone] for k in range(len(entrée))) + biases_[0][j]
File c:\users\-----\documents\spyder\----------\---------\-------\untitled1.py:38 in <genexpr>
f[j] = sum(entrée[k][0] * weights_[0][j + k * nombre_neurone] for k in range(len(entrée))) + biases_[0][j]
IndexError: list index out of range
Python:
import random
x1,x2,x3,x4,x5,x6,x7,x8 = [1],[1],[1],[1],[1],[1],[1],[1] # Random data
yt = [[1,0,0]] # Random output
nombre_neurone = 13
nombre_sortie = 3
weights_ = []
biases_ = []
entrée = [x1, x2, x3, x4, x5, x6, x7, x8]
nombreW = (len(entrée) * nombre_neurone) + (nombre_neurone * nombre_sortie) # Nombre de sorties
nombreB = nombre_neurone + nombre_sortie
def neurone(x1_, x2_, x3_, x4_, x5_, x6_, x7_, x8_, weights_, biases_):
f = [0.0] * nombre_neurone
y = [0] * nombre_neurone
f2 = [0.0] * nombre_sortie
y2 = [0] * nombre_sortie
# Calculer les valeurs de f
for j in range(nombre_neurone):
f[j] = sum(entrée[k][0] * weights_[0][j + k * nombre_neurone] for k in range(len(entrée))) + biases_[0][j]
for j in range(nombre_sortie):
for k in range(nombre_neurone):
f2[j] += weights_[1][j][k] * f[k]
f2[j] += biases_[1][j]
for j in range(nombre_neurone):
y[j] = 1 if f[j] > 0 else 0
for j in range(nombre_sortie):
y2[j] = 1 if f2[j] > 0 else 0
print(y2)
def DDG(inputs, yt):
learning_rate = 0.001
numIterations = 5000
global weights
global weights1
global biases
global biases1
numDataPoints = len(yt)
for iteration in range(numIterations):
for i in range(numDataPoints):
f = [0.0] * nombre_neurone
y = [0] * nombre_neurone
f2 = [0.0] * nombre_sortie
y2 = [0] * nombre_sortie
# Calculer les valeurs de f
for j in range(nombre_neurone):
f[j] = sum(inputs[k][i] * weights[j * len(inputs) + k] for k in range(len(inputs))) + biases[j]
for j in range(nombre_sortie):
for k in range(nombre_neurone):
f2[j] += weights1[j][k] * f[k]
f2[j] += biases1[j]
for j in range(nombre_neurone):
y[j] = 1 if f[j] > 0 else 0
for j in range(nombre_sortie):
y2[j] = 1 if f2[j] > 0 else 0
for j in range(nombre_sortie):
erreur = y2[j] - yt[i][j]
for k in range(nombre_neurone):
for L in range(len(yt)):
for Q in range(len(inputs)):
weights1[j][k] += learning_rate * ((1 / numDataPoints) * erreur * inputs[Q][L])
biases1[j] += learning_rate * ((1 / numDataPoints) * erreur)
weights_ = [weights, weights1]
biases_ = [biases, biases1]
# Initialiser les poids et les biais avec des valeurs aléatoires
biases = [0.0] * nombreB
weights = [0.0] * nombreW
biases1 = [0.0] * nombre_sortie
weights1 = [[0.0] * nombre_neurone for _ in range(nombre_sortie)]
for i in range(nombreW):
weights[i] = random.uniform(-2.0, 2.0)
for i in range(nombreB):
biases[i] = random.uniform(-2.0, 2.0)
for i in range(nombre_neurone):
for j in range(nombre_sortie):
weights1[j][i] = random.uniform(-2.0, 2.0)
for i in range(nombre_sortie):
biases1[i] = random.uniform(-2.0, 2.0)
DDG(entrée, yt)
for i in range(len(yt)):
neurone(x1[i], x2[i], x3[i], x4[i], x5[i], x6[i], x7[i], x8[i], weights_, biases_)
Thank you for any possible response.