コード例 #1
0
ファイル: fwdhpc.go プロジェクト: mingzhi/gomain
func simulateSome(b, e int, ch chan Result) {
	for i := b; i < e; i++ {
		sp := fwd.NewSeqPop(size, lens, mutation, transfer, frag)
		sp.SetExpTime(exptime)
		sp.Seed(i)
		for j := 0; j < gens; j++ {
			sp.Evolve()
		}

		seqs := sp.GetGenomes()

		diffmatrix := [][]int{}
		for j := 0; j < samp; j++ {
			a := rand.Intn(size)
			b := rand.Intn(size)
			for a == b {
				b = rand.Intn(size)
			}

			diff := []int{}

			for k := 0; k < lens; k++ {
				if seqs[a][k] != seqs[b][k] {
					diff = append(diff, k)
				}
			}

			diffmatrix = append(diffmatrix, diff)
		}

		cmatrix := covs.NewCMatrix(samp, lens, diffmatrix)

		ks, vd := cmatrix.D()
		scovs, rcovs, xyPL, xsysPL, smXYPL := cmatrix.CovCircle(maxl)
		result := Result{
			ks:     ks,
			vd:     vd,
			scovs:  scovs,
			rcovs:  rcovs,
			xyPL:   xyPL,
			xsysPL: xsysPL,
			smXYPL: smXYPL,
		}

		ch <- result
	}
}
コード例 #2
0
ファイル: bench_pop.go プロジェクト: mingzhi/gomain
func main() {
	t0 := time.Now()

	size := 1000
	length := 10000
	mutation := 0.001
	transfer := 0.001
	fragment := 1000

	pop := fwd.NewSeqPop(size, length, mutation, transfer, fragment)

	n := 1000
	for i := 0; i < n; i++ {
		pop.Evolve()
	}

	t1 := time.Now()
	t := t1.Sub(t0)
	fmt.Println(t)
}
コード例 #3
0
ファイル: fwdsingle.go プロジェクト: mingzhi/gomain
func main() {
	// create d file
	dfile, err := os.Create(fmt.Sprintf("%s_d.csv", prefix))
	if err != nil {
		log.Panic(err)
	}
	defer dfile.Close()

	// create population for simulation
	sp := fwd.NewSeqPop(size, lens, mutation, transfer, frag)

	// do eqvGens generations for reaching equilibrium
	for i := 0; i < eqvGens; i++ {
		sp.Evolve()
	}

	// create moments
	moments := make([][]Moment, 5)
	for i := 0; i < len(moments); i++ {
		for j := 0; j < maxl; j++ {
			m := Moment{
				Mean: desc.NewMean(),
				Sd:   desc.NewStandardDeviationWithBiasCorrection(),
			}
			moments[i] = append(moments[i], m)
		}
	}

	// do sample generations
	for i := 0; i < gens; i++ {
		sp.Evolve()

		seqs := sp.GetGenomes()

		diffmatrix := [][]int{}
		for j := 0; j < samp; j++ {
			a := rand.Intn(size)
			b := rand.Intn(size)
			for a == b {
				b = rand.Intn(size)
			}

			diff := []int{}

			for k := 0; k < lens; k++ {
				if seqs[a][k] != seqs[b][k] {
					diff = append(diff, k)
				}
			}

			diffmatrix = append(diffmatrix, diff)
		}

		cmatrix := covs.NewCMatrix(samp, lens, diffmatrix)

		ks, vd := cmatrix.D()
		dfile.WriteString(fmt.Sprintf("%g,%g\n", ks, vd))

		scovs, rcovs, xyPL, xsysPL, smXYPL := cmatrix.CovCircle(maxl)

		for j := 0; j < maxl; j++ {
			moments[0][j].Increment(scovs[j])
			moments[1][j].Increment(rcovs[j])
			moments[2][j].Increment(xyPL[j])
			moments[3][j].Increment(xsysPL[j])
			moments[4][j].Increment(smXYPL[j])
		}

		if (i+1)%(gens/100) == 0 {
			cfile, err := os.Create(fmt.Sprintf("%s_covs.csv", prefix))
			if err != nil {
				log.Panic(err)
			}

			cfile.WriteString(fmt.Sprintf("#size: %d\n", size))
			cfile.WriteString(fmt.Sprintf("#length: %d\n", lens))
			cfile.WriteString(fmt.Sprintf("#fragment: %d\n", frag))
			cfile.WriteString(fmt.Sprintf("#mutation: %g\n", mutation))
			cfile.WriteString(fmt.Sprintf("#transfer: %g\n", transfer))
			cfile.WriteString(fmt.Sprintf("#generations: %d\n", i+1))
			cfile.WriteString("dist, scov, rcov, xy, xsys, smxy_sd, scov_sd, rcov_sd, xy_sd, xsys_sd, smxy_sd\n")

			for j := 0; j < maxl; j++ {
				cfile.WriteString(fmt.Sprintf("%d,%g,%g,%g,%g,%g,%g,%g,%g,%g,%g\n",
					j,
					moments[0][j].Mean.GetResult(),
					moments[1][j].Mean.GetResult(),
					moments[2][j].Mean.GetResult(),
					moments[3][j].Mean.GetResult(),
					moments[4][j].Mean.GetResult(),
					moments[0][j].Sd.GetResult(),
					moments[1][j].Sd.GetResult(),
					moments[2][j].Sd.GetResult(),
					moments[3][j].Sd.GetResult(),
					moments[4][j].Sd.GetResult(),
				))
			}
			cfile.Close()
			log.Printf("Finish %%%d\n", (i+1)/(gens/100))
		}
	}

	// save the population for further use
	pfile, err := os.Create(fmt.Sprintf("%s.json", prefix))
	if err != nil {
		log.Panic(err)
	}
	defer pfile.Close()

	pfile.Write(sp.Json())
}