code: def ap_categorical_sampler(
      obs, prior_weight, p, size=(), rng=None, LF=DEFAULT_LF
  ):
      weights = scope.linear_forgetting_weights(scope.len(obs), LF=LF)
      # in order to support pchoice here, we need to find the size of p,
      # but p can have p.ndim == 2, so we pass p to bincount and unpack it
      # (if required) there
      counts = scope.bincount(obs, p=p, weights=weights)
      pseudocounts = scope.tpe_cat_pseudocounts(
          counts, prior_weight, p, size
      )
      return scope.categorical(pseudocounts, size=size, rng=rng)
  
imports: import logging
  import time
  import numpy
  from scipy.special import erf
  from .None import pyll
  from .pyll import scope
  from .pyll.stochastic import implicit_stochastic
  from .base import miscs_to_idxs_vals
  from .base import miscs_update_idxs_vals
  from .None import rand
label_desc: Use image node_id 26 for calling a global function with example usage: ap_categorical_sampler(obs, prior_weight, p, size, rng, LF) and returns: scope