Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'subset': 0.09; 'cc:addr :python-list': 0.11; '(x,': 0.16; '-tkc': 0.16; '[*]': 0.16; 'counter()': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'inputs': 0.16; 'limiting': 0.16; 'wrote:': 0.18; 'differ': 0.19; 'cc:addr:python.org': 0.22; 'own.': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'sort': 0.25; 'compare': 0.26; 'header:In- Reply-To:1': 0.27; 'possibility': 0.29; 'gives': 0.31; 'container': 0.31; 'keys': 0.31; 'could': 0.34; 'something': 0.35; 'equal': 0.35; 'there': 0.35; 'charset:us-ascii': 0.36; 'possible': 0.36; 'subject:?': 0.36; 'should': 0.36; 'two': 0.37; 'received:10': 0.37; 'performance': 0.37; 'does': 0.39; 'subject:" ': 0.39; 'skip:n 10': 0.64; 'to:addr:gmail.com': 0.65; 'within': 0.65; 'expectations': 0.74 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1411479887518:609831691 X-MC-Ingress-Time: 1411479887518 Date: Tue, 23 Sep 2014 08:42:46 -0500 From: Tim Chase To: Miki Tebeka Subject: Re: "Fuzzy" Counter? In-Reply-To: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> References: <0d28ee82-2240-4f10-9db9-e966c0e62a13@googlegroups.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 30 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1411480271 news.xs4all.nl 2830 [2001:888:2000:d::a6]:32843 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:78211 On 2014-09-23 05:34, Miki Tebeka wrote: > Before I start writing my own. Is there something like > collections.Counter (fore frequencies) that does "fuzzy" matching? > > Meaning x is considered equal to y if abs(x - y) < epsilon. (x, y > and my case will be numpy.array). Not that I know of -- the performance characteristics would differ radically from the O(1) expectations that Counter() gives you since you'd have to compare your value against *every* value in the container[*], and you have the possibility that two items in the container are equidistant yet within EPSILON: EPSILON = 0.51 my_counter[1.0] += 1 my_counter[2.0] += 1 my_counter[1.5] += 1 # which one should be incremented? -tkc [*] This could be mitigated if you had some constraints on your inputs and wanted to do some sort of bucket-hashing, limiting it to a subset of the possible keys