SergioFierens/ai4r

View on GitHub

Showing 15 of 28 total issues

Method populate_centroids has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
Open

      def populate_centroids(populate_method, number_of_clusters=@number_of_clusters)
        tried_indexes = []
        case populate_method
        when 'random' # for initial assignment (without the :centroid_indices option) and for reassignment of empty cluster centroids (with :on_empty option 'random')
          while @centroids.length < number_of_clusters && 
Severity: Minor
Found in lib/ai4r/clusterers/k_means.rb - About 5 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 distance has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

      def distance(a, b)
        d = 0
        a.each_with_index do |att_a, i|
          att_b = b[i]
          if att_a.nil?
Severity: Minor
Found in lib/ai4r/classifiers/ib1.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

Class DataSet has 21 methods (exceeds 20 allowed). Consider refactoring.
Open

    class DataSet

      attr_reader :data_labels, :data_items

      # Create a new DataSet. By default, empty.
Severity: Minor
Found in lib/ai4r/data/data_set.rb - About 2 hrs to fix

    Method build has 50 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def build(data)
            raise "Error instance must be passed" unless data.is_a?(DataSet)
            raise "Data should not be empty" if data.data_items.length == 0
            y_mean = data.get_mean_or_mode[data.num_attributes - 1]
    
    
    Severity: Minor
    Found in lib/ai4r/classifiers/simple_linear_regression.rb - About 2 hrs to fix

      Method build has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
      Open

            def build(data)
              raise "Error instance must be passed" unless data.is_a?(DataSet)
              raise "Data should not be empty" if data.data_items.length == 0
              y_mean = data.get_mean_or_mode[data.num_attributes - 1]
      
      
      Severity: Minor
      Found in lib/ai4r/classifiers/simple_linear_regression.rb - About 1 hr 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 populate_centroids has 39 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def populate_centroids(populate_method, number_of_clusters=@number_of_clusters)
              tried_indexes = []
              case populate_method
              when 'random' # for initial assignment (without the :centroid_indices option) and for reassignment of empty cluster centroids (with :on_empty option 'random')
                while @centroids.length < number_of_clusters && 
      Severity: Minor
      Found in lib/ai4r/clusterers/k_means.rb - About 1 hr to fix

        Method update_min_max has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

              def update_min_max(atts)
                atts.each_with_index do |att, i|
                  if att && att.is_a?(Numeric)
                    @min_values[i] = att if @min_values[i].nil? || @min_values[i] > att
                    @max_values[i] = att if @max_values[i].nil? || @max_values[i] < att
        Severity: Minor
        Found in lib/ai4r/classifiers/ib1.rb - About 1 hr 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 eval has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def eval(data)
                votes = Votes.new
                @pipes.each do |category, pipe|
                  pipe.each_with_index do |bounds, i|
                    if data[i].is_a? Numeric
        Severity: Minor
        Found in lib/ai4r/classifiers/hyperpipes.rb - About 55 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

        Method update_pipe has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

              def update_pipe(pipe, data_item)
                data_item[0...-1].each_with_index do |att, i|
                  if att.is_a? Numeric
                    pipe[i][:min] = att if att < pipe[i][:min]
                    pipe[i][:max] = att if att > pipe[i][:max]
        Severity: Minor
        Found in lib/ai4r/classifiers/hyperpipes.rb - About 55 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

        Method reproduce has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def self.reproduce(a, b)
                data_size = @@costs[0].length
                available = []
                0.upto(data_size-1) { |n| available << n }
                token = a.data[0]
        Severity: Minor
        Found in lib/ai4r/genetic_algorithm/genetic_algorithm.rb - About 45 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

        Method initialize has 6 arguments (exceeds 4 allowed). Consider refactoring.
        Open

              def initialize(nodes, learning_rate = 0.9, phase_one = 150, phase_two = 100,
                      phase_one_learning_rate = 0.1, phase_two_learning_rate = 0)
        Severity: Minor
        Found in lib/ai4r/som/two_phase_layer.rb - About 45 mins to fix

          Method min_entropy_index has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def min_entropy_index(data_examples, domain, flag_att=[])
                  min_entropy = nil
                  min_index = 0
                  domain[0..-2].each_index do |index|
                    unless flag_att.include?(index)
          Severity: Minor
          Found in lib/ai4r/classifiers/id3.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

          Method build has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def build(data_set, number_of_clusters)
                  @data_set = data_set
                  @number_of_clusters = number_of_clusters
                  raise ArgumentError, 'Length of centroid indices array differs from the specified number of clusters' unless @centroid_indices.empty? || @centroid_indices.length == @number_of_clusters
                  raise ArgumentError, 'Invalid value for on_empty' unless @on_empty == 'eliminate' || @on_empty == 'terminate' || @on_empty == 'random' || @on_empty == 'outlier'
          Severity: Minor
          Found in lib/ai4r/clusterers/k_means.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

          Method update_distance_matrix has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def update_distance_matrix(ci, cj)
                  ci, cj = cj, ci if cj > ci
                  distances_to_new_cluster = Array.new
                  (@distance_matrix.length+1).times do |cx|
                    if cx!= ci && cx!=cj
          Severity: Minor
          Found in lib/ai4r/clusterers/single_linkage.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

          Method build has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

                def build(data_set, number_of_clusters)
                  @data_set = data_set
                  @number_of_clusters = number_of_clusters
                  @clusters = [@data_set[0..-1]]
                  
          Severity: Minor
          Found in lib/ai4r/clusterers/diana.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

          Severity
          Category
          Status
          Source
          Language