필터 지우기
필터 지우기

Take the product of two probability density function histograms generated from data

조회 수: 9 (최근 30일)
I have two different sets of data $D_1$ and $D_2$ both of which have data between two values $a$ and $b$. I know I can get the histograms of these two data sets displayed as probability density functions, but what I'd like to do is take the product of these two probability density functions. What would be the most efficient way of achieving this?

채택된 답변

William Rose
William Rose 2023년 9월 21일
편집: William Rose 2023년 9월 21일
Since you did not provide data, let's create some.
x1=rand(10000,1)+rand(10000,1); % pdf(x1) = triangle from 0 to 2 with peak at 1
x2=0.8+0.4*randn(10000,1); % normal with mu=0.8, sigma=0.4.
x2=x2(x2>=0 & x2<=2); % discard x2 values <0 and >2
Compute the histograms.
bw=0.1;
h1=histogram(x1,'Normalization','pdf','BinWidth',bw);
figure
h2=histogram(x2,'Normalization','pdf','BinWidth',bw);
Multiply the histograms.
joint=h1.Values.*h2.Values; % bin-by-bin product
Plot result
bar(0.05:bw:1.95,joint,1)
How is that? Note that joint is not a PDF since the area under the curve is not 1. If you want joint to be a pdf, multiply it by the appropriate normmalization factor.
  댓글 수: 1
William Rose
William Rose 2023년 9월 21일
To make vector joint be a pdf, do
joint=joint/(sum(joint)*bw);
Check that the area under the curve of joint is unity:
disp(sum(joint)*bw)
Good luck.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by