mljs / distance

Distance functions to compare vectors
https://mljs.github.io/distance/
MIT License
66 stars 4 forks source link

Deal with negative values in tanimoto distance function #3

Closed JeffersonH44 closed 9 years ago

JeffersonH44 commented 9 years ago

When I have negative values in the two arrays, the function returns a value higher than 1, for example:

Inputs: [-0.8165923305465388,-0.6227223258417958,-0.7376210803683754,-0.7246447504765743,-0.641977943698424,-0.6669868962898413,-0.7676178852030262,-0.7835202506799679,-0.7627527613156739,-0.7299997857948187,-0.6936229028847094,-0.674071362798151,-0.6434115964249937,-0.570078613713689,-0.4981111039251913,-0.11145735881476775,0.036119989594323804,-0.3294535326081225,-0.00027747889591308846,-0.1062194160305661,-0.18084837972074652,-0.14511785675885974,-0.1759367879018395,-0.11445327448466641,0.052483515951305834,0.3677068430984752,0.6828127385877366,0.9794670031626882,1.2863431548044573,1.236878697195273,0.7091764441347758,0.8239687466814378,2.111528275663774,1.067722895285367,0.5796321813549996,0.4697555499291982,0.3920558329894355,0.35940106815512496,0.43252280224080786,0.5172901811501169,0.6386377638134841,0.7786415512848596,1.1238081317358006,1.2527750215013254,1.7538631887485059,1.8158724694443567,1.714658449063295,1.6477721963002798,0.9472495784591741,0.6193711996927718,0.5604391953252895,0.5664681192712431,0.6063266636848704,0.6645630736633635,0.7732647476398503,0.9218867384836363,0.9119278967138622,0.8952769967486071,1.057559981914887,1.0234065016200335,0.8785068712441167,0.9334666288446765,1.1357341034704298,0.8907558845680615,0.6187723179813062,0.48207739232111185,0.36928164623277066,0.27557569994628095,0.20224695430351575,0.13602581515193848,0.06550525701546842,-0.05400902191897353,-0.09604346875358673,-0.09586895523767179,-0.10327511648674507,-0.10695553393877372,-0.10291146310731875,-0.10721772579321318,-0.1097282733803795,-0.10574257432237001,-0.10639234175725418,-0.10614579034564474,-0.11350521058887267,-0.11670748190558461,-0.12517347583293872,-0.12854432648823816,-0.129708375873688,-0.809175776396029,-2.02933194740533,-2.02933194740533,-2.02933194740533,-2.02933194740533,-2.02933194740533,-2.02933194740533,-2.02933194740533,-2.02933194740533,-2.02933194740533,-2.02933194740533,-2.02933194740533,-2.02933194740533]

[-0.8084629960969547,-0.556999696602502,-0.7141364117276019,-0.7088939899052036,-0.6108183720706524,-0.6123113720930093,-0.7311292950536685,-0.7528443240394024,-0.7334487018346714,-0.6896853340422238,-0.6448215281887634,-0.6543041047044356,-0.6198635278746936,-0.557823619660433,-0.5108724372127488,-0.17206264229125234,0.060393438659251716,-0.3122199933038071,0.013974930927223926,-0.07466996589819187,-0.20467395759036314,-0.22856071012547874,-0.25476058627228354,-0.18040453270133877,-0.03183258030879687,0.3152217227428024,0.652050782971909,0.8735907306821648,1.1834615901019392,1.3397807389658334,0.6735361443667526,0.6497181907059607,2.2760336182552634,1.3955471416173104,0.6500912158452513,0.464206556491767,0.36611075177244407,0.33128986386245474,0.40062965389520394,0.5730193352597525,0.7478465494972929,0.8828252704813843,1.2321853736364892,1.2905044008897995,1.9812055971752636,1.9911985213423113,1.7965272786871143,1.8086809445752938,0.9804156591318498,0.5492984101465701,0.481705288944265,0.4646723060287777,0.5110506480961041,0.5843515394141502,0.71427568176299,0.9122806497265366,0.8846476403479124,0.8540561302568778,0.9565458450961466,0.8941523784295511,0.7894900237426187,0.8377414932977327,1.0919899684419718,0.8494671994610453,0.5676535882741143,0.426982214054889,0.3018994108565992,0.20359424058005998,0.09524430589050598,-0.047328374651315404,-0.04540230140869711,-0.10512763821352544,-0.12235784831071392,-0.16168732897430793,-0.16490994610532717,-0.11807360975478624,-0.15298260224324747,-0.09172709344532246,-0.0639133882231669,-0.09813461132343992,-0.09039634899734258,-0.08496634064781262,-0.09608871075561641,-0.09697230033496415,-0.1006112999005704,-0.09887365990113758,-0.09773895628256082,-0.777567558523248,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252,-1.9933903639828252]

Output: 1.9999999999999984

maasencioh commented 9 years ago

Tanimoto is only allowed for non-negative numbers, you can read it from here