Skip to content

Commit

Permalink
returns column contributions for MI
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewjdenny committed Dec 11, 2016
1 parent 2e40660 commit 572843d
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Fast_Sparse_Mutual_Information.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,35 @@ double Fast_Sparse_Mutual_Information(
}
return mutual_information;
}




// [[Rcpp::export]]
List Fast_Sparse_Mutual_Information_Full(
arma::vec rows,
arma::vec cols,
arma::vec vals,
arma::vec colsums,
arma::vec rowsums,
int num_entries
){

arma::vec column_contribution = arma::zeros(colsums.n_elem);

double mutual_information = 0;
// loop over non-zero entries
for(int i = 0; i < num_entries; ++i){
double temp = std::log((vals[i]/(colsums[cols[i]]*rowsums[rows[i]])));
if(!std::isfinite(temp)){
temp = 0;
}
mutual_information += vals[i] * temp;
column_contribution[cols[i]] += vals[i] * temp;
}

List to_return(2);
to_return[0] = mutual_information;
to_return[1] = column_contribution;
return to_return;
}

0 comments on commit 572843d

Please sign in to comment.