Reputation: 1
How can we apply PCA to a one dimensional array ?
double[][] data = new double [1][600];
PCA pca = new PCA(data, 20);
data = pca.getPCATransformedDataAsDoubleArray();
When a print the values in data array, the features in the data array decrease 600 to 20, but all values zero.
Why?
package VoiceRecognation;
import Jama.Matrix;
import comirva.data.DataMatrix;
import comirva.util.PCA;
import javax.print.attribute.standard.Finishings;
import java.io.File;
/**
* Created by IntelliJ IDEA.
* User: SAHIN
* Date: 11.06.2011
* Time: 19:33
* To change this template use File | Settings | File Templates.
*/
public class Deneme {
public static void main(String[] args) {
int[] group = Groups.getGroups();
File[] files = Files.getFiles();
double[][] data = FindMfccOfFiles.findMFCCValuesOfFiles(files);
PCA pca = new PCA(data, 20);
data = pca.getPCATransformedDataAsDoubleArray();
File file = new File("src/main/resources/Karisik/E-Mail/(1).wav");
double[] testdata = MFCC.getMFCC(file);
double[][] result = new double[1][600];
result[0] = testdata;
PCA p = new PCA(result, 20);
double [][] sum = p.getPCATransformedDataAsDoubleArray();
for (int i = 0; i < sum[0].length; i++) {
System.out.print(sum[0][i] + " ");
}
}
}
Upvotes: 0
Views: 1204
Reputation: 106
Principal component analysis is used for reducing the dimensionality of your problem. The dimensions of the audio file are the channels (e.g. left speaker, right speaker), not the individual samples. In that case, you really have only one dimension for a mono audio stream. So, you're not going to reduce the number of samples using PCA, but you could reduce the number of channels in the audio. But you could do that without PCA just by averaging the samples on each channel. So unless you're trying to convert stereo audio into mono, I think you need a different approach to your problem.
Upvotes: 3
Reputation: 44535
You overwrite the data array with the result of the method getPCATransformedDataAsDoubleArray. I assume, this is an array with 20 entries because of the constructor arg. I don't know, why all values are zero, i think, because it's defined in the class PCA.
Upvotes: 0