Coder Social home page Coder Social logo

Custom distances about ngt HOT 6 OPEN

yahoojapan avatar yahoojapan commented on May 21, 2024
Custom distances

from ngt.

Comments (6)

masajiro avatar masajiro commented on May 21, 2024

Currently I have no plan to implement a custom distance. But, since I know that a custom distance is important for some applications, I would like to implement a custom distance into C++ API in future. But, I do not think that a custom distance defined by slow python is an effective way, because the distance function largely affects the search time.

from ngt.

MilesCranmer avatar MilesCranmer commented on May 21, 2024

Thanks. Just to check, if I want to add a custom distance myself in the C++ without adding all the architecture for it, could I potentially just replace the following lines:

inline static double compareL2(const OBJECT_TYPE *a, const OBJECT_TYPE *b, size_t size) {
const OBJECT_TYPE *last = a + size;
const OBJECT_TYPE *lastgroup = last - 3;
COMPARE_TYPE diff0, diff1, diff2, diff3;
double d = 0.0;
while (a < lastgroup) {
diff0 = (COMPARE_TYPE)(a[0] - b[0]);
diff1 = (COMPARE_TYPE)(a[1] - b[1]);
diff2 = (COMPARE_TYPE)(a[2] - b[2]);
diff3 = (COMPARE_TYPE)(a[3] - b[3]);
d += diff0 * diff0 + diff1 * diff1 + diff2 * diff2 + diff3 * diff3;
a += 4;
b += 4;
}
while (a < last) {
diff0 = (COMPARE_TYPE)(*a++ - *b++);
d += diff0 * diff0;
}

and refer to my custom distance as "l2" ? (My distance is similar to L2) Or would there be a lot more I would need to replace?

Cheers,
Miles

from ngt.

masajiro avatar masajiro commented on May 21, 2024

You are right. You do not need to update other part of the source code. But you have to care about implementing your function. Objects (vector data) are automatically stored as a 16-byte boundary object with zero padding in the index.

inline static double compareL2(const OBJECT_TYPE *a, const OBJECT_TYPE *b, size_t size) {

The size above is the byte length of the 16-byte boundary object. You cannot get the original size of the object in the function. For example, when you specify 3-dimensional floating point object to create an empty index, the size of the function’s parameter is 16 and the added forth floating point of the object is always zero.

from ngt.

masajiro avatar masajiro commented on May 21, 2024

If you use the default cmake definitions, you have to replace

inline static double compareL2(const float *a, const float *b, size_t size) {

or
inline static double compareL2(const unsigned char *a, const unsigned char *b, size_t size) {

, because AVX must be available.

from ngt.

raulcarlomagno avatar raulcarlomagno commented on May 21, 2024

is there any plan to add support for braycurtis and canberra distances? thanks

from ngt.

masajiro avatar masajiro commented on May 21, 2024

We have no plan to implement braycurtis and canberra distances. However, it might not be so difficult to implement the distances by yourself referring to this PR #91.

from ngt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.