Exemple #1
0
// Returns a random vector using the mean and sd vectors.
func RandomVector(mean, sd []float64, r *rand.Rand) []float64 {

	nrows := len(mean)
	if !floats.EqualLengths(mean, sd) {
		panic(floatx.ErrLength)
	}

	vec := make([]float64, nrows)
	for i := 0; i < nrows; i++ {
		v := r.NormFloat64()*sd[i] + mean[i]
		vec[i] = v
	}
	return vec
}
Exemple #2
0
// RandomModel generates a random Gaussian mixture model using mean and variance vectors as seed.
// Use this function to initialize the GMM before training. The mean and sd
// vector can be estimated from the data set using a Gaussian model.
func RandomModel(mean, sd []float64, numComponents int,
	name string, seed int64) *Model {

	n := len(mean)
	if !floats.EqualLengths(mean, sd) {
		panic(floatx.ErrLength)
	}
	cs := make([]*gaussian.Model, n, n)
	r := rand.New(rand.NewSource(seed))
	for i := 0; i < n; i++ {
		rv := RandomVector(mean, sd, r)
		cs[i] = gaussian.NewModel(n, gaussian.Mean(rv), gaussian.StdDev(sd))
	}
	gmm := NewModel(n, numComponents, Name(name), Components(cs))
	return gmm
}