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)
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)
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)
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)
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)
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)