Ignore:
Timestamp:
Nov 28, 2013, 5:11:23 AM (8 years ago)
Author:
Peter
Message:

closes #772. new function that calculates mutual information

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/statistics.cc

    r3135 r3137  
    3333#include "yat/statistics/tTest.h"
    3434#include "yat/utility/DataWeight.h"
     35#include "yat/utility/Matrix.h"
    3536#include "yat/utility/MatrixWeighted.h"
    3637#include "yat/utility/Vector.h"
     
    4950void test_entropy(test::Suite&);
    5051void test_mad(test::Suite&);
     52void test_mutual_information(test::Suite&);
    5153
    5254void test_median_empty(test::Suite&);
     
    5557
    5658template<typename RandomAccessIterator>
    57 void test_percentiler(test::Suite&, RandomAccessIterator, 
     59void test_percentiler(test::Suite&, RandomAccessIterator,
    5860                      RandomAccessIterator,
    5961                      double p, double correct);
    6062
    6163template<typename RandomAccessIterator1, typename RandomAccessIterator2>
    62 void cmp_percentiler(test::Suite&, 
    63                      RandomAccessIterator1, 
     64void cmp_percentiler(test::Suite&,
     65                     RandomAccessIterator1,
    6466                     RandomAccessIterator1,
    6567                     RandomAccessIterator2,
     
    6769
    6870int main(int argc, char* argv[])
    69 { 
     71{
    7072  test::Suite suite(argc, argv);
    7173
     
    135137  test_entropy(suite);
    136138  test_median_empty(suite);
     139  test_mutual_information(suite);
    137140  return suite.return_value();
    138141}
     
    218221
    219222
     223void test_mutual_information(test::Suite& suite)
     224{
     225  suite.out() << "testing mutual_information\n";
     226  using statistics::mutual_information;
     227  utility::Matrix x(2,2);
     228  x(0,0) = 100;
     229  x(1,1) = 100;
     230  double mi = mutual_information(x);
     231  if (!suite.add(suite.equal(mi,1.0,100))) {
     232    suite.err() << "error: mutual information: " << mi << "\n";
     233  }
     234
     235  // testing a non-square Matrix
     236  x.resize(3,4,0);
     237  x(0,0) = 1;
     238  x(1,1) = 1;
     239  x(2,2) = 1;
     240  x(2,3) = 1;
     241  mi = mutual_information(x);
     242  suite.out() << "mi: " << mi << "\n";
     243}
     244
     245
    220246// test for ticket #660
    221247void test_median_empty(test::Suite& suite)
Note: See TracChangeset for help on using the changeset viewer.