Commits

Aleš Erjavec committed 38b3572

Fixed TMakeRandomIndicesMultiple.

Comments (0)

Files changed (2)

source/orange/trindex.cpp

   if (stratified==TMakeRandomIndices::NOT_STRATIFIED)
      return operator()(gen->numberOfExamples(), ap0);
 
+  if (!gen->domain->classVar)
+     if (stratified==TMakeRandomIndices::STRATIFIED_IF_POSSIBLE)
+       return operator()(gen->numberOfExamples(), ap0);
+     else
+       raiseError("invalid example generator or class-less domain");
+
+   if (gen->domain->classVar->varType!=TValue::INTVAR)
+     if (stratified==TMakeRandomIndices::STRATIFIED_IF_POSSIBLE)
+       return operator()(gen->numberOfExamples(), ap0);
+     else
+       raiseError("cannot prepare stratified indices (non-discrete class values)");
+
   if (!randomGenerator && (randseed<0))
     raiseCompatibilityWarning("object always returns the same indices unless either 'randomGenerator' or 'randseed' is set");
 
     else
       byclasses[(*ei).getClass().intV].push_back(nexamples++);
 
-  int no= (p0<=1.0) ? int(p0*nexamples+0.5) : int(p0+0.5);
+  int no= (ap0 <= 1.0) ? int(ap0 * nexamples + 0.5) : int(ap0 + 0.5);
   rsrgen rg(randomGenerator, randseed);
 
   PRandomIndices indices(mlnew TFoldIndices());

source/orange/trindex.hpp

 public:
   __REGISTER_CLASS
 
-  float p0; // proportion/number of examples
+  float p0; //P proportion/number of examples
 
   TMakeRandomIndicesMultiple(const float &p0=1.0, const int &stratified=TMakeRandomIndices::STRATIFIED_IF_POSSIBLE, const int &randseed=-1);
   TMakeRandomIndicesMultiple(const float &p0, const int &stratified, PRandomGenerator);