Sorry if I was unclear, but the thresholds do not need to be learned but x may be a Variable. If I try to use this code I get the following error:

RuntimeError: one of the variables needed for the gradient computation has been modified by an inplace operation

I assume this is due to repeated inplace operations on the Variable x.