예제 #1
0
def parseArgs(args):
  from optparse import make_option
  option = make_option('--test',action='store',dest='numTest',type='int',default=None,help='num test instances')
  options,_ = parseTrainArgs(args,parserOptions=[option])
  
  assert(options.numTest is not None),'numTest unspecified'
  options.testBase = options.base % options.numTest
  if not(baseExists(options.testBase)):
    print >>sys.stderr,'Dir for numTest doesn\'t exist at:',options.testBase
    sys.exit(2)
  return options
예제 #2
0
def parseArgs(args):
    from optparse import make_option
    option = make_option('--test',
                         action='store',
                         dest='numTest',
                         type='int',
                         default=None,
                         help='num test instances')
    options, _ = parseTrainArgs(args, parserOptions=[option])

    assert (options.numTest is not None), 'numTest unspecified'
    options.testBase = options.base % options.numTest
    if not (baseExists(options.testBase)):
        print >> sys.stderr, 'Dir for numTest doesn\'t exist at:', options.testBase
        sys.exit(2)
    return options
예제 #3
0
def parseArgs(args,
              parserOptions=[],
              numAdditionalArgs=0,
              additionalArgsString=''):
    from optparse import OptionParser
    parser = OptionParser('%prog [options] classifier student ' +
                          additionalArgsString)
    parser.add_option('-b',
                      '--baseLearner',
                      action='store',
                      dest='baseLearner',
                      type='str',
                      default=None,
                      help='use the classifier as the base learner')
    parser.add_option('-f',
                      '--fallbackLearner',
                      action='store',
                      dest='fallbackLearner',
                      type='str',
                      default=None,
                      help='use the classifier file as the fallback learner')
    #parser.add_option('--student',action='store',dest='student',type='str',default=None)
    parser.add_option('-s',
                      '--source',
                      action='store',
                      dest='numSource',
                      type='int',
                      default=None,
                      help='num source instances')
    parser.add_option('-t',
                      '--target',
                      action='store',
                      dest='numTarget',
                      type='int',
                      default=None,
                      help='num target instances')
    parser.add_option('--no-source',
                      action='store_false',
                      dest='useSource',
                      default=True,
                      help='don\'t use the source data, but use the name')
    parser.add_option(
        '--debug',
        action='store_true',
        dest='debug',
        default=False,
        help='print the cmd and don\'t remove the combined config')
    parser.add_option('--fracSourceData',
                      action='store',
                      dest='fracSourceData',
                      default=None,
                      help='frac of source data to use')
    parser.add_option('--partialMax',
                      action='store',
                      dest='partialMax',
                      type='int',
                      default=None,
                      help='num partial runs')
    parser.add_option('--no-save',
                      action='store_false',
                      dest='save',
                      default=True,
                      help='disable saving of the classifier')
    parser.add_option('--catchOutput',
                      action='store_true',
                      dest='catchOutput',
                      default=False,
                      help='catch the output of the training')
    parser.add_option('--ignorePartialMax',
                      action='store_true',
                      dest='ignorePartialMax',
                      default=False,
                      help='ignore partialmax')
    for option in parserOptions:
        parser.add_option(option)
    options, args = parser.parse_args(args)

    numExpectedArgs = 2
    if len(args) != numExpectedArgs + numAdditionalArgs:
        print >> sys.stderr, 'Incorrect number of arguments expected %i but got %i' % (
            numExpectedArgs, len(args))
        parser.parse_args(['--help'])
        sys.exit(1)

    classifierType, student = args[:numExpectedArgs]
    # num training should be an int, and the filename should exist
    options.base = 'studentsNew29-unperturbed-%i'
    assert (options.numTarget is not None), 'numTarget unspecified'
    options.targetBase = options.base % options.numTarget
    if not (baseExists(options.targetBase)):
        print >> sys.stderr, 'Dir for numTarget doesn\'t exist at:', options.targetBase
        sys.exit(2)
    assert (options.numSource is not None), 'numSource unspecified'
    if options.numSource != 0:
        options.sourceBase = options.base % options.numSource
        if not (baseExists(options.sourceBase)):
            print >> sys.stderr, 'Dir for numSource doesn\'t exist at:', options.sourceBase
            sys.exit(2)
    # get students and check provided student
    students = getUniqueStudents()
    try:
        ind = int(student)
        if (options.partialMax is not None) and not options.ignorePartialMax:
            options.partialInd = ind % options.partialMax
            ind /= options.partialMax
            print 'ind: %i partialInd: %i' % (ind, options.partialInd)
        student = students[ind]
    except:
        if student not in students:
            print >> sys.stderr, 'Unknown student:', student
            sys.exit(2)
    options.student = student
    options.studentInd = students.index(student)
    options.otherStudents = list(students)
    options.otherStudents.remove(student)
    # check provided classifiers
    options.classifier = getClassifier(classifierType)
    if (options.classifier[1] == True) and (options.baseLearner is None):
        print >> sys.stderr, 'Missing base learner:', classifierType
        sys.exit(1)
    if (options.classifier[2] == True) and (options.fallbackLearner is None):
        print >> sys.stderr, 'Missing fallback learner:', classifierType
        sys.exit(1)
    if options.baseLearner is not None:
        temp = getClassifier(options.baseLearner)
        assert ((not temp[1]) and (not temp[2]))
    if options.fallbackLearner is not None:
        temp = getClassifier(options.fallbackLearner)
        assert ((not temp[1]) and (not temp[2]))
    # get name
    name = options.classifier[0]
    if name == 'trbagg-partialLoad':
        name = 'trbagg'
    if name == 'twostagetradaboost-partial':
        name = 'twostagetradaboost'
    if options.baseLearner is not None:
        name += '_base' + options.baseLearner
    if options.fallbackLearner is not None:
        name += '_fb' + options.fallbackLearner
    options.name = name
    options.saveName = name + '-target%i-source%i' % (options.numTarget,
                                                      options.numSource)

    # get the arguments
    options.saveConfigFilename = getConfigFilename('saved/' +
                                                   options.saveName + '-' +
                                                   student)
    options.saveFile = getSaveFilename(options)

    return options, args[numExpectedArgs:]
