SciRuby/distribution

View on GitHub

Showing 98 of 98 total issues

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

        def pchi2(n, y)
          if n == 1
            w = Distribution::Normal.p_value(1 - y / 2) # = p1.0-Distribution::Normal.cdf(y/2)
            w * w
          elsif n == 2
Severity: Minor
Found in lib/distribution/chisquare/ruby.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 cdf has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def cdf(aa, bb, sigma, epsilon = 0.0001, alpha = 2.5, max_iterations = 100) # :nodoc:
        fail "Doesn't work yet"
        a = [nil] + aa
        b = [nil] + bb
        m = aa.size
Severity: Minor
Found in lib/distribution/normalmultivariate.rb - About 1 hr to fix

    Method log_beta has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def log_beta(x, y, with_error = false)
              sign = nil
    
              fail(ArgumentError, 'x and y must be nonzero') if x == 0.0 || y == 0.0
              fail(ArgumentError, 'not defined for negative integers') if [x, y].any? { |v| v < 0 }
    Severity: Minor
    Found in lib/distribution/math_extension/incomplete_beta.rb - About 1 hr to fix

      Method q_large_x has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

              def q_large_x(a, x, with_error = false)
                d = d(a, x, with_error)
                d, d_err = d if with_error
                sum  = 1.0
                term = 1.0
      Severity: Minor
      Found in lib/distribution/math_extension/incomplete_gamma.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 f_continued_fraction has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

              def f_continued_fraction(a, x, with_error = false)
                hn = 1.0 # convergent
                cn = 1.0 / SMALL
                dn = 1.0
                n  = 2
      Severity: Minor
      Found in lib/distribution/math_extension/incomplete_gamma.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 cdf has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

              def cdf(z)
                return 0.0 if z < -12
                return 1.0 if z > 12
                return 0.5 if z == 0.0
      
      
      Severity: Minor
      Found in lib/distribution/normal/ruby.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 log_1plusx has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

              def log_1plusx(x, with_error = false)
                fail(ArgumentError, 'Range error: x must be > -1') if x <= -1
      
                if x.abs < Math::ROOT6_FLOAT_EPSILON
                  result = x * (1.0 + x * (C1 + x * (C2 + x * (C3 + x * (C4 + x * begin
      Severity: Minor
      Found in lib/distribution/math_extension/log_utilities.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 evaluate has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def evaluate(a, b, x, with_error = false)
                fail(ArgumentError, "Domain error: a(#{a}), b(#{b}) must be positive; x(#{x}) must be between 0 and 1, inclusive") if a <= 0 || b <= 0 || x < 0 || x > 1
                if x == 0
                  return with_error ? [0.0, 0.0] : 0.0
                elsif x == 1
      Severity: Minor
      Found in lib/distribution/math_extension/incomplete_beta.rb - About 1 hr to fix

        Method quantile has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

                def quantile(probability, n, m)
                  return Float::NAN if n <= 0.0 || m <= 0.0
        
                  if n == Float::INFINITY || n == -Float::INFINITY || m == Float::INFINITY || m == -Float::INFINITY
                    return 1.0
        Severity: Minor
        Found in lib/distribution/f/ruby.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 ptsub has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

                def ptsub(q, n)
                  q = q.to_f
                  if n == 1 && 0.001 < q && q < 0.01
                    eps = 1.0e-4
                  elsif n == 2 && q < 0.0001
        Severity: Minor
        Found in lib/distribution/t/ruby.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 evaluate has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def evaluate(x, with_error = false)
                  ax = x.abs
                  e = nil
        
                  if ax <= 1.0
        Severity: Minor
        Found in lib/distribution/math_extension/erfc.rb - About 1 hr to fix

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

                      s = 1.0 / x * (scale ? 1.0 : Math.exp(-x))
                      result_c = ChebyshevSeries.eval((8.0 / x - 5.0) / 3.0, :ae13, with_error)
                      result_c, result_c_err = result_c if with_error
                      result   = s * (1.0 + result_c)
                      error ||= (s * result_c_err) + 2.0 * Float::EPSILON * result.abs
          Severity: Major
          Found in lib/distribution/math_extension/exponential_integral.rb and 1 other location - About 1 hr to fix
          lib/distribution/math_extension/exponential_integral.rb on lines 21..26

          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 53.

          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

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

                      s = 1.0 / x * (scale ? 1.0 : Math.exp(-x))
                      result_c = ChebyshevSeries.eval((40.0 / x + 7.0) / 3.0, :ae12, with_error)
                      result_c, result_c_err = result_c if with_error
                      result   = s * (1.0 + result_c)
                      error ||= (s * result_c_err) + 2.0 * Float::EPSILON * result.abs
          Severity: Major
          Found in lib/distribution/math_extension/exponential_integral.rb and 1 other location - About 1 hr to fix
          lib/distribution/math_extension/exponential_integral.rb on lines 43..48

          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 53.

          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

          Method cdf_hull has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def cdf_hull(a, b, rho)
                    # puts "a:#{a} - b:#{b} - rho:#{rho}"
                    if a <= 0 && b <= 0 && rho <= 0
                      # puts "ruta 1"
                      aprime = a.quo(Math.sqrt(2.0 * (1.0 - rho**2)))
          Severity: Minor
          Found in lib/distribution/bivariatenormal/ruby.rb - About 1 hr to fix

            Method evaluate has 29 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                    def evaluate(x, with_error = false)
                      fail(ArgumentError, 'x must be positive') if x <= 0
                      if x < 0.5
                        STDERR.puts("Warning: Don't know error on lg_x, error for this function will be incorrect") if with_error
                        lg = Math.lgamma(x).first
            Severity: Minor
            Found in lib/distribution/math_extension/gammastar.rb - About 1 hr to fix

              Method unnormalized has 28 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                      def unnormalized(a, x, with_error = false)
                        fail(ArgumentError, 'x cannot be negative') if x < 0.0
              
                        if x == 0.0
                          result  = Math.gamma(a.to_f)
              Severity: Minor
              Found in lib/distribution/math_extension/incomplete_gamma.rb - About 1 hr to fix

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

                        def cdf_jantaravareerat(x, y, rho, s1 = 1, s2 = 1)
                          # Special cases
                          return 1 if x > LIMIT && y > LIMIT
                          return 0 if x < -LIMIT || y < -LIMIT
                          return Distribution::Normal.cdf(y) if  x > LIMIT
                Severity: Minor
                Found in lib/distribution/bivariatenormal/ruby.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 continued_fraction has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                        def continued_fraction(a, b, x, epsabs = nil, with_error = false)
                          num_term = 1
                          den_term = 1 - (a + b) * x.quo(a + 1)
                          k        = 0
                
                
                Severity: Minor
                Found in lib/distribution/math_extension/incomplete_beta.rb - About 1 hr to fix

                  Method d has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                          def d(a, x, with_error = false)
                            error = nil
                            if a < 10.0
                              ln_a = Math.lgamma(a + 1.0).first
                              lnr  = a * Math.log(x) - x - ln_a
                  Severity: Minor
                  Found in lib/distribution/math_extension/incomplete_gamma.rb - About 1 hr to fix

                    Method q has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                            def q(a, x, with_error = false)
                              fail(ArgumentError, 'Range Error: a and x must be non-negative') if a < 0.0 || x < 0.0
                              if x == 0.0
                                return with_error ? [1.0, 0.0] : 1.0
                              elsif a == 0.0
                    Severity: Minor
                    Found in lib/distribution/math_extension/incomplete_gamma.rb - About 1 hr to fix
                      Severity
                      Category
                      Status
                      Source
                      Language