genW.cpp 1 KB
#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;
}