wrangle go types

This commit is contained in:
NunoSempere 2024-02-16 13:43:29 +01:00
parent 4544adb3d0
commit fa0065c96e
2 changed files with 15 additions and 5 deletions

View File

@ -4,4 +4,4 @@
- [x] Test with a million samples of a simple lognormal, just to get a sense of speed
- [ ] Add mixture distribution
- [ ] Look into go routines for filling up an array.
- [ ] Anonymous functions for nested: https://stackoverflow.com/questions/74523441/nested-functions-in-go
- [ ] Anonymous functions for nested: https://stackoverflow.com/questions/74523441/nested-functions-in-o

View File

@ -49,8 +49,12 @@ func sample_to(low float64, high float64) float64 {
type func64 func() float64
func sample_mixture(fs [](func(float64) float64), ps []float64) float64 {
return 1.0
func sample_mixture(fs []func64, weights []float64) float64 {
var sum_weights float64 = 0
for i_, weight := range weights {
sum_weights += weight
}
return sum_weights
}
func main() {
@ -67,6 +71,12 @@ func main() {
return sample_to(1, 10)
}
fs := [3](func64){f1, f1, f1}
// x := sample_mixture()
f2 := func() float64 {
return sample_to(100, 1000)
}
fs := [2](func64){f1, f2}
ws := [2](float64){0.4, 0.1}
x := sample_mixture(fs[0:], ws[0:])
fmt.Printf("%v\n", x)
}