Source

orange / source / orange / contingency.cpp

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
#include "stladdon.hpp"

#include "vars.hpp"
#include "domain.hpp"
#include "examples.hpp"
#include "examplegen.hpp"
#include "classify.hpp"
#include "estimateprob.hpp"

#include "learn.hpp"

#include "contingency.ppp"

DEFINE_TOrangeVector_classDescription(PContingencyClass, "TContingencyClassList", true, ORANGE_API)

#define NOTSPEC(v) if (v.isSpecial()) throw mlexception("unknown variable value");
#define NEEDS(ptype) if(varType!=ptype) throw mlexception("invalid variable type");


// Initializes type field and discrete/continuous field, whichever appropriate.
TContingency::TContingency(PVariable var, PVariable innervar)
: outerVariable(var),
  innerVariable(innervar),
  varType(var ? var->varType : TValue::NONE),
  outerDistribution(TDistribution::create(var)),
  discrete((TDistributionVector *)NULL),
  innerDistribution(TDistribution::create(innervar)),
  innerDistributionUnknown(TDistribution::create(innervar))
{ 
  if (varType==TValue::INTVAR) {
    discrete = mlnew TDistributionVector();
    for(int i=0, e=outerVariable->noOfValues(); i!=e; i++)
      discrete->push_back(TDistribution::create(innervar));
  }
  else if (varType==TValue::FLOATVAR)
    continuous = mlnew TDistributionMap();
}


TContingency::TContingency(const TContingency &old)
: outerVariable(old.outerVariable),
  innerVariable(old.innerVariable),
  varType(old.varType),
  discrete((TDistributionVector *)NULL),
  outerDistribution(CLONE(TDistribution, old.outerDistribution)),
  innerDistribution(CLONE(TDistribution, old.innerDistribution)),
  innerDistributionUnknown(CLONE(TDistribution, old.innerDistributionUnknown))
{ if (varType==TValue::INTVAR)
    discrete = mlnew TDistributionVector(*old.discrete);
  else if (varType==TValue::FLOATVAR)
    continuous = mlnew TDistributionMap(*old.continuous);
}


int TContingency::traverse(visitproc visit, void *arg) const
{ TRAVERSE(TOrange::traverse);

  if (varType==TValue::INTVAR) {
    PITERATE(TDistributionVector, di, discrete)
      PVISIT(*di);
  }
  else if (varType==TValue::FLOATVAR) {
    PITERATE(TDistributionMap, di, continuous)
      PVISIT((*di).second);
  }

  return 0;
}

int TContingency::dropReferences()
{ DROPREFERENCES(TOrange::dropReferences);

  if (varType==TValue::INTVAR)
    mldelete discrete;
  else if (varType==TValue::FLOATVAR)
    mldelete continuous;

  return 0;
}


TContingency &TContingency::operator =(const TContingency &old)
{ outerVariable = old.outerVariable;
  innerVariable = old.innerVariable;
  varType = old.varType;
  innerDistribution = CLONE(TDistribution, old.innerDistribution);
  outerDistribution = CLONE(TDistribution, old.outerDistribution);
  innerDistributionUnknown = CLONE(TDistribution, old.innerDistributionUnknown);

  if (varType==TValue::INTVAR)
    discrete=mlnew TDistributionVector(*old.discrete);
  else if (varType==TValue::FLOATVAR)
    continuous=mlnew TDistributionMap(*old.continuous);
  else discrete=NULL;

  return *this;
}


TContingency::~TContingency()
{ if (varType==TValue::INTVAR)
    mldelete discrete;
  else if (varType==TValue::FLOATVAR)
    mldelete continuous;
}


PDistribution TContingency::operator [](const int &i)                
{ NEEDS(TValue::INTVAR); 
  while (int(discrete->size())<=i) {
    discrete->push_back(TDistribution::create(innerVariable));
    if (innerVariable->varType==TValue::INTVAR)
      discrete->back()->addint(innerVariable->noOfValues()-1, 0);
  }
  return (*discrete)[i];
}


const PDistribution TContingency::operator [](const int &i) const
{ NEEDS(TValue::INTVAR);
  if (!discrete->size())
    raiseError("empty contingency");
  if (i>=int(discrete->size()))
    raiseError("index %i is out of range 0-%i", i, discrete->size()-1);
  return (*discrete)[i];
}


