diff --git a/examples/ContextBandit.jsx b/examples/ContextBandit.jsx index 77538a1..aea07e8 100644 --- a/examples/ContextBandit.jsx +++ b/examples/ContextBandit.jsx @@ -84,6 +84,14 @@ function ContextFruitBandit() { generateNewRecommendation(); }; + const HandleReset = () => { + setTrainingData([]); + setActionIdFeatures(true); + setActionFeatures(true); + setContextActionIdInteractions(true); + setContextActionFeatureInteractions(true); + }; + return (

Context dependent recommendations

@@ -221,6 +229,7 @@ function ContextFruitBandit() {
{JSON.stringify(trainingData)}

JSON serialized bandit

{serializedBandit}
+
); } diff --git a/examples/SlateBandit.jsx b/examples/SlateBandit.jsx index 20b6d1a..8afe3f9 100644 --- a/examples/SlateBandit.jsx +++ b/examples/SlateBandit.jsx @@ -21,11 +21,13 @@ function SlateFruitBandit() { cake: { fruit: -1, treat: 1 }, }, temperature: 0.2, - slateSize: 3, + slateSize: slateSize, slateNegativeSampleWeight: 0.5, }); + banditInstance.train(trainingData); + setSerializedBandit(banditInstance.toJSON()); setBandit(banditInstance); - }, []); + }, [slateSize]); useEffect(() => { if (bandit) { @@ -34,7 +36,7 @@ function SlateFruitBandit() { }, [bandit, slateSize]); const generateNewRecommendation = () => { - setSlate(bandit.slate({}, { slateSize: slateSize })); + setSlate(bandit.slate()); const _scoredActions = bandit.getScoredActions(); _scoredActions.forEach((scoredAction) => { const actionFeatures = bandit.actionsMap[scoredAction.actionId].features; @@ -61,6 +63,11 @@ function SlateFruitBandit() { generateNewRecommendation(); }; + const handleReset = () => { + setTrainingData([]); + setSlateSize(3); + }; + return (

Slate of multiple recommendations

@@ -133,6 +140,7 @@ function SlateFruitBandit() {
{JSON.stringify(trainingData)}

JSON serialized bandit

{serializedBandit}
+
); } diff --git a/examples/TemperatureBandit.jsx b/examples/TemperatureBandit.jsx index 06cd2cd..293de2a 100644 --- a/examples/TemperatureBandit.jsx +++ b/examples/TemperatureBandit.jsx @@ -48,6 +48,12 @@ function TemperatureFruitBandit() { generateNewRecommendation(); }; + const handleReset = () => { + setTrainingData([]); + setLearningRate(0.1); + setTemperature(0.1); + }; + return (

Adjusting the Fruit Bandit

@@ -124,6 +130,7 @@ function TemperatureFruitBandit() { )} +

Training Data

You can see the training data that is generated by accepting and @@ -133,6 +140,7 @@ function TemperatureFruitBandit() {

JSON serialized bandit

You can serialize the bandit to JSON and then rehydrate it later.

{serializedBandit}
+
); } diff --git a/examples/WeightedBandit.jsx b/examples/WeightedBandit.jsx index 3af0846..28f5537 100644 --- a/examples/WeightedBandit.jsx +++ b/examples/WeightedBandit.jsx @@ -12,20 +12,16 @@ function WeightedFruitBandit() { const [starRating, setStarRating] = useState(null); useEffect(() => { - let oldClickOracleWeights = bandit ? { ...bandit.oracle[0].weights } : {}; const clickOracle = new SimpleOracle({ learningRate: 0.1, targetLabel: "click", oracleWeight: clickWeight, - weights: oldClickOracleWeights, }); - let oldStarsOracleWeights = bandit ? { ...bandit.oracle[1].weights } : {}; const starsOracle = new SimpleOracle({ learningRate: 0.1, targetLabel: "stars", oracleWeight: 1 - clickWeight, - weights: oldStarsOracleWeights, }); const banditInstance = new SimpleBandit({ @@ -39,10 +35,10 @@ function WeightedFruitBandit() { cake: { treat: 1 }, }, temperature: 0.2, - slateSize: 3, }); + setSerializedBandit(banditInstance.toJSON()); + banditInstance.train(trainingData); setBandit(banditInstance); - setSerializedBandit(bandit ? bandit.toJSON() : ""); }, [clickWeight]); useEffect(() => { @@ -87,6 +83,13 @@ function WeightedFruitBandit() { setClickWeight(newWeight); }; + const handleReset = () => { + setTrainingData([]); + setSelectedAction(null); + setStarRating(null); + setClickWeight(0.5); + }; + return (

Weighted oracles

@@ -197,6 +200,7 @@ function WeightedFruitBandit() {
{JSON.stringify(trainingData)}

JSON serialized bandit

{serializedBandit}
+
); }