Behavioural Engines
A platform that turns foundational decision science models into interactive, working simulations.
Overview
Behavioural Engines brings together what I have learnt in behavioural science and programming. The idea came from Michael Hallsworth's Behavioural Insights, which argues that behavioural science needs a core framework to move forward. This project takes the frameworks at the heart of the field and turns them into working models you can experiment with.
Demo
Model catalogue
The platform is built around a catalogue of models, with prospect theory and hyperbolic discounting at its core and others, such as rational inattention, added over time. Each model is an independent, versioned unit within a shared structure.
New models slot in cleanly because each one defines its own assumptions, equations, and parameter ranges, so adding one never means restructuring the wider platform.

Catalogue
Mathematical implementation
The core of the project is mathematical. Every model is implemented from first principles in Python, so prospect theory's value functions, probability weighting curves, and discounting functions are all computed live from their underlying equations.
Translating theory into code exposed edge cases that are easy to miss on paper, from numerical stability to how sensitive each model is to its parameters, and deepened my understanding of the models themselves.

Model
Structured outputs
Every simulation produces the same output for the same inputs: clear metrics, a readable summary, and a versioned log that can be revisited later. The aim was a platform genuinely useful for teaching and experimentation.
Runs are stored in PostgreSQL alongside the model version that produced them, so results stay reproducible as the platform evolves.

Results
Visual representation
The graphs are drawn directly from each model's mathematical output, so changing a parameter updates the equations and redraws the curves in real time.

Graphs
Experiments
The models can also be run as experiments. A researcher builds a set of choice tasks from one of them, shares a join code, and every respondent's answers are fitted back into that model's parameters by maximum likelihood, with standard errors taken from the curvature of the fit. Option order and task order are randomised for each respondent so that position bias does not end up inside the estimates.
Results appear as they arrive and export with the parameter estimates, demographics, and the model version that produced them.

Study
Synthetic audiences
An experiment can also be answered by AI respondents rather than people. Each one is a real anonymised census record narrated as a first-person persona, and a language model answers the choice tasks in character while the platform fits parameters from those answers exactly as it does for humans.
The method is silicon sampling, following Argyle et al. (2023), with personas drawn from published microdata, the ONS 2011 Census teaching file for the UK, ACS 2023 PUMS for the US, and HESA totals for students, so age, region, and occupation stay correlated the way they are in reality. Layering the data this way is what lets a persona stand in for a real person, so the loss curve it produces under prospect theory reflects the sort of person it was built from.

Personas
Cohort analysis
Once a population exists you can put new decisions to it. Define a gamble or a delay trade-off and every respondent answers through their own fitted parameters and the model's equations, which keeps the prediction deterministic with no AI in the loop. The same panel compares cohort medians against the published literature estimates, tests human and synthetic cohorts against each other, and opens any individual respondent to show their demographics, their parameters, and the model that produced them.

Cohorts
Architecture and infrastructure
A Next.js frontend on Vercel talks to a FastAPI backend on Railway, with Clerk handling accounts and PostgreSQL storing the simulation logs.
Building this forced me to properly understand CORS policies, token verification, environment configuration, rate limiting, and production debugging.

Learning
What this project represents
Building Behavioural Engines taught me a great deal, from React state and Python to the design decisions that make a platform easier to use, such as a command-K palette and carefully written support pages. It also demanded real thought about versioning, typed interfaces, and how the platform could scale as new models arrive.
Building the models in code also strengthened my understanding of them. Translating prospect theory and hyperbolic discounting into formal, executable structures made their assumptions and constraints much clearer than studying them in theory alone.

Updates
Where it is going
A changelog page tracks every model addition and update, giving the platform a sense of ongoing development. There are currently six models, each of which took genuine thought to implement correctly, and the intention is to keep adding slowly, making sure each one earns its place in the catalogue. Stripe has since been integrated to support subscriptions.
Built with
- TypeScript
- Next.js
- FastAPI
- PostgreSQL
- Railway
- Vercel
- Clerk
- Redis
- Tailwind CSS
- Framer Motion
- Stripe
More projects