How to calculate the area dissimilarity between two curves?

3 vues (au cours des 30 derniers jours)
Mr. 206
Mr. 206 le 9 Oct 2018
Modifié(e) : Mr. 206 le 9 Oct 2018
I have two smoothed curves 'f' and 'g'.
f = [4.66356058704069;4.76003678995220;4.85195856216057;4.93937125386862;5.02241091568476;5.10134964882580;5.17664095531976;5.24896508820865;5.31927440175128;5.38883870162610;5.45908891231901;5.53146074451118;5.60723836246689;5.68739805142138;5.77245188496874;5.86229139244967;5.95603122633945;6.05185282963574;6.14684810324653;6.23686307337801;6.31713266653654;6.38291548453061;6.43012857947280;6.45598222878181;6.45961471018444;6.44272707671764;6.41021793173056;6.37081820388660;6.33483553209117;6.31189865041951;6.30870177304451;6.32932410300064;6.37554934094787;6.44718519393563;6.54238288416678;6.65795665776154;6.78970329352158;6.93272161169404;7.08173198273553;7.23139583607635;7.37663516888456;7.51295205483015;7.63674815284922;7.74522475322546;7.83628282367168;7.90842305541129;7.96064590925989;7.99235166170680;8.00324045099670;7.99321232321114]
and
g= [3.42595434180783;3.52889117917543;3.63122045210296;3.73294216049285;3.83405630405245;3.93456288219636;4.03446189394889;4.13375333784643;4.23243721183987;4.33051351319701;4.42798223853624;4.52484338386025;4.62109694458974;4.71674291559714;4.81178129124035;4.90621206539645;5.00003523149543;5.09325078264601;5.18585871176133;5.27785901168476;5.36925167531561;5.46003669573492;5.55021406633123;5.63978378092629;5.72874583375865;5.81710021946721;5.90484693307479;5.9919859699717;6.07851732589953;6.16444099693433;6.24975697947062;6.33446527020481;6.41856586611880;6.50205876447018;6.58494396278248;6.66722145883533;6.74889125065473;6.82995333650325;6.91040771487023;6.99025438446208;7.06949334419241;7.14812459317236;7.22614813069081;7.30356395619462;7.38037206926889;7.45657246961725;7.53216515704210;7.60715013142487;7.68152739270630;7.75529694086660]
'f' is produced by smoothing
x_f =[1.36; 1.26; 1.15; 1.07; 1.04; 0.975; 0.919; 0.902; 0.85]
y_f =[8.166216269;7.843848638;7.365180126;7.170119543;7.192934221;6.956545443;6.459904454;6.257667588;5.379897354]
And 'g' is produced by smoothing
x_g = [1.43;1.33;1.25;1.18;1.11;1.05;1;0.952;0.909;0.87;0.833]
y_g =[9.193091461;8.14221752;7.560356469;7.320262202;7.209229304;7.139303413;7.064348687;6.618999297;6.065270152;5.49321781;4.925745302]
I want to find the area dissimilarity between them. I am using this Equation
where D is the intersection between domains of two functions. The curves(f and g) needs to be rescaled before computing these dissimilarity. Dividing 'f' and 'g' by the maximum value of f. So the maximum value is 1.
Can you please help me, how can i implement this in MATLAB?
  5 commentaires
Torsten
Torsten le 9 Oct 2018
Modifié(e) : Torsten le 9 Oct 2018
d^0_L^2(f,g) is the integral distance between two functions:
d^0_L^2(f,g) = 1/(b-a) * sqrt[integral_{a}^{b} (f(x)-g(x))^2]
So, D = b-a, a normalization by the length of the interval of integration.
Best wishes
Torsten.
Mr. 206
Mr. 206 le 9 Oct 2018
Modifié(e) : Mr. 206 le 9 Oct 2018
Following your lead this is the code...
a_f=x_f(1,1);
b_f=x_f(end,1);
D = b_f.-a_f;
v = (f.-g);
d0_L2_pre = norm(v)/abs(D);
Though your explanation seems legit. However it is not giving desired results.

Connectez-vous pour commenter.

Réponses (1)

KSSV
KSSV le 9 Oct 2018
If D is the area you can calculate it using :
x_f =[1.36; 1.26; 1.15; 1.07; 1.04; 0.975; 0.919; 0.902; 0.85] ;
y_f =[8.166216269;7.843848638;7.365180126;7.170119543;7.192934221;6.956545443;6.459904454;6.257667588;5.379897354] ;
x_g = [1.43;1.33;1.25;1.18;1.11;1.05;1;0.952;0.909;0.87;0.833] ;
y_g =[9.193091461;8.14221752;7.560356469;7.320262202;7.209229304;7.139303413;7.064348687;6.618999297;6.065270152;5.49321781;4.925745302] ;
% Smoothe the curves
N = 1000 ;
xi_f = linspace(min(x_f),max(x_f),N)';
yi_f = interp1(x_f,y_f,xi_f) ;
f = [xi_f yi_f] ;
xi_g = linspace(min(x_g),max(x_g),N)';
yi_g = interp1(x_g,y_g,xi_g) ;
g = [xi_g yi_g] ;
P = InterX(f',g') ;
P(:,1) = [] ;
%%Get interscetion area
x0 = min(P(1,:)) ; x1 = max(P(1,:)) ;
f0 = f ; g0 = g ;
f(f(:,1)<x0,:) = [] ;f(f(:,1)>x1,:) = [] ;
g(g(:,1)<x0,:) = [] ;g(g(:,1)>x1,:) = [] ;
d = abs(trapz(f(:,1),f(:,2))-trapz(g(:,1),g(:,2))) ;
plot(f(:,1),f(:,2),'r')
hold on
plot(g(:,1),g(:,2),'b')
plot(P(1,:),P(2,:),'*k')
  3 commentaires
KSSV
KSSV le 9 Oct 2018
The above code worked fine for me......let them be not same...doesn't matter....did you get any error?
Mr. 206
Mr. 206 le 9 Oct 2018
Modifié(e) : Mr. 206 le 9 Oct 2018
So far it also worked for me, but i need to use the 'D'. And when using it in
q = f/max(f)
r = g/max(f)
v = norm(q-r)
d0_L2_pre = norm(v)/d
Then it is saying "Matrix dimensions must agree."

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by