def dual_copy_rounding(W,integer_bits=0,fractional_bits=1):
"""
Rounding as described in as in "Robustness of spiking Deep Belief Networks to noise and reduced bit precision
of neuro-inspired hardware platforms"
by Stromatidis et al. See http://dx.doi.org/10.3389/fnins.2015.00222
:param W: Weights
:param integer_bits: number of bits to represent the integer part
:param fractional_bits: number of bits to represent the fractional part
:return:quantized weights
"""
#print "Dual copy rounding!"
power = T.cast(2.**fractional_bits, theano.config.floatX) # float !
max_val = T.cast((2.**(fractional_bits+integer_bits))-1, theano.config.floatX)
value = W*power
value = GradPreserveRoundTensor(value) # rounding
value = T.clip(value, -max_val, max_val) # saturation arithmetic
Wb = value/power
return Wb
评论列表
文章目录