j'ouvre un topic (un peu inutile) sur un sujet de programmation que je trouve génial: les réseaux neuronaux artificiels (enfin du moins moi j'appelle ça comme ça et si c'est pas le nom é ben jé m'an fout) .
Bon, je le dit tout de suite, pas question de faire quoi que ce soit d'intelligent avec une calculatrice (ou alors je veux bien voir ), mais on peut faire déjà des chose assez fun avec des neurones artificiels.
Un exemple assez inutile mais fun: le calcul (ici un programme pouvant faire des addition binnaires avec des neurones quaternaires(quatre états possibles, et des neurones d'entrées-sortie):
- Code: Tout sélectionner
function on.resize (ww, hh)
w, h = ww, hh
n = 32
wi = ww/n
display = true
color = {
[0] = 12632256
, [2] = 12632256
, [1] = 0
, [3] = 0
}
mat = {}
for a = 1, n do
mat[a] = neuron (0)
mat[a+n] = neuron (0)
mat[a+n*2] = neuron (1, {a, a+n})
if a > 1 then mat[a+n*2].connect[3] = a+n*2-1 end
mat[a+n*3] = neuron(2, {a+n*2})
end
on.enterKey()
end
neuron = class ()
function neuron: init (t, connect)
self.t = t
if t == 0 then
self.value = math.random (0, 1)
self.connect = {}
end
if t == 1 then
self.value = 0
self.connect = connect
end
if t == 2 then
self.value = 0
self.connect = connect
end
end
function neuron: routine ()
if self.t == 0 then
self.value = math.random (0, 1)
elseif self.t == 1 then
local n = 0
if self.connect[3] then
n = mat[self.connect[3]].value
end
self.value = mat[self.connect[1]].value
+mat[self.connect[2]].value
+math.floor(n/2)
elseif self.t == 2 then
local n = mat[self.connect[1]].value
if math.floor(n/2) ~= n/2 then
self.value = 1
else
self.value = 0
end
end
end
function on.paint (gc)
if display then
for a = 1, 3 do
for b = 1, n do
local i = (a-1)*n+b
gc: setColorRGB (color[mat[i].value])
gc: fillRect ((b-1)*wi, a*32, wi, 16)
end
end
end
end
function on.enterKey ()
for a = 1, #mat do
mat[a]: routine ()
end
platform.window: invalidate ()
end
Notez qu'avec ce programme, on peut traiter de nombres beaucoup plus grands que la limite de capacité de la zone de calcul ( ), et qu'il est plutôt rapide.
Ou encore, un programme encore plus inutile, qui consiste juste en une liste de "neurones" qui se transmettent un signal (bizarrement, cela donne cycliquement les même configuration de neurones actives/inactive):
- Code: Tout sélectionner
function on.resize ()
mat = {}
n = 4240
for a = 1, n do
mat[a] = true
end
for a = 1, n do
mat[a] = neuron ()
end
cd = 3
timer.start (0.01)
end
neuron = class ()
function neuron: init ()
self.connect = {}
self.connect[1] = math.random (#mat)
self.min = math.random (3, 6)
self.on = math.random (5, 9)
self.off = math.random (0, 4)
self.value = self.off
self.cd = false
self.oncd = false
end
function neuron: routine ()
if self.cd then self.cd = self.cd-1 self.value = self.off
if self.cd < 1 then self.cd = false end
else
if not self.oncd then self.value = self.off else self.oncd = false end
for a = 1, #self.connect do
if mat[self.connect[a]].value >= self.min then
self.value = self.on
self.oncd = true
self.cd = cd
break
end
end
end
end
function on.timer ()
platform.window: invalidate ()
end
function on.paint (gc)
gc: setFont ("serif", "b", 6)
local x, y = 0, 0
for a = 1, #mat do
mat[a]: routine()
if mat[a].value == mat[a].on then
gc: setColorRGB (0, 255, 0)
else
gc: setColorRGB (255, 0, 0)
end
y = y+1
if y > 53 then x = x+1 y = 1 end
gc: fillRect (x*4, y*4-4, 4, 4)
end
end
function on.enterKey ()
mat[1].value = mat[1].on
end
Si vous avez déjà fait des programmes à la noix comme cela, je vous invite à les partager dans ce topic (ou pas).