add constraints and regularizers modules
This commit is contained in:
parent
a8dab51eeb
commit
babc0b9dd8
16
keras/constraints.py
Normal file
16
keras/constraints.py
Normal file
@ -0,0 +1,16 @@
|
||||
from __future__ import absolute_import
|
||||
import theano
|
||||
import theano.tensor as T
|
||||
import numpy as np
|
||||
|
||||
def maxnorm(m=2):
|
||||
def maxnorm_wrap(p):
|
||||
norms = T.sqrt(T.sum(T.sqr(p), axis=0))
|
||||
desired = T.clip(norms, 0, m)
|
||||
p = p * (desired / (1e-7 + norms))
|
||||
return p
|
||||
return maxnorm_wrap
|
||||
|
||||
def nonneg(p):
|
||||
p *= T.ge(p,0)
|
||||
return p
|
19
keras/regularizers.py
Normal file
19
keras/regularizers.py
Normal file
@ -0,0 +1,19 @@
|
||||
from __future__ import absolute_import
|
||||
import theano
|
||||
import theano.tensor as T
|
||||
import numpy as np
|
||||
|
||||
def l1(lam=.01):
|
||||
def l1wrap(g,p):
|
||||
g += T.sgn(p) * lam
|
||||
return g
|
||||
return l1wrap
|
||||
|
||||
def l2(lam=.01):
|
||||
def l2wrap(g,p):
|
||||
g += p * lam
|
||||
return g
|
||||
return l2wrap
|
||||
|
||||
def ident(g,*l):
|
||||
return g
|
Loading…
Reference in New Issue
Block a user