11-16-2023, 06:37 PM
Code: (Select All)
'Program NNET256.BAS produces neural net attractors
'(VGA 320 x 200 x 256 color version)
'Copyright (c) 1997 by J. C. Sprott
Screen 13
N% = 4 'Number of neurons
D% = 16 'Number of inputs (dimension)
s = .5 'Scaling factor (network gain)
tmax& = 80000 'Number of iterations
sw% = 319 'Screen width - 1
sh% = 199 'Screen height - 1
nc% = 254 'Number of colors - 2
Dim w(N%, D%), B(N%, D%), x(N%), y(D%), PAL&(nc% + 1)
PAL&(0) = 65536 * 63 + 256 * 63 + 63 'PAL&(0) IS WHITE
PAL&(1) = 65536 * 55 + 256 * 55 + 55 'PAL&(1) IS GRAY
For i% = 2 To nc% + 1
B% = Int(32 + 32 * Cos(.02464 * i%))
G% = Int(32 + 32 * Cos(.02464 * i% + 4.1888))
R% = Int(32 + 32 * Cos(.02464 * i% + 2.0944))
PAL&(i%) = 65536 * B% + 256 * G% + R%
Next i%
Randomize Timer
While InKey$ <> Chr$(27)
Cls
Palette Using PAL&(0)
p& = 0
For i% = 1 To N%
For j% = 1 To D%
w(i%, j%) = 1 - 2 * Rnd
Next j%
B(i%, 1) = s * Rnd
x(i%) = .5
Next i%
For t& = 1 To tmax&
y(0) = 0
For i% = 1 To N%
y(0) = y(0) + B(i%, 1) * x(i%)
Next i%
For j% = D% To 1 Step -1
y(j%) = y(j% - 1)
Next j%
For i% = 1 To N%
u = 0
For j% = 1 To D%
u = u + w(i%, j%) * y(j%)
Next j%
x(i%) = 1 - 2 / (Exp(2 * u) + 1)
Next i%
If t& > tmax& / 50 Then
If 10 * p& + 50 < t& - tmax& / 50 Then t& = tmax&
x% = .5 * (sw% + sw% * x(1))
y% = .5 * (sh% - sh% * x(2))
z% = .025 * (sw% + sw% * x(3))
c% = 2 + Int(nc% * (.5 * x(4) + .5))
If Point(x%, y%) < 2 Then p& = p& + 1
If c% > Point(x%, y%) Then PSet (x%, y%), c%
x% = x% + z%: y% = y% + z%
If Point(x%, y%) = 0 Then PSet (x%, y%), 1
End If
Next t&
Wend
End