emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Christian Moe <mail@christianmoe.com>
To: nicholas.dokos@hp.com
Cc: Jude DaShiell <jdashiel@shellworld.net>, emacs-orgmode@gnu.org
Subject: Re: unexpected failure on all formulas
Date: Tue, 20 Sep 2011 22:28:47 +0200	[thread overview]
Message-ID: <4E78F77F.30702@christianmoe.com> (raw)
In-Reply-To: <24637.1316530743@alphaville.dokosmarshall.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<mail@christianmoe.com>  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

      parent reply	other threads:[~2011-09-20 20:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-20  0:41 unexpected failure on all formulas Jude DaShiell
2011-09-20  6:17 ` Nick Dokos
2011-09-20  8:26   ` Nick Dokos
2011-09-20  9:15     ` Lawrence Mitchell
2011-09-20  9:29     ` Christian Moe
2011-09-20 14:59       ` Nick Dokos
2011-09-20 16:30         ` Nick Dokos
2011-09-20 20:28         ` Christian Moe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E78F77F.30702@christianmoe.com \
    --to=mail@christianmoe.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=jdashiel@shellworld.net \
    --cc=nicholas.dokos@hp.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).