Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XC3xr-0005n7-V5 for pgsql-performance@arkaria.postgresql.org; Tue, 29 Jul 2014 09:45:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XC3xr-0000Yz-6p for pgsql-performance@arkaria.postgresql.org; Tue, 29 Jul 2014 09:44:59 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XC3xq-0000Yr-2H for pgsql-performance@postgresql.org; Tue, 29 Jul 2014 09:44:58 +0000 Received: from mail-we0-x22e.google.com ([2a00:1450:400c:c03::22e]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XC3xl-0007Hy-VC for pgsql-performance@postgresql.org; Tue, 29 Jul 2014 09:44:56 +0000 Received: by mail-we0-f174.google.com with SMTP id x48so8764382wes.33 for ; Tue, 29 Jul 2014 02:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:references:in-reply-to:subject:date:message-id :mime-version:content-type:thread-index:content-language; bh=lhsrmgfY71KCqRMqNbaNEN4Q6ZaRvhgB4G/eIMmoHHU=; b=qucRLftiBk9U76OfDaCAEt6AN0kfbnFOJqK4C3poAklNU/8SIwy4AID9P1cvNns1lK YuRq8uncy7FDQShL9HG4n/P/EgTx/vTbOjekbJM69ytgYj4Pms1dF6kZOO4BW4ELGj2F B54rZ8/rYUFVqPye/2/sJMXHuY1qrPtWoucvcN0XPEtIg8iwZHt2kSte/yo0ykpyNfAm bBOpRmn6Gti6IGjELUAgz7awOajcyy93CUwf1HZZT3h4SMynl8z7sV4F8OOtafCM8EH/ 1O0zA2iM0GTNr+ku0q939aJ97ARfrFuA/gmgPzISr/pXN9kVxDXbdtlA4lckyKNH29Z4 wlTw== X-Received: by 10.180.221.134 with SMTP id qe6mr4609134wic.66.1406627091097; Tue, 29 Jul 2014 02:44:51 -0700 (PDT) Received: from ssvnadvornik (37-48-46-236.tmcz.cz. [37.48.46.236]) by mx.google.com with ESMTPSA id w6sm12116169wjq.39.2014.07.29.02.44.47 for (version=TLSv1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 29 Jul 2014 02:44:48 -0700 (PDT) From: =?UTF-8?B?SmnFmcOtIE7DoWR2b3Juw61r?= To: "'Craig James'" Cc: "'Vitalii Tymchyshyn'" , References: <01d201cfa8be$dd746880$985d3980$@gmail.com> <04b801cfa9a7$ffdcb280$ff961780$@gmail.com> In-Reply-To: Subject: Re: Cursor + upsert (astronomical data) Date: Tue, 29 Jul 2014 11:44:46 +0200 Message-ID: <004401cfab11$bd4a4a70$37dedf50$@gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_NextPart_000_0045_01CFAB22.80D82380" X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQHSB3FUPUcQjIVcmXO3GnoQtcDS6gLVq3F8Acu/I/kB8Tf07Jt9X63g Content-Language: cs X-Pg-Spam-Score: -1.0 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org This is a multipart message in MIME format. ------=_NextPart_000_0045_01CFAB22.80D82380 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Craig, =20 I=E2=80=99m really interested in those algorithms and study them. But I = would need somebody to point me directly at a specific algorithm to look = at. The main problem with choosing the right one (which couldn=E2=80=99t = get over even my university teacher) is that you don=E2=80=99t know the = number of clusters (classification problem) and you don=E2=80=99t know = the number of objects in one cluster (that isn=E2=80=99t such a big = deal), but each cluster has different count of objects =E2=80=93 which = is a big issue because it actually disqualifies all of k-means based = algorithms (correct me if I=E2=80=99m wrong). =20 We were thinking of some kind of Bayesian method or a likelihood ratio = computation, but dismissed that as we found an implementation that ran = ~hours for ~5e5 records =E2=80=93 I just don=E2=80=99t think such an = approach would provide better results from a faster algorithm than the = simple linear one (checking each row and updating/inserting it to = catalog). =20 I actually left the algorithm to run for a smaller set of data (~80 mil. = Rows) and on 8 cores (cca 4 of them used at a time) it ran 48 hours. = That=E2=80=99s not that bad assuming it must run only once for the = dataset (on DB population) =E2=80=93 and then the additions will be = processed fast. The result is actually cca 1.2 mil identifiers and 50 = thousand from them are closer to each other than 1 arcsec (collisions) = =E2=80=93 but that is only <5% error. I think if we worked a bit on this = algorithm we could make it faster and reduce that error percentage to = maybe 1% which would be acceptable? What do you think? =20 Thank you very much for your effort. =20 Kind Regards, =20 Jiri Nadvornik =20 From: Craig James [mailto:cjames@emolecules.com]=20 Sent: Sunday, July 27, 2014 5:35 PM To: Ji=C5=99=C3=AD N=C3=A1dvorn=C3=ADk Cc: Vitalii Tymchyshyn; pgsql-performance@postgresql.org Subject: Re: [PERFORM] Cursor + upsert (astronomical data) =20 Jiri, =20 If you haven't looked at clustering algorithms yet, you might want to do = so. Your problem is a special case of clustering, where you have a large = number of small clusters. A good place to start is the overview on = Wikipedia: http://en.wikipedia.org/wiki/Cluster_analysis =20 A lot of people have worked extensively on this problem, and you might = find a good solution, or at least some ideas to guide your own = algorithm. In my field (chemistry), researchers often need to cluster = 10^6 to 10^7 chemical compounds, and a great deal of research has gone = into efficient ways to do so. =20 Craig =20 =20 On Sun, Jul 27, 2014 at 7:35 AM, Ji=C5=99=C3=AD N=C3=A1dvorn=C3=ADk = > wrote: Hi Vitalii, thank you for your reply. =20 The problem you suggested can in the most pathological way be, that = these observations are on one line. As you suggested it, the B would be = in the middle. So A and C are not in 1 arcsec range of each other, but = they must be within 1 arcsec of their common average coordinates. If the = distances between A,B,C are 1 arcsec for each, the right solution is to = pick B as reference identifier and assign A and C to it. =20 We already tried the approach you suggest with applying a grid based on = the Q3C indexing of the database. We were not just rounding the results, = but using the center of the Q3C =E2=80=9Csquare=E2=80=9D in which the = observation took place. The result was poor however =E2=80=93 22% of the = identifiers were closer to each other than 1 arcsec. That means that = when you crossmatch the original observations to them, you don=E2=80=99t = know which one to use and you have duplicates. The reason for this is = that nearly all of the observations are from SMC (high density of = observations), which causes that you have more than 2 = =E2=80=9Crounded=E2=80=9D positions in a row and don=E2=80=99t know = which ones to join together (compute average coordinates from it). If it = is not clear enough I can draw it on an image for you. Maybe the simple round up would have better results because the squares = are not each the same size and you can scale them only by 2 (2-times = smaller, or larger square). We used a squre with the side cca 0.76 = arcsec which approximately covers the 1 arcsec radius circle. =20 Oh and one more important thing. The difficulty of our data is not that = it is 3e8 rows. But in the highest density, there are cca 1000 images = overlapping. Which kills you when you try to self-join the observations = to find neighbours for each of them =E2=80=93 the quadratic complexity = is based on the overlappingon the image (e.g. 10000 observations on one = image with another 999 images overlapping it means 10000 *1000^2).=20 =20 Best regards, =20 Jiri Nadvornik =20 From: tivv00@gmail.com [mailto: = tivv00@gmail.com] On Behalf Of Vitalii = Tymchyshyn Sent: Sunday, July 27, 2014 8:06 AM To: Ji=C5=99=C3=AD N=C3=A1dvorn=C3=ADk Cc: = pgsql-performance@postgresql.org Subject: Re: [PERFORM] Cursor + upsert (astronomical data) =20 I am not sure I understand the problem fully, e.g. what to do if there = are observations A,B and C with A to B and B to C less then treshold and = A to C over treshold, but anyway. Could you first apply a kind of grid to your observations? What I mean = is to round your coords to, say, 1/2 arcsec on each axe and group the = results. I think you will have most observations grouped this way and = then use your regular algorithm to combine the results. Best regards, Vitalii Tymchyshyn =20 --=20 --------------------------------- Craig A. James Chief Technology Officer eMolecules, Inc. --------------------------------- ------=_NextPart_000_0045_01CFAB22.80D82380 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Hi Craig,

 

I=E2=80=99m really interested in those algorithms and study them. But = I would need somebody to point me directly at a specific algorithm to = look at. The main problem with choosing the right one (which = couldn=E2=80=99t get over even my university teacher) is that you = don=E2=80=99t know the number of clusters (classification problem) and = you don=E2=80=99t know the number of objects in one cluster (that = isn=E2=80=99t such a big deal), but each cluster has different count of = objects =E2=80=93 which is a big issue because it actually disqualifies = all of k-means based algorithms (correct me if I=E2=80=99m = wrong).

 

We were thinking of some kind of Bayesian method or a likelihood = ratio computation, but dismissed that as we found an implementation that = ran ~hours for ~5e5 records =E2=80=93 I just don=E2=80=99t think such an = approach would provide better results from a faster algorithm than the = simple linear one (checking each row and updating/inserting it to = catalog).

 

I actually left the algorithm to run for a smaller set of data (~80 = mil. Rows) and on 8 cores (cca 4 of them used at a time) it ran 48 = hours. That=E2=80=99s not that bad assuming it must run only once for = the dataset (on DB population) =E2=80=93 and then the additions will be = processed fast. The result is actually cca 1.2 mil identifiers and 50 = thousand from them are closer to each other than 1 arcsec (collisions) = =E2=80=93 but that is only <5% error. I think if we worked a bit on = this algorithm we could make it faster and reduce that error percentage = to maybe 1% which would be acceptable? What do you = think?

 

Thank you very much for your effort.

 

Kind Regards,

 

Jiri Nadvornik

 

From: Craig = James [mailto:cjames@emolecules.com]
Sent: Sunday, July 27, = 2014 5:35 PM
To: Ji=C5=99=C3=AD = N=C3=A1dvorn=C3=ADk
Cc: Vitalii Tymchyshyn; = pgsql-performance@postgresql.org
Subject: Re: [PERFORM] Cursor = + upsert (astronomical data)

 

Jiri,

 

If you haven't looked at clustering algorithms yet, = you might want to do so. Your problem is a special case of clustering, = where you have a large number of small clusters.  A good place to = start is the overview on Wikipedia: http://en.wikipedi= a.org/wiki/Cluster_analysis

 

A = lot of people have worked extensively on this problem, and you might = find a good solution, or at least some ideas to guide your own = algorithm. In my field (chemistry), researchers often need to cluster = 10^6 to 10^7 chemical compounds, and a great deal of research has gone = into efficient ways to do so.

 

Craig

 

 

On Sun, Jul 27, 2014 at 7:35 AM, Ji=C5=99=C3=AD = N=C3=A1dvorn=C3=ADk <nadvornik.ji@gmail.com> = wrote:

Hi Vitalii, thank you for your reply.

 

The problem you suggested can in the most pathological way be, that = these observations are on one line. As you suggested it, the B would be = in the middle. So A and C are not in 1 arcsec range of each other, but = they must be within 1 arcsec of their common average coordinates. If the = distances between A,B,C are 1 arcsec for each, the right solution is to = pick B as reference identifier and assign A and C to it.

 

We already tried the approach you suggest with applying a grid based = on the Q3C indexing of the database. We were not just rounding the = results, but using the center of the Q3C =E2=80=9Csquare=E2=80=9D in = which the observation took place. The result was poor however =E2=80=93 = 22% of the identifiers were closer to each other than 1 arcsec. That = means that when you crossmatch the original observations to them, you = don=E2=80=99t know which one to use and you have duplicates. The reason = for this is that nearly all of the observations are from SMC (high = density of observations), which causes that you have more than 2 = =E2=80=9Crounded=E2=80=9D positions in a row and don=E2=80=99t know = which ones to join together (compute average coordinates from it). If it = is not clear enough I can draw it on an image for you.

Maybe the simple round up would have better results because the = squares are not each the same size and you can scale them only by 2 = (2-times smaller, or larger square). We used a squre with the side cca = 0.76 arcsec which approximately covers the 1 arcsec radius = circle.

 

Oh and one more important thing. The difficulty of our data is not = that it is 3e8 rows. But in the highest density, there are cca 1000 = images overlapping. Which kills you when you try to self-join the = observations to find neighbours for each of them =E2=80=93 the quadratic = complexity is based on the overlappingon the image (e.g. 10000 = observations on one image with another 999 images overlapping it means = 10000 *1000^2).

 

Best regards,

 

Jiri Nadvornik

 

From:= tivv00@gmail= .com = [mailto:tivv00@gmail= .com] On = Behalf Of Vitalii Tymchyshyn
Sent: Sunday, July 27, 2014 = 8:06 AM
To: Ji=C5=99=C3=AD N=C3=A1dvorn=C3=ADk
Cc: =
pgsql-perfor= mance@postgresql.org
Subje= ct: Re: [PERFORM] Cursor + upsert (astronomical data)

 

I am not sure I = understand the problem fully, e.g. what to do if there are observations = A,B and C with A to B and B to C less then treshold and A to C over = treshold, but anyway.

Could you = first apply a kind of grid to your observations? What I mean is to round = your coords to, say, 1/2 arcsec on each axe and group the results. I = think you will have most observations grouped this way and then use your = regular algorithm to combine the results.

Best regards, Vitalii = Tymchyshyn



 

-- =

---------------------------------
Craig A. = James

Chief Technology = Officer

eMolecules, = Inc.

---------------------------------

<= /div>
------=_NextPart_000_0045_01CFAB22.80D82380--