become a bit confused about FilledSamples and mixtures
This commit is contained in:
parent
7d8a582bd5
commit
e473223bbd
17
fermi.go
17
fermi.go
|
@ -21,6 +21,7 @@ type Stack struct {
|
||||||
|
|
||||||
type Dist interface {
|
type Dist interface {
|
||||||
Samples() []float64
|
Samples() []float64
|
||||||
|
Sampler(sample.State) float64
|
||||||
}
|
}
|
||||||
|
|
||||||
type Scalar float64
|
type Scalar float64
|
||||||
|
@ -48,21 +49,37 @@ func (p Scalar) Samples() []float64 {
|
||||||
}
|
}
|
||||||
return xs
|
return xs
|
||||||
}
|
}
|
||||||
|
func (p Scalar) Sampler(r sample.State) float64 {
|
||||||
|
return float64(p)
|
||||||
|
}
|
||||||
|
|
||||||
func (ln Lognormal) Samples() []float64 {
|
func (ln Lognormal) Samples() []float64 {
|
||||||
sampler := func(r sample.State) float64 { return sample.Sample_to(ln.low, ln.high, r) }
|
sampler := func(r sample.State) float64 { return sample.Sample_to(ln.low, ln.high, r) }
|
||||||
// Can't do parallel because then I'd have to await throughout the code
|
// Can't do parallel because then I'd have to await throughout the code
|
||||||
return sample.Sample_serially(sampler, N_SAMPLES)
|
return sample.Sample_serially(sampler, N_SAMPLES)
|
||||||
}
|
}
|
||||||
|
func (ln Lognormal) Sampler(r sample.State) float64 {
|
||||||
|
return sample.Sample_to(ln.low, ln.high, r)
|
||||||
|
}
|
||||||
|
|
||||||
func (beta Beta) Samples() []float64 {
|
func (beta Beta) Samples() []float64 {
|
||||||
sampler := func(r sample.State) float64 { return sample.Sample_beta(beta.a, beta.b, r) }
|
sampler := func(r sample.State) float64 { return sample.Sample_beta(beta.a, beta.b, r) }
|
||||||
return sample.Sample_serially(sampler, N_SAMPLES)
|
return sample.Sample_serially(sampler, N_SAMPLES)
|
||||||
}
|
}
|
||||||
|
func (beta Beta) Sampler(r sample.State) float64 {
|
||||||
|
return sample.Sample_beta(beta.a, beta.b, r)
|
||||||
|
}
|
||||||
|
|
||||||
func (fs FilledSamples) Samples() []float64 {
|
func (fs FilledSamples) Samples() []float64 {
|
||||||
return fs.xs
|
return fs.xs
|
||||||
}
|
}
|
||||||
|
func (fs FilledSamples) Sampler(r sample.State) float64 {
|
||||||
|
// This is a bit subtle, because sampling from a FilledSamples item iteratively converges
|
||||||
|
// to something different than the initial distribution
|
||||||
|
n := len(fs.xs)
|
||||||
|
i := sample.Sample_int(n, r)
|
||||||
|
return fs.xs[i]
|
||||||
|
}
|
||||||
|
|
||||||
/* Constants */
|
/* Constants */
|
||||||
const HELP_MSG = "1. Grammar:\n" +
|
const HELP_MSG = "1. Grammar:\n" +
|
||||||
|
|
|
@ -16,6 +16,10 @@ type func64 = func(State) float64
|
||||||
|
|
||||||
var global_state = rand.New(rand.NewPCG(uint64(1), uint64(2)))
|
var global_state = rand.New(rand.NewPCG(uint64(1), uint64(2)))
|
||||||
|
|
||||||
|
func Sample_int(n int, r State) int {
|
||||||
|
return r.IntN(n)
|
||||||
|
}
|
||||||
|
|
||||||
func Sample_unit_uniform(r State) float64 {
|
func Sample_unit_uniform(r State) float64 {
|
||||||
return r.Float64()
|
return r.Float64()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user