Sha256: 46c49ca5bf93a6e859c5d1eea514b47aff6d3ef7cf9e11136922337f0abcb438

Contents?: true

Size: 987 Bytes

Versions: 1

Compression:

Stored size: 987 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) > 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

1 entries across 1 versions & 1 rubygems

Version Path
glm-0.0.2 lib/glm/logit.rb