Math Problem
Given a vector X=(…, x_i ,…), H(X) denotes a histogram of X. Define a derivative of H(X) with respect to the i-th value x_i.
A Solution
X_i(+) and X_i(-) denote two vector made by replacing the i-th value of X with x_i + 1 and x_i - 1, respectively. We can define an interpolated histogram
I(X, h) = [ (1+h) H(X_i(+)) + (1-h) H(X_i(-)) ] / 2

for -1 < h < 1. Differentiating this interpolated histogram with respect to h, we get
dI(X,h)/dh =  [ H(X_i(+)) - H(X_i(-)) ] / 2.

@fangwei123456 If you need this derivative, you can define a backward() method as described in Defining new autograd functions 14.