Exemple #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
}
Exemple #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
}