kei500 / liblinear-ruby

MIT License
83 stars 8 forks source link

Quiet mode #5

Closed wvengen closed 7 years ago

wvengen commented 7 years ago

Thanks for the gem! I'm looking how to silence the (training) output. There is something like Liblinearswig.set_print_string_function but I don't really know how to use it.

kei500 commented 7 years ago

@wvengen

Thank you for your feedback. I'll try to find how to supress output. Please wait a moment.

kei500 commented 7 years ago

@wvengen

I've fixed this issue and released version 1.0.1. Please use Liblinear.quiet_mode to supuress output. See also README: https://github.com/kei500/liblinear-ruby#quiet--verbose-mode

Liblinear.quiet_mode
model = Liblinear.train(
  { solver_type: Liblinear::L2R_LR },
  [-1, -1, 1, 1],
  [[-2, -2], [-1, -1], [1, 1], [2, 2]],
)
puts Liblinear.predict(model, [0.5, 0.5])
# after
1.0

# before
iter  1 act 1.642e+00 pre 1.500e+00 delta 7.812e-01 f 2.773e+00 |g| 4.243e+00 CG   1
iter  2 act 8.240e-02 pre 7.642e-02 delta 7.812e-01 f 1.130e+00 |g| 7.279e-01 CG   1
iter  3 act 1.299e-03 pre 1.284e-03 delta 7.812e-01 f 1.048e+00 |g| 8.342e-02 CG   1
1.0

Thanks.

wvengen commented 7 years ago

Looks great, thanks a lot!

I'm sure you've thought about allowing a Ruby method to be called on print, I guess handling the callback was a bit involved. Or perhaps, even better, an IO stream to be passed, with nil meaning no output. Anyway, it's great as it is now :)