-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathpenalties.py
More file actions
31 lines (24 loc) · 722 Bytes
/
penalties.py
File metadata and controls
31 lines (24 loc) · 722 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from theano import tensor as T
def orthogonality(x):
'''
Penalty for deviation from orthogonality:
||dot(x.T, x) - I||**2
'''
xTx = T.dot(x.T, x)
return T.sum(T.square(xTx - T.identity_like(xTx)))
def constant_l2(val):
def penalty(x):
'''
Sum of squares of differences between elements of x and 'val'
sqrt((x-1)**2)
'''
return T.sum(T.square(x - val*T.ones_like(x)))
return penalty
def constant_l1(val):
def penalty(x):
'''
Sum of magnitudes of differences between elements of x and 'val'
sqrt((x-1)**2)
'''
return T.sum(T.abs(x - val*T.ones_like(x)))
return penalty