Fix incorrect LatinHypercube documentation and add code for Uniform convenience
MODIFY
distmv/general.go
distmv/general.go
@@ -10,6 +10,7 @@ var (
badReceiver = "distmv: input slice is not nil or the correct length"
badSizeMismatch = "distmv: size mismatch"
badZeroDimension = "distmv: zero dimensional input"
+ nonPosDimension = "distmv: non-positive dimension input"
)
const logTwoPi = 1.8378770664093454835606594728112352797227949472755668

MODIFY
distmv/uniform.go
distmv/uniform.go
@@ -44,6 +44,25 @@ func NewUniform(bnds []Bound, src *rand.Source) *Uniform {
return u
}
+// NewUnitUniform creates a new Uniform distribution over the dim-dimensional
+// unit hypercube. That is, a uniform distribution where each dimension has
+// Min = 0 and Max = 1.
+func NewUnitUniform(dim int, src *rand.Source) *Uniform {
+ if dim <= 0 {
+ panic(nonPosDimension)
+ }
+ bounds := make([]Bound, dim)
+ for i := range bounds {
+ bounds[i].Min = 0
+ bounds[i].Max = 1
+ }
+ return &Uniform{
+ bounds: bounds,
+ dim: dim,
+ src: src,
+ }
+}
+
// CDF returns the multidimensional cumulative distribution function of the
// probability distribution at the point x. If p is non-nil, the CDF is stored
// in-place into the first argument, otherwise a new slice is allocated and

MODIFY
distuv/norm.go
distuv/norm.go
@@ -12,7 +12,7 @@ import (
"github.com/gonum/stat"
)
-// UnitNormal is an instantiation of the standard normal distribution
+// UnitNormal is an instantiation of the normal distribution with Mu = 0 and Sigma = 1.
var UnitNormal = Normal{Mu: 0, Sigma: 1}
// Normal respresents a normal (Gaussian) distribution (https://en.wikipedia.org/wiki/Normal_distribution).

MODIFY
distuv/uniform.go
distuv/uniform.go
@@ -9,6 +9,10 @@ import (
"math/rand"
)
+// UnitUniform is an instantiation of the uniform distribution with Min = 0
+// and Max = 1.
+var UnitUniform = Uniform{Min: 0, Max: 1}
+
// Uniform represents a continuous uniform distribution (https://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29).
type Uniform struct {
Min float64

MODIFY
samplemv/samplemv.go
samplemv/samplemv.go
@@ -94,8 +94,8 @@ func (l LatinHypercuber) Sample(batch *mat64.Dense) {
//
// Latin hypercube sampling divides the cumulative distribution function into equally
// spaced bins and guarantees that one sample is generated per bin. Within each bin,
-// the location is randomly sampled. The distmv.UnitNormal variable can be used
-// for easy generation from the unit interval.
+// the location is randomly sampled. The distmv.NewUnitUniform function can be used
+// for easy sampling from the unit hypercube.
func LatinHypercube(batch *mat64.Dense, q distmv.Quantiler, src *rand.Rand) {
r, c := batch.Dims()
var f64 func() float64

MODIFY
sampleuv/sample.go
sampleuv/sample.go
@@ -93,7 +93,7 @@ func (l LatinHypercuber) Sample(batch []float64) {
//
// Latin hypercube sampling divides the cumulative distribution function into equally
// spaced bins and guarantees that one sample is generated per bin. Within each bin,
-// the location is randomly sampled. The distuv.UnitNormal variable can be used
+// the location is randomly sampled. The distuv.UnitUniform variable can be used
// for easy generation from the unit interval.
func LatinHypercube(batch []float64, q distuv.Quantiler, src *rand.Rand) {
n := len(batch)

Fix incorrect LatinHypercube documentation and add code for Uniform convenience