Example #1
0
def main(args=sys.argv[1:]):
    if '--suffix' in args:
        ind = args.index('--suffix')
        suffix = args[ind + 1]
        del args[ind]
        del args[ind]
    else:
        suffix = ''

    if '--monitor' in args:
        args.remove('--monitor')
        return monitorCondor(args, suffix)

    optionsNoSuffix, _ = parseArgs(addArgs(args))

    args = addArgs(args, suffix)
    options, _ = parseArgs(args)

    if os.path.exists(options.saveFile):
        return

    if not (os.path.exists(addSuffix(options.saveFile))) and os.path.exists(
            addSuffix(optionsNoSuffix.saveFile)):
        import shutil
        shutil.copy(addSuffix(optionsNoSuffix.saveFile),
                    addSuffix(options.saveFile))

    def repl(x):
        numStudentsToAdd = 1
        filename = ''
        saveFile = addSuffix(options.saveFile)
        if os.path.exists(saveFile):
            filename = options.saveFile

        x = x.replace(
            '$(EVAL_PATH)',
            'data/dt/studentsNew29-unperturbed-%i/weighted/only-$(EVAL_STUDENT).weka'
            % options.numSource)
        x = x.replace(
            '$(SOURCE_DATA_PATH)',
            'data/dt/studentsNew29-unperturbed-%i/train/$(DATA_STUDENT).arff' %
            options.numSource)
        x = x.replace('$(TARGET_STUDENT)', options.student)
        x = x.replace('$(NUM_STUDENTS_TO_ADD)', str(numStudentsToAdd))
        x = x.replace('$(FILENAME)', filename)
        return x

    trainClassifierMain(options, repl)
def main(args=sys.argv[1:]):
    args = ['twostagetradaboost-partial'] + args
    combine = False
    if '--combine' in args:
        args.remove('--combine')
        combine = True
        args = args + ['--ignorePartialMax']

    options, _ = parseArgs(args)
    directory = os.path.join('configs/learners/saved/twostage-partial',
                             options.baseLearner, options.student)
    pathBase = os.path.join(directory, '%i.txt')
    if combine:
        print options.student, options.partialMax
        bestT = None
        bestError = numpy.inf
        for t in range(options.partialMax):
            path = pathBase % t
            with open(path, 'r') as f:
                error = float(f.read().strip())
            if error < bestError:
                bestError = error
                bestT = t
        options.partialInd = bestT
        print 'bestT:', bestT
        print 'bestError:', bestError
        trainClassifierMain(options)
    else:
        args = args + ['--no-save', '--catchOutput']
        options, _ = parseArgs(args)
        output, error = trainClassifierMain(options)
        res = re.findall('BEST T: (\d+)\nBEST ERROR: ([.0-9]+)', output)
        bestT = int(res[0][0])
        bestError = float(res[0][1])

        try:
            os.makedirs(directory)
        except:
            pass
        filename = pathBase % bestT
        with open(filename, 'w') as f:
            f.write('%f\n' % bestError)
def main(args=sys.argv[1:]):
  args = ['twostagetradaboost-partial'] + args
  combine = False
  if '--combine' in args:
    args.remove('--combine')
    combine = True
    args = args + ['--ignorePartialMax']

  options,_ = parseArgs(args)
  directory = os.path.join('configs/learners/saved/twostage-partial',options.baseLearner,options.student)
  pathBase = os.path.join(directory,'%i.txt')
  if combine:
    print options.student,options.partialMax
    bestT = None
    bestError = numpy.inf
    for t in range(options.partialMax):
      path = pathBase % t
      with open(path,'r') as f:
        error = float(f.read().strip())
      if error < bestError:
        bestError = error
        bestT = t
    options.partialInd = bestT
    print 'bestT:',bestT
    print 'bestError:',bestError
    trainClassifierMain(options)
  else:
    args = args + ['--no-save','--catchOutput']
    options,_ = parseArgs(args)
    output,error = trainClassifierMain(options)
    res = re.findall('BEST T: (\d+)\nBEST ERROR: ([.0-9]+)',output)
    bestT = int(res[0][0])
    bestError = float(res[0][1])
    
    try:
      os.makedirs(directory)
    except:
      pass
    filename = pathBase % bestT
    with open(filename,'w') as f:
      f.write('%f\n'%bestError)
def main(args=sys.argv[1:]):
  if '--suffix' in args:
    ind = args.index('--suffix')
    suffix = args[ind+1]
    del args[ind]
    del args[ind]
  else:
    suffix = ''

  if '--monitor' in args:
    args.remove('--monitor')
    return monitorCondor(args,suffix)

  optionsNoSuffix,_ = parseArgs(addArgs(args))

  args = addArgs(args,suffix)
  options,_ = parseArgs(args)

  if os.path.exists(options.saveFile):
    return

  if not(os.path.exists(addSuffix(options.saveFile))) and os.path.exists(addSuffix(optionsNoSuffix.saveFile)):
    import shutil
    shutil.copy(addSuffix(optionsNoSuffix.saveFile),addSuffix(options.saveFile))

  def repl(x):
    numStudentsToAdd = 1
    filename = ''
    saveFile = addSuffix(options.saveFile)
    if os.path.exists(saveFile):
      filename = options.saveFile

    x = x.replace('$(EVAL_PATH)','data/dt/studentsNew29-unperturbed-%i/weighted/only-$(EVAL_STUDENT).weka' % options.numSource)
    x = x.replace('$(SOURCE_DATA_PATH)','data/dt/studentsNew29-unperturbed-%i/train/$(DATA_STUDENT).arff' % options.numSource)
    x = x.replace('$(TARGET_STUDENT)',options.student)
    x = x.replace('$(NUM_STUDENTS_TO_ADD)',str(numStudentsToAdd))
    x = x.replace('$(FILENAME)',filename)
    return x

  trainClassifierMain(options,repl)