Example #1
0
  //----------------------------------------------------------------------
  void CondProbTableTest::testTable(const string& testName, CondProbTable& table, 
                                    const vector<vector<Real> > & rows)
  {
  
    // Test the numRows(), numCols() calls
    TESTEQUAL(numRows(), table.numRows());
    TESTEQUAL(numCols(), table.numColumns());

    // See if they got added right
    vector<Real>  testRow(numCols());
    for (Size i=0; i<numRows(); i++) {
      stringstream ss;
      ss << "updateRow " << i;
    
      table.getRow((UInt)i, testRow);
      testVectors(testName+ss.str(), rows[i], testRow);
    }


    // --------------------------------------------------------------------
    // Try out normal inference
    vector<Real> expValue;
    vector<Real> output(numRows());
  
    // Row 0 matches row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 0 infer", makeCol((Real).16, (Real)0, (Real)0, (Real).24), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 1 infer", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and 3
    table.inferRow (rows[2], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 2 infer", makeCol((Real)0, (Real)0, (Real).36, (Real).24), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferMarginal);
    testVectors(testName+"row 3 infer", makeCol((Real).24, (Real)0, (Real).24, (Real).52), output);
  
  
    // --------------------------------------------------------------------
    // Try out inferEvidence inference
  
    // Row 0 matches row 0 and half row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 0 inferEvidence", makeCol((Real).4, (Real)0, (Real)0, (Real).24), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 1 inferEvidence", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and half row 3
    table.inferRow (rows[2], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 2 inferEvidence", makeCol((Real)0, (Real)0, (Real).6, (Real).24), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferRowEvidence);
    testVectors(testName+"row 3 inferEvidence", makeCol((Real).6, (Real)0, (Real).4, (Real).52), output);
  
  
    // --------------------------------------------------------------------
    // Try out inferMaxProd inference
  
    // Row 0 matches row 0 and half row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 0 inferMaxProd", makeCol((Real).16, (Real)0, (Real)0, (Real).24), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 1 inferMaxProd", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and half row 3
    table.inferRow (rows[2], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 2 inferMaxProd", makeCol((Real)0, (Real)0, (Real).36, (Real).24), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferMaxProd);
    testVectors(testName+"row 3 inferMaxProd", makeCol((Real).24, (Real)0, (Real).24, (Real).36), output);
  
  
    // --------------------------------------------------------------------
    // Try out inferViterbi inference
  
    // Row 0 matches row 0 and half row 3, so we get half and half hits on those rows
    table.inferRow (rows[0], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 0 inferViterbi", makeCol((Real)0, (Real)0, (Real)0, (Real).4), output);
  
    // Row 1 matches only row 1
    table.inferRow (rows[1], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 1 inferViterbi", makeCol((Real)0, 1, (Real)0, (Real)0), output);

    // Row 2 matches only row 2 and half row 3
    table.inferRow (rows[2], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 2 inferViterbi", makeCol((Real)0, (Real)0, (Real).6, (Real)0), output);

    // Row 3 matches row 0 & row 2 halfway, and row 3 exactly
    table.inferRow (rows[3], output, CondProbTable::inferViterbi);
    testVectors(testName+"row 3 inferViterbi", makeCol((Real)0, (Real)0, (Real).4, (Real).6), output);
  
  
    // Add a row a second time, the row should double in value
    table.updateRow(0, rows[0]);
    expValue = rows[0];
    for (Size i=0; i<numCols(); i++)
      expValue[i] *= 2;
    table.getRow(0, testRow);
    testVectors(testName+"row 0 update#2", expValue, testRow);
  
  }
Example #2
0
static void posix_print(std::ostream& os, qi::StreamColor col) {
  switch (col) {
  case qi::StreamColor_None:
    break;
  case qi::StreamColor_Reset:
    os << makeCol(0);
    break;
  case qi::StreamColor_Bold:
    os << makeCol(1);
    break;
  case qi::StreamColor_Faint:
    os << makeCol(2);
    break;
  case qi::StreamColor_Standout:
    os << makeCol(3);
    break;
  case qi::StreamColor_Underline:
    os << makeCol(4);
    break;
  case qi::StreamColor_Blink:
    os << makeCol(5);
    break;
  case qi::StreamColor_Overline:
    os << makeCol(6);
    break;

  case qi::StreamColor_Black:
    os << makeCol(30, 0);
    break;
  case qi::StreamColor_DarkRed:
    os << makeCol(31, 0);
    break;
  case qi::StreamColor_DarkGreen:
    os << makeCol(32, 0);
    break;
  case qi::StreamColor_Brown:
    os << makeCol(33, 0);
    break;
  case qi::StreamColor_DarkBlue:
    os << makeCol(34, 0);
    break;
  case qi::StreamColor_Purple:
    os << makeCol(35, 0);
    break;
  case qi::StreamColor_Teal:
    os << makeCol(36, 0);
    break;
  case qi::StreamColor_LightGray:
    os << makeCol(37, 0);
    break;

  case qi::StreamColor_DarkGray:
    os << makeCol(30, 1);
    break;
  case qi::StreamColor_Red:
    os << makeCol(31, 1);
    break;
  case qi::StreamColor_Green:
    os << makeCol(32, 1);
    break;
  case qi::StreamColor_Yellow:
    os << makeCol(33, 1);
    break;
  case qi::StreamColor_Blue:
    os << makeCol(34, 1);
    break;
  case qi::StreamColor_Fuchsia:
    os << makeCol(35, 1);
    break;
  case qi::StreamColor_Turquoise:
    os << makeCol(36, 1);
    break;
  case qi::StreamColor_White:
    os << makeCol(37, 1);
    break;
  };
}