It's easy to see how to organise a database if you want to be able to, say, find all the people in it whose names are between "Charybdis" and "Scylla" in alphabetical order. But how would you organise it if you want to find all the people whose pictures look most like a particular sample picture, when all you have is a tool that measures how similar two pictures are? There's a family of very general approaches to the problem called "metric space searches"; in this approach, we don't need to know anything about what we're storing except that we can measure the distance between two items and get a sensible answer.
I thought I'd invented a smashing new algorithm for searching in metric spaces. But I'm having a hard time finding out if it's any good.
Searching in Metric Spaces (1999) provides an overview of the state of the art as of five years ago.
The usual assumption when designing these algorithms is that the distance measurement function is very expensive, and so the first order of business is to minimise the number of distance measurements. I implemented my algorithm and got very good results on random points in a cube. But when I tried a harder data set - random lines from "A Tale of Two Cities" with string edit distance as the metric, a standard test used in Brin's tests on his GNAT algorithm - I found it would compare the target string to over half the strings in the database before returning an answer.
So I tried implementing one of the standard algorithms from the paper - AESA, a simple one that's supposed to be very good at minimising distance measurements at search time, at the cost of very high startup time and storage - and that doesn't do much better!
Results using Hamming distance between random binary strings are even worse - AESA averages 882.4 measurements in a dataset of 1000 items, while my algorithm averages 999.3...
How am I supposed to assess my algorithm if I can't find an interesting test case on which any algorithm performs even vaguely OK? Random points in a cube is not a good test, because there are already much better algorithms for the special case of vector spaces...
I thought I'd invented a smashing new algorithm for searching in metric spaces. But I'm having a hard time finding out if it's any good.
Searching in Metric Spaces (1999) provides an overview of the state of the art as of five years ago.
The usual assumption when designing these algorithms is that the distance measurement function is very expensive, and so the first order of business is to minimise the number of distance measurements. I implemented my algorithm and got very good results on random points in a cube. But when I tried a harder data set - random lines from "A Tale of Two Cities" with string edit distance as the metric, a standard test used in Brin's tests on his GNAT algorithm - I found it would compare the target string to over half the strings in the database before returning an answer.
So I tried implementing one of the standard algorithms from the paper - AESA, a simple one that's supposed to be very good at minimising distance measurements at search time, at the cost of very high startup time and storage - and that doesn't do much better!
Results using Hamming distance between random binary strings are even worse - AESA averages 882.4 measurements in a dataset of 1000 items, while my algorithm averages 999.3...
How am I supposed to assess my algorithm if I can't find an interesting test case on which any algorithm performs even vaguely OK? Random points in a cube is not a good test, because there are already much better algorithms for the special case of vector spaces...
no subject
Date: 2004-04-03 01:23 am (UTC)Some of the research focused on pattern recognition. The only link I was able to find is below.
http://www.lic.gov.uk/research/information_retrieval/ir-im-rr.html
no subject
Date: 2004-04-03 04:38 am (UTC)I guess what you've discovered is that all the existing algorithms suck. I think this is probably why Google Image search doesn't have a "Find images similar to this one..." function.
From my brief read of AESA, I really don't see how it's supposed to be O(1) at all. It looks to me like its performance is heavily dependent on the value of r used - smaller r should eliminate many more elements of U on each iteration. What r are you using?
I'd be interested to hear what your algorithm is.
no subject
Date: 2004-04-03 04:59 am (UTC)By O(1) they mean about O(1) distance measurements - it's at least O(n) overall work, and that's not counting the O(n^2) initialisation and storage requirements.
My algorithm is a variant of GHT. The big ideas are
(*) at each node in the tree, you use one old point (one you already know the distance to) and one new point to decide the dividing line between the two subtrees. But you can use any old node, not just one from the parent; you choose the one that gives you the biggest range in distances from the points in the subtree, then use the point furthest from that as the new node
(*) at each node in the tree, you record the range of distances for points contained in the node from *all* points already considered, to maximise the chances you'll be able to prune that branch
(*) instead of hyperplanes as the dividing line, you use hyperhyperbolae, in order to exactly divide the points remaining into two. IE your test is not d[1] - d[0] < 0 but d[1] - d[0] < node.bias. This turned out to make a substantial positive difference
(*) I'm considering beefing up the pruning some more by adding hyperhyperbola-based pruning: ie the range of values of d_a - d_b for every point in the node and for all d_a and d_b considered so far.
Er, that was all clear as mud wasn't it. OK, here's another way to put it. The function that constructs the node takes two arguments: a set of points to put in the node, and a set of "comparator points". When the search method on the node is called, it will be passed the target point, the range r, and the distance of the target point from each of the comparator points. It'll use all these distances to try and "early reject". Then failing that, it'll add a new comparator point to the set, measure the distance from the target to the new point, and use this new point along with an existing point to define a hyperbolic dividing plane. It decides which side of the plane the target point is on, searches the subtree corresponding to that side first, and then tries the other subtree unless it can demonstrate that nothing on the other side can be close enough.
Er, slightly clearer mud?
no subject
Date: 2004-04-03 05:13 am (UTC)I still don't get it. AESA repeatedly measures distance between the pivot and the query node, rejecting a proportion of the data set each time. Not a constant proportion, so we can't be exact, but that sounds more like O(log n) to me. What am I missing?
Must read up on GHT before peering into your mud. Actually fuck that; must have bath, sort costume, talk to lovers etc...
no subject
Date: 2004-04-03 05:14 am (UTC)no subject
Date: 2004-04-03 08:08 am (UTC)"In theory, there's no difference between theory and practice."
no subject
Date: 2004-04-05 12:23 am (UTC)I don't suppose it can be O(1), but if it's, say, O(log log n) then it would be very hard to determine that by experiment, so they're doing the right thing by reporting what they observe as best they can. And it's a survey paper so there's a limit on how much detail they can go into.
no subject
no subject
Date: 2004-04-04 12:46 am (UTC)no subject
Date: 2004-04-05 12:20 am (UTC)no subject
Date: 2004-04-05 07:31 am (UTC)no subject
Date: 2004-04-05 08:05 am (UTC)Here's an example application: you have pictures of a million faces, and a function that computes distance between pictures. You do some preprocessing. Later, you capture a picture of a face, and you want to find the picture in the database that most closely matches your capture, without explicitly comparing with all million.
You could store the distances between all points as AESA does, but the O(n^2) cost makes this pretty much prohibitive if you're matching against a few million points.
no subject
Date: 2004-04-05 09:30 am (UTC)For your million photo example I'm guessing this would still be your best bet if you have enough hardware to throw at it and your distance metric isn't woefully expensive to calculate.
Another option for that example would be to come up with a quick 'candidate match' algorithm - maybe based on a small set of numbers you generate cheaply for each photo individually. When you want to match a new photo, you find a largish number of candidate matches using these numbers, and use your expensive picture-picture matching algorithm on the results. (I'd also want to fill in the lines on the graph at that point by storing the distances, but that's still O(n^2) and you'll struggle with six billion photos on any near future kit.) Of course this depends on coming up with some cunning 'candidate match' algorithm that works.
If your requirement is to find the closest matching photo(s), I don't see how you can avoid the O(n^2) hit at some point (and throughout in storage terms), unless there are some strong properties of your match algorithm that don't leap out instantly?
My guess is that the known search algorithms are crap because the problem is bloody hard. It's bad enough doing NP optimisation stuff where evaluating candidate solutions is cheap - if evaluating solutions is hard you're stuffed unless you know something about how your data is structured/tends to cluster.
All of this is dodging the problem as you stated it - solving the metric space search problem elegantly - but that's because my instinct is that if a problem is well known but not well solved I'm unlikely to find a solution myself in polynomial time :-) (This is also probably why you have some distinction as an inventor of algorithms and I have none!)
no subject
Date: 2004-04-05 09:40 am (UTC)I think an algorithm something like what you describe is in the survey paper, but I can't remember the name...
no subject
Date: 2004-04-05 03:06 pm (UTC)Assessing your algorithm...
Date: 2004-04-07 06:42 pm (UTC)- Your cube case is intrinsically 3D (if your cube was 3D) and the distribution is totally even (no interesting structure), so this is nearly a pathological case.
- Your random lines from "A Tale of Two Cities" test is (I would imagine) pretty close to n-dimensional (since the edit distances would be pretty large between random strings), but once again with a fairly even distribution.
Your test cases only cover two corners of the dimensionality/distribution property space. What it seems you need are just some more interesting test cases, starting with cases that test distributions that have structure:- Simple shapes like sines, sombrero, or some other simple function embedded in whatever dimensional space you want to test (pick random a coordinates for the function input and set the final dimensions value with the function).
- Points in a cube with a perlin noise distribution (pick a point in the space and discard ones where the noise value is outside of a certain threshold range- creating a nice marble like structure).
- Load in the points of a model file (say of a video game character).
In fact, now that I think about it, perlin noise (or fBm) functions are ideal for testing all sorts of algorithms since you can easily control how much or little structure there is to the space. You can control with simple input parameter changes the dimensionality, structure, frequency, and fractal dimensionality for each test set. It should be rather easy to write a program which generates an extremely thorough set of test sets to use. These test sets should give a very clear picture of comparative performance under different environments for each algorithm.Heck, I'll even write the program to generate the test sets for you if you want me to...
Re: Assessing your algorithm...
Date: 2004-05-12 05:21 pm (UTC)Check it out and let me know if it is of any use to you. :)