Example #1
0
func q3() {
	fns := []linreg.TransformFunc{phi0, phi1, phi2, phi3, phi4, phi5, phi6, phi7}

	ks := []int{3, 4, 5, 6, 7}

	data := getData("data/in.dta")
	for _, k := range ks {
		linreg := linreg.NewLinearRegression()

		linreg.InitializeFromData(data[25:])
		linreg.InitializeValidationFromData(data[:25])

		linreg.TransformFunction = fns[k]

		linreg.ApplyTransformation()
		linreg.ApplyTransformationOnValidation()
		linreg.Learn()
		eIn := linreg.Ein()
		eVal := linreg.EValIn()
		eOut, _ := linreg.EoutFromFile("data/out.dta")

		fmt.Printf("EVal = %f, for k = %d\n", eVal, k)
		fmt.Printf("EIn = %f, for k = %d\n", eIn, k)
		fmt.Printf("EOut = %f, for k = %d\n", eOut, k)
		fmt.Println()
	}
}
Example #2
0
func q2() {
	linreg := linreg.NewLinearRegression()
	linreg.InitializeFromFile("data/in.dta")
	linreg.TransformFunction = nonLinearFeature
	linreg.ApplyTransformation()
	linreg.Learn()
	ein := linreg.Ein()
	eout, _ := linreg.EoutFromFile("data/out.dta")
	fmt.Printf("Ein = %f, Eout = %f\n", ein, eout)
	linreg.K = -3
	linreg.LearnWeightDecay()
	eAugIn := linreg.EAugIn()
	eAugOut, _ := linreg.EAugOutFromFile("data/out.dta")
	fmt.Printf("Ein = %f, Eout = %f for k = %d\n", eAugIn, eAugOut, linreg.K)

	linreg.K = 3
	linreg.LearnWeightDecay()
	eAugIn = linreg.EAugIn()
	eAugOut, _ = linreg.EAugOutFromFile("data/out.dta")
	fmt.Printf("Ein = %f, Eout = %f for k = %d\n", eAugIn, eAugOut, linreg.K)

	k := []int{2, 1, 0, -1, -2}
	for _, ki := range k {
		linreg.K = ki
		linreg.LearnWeightDecay()
		eAugIn = linreg.EAugIn()
		eAugOut, _ = linreg.EAugOutFromFile("data/out.dta")
		fmt.Printf("Ein = %f, Eout = %f for k = %d\n", eAugIn, eAugOut, ki)
	}

	minK := 0
	minEAug := float64(1000)
	for i := -10; i < 10; i++ {
		linreg.K = i
		linreg.LearnWeightDecay()
		eAugOut, _ = linreg.EAugOutFromFile("data/out.dta")
		if minEAug > eAugOut {
			minK = i
			minEAug = eAugOut
		}
	}
	fmt.Printf("mininum Eout = %f with k = %d for k in {-10; 10}\n", minEAug, minK)
}