code: 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
      )
  
imports: from __future__ import print_function
  from __future__ import absolute_import
  from __future__ import division
  from builtins import str
  from builtins import map
  from builtins import zip
  from builtins import range
  from past.utils import old_div
  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 25 for calling a global function with example usage: ap_categorical_sampler(obs, prior_weight, p, upper, size, rng, LF) and returns: scope