Пример #1
0
    def objwrapper(spsample):
        conf = defaults.copy()
        conf.update(spsample)
        logging.critical(tabulate([conf], headers='keys', floatfmt='.2e'))
        f1, f1std = xvalidate(dset, conf, emb)
        loss = 1-f1
        logging.critical('f1:{:.2f} f1std:{:.2f}\n'.format(f1,f1std))

        return {'loss': loss, 'status': STATUS_OK}
Пример #2
0
def c_opt(dset, emb, dargs):
    logging.critical(tabulate([dargs],headers='keys'))
    f1s = []
    for C in C_values:
        targs = dargs.copy()
        targs['C'] = C
        f1, f1std = cwi.xvalidate(dset, targs, emb)
        f1s.append((f1,f1std,C))
        logging.critical('{}\t{}\t{}'.format(C, f1,f1std))
    logging.critical('\n')
    return max(f1s)
Пример #3
0
def main(args):
    logging.critical(tabulate([args], headers='keys', floatfmt='.2f')+'\n')
    random.seed(0)
    defaults = {'embs': args['embs'], 'n_fold' : 5, 'e_context' : args['e_context'],
            'feats' : args['feats'], 'percentile' : 20, 'unkt' : 2,
            'clf' : 'svm', 'kerntype' : 'rbf', 'kerngamma' : 1, 'kerncoef0' : 1, 'kerndegree' : 2, 'cweights' : 1}

    
    assert hasattr(hp,'loguniform')
    space = {
            # 'kerngamma' : hp.loguniform('kerngamma', -20, 8),
            'kerngamma' : getattr(hp, args['kerngamma'][0])('kerngamma', *map(int, args['kerngamma'][1:])),
            'C' : getattr(hp,args['C'][0])('C', *map(int, args['C'][1:])),
            'percentile' : getattr(hp,args['percentile'][0])('percentile', *map(int, args['percentile'][1:])),
            # 'percentile' : hp.quniform('percentile', 5, 30,1),
            # 'percentile' : getattr(hp,args['percentile'][0])('percentile',args['percentile'][1], args['percentile'][2]),
            # 'C' : hp.loguniform('C', -20, 8),
            # 'C' : hp.lognormal('C', -4, 1),
            # 'percentile' : hp.normal('percentile', 20, 5),
            # 'kerngamma' : hp.uniform('kerngamma', .00001, .1),
    }

    from cwi import xvalidate, Emb
    import utils
    dset = utils.get_dset(args['data'])
    emb = Emb(dset)


    def objwrapper(spsample):
        conf = defaults.copy()
        conf.update(spsample)
        logging.critical(tabulate([conf], headers='keys', floatfmt='.2e'))
        f1, f1std = xvalidate(dset, conf, emb)
        loss = 1-f1
        logging.critical('f1:{:.2f} f1std:{:.2f}\n'.format(f1,f1std))

        return {'loss': loss, 'status': STATUS_OK}


    best = fmin(objwrapper,
            space=space,
            algo=tpe.suggest,
            max_evals=args['evals']
            )
    logging.critical(best)
    defaults.update(best)
    f1, f1std = xvalidate(dset, defaults, emb)
    logging.critical('f1:{:.2f} f1std:{:.2f}\n'.format(f1,f1std))