2323#include < RcppArmadillo.h>
2424#include < math.h>
2525#include " IDistance.h"
26- #include " Utility .h"
26+ #include " Util .h"
2727#include " BinaryCount.h"
2828
2929#undef max
@@ -37,8 +37,8 @@ class DistanceBinary : public IDistance {
3737public:
3838double calcDistance (const arma::mat &A,const arma::mat &B) {
3939 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
40- unsigned long denominator = bc.getA () + bc.getB () + bc.getC ();
41- return ((denominator ==0 ) ?0 :( double ) (bc.getB () + bc.getC ()) / denominator);
40+ uint64_t denominator = bc.getA () + bc.getB () + bc.getC ();
41+ return ((denominator ==0 ) ?0 :static_cast < double > (bc.getB () + bc.getC ()) / denominator);
4242 }
4343};
4444
@@ -49,8 +49,8 @@ class DistanceBraunblanquet : public IDistance {
4949public:
5050double calcDistance (const arma::mat &A,const arma::mat &B) {
5151 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
52- unsigned long denominator =maxOfPair ((bc.getA () + bc.getB ()), (bc.getA () + bc.getC ()));
53- return utility ::similarityToDistance (( double ) bc.getA () / denominator);
52+ uint64_t denominator =maxOfPair ((bc.getA () + bc.getB ()), (bc.getA () + bc.getC ()));
53+ return util ::similarityToDistance (static_cast < double >( bc.getA () ) / denominator);
5454 }
5555};
5656
@@ -61,8 +61,8 @@ class DistanceDice : public IDistance {
6161public:
6262double calcDistance (const arma::mat &A,const arma::mat &B) {
6363 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
64- unsigned long denominator =2 * bc.getA () + bc.getB () + bc.getC ();
65- return utility ::similarityToDistance (( double ) (2 * bc.getA ()) / denominator);
64+ uint64_t denominator =2 * bc.getA () + bc.getB () + bc.getC ();
65+ return util ::similarityToDistance (static_cast < double > (2 * bc.getA ()) / denominator);
6666 }
6767};
6868
@@ -73,7 +73,8 @@ class DistanceFager : public IDistance {
7373public:
7474double calcDistance (const arma::mat &A,const arma::mat &B) {
7575 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
76- return utility::similarityToDistance (((double ) bc.getA () /sqrt ((bc.getA () + bc.getB ()) * (bc.getA () + bc.getC ()))) - ((sqrt (bc.getA () + bc.getC ())) /2.0 ));
76+ return util::similarityToDistance ((static_cast <double >(bc.getA ()) /
77+ sqrt ((bc.getA () + bc.getB ()) * (bc.getA () + bc.getC ()))) - ((sqrt (bc.getA () + bc.getC ())) /2.0 ));
7778 }
7879};
7980
@@ -84,7 +85,7 @@ class DistanceFaith : public IDistance {
8485public:
8586double calcDistance (const arma::mat &A,const arma::mat &B) {
8687 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
87- return utility ::similarityToDistance ((bc.getA () +( double ) bc.getD () /2.0 ) / A.n_cols );
88+ return util ::similarityToDistance ((bc.getA () +static_cast < double >( bc.getD () ) /2.0 ) / A.n_cols );
8889 }
8990};
9091
@@ -95,7 +96,8 @@ class DistanceHamman : public IDistance {
9596public:
9697double calcDistance (const arma::mat &A,const arma::mat &B) {
9798 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
98- return utility::similarityToDistance (((double ) bc.getA () + bc.getD () - bc.getB () - bc.getC ()) / A.n_cols );
99+ return util::similarityToDistance (
100+ (static_cast <double >(bc.getA ()) + bc.getD () - bc.getB () - bc.getC ()) / A.n_cols );
99101 }
100102};
101103
@@ -106,7 +108,7 @@ class DistanceKulczynski1 : public IDistance {
106108public:
107109double calcDistance (const arma::mat &A,const arma::mat &B) {
108110 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
109- return utility ::similarityToDistance (( double ) bc.getA () / (bc.getB () + bc.getC ()));
111+ return util ::similarityToDistance (static_cast < double >( bc.getA () ) / (bc.getB () + bc.getC ()));
110112 }
111113};
112114
@@ -117,9 +119,9 @@ class DistanceKulczynski2 : public IDistance {
117119public:
118120double calcDistance (const arma::mat &A,const arma::mat &B) {
119121 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
120- double div1 =( double ) bc.getA () / (bc.getA () + bc.getB ());
121- double div2 =( double ) bc.getA () / (bc.getA () + bc.getC ());
122- return utility ::similarityToDistance ((div1 + div2) /2.0 );
122+ double div1 =static_cast < double >( bc.getA () ) / (bc.getA () + bc.getB ());
123+ double div2 =static_cast < double >( bc.getA () ) / (bc.getA () + bc.getC ());
124+ return util ::similarityToDistance ((div1 + div2) /2.0 );
123125 }
124126};
125127
@@ -131,7 +133,8 @@ class DistanceMichael : public IDistance {
131133double calcDistance (const arma::mat &A,const arma::mat &B) {
132134 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
133135double denominator =pow (bc.getA () + bc.getD (),2 ) +pow (bc.getB () + bc.getC (),2 );
134- return utility::similarityToDistance ((4.0 * ((double )(bc.getA () * bc.getD ()) - (bc.getB () * bc.getC ()))) / denominator);
136+ return util::similarityToDistance ((4.0 * (static_cast <double >(bc.getA () * bc.getD ()) -
137+ (bc.getB () * bc.getC ()))) / denominator);
135138 }
136139};
137140
@@ -142,8 +145,8 @@ class DistanceMountford : public IDistance {
142145public:
143146double calcDistance (const arma::mat &A,const arma::mat &B) {
144147 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
145- unsigned long denominator = bc.getA () * (bc.getB () + bc.getC ()) +2 * bc.getB () * bc.getC ();
146- return utility ::similarityToDistance (( double ) (2 * bc.getA ()) / denominator);
148+ uint64_t denominator = bc.getA () * (bc.getB () + bc.getC ()) +2 * bc.getB () * bc.getC ();
149+ return util ::similarityToDistance (static_cast < double > (2 * bc.getA ()) / denominator);
147150 }
148151};
149152
@@ -154,8 +157,8 @@ class DistanceMozley : public IDistance {
154157public:
155158double calcDistance (const arma::mat &A,const arma::mat &B) {
156159 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
157- unsigned long denominator = (bc.getA () + bc.getB ()) * (bc.getA () + bc.getC ());
158- return utility ::similarityToDistance ((( double ) bc.getA () * A.n_cols ) / denominator);
160+ uint64_t denominator = (bc.getA () + bc.getB ()) * (bc.getA () + bc.getC ());
161+ return util ::similarityToDistance ((static_cast < double >( bc.getA () * A.n_cols ) ) / denominator);
159162 }
160163};
161164
@@ -167,7 +170,7 @@ class DistanceOchiai : public IDistance {
167170double calcDistance (const arma::mat &A,const arma::mat &B) {
168171 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
169172double denominator =sqrt ((bc.getA () + bc.getB ()) * (bc.getA () + bc.getC ()));
170- return utility ::similarityToDistance (( double ) bc.getA () / denominator);
173+ return util ::similarityToDistance (static_cast < double >( bc.getA () ) / denominator);
171174 }
172175};
173176
@@ -178,8 +181,10 @@ class DistancePhi : public IDistance {
178181public:
179182double calcDistance (const arma::mat &A,const arma::mat &B) {
180183 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
181- double denominator = (sqrt (bc.getA () + bc.getB ()) *sqrt (bc.getC () + bc.getD ()) *sqrt (bc.getA () + bc.getC ()) *sqrt (bc.getB () + bc.getD ()));
182- return utility::similarityToDistance (((double ) (bc.getA () * bc.getD ()) - (bc.getB () * bc.getC ())) / denominator);
184+ double denominator = (sqrt (bc.getA () + bc.getB ()) *sqrt (bc.getC () + bc.getD ()) *
185+ sqrt (bc.getA () + bc.getC ()) *sqrt (bc.getB () + bc.getD ()));
186+ return util::similarityToDistance (
187+ (static_cast <double >(bc.getA () * bc.getD ()) - (bc.getB () * bc.getC ()))/ denominator);
183188 }
184189};
185190
@@ -190,7 +195,7 @@ class DistanceRussel : public IDistance {
190195public:
191196double calcDistance (const arma::mat &A,const arma::mat &B) {
192197 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
193- return utility ::similarityToDistance (( double ) bc.getA () / A.n_cols );
198+ return util ::similarityToDistance (static_cast < double >( bc.getA () ) / A.n_cols );
194199 }
195200};
196201
@@ -201,7 +206,7 @@ class DistanceSimplematching : public IDistance {
201206public:
202207double calcDistance (const arma::mat &A,const arma::mat &B) {
203208 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
204- return utility ::similarityToDistance (( double ) (bc.getA () + bc.getD ()) / A.n_cols );
209+ return util ::similarityToDistance (static_cast < double > (bc.getA () + bc.getD ()) / A.n_cols );
205210 }
206211};
207212
@@ -212,8 +217,8 @@ class DistanceSimpson : public IDistance {
212217public:
213218double calcDistance (const arma::mat &A,const arma::mat &B) {
214219 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
215- unsigned long denominator =minOfPair ((bc.getA () + bc.getB ()), (bc.getA () + bc.getC ()));
216- return utility ::similarityToDistance (( double ) bc.getA () / denominator);
220+ uint64_t denominator =minOfPair ((bc.getA () + bc.getB ()), (bc.getA () + bc.getC ()));
221+ return util ::similarityToDistance (static_cast < double >( bc.getA () ) / denominator);
217222 }
218223};
219224
@@ -225,7 +230,10 @@ class DistanceStiles : public IDistance {
225230double calcDistance (const arma::mat &A,const arma::mat &B) {
226231 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
227232unsigned int n = A.n_cols ;
228- return utility::similarityToDistance ((log (n) +2 *log (abs ((double ) bc.getA () * bc.getD () - bc.getB () * bc.getC ()) - n /2.0 ) -log (bc.getA () + bc.getB ()) -log (bc.getC () + bc.getD ()) -log (bc.getA () + bc.getC ()) -log (bc.getB () + bc.getD ())));
233+ return util::similarityToDistance (
234+ (log (n) +2 *log (fabs (static_cast <double >(bc.getA () * bc.getD ()) - bc.getB () * bc.getC ()) - n /2.0 ) -
235+ log (bc.getA () + bc.getB ()) -log (bc.getC () + bc.getD ()) -
236+ log (bc.getA () + bc.getC ()) -log (bc.getB () + bc.getD ())));
229237 }
230238};
231239
@@ -236,8 +244,8 @@ class DistanceTanimoto : public IDistance {
236244public:
237245double calcDistance (const arma::mat &A,const arma::mat &B) {
238246 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
239- unsigned long denominator = bc.getA () +2 * bc.getB () +2 * bc.getC () + bc.getD ();
240- return utility ::similarityToDistance (( double ) (bc.getA () + bc.getD ()) / denominator);
247+ uint64_t denominator = bc.getA () +2 * bc.getB () +2 * bc.getC () + bc.getD ();
248+ return util ::similarityToDistance (static_cast < double > (bc.getA () + bc.getD ()) / denominator);
241249 }
242250};
243251
@@ -248,8 +256,9 @@ class DistanceYule : public IDistance {
248256public:
249257double calcDistance (const arma::mat &A,const arma::mat &B) {
250258 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
251- unsigned long denominator = (bc.getA () * bc.getD ()) + (bc.getB () * bc.getC ());
252- return utility::similarityToDistance (((double ) (bc.getA () * bc.getD ()) - (bc.getB () * bc.getC ())) / denominator);
259+ uint64_t denominator = (bc.getA () * bc.getD ()) + (bc.getB () * bc.getC ());
260+ return util::similarityToDistance ((static_cast <double >(bc.getA () * bc.getD ()) -
261+ (bc.getB () * bc.getC ())) / denominator);
253262 }
254263};
255264
@@ -261,8 +270,9 @@ class DistanceYule2 : public IDistance {
261270double calcDistance (const arma::mat &A,const arma::mat &B) {
262271 BinaryCount bc =BinaryCount::getBinaryCount (A, B);
263272double denominator =sqrt (bc.getA () * bc.getD ()) +sqrt (bc.getB () * bc.getC ());
264- return utility::similarityToDistance ((double ) (sqrt (bc.getA () * bc.getD ()) -sqrt (bc.getB () * bc.getC ())) / denominator);
273+ return util::similarityToDistance ((static_cast <double >(sqrt (bc.getA () * bc.getD ())) -
274+ sqrt (bc.getB () * bc.getC ())) / denominator);
265275 }
266276};
267277
268- #endif
278+ #endif // DISTANCEBINARY_H_