SciRuby/distribution

View on GitHub
lib/distribution/math_extension/incomplete_gamma.rb

Summary

Maintainability
F
4 days
Test Coverage

Method q has a Cognitive Complexity of 30 (exceeds 5 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 4 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

File incomplete_gamma.rb has 340 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Distribution
  module MathExtension
    module IncompleteGamma
      NMAX  = 5000
      SMALL = Float::EPSILON**3
Severity: Minor
Found in lib/distribution/math_extension/incomplete_gamma.rb - About 4 hrs to fix

    Method q_series has 84 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def q_series(a, x, with_error = false)
              term1 = nil
              sum   = nil
              term2 = nil
              begin
    Severity: Major
    Found in lib/distribution/math_extension/incomplete_gamma.rb - About 3 hrs to fix

      Method d has a Cognitive Complexity of 23 (exceeds 5 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 3 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 unnormalized has a Cognitive Complexity of 20 (exceeds 5 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 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 p has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

              def p(a, x, with_error = false)
                fail(ArgumentError, 'Range Error: a must be positive, x must be non-negative') if a <= 0.0 || x < 0.0
                if x == 0.0
                  return with_error ? [0.0, 0.0] : 0.0
                elsif x < 20.0 || x < 0.5 * a
      Severity: Minor
      Found in lib/distribution/math_extension/incomplete_gamma.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 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 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 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

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

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

                    def q_asymptotic_uniform(a, x, with_error = false)
                      rta = Math.sqrt(a)
                      eps = (x - a).quo(a)
            
                      ln_term = Log.log_1plusx_minusx(eps, with_error)
            Severity: Minor
            Found in lib/distribution/math_extension/incomplete_gamma.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

            Avoid deeply nested control flow statements.
            Open

                        if x > a - Math.sqrt(a)
                          return q_continued_fraction(a, x, with_error)
                        else
                          p = p_series(a, x, with_error)
                          p, p_err = p if with_error
            Severity: Major
            Found in lib/distribution/math_extension/incomplete_gamma.rb - About 45 mins to fix

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

                      def q_series(a, x, with_error = false)
                        term1 = nil
                        sum   = nil
                        term2 = nil
                        begin
              Severity: Minor
              Found in lib/distribution/math_extension/incomplete_gamma.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

              Avoid deeply nested control flow statements.
              Open

                          return x <= 1.0e+06 ? q_continued_fraction(a, x, with_error) : q_large_x(a, x, with_error)
              Severity: Major
              Found in lib/distribution/math_extension/incomplete_gamma.rb - About 45 mins to fix

                Avoid too many return statements within this method.
                Open

                              return with_error ? [result, p_err + 2.0 * Float::EPSILON * result.abs] : result
                Severity: Major
                Found in lib/distribution/math_extension/incomplete_gamma.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                                return q_continued_fraction(a, x, with_error)
                  Severity: Major
                  Found in lib/distribution/math_extension/incomplete_gamma.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return q_series(a, x, with_error)
                    Severity: Major
                    Found in lib/distribution/math_extension/incomplete_gamma.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return with_error ? [result, 2.0 * (1.0 + a.abs) * Float::EPSILON * gax.abs] : result
                      Severity: Major
                      Found in lib/distribution/math_extension/incomplete_gamma.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return q_asymptotic_uniform_complement a, x, with_error
                        Severity: Major
                        Found in lib/distribution/math_extension/incomplete_gamma.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                      return x <= 1.0e+06 ? q_continued_fraction(a, x, with_error) : q_large_x(a, x, with_error)
                          Severity: Major
                          Found in lib/distribution/math_extension/incomplete_gamma.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return series(a.to_f, x.to_f, with_error)
                            Severity: Major
                            Found in lib/distribution/math_extension/incomplete_gamma.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                            return q_large_x_complement(a, x, with_error)
                              Severity: Major
                              Found in lib/distribution/math_extension/incomplete_gamma.rb - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return p_series(a, x, with_error)
                                Severity: Major
                                Found in lib/distribution/math_extension/incomplete_gamma.rb - About 30 mins to fix

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

                                                   c9 = -2.75573192239859e-6 *
                                                        (-2.8243487670469080 + lnx) *
                                                        (-2.3798494322701120 + lnx) *
                                                        (-1.9143674728689960 + lnx) *
                                                        (-1.3814529102920370 + lnx) *
                                  Severity: Minor
                                  Found in lib/distribution/math_extension/incomplete_gamma.rb and 1 other location - About 40 mins to fix
                                  lib/distribution/math_extension/incomplete_gamma.rb on lines 310..319

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

                                  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

                                                        c10 = -2.75573192239859e-7 *
                                                              (-2.9540329644556910 + lnx) *
                                                              (-2.5491366926991850 + lnx) *
                                                              (-2.1348279229279880 + lnx) *
                                                              (-1.6741881076349450 + lnx) *
                                  Severity: Minor
                                  Found in lib/distribution/math_extension/incomplete_gamma.rb and 1 other location - About 40 mins to fix
                                  lib/distribution/math_extension/incomplete_gamma.rb on lines 300..309

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

                                  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

                                                p = p_series(a, x, with_error)
                                                p, p_err = p if with_error
                                                result = 1.0 - p
                                                return with_error ? [result, p_err + 2.0 * Float::EPSILON * result.abs] : result
                                              end
                                  Severity: Minor
                                  Found in lib/distribution/math_extension/incomplete_gamma.rb and 1 other location - About 30 mins to fix
                                  lib/distribution/math_extension/incomplete_gamma.rb on lines 139..143

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

                                  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

                                              p = p_series(a, x, with_error)
                                              p, p_err = p if with_error
                                              result  = 1.0 - p
                                              return with_error ? [result, p_err + 2.0 * Float::EPSILON * result.abs] : result
                                            elsif a >= 1.0e+06 && (x - a) * (x - a) < a # difficult asymptotic regime, only way to do this region
                                  Severity: Minor
                                  Found in lib/distribution/math_extension/incomplete_gamma.rb and 1 other location - About 30 mins to fix
                                  lib/distribution/math_extension/incomplete_gamma.rb on lines 153..157

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

                                  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

                                          def q_large_x_complement(a, x, with_error = false)
                                            q = q_large_x(a, x, with_error)
                                            with_error ? [1.0 - q.first, q.last + 2.0 * Float::EPSILON * (1.0 - q.first).abs] : 1.0 - q
                                          end
                                  Severity: Minor
                                  Found in lib/distribution/math_extension/incomplete_gamma.rb and 1 other location - About 30 mins to fix
                                  lib/distribution/math_extension/incomplete_gamma.rb on lines 97..100

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

                                  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

                                          def q_continued_fraction_complement(a, x, with_error = false)
                                            q = q_continued_fraction(a, x, with_error)
                                            with_error ? [1.0 - q.first, q.last + 2.0 * Float::EPSILON * (1.0 - q.first).abs] : 1.0 - q
                                          end
                                  Severity: Minor
                                  Found in lib/distribution/math_extension/incomplete_gamma.rb and 1 other location - About 30 mins to fix
                                  lib/distribution/math_extension/incomplete_gamma.rb on lines 102..105

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

                                  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 3 locations. Consider refactoring.
                                  Open

                                              term1 = a * (c1 + a * (c2 + a * (c3 + a * (c4 + a * (c5 + a * (c6 + a * (c7 + a * (c8 + a * (c9 + a * c10)))))))))
                                  Severity: Minor
                                  Found in lib/distribution/math_extension/incomplete_gamma.rb and 2 other locations - About 20 mins to fix
                                  lib/distribution/math_extension.rb on lines 125..125
                                  lib/distribution/math_extension.rb on lines 135..135

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

                                  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

                                  There are no issues that match your filters.

                                  Category
                                  Status