QB64 Phoenix Edition
artificial net attractors - Printable Version

+- QB64 Phoenix Edition (https://staging.qb64phoenix.com)
+-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3)
+---- Forum: Programs (https://staging.qb64phoenix.com/forumdisplay.php?fid=7)
+---- Thread: artificial net attractors (/showthread.php?tid=421)



artificial net attractors - BSpinoza - 05-16-2022

This program generates an endless succession of artificial net attractors,
by a program of J.C.Sprott from 1989.

A description you will find in the following paper:

https://sprott.physics.wisc.edu/pubs/paper232.pdf

I made small changes to adapt it into QB64.


Code: (Select All)
' program: neutal_net_attractors.bas
'          by J. C. Sprott
'
' adapted to QB64 by BSpinoza
'
' This program produces neural net attractors,
' it generates endless succession of artificial neural net attractors
' Copyright (c) 1997 by J. C. Sprott

SCREEN _NEWIMAGE(880, 650, 256)
WINDOW (-5, -5)-(680, 410)
N% = 4 'Number of neurons
D% = 16 'Number of inputs (dimension)
s = .5 'Scaling factor (network gain)
tmax& = 80000 'Number of iterations
sw% = 638 '319 'Screen width - 1
sh% = 399 '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)
    _DELAY 0.2
    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



RE: artificial net attractors - triggered - 05-24-2022

BSpinoza

Thanks for sharing this wonderful program and the paper that follows is stunning. It's an actual scientific paper with that used QBASIC to generate all of the graphics.

Do you have more like this?

Thanks,

T'd


RE: artificial net attractors - euklides - 05-29-2022

Nice. Thank's. Just add a small delay to observe the results !