gusl: (Default)
gusl ([personal profile] gusl) wrote2007-03-01 03:21 pm

lucky accidents

My refactoring fastICA was performing better than fastICA itself (better agreement with R), so I went hunting for the difference.

This is my "buggy" code:
    DoubleMatrix2D resultMatrix = (DoubleMatrix2D) inVectors.clone();

The "clone" is deceptive: essentially, resultMatrix is going to have the same pointers as inVectors... so changing entries in resultMatrix changes them in inVectors.

This is the correct way to clone:
    DoubleMatrix2D resultMatrix = new DenseDoubleMatrix2D(convert(inVectors));


I think there may be a mathematical reason why using the resultMatrix is superior to using inVectors, despite the FastICA implementation.

Another possibility is that the R implementation has the exact same bug as the one I introduced in my poorly-executed "cloning".

[identity profile] ekorber.livejournal.com 2007-03-02 12:25 am (UTC)(link)
Haha, as I repeated to my students many times last summer... when coding in Java, if you didn't type the word new, NO new object will be created.