Class: LProblem
- Inherits:
-
Object
- Object
- LProblem
- Defined in:
- lib/linear.rb
Instance Attribute Summary collapse
-
#maxlen ⇒ Object
Returns the value of attribute maxlen.
-
#prob ⇒ Object
Returns the value of attribute prob.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(y, x, bias) ⇒ LProblem
constructor
A new instance of LProblem.
- #inspect ⇒ Object
Constructor Details
#initialize(y, x, bias) ⇒ LProblem
Returns a new instance of LProblem.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/linear.rb', line 144 def initialize(y,x,bias) # assert_equal(y.size, x.size) @prob = prob = Problem.new @size = size = y.size @y_array = y_array = new_int(size) for i in (0..size-1) int_setitem(@y_array,i,y[i]) end @x_matrix = x_matrix = feature_node_matrix(size) @data = [] @maxlen = 0 #max number of features len_array=[] for i in (0..size-1) data = _convert_to_feature_node_array(x[i], @maxlen, bias) @data << data feature_node_matrix_set(x_matrix,i,data) if x[i].class == Hash if x[i].size > 0 @maxlen = [@maxlen,x[i].keys.max].max end else @maxlen = [@maxlen,x[i].size].max end len_array << x[i].size end if bias >= 0 set_bias_index(x_matrix, size, @maxlen, _int_array(len_array)) end prob.y = y_array prob.x = x_matrix prob.bias = bias prob.l = size prob.n = @maxlen if bias >= 0 prob.n += 1 end end |
Instance Attribute Details
#maxlen ⇒ Object
Returns the value of attribute maxlen.
142 143 144 |
# File 'lib/linear.rb', line 142 def maxlen @maxlen end |
#prob ⇒ Object
Returns the value of attribute prob.
142 143 144 |
# File 'lib/linear.rb', line 142 def prob @prob end |
#size ⇒ Object
Returns the value of attribute size.
142 143 144 |
# File 'lib/linear.rb', line 142 def size @size end |
Instance Method Details
#destroy ⇒ Object
192 193 194 195 196 197 198 199 |
# File 'lib/linear.rb', line 192 def destroy delete_problem(@prob) delete_int(@y_array) for i in (0..size-1) feature_node_array_destroy(@data[i]) end feature_node_matrix_destroy(@x_matrix) end |
#inspect ⇒ Object
188 189 190 |
# File 'lib/linear.rb', line 188 def inspect "LProblem: size = #{size} n=#{prob.n} bias=#{prob.bias} maxlen=#{@maxlen}" end |