Received: from localhost (maia-3.hub.org [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id 261159FB4E5 for ; Fri, 27 Apr 2007 03:07:44 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 70035-10 for ; Fri, 27 Apr 2007 03:07:37 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.4 Received: from olive.qinip.net (olive.qinip.net [62.100.30.40]) by postgresql.org (Postfix) with ESMTP id EBAC09FA206 for ; Fri, 27 Apr 2007 03:07:38 -0300 (ADT) Received: from [10.0.0.21] (h8441139206.dsl.speedlinq.nl [84.41.139.206]) by olive.qinip.net (Postfix) with ESMTP id 6AB7D18441; Fri, 27 Apr 2007 08:07:35 +0200 (MEST) Message-ID: <4631932A.6000000@tweakers.net> Date: Fri, 27 Apr 2007 08:07:38 +0200 From: Arjen van der Meijden User-Agent: Thunderbird 2.0.0.0 (Windows/20070326) MIME-Version: 1.0 To: Mark Kirkwood CC: Jeff Davis , Andrew Lazarus , pgsql-performance@postgresql.org Subject: Re: index structure for 114-dimension vector References: <01db01c781e4$c700bf30$2e00a8c0@tridecap.com> <1217328326.20070420120729@pillette.com> <1177105284.28383.31.camel@dogma.v10.wvs> <46294FEB.9010909@paradise.net.nz> In-Reply-To: <46294FEB.9010909@paradise.net.nz> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200704/457 X-Sequence-Number: 24334 On 21-4-2007 1:42 Mark Kirkwood wrote: > I don't think that will work for the vector norm i.e: > > |x - y| = sqrt(sum over j ((x[j] - y[j])^2)) I don't know if this is usefull here, but I was able to rewrite that algorithm for a set of very sparse vectors (i.e. they had very little overlapping factors) to something like: |x - y| = sum over j (x[j]^2) + sum over j (y[j]^2) + for each j where x[j] and y[j] are both non-zero: - (x[j]^2 + y[j]^2) + (x[j] - y[j])^2 The first two parts sums can be calculated only once. So if you have very little overlap, this is therefore much more efficient (if there is no overlap at all you end up with x[j]^2 + y[j]^2 anyway). Besides, this rewritten calculation allows you to store the X and Y vectors using a trivial table-layout vector(x,i,value) which is only filled with non-zero's and which you can trivially self-join to find the closest matches. You don't care about the j's where there is either no x or y-value anyway with this rewrite. I can compare over 1000 y's of on average 100 elements to two x's of over 1000 elements on just a single 1.8Ghz amd processor. (I use it for a bi-kmeans algorithm, so there are only two buckets to compare to). So it might be possible to rewrite your algorithm to be less calculation-intensive. Obviously, with a dense-matrix this isn't going to work, but there may be other ways to circumvent parts of the algorithm or to cache large parts of it. It might also help to extract only the 6 relevant columns into a seperate temporary table which will have much smaller records and thus can fit more records per page. Best regards, Arjen