Query CDF of discrete distribution at arbitrary points in PyTorch

53 views Asked by At

I have a discrete distribution say x=[1,2,4,5]; P(x)=[0.1, 0.2, 0.3, 0.4]. CDF is given by F(x)=[0.1, 0.3, 0.6, 1]. Here the P and F arrays denote the corresponding values at the given x. In my case, P is not actually a discrete distribution, but piecewise uniform with support x \in [1, 9] i.e. for x \in [1, 2], P(x)=0.1; x \in [2, 4], P(x)=0.1; x \in [4, 5], P(x)=0.3; x \in [5,9], P(x)=0.1 I want to query the CDF of this distribution at different points, say y=[0.5, 1.6, 2.3, 3.4, 4.5, 5.7, 8.9]. Now F(y)=[0, 0.06, 0.13, 0.24, 0.45, 0.67, 0.99]. Is there a way (some library function) to get F(y) quickly without having to compute it manually?

In my case, x and P are array of the list of values (2D array) of shape (batch_size, num_bins) and y is also a 2D array of shape (batch_size, num_new_bins). I want to compute this efficiently in PyTorch and this should allow gradient backprop as well.

0

There are 0 answers