spatial/r1: import and rename from bound

* spatial/r1: import and rename from bound

Mechanically generated with:

 $> gomvpkg -from gonum.org/v1/gonum/bound -to gonum.org/v1/gonum/spatial/r1 -vcs_mv_cmd "git mv {{.Src}} {{.Dst}}"

Fixes #956.
This commit is contained in:
Sebastien Binet
2019-06-21 13:49:53 +02:00
committed by GitHub
parent 5dc218f865
commit 5c77642844
7 changed files with 30 additions and 30 deletions

View File

@@ -2,5 +2,5 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
// Package bound provides types for bounded data. // Package r1 provides 1D vectors and intervals and operations on them.
package bound // import "gonum.org/v1/gonum/bound" package r1 // import "gonum.org/v1/gonum/spatial/r1"

View File

@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package bound package r1
// Bound represents [Min, Max] bounds. // Interval represents an interval.
type Bound struct { type Interval struct {
Min, Max float64 Min, Max float64
} }

View File

@@ -7,10 +7,10 @@ package distmv
import ( import (
"math" "math"
"gonum.org/v1/gonum/bound"
"gonum.org/v1/gonum/floats" "gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/mat" "gonum.org/v1/gonum/mat"
"gonum.org/v1/gonum/mathext" "gonum.org/v1/gonum/mathext"
"gonum.org/v1/gonum/spatial/r1"
"gonum.org/v1/gonum/stat" "gonum.org/v1/gonum/stat"
) )
@@ -76,7 +76,7 @@ func (Bhattacharyya) DistUniform(l, r *Uniform) float64 {
// unifLogVolOverlap computes the log of the volume of the hyper-rectangle where // unifLogVolOverlap computes the log of the volume of the hyper-rectangle where
// both uniform distributions have positive probability. // both uniform distributions have positive probability.
func unifLogVolOverlap(b1, b2 []bound.Bound) float64 { func unifLogVolOverlap(b1, b2 []r1.Interval) float64 {
var logVolOverlap float64 var logVolOverlap float64
for dim, v1 := range b1 { for dim, v1 := range b1 {
v2 := b2[dim] v2 := b2[dim]

View File

@@ -10,9 +10,9 @@ import (
"golang.org/x/exp/rand" "golang.org/x/exp/rand"
"gonum.org/v1/gonum/bound"
"gonum.org/v1/gonum/floats" "gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/mat" "gonum.org/v1/gonum/mat"
"gonum.org/v1/gonum/spatial/r1"
) )
func TestBhattacharyyaNormal(t *testing.T) { func TestBhattacharyyaNormal(t *testing.T) {
@@ -62,14 +62,14 @@ func TestBhattacharyyaUniform(t *testing.T) {
tol float64 tol float64
}{ }{
{ {
a: NewUniform([]bound.Bound{{-3, 2}, {-5, 8}}, rnd), a: NewUniform([]r1.Interval{{-3, 2}, {-5, 8}}, rnd),
b: NewUniform([]bound.Bound{{-4, 1}, {-7, 10}}, rnd), b: NewUniform([]r1.Interval{{-4, 1}, {-7, 10}}, rnd),
samples: 100000, samples: 100000,
tol: 1e-2, tol: 1e-2,
}, },
{ {
a: NewUniform([]bound.Bound{{-3, 2}, {-5, 8}}, rnd), a: NewUniform([]r1.Interval{{-3, 2}, {-5, 8}}, rnd),
b: NewUniform([]bound.Bound{{-5, -4}, {-7, 10}}, rnd), b: NewUniform([]r1.Interval{{-5, -4}, {-7, 10}}, rnd),
samples: 100000, samples: 100000,
tol: 1e-2, tol: 1e-2,
}, },
@@ -257,14 +257,14 @@ func TestKullbackLeiblerUniform(t *testing.T) {
tol float64 tol float64
}{ }{
{ {
a: NewUniform([]bound.Bound{{-5, 2}, {-7, 12}}, rnd), a: NewUniform([]r1.Interval{{-5, 2}, {-7, 12}}, rnd),
b: NewUniform([]bound.Bound{{-4, 1}, {-7, 10}}, rnd), b: NewUniform([]r1.Interval{{-4, 1}, {-7, 10}}, rnd),
samples: 100000, samples: 100000,
tol: 1e-2, tol: 1e-2,
}, },
{ {
a: NewUniform([]bound.Bound{{-5, 2}, {-7, 12}}, rnd), a: NewUniform([]r1.Interval{{-5, 2}, {-7, 12}}, rnd),
b: NewUniform([]bound.Bound{{-9, -6}, {-7, 10}}, rnd), b: NewUniform([]r1.Interval{{-9, -6}, {-7, 10}}, rnd),
samples: 100000, samples: 100000,
tol: 1e-2, tol: 1e-2,
}, },

View File

@@ -8,18 +8,18 @@ import (
"math" "math"
"golang.org/x/exp/rand" "golang.org/x/exp/rand"
"gonum.org/v1/gonum/bound" "gonum.org/v1/gonum/spatial/r1"
) )
// Uniform represents a multivariate uniform distribution. // Uniform represents a multivariate uniform distribution.
type Uniform struct { type Uniform struct {
bounds []bound.Bound bounds []r1.Interval
dim int dim int
rnd *rand.Rand rnd *rand.Rand
} }
// NewUniform creates a new uniform distribution with the given bounds. // NewUniform creates a new uniform distribution with the given bounds.
func NewUniform(bnds []bound.Bound, src rand.Source) *Uniform { func NewUniform(bnds []r1.Interval, src rand.Source) *Uniform {
dim := len(bnds) dim := len(bnds)
if dim == 0 { if dim == 0 {
panic(badZeroDimension) panic(badZeroDimension)
@@ -30,7 +30,7 @@ func NewUniform(bnds []bound.Bound, src rand.Source) *Uniform {
} }
} }
u := &Uniform{ u := &Uniform{
bounds: make([]bound.Bound, dim), bounds: make([]r1.Interval, dim),
dim: dim, dim: dim,
} }
if src != nil { if src != nil {
@@ -50,7 +50,7 @@ func NewUnitUniform(dim int, src rand.Source) *Uniform {
if dim <= 0 { if dim <= 0 {
panic(nonPosDimension) panic(nonPosDimension)
} }
bounds := make([]bound.Bound, dim) bounds := make([]r1.Interval, dim)
for i := range bounds { for i := range bounds {
bounds[i].Min = 0 bounds[i].Min = 0
bounds[i].Max = 1 bounds[i].Max = 1
@@ -69,9 +69,9 @@ func NewUnitUniform(dim int, src rand.Source) *Uniform {
// is nil, a new slice is allocated and returned. If the input is non-nil, then // is nil, a new slice is allocated and returned. If the input is non-nil, then
// the bounds are stored in-place into the input argument, and Bounds will panic // the bounds are stored in-place into the input argument, and Bounds will panic
// if len(bounds) != u.Dim(). // if len(bounds) != u.Dim().
func (u *Uniform) Bounds(bounds []bound.Bound) []bound.Bound { func (u *Uniform) Bounds(bounds []r1.Interval) []r1.Interval {
if bounds == nil { if bounds == nil {
bounds = make([]bound.Bound, u.Dim()) bounds = make([]r1.Interval, u.Dim())
} }
if len(bounds) != u.Dim() { if len(bounds) != u.Dim() {
panic(badInputLength) panic(badInputLength)

View File

@@ -8,7 +8,7 @@ import (
"math" "math"
"testing" "testing"
"gonum.org/v1/gonum/bound" "gonum.org/v1/gonum/spatial/r1"
) )
func TestUniformEntropy(t *testing.T) { func TestUniformEntropy(t *testing.T) {
@@ -17,11 +17,11 @@ func TestUniformEntropy(t *testing.T) {
Entropy float64 Entropy float64
}{ }{
{ {
NewUniform([]bound.Bound{{0, 1}, {0, 1}}, nil), NewUniform([]r1.Interval{{0, 1}, {0, 1}}, nil),
0, 0,
}, },
{ {
NewUniform([]bound.Bound{{-1, 3}, {2, 8}, {-5, -3}}, nil), NewUniform([]r1.Interval{{-1, 3}, {2, 8}, {-5, -3}}, nil),
math.Log(48), math.Log(48),
}, },
} { } {

View File

@@ -10,9 +10,9 @@ import (
"golang.org/x/exp/rand" "golang.org/x/exp/rand"
"gonum.org/v1/gonum/bound"
"gonum.org/v1/gonum/floats" "gonum.org/v1/gonum/floats"
"gonum.org/v1/gonum/mat" "gonum.org/v1/gonum/mat"
"gonum.org/v1/gonum/spatial/r1"
"gonum.org/v1/gonum/stat" "gonum.org/v1/gonum/stat"
"gonum.org/v1/gonum/stat/distmv" "gonum.org/v1/gonum/stat/distmv"
) )
@@ -27,8 +27,8 @@ func TestLatinHypercube(t *testing.T) {
src := rand.New(rand.NewSource(1)) src := rand.New(rand.NewSource(1))
for _, nSamples := range []int{1, 2, 5, 10, 20} { for _, nSamples := range []int{1, 2, 5, 10, 20} {
for _, dist := range []lhDist{ for _, dist := range []lhDist{
distmv.NewUniform([]bound.Bound{{Min: 0, Max: 3}}, src), distmv.NewUniform([]r1.Interval{{Min: 0, Max: 3}}, src),
distmv.NewUniform([]bound.Bound{{Min: 0, Max: 3}, {Min: -1, Max: 5}, {Min: -4, Max: -1}}, src), distmv.NewUniform([]r1.Interval{{Min: 0, Max: 3}, {Min: -1, Max: 5}, {Min: -4, Max: -1}}, src),
} { } {
dim := dist.Dim() dim := dist.Dim()
batch := mat.NewDense(nSamples, dim, nil) batch := mat.NewDense(nSamples, dim, nil)
@@ -93,7 +93,7 @@ func TestRejection(t *testing.T) {
src := rand.New(rand.NewSource(1)) src := rand.New(rand.NewSource(1))
// Test by finding the expected value of a uniform. // Test by finding the expected value of a uniform.
dim := 3 dim := 3
bounds := make([]bound.Bound, dim) bounds := make([]r1.Interval, dim)
for i := 0; i < dim; i++ { for i := 0; i < dim; i++ {
min := src.NormFloat64() min := src.NormFloat64()
max := src.NormFloat64() max := src.NormFloat64()