예제 #1
0
파일: ring.go 프로젝트: postfix/dolphin
func VFoldCv(ring *Ring, queue *mpi.CircularMPI, data []models.SLPoint, len_ring int) {
	// We compute the fold size
	folds := exutils.PrepareFolds(5, data)
	for k, fold := range folds {
		fmt.Println("INFO:", *me, " Entering fold ", k)
		// Now we build the training dataset for this fold
		tdata := data[fold[0]:fold[1]]
		tpoints := make([]models.Vector, 0, len(tdata))
		for _, pt := range tdata {
			tpoints = append(tpoints, models.Vector(pt.X))
		}

		// Now We will build the Workers
		cmpt := make([]*workers.Computable, 0, *workrs)
		for i := 0; i < *workrs; i++ {
			est, _ := np.NewRevezEstimator(tpoints)
			cp := workers.NewComputable(queue, *me*10+i, est)
			cmpt = append(cmpt, cp)
		}
		for i := 0; i < *workrs; i++ {
			go workers.SimpleWorker(queue, cmpt[i], *tau)
		}

		var wg sync.WaitGroup
		wg.Add(*workrs)
		totalWorkers := len_ring * (*workrs)
		j := 0
		fl := make(chan bool)
		for i := *workrs * (*me - 1); i < *workrs*(*me); i++ {
			if j == 0 && *me == 1 {
				go exutils.FeedWorker(&wg, data, tdata, fold, cmpt[j], i, totalWorkers, fl)
			} else {
				go exutils.FeedWorker(&wg, data, tdata, fold, cmpt[j], i, totalWorkers, nil)
			}
			j++
		}
		if *me == 1 {
			go func() {
				<-fl
				time.Sleep(250 * time.Millisecond)
				err := queue.Flush()
				if err != nil {
					fmt.Println("ERROR: Can't Flush the Queue, ", err)
				}
			}()
		}
		quit := make(chan bool)
		go exutils.MesureState(quit, cmpt[0], tdata)
		wg.Wait()
		fmt.Println("L2:FINAL:", cmpt[0].Id, ":", cmpt[0].Est.Error(tdata))
		quit <- true
		return
	}
}
예제 #2
0
파일: simple.go 프로젝트: postfix/dolphin
func VFoldCv(queue mpi.Dummy, data []models.SLPoint) {
	// We compute the fold size
	folds := exutils.PrepareFolds(5, data)
	for k, fold := range folds {
		fmt.Println("Entering fold ", k)
		// Now we build the training dataset for this fold
		tdata := data[fold[0]:fold[1]]
		tpoints := make([]models.Vector, 0, len(tdata))
		for _, pt := range tdata {
			tpoints = append(tpoints, models.Vector(pt.X))
		}

		// Now We will build the Workers
		cmpt := make([]*workers.Computable, 0, *workrs)
		for i := 0; i < *workrs; i++ {

			est, _ := np.NewRevezEstimator(tpoints)
			cp := workers.NewComputable(queue, i, est)
			cmpt = append(cmpt, cp)
		}
		for i := 0; i < *workrs; i++ {
			go workers.SimpleWorker(queue, cmpt[i], *tau)
		}

		var wg sync.WaitGroup
		wg.Add(*workrs)
		for i := 0; i < *workrs; i++ {
			go func(j int) {
				for k, val := range data {
					if k < fold[0] || k > fold[1] {
						cmpt[j].Input <- val
					}
				}
				wg.Done()
			}(i)
		}
		quit := make(chan bool)
		go exutils.MesureState(quit, cmpt[0], tdata)
		wg.Wait()
		fmt.Println("Final;", cmpt[0].Est.Error(tdata))
		quit <- true
	}
}