Пример #1
0
def optimize_model(args):
    feature_fn, margin_fn, num_features, actions = select_feature_fn(args)
    print 'Found model: {}'.format(args.modelfile)
    if args.multi_slack:
        mm_model = MultiSlackMaxMarginModel.read(args.modelfile, actions, feature_fn, margin_fn)
    else:
        mm_model = MaxMarginModel.read(args.modelfile, actions, feature_fn, margin_fn)
    mm_model.C = args.C
    mm_model.optimize_model()
    mm_model.save_weights_to_file(args.weightfile)
Пример #2
0
def build_model(args):
    feature_fn, margin_fn, num_features, actions = select_feature_fn(args)
    print 'Building model into {}.'.format(args.modelfile)
    if args.multi_slack:
        mm_model = MultiSlackMaxMarginModel(actions, args.C, num_features, feature_fn, margin_fn)
    else:
        mm_model = MaxMarginModel(actions, args.C, num_features, feature_fn, margin_fn)
    mm_model.load_constraints_from_file(args.constraintfile)
    mm_model.save_model(args.modelfile)
Пример #3
0
def build_model(args):
    feature_fn, margin_fn, num_features, actions = select_feature_fn(args)
    print 'Building model into {}.'.format(args.modelfile)
    if args.model == 'multi':
        mm_model = MultiSlackMaxMarginModel(actions, args.C, num_features, feature_fn, margin_fn)
    elif args.model == 'bellman':
        mm_model = BellmanMaxMarginModel(actions, args.C, args.D, args.F, 1, num_features, feature_fn, margin_fn) # changed
    else:
        mm_model = MaxMarginModel(actions, args.C, num_features, feature_fn, margin_fn)
    if not args.goal_constraints and args.model == 'bellman':
        demofile = h5py.File(args.demofile, 'r')
        ignore_keys = [k for k in demofile if demofile[k]['knot'][()]]
        demofile.close()
    else:
        ignore_keys = None
    mm_model.load_constraints_from_file(args.constraintfile, ignore_keys)
    mm_model.save_model(args.modelfile)
Пример #4
0
def optimize_model(args):
    feature_fn, margin_fn, num_features, actions = select_feature_fn(args)
    print 'Found model: {}'.format(args.modelfile)
    if args.model == 'multi':
        mm_model = MultiSlackMaxMarginModel.read(args.modelfile, actions, num_features, feature_fn, margin_fn)
    elif args.model == 'bellman':
        mm_model = BellmanMaxMarginModel.read(args.modelfile, actions, num_features, feature_fn, margin_fn)
        mm_model.D = args.D
        mm_model.F = args.F
    else:
        mm_model = MaxMarginModel.read(args.modelfile, actions, num_features, feature_fn, margin_fn)
    if args.save_memory:
        mm_model.model.setParam('threads', 1)  # Use single thread instead of maximum
        # barrier method (#2) is default for QP, but uses more memory and could lead to error
        mm_model.model.setParam('method', 1)  # Use dual simplex method to solve model
        #mm_model.model.setParam('method', 0)  # Use primal simplex method to solve model
    mm_model.C = args.C
    mm_model.optimize_model()
    mm_model.save_weights_to_file(args.weightfile)
Пример #5
0
def build_constraints(args):
    #test_features(args, "sc")
    test_features(args, "rope_dist")
    feature_fn, margin_fn, num_features, actions = select_feature_fn(args)
    print 'Building constraints into {}.'.format(args.constraintfile)
    if args.model == 'multi':
        mm_model = MultiSlackMaxMarginModel(actions, args.C, num_features, feature_fn, margin_fn)
    elif args.model == 'bellman':
        mm_model = BellmanMaxMarginModel(actions, args.C, args.D, args.F, .9, num_features, feature_fn, margin_fn)
    else:
        mm_model = MaxMarginModel(actions, args.C, num_features, feature_fn, margin_fn)
    if args.model == 'bellman':
        add_bellman_constraints_from_demo(mm_model,
                                          args.demofile,
                                          args.start, args.end,
                                          outfile=args.constraintfile,
                                          verbose=True)
    else:
        add_constraints_from_demo(mm_model,
                                  args.demofile,
                                  args.start, args.end,
                                  outfile=args.constraintfile,
                                  verbose=True)