示例#1
0
def ap_categorical_sampler(obs, prior_weight, upper,
        size=(), rng=None, LF=DEFAULT_LF):
    weights = scope.linear_forgetting_weights(scope.len(obs), LF=LF)
    counts = scope.bincount(obs, minlength=upper, weights=weights)
    # -- add in some prior pseudocounts
    pseudocounts = counts + prior_weight
    return scope.categorical(pseudocounts / scope.sum(pseudocounts),
            upper=upper, size=size, rng=rng)
示例#2
0
def hp_pchoice(label, p_options):
    """
    label: string
    p_options: list of (probability, option) pairs
    """
    p, options = zip(*p_options)
    n_options = len(options)
    ch = scope.hyperopt_param(label, scope.categorical(p, upper=n_options))
    return scope.switch(ch, *options)
示例#3
0
def hp_pchoice(label, p_options):
    """
    label: string
    p_options: list of (probability, option) pairs
    """
    p, options = zip(*p_options)
    n_options = len(options)
    ch = scope.hyperopt_param(label, scope.categorical(p, upper=n_options))
    return scope.switch(ch, *options)
示例#4
0
def hp_pchoice(label, p_options):
    """
    label: string
    p_options: list of (probability, option) pairs
    """
    if not isinstance(label, basestring):
        raise TypeError("require string label")
    p, options = zip(*p_options)
    n_options = len(options)
    ch = scope.hyperopt_param(label, scope.categorical(p, upper=n_options))
    return scope.switch(ch, *options)
示例#5
0
def hp_pchoice(label, p_options):
    """
    label: string
    p_options: list of (probability, option) pairs
    """
    if not isinstance(label, basestring):
        raise TypeError('require string label')
    p, options = zip(*p_options)
    n_options = len(options)
    ch = scope.hyperopt_param(label, scope.categorical(p, upper=n_options))
    return scope.switch(ch, *options)
示例#6
0
def ap_categorical_sampler(obs,
                           prior_weight,
                           p,
                           upper=None,
                           size=(),
                           rng=None,
                           LF=DEFAULT_LF):
    weights = scope.linear_forgetting_weights(scope.len(obs), LF=LF)
    counts = scope.bincount(obs, minlength=upper, weights=weights)
    pseudocounts = scope.tpe_cat_pseudocounts(counts, upper, prior_weight, p,
                                              size)
    return scope.categorical(pseudocounts, upper=upper, size=size, rng=rng)
示例#7
0
文件: tpe.py 项目: gabekron/hyperopt
def ap_categorical_sampler(obs, prior_weight, p, upper=None,
        size=(), rng=None, LF=DEFAULT_LF):
    weights = scope.linear_forgetting_weights(scope.len(obs), LF=LF)
    counts = scope.bincount(obs, minlength=upper, weights=weights)
    pseudocounts = scope.tpe_cat_pseudocounts(counts, upper, prior_weight, p, size)
    return scope.categorical(pseudocounts, upper=upper, size=size, rng=rng)
示例#8
0
def ap_categorical_sampler(obs, prior_weight, upper, size=(), rng=None):
    counts = scope.bincount(obs, minlength=upper)
    # -- add in some prior pseudocounts
    pseudocounts = counts + prior_weight
    return scope.categorical(pseudocounts / scope.sum(pseudocounts),
            size=size, rng=rng)