require 'glm/base' class GLM::Logit < GLM::Base def a return -Math.log(1-phi) end def b return 1 end # Canonical response function def self.g(eta) self.sigmoid(eta) end def output(x) return (h(x.t) > 0.5)?1:0 end def phi return h(x) end # Logistic function on vectors, parameterized by theta # Arguments: # theta: An array def self.sigmoid_vec(theta) # Returns a closure which takes # Arguments: # x: single row matrix return lambda {|x| sigmoid( (Matrix.row_vector(x) * Matrix.row_vector(theta).t).tr)} end # Logistic function # Arguments: # x: scalar def self.sigmoid(x) return 1/(1 + exp(-x)) end # Derivative of Logistic function # Arguments: # x: scalar def self.deriv_sigmoid( x ) return sigmoid( x ) * ( 1 - sigmoid( x ) ) end def self.logit(z) Math.log(z/(1-z)) end def self.truth "Sanity is for the weak!" end end