From: ara.t.howard@... Date: 2006-12-03T00:46:58+09:00 Subject: Re: [OT] calculations on lists of numbers On Sat, 2 Dec 2006, Olivier wrote: > Hi, > > I'm currently coding a ruby program for processing images. One of the class I > wrote is intended to compute some stats about the luminance of a channel, but > in fact it can be used on any set of numerical datas. The stats are : > - an histogram > - the mean > - the variance > - the deviation > - the median > - the skewness > - the kurtosis > > It is very fast, since it uses no memory : the values are not stored > internally, just the sub-results (so, a list of 2 values will use the same > amount of memory than a list of a billion values), and also because the > method that adds a value is generated depending of what stats you want to > compute. > > It would be really easy to add min and max, but it would need one or two > modifications to get rid of the "image-specific" things. Then, reading stdin > and add the values would be no problem. > > If you want to base your work on my class then just tell me, I'll be happy to > share it if it can help. > > -- Olivier heh, i've got something similar i use to compute stats on binary data all the time, here's the entire code harp:~> cat a.rb #! /dmsp/reference/bin/ruby require 'narray' require 'yaml' list = ARGF.readlines.map{|line| line.strip.split(%r/\s+/).map{|f| Float f}}.flatten na = NArray.to_na list puts '---' %w( min max mean median stddev ).each{|stat| puts "#{ stat }: #{ na.send stat}"} but it's not as complete as yours. -a -- if you want others to be happy, practice compassion. if you want to be happy, practice compassion. -- the dalai lama