示例#1
0
func q9cc() experiment {
	exp := experiment{NRuns: 1000, NPoints: 100}
	pla := pla.NewPLA()

	chanDisagreement := make(chan float64, exp.NRuns)
	chanIterations := make(chan int, exp.NRuns)

	for run := 0; run < exp.NRuns; run++ {
		go func() {
			pla.N = exp.NPoints
			pla.Initialize()
			iterations := pla.Converge()
			chanDisagreement <- pla.Disagreement()
			chanIterations <- iterations
		}()
	}

	for i := 0; i < exp.NRuns; i++ {
		exp.SumOfDisagreement += <-chanDisagreement
	}
	for i := 0; i < exp.NRuns; i++ {
		exp.SumOfIterations += <-chanIterations
	}

	exp.print()
	return exp
}
示例#2
0
// Take N = 10. How many iterations does it take on average for the PLA to
// converge for N = 10 training points?
func q7() experiment {
	exp := experiment{NRuns: 1000, NPoints: 10}
	pla := pla.NewPLA()

	for run := 0; run < exp.NRuns; run++ {
		pla.Initialize()
		iterations := pla.Converge()
		exp.SumOfDisagreement += pla.Disagreement()
		exp.SumOfIterations += iterations
	}
	exp.print()
	return exp
}
示例#3
0
func q7() {
	runs := 1000 // number of times we repeat the experiment
	linreg := linreg.NewLinearRegression()
	linreg.N = 10
	iterations := 0
	for run := 0; run < runs; run++ {
		linreg.Initialize()

		linreg.Learn()
		pla := pla.NewPLA()
		pla.Initialize()
		for i := 0; i < len(pla.Wn); i++ {
			pla.Wn[i] = linreg.Wn[i]
		}
		iterations += pla.Converge()
	}
	avgIterations := float64(iterations) / float64(runs)
	fmt.Printf("average for PLA to converge for N = %v with initial weight computed by linear regression is %4.2f\n", linreg.N, avgIterations)
}