PDistribution TContingency::operator [](const float &i)
{ NEEDS(TValue::FLOATVAR); 
  TDistributionMap::iterator mi=continuous->find(i);
  if (mi==continuous->end()) {
    PDistribution ret = (*continuous)[i] = TDistribution::create(innerVariable);
    if (innerVariable->varType==TValue::INTVAR)
      ret->addint(innerVariable->noOfValues()-1, 0);
    return ret;
  }
  else
    return (*mi).second;
}

    
const PDistribution TContingency::operator [](const float &i) const
{ NEEDS(TValue::FLOATVAR); 
  TDistributionMap::iterator mi = continuous->find(float(i));
  if (mi==continuous->end())
    raiseError("index out of range.");
  return (*mi).second;
}


PDistribution TContingency::operator [](const TValue &i)             
{ NOTSPEC(i);
  return (varType==TValue::INTVAR) ? operator[](int(i)) : operator[](float(i));
}


PDistribution const TContingency::operator [](const TValue &i) const // same, but calls 'const' version of operators[]
{ NOTSPEC(i);
  return (varType==TValue::INTVAR) ? operator[](int(i)) : operator[](float(i)); 
}


PDistribution TContingency::operator [](const string &i)             
{ TValue val;
  checkProperty(outerVariable);
  outerVariable->str2val(i, val);
  return operator[](val);
}


PDistribution const TContingency::operator [](const string &i) const // same, but calls 'const' version of operators[]
{ TValue val;
  checkProperty(outerVariable);
  outerVariable.getReference().str2val(i, val);
  return operator[](val);
}


void TContingency::add(const TValue &outvalue, const TValue &invalue, const float p)
{
  outerDistribution->add(outvalue, p);

  if (outvalue.isSpecial()) {
    innerDistributionUnknown->add(invalue, p);
  }
  else {
    innerDistribution->add(invalue, p);

    switch(outvalue.varType) {
      case TValue::INTVAR:
        if (!outvalue.svalV) {
          (*this)[outvalue]->add(invalue, p);
          return;
        }
        else {
          const TDiscDistribution &dv=dynamic_cast<const TDiscDistribution &>(outvalue.svalV.getReference());
          int i=0;
          float dp=p/dv.abs;
          const_ITERATE(TDiscDistribution, vi, dv)
            (*this)[i++]->add(invalue, dp*(*vi));
          return;
        }

      case TValue::FLOATVAR:
        if (!outvalue.svalV) {
          (*this)[outvalue]->add(invalue, p);
          return;
        }
        else {
          const TContDistribution &dv=dynamic_cast<const TContDistribution &>(outvalue.svalV.getReference());
          float dp=p/dv.abs;
          const_ITERATE(TContDistribution, vi, dv)
            (*this)[(*vi).first]->add(invalue, dp*(*vi).second);
          return;
        }
      default:
        raiseError("unknown value type");
    }
  }
}

       
PDistribution TContingency::p(const int &i) const
{ return operator[](i); }


PDistribution TContingency::p(const string &s) const
{ return operator[](s); }


PDistribution TContingency::p(const TValue &val) const
{ NOTSPEC(val);
  return (varType==TValue::INTVAR) ? p(int(val)) : p(float(val));
}


PDistribution TContingency::p(const float &f) const
{
  NEEDS(TValue::FLOATVAR);
  TDistributionMap::const_iterator i1;
  
  i1 = continuous->end();
  if (f > (*--i1).first)
    return CLONE(TDistribution, (*i1).second);
    
  i1=continuous->lower_bound(f);
  if (i1==continuous->end())
    if (continuous->size()==0)
      raiseError("empty contingency");
    else
      return CLONE(TDistribution, (*(--i1)).second);
  else if (((*i1).first == f) || (i1==continuous->begin()))
    return CLONE(TDistribution, (*i1).second);

  TDistributionMap::const_iterator i2 = i1;
  i1--;

  const float &x1 = (*i1).first;
  const float &x2 = (*i2).first;
  const PDistribution &y1 = (*i1).second;
  const PDistribution &y2 = (*i2).second;

  const float r = (x1==x2) ? 0.5 : (f-x1)/(x2-x1);

  // We want to compute y1*(1-r) + y2*r
  // We know that r!=0, so we can compute (y1*(1-r)/r + y2) * r
  TDistribution *res = CLONE(TDistribution, y1);
  PDistribution wres = res;
  *res *= (1-r)/r;
  *res += y2;
  *res *= r;

  return wres;
}


void TContingency::normalize()
{ if (varType==TValue::INTVAR)
    ITERATE(TDistributionVector, ci, *discrete)
      (*ci)->normalize();
  else if (varType==TValue::FLOATVAR)
    ITERATE(TDistributionMap, ci, *continuous)
      (*ci).second->normalize();
}




