File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ """Utilities module"""
2+
13from . import testing
24from . import data_structures
35from . import distance_metrics
46from . import kernels
57from . import windows
68from . import graphs
9+ from . import misc
Original file line number Diff line number Diff line change 1+ """Miscellaneous utility functions"""
2+ import numpy as np
3+
4+
5+ def logsumexp (log_probs , axis = None ):
6+ """
7+ Redefine scipy.special.logsumexp
8+ see: http://bayesjumping.net/log-sum-exp-trick/
9+ """
10+ _max = np .max (log_probs )
11+ ds = log_probs - _max
12+ exp_sum = np .exp (ds ).sum (axis = axis )
13+ return _max + np .log (exp_sum )
14+
15+
16+ def log_gaussian_pdf (x_i , mu , sigma ):
17+ """Compute log N(x_i | mu, sigma)"""
18+ n = len (mu )
19+ a = n * np .log (2 * np .pi )
20+ _ , b = np .linalg .slogdet (sigma )
21+
22+ y = np .linalg .solve (sigma , x_i - mu )
23+ c = np .dot (x_i - mu , y )
24+ return - 0.5 * (a + b + c )
You can’t perform that action at this time.
0 commit comments