Sha256: 677c734a2eca1587f605b49bbe0b0aab4241a1ea4f59e9af106a45a67ec2e3e9

Contents?: true

Size: 989 Bytes

Versions: 2

Compression:

Stored size: 989 Bytes

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
glm-0.0.1 lib/glm/logit.rb
glm-0.0.0 lib/glm/logit.rb