haifengl / smile

Statistical Machine Intelligence & Learning Engine
https://haifengl.github.io
Other
5.97k stars 1.13k forks source link

Bug report for ICA: The output of Independent Components size are wrong #733

Closed LeXing1105 closed 1 year ago

LeXing1105 commented 1 year ago

Describe the bug For the fastICA algorithm, you mentioned: "* @param components each row is an independent component. "

if we input the training data (shape=32x800), set up the number of source as 32, the expected results should be the Independent Components (shape=32x800 too), but for now, it outputs the results of 32*32 matrix, which is not expected.

I think there should be a bug in the ICA Class:(inside ICA fit)

public static ICA fit(double[][] data, int p, DifferentiableFunction contrast, double tol, int maxIter){

double[][] W = new double[p][n];

int n = data.length; //(n=32 in my case) int m = data[0].length; //(m=800 in my case) ...

return new ICA(W)

}

if W has the size of [p][m] (32x800), rather than [p][n] (32x32), the results should be correct. Is it right? Please help have a look and clarify this. Thank you very much!

Input data

The data I input for ICA training is a randomly simulated matrix 32*800

double[][] multichannelEEG = new double[32][200*4];

    // simulate a signal: 32 rows, 800 columns
    Random random1 = new Random();
    for (int i=0; i<32; i++){
        for (int j=0; j<EEGDuration; j++){
            multichannelEEG[i][j] = 100*(random1.nextDouble()-0.5);
        }
    }

Actually I tried different lengths, 32x800, 32x8000, etc. The results constantly output 32x32 matrix.

Attached are: ICA Class, my code, my logCat

ica mycode log
haifengl commented 1 year ago

This should have been fixed in the master branch. Please build and test it locally (see http://haifengl.github.io/quickstart.html). If it works, we will make a new release. Thanks.

LeXing1105 commented 1 year ago

Thank you sir for updating. I tried to build and test it according to the guidance, but it was very hard to make it work in Android Studio. I downloaded the Master Branch, converted zip it to JAR, and imported it to Android Project, but Android studio just cannot recognize it, making me struggle. I usually only use implementation to add libraries. Can you just make a newer version release which should be easier for testing? Many thanks! image

saudet commented 1 year ago

Android Studio doesn't support native libraries in JAR files very well, but we can easily extract them from Gradle with a task like the javacppExtract one shown at https://github.com/bytedeco/gradle-javacpp#the-platform-plugin

haifengl commented 1 year ago

Do you just zip the source code? You should run

sbt publishM2

This will build and publish the library to your local maven cache. Android Studio should be able to pick it up there.

LeXing1105 commented 1 year ago

I followed the instructions and tried but it didn't work for me! (Installed JDK, scala, sbt, then added everything to environment variables and path). The issue screenshot is attached. Maybe my laptop configurations are different.

I also tried importing the source code into Eclipse and exporting it as an executable JAR file, but it didn't work either.

Are there any other easier way to build the GitHub source code into an executable jar file? Does it have to be so hard? Could you please make a package that can be used directly? I am really a newbie to Java.

image

haifengl commented 1 year ago

I guess that you are using JDK8. From Smile 3.0+, you should use JDK11 or JDK17 to build the software.

LeXing1105 commented 1 year ago

I am using JAVA 17 now, but the sbt commands don't work for me. I have no idea how to fix it. Could you please just make a new release to make things easier? Thank you so much! :)

image

haifengl commented 1 year ago

I make some revision to make build work on windows. Please run the following

git pull
sbt core/publishM2

This will build Smile 3.0.1 to your local maven. Then you should update your project to use version 3.0.1.

LeXing1105 commented 1 year ago

@haifengl Thank you very much, Sir! It's working now. I have built the package and tested it on Android Studio. The ICA algorithm can output the correct result shape now. Excellent!

I input a 32x800 matrix, and the ICA decomposes it and outputs a 32x800 matrix (ICs), I think the bug is fixed now!