TContingencyClass::TContingencyClass(PVariable outer, PVariable inner)
: TContingency(outer, inner)
{}


float TContingencyClass::p_attr(const TValue &, const TValue &) const
{ raiseError("cannot compute p(value|class)"); 
  return 0.0;
}


float TContingencyClass::p_class(const TValue &, const TValue &) const
{ raiseError("cannot compute p(class|value)");
  return 0.0;
}

PDistribution TContingencyClass::p_attrs(const TValue &) const
{ raiseError("cannot compute p(.|class)"); 
  return PDistribution();
}


PDistribution TContingencyClass::p_classes(const TValue &) const
{ raiseError("cannot compute p(class|.)");
  return PDistribution();
}


void TContingencyClass::constructFromGenerator(PVariable outer, PVariable inner, PExampleGenerator gen, const long &weightID, const int &attrNo)
{
  outerVariable = outer;
  innerVariable = inner;

  outerDistribution = TDistribution::create(outerVariable);
  innerDistribution = TDistribution::create(innerVariable);
  innerDistributionUnknown = TDistribution::create(innerVariable);

  varType = outerVariable->varType;
  if (varType==TValue::INTVAR) {
    discrete = mlnew TDistributionVector();
    for(int i=0, e=outerVariable->noOfValues(); i!=e; i++)
      discrete->push_back(TDistribution::create(innerVariable));
  } 
  else {
   _ASSERT(varType==TValue::FLOATVAR);
    continuous = mlnew TDistributionMap();
  }

  if (attrNo == ILLEGAL_INT)
    add_gen(gen, weightID);
  else
    add_gen(gen, attrNo, weightID);
}




TContingencyClassAttr::TContingencyClassAttr(PVariable attrVar, PVariable classVar)
: TContingencyClass(classVar, attrVar)
{}


TContingencyClassAttr::TContingencyClassAttr(PExampleGenerator gen, const int &attrNo, const long &weightID)
{
  const TDomain &domain = gen->domain.getReference();

  if (!domain.classVar)
    raiseError("classless domain");
  if (attrNo>=int(domain.attributes->size()))
    raiseError("attribute index %i out of range", attrNo, domain.attributes->size()-1);

  PVariable attribute = domain.getVar(attrNo, false);
  if (!attribute)
    raiseError("attribute not found");

  constructFromGenerator(domain.classVar, attribute, gen, weightID, attrNo);
}    


TContingencyClassAttr::TContingencyClassAttr(PExampleGenerator gen, PVariable var, const long &weightID)
{ 
  if (!gen->domain->classVar)
    raiseError("classless domain");

  const int attrNo = gen->domain->getVarNum(var, false);
  constructFromGenerator(gen->domain->classVar, var, gen, weightID, attrNo);
}


PVariable TContingencyClassAttr::getClassVar()
{ return outerVariable; }


PVariable TContingencyClassAttr::getAttribute()
{ return innerVariable; }


void TContingencyClassAttr::add_gen(PExampleGenerator gen, const long &weightID)
{ checkProperty(innerVariable);
  int attrNo = gen->domain->getVarNum(innerVariable, false);
  if (attrNo != ILLEGAL_INT)
    PEITERATE(ei, gen)
      add((*ei).getClass(), (*ei)[attrNo], WEIGHT(*ei));
  else {
    if (!innerVariable->getValueFrom)
      raiseError("attribute '%s' is not in the domain and its 'getValueFrom' is not defined", innerVariable->get_name().c_str());

    TVariable &vfe = innerVariable.getReference();
    PEITERATE(ei, gen)
      add((*ei).getClass(), vfe.computeValue(*ei), WEIGHT(*ei));
  }
}


void TContingencyClassAttr::add_gen(PExampleGenerator gen, const int &attrNo, const long &weightID)
{ PEITERATE(ei, gen)
    add((*ei).getClass(), (*ei)[attrNo], WEIGHT(*ei));
}


void TContingencyClassAttr::add_attrclass(const TValue &varValue, const TValue &classValue, const float &p)
{ add(classValue, varValue, p); }


float TContingencyClassAttr::p_attr(const TValue &varValue, const TValue &classValue) const
{ return p(classValue)->p(varValue); }


PDistribution TContingencyClassAttr::p_attrs(const TValue &classValue) const
{ return p(classValue); }




TContingencyAttrClass::TContingencyAttrClass(PVariable attrVar, PVariable classVar)
: TContingencyClass(attrVar, classVar)
{}


