#include "sources/convexSolver.h" #include //to trace LL evolution #include #include #include "sources/utils/algebra.h" // auxiliary to compute log-likelihood + penalty double computeLogLikelihood( double** f, double* theta, double** Z, double*** phi, int* lengthNIix, int** NIix, double alpha, int nrow, int ncol) { double LL = 0.0; // for each row in data matrix: (one row = observations from 2001 to 2009) for (int i=0; i with u == NIix[i][j] (j-th neighbor of i) double dotProduct = 0.0; for (int jj=0; jj 0.0) F[i][j] = log(Z[i][j]) - theta[i]; } } } // phi_s,u = 1/sqrt(ncol) (1 ... 1) [TODO:: costly in memory !] double invSqrtNcol = 1.0/sqrt(ncol); double*** phi = (double***)malloc(nrow*sizeof(double**)); for (int i=0; i= epsilon && kounter++ < maxiter) { // gradient descent for theta for (int i=0; iu, - sum on neighbors u: u-->s sumDdivPhi = 0.0; for (int jj=0; jjs sumDdivPhi -= phi[NIix[i][jj]][i][j] / Dsu; } } gradIJ += alpha * sumDdivPhi; if (!symmNeighbs) { // need to remove sum on neighbors u: u-->s, uneasy way. //TODO: computation is much too costly here; need preprocessing sumDdivPhi = 0.0; for (int ii=0; ii 1.0) { if (normPhi > EPS) { for (int j=0; j