예제 #4
0
def parseArgs(args, parserOptions=[], numAdditionalArgs=0, additionalArgsString=""):
    from optparse import OptionParser

    parser = OptionParser("%prog [options] classifier student " + additionalArgsString)
    parser.add_option(
        "-b",
        "--baseLearner",
        action="store",
        dest="baseLearner",
        type="str",
        default=None,
        help="use the classifier as the base learner",
    )
    parser.add_option(
        "-f",
        "--fallbackLearner",
        action="store",
        dest="fallbackLearner",
        type="str",
        default=None,
        help="use the classifier file as the fallback learner",
    )
    # parser.add_option('--student',action='store',dest='student',type='str',default=None)
    parser.add_option(
        "-s", "--source", action="store", dest="numSource", type="int", default=None, help="num source instances"
    )
    parser.add_option(
        "-t", "--target", action="store", dest="numTarget", type="int", default=None, help="num target instances"
    )
    parser.add_option(
        "--no-source",
        action="store_false",
        dest="useSource",
        default=True,
        help="don't use the source data, but use the name",
    )
    parser.add_option(
        "--debug",
        action="store_true",
        dest="debug",
        default=False,
        help="print the cmd and don't remove the combined config",
    )
    parser.add_option(
        "--fracSourceData", action="store", dest="fracSourceData", default=None, help="frac of source data to use"
    )
    parser.add_option(
        "--partialMax", action="store", dest="partialMax", type="int", default=None, help="num partial runs"
    )
    parser.add_option(
        "--no-save", action="store_false", dest="save", default=True, help="disable saving of the classifier"
    )
    parser.add_option(
        "--catchOutput", action="store_true", dest="catchOutput", default=False, help="catch the output of the training"
    )
    parser.add_option(
        "--ignorePartialMax", action="store_true", dest="ignorePartialMax", default=False, help="ignore partialmax"
    )
    for option in parserOptions:
        parser.add_option(option)
    options, args = parser.parse_args(args)

    numExpectedArgs = 2
    if len(args) != numExpectedArgs + numAdditionalArgs:
        print >> sys.stderr, "Incorrect number of arguments expected %i but got %i" % (numExpectedArgs, len(args))
        parser.parse_args(["--help"])
        sys.exit(1)

    classifierType, student = args[:numExpectedArgs]
    # num training should be an int, and the filename should exist
    options.base = "studentsNew29-unperturbed-%i"
    assert options.numTarget is not None, "numTarget unspecified"
    options.targetBase = options.base % options.numTarget
    if not (baseExists(options.targetBase)):
        print >> sys.stderr, "Dir for numTarget doesn't exist at:", options.targetBase
        sys.exit(2)
    assert options.numSource is not None, "numSource unspecified"
    if options.numSource != 0:
        options.sourceBase = options.base % options.numSource
        if not (baseExists(options.sourceBase)):
            print >> sys.stderr, "Dir for numSource doesn't exist at:", options.sourceBase
            sys.exit(2)
    # get students and check provided student
    students = getUniqueStudents()
    try:
        ind = int(student)
        if (options.partialMax is not None) and not options.ignorePartialMax:
            options.partialInd = ind % options.partialMax
            ind /= options.partialMax
            print "ind: %i partialInd: %i" % (ind, options.partialInd)
        student = students[ind]
    except:
        if student not in students:
            print >> sys.stderr, "Unknown student:", student
            sys.exit(2)
    options.student = student
    options.studentInd = students.index(student)
    options.otherStudents = list(students)
    options.otherStudents.remove(student)
    # check provided classifiers
    options.classifier = getClassifier(classifierType)
    if (options.classifier[1] == True) and (options.baseLearner is None):
        print >> sys.stderr, "Missing base learner:", classifierType
        sys.exit(1)
    if (options.classifier[2] == True) and (options.fallbackLearner is None):
        print >> sys.stderr, "Missing fallback learner:", classifierType
        sys.exit(1)
    if options.baseLearner is not None:
        temp = getClassifier(options.baseLearner)
        assert (not temp[1]) and (not temp[2])
    if options.fallbackLearner is not None:
        temp = getClassifier(options.fallbackLearner)
        assert (not temp[1]) and (not temp[2])
    # get name
    name = options.classifier[0]
    if name == "trbagg-partialLoad":
        name = "trbagg"
    if name == "twostagetradaboost-partial":
        name = "twostagetradaboost"
    if options.baseLearner is not None:
        name += "_base" + options.baseLearner
    if options.fallbackLearner is not None:
        name += "_fb" + options.fallbackLearner
    options.name = name
    options.saveName = name + "-target%i-source%i" % (options.numTarget, options.numSource)

    # get the arguments
    options.saveConfigFilename = getConfigFilename("saved/" + options.saveName + "-" + student)
    options.saveFile = getSaveFilename(options)

    return options, args[numExpectedArgs:]