Public
Edited
Mar 16, 2024
1 star
Insert cell
Insert cell
Insert cell
Plot.plot({
title: "Forgetting curve",
subtitle: "Retention (y) over time (x)",
caption: "Try sliding the number of repetitions input and see how retention changes.",
x: { label: "Time", ticks: [] },
y: { label: "Retention", domain: [0, scale], ticks: [scale], tickFormat: d => `${d}%` },
marginTop: 32,
marks: [
Plot.frame({anchor: "left"}),
Plot.frame({anchor: "bottom"}),
Plot.line(generateForgettingCurve(numRepetitions)),
]
})
Insert cell
Insert cell
Insert cell
Insert cell
function generateEbbinghausForgettingCurve() {
const datapoints = [];
const K = 1.84;
const C = 1.25;

for (let time = 1; time <= 100; time++) {
const retention = (100 * K) / (Math.pow(Math.log(time), C) + K)
datapoints.push([time, retention])
}

return datapoints;
}
Insert cell
Insert cell
Insert cell
function generateForgettingCurve(num) {
const intervals = getRepetitionIntervals(num, scale)
const coordinates = [];
let base = 2;
let adj = 0

for (let time = 0; time <= scale; time++) {
if (time === intervals[0]) {
base *= 2;
adj = intervals.shift()
}
const retention = (1 / getBaseLog(base, time - adj + base)) * scale;
coordinates.push([time, retention])
}

console.log(coordinates)
return coordinates;
}
Insert cell
function getRepetitionIntervals(reps, scale) {
// if only 1 repetition, hard-code the interval
if (reps === 1) return [40]

const repetitions = Array.from({ length: reps }, (_, index) => index + 1)
const sumOfSquares = repetitions.reduce((sum, value) => sum + value ** 2, 0);
const intervals = []
for (let i = 0; i < repetitions.length; i++) {
const interval = repetitions[i] ** 2 / sumOfSquares
intervals.push(Math.floor(interval * scale))
}

return intervals
}
Insert cell
// E.g. getBaseLog(3, 27) returns 3 because log base 3 of 27 is 3
function getBaseLog (b, x) {
return Math.log(x) / Math.log(b);
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more