void OnEnable() { recorder = GetComponent <MyRecorder>(); recorder.OnAudioReady += OnAudioReady; encoder = new UnityOpus.Encoder( UnityOpus.SamplingFrequency.Frequency_48000, UnityOpus.NumChannels.Mono, UnityOpus.OpusApplication.Audio) { Bitrate = bitrate, Complexity = 10, Signal = UnityOpus.OpusSignal.Music }; }
public async Task InitialFullExplorationTest() { var recorder = new MyRecorder(); using (var model = new MemoryStream()) { using (var vw = new VowpalWabbit("--cb_explore_adf --epsilon 0.3")) { vw.Learn(new[] { "1:-3:0.2 | b:2" }); vw.ID = "123"; vw.SaveModel(model); } var config = new DecisionServiceConfiguration("") { OfflineMode = true, OfflineApplicationID = "", DevelopmentMode = true }; var metaData = new ApplicationClientMetadata { TrainArguments = "--cb_explore_adf --epsilon 0.3", InitialExplorationEpsilon = 1f }; using (var ds = DecisionService.CreateJson(config, metaData: metaData).WithRecorder(recorder)) { var decision = await ds.ChooseRankingAsync("abc", "{\"a\":1,\"_multi\":[{\"b\":2}]}"); // since there's not a model loaded why should get 100% exploration // Assert.AreEqual(1f, recorder.LastExplorerState.Probability); model.Position = 0; ds.UpdateModel(model); decision = await ds.ChooseRankingAsync("abc", "{\"a\":1,\"_multi\":[{\"b\":2}, {\"b\":3}]}"); // Assert.AreNotEqual(1f, recorder.LastExplorerState.Probability); var vwState = recorder.LastMapperState as VWState; Assert.IsNotNull(vwState); Assert.AreEqual("123", vwState.ModelId); } } }
public static void Run() { string exploration_type = "greedy"; if (exploration_type == "greedy") { // Initialize Epsilon-Greedy explore algorithm using built-in StringRecorder and SimpleContext types StringRecorder <SimpleContext> recorder = new StringRecorder <SimpleContext>(); MwtExplorer <SimpleContext> mwtt = new MwtExplorer <SimpleContext>("mwt", recorder); uint numActions = 10; float epsilon = 0.2f; StringPolicy policy = new StringPolicy(); SimpleContext context = new SimpleContext(new Feature[] { new Feature() { Id = 1, Value = 0.5f }, new Feature() { Id = 4, Value = 1.3f }, new Feature() { Id = 9, Value = -0.5f }, }); uint action = mwtt.ChooseAction(new EpsilonGreedyExplorer <SimpleContext>(policy, epsilon, numActions), "key", context); Console.WriteLine(recorder.GetRecording()); return; } else if (exploration_type == "tau-first") { // Initialize Tau-First explore algorithm using custom Recorder, Policy & Context types MyRecorder recorder = new MyRecorder(); MwtExplorer <MyContext> mwtt = new MwtExplorer <MyContext>("mwt", recorder); uint numActions = 10; uint tau = 0; MyPolicy policy = new MyPolicy(); uint action = mwtt.ChooseAction(new TauFirstExplorer <MyContext>(policy, tau, numActions), "key", new MyContext()); Console.WriteLine(String.Join(",", recorder.GetData())); return; } else if (exploration_type == "bagging") { // Initialize Bagging explore algorithm using custom Recorder, Policy & Context types MyRecorder recorder = new MyRecorder(); MwtExplorer <MyContext> mwtt = new MwtExplorer <MyContext>("mwt", recorder); uint numActions = 10; uint numbags = 2; MyPolicy[] policies = new MyPolicy[numbags]; for (int i = 0; i < numbags; i++) { policies[i] = new MyPolicy(i * 2); } uint action = mwtt.ChooseAction(new BaggingExplorer <MyContext>(policies, numbags, numActions), "key", new MyContext()); Console.WriteLine(String.Join(",", recorder.GetData())); return; } else if (exploration_type == "softmax") { // Initialize Softmax explore algorithm using custom Recorder, Scorer & Context types MyRecorder recorder = new MyRecorder(); MwtExplorer <MyContext> mwtt = new MwtExplorer <MyContext>("mwt", recorder); uint numActions = 10; float lambda = 0.5f; MyScorer scorer = new MyScorer(numActions); uint action = mwtt.ChooseAction(new SoftmaxExplorer <MyContext>(scorer, lambda, numActions), "key", new MyContext()); Console.WriteLine(String.Join(",", recorder.GetData())); return; } else if (exploration_type == "generic") { // Initialize Generic explore algorithm using custom Recorder, Scorer & Context types MyRecorder recorder = new MyRecorder(); MwtExplorer <MyContext> mwtt = new MwtExplorer <MyContext>("mwt", recorder); uint numActions = 10; MyScorer scorer = new MyScorer(numActions); uint action = mwtt.ChooseAction(new GenericExplorer <MyContext>(scorer, numActions), "key", new MyContext()); Console.WriteLine(String.Join(",", recorder.GetData())); return; } else { //add error here } }
public static void Run() { string exploration_type = "greedy"; if (exploration_type == "greedy") { // Initialize Epsilon-Greedy explore algorithm using built-in StringRecorder and SimpleContext types // Creates a recorder of built-in StringRecorder type for string serialization StringRecorder <SimpleContext> recorder = new StringRecorder <SimpleContext>(); int numActions = 10; float epsilon = 0.2f; // Creates an Epsilon-Greedy explorer using the specified settings var explorer = new EpsilonGreedyExplorer(epsilon); // Creates an MwtExplorer instance using the recorder above // Creates a policy that interacts with SimpleContext type var mwtt = MwtExplorer.Create("mwt", numActions, recorder, explorer, new StringPolicy()); // Creates a context of built-in SimpleContext type SimpleContext context = new SimpleContext(new float[] { .5f, 1.3f, -.5f }); // Performs exploration by passing an instance of the Epsilon-Greedy exploration algorithm into MwtExplorer // using a sample string to uniquely identify this event string uniqueKey = "eventid"; int action = mwtt.ChooseAction(uniqueKey, context); Console.WriteLine(recorder.GetRecording()); return; } else if (exploration_type == "tau-first") { // Initialize Tau-First explore algorithm using custom Recorder, Policy & Context types MyRecorder recorder = new MyRecorder(); int numActions = 10; int tau = 0; //MwtExplorer<MyContext> mwtt = new MwtExplorer<MyContext>("mwt", recorder); var mwtt = MwtExplorer.Create("mwt", numActions, recorder, new TauFirstExplorer(tau), new MyPolicy()); int action = mwtt.ChooseAction("key", new MyContext()); Console.WriteLine(String.Join(",", recorder.GetAllInteractions().Select(it => it.Action))); return; } else if (exploration_type == "bootstrap") { // TODO: add support for bootstrap //// Initialize Bootstrap explore algorithm using custom Recorder, Policy & Context types //MyRecorder recorder = new MyRecorder(); ////MwtExplorer<MyContext> mwtt = new MwtExplorer<MyContext>("mwt", recorder); //uint numActions = 10; //uint numbags = 2; //MyPolicy[] policies = new MyPolicy[numbags]; //for (int i = 0; i < numbags; i++) //{ // policies[i] = new MyPolicy(i * 2); //} //var mwtt = MwtExplorer.Create("mwt", recorder, new BootstrapExplorer(numActions)); //uint action = mwtt.ChooseAction(new BootstrapExplorer<MyContext>(policies, numActions), "key", new MyContext()); //Console.WriteLine(String.Join(",", recorder.GetAllInteractions().Select(it => it.Action))); return; } else if (exploration_type == "softmax") { // TODO: add support for softmax //// Initialize Softmax explore algorithm using custom Recorder, Scorer & Context types //MyRecorder recorder = new MyRecorder(); //MwtExplorer<MyContext> mwtt = new MwtExplorer<MyContext>("mwt", recorder); //uint numActions = 10; //float lambda = 0.5f; //MyScorer scorer = new MyScorer(numActions); //uint action = mwtt.ChooseAction(new SoftmaxExplorer<MyContext>(scorer, lambda, numActions), "key", new MyContext()); //Console.WriteLine(String.Join(",", recorder.GetAllInteractions().Select(it => it.Action))); return; } else if (exploration_type == "generic") { // TODO: add support for generic //// Initialize Generic explore algorithm using custom Recorder, Scorer & Context types //MyRecorder recorder = new MyRecorder(); //MwtExplorer<MyContext> mwtt = new MwtExplorer<MyContext>("mwt", recorder); //uint numActions = 10; //MyScorer scorer = new MyScorer(numActions); //uint action = mwtt.ChooseAction(new GenericExplorer<MyContext>(scorer, numActions), "key", new MyContext()); //Console.WriteLine(String.Join(",", recorder.GetAllInteractions().Select(it => it.Action))); return; } else { //add error here } }
public static void Run() { string exploration_type = "greedy"; if (exploration_type == "greedy") { // Initialize Epsilon-Greedy explore algorithm using built-in StringRecorder and SimpleContext types // Creates a recorder of built-in StringRecorder type for string serialization StringRecorder <SimpleContext> recorder = new StringRecorder <SimpleContext>(); // Creates an MwtExplorer instance using the recorder above MwtExplorer <SimpleContext> mwtt = new MwtExplorer <SimpleContext>("mwt", recorder); // Creates a policy that interacts with SimpleContext type StringPolicy policy = new StringPolicy(); uint numActions = 10; float epsilon = 0.2f; // Creates an Epsilon-Greedy explorer using the specified settings EpsilonGreedyExplorer <SimpleContext> explorer = new EpsilonGreedyExplorer <SimpleContext>(policy, epsilon, numActions); // Creates a context of built-in SimpleContext type SimpleContext context = new SimpleContext(new Feature[] { new Feature() { Id = 1, Value = 0.5f }, new Feature() { Id = 4, Value = 1.3f }, new Feature() { Id = 9, Value = -0.5f }, }); // Performs exploration by passing an instance of the Epsilon-Greedy exploration algorithm into MwtExplorer // using a sample string to uniquely identify this event string uniqueKey = "eventid"; uint action = mwtt.ChooseAction(explorer, uniqueKey, context); Console.WriteLine(recorder.GetRecording()); return; } else if (exploration_type == "tau-first") { // Initialize Tau-First explore algorithm using custom Recorder, Policy & Context types MyRecorder recorder = new MyRecorder(); MwtExplorer <MyContext> mwtt = new MwtExplorer <MyContext>("mwt", recorder); uint numActions = 10; uint tau = 0; MyPolicy policy = new MyPolicy(); uint action = mwtt.ChooseAction(new TauFirstExplorer <MyContext>(policy, tau, numActions), "key", new MyContext()); Console.WriteLine(String.Join(",", recorder.GetAllInteractions().Select(it => it.Action))); return; } else if (exploration_type == "bootstrap") { // Initialize Bootstrap explore algorithm using custom Recorder, Policy & Context types MyRecorder recorder = new MyRecorder(); MwtExplorer <MyContext> mwtt = new MwtExplorer <MyContext>("mwt", recorder); uint numActions = 10; uint numbags = 2; MyPolicy[] policies = new MyPolicy[numbags]; for (int i = 0; i < numbags; i++) { policies[i] = new MyPolicy(i * 2); } uint action = mwtt.ChooseAction(new BootstrapExplorer <MyContext>(policies, numActions), "key", new MyContext()); Console.WriteLine(String.Join(",", recorder.GetAllInteractions().Select(it => it.Action))); return; } else if (exploration_type == "softmax") { // Initialize Softmax explore algorithm using custom Recorder, Scorer & Context types MyRecorder recorder = new MyRecorder(); MwtExplorer <MyContext> mwtt = new MwtExplorer <MyContext>("mwt", recorder); uint numActions = 10; float lambda = 0.5f; MyScorer scorer = new MyScorer(numActions); uint action = mwtt.ChooseAction(new SoftmaxExplorer <MyContext>(scorer, lambda, numActions), "key", new MyContext()); Console.WriteLine(String.Join(",", recorder.GetAllInteractions().Select(it => it.Action))); return; } else if (exploration_type == "generic") { // Initialize Generic explore algorithm using custom Recorder, Scorer & Context types MyRecorder recorder = new MyRecorder(); MwtExplorer <MyContext> mwtt = new MwtExplorer <MyContext>("mwt", recorder); uint numActions = 10; MyScorer scorer = new MyScorer(numActions); uint action = mwtt.ChooseAction(new GenericExplorer <MyContext>(scorer, numActions), "key", new MyContext()); Console.WriteLine(String.Join(",", recorder.GetAllInteractions().Select(it => it.Action))); return; } else { //add error here } }