aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/aclements
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2018-10-05 10:06:54 -0700
committerChristine Dodrill <me@christine.website>2018-10-05 14:31:22 -0700
commitdbeba1e5c5c0bc534a515eb298ee4f1d49df4d20 (patch)
tree2bbca457936bbf32290b9a8543f9a2f156b45175 /vendor/github.com/aclements
parent7332b16d4a09492e5a35ad00d3ab58ac5742cad6 (diff)
downloadx-dbeba1e5c5c0bc534a515eb298ee4f1d49df4d20.tar.xz
x-dbeba1e5c5c0bc534a515eb298ee4f1d49df4d20.zip
update vendor
Diffstat (limited to 'vendor/github.com/aclements')
-rw-r--r--vendor/github.com/aclements/go-moremath/LICENSE27
-rw-r--r--vendor/github.com/aclements/go-moremath/mathx/beta.go93
-rw-r--r--vendor/github.com/aclements/go-moremath/mathx/choose.go62
-rw-r--r--vendor/github.com/aclements/go-moremath/mathx/gamma.go96
-rw-r--r--vendor/github.com/aclements/go-moremath/mathx/package.go11
-rw-r--r--vendor/github.com/aclements/go-moremath/mathx/sign.go18
6 files changed, 307 insertions, 0 deletions
diff --git a/vendor/github.com/aclements/go-moremath/LICENSE b/vendor/github.com/aclements/go-moremath/LICENSE
new file mode 100644
index 0000000..d29b372
--- /dev/null
+++ b/vendor/github.com/aclements/go-moremath/LICENSE
@@ -0,0 +1,27 @@
+Copyright (c) 2015 The Go Authors. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are
+met:
+
+ * Redistributions of source code must retain the above copyright
+notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+copyright notice, this list of conditions and the following disclaimer
+in the documentation and/or other materials provided with the
+distribution.
+ * Neither the name of Google Inc. nor the names of its
+contributors may be used to endorse or promote products derived from
+this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/vendor/github.com/aclements/go-moremath/mathx/beta.go b/vendor/github.com/aclements/go-moremath/mathx/beta.go
new file mode 100644
index 0000000..49f8722
--- /dev/null
+++ b/vendor/github.com/aclements/go-moremath/mathx/beta.go
@@ -0,0 +1,93 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package mathx
+
+import "math"
+
+func lgamma(x float64) float64 {
+ y, _ := math.Lgamma(x)
+ return y
+}
+
+// Beta returns the value of the complete beta function B(a, b).
+func Beta(a, b float64) float64 {
+ // B(x,y) = Γ(x)Γ(y) / Γ(x+y)
+ return math.Exp(lgamma(a) + lgamma(b) - lgamma(a+b))
+}
+
+// BetaInc returns the value of the regularized incomplete beta
+// function Iₓ(a, b).
+//
+// This is not to be confused with the "incomplete beta function",
+// which can be computed as BetaInc(x, a, b)*Beta(a, b).
+//
+// If x < 0 or x > 1, returns NaN.
+func BetaInc(x, a, b float64) float64 {
+ // Based on Numerical Recipes in C, section 6.4. This uses the
+ // continued fraction definition of I:
+ //
+ // (xᵃ*(1-x)ᵇ)/(a*B(a,b)) * (1/(1+(d₁/(1+(d₂/(1+...))))))
+ //
+ // where B(a,b) is the beta function and
+ //
+ // d_{2m+1} = -(a+m)(a+b+m)x/((a+2m)(a+2m+1))
+ // d_{2m} = m(b-m)x/((a+2m-1)(a+2m))
+ if x < 0 || x > 1 {
+ return math.NaN()
+ }
+ bt := 0.0
+ if 0 < x && x < 1 {
+ // Compute the coefficient before the continued
+ // fraction.
+ bt = math.Exp(lgamma(a+b) - lgamma(a) - lgamma(b) +
+ a*math.Log(x) + b*math.Log(1-x))
+ }
+ if x < (a+1)/(a+b+2) {
+ // Compute continued fraction directly.
+ return bt * betacf(x, a, b) / a
+ } else {
+ // Compute continued fraction after symmetry transform.
+ return 1 - bt*betacf(1-x, b, a)/b
+ }
+}
+
+// betacf is the continued fraction component of the regularized
+// incomplete beta function Iₓ(a, b).
+func betacf(x, a, b float64) float64 {
+ const maxIterations = 200
+ const epsilon = 3e-14
+
+ raiseZero := func(z float64) float64 {
+ if math.Abs(z) < math.SmallestNonzeroFloat64 {
+ return math.SmallestNonzeroFloat64
+ }
+ return z
+ }
+
+ c := 1.0
+ d := 1 / raiseZero(1-(a+b)*x/(a+1))
+ h := d
+ for m := 1; m <= maxIterations; m++ {
+ mf := float64(m)
+
+ // Even step of the recurrence.
+ numer := mf * (b - mf) * x / ((a + 2*mf - 1) * (a + 2*mf))
+ d = 1 / raiseZero(1+numer*d)
+ c = raiseZero(1 + numer/c)
+ h *= d * c
+
+ // Odd step of the recurrence.
+ numer = -(a + mf) * (a + b + mf) * x / ((a + 2*mf) * (a + 2*mf + 1))
+ d = 1 / raiseZero(1+numer*d)
+ c = raiseZero(1 + numer/c)
+ hfac := d * c
+ h *= hfac
+
+ if math.Abs(hfac-1) < epsilon {
+ return h
+ }
+ }
+ panic("betainc: a or b too big; failed to converge")
+}
diff --git a/vendor/github.com/aclements/go-moremath/mathx/choose.go b/vendor/github.com/aclements/go-moremath/mathx/choose.go
new file mode 100644
index 0000000..54dc27c
--- /dev/null
+++ b/vendor/github.com/aclements/go-moremath/mathx/choose.go
@@ -0,0 +1,62 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package mathx
+
+import "math"
+
+const smallFactLimit = 20 // 20! => 62 bits
+var smallFact [smallFactLimit + 1]int64
+
+func init() {
+ smallFact[0] = 1
+ fact := int64(1)
+ for n := int64(1); n <= smallFactLimit; n++ {
+ fact *= n
+ smallFact[n] = fact
+ }
+}
+
+// Choose returns the binomial coefficient of n and k.
+func Choose(n, k int) float64 {
+ if k == 0 || k == n {
+ return 1
+ }
+ if k < 0 || n < k {
+ return 0
+ }
+ if n <= smallFactLimit { // Implies k <= smallFactLimit
+ // It's faster to do several integer multiplications
+ // than it is to do an extra integer division.
+ // Remarkably, this is also faster than pre-computing
+ // Pascal's triangle (presumably because this is very
+ // cache efficient).
+ numer := int64(1)
+ for n1 := int64(n - (k - 1)); n1 <= int64(n); n1++ {
+ numer *= n1
+ }
+ denom := smallFact[k]
+ return float64(numer / denom)
+ }
+
+ return math.Exp(lchoose(n, k))
+}
+
+// Lchoose returns math.Log(Choose(n, k)).
+func Lchoose(n, k int) float64 {
+ if k == 0 || k == n {
+ return 0
+ }
+ if k < 0 || n < k {
+ return math.NaN()
+ }
+ return lchoose(n, k)
+}
+
+func lchoose(n, k int) float64 {
+ a, _ := math.Lgamma(float64(n + 1))
+ b, _ := math.Lgamma(float64(k + 1))
+ c, _ := math.Lgamma(float64(n - k + 1))
+ return a - b - c
+}
diff --git a/vendor/github.com/aclements/go-moremath/mathx/gamma.go b/vendor/github.com/aclements/go-moremath/mathx/gamma.go
new file mode 100644
index 0000000..d11096e
--- /dev/null
+++ b/vendor/github.com/aclements/go-moremath/mathx/gamma.go
@@ -0,0 +1,96 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package mathx
+
+import "math"
+
+// GammaInc returns the value of the incomplete gamma function (also
+// known as the regularized gamma function):
+//
+// P(a, x) = 1 / Γ(a) * ∫₀ˣ exp(-t) t**(a-1) dt
+func GammaInc(a, x float64) float64 {
+ // Based on Numerical Recipes in C, section 6.2.
+
+ if a <= 0 || x < 0 || math.IsNaN(a) || math.IsNaN(x) {
+ return math.NaN()
+ }
+
+ if x < a+1 {
+ // Use the series representation, which converges more
+ // rapidly in this range.
+ return gammaIncSeries(a, x)
+ } else {
+ // Use the continued fraction representation.
+ return 1 - gammaIncCF(a, x)
+ }
+}
+
+// GammaIncComp returns the complement of the incomplete gamma
+// function 1 - GammaInc(a, x). This is more numerically stable for
+// values near 0.
+func GammaIncComp(a, x float64) float64 {
+ if a <= 0 || x < 0 || math.IsNaN(a) || math.IsNaN(x) {
+ return math.NaN()
+ }
+
+ if x < a+1 {
+ return 1 - gammaIncSeries(a, x)
+ } else {
+ return gammaIncCF(a, x)
+ }
+}
+
+func gammaIncSeries(a, x float64) float64 {
+ const maxIterations = 200
+ const epsilon = 3e-14
+
+ if x == 0 {
+ return 0
+ }
+
+ ap := a
+ del := 1 / a
+ sum := del
+ for n := 0; n < maxIterations; n++ {
+ ap++
+ del *= x / ap
+ sum += del
+ if math.Abs(del) < math.Abs(sum)*epsilon {
+ return sum * math.Exp(-x+a*math.Log(x)-lgamma(a))
+ }
+ }
+ panic("a too large; failed to converge")
+}
+
+func gammaIncCF(a, x float64) float64 {
+ const maxIterations = 200
+ const epsilon = 3e-14
+
+ raiseZero := func(z float64) float64 {
+ if math.Abs(z) < math.SmallestNonzeroFloat64 {
+ return math.SmallestNonzeroFloat64
+ }
+ return z
+ }
+
+ b := x + 1 - a
+ c := math.MaxFloat64
+ d := 1 / b
+ h := d
+
+ for i := 1; i <= maxIterations; i++ {
+ an := -float64(i) * (float64(i) - a)
+ b += 2
+ d = raiseZero(an*d + b)
+ c = raiseZero(b + an/c)
+ d = 1 / d
+ del := d * c
+ h *= del
+ if math.Abs(del-1) < epsilon {
+ return math.Exp(-x+a*math.Log(x)-lgamma(a)) * h
+ }
+ }
+ panic("a too large; failed to converge")
+}
diff --git a/vendor/github.com/aclements/go-moremath/mathx/package.go b/vendor/github.com/aclements/go-moremath/mathx/package.go
new file mode 100644
index 0000000..9d5de0d
--- /dev/null
+++ b/vendor/github.com/aclements/go-moremath/mathx/package.go
@@ -0,0 +1,11 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package mathx implements special functions not provided by the
+// standard math package.
+package mathx // import "github.com/aclements/go-moremath/mathx"
+
+import "math"
+
+var nan = math.NaN()
diff --git a/vendor/github.com/aclements/go-moremath/mathx/sign.go b/vendor/github.com/aclements/go-moremath/mathx/sign.go
new file mode 100644
index 0000000..372e92f
--- /dev/null
+++ b/vendor/github.com/aclements/go-moremath/mathx/sign.go
@@ -0,0 +1,18 @@
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package mathx
+
+// Sign returns the sign of x: -1 if x < 0, 0 if x == 0, 1 if x > 0.
+// If x is NaN, it returns NaN.
+func Sign(x float64) float64 {
+ if x == 0 {
+ return 0
+ } else if x < 0 {
+ return -1
+ } else if x > 0 {
+ return 1
+ }
+ return nan
+}