Thursday, January 20, 2011

Ruby Simple Statistics adding standard deviation

Ruby Simple Statistics - Standard Deviation





>> data
=> [1, 2, 3, 4, 5, 6]
>> data.class
=> Array


An array of numbers in ruby, (an Array object), can return the size/length, minimum (min) value, maximum (max) value. Missing methods are average, sample_variance, standard_deviation. These can added using an Enumerable module mixins.


Enumerable module mixins - add standard deviation to all arrays etc.


# Add methods to Enumerable, which makes them available to Array
module Enumerable

# sum of an array of numbers
def sum
return self.inject(0){|acc,i|acc +i}
end

# average of an array of numbers
def average
return self.sum/self.length.to_f
end

# variance of an array of numbers
def sample_variance
avg=self.average
sum=self.inject(0){|acc,i|acc +(i-avg)**2}
return(1/self.length.to_f*sum)
end

# standard deviation of an array of numbers
def standard_deviation
return Math.sqrt(self.sample_variance)
end

end # module Enumerable



Example Useage


# enter an interpreted ruby session to play with this:

$ irb
# create a new array called data with six numbers in it

>> data = [1, 2, 3, 4, 5, 6]
=> [1, 2, 3, 4, 5, 6]

>> data.class
=> Array

# try running the following commands. Some will work, some require the module from above.

>> data.sum
=> 21

>> data.size
=> 6

>> data.min
=> 1

>> data.max
=> 6

>> data.average
=> 3.5

>> data.sample_variance
=> 2.91666666666667

>> data.standard_deviation
=> 1.70782512765993



References

  1. ruby inject blogbackground on inject.
  2. see notes for mixins for Enumerable adding standard_deviation to Enumerable
  3. ruby core documentationSee Module Enumerable and Class Enumerable::Enumerator

mysql notes

reminders for some mysql tasks.

Dump a database to a file and compress it.

mysqldump -u root study_manager_development > study_manager_development.sql

gzip -v study_manager_development.sql


Select to outputfile

select id,sku, from line_items where sku LIKE '%u123%' into outfile '/tmp/u123.txt';

Saturday, January 8, 2011

OS X, iOS, MacOS X - PDF Documents in Teaching Annotations and Full Screen Viewing

in progress 8Jan2011...

Want to be able to teach from a PDF document, click on links in the document, add annotations while presenting, have the PDF displayed full-screen. I am looking at those options now.


  1. Preview - included with MacOS X, you can present a pdf document full-screen in slideshow mode. View --> Slideshow. Editing is not available in this mode.
  2. Skim - Presentation and full-screen menu options are available.
  3. PDF Studio
  4. PDFPen
  5. Keynote - You can't present and edit at the same time, However you can place and resize several different pdfs at the same time, adding highlights, building out a page and presenting full screen with different themes available.
  6. iOS iPad GoodReader is an option with a VGA cable.
Preview Menu:



Skim Menu: