def __init__(self, N, K, D, M=0, single_subspace=True, link="log", bin_size=1.0, **kwargs): super(_PoissonEmissionsMixin, self).__init__(N, K, D, M, single_subspace=single_subspace, **kwargs) self.link_name = link self.bin_size = bin_size mean_functions = dict(log=lambda x: np.exp(x) * self.bin_size, softplus=lambda x: softplus(x) * self.bin_size) self.mean = mean_functions[link] link_functions = dict( log=lambda rate: np.log(rate) - np.log(self.bin_size), softplus=lambda rate: inv_softplus(rate / self.bin_size)) self.link = link_functions[link] # Set the bias to be small if using log link if link == "log": self.ds = -3 + .5 * npr.randn( 1, N) if single_subspace else npr.randn(K, N)
def __init__(self, K, D, M, link="softplus", bin_size=1.0, **kwargs): super(PoissonTransitions, self).__init__(K, D, M) # uniform transitions Ps = np.ones((K, K)) Ps /= Ps.sum(axis=1, keepdims=True) self.log_Ps = np.log(Ps) self.link_name = link self.bin_size = bin_size mean_functions = dict(log=lambda x: np.exp(x) * self.bin_size, softplus=lambda x: softplus(x) * self.bin_size) self.mean = mean_functions[link] link_functions = dict( log=lambda rate: np.log(rate) - np.log(self.bin_size), softplus=lambda rate: inv_softplus(rate / self.bin_size)) self.link = link_functions[link] # parameters are a vector of weights # no other transition parameters self.Ws = npr.randn(M)
def _softplus_mean(self, x): return softplus(x) * self.bin_size