Archive

Posts Tagged ‘ruby’

Ruby ImageMagick memory allocation errors

April 14th, 2009

Summary: A Ruby/RMagick script of mine was failing with a variety of “Cannot allocate memory” errors. Adding a single line to the bottom of my thumbnail generation loop fixed this: img.destroy!.
Read more…

Aidan Findlater Impersonal ,

Bootstrapping Ruby on Fedora Core 7

April 13th, 2009

The context: a GoDaddy VPS running FC7 (apparently, GoDaddy hasn’t updated their VPS distros in years).

The problem: The inability to use any Ruby Gems because the FC7 ruby and ruby-gems packages are years and years behind everything I’m trying to install. Also, RMagick is segfaulting.

More problems: I can download and compile Ruby 1.9 just fine, but when I try to install Ruby Gems 1.3.1, it overwrites the Ruby interpreter (what??). This problem is documented here, but I’m pretty sure I’d have to pull from the repository to grab the fix.

My solution: Install Ruby (make install). Install Ruby Gems (ruby setup.rb). Move the gem binary to where it belongs (mv /usr/local/bin/ruby /usr/local/bin/gem). Install Ruby again (make install). This appears to work.

I gotta get off that GoDaddy VPS.

Aidan Findlater Impersonal , ,

Sorting rated content

February 14th, 2009

Anything with user-submitted ratings can be sorted by those ratings. But what is the best way? The naive approach is to sort by average rating. Unfortunately, this would rate 5-stars from a single user as higher than 4.5-stars from 150 users.

This guy has an answer. In short, his recommendation is to take the lower bound of the 95% confidence interval, given by:

[pmath] {hat{ p }+{ z^2_{alpha slash 2}} / { 2 n } pm z_{alpha slash 2} sqrt{ { [ hat{p} (1 - hat{p}) + z^2_{alpha slash 2}/{4n}]}/n}} / {1+z^2_{ alpha slash 2 }/n} [/pmath]

where

  • [pmath]hat{p}[/pmath] is the observed fraction of positive ratings
  • [pmath]z_{alpha slash 2}[/pmath] is the [pmath]1-alpha slash 2[/pmath] quantile of the standard normal distribution
  • [pmath]n[/pmath] is the total number of ratings

Or, in Ruby:

require 'statistics2'

def ci_lower_bound(pos, n, power)
    if n == 0
        return 0
    end
    z = Statistics2.pnormaldist(1-power/2)
    phat = 1.0*pos/n
    (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
end

where

  • pos is the number of positive rating
  • n is the total number of ratings
  • power refers to the statistical power (0.05 recommended)

Aidan Findlater Impersonal , ,

Calculating the area under the normal curve in Ruby

July 24th, 2007

Summary: Attached is a pure Ruby implementation of the AS66 algorithm (Hill 1973), ported from the Fortran code available here. It estimates the integral of the normal distribution, defaulting to the area under the right tail.
Read more…

Aidan Findlater Impersonal , , ,

BioRuby’s Bio::FlatFileIndex compatibility with BioPerl’s Bio::DB::Flat

July 20th, 2007

Summary: Attached is a diff that allows Bio::FlatFileIndex to access BDB flatfile databases created by BioPerl’s Bio::DB::Flat. I have not changed the way BioRuby creates its databases, so this likely breaks access to BioRuby-created flatfile indices.
Read more…

Aidan Findlater Impersonal , , ,