Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 11658 invoked from network); 27 Oct 2009 18:01:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Oct 2009 18:01:16 -0000 Received: (qmail 53052 invoked by uid 500); 27 Oct 2009 18:01:16 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 52969 invoked by uid 500); 27 Oct 2009 18:01:16 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 52957 invoked by uid 500); 27 Oct 2009 18:01:16 -0000 Delivered-To: apmail-incubator-couchdb-commits@incubator.apache.org Received: (qmail 52954 invoked by uid 99); 27 Oct 2009 18:01:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Oct 2009 18:01:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.130] (HELO eos.apache.org) (140.211.11.130) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Oct 2009 18:01:00 +0000 Received: from eos.apache.org (localhost [127.0.0.1]) by eos.apache.org (Postfix) with ESMTP id E958716E31; Tue, 27 Oct 2009 18:00:38 +0000 (GMT) MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable From: Apache Wiki To: Apache Wiki Date: Tue, 27 Oct 2009 18:00:38 -0000 Message-ID: <20091027180038.6145.37729@eos.apache.org> Subject: =?utf-8?q?=5BCouchdb_Wiki=5D_Update_of_=22View=5FSnippets=22_by_MarcaJame?= =?utf-8?q?s?= X-Virus-Checked: Checked by ClamAV on apache.org Dear Wiki user, You have subscribed to a wiki page or wiki category on "Couchdb Wiki" for c= hange notification. The "View_Snippets" page has been changed by MarcaJames. The comment on this change is: Clarified why one would *want* to use the co= mplicated algorithm.. http://wiki.apache.org/couchdb/View_Snippets?action=3Ddiff&rev1=3D28&rev2= =3D29 -------------------------------------------------- <> =3D=3D Computing simple summary statistics (min,max,mean,standard deviati= on) =3D=3D = - Implementation in {{{JavaScript}}} by MarcaJames. Mistakes in coding are= my fault, algorithms are from others, as noted. To the best of my knowled= ge the algorithms are public domain, and my implementation freely available= to all (Perl Artistic License if you really need a license to consult) + This implementation of standard deviation is more complex than the above = algorithm, called the "textbook one-pass algorithm" by Chan, Golub, and LeV= eque. While it is mathematically equivalent to the standard two-pass compu= tation of standard deviation, it can be numerically unstable under certain = conditions. Specifically, if the square of the sums and the sum of the sq= uares terms are large, then they will be computed with some rounding error.= If the variance of the data set is small, then subtracting those two larg= e numbers (which have been rounded off slightly) might wipe out the computa= tion of the variance. See http://www.jstor.org/stable/2683386, http://peop= le.xiph.org/~tterribe/notes/homs.html, and the wikipedia description of Knu= th's algorithm http://en.wikipedia.org/wiki/Algorithms_for_calculating_vari= ance. = - Here is some code I have developed to compute standard deviation. I do i= t two ways, both of which are different from jchris' github version (add li= nk?). In practice of course you wouldn't need both ways. The view is spec= ialized to my dataset, but the reduce function might be useful to others. + The below implementation in {{{JavaScript}}} by MarcaJames. Any mistakes= in the js coding are my fault. The algorithms are from others (all smarte= r than I), as noted in the comments in the code. To the best of my knowled= ge the algorithms are public domain, and my implementation freely available= to all. = = - I've only ever tested it on futon, and have no idea what the "group" para= meter does to the output. Probably nothing! + Note that the view is specialized to my dataset, but the reduce function = is written to be fairly generic. I kept the view as is because I'm too laz= y to write up a generic view, and also because when I wrote it I wasn't sur= e one could use Date, Math, and Reg``Exp in Couch``DB Java``Script. = = {{{ // Map function