TContingencyAttrClass::TContingencyAttrClass(PExampleGenerator gen, PVariable var, const long &weightID)
{ 
  if (!gen->domain->classVar)
    raiseError("classless domain");

  const int attrNo = gen->domain->getVarNum(var, false);
  constructFromGenerator(var, gen->domain->classVar, gen, weightID, attrNo);
}


TContingencyAttrClass::TContingencyAttrClass(PExampleGenerator gen, const int &attrNo, const long &weightID)
{
  const TDomain &domain = gen->domain.getReference();

  if (!domain.classVar)
    raiseError("classless domain");
  if (attrNo>=int(gen->domain->attributes->size()))
    raiseError("attribute index %i out of range", attrNo, gen->domain->attributes->size()-1);

  PVariable attribute = domain.getVar(attrNo);
  if (!attribute)
    raiseError("attribute not found");

  constructFromGenerator(attribute, domain.classVar, gen, weightID, attrNo);
}


PVariable TContingencyAttrClass::getClassVar()
{ return innerVariable; }


PVariable TContingencyAttrClass::getAttribute()
{ return outerVariable; }


void TContingencyAttrClass::add_gen(PExampleGenerator gen, const long &weightID)
{ int attrNo = gen->domain->getVarNum(outerVariable, false);
  if (attrNo != ILLEGAL_INT)
    PEITERATE(ei, gen)
      add((*ei)[attrNo], (*ei).getClass(), WEIGHT(*ei));
  else {
    if (!outerVariable->getValueFrom)
      raiseError("attribute '%s' is not in the domain and its value cannot be computed", outerVariable->get_name().c_str());

    TVariable &vfe = outerVariable.getReference();
    PEITERATE(ei, gen)
      add(vfe.computeValue(*ei), (*ei).getClass(), WEIGHT(*ei));
  }
}


void TContingencyAttrClass::add_gen(PExampleGenerator gen, const int &attrNo, const long &weightID)
{ PEITERATE(ei, gen)
    add((*ei)[attrNo], (*ei).getClass(), WEIGHT(*ei));
}


void TContingencyAttrClass::add_attrclass(const TValue &varValue, const TValue &classValue, const float &p)
{ add(varValue, classValue, p); }


float TContingencyAttrClass::p_class(const TValue &varValue, const TValue &classValue) const
{ try {
    return p(varValue)->p(classValue); 
  }
  catch (mlexception exc) {
    // !!! This is extremely ugly. Correct it by asking p not to raise exceptions!
    if (!strcmp(exc.what(), "TDistribution: index out of range."))
      return 0.0;
    else
      throw;
  }
}

PDistribution TContingencyAttrClass::p_classes(const TValue &varValue) const
{ return p(varValue); }




TContingencyAttrAttr::TContingencyAttrAttr(PVariable variable, PVariable innervar)
: TContingency(variable, innervar)
{}


TContingencyAttrAttr::TContingencyAttrAttr(PVariable variable, PVariable innervar, PExampleGenerator gen, const long weightID)
: TContingency(variable, innervar)
{ if (gen)
    operator()(gen, weightID);
}


TContingencyAttrAttr::TContingencyAttrAttr(const int &var, const int &innervar, PExampleGenerator gen, const long weightID)
 : TContingency(gen->domain->getVar(var), gen->domain->getVar(innervar))
{ operator()(gen, weightID); }


void TContingencyAttrAttr::operator()(PExampleGenerator gen, const long weightID)
{ int var=gen->domain->getVarNum(outerVariable, false);
  int invar=gen->domain->getVarNum(innerVariable, false);

  if (var == ILLEGAL_INT)
    if (invar == ILLEGAL_INT)
      PEITERATE(ei, gen) {
        TValue val = outerVariable->computeValue(*ei);
        add(val, innerVariable->computeValue(*ei), WEIGHT(*ei));
      }
    else // var == ILLEGAL_INT, invar is not
      PEITERATE(ei, gen) {
        TValue val = outerVariable->computeValue(*ei);
        add(val, (*ei)[invar], WEIGHT(*ei));
      }
  else 
    if (invar<0) // invar == ILLEGAL_INT, var is not
      PEITERATE(ei, gen)
        add((*ei)[var], innerVariable->computeValue(*ei), WEIGHT(*ei));
  else // both OK
      PEITERATE(ei, gen)
        add((*ei)[var], (*ei)[invar], WEIGHT(*ei));
}


