genW.cpp
1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include <armadillo>
using namespace std;
using namespace arma;
int main(int argc, char **argv)
{
mat X;
umat spkRows;
mat W;
X.load("./ivecs/X.dat");
spkRows.load("./ivecs/spkRows.dat");
int m(X.n_rows);
int n(X.n_cols);
int nSpk(spkRows.n_rows);
W.zeros(n, n);
// looping over the speakers
for (int i(0); i < nSpk; i++) {
// index of current speaker utterances in X matrix
umat idx = find(spkRows.row(i));
// number of current speaker utterances
int nUtt(idx.n_rows);
// submatrix of vectorized speaker utterances
mat S = X.rows(idx);
// speaker covariance matrix
mat C = zeros(n, n);
// mean vector of speaker utterance vectors
mat mu = mean(S);
// looping over speaker utterances
for (int j(0); j < nUtt; j++) {
mat dev = S.row(j) - mu;
C += dev.t() * dev;
}
// updating W
W += C;
}
// normalizing W
W /= m;
// writing out W
W.save("./ivecs/W.dat", raw_ascii);
return 0;
}