|
PLearn 0.1
|
#include <SmoothedProbSparseMatrix.h>


Public Member Functions | |
| void | complement (ProbSparseMatrix &nXY, bool clear_nXY=false) |
| real | get (int i, int j) |
| bool | checkCondProbIntegrity () |
Protected Attributes | |
| real | grandSum |
| Vec | rowSum |
| Vec | columnSum |
Definition at line 77 of file SmoothedProbSparseMatrix.h.
| bool PLearn::ComplementedProbSparseMatrix::checkCondProbIntegrity | ( | ) |
Reimplemented from PLearn::ProbSparseMatrix.
Definition at line 468 of file SmoothedProbSparseMatrix.cc.
References PLearn::DoubleAccessSparseMatrix< real >::cols, PLearn::DoubleAccessSparseMatrix< real >::height, i, j, PLearn::DoubleAccessSparseMatrix< real >::mode, ROW_WISE, PLearn::DoubleAccessSparseMatrix< real >::rows, PLearn::sum(), and PLearn::DoubleAccessSparseMatrix< real >::width.
{
real sum = 0.0;
int null_size;
// TO BE DONE
if (mode == ROW_WISE){
for (int i = 0; i < height; i++){
map<int, real>& row_i = rows[i];
for (map<int, real>::iterator it = row_i.begin(); it != row_i.end(); ++it){
}
if (fabs(sum - 1.0) > 1e-4 && (sum > 0.0))
cout << " Inconsistent line " << i << " sum = "<< sum;
return false;
}
return true;
}else{
for (int j = 0; j < width; j++){
map<int, real>& col_j = cols[j];
for (map<int, real>::iterator it = col_j.begin(); it != col_j.end(); ++it){
}
if(fabs(sum - 1.0) > 1e-4 && (sum > 0.0)){
cout << " Inconsistent column " << j << " sum = "<< sum;
return false;
}
}
return true;
}
}

| void PLearn::ComplementedProbSparseMatrix::complement | ( | ProbSparseMatrix & | nXY, |
| bool | clear_nXY = false |
||
| ) |
Definition at line 406 of file SmoothedProbSparseMatrix.cc.
References PLearn::DoubleAccessSparseMatrix< T >::clear(), COLUMN_WISE, columnSum, PLearn::DoubleAccessSparseMatrix< T >::getCol(), PLearn::DoubleAccessSparseMatrix< T >::getHeight(), PLearn::DoubleAccessSparseMatrix< T >::getMode(), PLearn::DoubleAccessSparseMatrix< T >::getRow(), PLearn::DoubleAccessSparseMatrix< T >::getWidth(), grandSum, i, PLearn::DoubleAccessSparseMatrix< T >::isDoubleAccessible(), j, PLearn::DoubleAccessSparseMatrix< real >::mode, PLERROR, PLearn::TVec< T >::resize(), ROW_WISE, and rowSum.
{
int nXY_height = nXY.getHeight();
int nXY_width = nXY.getWidth();
rowSum.resize(nXY_height);
columnSum.resize(nXY_width);
if (mode == ROW_WISE && (nXY.getMode() == ROW_WISE || nXY.isDoubleAccessible())){
for (int i = 0; i < nXY_height; i++){
map<int, real>& row_i = nXY.getRow(i);
for (map<int, real>::iterator it = row_i.begin(); it != row_i.end(); ++it){
rowSum[i]+=it->second;
columnSum[it->first]+=it->second;
grandSum+=it->second;
}
}
if (clear_nXY)
nXY.clear();
} else if (mode == COLUMN_WISE && (nXY.getMode() == COLUMN_WISE || nXY.isDoubleAccessible())){
for (int j = 0; j < nXY_width; j++){
map<int, real>& col_j = nXY.getCol(j);
for (map<int, real>::iterator it = col_j.begin(); it != col_j.end(); ++it){
rowSum[it->first]+=it->second;
columnSum[j]+=it->second;
grandSum+=it->second;
}
}
if (clear_nXY)
nXY.clear();
} else{
PLERROR("pXY and nXY accessibility modes must match");
}
}

Definition at line 442 of file SmoothedProbSparseMatrix.cc.
References PLearn::DoubleAccessSparseMatrix< real >::cols, columnSum, grandSum, PLearn::DoubleAccessSparseMatrix< real >::height, i, j, PLearn::DoubleAccessSparseMatrix< real >::mode, PLERROR, ROW_WISE, PLearn::DoubleAccessSparseMatrix< real >::rows, rowSum, and PLearn::DoubleAccessSparseMatrix< real >::width.
{
#ifdef BOUNDCHECK
if (i < 0 || i >= height || j < 0 || j >= width)
PLERROR("SmoothedProbSparseMatrix.get : out-of-bound access to (%d, %d), dims = (%d, %d)", i, j, height, width);
#endif
if (mode == ROW_WISE){
map<int, real>& row_i = rows[i];
map<int, real>::iterator it = row_i.find(j);
if (it == row_i.end()){
return rowSum[j]/(grandSum-columnSum[i]);
}else{
return (rowSum[j]-it->second)/(grandSum-columnSum[i]);
}
} else{
map<int, real>& col_j = cols[j];
map<int, real>::iterator it = col_j.find(i);
if (it == col_j.end()){
return columnSum[j]/(grandSum-rowSum[i]);
}else{
return (columnSum[j]-it->second)/(grandSum-rowSum[i]);
}
}
}
Vec PLearn::ComplementedProbSparseMatrix::columnSum [protected] |
Definition at line 83 of file SmoothedProbSparseMatrix.h.
Referenced by complement(), and get().
real PLearn::ComplementedProbSparseMatrix::grandSum [protected] |
Definition at line 81 of file SmoothedProbSparseMatrix.h.
Referenced by complement(), and get().
Vec PLearn::ComplementedProbSparseMatrix::rowSum [protected] |
Definition at line 82 of file SmoothedProbSparseMatrix.h.
Referenced by complement(), and get().
1.7.4