diff --git a/ActiveBOWeb/package.json b/ActiveBOWeb/package.json index e4e8e34..7de3e8e 100644 --- a/ActiveBOWeb/package.json +++ b/ActiveBOWeb/package.json @@ -16,6 +16,8 @@ "roslib": "^1.3.0", "vue": "^3.2.45", "vue-resource": "^1.5.3", + "vue-slider-component": "^3.2.24", + "vue3-slider": "^1.8.0", "vuetify": "^3.1.4" }, "devDependencies": { diff --git a/ActiveBOWeb/src/components/PolicyPlot.vue b/ActiveBOWeb/src/components/PolicyPlot.vue new file mode 100644 index 0000000..d4885a6 --- /dev/null +++ b/ActiveBOWeb/src/components/PolicyPlot.vue @@ -0,0 +1,13 @@ + + + + + diff --git a/ActiveBOWeb/src/components/RewardPlot.vue b/ActiveBOWeb/src/components/RewardPlot.vue index 93ff345..ddd1cbd 100644 --- a/ActiveBOWeb/src/components/RewardPlot.vue +++ b/ActiveBOWeb/src/components/RewardPlot.vue @@ -10,8 +10,106 @@ import { onMounted, watch, } from "vue"; -import { Chart } from 'chart.js/auto'; +import { Chart } from "chart.js/auto"; +import { useRStore } from "@/store/RewardStore"; +const store = useRStore(); + +let chartHandle; + +function buildChart() { + const reward_mean = store.getMean(); + const reward_std = store.getStd(); + const upper_bound = Array(reward_mean.length).fill(0).map((_, i) => reward_mean[i] + 1.96 * reward_std[i]); + const lower_bound = Array(reward_mean.length).fill(0).map((_, i) => reward_mean[i] - 1.96 * reward_std[i]); + const reward_labels = Array(reward_mean.length).fill(0).map((_, i) => i); + const RewardPlot = { + data: { + datasets: [ + { + label: 'Reward', + type: 'line', + xAxisID: 'x', + yAxisID: 'y', + fill: false, + data: reward_mean, + borderColor: '#3DC47A', + borderWidth: 2, + pointRadius: 0, + }, + { + type: 'line', + xAxisID: 'x', + yAxisID: 'y', + fill: 0, + data: upper_bound, + pointRadius: 0, + borderColor: 'transparent', + + }, + { + type: 'line', + xAxisID: 'x', + yAxisID: 'y', + fill: 0, + data: lower_bound, + pointRadius: 0, + borderColor: 'transparent', + + }, + ], + }, + options: { + maintainAspectRatio: false, + responsive: true, + animation: { + duration: 0, + }, + lineTension: 0, + tooltip: { + mode: 'label', + }, + scales: { + x: { + grid: { + display: false, + }, + labels: reward_labels, + ticks: { + autoSkip: true, + }, + }, + y: + { + type: 'linear', + ticks: { + beginAtZero: true, + }, + }, + }, + }, + }; + const ctx = document.getElementById('reward-chart'); + // eslint-disable-next-line no-new + chartHandle = new Chart(ctx, RewardPlot); +} + +onMounted(() => { + buildChart(); +}); + +watch(() => store.getMean(), () => { + const reward_mean = store.getMean(); + const reward_std = store.getStd(); + const upper_bound = Array(reward_mean.length).fill(0).map((_, i) => reward_mean[i] + 1.96 * reward_std[i]); + const lower_bound = Array(reward_mean.length).fill(0).map((_, i) => reward_mean[i] - 1.96 * reward_std[i]); + + chartHandle.data.dataset[0].data = reward_mean; + chartHandle.data.dataset[1].data = upper_bound; + chartHandle.data.dataset[2].data = lower_bound; + + chartHandle.update(); +}); diff --git a/ActiveBOWeb/src/components/SubLayout.vue b/ActiveBOWeb/src/components/SubLayout.vue index 2dd905f..48ba00b 100644 --- a/ActiveBOWeb/src/components/SubLayout.vue +++ b/ActiveBOWeb/src/components/SubLayout.vue @@ -1,9 +1,9 @@ diff --git a/ActiveBOWeb/src/store/BaseWebsiteStore.js b/ActiveBOWeb/src/store/BaseWebsiteStore.js index 9737359..6cd7ed6 100644 --- a/ActiveBOWeb/src/store/BaseWebsiteStore.js +++ b/ActiveBOWeb/src/store/BaseWebsiteStore.js @@ -1,6 +1,6 @@ import { defineStore } from "pinia"; -export const useBWStore = defineStore('BaseWebsiteStore', { +export const useBWStore = defineStore('Base Website Store', { state: () => { return { play: false, diff --git a/ActiveBOWeb/src/store/MountainCarStore.js b/ActiveBOWeb/src/store/MountainCarStore.js index 536ba0d..3e381d0 100644 --- a/ActiveBOWeb/src/store/MountainCarStore.js +++ b/ActiveBOWeb/src/store/MountainCarStore.js @@ -1,6 +1,6 @@ import { defineStore } from "pinia"; -export const useMCStore = defineStore('MountainCarStore', { +export const useMCStore = defineStore('Mountain Car Store', { state: () => { return { play: false, diff --git a/ActiveBOWeb/src/store/PolicyStore.js b/ActiveBOWeb/src/store/PolicyStore.js new file mode 100644 index 0000000..1fe78bf --- /dev/null +++ b/ActiveBOWeb/src/store/PolicyStore.js @@ -0,0 +1,27 @@ +import { defineStore } from "pinia"; + +export const usePStore = defineStore('Policy Store', { + state: () => { + return { + policy: Array, + weights: [-1, 1, 1], + nr_steps: 0, + } + }, + getters: { + getPolicy: (state) => state.policy, + getWeights: (state) => state.weights, + getNrSteps: (state) => state.nr_steps, + }, + actions: { + setPolicy(value) { + this.policy = value; + }, + setWeights(value) { + this.weights = value; + }, + setNrSteps(value) { + this.nr_steps = value; + }, + } +}) diff --git a/ActiveBOWeb/src/store/RewardStore.js b/ActiveBOWeb/src/store/RewardStore.js index e69de29..3e9b3f9 100644 --- a/ActiveBOWeb/src/store/RewardStore.js +++ b/ActiveBOWeb/src/store/RewardStore.js @@ -0,0 +1,27 @@ +import { defineStore } from "pinia"; + +export const useRStore = defineStore('Reward Store', { + state: () => { + return { + reward_mean: Array, + reward_std: Array, + nr_episodes: 0, + } + }, + getters: { + getMean: (state) => state.reward_mean, + getStd: (state) => state.reward_std, + getNrEpisodes: (state) => state.nr_episodes, + }, + actions: { + setMean(value) { + this.reward_mean = value; + }, + setStd(value) { + this.reward_std = value; + }, + setNrEpisodes(value) { + this.nr_episodes = value; + }, + } +})