Class: GLM::Logit

Inherits:
Base
  • Object
show all
Defined in:
lib/glm/logit.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#T, #est, #eta, #format, #gradient, #h, #initialize, #single_update, #sto_update, #theta

Constructor Details

This class inherits a constructor from GLM::Base

Class Method Details

.deriv_sigmoid(x) ⇒ Object

Derivative of Logistic function Arguments:

x: scalar


50
51
52
# File 'lib/glm/logit.rb', line 50

def self.deriv_sigmoid( x )
  return sigmoid( x ) * ( 1 - sigmoid( x ) )
end

.g(eta) ⇒ Object

Canonical response function



15
16
17
# File 'lib/glm/logit.rb', line 15

def self.g(eta)
  self.sigmoid(eta)
end

.logit(z) ⇒ Object



54
55
56
# File 'lib/glm/logit.rb', line 54

def self.logit(z)
  Math.log(z/(1-z))
end

.sigmoid(x) ⇒ Object

Logistic function Arguments:

x: scalar


43
44
45
# File 'lib/glm/logit.rb', line 43

def self.sigmoid(x)
  return 1/(1 + exp(-x))
end

.sigmoid_vec(theta) ⇒ Object

Logistic function on vectors, parameterized by theta Arguments:

theta: An array


31
32
33
34
35
36
37
38
# File 'lib/glm/logit.rb', line 31

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

.truthObject



58
59
60
# File 'lib/glm/logit.rb', line 58

def self.truth
  "Sanity is for the weak!"
end

Instance Method Details

#aObject



6
7
8
# File 'lib/glm/logit.rb', line 6

def a
  return -Math.log(1-phi)
end

#bObject



10
11
12
# File 'lib/glm/logit.rb', line 10

def b
  return 1
end

#output(x) ⇒ Object



19
20
21
# File 'lib/glm/logit.rb', line 19

def output(x)
  return (h(x) > 0.5)?1:0
end

#phiObject



23
24
25
# File 'lib/glm/logit.rb', line 23

def phi
  return h(x)
end