1
1
from __future__ import division
2
- from theano .tensor import constant , flatten , zeros_like , ones_like , stack , concatenate , sum , prod , lt , gt , le , ge , eq , neq , switch , clip , where , and_ , or_ , abs_
3
-
4
- from theano .tensor import exp , log , cos , sin , tan , cosh , sinh , tanh , sqr , sqrt , erf , erfinv , dot
2
+ from theano .tensor import constant , flatten , zeros_like , ones_like , stack , concatenate , sum , prod , lt , gt , le , ge , eq , \
3
+ neq , switch , clip , where , and_ , or_ , abs_
4
+ from theano .tensor import exp , log , cos , sin , tan , cosh , sinh , \
5
+ tanh , sqr , sqrt , erf , erfinv , dot
5
6
from theano .tensor import maximum , minimum , sgn , ceil , floor
6
-
7
- from theano . tensor . nlinalg import det , matrix_inverse , extract_diag , matrix_dot , trace
7
+ from theano . tensor . nlinalg import det , matrix_inverse , \
8
+ extract_diag , matrix_dot , trace
8
9
from theano .tensor .nnet import sigmoid
9
10
import theano
10
11
import theano .tensor as tt
11
12
import sys
12
13
14
+
13
15
def logsumexp (x , axis = None ):
14
- # Adapted from https://github.com/Theano/Theano/issues/1563
15
- x_max = tt .max (x , axis = axis , keepdims = True )
16
- return tt .log (tt .sum (tt .exp (x - x_max ), axis = axis , keepdims = True )) + x_max
16
+ # Adapted from https://github.com/Theano/Theano/issues/1563
17
+ x_max = tt .max (x , axis = axis , keepdims = True )
18
+ return tt .log (tt .sum (tt .exp (x - x_max ), axis = axis , keepdims = True )) + x_max
19
+
17
20
18
21
def invlogit (x , eps = sys .float_info .epsilon ):
19
22
return (1 - 2 * eps ) / (1 + tt .exp (- x )) + eps
20
23
24
+
21
25
def logit (p ):
22
- return tt .log (p / ( 1 - p ))
26
+ return tt .log (p / ( 1 - p ))
0 commit comments