示例#1
0
文件: Table.cpp 项目: rimsa/SCGaz
/**
 * Set value in row and column.
*/
int Table::setValue(int value, int row, int col) {
  int pos;
  int ret = -1;

  if (validated && row >= 0 && row < height) {
    // was the value added
    if (!lines[row]->setValue(value, col)) {
      // check if not violates table
      if ((value ? fullRow(row) : emptyRow(row)) || 
          (value ? fullColumn(col) : emptyColumn(col)) ||
          duplicatedRow(row, &pos))
        lines[row]->setValue((value ? 0 : 1), col);
      else
        ret = 0; // no error
    }
  }

  return ret;
}
示例#2
0
// virtual
void GNaiveBayes::trainSparse(GSparseMatrix& features, GMatrix& labels)
{
	if(features.rows() != labels.rows())
		throw Ex("Expected the features and labels to have the same number of rows");
	size_t featureDims = features.cols();
	GUniformRelation featureRel(featureDims, 2);
	beginIncrementalLearning(featureRel, labels.relation());
	GVec fullRow(featureDims);
	for(size_t n = 0; n < features.rows(); n++)
	{
		features.fullRow(fullRow, n);
		for(size_t i = 0; i < featureDims; i++)
		{
			if(fullRow[i] < 1e-6)
				fullRow[i] = 0.0;
			else
				fullRow[i] = 1.0;
		}
		trainIncremental(fullRow, labels[n]);
	}
}