5
5
from pybasicbayes .abstractions import Model , ModelGibbsSampling , \
6
6
ModelEM , ModelMeanField , ModelMeanFieldSVI
7
7
8
- from pybasicbayes .distributions import DiagonalRegression
9
-
8
+ from pybasicbayes .distributions import DiagonalRegression , Gaussian , Regression
9
+ from pylds . distributions import PoissonRegression
10
10
from pylds .states import LDSStates , LDSStatesZeroInflatedCountData , LaplaceApproxPoissonLDSStates
11
+ from pylds .util import random_rotation
11
12
12
- # TODO make separate versions for stationary, nonstationary,
13
- # nonstationary-and-distinct-for-each-sequence
14
-
15
- # NOTE: dynamics_distn should probably be an instance of AutoRegression,
16
- # emission_distn should probably be an instance of Regression, and
13
+ # NOTE: dynamics_distn should be an instance of Regression,
14
+ # emission_distn should be an instance of Regression, and
17
15
# init_dynamics_distn should probably be an instance of Gaussian
18
16
19
- ######################
20
- # algorithm mixins #
21
- ######################
22
-
23
17
class _LDSBase (Model ):
24
18
25
19
_states_class = LDSStates
@@ -381,7 +375,7 @@ def sigma_init(self, sigma_init):
381
375
class ZeroInflatedCountLDS (_LDSGibbsSampling , _LDSBase ):
382
376
_states_class = LDSStatesZeroInflatedCountData
383
377
384
- def __init__ (self , * args , rho = 1.0 , ** kwargs ):
378
+ def __init__ (self , rho , * args , ** kwargs ):
385
379
"""
386
380
:param rho: Probability of count drawn from model
387
381
With pr 1-rho, the emission is deterministically zero
@@ -401,7 +395,6 @@ def _generate_obs(self,s, inputs):
401
395
x = np .hstack ((s .gaussian_states , inputs )), return_xy = False )
402
396
403
397
# Zero out data
404
- from scipy .sparse import csr_matrix
405
398
zeros = np .random .rand (s .T , self .D_obs ) > self .rho
406
399
data [zeros ] = 0
407
400
s .data = csr_matrix (data )
@@ -509,25 +502,6 @@ def expected_log_likelihood(self):
509
502
##############################
510
503
511
504
# TODO make data-dependent default constructors
512
-
513
- from pybasicbayes .distributions import Regression
514
-
515
-
516
- def random_rotation (n , theta = None ):
517
- if theta is None :
518
- # Sample a random, slow rotation
519
- theta = 0.5 * np .pi * np .random .rand ()
520
-
521
- if n == 1 :
522
- return np .random .rand () * np .eye (1 )
523
-
524
- rot = np .array ([[np .cos (theta ), - np .sin (theta )],
525
- [np .sin (theta ), np .cos (theta )]])
526
- out = np .zeros ((n , n ))
527
- out [:2 , :2 ] = rot
528
- q = np .linalg .qr (np .random .randn (n , n ))[0 ]
529
- return q .dot (out ).dot (q .T )
530
-
531
505
def DefaultLDS (D_obs , D_latent , D_input = 0 ,
532
506
mu_init = None , sigma_init = None ,
533
507
A = None , B = None , sigma_states = None ,
@@ -561,10 +535,6 @@ def DefaultLDS(D_obs, D_latent, D_input=0,
561
535
562
536
return model
563
537
564
-
565
- from pybasicbayes .distributions import Gaussian
566
- from pylds .distributions import PoissonRegression
567
-
568
538
def DefaultPoissonLDS (D_obs , D_latent , D_input = 0 ,
569
539
mu_init = None , sigma_init = None ,
570
540
A = None , B = None , sigma_states = None ,
0 commit comments