htm-community / comportex

Hierarchical Temporal Memory in Clojure
154 stars 27 forks source link

better hash / random number generator #22

Closed floybix closed 8 years ago

floybix commented 9 years ago

Random numbers are used:

  1. to generate initial proximal (potential) synapse connections;
  2. to sub-sample from active cells when growing dendrites;
  3. in unique encoder (each distinct input given a unique bit set);
  4. in coordinate encoder (coordinates' priorities and corresponding bits);
  5. in some of the example input generators.

The encoder uses require deterministic (seeded) random numbers.

Currently we use PPRNG since it presents a uniform API across clojurescript and jvm clojure. However I found, when testing coordinate encoder, that the RNG produces a very similar bitset (i.e. random number sequence) when given different seeds -- if the seeds are related: cljs hashes of vector tuples having the same first element, [x y] vs [x z].

I've worked around that for the moment, but the same problem would come up in unique encoder, and generally suggests problems (although I haven't looked into it). It may be that this kind of usage is not reasonable for a RNG and we should use a full-blown hashing algorithm instead?

Anyway if we need a new random number generator, a very nice splittable RNG has been implemented by Gary Fredericks for test.check https://github.com/clojure/test.check/blob/master/src/main/clojure/clojure/test/check/random.clj