#!/usr/bin/perl 

use POSIX qw /floor/;

# Usage: gen_samples STEPS
#
# if uc(STEPS) eq INF, then the increment in training set size is 1,
# otherwise, it is set so that at most STEPS rounds are needed to 
# reach the validation set size.

$rounds = $ARGV[0];

open IN, "labeled";
@labeled = <IN>;

if(uc($rounds) eq "INF" || $rounds > $#labeled) {
  $rounds = $#labeled+1;
  $increment = 1;
} else {
  $increment = floor(($#labeled+1) / $rounds);
}

for($i=0,$end=0; $i < $rounds; $i++) {
  open OUTPUT, '>', "labeled_" . ($i+1);
  $beg = $end+1;
  if($i < $rounds - (($#labeled+1) % $rounds)) {
    $end = $end + $increment;
  } else { $end = $end + $increment + 1; }
  print OUTPUT @labeled[$beg..$end];
  close OUTPUT;
}
