/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dm;
import weka.core.matrix.Matrix;
/**
*
* @author student
*/
public class Irysy {
public static void main(String[] args) throws Exception {
TestDm irysy = new TestDm("C:/Program Files/Weka-3-6/data/iris.arff");
irysy.wypisz();
double[][] Z = new double[150][4];
double[] śr = new double[4];
double[] nowy = new double[4];
for (int i = 0; i < 150; i++) {
for (int q = 0; q < 4; q++) {
Z[i][q] = irysy.element(i, q);
}
}
normalizuj(Z);
Matrix zM = new Matrix(Z);
Matrix cov = zM.transpose().times(zM).times(1. / 150);
System.out.println("Nasza korelacja to: ");
System.out.println(cov);
}
private static void normalizuj(double[][] Z) {
double[] śr = new double[4];
double[] nowy = new double[4];
for (int q = 0; q < 4; q++) {
double suma = 0;
for (int i = 0; i < 150; i++) {
suma = Z[i][q] + suma;
}
śr[q] = suma / 150;
}
for (int i = 0; i < 150; i++) {
for (int q = 0; q < 4; q++) {
Z[i][q] = Z[i][q] - śr[q];
}
}
for (int q = 0; q < 4; q++) {
double suma = 0;
for (int i = 0; i < 150; i++) {
suma = (Z[i][q]) * (Z[i][q]) + suma;
}
nowy[q] = Math.sqrt(suma / 150);
}
for (int i = 0; i < 150; i++) {
for (int q = 0; q < 4; q++) {
Z[i][q] = Z[i][q] / nowy[q];
}
}
}
}