- Code: Select all Expand view RUN
- // neural network
procedure main
ogg:={{"dog",0},{"mouse",0},{"snake",0},{"sparrow",0}}
azi:={{"has fur",0},{"has 4 legs",0},{"gnaws",0},{"slithers",0},{"has wings",0}}
dom:={0,0,0,0,0}
rules:={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}}
nquestions=5
nobjects=4
clear
if file ("rules.txt")
nHandle=fopen("rules.txt",0)
mr:=freadstr(nHandle,1000)
fclose(nHandle)
? mr
z=1
for j=1 to nobjects
for k=1 to nquestions
rules[j,k]=val(token(mr,",",z))
++z
next j
next k
endif
do while .t.
answer=" "
score=0
for j=1 to nobjects
ogg[j,2]=0
next j
? "think of an animal among dog, mouse, snake and sparrow and press enter (x ends)"
accept to answer
if answer="x"
exit
endif
for j=1 to nquestions
? azi[j,1] +"? "
accept to answer
dom[j]=if(upper(answer)="Y",1,0)
next j
// adesso calcola la variabile di decisione
for j=1 to nobjects
for k=1 to nquestions
ogg[j,2]=ogg[j,2]+dom[k]*rules[j,k]
next k
next j
// guarda chi ha raggiunto il punteggio maggiore
maxscore=0
nogg=0
for j=1 to nobjects
if ogg[j,2]>=maxscore
maxscore=ogg[j,2]
nogg=j
endif
next j
? "it is a " + ogg[nogg,1] + " ?"
accept to answer
if answer="N" .or. answer="n"
? "What was it?"
for j=1 to nobjects
? str(j) + " " + ogg[j,1]
next j
? "(animal number):"
accept to answer
nogg=val(answer)
//newpunt=0
for j=1 to nobjects
? dom[j]
// aggiorna matrice per oggetti diversi da quello giusto
if ogg[j,2]>=maxscore .and. j!=nogg
for k=1 to nquestions
rules[j,k]=rules[j,k]-dom[k]
next k
endif
if j=nogg
for k=1 to nquestions
rules[nogg,k]=rules[nogg,k]+dom[k]
next k
endif
next j
endif
ou=space(12)
for k=1 to nquestions
ou+=padr(azi[k,1],12)
next
? ou
for j=1 to nobjects
ou=padr(ogg[j,1],12) //+" "
for k=1 to nquestions
ou=ou+ str(rules[j,k])+" "
next k
? ou
next j
enddo
clear
? "save matrix ?"
accept to answer
if upper(answer)="S"
fcreate("rules.txt")
nHandle:=fcreate("rules.txt")
separ=","
ndati=0
for j=1 to nobjects
for k=1 to nquestions
cdato=str(rules[j,k])
fwrite (nhandle,cdato)
++ndati
if ndati<nobjects*nquestions
fwrite (nhandle,separ)
endif
next k
next j
fclose(nHandle)
endif
RETURN
Best regards,