Define Loss Function in TF based on a histogram

Viewed 805

I'd like to define a loss function in tensorflow based on a histogram but that requires the histogram function to support gradients, which is not the case. For example, using tf.histogram_fixed_width I get an error "No gradients provided for any variable, check your graph for ops that do not support gradients". I am hence looking for a work-around or an alternative function to compute histograms in tensorflow that supports gradients.

1 Answers

Loss function must be of form f(x, [y, ...])->R. It has to produce a single real number and must be differentiable (for every R there must exist a sence of direction towards a better solution). Histograms are taking in your input but produce a data structure as output and they are not differentiable. You can try to define in your own words what a "better" or "good" histogram should look like. If you have a shape in mind, you can describe it in terms of ideal hitogram and use KL-divergence as a loss function between ideal and actual histogram.

Related