Class: Alglib::Logit

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lm, lr, cases, ivars, nclasses) ⇒ Logit

Use with care…



25
26
27
28
29
30
31
# File 'lib/alglib/logit.rb', line 25

def initialize(lm,lr,cases,ivars,nclasses)
    @model=lm
    @report=lr
    @cases=cases
    @ivars=ivars
    @nclasses=nclasses
end

Instance Attribute Details

#casesObject (readonly)

Returns the value of attribute cases.



3
4
5
# File 'lib/alglib/logit.rb', line 3

def cases
  @cases
end

#ivarsObject (readonly)

Returns the value of attribute ivars.



3
4
5
# File 'lib/alglib/logit.rb', line 3

def ivars
  @ivars
end

#modelObject (readonly)

Returns the value of attribute model.



3
4
5
# File 'lib/alglib/logit.rb', line 3

def model
  @model
end

Class Method Details

.build_from_matrix(matrix) ⇒ Object

Creates a Logit object based on a Matrix EXAMPLE:

require 'alglib'
matrix=Matrix[[2,3,4],[2,5,5],[1,5,3],[4,6,5]]
lr=Alglib::LinearRegression.build_from_matrix(matrix)
  => #<Alglib::LinearRegression:0x7ffaf6c05dc0 @model=#<Alglib_ext::LinearModel:0x7ffaf6c05e60>, @cases=4, @report=#<Alglib_ext::LrReport:0x7ffaf6c05e10>, @ivars=2>
  lr.coeffs
  => [0.585714285714286, -0.0142857142857142]


13
14
15
16
17
18
19
20
21
22
23
# File 'lib/alglib/logit.rb', line 13

def self.build_from_matrix(matrix)
    raise "Argument should be a matrix" unless matrix.is_a? Matrix
    cases=matrix.row_size
    ivars=matrix.column_size-1
    lm=Alglib_ext::LogitModel.new
    lr=Alglib_ext::MNLReport.new
    nclasses=matrix.column(matrix.column_size-1).to_a.uniq.size
    am=matrix.to_alglib_matrix
    Alglib_ext::mnltrainh(am,cases,ivars,nclasses,lm,lr)
    self.new(lm,lr,cases,ivars,nclasses)
end

Instance Method Details

#process(vector) ⇒ Object



32
33
34
# File 'lib/alglib/logit.rb', line 32

def process(vector)
    Alglib_ext.mnlprocess(@model,vector)
end

#unpackObject



35
36
37
38
39
# File 'lib/alglib/logit.rb', line 35

def unpack
    a2d=Alglib_ext::Real2dArray.new
    Alglib_ext::mnlunpack(@model, a2d,@ivars,@nclasses);
    Alglib.real2darray_to_array(a2d)
end