func main() {
	features := 15
	size := 10
	numAgents := 30
	runs := 200
	FollowedBlogs := 4
	probveloc := 0.15
	steplength := 0.2
	sight := 1.0
	POnline := 0.5
	PLooking := 0.2
	goabm.Init()
	//fmt.Printf("#Parameter search...\n");
	Min1 := 10
	Max1 := 20

	Min2 := 10
	Max2 := 20

	fmt.Printf("traits,f, cdiff,onc,offc,avgon,avgoff\n")
	for i := Min1; i < Max1; i++ {
		for j := Min2; j < Max2; j++ {

			r := simRun(i, features, size, numAgents, runs, FollowedBlogs, probveloc, steplength, sight, POnline, PLooking)

			fmt.Printf("%d, %d, %d, %d, %d, %f, %f\n", i, j, r.CultureDiff, r.OnlineCultures, r.OfflineCultures, r.AvgOnline, r.AvgOffline)
		}
	}

}
Exemple #2
0
func main() {
	//initialize the goabm library (logs & flags)
	goabm.Init()

	var traits = flag.Int("traits", 15, "number of cultural traits per feature")
	var features = flag.Int("features", 15, "number of cultural features")
	var size = flag.Int("size", 10, "size (width/height) of the landscape")

	var runs = flag.Int("runs", 200, "number of simulation runs")
	flag.Parse()
	fmt.Println("ABM simulation")
	// create your model which has to satisfy the Modeler interface
	model := &Axelrod{Traits: *traits, Features: *features}
	// create the simulation with a Landscape, your model and a logger
	sim := &goabm.Simulation{Landscape: &goabm.FixedLandscapeNoMovement{Size: *size}, Model: model, Log: goabm.Logger{StdOut: true}}
	sim.Init()
	for i := 0; i < *runs; i++ {
		//fmt.Printf("Step #%d, Events:%d, Cultures:%d\n", i, sim.Stats.Events, model.Cultures)
		if model.Cultures == 1 {
			sim.Stop()
			fmt.Printf("Stimulation prematurely done\n")
			return
		}
		sim.Step()

	}
	sim.Stop()
	fmt.Printf("Stimulation done\n")

}
Exemple #3
0
func main() {
	//initialize the goabm library (logs & flags)
	goabm.Init()

	fmt.Println("ABM simulation")
	// general model parameters
	var traits = flag.Int("traits", 5, "number of cultural traits per feature")
	var Features = flag.Int("Features", 5, "number of cultural Features")
	var size = flag.Int("size", 10, "size (width/height) of the landscape")

	// parameters for the moving model
	var probveloc = flag.Float64("pveloc", 0.05, "probability that an agent moves")
	var steplength = flag.Float64("steplength", 0.1, "maximal distance a agent can travel per step")
	var sight = flag.Float64("sight", 1, "radius in which agent can interact")
	var numAgents = flag.Int("agents", 100, "number of agents to simulate")

	var runs = flag.Int("runs", 200, "number of simulation runs")
	flag.Parse()

	model := &Axelrod{Traits: *traits, Features: *Features, ProbVeloc: *probveloc, Steplength: *steplength}
	sim := &goabm.Simulation{Landscape: &goabm.FixedLandscapeWithMovement{Size: *size, NAgents: *numAgents, Sight: *sight},
		Model: model, Log: goabm.Logger{StdOut: true}}
	sim.Init()
	for i := 0; i < *runs; i++ {
		//fmt.Printf("Step #%d, Events:%d, Cultures:%d\n", i, sim.Stats.Events, model.Cultures)
		if model.Cultures == 1 {
			sim.Stop()
			fmt.Printf("Stimulation prematurely done\n")
			return
		}
		sim.Step()

	}
	sim.Stop()
	//fmt.Printf("%v\n",sim.Landscape.GetAgents())

}
func omain() {
	goabm.Init()

	var traits = flag.Int("traits", 25, "number of cultural traits per feature")
	var features = flag.Int("features", 15, "number of cultural features")
	var size = flag.Int("size", 10, "size (width/height) of the landscape")

	var probveloc = flag.Float64("pveloc", 0.15, "probability that an agent moves")
	var steplength = flag.Float64("steplength", 0.2, "maximal distance a agent can travel per step")
	var sight = flag.Float64("sight", 1, "radius in which agent can interact")

	var FollowedBlogs = flag.Int("blogs", 4, "number of blogs to follow in the virtual world")
	var POnline = flag.Float64("p-online", 0.5, "probability of being online")
	var PLooking = flag.Float64("p-looking", 0.2, "probability of looking for new blogs (more similar and ditching old ones)")

	var runs = flag.Int("runs", 300, "number of simulation runs")
	var numAgents = flag.Int("agents", 30, "number of agents to simulate")

	var memprofile = flag.String("memprofile", "", "write memory profile to this file")
	var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

	flag.Parse()

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	model := &EchoChamberModel{Traits: *traits, Features: *features, PVeloc: *probveloc, Steplength: *steplength,
		FollowedBlogs: *FollowedBlogs, POnline: *POnline, PLookingForBlogs: *PLooking}
	physicalWorld := &goabm.FixedLandscapeWithMovement{Size: *size, NAgents: *numAgents, Sight: *sight}
	virtualWorld := &goabm.NetworkLandscape{}

	combinedLandscape := &MultilevelLandscape{Base: physicalWorld, Overlay: virtualWorld}

	sim := &goabm.Simulation{Landscape: combinedLandscape, Model: model, Log: goabm.Logger{StdOut: false}}
	fmt.Println("ABM simulation")
	sim.Init()

	var diffScore = 0

	for i := 0; i < *runs; i++ {

		diffScore += Abs(model.PhysicalCultures - model.VirtualCultures)
		if model.PhysicalCultures == 1 || model.VirtualCultures == 1 {
			sim.Stop()
			fmt.Printf("Stimulation prematurely done\n")
			break
		}
		sim.Step()

	}
	sim.Stop()

	d := model.Landscape.Dump()

	var avgOffline, avgOnline float64
	var sOnline, sOffline uint

	for _, a := range d.Nodes {
		v := a.(*EchoChamberAgent)
		sOnline += v.OnlineChangeCounter
		sOffline += v.OfflineChangeCounter
		//fmt.Printf("Node: %d : %d - %d\n",i,v.OnlineChangeCounter,v.OfflineChangeCounter)
	}
	avgOffline = float64(sOffline / uint(len(d.Nodes)))
	avgOnline = float64(sOnline / uint(len(d.Nodes)))
	fmt.Printf("\nAverage Online: %f Offline: %f\n", avgOnline, avgOffline)

	fmt.Printf("Total diff: %d\n", diffScore)
	if *memprofile != "" {
		f, err := os.Create(*memprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.WriteHeapProfile(f)
		f.Close()
		return
	}
	//fmt.Printf("%v\n",sim.Landscape.GetAgents())
}
Exemple #5
0
func main() {

	//initialize the goabm library (logs & flags)
	goabm.Init()

	var memprofile = flag.String("memprofile", "", "write memory profile to this file")
	var cpuprofile = flag.String("cpuprofile", "", "write cpu profile to file")

	flag.Parse()

	if *cpuprofile != "" {
		f, err := os.Create(*cpuprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	//f := dst.Beta(2.0,2.0)

	/*
	    combine MC with Sa?
	   inner loop is MC sampling?
	*/
	//fmt.Printf("#Parameter search...\n");

	//fmt.Printf("%d, %d, %d, %d, %d, %f, %f\n", traits, features, r.CultureDiff, r.OnlineCultures, r.OfflineCultures, r.AvgOnline, r.AvgOffline)
	/*
		PStartBlogging := 0.005
		PWriteBlogPost := 0.2
		PRespondBlogPost := 0.1
	*/
	/*
		// simulated annealing
		p := Parameters{
			Probabilities: []float64{PStartBlogging,
				PWriteBlogPost,
				PRespondBlogPost},
		}

		sa := SimulatedAnnealing{Temp: 100, CoolingRate: 0.01, KMax: 400}
		sa.Parameters = p
		sa.TF = mt
		r := sa.Run()
		fmt.Printf("best score %f for %v\n", r.Energy, r)*/
	rules := goabm.Ruleset{}
	rules.Init()
	rules.SetRule("movement", true)            // not implemented
	rules.SetRule("transmission_error", false) // not implemented
	rules.SetRule("only_stable_models", false) // not implemented

	/*
	   pf(Online) = α, β
	   pf(ActiveInteraction) = α, β
	   pf(Understanding) = α, β
	*/

	/*pfOnline := BPFP{α: DiscreteVarWithLimit{Min:2.5, Max: 12, Var:1.5},
	  β: DiscreteVarWithLimit{Min:0.1, Max: 7, Var:2}}

	  pfActiveInteraction := BPFP{α: DiscreteVarWithLimit{Min:0.5, Max: 7, Var:2} ,
	  β: DiscreteVarWithLimit{Min:0.5, Max: 9, Var:2}}*/

	pfUnderstanding := BPFP{α: DiscreteVarWithLimit{Min: 300, Max: 1150, Var: 1.8},
		β: DiscreteVarWithLimit{Min: 1, Max: 500, Var: 2.1}}

	/*
	   search space = 6 dimensions
	*/

	p := Parameters{Probabilities: []BPFP{ /*pfOnline,pfActiveInteraction,*/ pfUnderstanding, pfUnderstanding, pfUnderstanding}, Rules: rules}

	// parameter search
	res := 55
	samples := res * res // best multiple of N^2

	pars := samplePS(p, samples)
	fmt.Printf("size of ps: %d", len(pars))
	mt := MyTarget{}
	// run model for each parameter
	fmt.Printf("run, score, pfOnline, pfActiveInteraction, pfUnderstanding\n")

	// keep n best
	keep := 15

	best := Results{}
	best.Init(keep)

	fon, _ := os.Create("pfOnline.csv")
	fai, _ := os.Create("pfAI.csv")
	fu, _ := os.Create("pfU.csv")

	fmt.Fprintf(fon, "score, α, β\n")
	fmt.Fprintf(fai, "score, α, β\n")
	fmt.Fprintf(fu, "score, α, β\n")

	for i, p := range pars {
		/*if 0 == p.Probabilities[0] {
		continue
		}*/
		r := mt.Run(p)

		/*
			fmt.Printf("%d,\t %f,\t (α: %.2f,β: %.2f),\t (α: %.2f,β: %.2f),\t (α: %.2f,β: %.2f)\n", i, r,
			p.Probabilities[0].α.Var, p.Probabilities[0].β.Var,
			p.Probabilities[1].α.Var, p.Probabilities[1].β.Var,
			p.Probabilities[2].α.Var, p.Probabilities[2].β.Var,)*/

		fmt.Printf("%d,\t %f,\t (α: %.2f,β: %.2f),\t \n", i, r,
			p.Probabilities[0].α.Var, p.Probabilities[0].β.Var)

		srr := SimRunRes{Parameters: p, Score: r}
		best.Check(srr)

		//fmt.Fprintf(fon,"%f, %f, %f\n",r, p.Probabilities[0].α.Var, p.Probabilities[0].β.Var)
		// fmt.Fprintf(fai,"%f, %f, %f\n",r, p.Probabilities[1].α.Var, p.Probabilities[2].β.Var)
		fmt.Fprintf(fu, "%f, %f, %f\n", r, p.Probabilities[0].α.Var, p.Probabilities[0].β.Var)

	}

	/*ioutil.WriteFile("pfOnline.csv",[]byte(logpfOnline),0777)
	ioutil.WriteFile("pfAI.csv",[]byte(logpfActiveInteraction),0777)
		ioutil.WriteFile("pfU.csv",[]byte(logpfUnderstanding),0777)/*/

	fmt.Printf("Best res:\n")

	asA1 := 0.0
	asB1 := 0.0
	/*	asA2:=0.0
		asB2:=0.0
			asA3:=0.0
		asB3:=0.0*/

	for i := 0; i < keep; i++ {
		if best.Best[i].Score > 10 {
			continue
		}
		/* fmt.Printf("#%d, score: %f\t (α: %.2f,β: %.2f),\t (α: %.2f,β: %.2f),\t (α: %.2f,β: %.2f)\n",i, best.Best[i].Score,
		 best.Best[i].Probabilities[0].α.Var, best.Best[i].Probabilities[0].β.Var,
			best.Best[i].Probabilities[1].α.Var, best.Best[i].Probabilities[1].β.Var,
			best.Best[i].Probabilities[2].α.Var, best.Best[i].Probabilities[2].β.Var,)*/

		fmt.Printf("#%d, score: %f\t (α: %.2f,β: %.2f),\n", i, best.Best[i].Score,
			best.Best[i].Probabilities[0].α.Var, best.Best[i].Probabilities[0].β.Var)

		asA1 += best.Best[i].Probabilities[0].α.Var
		//	asA2 += best.Best[i].Probabilities[1].α.Var
		//		asA3 += best.Best[i].Probabilities[2].α.Var

		asB1 += best.Best[i].Probabilities[0].β.Var
		//	asB2 += best.Best[i].Probabilities[1].β.Var
		//		asB3 += best.Best[i].Probabilities[2].β.Var
	}

	avgA1 := asA1 / float64(keep)
	//avgA2 := asA2 / float64(keep)
	//avgA3 := asA3 / float64(keep)
	avgB1 := asB1 / float64(keep)
	//avgB2 := asB2 / float64(keep)
	//avgB3 := asB3 / float64(keep)

	/*fmt.Printf("avg:\t (α: %.2f,β: %.2f),\t (α: %.2f,β: %.2f),\t (α: %.2f,β: %.2f)\n",
	avgA1,avgB1, avgA2, avgB2, avgA3, avgB3)*/
	fmt.Printf("avg:\t (α: %.2f,β: %.2f),\t \n",
		avgA1, avgB1)

	if *memprofile != "" {
		f, err := os.Create(*memprofile)
		if err != nil {
			log.Fatal(err)
		}
		pprof.WriteHeapProfile(f)
		f.Close()
		return
	}
}