Example #1
0
func NewGenerator(CDF vec.Mathop, mean float64, std float64) *Generator {
	pts := vec.Arange(mean-(10*std), mean+(10*std), 10000)
	cdf := vec.Arange(mean-(10*std), mean+(10*std), 10000)
	vec.PPmap(CDF, cdf)
	bvd := vec.MakeBiVariateData(cdf, pts)
	spl := vec.CubicSpline(bvd)
	src := rand.NewSource(0)
	rnd := rand.New(src)
	return &Generator{interp: spl, rgen: rnd}
}
Example #2
0
File: ops.go Project: philhofer/tcx
func Spline(trk *Track) *TrackSpline {
	Npts := len(trk.Pt)
	lats := make([]float64, Npts)
	longs := make([]float64, Npts)
	spds := make([]float64, Npts)
	alts := make([]float64, Npts)
	dists := make([]float64, Npts)
	for i := 0; i < Npts; i++ {
		lats[i] = trk.Pt[i].Lat
		longs[i] = trk.Pt[i].Long
		spds[i] = trk.Pt[i].Speed
		alts[i] = trk.Pt[i].Alt
		dists[i] = trk.Pt[i].Dist
	}
	latsplin := vec.CubicSpline(vec.MakeBiVariateData(dists, lats))
	longssplin := vec.CubicSpline(vec.MakeBiVariateData(dists, longs))
	spdssplin := vec.CubicSpline(vec.MakeBiVariateData(dists, spds))
	altssplin := vec.CubicSpline(vec.MakeBiVariateData(dists, alts))
	return &TrackSpline{lat: latsplin, long: longssplin, spd: spdssplin, alt: altssplin}
}