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 EndToEndGeneric() { uint numActions = 10; TestRecorder <SimpleContext> recorder = new TestRecorder <SimpleContext>(); TestScorer <SimpleContext> scorer = new TestScorer <SimpleContext>(numActions); MwtExplorer <SimpleContext> mwtt = new MwtExplorer <SimpleContext>("mwt", recorder); var explorer = new GenericExplorer <SimpleContext>(scorer, numActions); EndToEnd(mwtt, explorer, recorder); }
public void GenericFixedActionUsingVariableActionInterface() { int numActions = 10; var scorer = new TestScorer <VariableActionTestContext>(1, numActions); var testContext = new VariableActionTestContext(numActions) { Id = 100 }; var explorer = new GenericExplorer(); GenericWithContext(numActions, testContext, explorer, scorer); }
public void Generic() { int numActions = 10; var scorer = new TestScorer <RegularTestContext>(1, numActions); RegularTestContext testContext = new RegularTestContext() { Id = 100 }; var explorer = new GenericExplorer(); GenericWithContext(numActions, testContext, explorer, scorer); }
public void Generic() { uint numActions = 10; TestScorer <TestContext> scorer = new TestScorer <TestContext>(numActions); TestContext testContext = new TestContext() { Id = 100 }; var explorer = new GenericExplorer <TestContext>(scorer, numActions); GenericWithContext(numActions, testContext, explorer); }
public void Generic() { uint numActions = 10; string uniqueKey = "ManagedTestId"; TestRecorder <TestContext> recorder = new TestRecorder <TestContext>(); TestScorer <TestContext> scorer = new TestScorer <TestContext>(numActions); MwtExplorer <TestContext> mwtt = new MwtExplorer <TestContext>("mwt", recorder); var explorer = new GenericExplorer <TestContext>(scorer, numActions); TestContext testContext = new TestContext() { Id = 100 }; uint chosenAction = mwtt.ChooseAction(explorer, uniqueKey, testContext); var interactions = recorder.GetAllInteractions(); Assert.AreEqual(1, interactions.Count); Assert.AreEqual(testContext.Id, interactions[0].Context.Id); }
static void ExploreGeneric <TContext> ( string appId, int policyType, JToken configPolicy, 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 all-equal scorer { var scorerScore = configPolicy["Score"].Value <int>(); var scorer = new TestScorer <TContext>(scorerScore, numActions); var explorer = new GenericExplorer(); var mwt = isVariableActionContext ? MwtExplorer.Create(appId, new VariableActionProvider <TContext>(), recorder, explorer, scorer) : MwtExplorer.Create(appId, numActions, recorder, explorer, scorer); 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; } case 1: // integer-progression scorer { var scorerStartScore = configPolicy["Start"].Value <int>(); var scorer = new TestScorer <TContext>(scorerStartScore, numActions, uniform: false); var explorer = new GenericExplorer(); var mwt = isVariableActionContext ? MwtExplorer.Create(appId, new VariableActionProvider <TContext>(), recorder, explorer, scorer) : MwtExplorer.Create(appId, numActions, recorder, explorer, scorer); 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; } } }