float TContingencyAttrAttr::p_attr(const TValue &outerValue, const TValue &innerValue) const
{ return p(outerValue)->p(innerValue); }


PDistribution TContingencyAttrAttr::p_attrs(const TValue &outerValue) const
{ return p(outerValue); }


TDomainContingency::TDomainContingency(bool acout)
: classIsOuter(acout)
{}


// Extract TContingency values for all attributes, by iterating through all examples from the generator
TDomainContingency::TDomainContingency(PExampleGenerator gen, const long weightID, bool acout)
: classIsOuter(acout)
{ computeMatrix(gen, weightID); }


// Extract TContingency values for all attributes, by iterating through all examples from the generator
TDomainContingency::TDomainContingency(PExampleGenerator gen, const long weightID, const vector<bool> &attributes, bool acout)
: classIsOuter(acout)
{ computeMatrix(gen, weightID, &attributes); }


void TDomainContingency::computeMatrix(PExampleGenerator gen, const long &weightID, const vector<bool> *attributes, PDomain newDomain)
// IMPORTANT NOTE: When weightID and newDomain are specified, weights are computed from the original examples
// (this is to avoid the need to copy the meta-attributes)
{ PDomain myDomain = newDomain ? newDomain : gen->domain;
  PVariable classVar = myDomain->classVar;

  if (!classVar)
   raiseError("classless domain");

  classes = TDistribution::create(classVar);
  char classType = classVar->varType;

  // Prepare a TContingency for each attribute that has discrete or continuous values

  TValue lastClassValue;
  if (classVar->varType==TValue::INTVAR)
    lastClassValue = TValue(classVar->noOfValues()-1);

  vector<bool>::const_iterator ai, ae;
  if (attributes) {
    ai = attributes->begin();
    ae = attributes->end();
  }
  PITERATE(TVarList, vli, myDomain->attributes) {
    if (attributes) {
      if (ai == ae)
        break;

      if (!*ai++) {
        push_back(NULL);
        continue;
      }
    }
        
    if (classIsOuter)
      push_back(mlnew TContingencyClassAttr(*vli, myDomain->classVar));
    else
      push_back(mlnew TContingencyAttrClass(*vli, myDomain->classVar));

    // if variable and class types are discrete, it initializes distributions to full length
    //   (which will help the copy constructor with estimation below)
    if (((*vli)->varType==TValue::INTVAR) && (classType==TValue::INTVAR) && (lastClassValue.intV >= 0))
      for(int i=0, e=(*vli)->noOfValues(); i!=e; i++)
        back()->add_attrclass(TValue(i), lastClassValue, 0);
  }

  iterator si;
  int Na = myDomain->attributes->size();
  TExample newExample(myDomain);
  TExample::iterator vi, cli;

  PEITERATE(fi, gen) {
    if (newDomain) {
      newDomain->convert(newExample, *fi);
      vi=newExample.begin();
    }
    else
      vi=(*fi).begin();

    cli=vi+Na;
    float xmplWeight=WEIGHT(*fi);
    classes->add(*cli, xmplWeight);
    for(si=begin(); vi!=cli; vi++, si++)
      if (*si)
        (*si)->add_attrclass(*vi, *cli, xmplWeight);
  }
}


/*
TDomainContingency::TDomainContingency(const TDomainContingency &old, PProbabilityEstimator estimator)
: classIsOuter(old.classIsOuter)
{ 
  if (!estimator)
    classes = estimator->operator()(old.classes);
  else {
    classes = CLONE(TDistribution, old.classes);
    classes->normalize();
  }

  if (classIsOuter)
    const_ITERATE(TDomainContingency, di, old)
      push_back(mlnew TContingencyClassAttr(*di, estimator));
  else
    const_ITERATE(TDomainContingency, di, old)
      push_back(mlnew TContingencyAttrClass(*di, estimator));
}
*/


void TDomainContingency::normalize()
{ classes->normalize();
  this_ITERATE(ti) 
    (*ti)->normalize();
}


PDomainDistributions TDomainContingency::getDistributions()
{ PDomainDistributions ddist;
  if (classIsOuter)
    this_ITERATE(ti)
      ddist->push_back((*ti)->innerDistribution);
  else
    this_ITERATE(ti)
      ddist->push_back((*ti)->outerDistribution);
  return ddist;
}


TComputeDomainContingency::TComputeDomainContingency(bool acout)
: classIsOuter(acout)
{}


PDomainContingency TComputeDomainContingency::operator()(PExampleGenerator eg, const long &weightID)
{ return mlnew TDomainContingency(eg, weightID); }