From mboxrd@z Thu Jan 1 00:00:00 1970 From: Christian Moe Subject: Re: unexpected failure on all formulas Date: Tue, 20 Sep 2011 22:28:47 +0200 Message-ID: <4E78F77F.30702@christianmoe.com> References: <18072.1316499460@alphaville.dokosmarshall.org> <19773.1316507170@alphaville.dokosmarshall.org> <4E785CDC.9070503@christianmoe.com> <24637.1316530743@alphaville.dokosmarshall.org> Reply-To: mail@christianmoe.com Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([140.186.70.92]:34517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R66uM-0002HN-VJ for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 16:27:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R66uL-0005fm-OA for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 16:27:10 -0400 Received: from mars.hitrost.net ([91.185.211.18]:47862) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R66uL-0005fE-8h for emacs-orgmode@gnu.org; Tue, 20 Sep 2011 16:27:09 -0400 In-Reply-To: <24637.1316530743@alphaville.dokosmarshall.org> List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: nicholas.dokos@hp.com Cc: Jude DaShiell , emacs-orgmode@gnu.org Hi, Nick, No whacks intended! It was an easy catch because I was mulling over similar problems with my code. My own second pass at a vmode implementation for Calc is below, now with support for negative values and bimodal data. It takes a different route and is a bit shorter, but doesn't handle all the cases your code does (I guess; I don't grok it all). Yours, Christian (defmath vmode (vec) "Return the mode(s), i.e. most frequent value(s), of a vector of integers VEC." (let ((results (vec)) ; hold results (index 1) offset maxfreq) (setq offset (- 1 (vmin vec)) vec (+ offset vec) ; bump all ints positive freq (histogram vec (1+ (vmax vec))) offset (1+ offset) ; histogram added `0' slot maxfreq (vmax freq)) ;; Collect indexes (less offset) of all max freqs (while (> (setq index (find freq maxfreq index)) 0) (setq results (vconcat results index) index (1+ index))) (setq results (- results offset)) ; get neg ints back ;; Return results as vector or number (if (> (vlen results) 1) results (head results)))) On 9/20/11 4:59 PM, Nick Dokos wrote: > Christian Moe wrote: > > >> I think your vmode() needs to subtract one from the result. The mode >> in the "systolic" column of Jude's dataset should be 124 (f=12), not >> 125 (f=2). >> > > Yes, this is an off-by-one error: in vfreqs, I should cons prev onto > freqs, not (nth 0 vec). In addition to this and the multimodal problem > that both you and Lawrence Mitchell pointed out, there is another > off-by-one error when vfreqs gets to the end of the list. > > All in all, a disaster: can a posting be deleted? or at least marked > with a big, red X so that it won't mislead in the future? I'll try to > post a corrected version later on. > > OTOH, my main interest in this was the hooking up of a user function > onto calc and the example, though deeply flawed, does illustrate that. > > Thanks to both Christian and Lawrence for the whacks in the head > (although now I have a headache...) > > Nick