Class: Wapiti::Options
- Inherits:
-
Object
- Object
- Wapiti::Options
- Includes:
- Comparable
- Defined in:
- lib/wapiti/options.rb,
ext/wapiti/native.c
Instance Attribute Summary collapse
-
#compress ⇒ Object
(also: #compress?)
Returns the value of attribute compress.
Class Method Summary collapse
-
.algorithms ⇒ Object
Returns the list of supported algorithm options.
-
.attribute_names ⇒ Object
Returns a sorted list of available option attributes.
-
.defaults ⇒ Object
Returns the default options.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#[](name) ⇒ Object
Returns the value of the attribute identified by
nameor nil if there is no such attribute. -
#[]=(name, value) ⇒ Object
Updates the value of the attribute identified by
namewith the passed-invalue. - #algorithm ⇒ Object (also: #algo)
- #algorithm=(rb_string) ⇒ Object (also: #algo=)
- #alpha ⇒ Object
- #alpha=(rb_numeric) ⇒ Object
-
#attributes ⇒ Object
(also: #to_hash)
Returns a hash of all the attributes with their names and values.
- #bcd ⇒ Object
- #check ⇒ Object (also: #check?)
- #check=(rb_boolean) ⇒ Object
- #clip ⇒ Object
- #clip=(rb_boolean) ⇒ Object
- #compact ⇒ Object (also: #compact?)
- #compact=(rb_boolean) ⇒ Object
- #cutoff ⇒ Object
- #cutoff=(rb_boolean) ⇒ Object
- #development_data ⇒ Object (also: #devel)
- #development_data=(rb_string) ⇒ Object (also: #devel=)
- #eta0 ⇒ Object
- #eta0=(rb_numeric) ⇒ Object
- #has_attribute?(attribute) ⇒ Boolean
- #histsz ⇒ Object
- #histsz=(rb_fixnum) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #jobsize ⇒ Object
- #jobsize=(rb_fixnum) ⇒ Object
- #kappa ⇒ Object
- #kappa=(rb_numeric) ⇒ Object
- #lbfgs ⇒ Object
- #lblpost ⇒ Object (also: #lblpost?, #posterior, #posterior?)
- #lblpost=(rb_boolean) ⇒ Object (also: #posterior=)
-
#maxent ⇒ Object
(also: #maxent?)
Boolean Accessors.
- #maxent=(rb_boolean) ⇒ Object
- #maxiter ⇒ Object (also: #max_iterations)
- #maxiter=(rb_fixnum) ⇒ Object (also: #max_iterations=)
- #maxls ⇒ Object
- #maxls=(rb_fixnum) ⇒ Object
- #model ⇒ Object
- #model=(rb_string) ⇒ Object
-
#nbest ⇒ Object
Fixnum Accessors.
- #nbest=(rb_fixnum) ⇒ Object
- #nthread ⇒ Object (also: #threads)
- #nthread=(rb_fixnum) ⇒ Object (also: #threads=)
- #objwin ⇒ Object (also: #convergence_window)
- #objwin=(rb_fixnum) ⇒ Object (also: #convergence_window=)
- #outsc ⇒ Object (also: #outsc?, #score, #score?)
- #outsc=(rb_boolean) ⇒ Object (also: #score=)
-
#pattern ⇒ Object
(also: #template)
String Accessors.
- #pattern=(rb_string) ⇒ Object (also: #template=)
-
#rho1 ⇒ Object
Float Accessors.
- #rho1=(rb_numeric) ⇒ Object
- #rho2 ⇒ Object
- #rho2=(rb_numeric) ⇒ Object
- #rprop ⇒ Object
- #sgdl1 ⇒ Object
- #skip_tokens ⇒ Object (also: #skip_tokens?)
- #skip_tokens=(rb_boolean) ⇒ Object
- #sparse ⇒ Object (also: #sparse?)
- #sparse=(rb_boolean) ⇒ Object
- #stopeps ⇒ Object (also: #stop_epsilon)
- #stopeps=(rb_numeric) ⇒ Object (also: #stop_epsilon=)
-
#stopwin ⇒ Object
(also: #stop_window)
Option Accessors.
- #stopwin=(rb_fixnum) ⇒ Object (also: #stop_window=)
- #stpdec ⇒ Object
- #stpdec=(rb_numeric) ⇒ Object
- #stpinc ⇒ Object
- #stpinc=(rb_numeric) ⇒ Object
- #stpmax ⇒ Object
- #stpmax=(rb_numeric) ⇒ Object
- #stpmin ⇒ Object
- #stpmin=(rb_numeric) ⇒ Object
-
#update(attributes = {}) ⇒ Object
(also: #update_attributes)
Updates all the attributes from the passed-in hash.
- #valid? ⇒ Boolean
- #valid_algorithm? ⇒ Boolean
- #validate ⇒ Object
Constructor Details
#initialize(*args) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'ext/wapiti/native.c', line 96 static VALUE (int argc, VALUE *argv, VALUE self) { opt_t* = (self); * = opt_defaults; if (->maxiter == 0) { ->maxiter = INT_MAX; } // copy the default algorithm name to the heap so that all strings // are on the heap char* tmp = calloc(strlen(->algo), sizeof(char)); memcpy(tmp, ->algo, strlen(->algo)); ->algo = tmp; if (argc > 1) { rb_raise(rb_const_get(rb_mKernel, rb_intern("ArgumentError")), "wrong number of arguments (%d for 0..1)", argc); } // set defaults if (argc) { Check_Type(argv[0], T_HASH); (void)rb_funcall(self, rb_intern("update"), 1, argv[0]); } // yield self if block_given? if (rb_block_given_p()) { rb_yield(self); } return self; } |
Instance Attribute Details
#compress ⇒ Object Also known as: compress?
Returns the value of attribute compress.
28 29 30 |
# File 'lib/wapiti/options.rb', line 28 def compress @compress end |
Class Method Details
.algorithms ⇒ Object
Returns the list of supported algorithm options.
22 23 24 |
# File 'lib/wapiti/options.rb', line 22 def algorithms @algorithms ||= %w{ l-bfgs sgd-l1 bcd rprop rprop+ rprop- auto }.freeze end |
.attribute_names ⇒ Object
Returns a sorted list of available option attributes.
9 10 11 12 13 14 |
# File 'lib/wapiti/options.rb', line 9 def attribute_names @attribute_names ||= %w{ stop_window convergence_window posterior max_iterations jobsize threads rho1 rho2 stop_epsilon score check algorithm pattern development_data maxent compact sparse skip_tokens compress }.sort.map(&:to_sym).freeze end |
.defaults ⇒ Object
Returns the default options.
17 18 19 |
# File 'lib/wapiti/options.rb', line 17 def defaults @defaults ||= new.attributes end |
Instance Method Details
#<=>(other) ⇒ Object
118 119 120 |
# File 'lib/wapiti/options.rb', line 118 def <=>(other) other.respond_to?(:attributes) ? attributes <=> other.attributes : nil end |
#[](name) ⇒ Object
Returns the value of the attribute identified by name or nil if there is no such attribute.
34 35 36 |
# File 'lib/wapiti/options.rb', line 34 def [](name) has_attribute?(name) ? send(name) : nil end |
#[]=(name, value) ⇒ Object
Updates the value of the attribute identified by name with the passed-in value.
40 41 42 43 |
# File 'lib/wapiti/options.rb', line 40 def []=(name, value) raise ArgumentError, "bad attribute name: #{name}" unless has_attribute?(name) send("#{name}=", value) end |
#algorithm ⇒ Object Also known as: algo
438 439 440 441 |
# File 'ext/wapiti/native.c', line 438 static VALUE (VALUE self) { const char *algorithm = (self)->algo; return rb_str_new2(algorithm ? algorithm : ""); } |
#algorithm=(rb_string) ⇒ Object Also known as: algo=
443 444 445 446 447 448 |
# File 'ext/wapiti/native.c', line 443 static VALUE (VALUE self, VALUE rb_string) { opt_t * = (self); copy_string((char**)&(->algo), rb_string); return rb_string; } |
#alpha ⇒ Object
270 271 272 |
# File 'ext/wapiti/native.c', line 270 static VALUE (VALUE self) { return rb_float_new((self)->sgdl1.alpha); } |
#alpha=(rb_numeric) ⇒ Object
274 275 276 277 |
# File 'ext/wapiti/native.c', line 274 static VALUE (VALUE self, VALUE rb_numeric) { (self)->sgdl1.alpha = NUM2DBL(rb_numeric); return rb_numeric; } |
#attributes ⇒ Object Also known as: to_hash
Returns a hash of all the attributes with their names and values.
76 77 78 |
# File 'lib/wapiti/options.rb', line 76 def attributes Hash[*Options.attribute_names.map { |a| [a, send(a)] }.flatten] end |
#bcd ⇒ Object
64 65 66 |
# File 'lib/wapiti/options.rb', line 64 def bcd { :kappa => kappa } end |
#check ⇒ Object Also known as: check?
355 356 357 |
# File 'ext/wapiti/native.c', line 355 static VALUE (VALUE self) { return (self)->check ? Qtrue : Qfalse; } |
#check=(rb_boolean) ⇒ Object
359 360 361 362 |
# File 'ext/wapiti/native.c', line 359 static VALUE (VALUE self, VALUE rb_boolean) { (self)->check = !(TYPE(rb_boolean) == T_NIL || !rb_boolean); return rb_boolean; } |
#clip ⇒ Object
391 392 393 |
# File 'ext/wapiti/native.c', line 391 static VALUE (VALUE self) { return (self)->lbfgs.clip ? Qtrue : Qfalse; } |
#clip=(rb_boolean) ⇒ Object
395 396 397 398 |
# File 'ext/wapiti/native.c', line 395 static VALUE (VALUE self, VALUE rb_boolean) { (self)->lbfgs.clip = !(TYPE(rb_boolean) == T_NIL || !rb_boolean); return rb_boolean; } |
#compact ⇒ Object Also known as: compact?
337 338 339 |
# File 'ext/wapiti/native.c', line 337 static VALUE (VALUE self) { return (self)->compact ? Qtrue : Qfalse; } |
#compact=(rb_boolean) ⇒ Object
341 342 343 344 |
# File 'ext/wapiti/native.c', line 341 static VALUE (VALUE self, VALUE rb_boolean) { (self)->compact = !(TYPE(rb_boolean) == T_NIL || !rb_boolean); return rb_boolean; } |
#cutoff ⇒ Object
400 401 402 |
# File 'ext/wapiti/native.c', line 400 static VALUE (VALUE self) { return (self)->rprop.cutoff ? Qtrue : Qfalse; } |
#cutoff=(rb_boolean) ⇒ Object
404 405 406 407 |
# File 'ext/wapiti/native.c', line 404 static VALUE (VALUE self, VALUE rb_boolean) { (self)->rprop.cutoff = !(TYPE(rb_boolean) == T_NIL || !rb_boolean); return rb_boolean; } |
#development_data ⇒ Object Also known as: devel
450 451 452 453 |
# File 'ext/wapiti/native.c', line 450 static VALUE (VALUE self) { char *development_data = (self)->devel; return rb_str_new2(development_data ? development_data : ""); } |
#development_data=(rb_string) ⇒ Object Also known as: devel=
455 456 457 458 459 460 |
# File 'ext/wapiti/native.c', line 455 static VALUE (VALUE self, VALUE rb_string) { opt_t * = (self); copy_string(&(->devel), rb_string); return rb_string; } |
#eta0 ⇒ Object
261 262 263 |
# File 'ext/wapiti/native.c', line 261 static VALUE (VALUE self) { return rb_float_new((self)->sgdl1.eta0); } |
#eta0=(rb_numeric) ⇒ Object
265 266 267 268 |
# File 'ext/wapiti/native.c', line 265 static VALUE (VALUE self, VALUE rb_numeric) { (self)->sgdl1.eta0 = NUM2DBL(rb_numeric); return rb_numeric; } |
#has_attribute?(attribute) ⇒ Boolean
82 83 84 |
# File 'lib/wapiti/options.rb', line 82 def has_attribute?(attribute) Options.attribute_names.include?(attribute) end |
#histsz ⇒ Object
209 210 211 |
# File 'ext/wapiti/native.c', line 209 static VALUE (VALUE self) { return INT2FIX((self)->lbfgs.histsz); } |
#histsz=(rb_fixnum) ⇒ Object
213 214 215 216 217 218 |
# File 'ext/wapiti/native.c', line 213 static VALUE (VALUE self, VALUE rb_fixnum) { Check_Type(rb_fixnum, T_FIXNUM); (self)->lbfgs.histsz = FIX2INT(rb_fixnum); return rb_fixnum; } |
#jobsize ⇒ Object
183 184 185 |
# File 'ext/wapiti/native.c', line 183 static VALUE (VALUE self) { return INT2FIX((self)->jobsize); } |
#jobsize=(rb_fixnum) ⇒ Object
187 188 189 190 191 192 193 194 |
# File 'ext/wapiti/native.c', line 187 static VALUE (VALUE self, VALUE rb_fixnum) { opt_t * = (self); Check_Type(rb_fixnum, T_FIXNUM); ->jobsize = FIX2INT(rb_fixnum); return rb_fixnum; } |
#kappa ⇒ Object
279 280 281 |
# File 'ext/wapiti/native.c', line 279 static VALUE (VALUE self) { return rb_float_new((self)->bcd.kappa); } |
#kappa=(rb_numeric) ⇒ Object
283 284 285 286 |
# File 'ext/wapiti/native.c', line 283 static VALUE (VALUE self, VALUE rb_numeric) { (self)->bcd.kappa = NUM2DBL(rb_numeric); return rb_numeric; } |
#lbfgs ⇒ Object
56 57 58 |
# File 'lib/wapiti/options.rb', line 56 def lbfgs { :clip => clip, :histsz => histsz, :maxls => maxls } end |
#lblpost ⇒ Object Also known as: lblpost?, posterior, posterior?
382 383 384 |
# File 'ext/wapiti/native.c', line 382 static VALUE (VALUE self) { return (self)->lblpost ? Qtrue : Qfalse; } |
#lblpost=(rb_boolean) ⇒ Object Also known as: posterior=
386 387 388 389 |
# File 'ext/wapiti/native.c', line 386 static VALUE (VALUE self, VALUE rb_boolean) { (self)->lblpost = !(TYPE(rb_boolean) == T_NIL || !rb_boolean); return rb_boolean; } |
#maxent ⇒ Object Also known as: maxent?
Boolean Accessors
328 329 330 |
# File 'ext/wapiti/native.c', line 328 static VALUE (VALUE self) { return (self)->maxent ? Qtrue : Qfalse; } |
#maxent=(rb_boolean) ⇒ Object
332 333 334 335 |
# File 'ext/wapiti/native.c', line 332 static VALUE (VALUE self, VALUE rb_boolean) { (self)->maxent = !(TYPE(rb_boolean) == T_NIL || !rb_boolean); return rb_boolean; } |
#maxiter ⇒ Object Also known as: max_iterations
170 171 172 |
# File 'ext/wapiti/native.c', line 170 static VALUE (VALUE self) { return INT2FIX((self)->maxiter); } |
#maxiter=(rb_fixnum) ⇒ Object Also known as: max_iterations=
174 175 176 177 178 179 180 181 |
# File 'ext/wapiti/native.c', line 174 static VALUE (VALUE self, VALUE rb_fixnum) { opt_t * = (self); Check_Type(rb_fixnum, T_FIXNUM); ->maxiter = FIX2INT(rb_fixnum); return rb_fixnum; } |
#maxls ⇒ Object
220 221 222 |
# File 'ext/wapiti/native.c', line 220 static VALUE (VALUE self) { return INT2FIX((self)->lbfgs.maxls); } |
#maxls=(rb_fixnum) ⇒ Object
224 225 226 227 228 229 |
# File 'ext/wapiti/native.c', line 224 static VALUE (VALUE self, VALUE rb_fixnum) { Check_Type(rb_fixnum, T_FIXNUM); (self)->lbfgs.maxls = FIX2INT(rb_fixnum); return rb_fixnum; } |
#model ⇒ Object
426 427 428 429 |
# File 'ext/wapiti/native.c', line 426 static VALUE (VALUE self) { const char *model = (self)->model; return rb_str_new2(model ? model : ""); } |
#model=(rb_string) ⇒ Object
431 432 433 434 435 436 |
# File 'ext/wapiti/native.c', line 431 static VALUE (VALUE self, VALUE rb_string) { opt_t * = (self); copy_string(&(->model), rb_string); return rb_string; } |
#nbest ⇒ Object
Fixnum Accessors
135 136 137 |
# File 'ext/wapiti/native.c', line 135 static VALUE (VALUE self) { return INT2FIX((self)->nbest); } |
#nbest=(rb_fixnum) ⇒ Object
139 140 141 142 143 144 |
# File 'ext/wapiti/native.c', line 139 static VALUE (VALUE self, VALUE rb_fixnum) { Check_Type(rb_fixnum, T_FIXNUM); (self)->nbest = FIX2INT(rb_fixnum); return rb_fixnum; } |
#nthread ⇒ Object Also known as: threads
196 197 198 |
# File 'ext/wapiti/native.c', line 196 static VALUE (VALUE self) { return INT2FIX((self)->nthread); } |
#nthread=(rb_fixnum) ⇒ Object Also known as: threads=
200 201 202 203 204 205 206 207 |
# File 'ext/wapiti/native.c', line 200 static VALUE (VALUE self, VALUE rb_fixnum) { opt_t * = (self); Check_Type(rb_fixnum, T_FIXNUM); ->nthread = FIX2INT(rb_fixnum); return rb_fixnum; } |
#objwin ⇒ Object Also known as: convergence_window
158 159 160 |
# File 'ext/wapiti/native.c', line 158 static VALUE (VALUE self) { return INT2FIX((self)->objwin); } |
#objwin=(rb_fixnum) ⇒ Object Also known as: convergence_window=
162 163 164 165 166 167 |
# File 'ext/wapiti/native.c', line 162 static VALUE (VALUE self, VALUE rb_fixnum) { Check_Type(rb_fixnum, T_FIXNUM); (self)->objwin = FIX2INT(rb_fixnum); return rb_fixnum; } |
#outsc ⇒ Object Also known as: outsc?, score, score?
373 374 375 |
# File 'ext/wapiti/native.c', line 373 static VALUE (VALUE self) { return (self)->outsc ? Qtrue : Qfalse; } |
#outsc=(rb_boolean) ⇒ Object Also known as: score=
377 378 379 380 |
# File 'ext/wapiti/native.c', line 377 static VALUE (VALUE self, VALUE rb_boolean) { (self)->outsc = !(TYPE(rb_boolean) == T_NIL || !rb_boolean); return rb_boolean; } |
#pattern ⇒ Object Also known as: template
String Accessors
414 415 416 417 |
# File 'ext/wapiti/native.c', line 414 static VALUE (VALUE self) { const char *pattern = (self)->pattern; return rb_str_new2(pattern ? pattern : ""); } |
#pattern=(rb_string) ⇒ Object Also known as: template=
419 420 421 422 423 424 |
# File 'ext/wapiti/native.c', line 419 static VALUE (VALUE self, VALUE rb_string) { opt_t * = (self); copy_string((char**)&(->pattern), rb_string); return rb_string; } |
#rho1 ⇒ Object
Float Accessors
234 235 236 |
# File 'ext/wapiti/native.c', line 234 static VALUE (VALUE self) { return rb_float_new((self)->rho1); } |
#rho1=(rb_numeric) ⇒ Object
238 239 240 241 |
# File 'ext/wapiti/native.c', line 238 static VALUE (VALUE self, VALUE rb_numeric) { (self)->rho1 = NUM2DBL(rb_numeric); return rb_numeric; } |
#rho2 ⇒ Object
243 244 245 |
# File 'ext/wapiti/native.c', line 243 static VALUE (VALUE self) { return rb_float_new((self)->rho2); } |
#rho2=(rb_numeric) ⇒ Object
247 248 249 250 |
# File 'ext/wapiti/native.c', line 247 static VALUE (VALUE self, VALUE rb_numeric) { (self)->rho2 = NUM2DBL(rb_numeric); return rb_numeric; } |
#rprop ⇒ Object
68 69 70 71 72 73 |
# File 'lib/wapiti/options.rb', line 68 def rprop { :stpmin => stpmin, :stpmax => stpmax, :stpinc => stpinc, :stpdec => stpdec, :cutoff => cutoff } end |
#sgdl1 ⇒ Object
60 61 62 |
# File 'lib/wapiti/options.rb', line 60 def sgdl1 { :eta0 => eta0, :alpha => alpha } end |
#skip_tokens ⇒ Object Also known as: skip_tokens?
364 365 366 |
# File 'ext/wapiti/native.c', line 364 static VALUE (VALUE self) { return (self)->label ? Qtrue : Qfalse; } |
#skip_tokens=(rb_boolean) ⇒ Object
368 369 370 371 |
# File 'ext/wapiti/native.c', line 368 static VALUE (VALUE self, VALUE rb_boolean) { (self)->label = !(TYPE(rb_boolean) == T_NIL || !rb_boolean); return rb_boolean; } |
#sparse ⇒ Object Also known as: sparse?
346 347 348 |
# File 'ext/wapiti/native.c', line 346 static VALUE (VALUE self) { return (self)->sparse ? Qtrue : Qfalse; } |
#sparse=(rb_boolean) ⇒ Object
350 351 352 353 |
# File 'ext/wapiti/native.c', line 350 static VALUE (VALUE self, VALUE rb_boolean) { (self)->sparse = !(TYPE(rb_boolean) == T_NIL || !rb_boolean); return rb_boolean; } |
#stopeps ⇒ Object Also known as: stop_epsilon
252 253 254 |
# File 'ext/wapiti/native.c', line 252 static VALUE (VALUE self) { return rb_float_new((self)->stopeps); } |
#stopeps=(rb_numeric) ⇒ Object Also known as: stop_epsilon=
256 257 258 259 |
# File 'ext/wapiti/native.c', line 256 static VALUE (VALUE self, VALUE rb_numeric) { (self)->stopeps = NUM2DBL(rb_numeric); return rb_numeric; } |
#stopwin ⇒ Object Also known as: stop_window
Option Accessors
147 148 149 |
# File 'ext/wapiti/native.c', line 147 static VALUE (VALUE self) { return INT2FIX((self)->stopwin); } |
#stopwin=(rb_fixnum) ⇒ Object Also known as: stop_window=
151 152 153 154 155 156 |
# File 'ext/wapiti/native.c', line 151 static VALUE (VALUE self, VALUE rb_fixnum) { Check_Type(rb_fixnum, T_FIXNUM); (self)->stopwin = FIX2INT(rb_fixnum); return rb_fixnum; } |
#stpdec ⇒ Object
315 316 317 |
# File 'ext/wapiti/native.c', line 315 static VALUE (VALUE self) { return rb_float_new((self)->rprop.stpdec); } |
#stpdec=(rb_numeric) ⇒ Object
319 320 321 322 |
# File 'ext/wapiti/native.c', line 319 static VALUE (VALUE self, VALUE rb_numeric) { (self)->rprop.stpdec = NUM2DBL(rb_numeric); return rb_numeric; } |
#stpinc ⇒ Object
306 307 308 |
# File 'ext/wapiti/native.c', line 306 static VALUE (VALUE self) { return rb_float_new((self)->rprop.stpinc); } |
#stpinc=(rb_numeric) ⇒ Object
310 311 312 313 |
# File 'ext/wapiti/native.c', line 310 static VALUE (VALUE self, VALUE rb_numeric) { (self)->rprop.stpinc = NUM2DBL(rb_numeric); return rb_numeric; } |
#stpmax ⇒ Object
297 298 299 |
# File 'ext/wapiti/native.c', line 297 static VALUE (VALUE self) { return rb_float_new((self)->rprop.stpmax); } |
#stpmax=(rb_numeric) ⇒ Object
301 302 303 304 |
# File 'ext/wapiti/native.c', line 301 static VALUE (VALUE self, VALUE rb_numeric) { (self)->rprop.stpmax = NUM2DBL(rb_numeric); return rb_numeric; } |
#stpmin ⇒ Object
288 289 290 |
# File 'ext/wapiti/native.c', line 288 static VALUE (VALUE self) { return rb_float_new((self)->rprop.stpmin); } |
#stpmin=(rb_numeric) ⇒ Object
292 293 294 295 |
# File 'ext/wapiti/native.c', line 292 static VALUE (VALUE self, VALUE rb_numeric) { (self)->rprop.stpmin = NUM2DBL(rb_numeric); return rb_numeric; } |
#update(attributes = {}) ⇒ Object Also known as: update_attributes
Updates all the attributes from the passed-in hash.
46 47 48 49 50 51 52 |
# File 'lib/wapiti/options.rb', line 46 def update(attributes = {}) attributes.each_pair do |k,v| mid = "#{k}=" send(mid, v) if respond_to?(mid) end self end |
#valid? ⇒ Boolean
90 91 92 |
# File 'lib/wapiti/options.rb', line 90 def valid? validate.empty? end |
#valid_algorithm? ⇒ Boolean
86 87 88 |
# File 'lib/wapiti/options.rb', line 86 def valid_algorithm? self.class.algorithms.include?(algorithm) end |
#validate ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/wapiti/options.rb', line 94 def validate e = [] %w{ threads jobsize alpha histsz maxls eta0 alpha nbest }.each do |name| e << "invalid value for #{name}: #{send(name)}" unless send(name) > 0 end %w{ rho1 rho2 }.each do |name| e << "invalid value for #{name}: #{send(name)}" unless send(name) >= 0.0 end e << "unknown algorithm: #{algorithm}" unless valid_algorithm? e << "BCD not supported for training maxent models" if maxent && algorithm == 'bcd' e end |