What is the proper way to compute effectively (fast) the expected value E(x) in a case when I have approximation of probability desity function f(x) by probability normalized histogram?
In what form do you have the approximate pdf? Is it a MATLAB function? Or is it a series of discrete values at specific x locations? Or something else? Can you upload your input data?
Yes, but your example is too simple. My histogram probability density approximation data are defined more general (BinEdges, NumBins, etc) with non-equidistant BinWidths.
Not clear to me how to work with x values outside of BinLimits, for example.
I would like to avoid of any smooth density estimation, because my histograms are very rough. In this case is not clear how to choose proper Bandwidth parameter of ksdensity function.
The ksdensity was only for me to simulate something like what you probably had -- a discrete vector of locations and densitiies. You shouldn't need to do any smoothing, etc.
If you have irregular bin widths, all you need to do is the numerical integration of x * pdf * width, as I did.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
2 Comments
Direct link to this comment
https://ww2.mathworks.cn/matlabcentral/answers/486796-how-can-i-effectively-compute-expected-value-by-histogram-approximation-of-probability-desnsity-func#comment_759063
Direct link to this comment
https://ww2.mathworks.cn/matlabcentral/answers/486796-how-can-i-effectively-compute-expected-value-by-histogram-approximation-of-probability-desnsity-func#comment_759063
Direct link to this comment
https://ww2.mathworks.cn/matlabcentral/answers/486796-how-can-i-effectively-compute-expected-value-by-histogram-approximation-of-probability-desnsity-func#comment_759068
Direct link to this comment
https://ww2.mathworks.cn/matlabcentral/answers/486796-how-can-i-effectively-compute-expected-value-by-histogram-approximation-of-probability-desnsity-func#comment_759068
Sign in to comment.