필터 지우기
필터 지우기

Implement the "total variation distance" (TVD) in Matlab

조회 수: 32 (최근 30일)
Sim
Sim 2023년 7월 3일
편집: Bruno Luong 2023년 8월 4일
I am trying to implement the Total variation distance of probability measures (TVD) in Matlab.
Would it be correct to use the max function, in order to calculate the "supremum" of the TVD equation (here below)?
My attempt:
% Input
A =[ 0.444643925792938 0.258402203856749
0.224416517055655 0.309641873278237
0.0730101735487732 0.148209366391185
0.0825852782764812 0.0848484848484849
0.0867743865948534 0.0727272727272727
0.0550568521843208 0.0440771349862259
0.00718132854578097 0.0121212121212121
0.00418910831837223 0.0336088154269972
0.00478755236385398 0.0269972451790634
0.00359066427289048 0.00110192837465565
0.00538599640933573 0.00220385674931129
0.000598444045481747 0
0.00299222022740874 0.00165289256198347
0 0
0.00119688809096349 0.000550964187327824
0 0.000550964187327824
0.00119688809096349 0.000550964187327824
0 0.000550964187327824
0 0.000550964187327824
0.000598444045481747 0
0.000598444045481747 0
0 0
0 0.000550964187327824
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0.000550964187327824
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0.00119688809096349 0.000550964187327824];
P = A(:,1);
Q = A(:,2);
% Total variation distance (of probability measures)
d = max(abs(P-Q))
d = 0.1862

채택된 답변

Bruno Luong
Bruno Luong 2023년 8월 4일
편집: Bruno Luong 2023년 8월 4일
Supremum is very often implemented by max, since one can only list or compute a finite set on computer.
However your formula d = max(abs(P-Q)) is not correct to compute TVD.
According to this wiki page; correct formula is given bellow "When Ω is countable"
d = 0.5 * norm(P-Q,1)
or
d = 0.5 * sum(abs(P-Q));
  댓글 수: 8
Bruno Luong
Bruno Luong 2023년 8월 4일
편집: Bruno Luong 2023년 8월 4일
Don't use the brute force implementation of the initial definition for any discrete pdf with more than 20 values (n = cardinal of Omega), rather use
dFormula = 0.5 * norm(P-Q,1)
The for-loop I made is just to illustrate the correctness of the formula. Just like no-one would computes the determinant of matrix 30 x 30 using Leibniz formula.
Sim
Sim 2023년 8월 4일
Ah ok..great..!! Many many thanks!
Then, I will use:
dFormula = 0.5 * norm(P-Q,1)

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

추가 답변 (1개)

Debadipto
Debadipto 2023년 8월 4일
Hi Sim,
Upon searching, I found the exact question being asked on stackoverflow (I'm assuming it was posted by you only), where somebody has already answered the question. I am attaching the link to that answer for future reference:

Community Treasure Hunt

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

Start Hunting!

Translated by