예제 #1
0
파일: fs3sys.go 프로젝트: skelterjohn/rlenv
func main() {
	defer nicetrace.Print()
	cfg := ConfigDefault()
	argcfg.LoadArgs(&cfg)
	agent := sysadmin.NewBFS3Agent(cfg.BFS3, cfg.Sysadmin)
	rlglue.LoadAgent(agent)
}
예제 #2
0
파일: fl.go 프로젝트: postfix/rlbayes
func main() {
	defer nicetrace.Print()
	cfg = ConfigDefault()
	argcfg.LoadArgs(&cfg)
	agent := NewAgent(cfg)
	rlglue.LoadAgent(agent)
}
예제 #3
0
func TestEnvTraj(t *testing.T) {
	if false {
		return
	}
	stat.TimeSeed()
	defer nicetrace.Print()
	env := New()
	obsi := env.EnvStart()
	indexi := task.Obs.Ints.Index(obsi.Ints())
	b := NewBelief(make(MapBelief, 16))
	b.Teleport(indexi)
	fmt.Printf("%v\n", b.Hunter)
	do := func(what int32) bool {
		action := rlglue.NewAction([]int32{what}, []float64{}, []byte{})
		obs, r, t := env.EnvStep(action)
		fmt.Println(what, r)
		if t {
			fmt.Println("done")
			return false
		}
		index := task.Obs.Ints.Index(obs.Ints())
		bs := b.Update(uint64(what), index, r)
		b = bs.(*Belief)
		fmt.Printf("%v\n", b.Hunter)
		return true
	}
	guess := func() (what int32) {
		fmt.Scanf("%d", &what)
		return
	}
	for do(guess()) {
	}
}
예제 #4
0
파일: coffee.go 프로젝트: skelterjohn/rlenv
func main() {
	defer nicetrace.Print()
	cfg := coffee.ConfigDefault()
	argcfg.LoadArgs(&cfg)
	env := coffee.NewEnv(cfg)
	if err := rlglue.LoadEnvironment(env); err != nil {
		println(err.String())
	}
}
예제 #5
0
파일: paint.go 프로젝트: skelterjohn/rlenv
func main() {
	defer nicetrace.Print()
	config := paint.ConfigDefault()
	argcfg.LoadArgs(&config)
	env := paint.New(config)
	env.Live = false
	if err := rlglue.LoadEnvironment(env); err != nil {
		fmt.Println("Error running paint: %v\n", err)
	}
}
예제 #6
0
파일: plottest.go 프로젝트: postfix/rlbayes
func inferenceLoop() {
	defer nicetrace.Print()
	for i := 0; running; i++ {
		const cycle = 100
		counter := i % cycle
		temperature := 2 * (float64(cycle-counter) / cycle)
		rpost.SweepC(temperature)
		rpost.SweepG(temperature)
	}
}
예제 #7
0
func main() {
	defer nicetrace.Print()
	cfg := coffee.ConfigDefault()
	argcfg.LoadArgs(&cfg)
	agent := coffee.NewOptAgent(cfg)
	err := rlglue.LoadAgent(agent)
	if err != nil {
		fmt.Println(err)
	}
}
예제 #8
0
파일: grid.go 프로젝트: skelterjohn/rlenv
func main() {
	defer nicetrace.Print()
	var config Config
	config.Width, config.Height = 3, 3
	argcfg.LoadArgs(&config)
	genv := grid.New(int32(config.Width), int32(config.Height))
	if err := rlglue.LoadEnvironment(genv); err != nil {
		fmt.Println("Error running grid: %v\n", err)
	}
}
예제 #9
0
파일: dep_test.go 프로젝트: postfix/rlbayes
func TestDepMatch(t *testing.T) {
	defer nicetrace.Print()
	stat.Seed(seed)
	tstr := "VERSION RL-Glue-3.0 PROBLEMTYPE episodic DISCOUNTFACTOR 1 OBSERVATIONS INTS (0 4) (-1 1) (0 2) ACTIONS INTS (0 1) REWARDS (0 1.0)"
	task, _ := rlglue.ParseTaskSpec(tstr)
	stateRanges := task.Obs.Ints
	actionRanges := task.Act.Ints
	cfg := ConfigDefault()
	cfg.Alpha = alpha
	cfg.M = M
	genDLs := []*DepLearner{NewDepLearner(0, cfg, stateRanges, actionRanges), NewDepLearner(1, cfg, stateRanges, actionRanges), NewDepLearner(2, cfg, stateRanges, actionRanges)}
	genDLs[0].SetParents(ParentSet(0).Insert(0, 1))
	genDLs[1].SetParents(ParentSet(0).Insert(0, 2))
	genDLs[2].SetParents(ParentSet(0).Insert(2))
	patDLs := []*DepLearner{NewDepLearner(0, cfg, stateRanges, actionRanges), NewDepLearner(1, cfg, stateRanges, actionRanges), NewDepLearner(2, cfg, stateRanges, actionRanges)}
	numStates := stateRanges.Count()
	numActions := actionRanges.Count()
	RS := stat.Range(int64(numStates))
	RA := stat.Range(int64(numActions))
	startTime := time.Nanoseconds()
	lastWrongStep := make([]int, len(genDLs))
	for i := 0; i < steps; i++ {
		s := uint64(RS())
		a := uint64(RA())
		nv := make([]int32, len(genDLs))
		for child := 0; child < len(nv); child++ {
			nv[child] = genDLs[child].Next(s, a)
		}
		for child := 0; child < len(nv); child++ {
			genDLs[child] = genDLs[child].Update(s, a, nv[child])
		}
		for child := 0; child < len(nv); child++ {
			patDLs[child] = patDLs[child].Update(s, a, nv[child])
		}
		if i%1 == 0 {
			for child := 0; child < len(nv); child++ {
				patDLs[child].ConsiderRandomFlip()
				if genDLs[child].parents != patDLs[child].parents {
					lastWrongStep[child] = i
				}
			}
		}
	}
	fmt.Println(lastWrongStep)
	endTime := time.Nanoseconds()
	duration := endTime - startTime
	if true {
		fmt.Printf("Ran in %fms\n", float64(duration)/1e6)
	}
	for child := range genDLs {
		if genDLs[child].parents != patDLs[child].parents {
			t.Error(fmt.Sprintf("%d: %v != %v", child, genDLs[child].parents.Slice(), patDLs[child].parents.Slice()))
		}
	}
}
예제 #10
0
func main() {
	defer nicetrace.Print()
	var cfg Config
	cfg.M = 5
	cfg.Depth = 10
	cfg.NumTrajectories = 500
	cfg.FS3 = fsss.ConfigDefault()
	argcfg.LoadArgs(&cfg)
	agent := NewRmaxFSSSAgent(cfg)
	rlglue.LoadAgent(agent)
}
예제 #11
0
파일: rmax.go 프로젝트: skelterjohn/rlalg
func main() {
	defer nicetrace.Print()
	var config rmax.RmaxConfig
	config.M = 5
	config.Epsilon = .1
	argcfg.LoadArgs(&config)
	ragent := rmax.NewRmaxAgent(config)
	if err := rlglue.LoadAgent(ragent); err != nil {
		fmt.Println("Error running rmax: %v\n", err)
	}
}
예제 #12
0
func main() {
	defer nicetrace.Print()
	var cfg Config
	cfg.NumActions = 5
	argcfg.LoadArgs(&cfg)
	ones := make([]float64, cfg.NumActions)
	for i, _ := range ones {
		ones[i] = 1
	}
	genv := bbandits.NewEnv(bbandits.NewBelief(ones, ones))
	if err := rlglue.LoadEnvironment(genv); err != nil {
		fmt.Println("Error running grid: %v\n", err)
	}
}
예제 #13
0
파일: plottest.go 프로젝트: postfix/rlbayes
func drawLoop() {
	defer nicetrace.Print()
	for i := 0; running; i++ {
		const cycle = 100
		counter := i % cycle
		drawAssignments()
		window.FlushImage()
		if true {
			time.Sleep(0.5e8)
		}
		if counter == 0 {
		}
	}
}
예제 #14
0
func OpenFile(file string) (code string) {
	defer nicetrace.Print()

	data, err := ReadFile(file)

	if err == nil {
		buf := bytes.NewBuffer([]byte{})
		EditorT.Execute(buf, Source{file, data})
		code = buf.String()
	} else {
		code = err.String()
	}
	return
}
예제 #15
0
func main() {
	defer nicetrace.Print()
	cfg := sysadmin.ConfigDefault()
	argcfg.LoadArgs(&cfg)
	if false {
		env := sysadmin.New(cfg)
		if err := rlglue.LoadEnvironment(env); err != nil {
			println(err.String())
		}
	} else {
		mdp := sysadmin.NewSysMDP(cfg)
		env := discrete.NewMDPEnvNoReset(mdp, mdp.Task, (1<<uint(cfg.NumSystems))-1)
		if err := rlglue.LoadEnvironment(env); err != nil {
			println(err.String())
		}
	}
}
예제 #16
0
파일: dep_test.go 프로젝트: postfix/rlbayes
func TestBeliefMatch(t *testing.T) {
	defer nicetrace.Print()
	stat.Seed(seed)
	tstr := "VERSION RL-Glue-3.0 PROBLEMTYPE episodic DISCOUNTFACTOR 1 OBSERVATIONS INTS (0 4) (-1 1) (0 2) ACTIONS INTS (0 1) REWARDS (0 1.0)"
	task, _ := rlglue.ParseTaskSpec(tstr)
	cfg := ConfigDefault()
	cfg.Alpha = alpha
	cfg.M = M
	beliefG := NewBelief(cfg, task)
	beliefG.learners[0].SetParents(ParentSet(0).Insert(0, 1))
	beliefG.learners[1].SetParents(ParentSet(0).Insert(0, 2))
	beliefG.learners[2].SetParents(ParentSet(0).Insert(2))
	beliefP := NewBelief(cfg, task)
	numStates := task.Obs.Ints.Count()
	numActions := task.Act.Ints.Count()
	RS := stat.Range(int64(numStates))
	RA := stat.Range(int64(numActions))
	startTime := time.Nanoseconds()
	lastWrongStep := make([]int, len(task.Obs.Ints))
	for i := 0; i < steps; i++ {
		s := uint64(RS())
		a := uint64(RA())
		n := beliefG.Next(s, a)
		beliefG = beliefG.Update(s, a, n).(*Belief)
		beliefP = beliefP.Update(s, a, n).(*Belief)
		if i%1 == 0 {
			beliefP.ConsiderRandomFlipAll()
			for child, learner := range beliefP.learners {
				if beliefG.learners[child].parents != learner.parents {
					lastWrongStep[child] = i
				}
			}
		}
	}
	fmt.Println(lastWrongStep)
	endTime := time.Nanoseconds()
	duration := endTime - startTime
	if true {
		fmt.Printf("Ran in %fms\n", float64(duration)/1e6)
	}
	for child := range beliefP.learners {
		if beliefG.learners[child].parents != beliefP.learners[child].parents {
			t.Error(fmt.Sprintf("%d: %v != %v", child, beliefG.learners[child].parents.Slice(), beliefP.learners[child].parents.Slice()))
		}
	}
}
예제 #17
0
파일: plottest.go 프로젝트: postfix/rlbayes
func main() {
	defer nicetrace.Print()
	block = make(chan bool, 1)
	var err os.Error
	window, err = x11.NewWindow()
	if err != nil {
		fmt.Printf("%v\n", err)
	}
	clearScreen()
	cfg := roar.PosteriorCFGDefault()
	cfg.Partition = 1
	cfg.M = 1
	rpost = roar.New(cfg)
	running = true
	go drawLoop()
	go inferenceLoop()
	processEvents(window.EventChan())
	running = false
}
예제 #18
0
파일: beb.go 프로젝트: skelterjohn/rlalg
func main() {
	defer nicetrace.Print()
	var config Config
	config.BEB = beb.BebConfigDefault()
	argcfg.LoadArgs(&config)
	var getRFoo func(task *rlglue.TaskSpec) (foo beb.RewardFunc)
	switch config.Which {
	case 0:
		getRFoo = func(task *rlglue.TaskSpec) (foo beb.RewardFunc) {
			foo = func(s discrete.State, a discrete.Action) (r float64) {
				return -1
			}
			return
		}
	case 2:
		getRFoo = getRewardFooPaint
	}
	bebagent := beb.NewBebAgent(config.BEB, getRFoo)
	if err := rlglue.LoadAgent(bebagent); err != nil {
		fmt.Println("Error running rmax: %v\n", err)
	}
}
예제 #19
0
파일: gorf.go 프로젝트: newblue/gorf
func main() {
	defer nicetrace.Print()

	var err os.Error

	erf := func(format string, args ...interface{}) {
		fmt.Fprintf(os.Stderr, format, args...)
	}
	defer func() {
		if err != nil {
			erf("%v\n", err)
		}
	}()

	flag.StringVar(&LocalRoot, "r", ".", "Local package root")
	flag.BoolVar(&Usage, "?", false, "Print usage and quit")

	flag.Parse()

	norollCmds := map[string]func([]string) os.Error{
		"undo":    UndoCmd,
		"scan":    ScanCmd,
		"changes": ChangesCmd,
		"clear":   ClearCmd,
	}

	rollCmds := map[string]func([]string) os.Error{

		"pkg":     PkgCmd,
		"rename":  RenameCmd,
		"move":    MoveCmd,
		"moveall": MoveAllCmd,
		"merge":   MergeCmd,
	}

	foo, ok := norollCmds[flag.Arg(0)]
	if ok && Usage {
		fmt.Print(Help(flag.Arg(0)))
		return
	}
	if !ok {
		foo, ok = rollCmds[flag.Arg(0)]
		err = RollbackUndos()
		if err != nil {
			return
		}

		if ok {
			var out io.Writer
			out, err = os.Create(filepath.Join(LocalRoot, ".change.0.gorfc"))
			if err != nil {
				return
			}
			cmdline := strings.Join(flag.Args(), " ")
			fmt.Fprintf(out, "%s\n", cmdline)
		}
		//out.Close()
	}

	if !ok || Usage || len(flag.Args()) == 0 {
		erf(UsageText)
		erf("flags\n")
		flag.PrintDefaults()
		return
	}

	err = foo(flag.Args()[1:])

}