Poor man's neural network

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Poor man's neural network

Post by hgm »

Neural networks are rather computation intensive. But perhaps there is an alterative to do similar things in a different way. I coined the idea to use a small hash table for learning SEE from scratch in Ed's conspiracy thread. But perhaps this idea has more mileage than I originally suspected.

For those who have not been following the thread, the idea was this:

Assign a randomly picked hash key to each colored piece type. Then calculate all attacks to each square (also those that protect an own piece), and add the hash keys of all attacking pieces. (No XOR; you want to be able to see if two identical pieces attack the square, rather than none.) Also add the key of the occupant, but multiplied by a factor. (So that you can see the difference between a occupant ad a attacker/protector of the same type. Clip to (say) 12 bits, and use as index in a table to look up one or more number to use as 'output' of this calculation.

This can be pretty good at recognizing whether the occupant is sufficiently protected, because each combination of attackers and protectors will in general map to a different entry of the lookup table, if it is large enough. If not large enough you will get collisions, but unless you are very unlucky, only for quite complex combinations of attackers and protectors, which hardly occur anyway. So you can use the output as a signal to indicate whether the occupant can be safely captured by one of its attackers, or (when it has the move) should better move away. You would have needed a pretty complex neural net to do that. And this is about as much work as simulating a single cell. It is also quite easy to make it learn: just alter the value in the table of the entry that was chosen as output to alter the output in that situation.

You could learn to recogize pins in a similar way, by calculating the sum of the keys of diametrically opposite neighbors of each occupied square, and using that as index in another table. This table could easily learn to flag situatios where moving the occupant away would create a LxH capture for the opponent. I fact looking on one ray oly is a bit easy, you can easily add the hash key of all 8 nearest neighbors in the principal directions, but with a differet multiplier for each ray orientation, to examine all possible pins of the piece at once.

Of course you would also like to be able to detect (soft-)pins where moving the piece would result in HxL or equal captures of an unprotected piece. This is a 'second-order' pattern, which depends both on the pin pattern, and on the protection status of the piece that would receive the discovered slider attack. The key-sum used to look up if a piece is sufficietly protected could also be used to generate a second output to indicate the piece is only barely sufficietly protected, and cannot bear an extra attacker. Which would make it a 'pin point'. This output could be used as a second index to the table for pin lookups, so that the pin detector gives other outputs when ignoring the pin would expose sufficiently protected pieces and insufficietly protected pieces.

There is a lot you could play with here, to make something that suggests moves to a MCTS and can be trained, but is not excessively expesive to calculate.
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: Poor man's neural network

Post by Michael Sherwin »

Indeed! I was thinking along these same lines when I made this one sentence reply in another thread about how RomiChess works.

"It is experiential data modified by reinforcement learning values that is loaded into the hash file that affects the values in the nodes of the alpha-beta search which result in a feedback value to the piece-square-tables of the evaluator that result in a lingering generalized influence."

The hash table really does act as a poor man's NN.
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
Daniel Shawul
Posts: 4185
Joined: Tue Mar 14, 2006 11:34 am
Location: Ethiopia

Re: Poor man's neural network

Post by Daniel Shawul »

Michael Sherwin wrote:Indeed! I was thinking along these same lines when I made this one sentence reply in another thread about how RomiChess works.

"It is experiential data modified by reinforcement learning values that is loaded into the hash file that affects the values in the nodes of the alpha-beta search which result in a feedback value to the piece-square-tables of the evaluator that result in a lingering generalized influence."

The hash table really does act as a poor man's NN.
Isn't there something you haven't invented ?? You hear "learning", you go i invented this 10 years ago and tell us how stupid we are, you hear "hashtables and NN", you go i though of this!

Note that the hashing H.G. is talking about doesn't involve where pieces are placed.
Your hashtable is a 64-bit key specific that simply avoids loosing lines, not something generalizable.

Please take your pills cause your delusions are escalating.
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: Poor man's neural network

Post by Michael Sherwin »

Daniel Shawul wrote:
Michael Sherwin wrote:Indeed! I was thinking along these same lines when I made this one sentence reply in another thread about how RomiChess works.

"It is experiential data modified by reinforcement learning values that is loaded into the hash file that affects the values in the nodes of the alpha-beta search which result in a feedback value to the piece-square-tables of the evaluator that result in a lingering generalized influence."

The hash table really does act as a poor man's NN.
Isn't there something you haven't invented ?? You hear "learning", you go i invented this 10 years ago and tell us how stupid we are, you hear "hashtables and NN", you go i though of this!

Note that the hashing H.G. is talking about doesn't involve where pieces are placed.
Your hashtable is a 64-bit key specific that simply avoids loosing lines, not something generalizable.

Please take your pills cause your delusions are escalating.
I have posted many times about the feedback loop learning between the search and evaluation many times over the years. I never thought about the poor man's NN before a few days ago because I never had to think in terms of NN, since nothing NN has made a splash till now.

As far as the HGM connection, HG never used the word contiguous or even heard of it before until I posted that if INTEL was smart they would create instructions that used a mask to do arithmetic on non contiguous bits. Three years later INTEL came out with that instruction. For INTEL the turnaround time is three years from idea to release. So how about I take credit for inventing that instruction that is in your newer computers. Now you will never be able to look at your computers again without getting boiling mad, :lol: . HGM uses the word contiguous quite often now. I posted about a poor man's something, can't remember what it was, but since then HGM has used that terminology as in poor man's SEE and now poor Man's NN. Are you punching holes in the wall yet? Do you want to hear about split index compression that I invented? Or maybe about what I called metadata that I posted about? Although I have no idea if the metadata that I posed about is similar to what others talk about today. Would you like a list of everything that I have come up with and posted about that you never noticed? I'd be happy to do it if it would push you over the edge. Do you want to hear about how after I published my feedback idea Tord put a feedback idea into Glaurung. Is it the same as mine, idk. I just thought I'd mention it if it would cause you to beat your head against the wall! :P

So Daniel just let me know how you'd like me to antagonize you and I'd be more than happy to help you out. After all what are BFF's for?

:lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol: :lol:
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through