Solved by KFrank in post #5 
              
              
                Hello Hwarang! 

No, this won’t work.  The problem is that this version of myloss() isn’t 
usefully differentiable.  It is constant almost everywhere, so the gradient 
will always be zero. 
Mathematically, myloss() is differentiable (with zero gradient) except 
when any of the data[i] = 0.5, at whic…