etaler / Etaler

A flexable HTM (Hierarchical Temporal Memory) framework with full GPU support.
BSD 3-Clause "New" or "Revised" License
89 stars 14 forks source link

GridCellEncoder problems #163

Open Thanh-Binh opened 1 year ago

Thanh-Binh commented 1 year ago

Hi Martin, this week I have time to look at your codes, and found somethings in "GridCell2d.hpp" that seem to be not-correct (sorry, if I am wrong!):

  1. The transformation matrix should not be inverted like
    std::array<float, 4> mat = inv2x2({cosf(theta), -sinf(theta)
                    ,sinf(theta), cosf(theta)});

    The correct formular should be:

    std::array<float, 4> mat = {cosf(theta), -sinf(theta)
                    ,sinf(theta), cosf(theta)};
  2. you use a utils- function inline Tensor gridCell2d() for encoding the different 2d-position values of the same input source. But every call this utils function creats new GridCell modules with different scale/rotation etc, so that the encoding results may not be consistant (i.e. encoding results of the same position are different from call to call

What do you think? Thanks

marty1885 commented 1 year ago

Long time! How's going on your side? New stuff?

  1. I think you are right. I vaguely remember there was a reason to use a inverse matrix (IIRC some semantic reason, not mathematical). But I can't recall now. Let me do some experiments and see if it there's a difference. But mathematically it should change nothing since inv(rotate(theta)) is just rotate(-theta). Thank you

  2. No, every call to gridCell2d() with the same parameters will result in the same tensor. The scale/rotation of the modules are controlled by the seed parameter and has a default value of 42. As long as you didn't change seed, the encoding result shouldn't change.

auto t1 = encoder::gridCell2d({2, 2});
auto t2 = encoder::gridCell2d({2, 2});
assert((t1 == t2).all() == true);
Thanh-Binh commented 1 year ago

for 1. theoretically OK, but practically? for 2.: OK