Statistiques
| Révision :

root / tmp / org.txm.analec.rcp / src matt / JamaPlus / AFC.java @ 1968

Historique | Voir | Annoter | Télécharger (1,95 ko)

1
/*
2
 * To change this template, choose Tools | Templates
3
 * and open the template in the editor.
4
 */
5
package JamaPlus;
6

    
7
/**
8
 *
9
 * AFC analyse factorielle des correspondances (optimisé mémoire)
10
 * mat :  matrice binaire (0. ou 1.) profil des lignes (un individu par ligne, un caractère par colonne)
11
 * CP: composantes principales,
12
 * VP: valeurs d'inertie, 
13
 * CG: centres de gravité des CP contenant un même caractère (non calculé dans cette version)
14
 * [p,q] = size(mat); p:nb de lignes, q:nb de col
15
 * 
16
 * @author Bernard Victorri
17
 */
18
public class AFC {
19

    
20
  private double[][] CP;
21
  private double[] VP;
22
  private int p, q, n;
23

    
24
  AFC(Matrix Arg) {
25
    Matrix mat = Arg.copy();
26
    mat = mat.nulColumnSuppression();
27
    p = mat.getRowDimension();
28
    q = mat.getColumnDimension();
29
    n = Math.min(Math.min(p, q), 5); // n : nombre de composantes principales calculées
30
    if (n == 0) return;
31
    if (n == 1) {
32
      CP = new double[p][1];
33
      VP = new double[1];
34
      return;
35
    }
36
    double f = mat.elementSum();
37
    if (f == 0) return;
38
    mat = mat.timesEquals(1 / f);
39
    Matrix r = mat.lineSum();
40
    Matrix r1 = r.arrayInverse();
41
    Matrix r2 = r.arraySqrt();
42
    Matrix r3 = r2.arrayInverse();
43
    Matrix c = mat.columnSum();
44
    Matrix c1 = c.arrayInverse();
45
    Matrix c2 = c.arraySqrt();
46
    Matrix c3 = c2.arrayInverse();
47
    mat = mat.firstColumnTimesEqual(r3);
48
    mat = mat.firstLineTimesEqual(c3);
49
    SingularValueDecomposition svd = mat.svd();
50
    Matrix cp = svd.getU();
51
    Matrix vp = new Matrix(svd.getSingularValues(), 1);
52
    cp = cp.getMatrix(0, p - 1, 1, n - 1);
53
    cp = cp.firstColumnTimesEqual(r2);
54
    vp = vp.getMatrix(0, 0, 1, n - 1);
55
    cp = cp.firstLineTimesEqual(vp);
56
    cp.fixColumnSigns();
57
    cp = cp.firstColumnTimesEqual(r1);
58
    CP = cp.getArray();
59
    VP = vp.getColumnPackedCopy();
60
  }
61

    
62
  public Matrix getCP() {
63
    if (CP == null) return null;
64
    return new Matrix(CP, p, n - 1);
65
  }
66

    
67
  public double[] getVP() {
68
    return VP;
69
  }
70
}