public void UsageBadVariableActionContext() { int numExceptionsCaught = 0; int numExceptionsExpected = 5; var tryCatchArgumentException = (Action <Action>)((action) => { try { action(); } catch (ArgumentException ex) { if (ex.ParamName.ToLower() == "ctx") { numExceptionsCaught++; } } }); tryCatchArgumentException(() => { var mwt = new MwtExplorer <TestContext>("test", new TestRecorder <TestContext>()); var policy = new TestPolicy <TestContext>(); var explorer = new EpsilonGreedyExplorer <TestContext>(policy, 0.2f); mwt.ChooseAction(explorer, "key", new TestContext()); }); tryCatchArgumentException(() => { var mwt = new MwtExplorer <TestContext>("test", new TestRecorder <TestContext>()); var policy = new TestPolicy <TestContext>(); var explorer = new TauFirstExplorer <TestContext>(policy, 10); mwt.ChooseAction(explorer, "key", new TestContext()); }); tryCatchArgumentException(() => { var mwt = new MwtExplorer <TestContext>("test", new TestRecorder <TestContext>()); var policies = new TestPolicy <TestContext> [2]; for (int i = 0; i < 2; i++) { policies[i] = new TestPolicy <TestContext>(i * 2); } var explorer = new BootstrapExplorer <TestContext>(policies); mwt.ChooseAction(explorer, "key", new TestContext()); }); tryCatchArgumentException(() => { var mwt = new MwtExplorer <TestContext>("test", new TestRecorder <TestContext>()); var scorer = new TestScorer <TestContext>(10); var explorer = new SoftmaxExplorer <TestContext>(scorer, 0.5f); mwt.ChooseAction(explorer, "key", new TestContext()); }); tryCatchArgumentException(() => { var mwt = new MwtExplorer <TestContext>("test", new TestRecorder <TestContext>()); var scorer = new TestScorer <TestContext>(10); var explorer = new GenericExplorer <TestContext>(scorer); mwt.ChooseAction(explorer, "key", new TestContext()); }); Assert.AreEqual(numExceptionsExpected, numExceptionsCaught); }
public void TauFirst() { uint numActions = 10; uint tau = 0; string uniqueKey = "ManagedTestId"; TestRecorder <TestContext> recorder = new TestRecorder <TestContext>(); TestPolicy policy = new TestPolicy(); MwtExplorer <TestContext> mwtt = new MwtExplorer <TestContext>("mwt", recorder); TestContext testContext = new TestContext() { Id = 100 }; var explorer = new TauFirstExplorer <TestContext>(policy, tau, numActions); uint expectedAction = policy.ChooseAction(testContext); uint chosenAction = mwtt.ChooseAction(explorer, uniqueKey, testContext); Assert.AreEqual(expectedAction, chosenAction); var interactions = recorder.GetAllInteractions(); Assert.AreEqual(0, interactions.Count); }
public void TauFirstFixedActionUsingVariableActionInterface() { int numActions = 10; int tau = 0; var testContext = new VariableActionTestContext(numActions) { Id = 100 }; var policy = new TestPolicy <VariableActionTestContext>(); var explorer = new TauFirstExplorer(tau); TauFirstWithContext(numActions, testContext, policy, explorer); }
public void TauFirst() { int numActions = 10; int tau = 0; RegularTestContext testContext = new RegularTestContext() { Id = 100 }; var policy = new TestPolicy <RegularTestContext>(); var explorer = new TauFirstExplorer(tau); TauFirstWithContext(numActions, testContext, policy, explorer); }
public void EndToEndTauFirst() { uint numActions = 10; uint tau = 5; TestRecorder <SimpleContext> recorder = new TestRecorder <SimpleContext>(); TestSimplePolicy policy = new TestSimplePolicy(); MwtExplorer <SimpleContext> mwtt = new MwtExplorer <SimpleContext>("mwt", recorder); var explorer = new TauFirstExplorer <SimpleContext>(policy, tau, numActions); EndToEnd(mwtt, explorer, recorder); }
public void TauFirst() { uint numActions = 10; uint tau = 0; TestContext testContext = new TestContext() { Id = 100 }; var policy = new TestPolicy <TestContext>(); var explorer = new TauFirstExplorer <TestContext>(policy, tau, numActions); TauFirstWithContext(numActions, testContext, policy, explorer); }
static void ExploreTauFirst <TContext> ( string appId, int policyType, JToken configPolicy, int tau, int numActions, string[] experimentalUnitIdList, TContext[] contextList, string outputFile ) { var recorder = new StringRecorder <TContext>(); bool isVariableActionContext = typeof(IVariableActionContext).IsAssignableFrom(typeof(TContext)); switch (policyType) { case 0: // fixed policy { var policyAction = configPolicy["Action"].Value <uint>(); var policy = new TestPolicy <TContext> { ActionToChoose = policyAction }; var explorer = new TauFirstExplorer(tau); var mwt = isVariableActionContext ? MwtExplorer.Create(appId, new VariableActionProvider <TContext>(), recorder, explorer, policy) : MwtExplorer.Create(appId, numActions, recorder, explorer, policy); for (int i = 0; i < experimentalUnitIdList.Length; i++) { int numActionsVariable = isVariableActionContext ? ((IVariableActionContext)contextList[i]).GetNumberOfActions() : int.MaxValue; mwt.ChooseAction(experimentalUnitIdList[i], contextList[i]); } File.AppendAllText(outputFile, recorder.GetRecording()); break; } } }