in reply to Encoding function needed
If your logic can work on a hash, I also suggest using a hash as a "sparse array". This also has the advantage that your indices are not restricted to positive integers. You can use anything that stringifies. Hashes are maybe a little slower than arrays, but with hashes you do not need the mapping and reverse mapping. In most cases the hash will be not (much) slower than map+array+remap.
An example of sparse vector cosine calculation:
Bag::Similarity::Cosine.
An example of a matrix with mixed negative and positive indices:
Align::Sequence::Ukkonen. See the "matrix" $F implemented as a hashref.
Helmut Wollmersdorfer
|
|---|