time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

commit bfb5c75070b3fe203554dc83524bdf778a697319
parent c9f6e964ee449588d13bb7d08959da38766682ff
Author: NunoSempere <nuno.sempere@protonmail.com>
Date:   Fri, 16 Feb 2024 00:42:39 +0100

add sample_to

Diffstat:
Mgo/squiggle.go | 11+++++++++++
1 file changed, 11 insertions(+), 0 deletions(-)

diff --git a/go/squiggle.go b/go/squiggle.go @@ -34,6 +34,17 @@ func sample_normal_from_90_ci(low float64, high float64) float64 { } +func sample_to(low float64, high float64) float64 { + // Given a (positive) 90% confidence interval, + // returns a sample from a lognorma with a matching 90% c.i. + // Key idea: If we want a lognormal with 90% confidence interval [a, b] + // we need but get a normal with 90% confidence interval [log(a), log(b)]. + // Then see code for sample_normal_from_90_ci + var loglow float64 = math.Log(low) + var loghigh float64 = math.Log(high) + return math.Exp(sample_normal_from_90_ci(loglow, loghigh)) +} + func main() { fmt.Println("Hello world!") fmt.Printf("%v\n", r.Float64())