giuse/machine_learning_workbench

View on GitHub

Showing 443 of 443 total issues

Assignment Branch Condition size for initialize_distribution is too high. [17.97/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

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

    def load_weights weights
      raise ArgumentError unless weights.size == nweights
      weights = weights.to_na unless weights.kind_of? NArray
      from = 0
      @layers = layer_shapes.collect do |shape|

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_one is too high. [16.88/15]
Open

    def train_one vec, eps: equal_simil
      mses = centrs.map do |centr|
        ((centr-vec)**2).sum / centr.size
      end
      # BEWARE: I am currently not handling the case where we run out of centroids!

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 map is too high. [16.55/15]
Open

    def map dim=0
      raise ArgumentError unless dim.kind_of?(Integer) && dim.between?(0,ndim)
      # TODO: return iterator instead of raise
      raise NotImplementedError unless block_given?
      indices = [true]*ndim

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 sorted_inds_lst is too high. [7/6]
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 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.

Cyclomatic complexity for initialize_distribution is too high. [7/6]
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 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 sorted_inds_lst has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
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)

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 sorted_inds has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def sorted_inds
      # Xumo::NArray implements the Box-Muller, but no random seed (yet)
      samples = standard_normal_samples
      # samples = NArray.new([popsize, ndims]).rand_norm(0,1)
      inds = move_inds(samples)

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 initialize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize ndims, obj_fn, opt_type, rseed: nil, mu_init: 0, sigma_init: 1, parallel_fit: false, rescale_popsize: 1, rescale_lrate: 1, utilities: nil, popsize: nil, lrate: nil
      raise ArgumentError, "opt_type: #{opt_type}" unless [:min, :max].include? opt_type
      raise ArgumentError, "obj_fn not callable: #{obj_fn}" unless obj_fn.respond_to? :call
      raise ArgumentError, "utilities only if popsize" if utilities && popsize.nil?
      raise ArgumentError, "wrong sizes" if utilities && utilities.size != popsize

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 initialize_distribution has 30 lines of code (exceeds 25 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)

    Block has too many lines. [33/25]
    Open

    Gem::Specification.new do |spec|
      spec.name          = "machine_learning_workbench"
      spec.version       = `git describe`
      spec.author        = "Giuseppe Cuccu"
      spec.email         = "giuseppe.cuccu@gmail.com"
    Severity: Minor
    Found in machine_learning_workbench.gemspec by rubocop

    This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

    Method initialize_distribution has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    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]

    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 initialize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize ncentrs:, dims:, vrange:, lrate:, simil_type: nil, encoding_type: nil, init_centr_vrange: nil, rseed: Random.new_seed
    
          @rng = Random.new rseed # TODO: RNG CURRENTLY NOT USED!!
    
          @dims = Array(dims)
    Severity: Minor
    Found in lib/machine_learning_workbench/compressor/vector_quantization.rb - About 35 mins 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

    Avoid parameter lists longer than 5 parameters. [7/5]
    Open

        def initialize ndims_lst, obj_fn, opt_type, parallel_fit: false, rseed: nil, parallel_update: false, **init_opts

    This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

          @mu = case mu_init
            when Array
              raise ArgumentError unless mu_init.size == ndims
              NArray[mu_init]
            when Numeric
    lib/machine_learning_workbench/optimizer/natural_evolution_strategies/snes.rb on lines 10..17

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 31.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Identical blocks of code found in 2 locations. Consider refactoring.
    Open

          @mu = case mu_init
            when Array
              raise ArgumentError unless mu_init.size == ndims
              NArray[mu_init]
            when Numeric
    lib/machine_learning_workbench/optimizer/natural_evolution_strategies/rnes.rb on lines 9..16

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 31.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Line is too long. [84/80]
    Open

    # nes = WB::Optimizer::NaturalEvolutionStrategies::BDNES.new NET.nweights_per_layer,
    Severity: Minor
    Found in examples/neuroevolution.rb by rubocop

    Line is too long. [87/80]
    Open

    # NOTE: In practical applications it is best to delegate parallelization to the fitness
    Severity: Minor
    Found in examples/neuroevolution.rb by rubocop

    Line is too long. [85/80]
    Open

    # achieved by passing  an objective function defined on a _list_ of weight-lists, and
    Severity: Minor
    Found in examples/neuroevolution.rb by rubocop

    unexpected token error (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
    Open

    raise "Download the JAFFE dataset in your home dir" if image_files&.empty?
    Severity: Minor
    Found in examples/image_compression.rb by rubocop
    Severity
    Category
    Status
    Source
    Language