You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: probabilistic_output.rb
    path of file: ./repos/rumale/rumale-core/lib/rumale
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

require 'numo/narray'

module Rumale
  # Module for calculating posterior class probabilities with SVM outputs.
  # This module is used for internal processes.
  #
  # @example
  #   estimator = Rumale::
    
      def fit_sigmoid(df, bin_y, max_iter = 100, min_step = 1e-10, sigma = 1e-12)
        # Initialize some variables.
        n_samples = bin_y.size
        negative_label = bin_y.to_a.uniq.min
        pos = bin_y.ne(negative_label)
        neg = bin_y.eq(negative_label)
        n_pos_samples = pos.count
        n_neg_samples = neg.count
        target_probs = Numo::DFloat.zeros(n_samples)
        target_probs[pos] = (n_pos_samples + 1) / (n_pos_samples + 2.0)
        target_probs[neg] = 1 / (n_neg_samples + 2.0)
        alpha = 0.0
        beta = Math.log((n_neg_samples + 1) / (n_pos_samples + 1.0))
        err = error_function(target_probs, df, alpha, beta)
        # Optimize parameters for class porbability calculation.
        old_grad_vec = Numo::DFloat.zeros(2)
        max_iter.times do
          # Calculate gradient and hessian matrix.
          probs = predicted_probs(df, alpha, beta)
          grad_vec = gradient(target_probs, probs, df)
          hess_mat = hessian_matrix(probs, df, sigma)
          break if grad_vec.abs.lt(1e-5).count == 2
          break if (old_grad_vec - grad_vec).abs.sum < 1e-5

          old_grad_vec = grad_vec
          # Calculate Newton directions.
          dirs_vec = directions(grad_vec, hess_mat)
          grad_dir = grad_vec.dot(dirs_vec)
          stepsize = 2.0
          while stepsize >= min_step
            stepsize *= 0.5
            new_alpha = alpha + stepsize * dirs_vec[0]
            new_beta = beta + stepsize * dirs_vec[1]
            new_err = error_function(target_probs, df, new_alpha, new_beta)
            next unless new_err < err + 0.0001 * stepsize * grad_dir

            alpha = new_alpha
            beta = new_beta
            err = new_err
            break
          end
        end