cair / TsetlinMachine

Code and datasets for the Tsetlin Machine
https://arxiv.org/abs/1804.01508
MIT License
466 stars 51 forks source link

clause sign and feedback to clauses seems never to change? #11

Closed superqd closed 4 years ago

superqd commented 4 years ago

I was creating yet another node.js port of the code, well, less of a port, and more of a re-implementation, and I noticed in the MultiClassTsetlinMachine.pyx code, that the sign of a clause seems never to change, which means the type of feedback it receives will never change, is that correct?

I don't see how the sign of any particular clause will get updated, apart from the initial clause sign setup (line 83). In the feedback starting at line 260, it would seem to imply the checks for the sign polarity would always yield the same values, which would mean the feedbacks calculated on lines 267, 271, 279 and 283 would always be the same. This would seem to imply there is no reason for these feedback loops through the clauses in the first place (lines 261, 273).

Is that correct? Is there a reason why these feedbacks are re-checked every time update is called? They would seem never to change to me.

My worry is that could cause a subtle bug somehow, as I'd noticed that changing the initialization of the clause signs on line 86 from if j % 2 == 0: to if j % 2 != 0: caused a drop in accuracy, which didn't seem right, as it seemed like that would still yield the same number of clauses with each sign.

olegranmo commented 4 years ago

Hi supqd! Thanks for porting to node.js and your keen observation. The signs are in fact designed to be static, and instead the clause adapts to the sign. Those that have sign '+' learn the target class and those that have sign '-' learn what the other classes look like. In other words, the feedback loops modify which literals are in each clause, but not the sign of the clause.

The reason that you get different results is probably due to the randomness of the learning. Take the average of 100 executions, and "if j % 2 == 0:" and "if j % 2 != 0" should be quite similar.

superqd commented 4 years ago

Thanks for the response, that makes sense!