Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Sylvain Jasson
amap
Commits
234adb4c
Commit
234adb4c
authored
Jan 16, 2012
by
Antoine Lucas
Browse files
make correlation distance robust
parent
3437feb9
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/distance_T.cpp
View file @
234adb4c
...
...
@@ -2,7 +2,7 @@
* \brief all functions requiered for R dist function and C hcluster function.
*
* \date Created: probably in 1995
* \date Last modified: Time-stamp: <201
1-1
1-08
21:0
6:41 antoine>
* \date Last modified: Time-stamp: <201
2-0
1-08
12:1
6:41 antoine>
*
* \author R core members, and lately: Antoine Lucas
*
...
...
@@ -395,7 +395,7 @@ template<class T> T distance_T<T>::R_correlation(double * x, double * y , int n
int
i1
,
int
i2
,
int
*
flag
,
T_tri
&
opt
)
{
T
num
,
denum
,
sumx
,
sumy
,
sumxx
,
sumyy
,
sumxy
;
T
num
,
denum
2
,
sumx
,
sumy
,
sumxx
,
sumyy
,
sumxy
;
int
count
,
j
;
count
=
0
;
...
...
@@ -424,8 +424,12 @@ template<class T> T distance_T<T>::R_correlation(double * x, double * y , int n
return
NA_REAL
;
}
num
=
sumxy
-
(
sumx
*
sumy
/
count
);
denum
=
sqrt
(
(
sumxx
-
(
sumx
*
sumx
/
count
)
)
*
(
sumyy
-
(
sumy
*
sumy
/
count
)
)
);
return
1
-
(
num
/
denum
);
denum2
=
(
sumxx
-
(
sumx
*
sumx
/
count
)
)
*
(
sumyy
-
(
sumy
*
sumy
/
count
)
)
;
if
(
denum2
<=
0
)
{
return
0
;
}
return
1
-
(
num
/
sqrt
(
denum2
));
}
/** \brief Absolute Distance correlation (Uncentered Pearson)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment