how can I effectively compute expected value by histogram approximation of probability desnsity function

14 ビュー (過去 30 日間)
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?
Is there (FEX) any code available?
  2 件のコメント
the cyclist
the cyclist 2019 年 10 月 22 日
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?
Michal
Michal 2019 年 10 月 22 日
編集済み: Michal 2019 年 10 月 22 日
It is structure of discrete values similar to matlab histogram object.

サインインしてコメントする。

回答 (1 件)

the cyclist
the cyclist 2019 年 10 月 22 日
There might be some nuances in the numerical integration, but here is the basic idea. You need to approximate the integral of x over the pdf.
% For reproducibility
rng default
% Simulated data -- normal centered on x=5.
N = 1000000;
x = 5 + randn(N,1);
% Get the probability density function. (You have these values already?)
[pdf_x,xi] = ksdensity(x);
% The bin width. (In this case, they are all equal, so I just take the first one.)
dx = xi(2) - xi(1);
% Calculate the total probability. (It should be 1.)
total_probability = sum(pdf_x*dx)
% Calculate the mean, which is the expected value of x.
mean_x = sum(xi.*pdf_x*dx)
  4 件のコメント
Michal
Michal 2019 年 10 月 22 日
OK ... thanks for basic info. I think the "nuances" of integration will be my main problem.
I will try to use matlab "discretize" function to find pdf approximation at my histogram points and then integration over x * pdf * width.
the cyclist
the cyclist 2019 年 10 月 22 日
You might be able to use the trapz function.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeExploration and Visualization についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by