giuse/machine_learning_workbench

View on GitHub

Showing 443 of 443 total issues

Assignment Branch Condition size for initialize_distribution is too high. [60.04/15]
Open

    def initialize_distribution mu_init: 0, sigma_init: 1
      @mu = case mu_init
        when Range # initialize with random in range
          raise ArgumentError, "mu_init: `Range` start/end in `Float`s" \
            unless mu_init.first.kind_of?(Float) && mu_init.last.kind_of?(Float)

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Assignment Branch Condition size for sorted_inds_lst is too high. [43.5/15]
Open

    def sorted_inds_lst
      # Build samples and inds from the list of blocks
      samples_lst, inds_lst = blocks.map do |xnes|
        samples = xnes.standard_normal_samples
        inds = xnes.move_inds(samples)

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [30/10]
Open

    def initialize_distribution mu_init: 0, sigma_init: 1
      @mu = case mu_init
        when Range # initialize with random in range
          raise ArgumentError, "mu_init: `Range` start/end in `Float`s" \
            unless mu_init.first.kind_of?(Float) && mu_init.last.kind_of?(Float)

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method encode has 94 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def encode vec, type: encoding_type
      case type
      when :most_similar
        simils = similarities vec
        code = simils.max_index
Severity: Major
Found in lib/machine_learning_workbench/compressor/vector_quantization.rb - About 3 hrs to fix

    Method initialize_distribution has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize_distribution mu_init: 0, sigma_init: 1
          @mu = case mu_init
            when Range # initialize with random in range
              raise ArgumentError, "mu_init: `Range` start/end in `Float`s" \
                unless mu_init.first.kind_of?(Float) && mu_init.last.kind_of?(Float)

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Assignment Branch Condition size for train is too high. [28.79/15]
    Open

        def train picks: sorted_inds
          g_mu = utils.dot(picks)
          g_log_sigma = popsize.times.inject(NArray.zeros sigma.shape) do |sum, i|
            u = utils[i]
            ind = picks[i, true]

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Method has too many lines. [20/10]
    Open

        def initialize_distribution mu_init: 0, sigma_init: 1
          @mu = case mu_init
            when Array
              raise ArgumentError unless mu_init.size == ndims
              NArray[mu_init]

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Assignment Branch Condition size for train is too high. [25.3/15]
    Open

        def train picks: sorted_inds
          g_mu = utils.dot(picks)
          # g_sigma = utils.dot(picks.row_norms**2 - ndims).first # back to scalar
          row_norms = NLinalg.norm picks, 2, axis:1
          g_sigma = utils.dot(row_norms**2 - ndims)[0] # back to scalar

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Cyclomatic complexity for initialize_distribution is too high. [16/6]
    Open

        def initialize_distribution mu_init: 0, sigma_init: 1
          @mu = case mu_init
            when Range # initialize with random in range
              raise ArgumentError, "mu_init: `Range` start/end in `Float`s" \
                unless mu_init.first.kind_of?(Float) && mu_init.last.kind_of?(Float)

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Method encode has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def encode vec, type: encoding_type
          case type
          when :most_similar
            simils = similarities vec
            code = simils.max_index
    Severity: Minor
    Found in lib/machine_learning_workbench/compressor/vector_quantization.rb - About 2 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method has too many lines. [18/10]
    Open

        def sorted_inds_lst
          # Build samples and inds from the list of blocks
          samples_lst, inds_lst = blocks.map do |xnes|
            samples = xnes.standard_normal_samples
            inds = xnes.move_inds(samples)

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Method has too many lines. [18/10]
    Open

        def initialize_distribution mu_init: 0, sigma_init: 1
          @mu = case mu_init
            when Array
              raise ArgumentError unless mu_init.size == ndims
              NArray[mu_init]

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Assignment Branch Condition size for initialize is too high. [22.41/15]
    Open

        def initialize ndims_lst, obj_fn, opt_type, parallel_fit: false, rseed: nil, parallel_update: false, **init_opts
          # mu_init: 0, sigma_init: 1
          # init_opts = {rseed: rseed, mu_init: mu_init, sigma_init: sigma_init}
          # TODO: accept list of `mu_init`s and `sigma_init`s
          @ndims_lst, @obj_fn, @opt_type, @parallel_fit = ndims_lst, obj_fn, opt_type, parallel_fit

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Perceived complexity for initialize_distribution is too high. [12/7]
    Open

        def initialize_distribution mu_init: 0, sigma_init: 1
          @mu = case mu_init
            when Range # initialize with random in range
              raise ArgumentError, "mu_init: `Range` start/end in `Float`s" \
                unless mu_init.first.kind_of?(Float) && mu_init.last.kind_of?(Float)

    This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

    Example:

    def my_method                   # 1
      if cond                       # 1
        case var                    # 2 (0.8 + 4 * 0.2, rounded)
        when 1 then func_one
        when 2 then func_two
        when 3 then func_three
        when 4..10 then func_other
        end
      else                          # 1
        do_something until a && b   # 2
      end                           # ===
    end                             # 7 complexity points

    Assignment Branch Condition size for activate_layer is too high. [20.22/15]
    Open

        def activate_layer nlay
          # Mark begin and end of recursion outputs in current state
          begin_recur = nneurs(nlay)
          end_recur = nneurs(nlay) + nneurs(nlay+1)
          # Copy the level's last-time activation to the current input recurrency

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for initialize_distribution is too high. [20.15/15]
    Open

        def initialize_distribution mu_init: 0, sigma_init: 1
          @mu = case mu_init
            when Array
              raise ArgumentError unless mu_init.size == ndims
              NArray[mu_init]

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for train is too high. [19.31/15]
    Open

        def train picks: sorted_inds
          g_mu = utils.dot(picks)
          g_sigma = utils.dot(picks**2 - 1)
          @mu += sigma.dot(g_mu.transpose).transpose * lrate
          @variances *= (g_sigma * lrate / 2).exponential.flatten

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for exponential is too high. [19.21/15]
    Open

        def exponential
          raise ArgumentError if ndim > 2
          # special case: one-dimensional matrix: just exponentiate the values
          return NMath.exp(self) if (ndim == 1) || shape.include?(1)
          # at this point we need to validate it is a square matrix

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for activate is too high. [18.28/15]
    Open

        def activate input
          raise ArgumentError unless input.size == struct.first
          # load input in first state
          state[0][0...struct.first] = input
          # activate layers in sequence

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Method has too many lines. [13/10]
    Open

        def initialize ndims_lst, obj_fn, opt_type, parallel_fit: false, rseed: nil, parallel_update: false, **init_opts
          # mu_init: 0, sigma_init: 1
          # init_opts = {rseed: rseed, mu_init: mu_init, sigma_init: sigma_init}
          # TODO: accept list of `mu_init`s and `sigma_init`s
          @ndims_lst, @obj_fn, @opt_type, @parallel_fit = ndims_lst, obj_fn, opt_type, parallel_fit

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

    Severity
    Category
    Status
    Source
    Language