lib/svmkit/linear_model/svc.rb in svmkit-0.4.0 vs lib/svmkit/linear_model/svc.rb in svmkit-0.4.1

- old
+ new

@@ -49,11 +49,11 @@ # @param bias_scale [Float] The scale of the bias term. # @param max_iter [Integer] The maximum number of iterations. # @param batch_size [Integer] The size of the mini batches. # @param probability [Boolean] The flag indicating whether to perform probability estimation. # @param optimizer [Optimizer] The optimizer to calculate adaptive learning rate. - # Nadam is selected automatically on current version. + # If nil is given, Nadam is used. # @param random_seed [Integer] The seed value using to initialize the random generator. def initialize(reg_param: 1.0, fit_bias: false, bias_scale: 1.0, max_iter: 1000, batch_size: 20, probability: false, optimizer: nil, random_seed: nil) check_params_float(reg_param: reg_param, bias_scale: bias_scale) check_params_integer(max_iter: max_iter, batch_size: batch_size) @@ -66,10 +66,11 @@ @params[:bias_scale] = bias_scale @params[:max_iter] = max_iter @params[:batch_size] = batch_size @params[:probability] = probability @params[:optimizer] = optimizer + @params[:optimizer] ||= Optimizer::Nadam.new @params[:random_seed] = random_seed @params[:random_seed] ||= srand @weight_vec = nil @bias_term = nil @prob_param = nil @@ -192,10 +193,10 @@ samples = @params[:fit_bias] ? expand_feature(x) : x # Initialize some variables. n_samples, n_features = samples.shape rand_ids = [*0...n_samples].shuffle(random: @rng) weight_vec = Numo::DFloat.zeros(n_features) - optimizer = Optimizer::Nadam.new + optimizer = @params[:optimizer].dup # Start optimization. @params[:max_iter].times do |_t| # random sampling. subset_ids = rand_ids.shift(@params[:batch_size]) rand_ids.concat(subset_ids)