Example #1
0
func q6() {
	runs := float64(10000)
	interval1 := linear.NewInterval(0, 1)
	interval2 := linear.NewInterval(0, 1)

	sumE1 := float64(0)
	sumE2 := float64(0)
	sumE := float64(0)
	for i := 0; i < int(runs); i++ {
		e1 := interval1.RandFloat()
		e2 := interval2.RandFloat()
		sumE1 += e1
		sumE2 += e2
		sumE += min(e1, e2)
	}
	fmt.Printf("e1 = %f, e2 = %f, e = %f\n", sumE1/runs, sumE2/runs, sumE/runs)
}
Example #2
0
// NewLinearRegression creates a linear regression object.
// TrainingPoints = 10
// Interval [-1 : 1]
// RandomTargetFunction is true
// Noise = 0
// VectorSize = 3
//
func NewLinearRegression() *LinearRegression {
	lr := LinearRegression{
		TrainingPoints:       10,                        // default training points is 10
		Interval:             linear.NewInterval(-1, 1), // default interval is [-1, 1]
		RandomTargetFunction: true,                      // default RandomTargetFunction is true
		Noise:                0,                         // default noise is 0
		VectorSize:           3,                         // default vector size is 3
	}
	return &lr
}
Example #3
0
func NewBiasAndVariance() *BiasAndVariance {
	bav := BiasAndVariance{}
	bav.Interval = linear.NewInterval(float64(-1), float64(1))
	bav.Runs = 1000
	bav.TargetFunction = func(x float64) float64 {
		return math.Sin(math.Pi * x)
	}
	bav.TrainingExampleSize = 2
	bav.ThroughOrigin = true
	return &bav
}