AEPsych is a framework and library for adaptive experimentation in psychophysics and related domains made by folks at Meta Reality Labs. It is open source and available on GitHub here.
These samples are driven using an AEPsych server running locally, communicating with Unity via ZeroMQ. Experiment are defined in Unity and sent over to the server, then each trial's configuration is requested from the server, and the outcome is sent back.
- AEPsych server running in ZeroMQ mode
- Important: AEPsych is in active development, these examples are based on the specific commit linked (81b6b9385b) and has been known to work on that specific state. Unfortunately, the latest commit will most likely be in a broken state. These samples will be updated again once there is an actual release.
- Install the server in you python environment following the instructions in their repo
- Launch the server using
python aepsych/server.py --socket_type zmq
- Note: You should not import AEPsych's Unity client, as it is not suited for our workflow and not a dependency.
- NetMQ for ZeroMQ communication with AEPsych
- Newtonsoft Json for serialization
Start by installing the prerequisites (NetMQ & Json.NET) - you can use NuGetForUnity, then install the sample from the Package Manager: Under the package, open the Samples foldout and click Install under AEPsych-driven.
Important: Copy the configs
folder from the imported sample into your Assets/StreamingAssets
folder.
All the samples are in a single scene AEPsychSamples.unity
. After hitting Play, you can choose from four samples (these mimic some of the samples provided with AEPsych):
- 1D Threshold Estimation from Single Observations: determine the minimum brightness to see a circle.
- 1D Optimization from Single Observations: find your optimal 'medium gray' circle
- 2D Optimization from Single Observations: find your optimal 'indigo' circle among colors with varying red and blue channels (2 dimensions)
- 3D Optimization from Single Observations: find your optimal 'indigo' circle among colors with varying red, green and blue channels (3 dimensions)
aepsych-sample.mp4
There are three main components to the AEPsych samples
-
AEPsychClient.cs
: This is my implementation of AEPsych's Unity client. It maintains the Request/Reply pattern from ZeroMQ by having the user provide a callback for a response for every request. For example, callingAEPsychClient.AskForNextTrialConfig(...)
requires a callback with parametersTrialConfig, bool
e.g.void MyCallback(TrialConfig t, bool isFinished) {}
. -
AEPsychTrial.cs
: This class is derived fromTrial
and holds theTrialConfig
,isFinished
, andoutcome
properties. Phases would reference this trial by casting from theirtrial
property, i.e.((AEPsychTrial)trial).isFinished = true;
. The trial uses theEndless
flag, and therefore onceisFinished
istrue
,ExitTrial()
will be called to end the trial. Simply put, AEPsych has control over the number of trials. -
AEPsych(...)Phase.cs
These are a collection of phases that recreates AEPsych's Setup→(Ask→Tell)↺ loop.AEPsychSetupPhase.cs
AEPsychAskPhase.cs
AEPsychTellPhase.cs
AEPsychResumePhase.cs
AEPsychSample(...)Phase.cs
other helper Phases to help present stimulus and collect data
Here's a diagram showing how the components work together:
AEPsychClient.cs was adapted from AEPsych's Unity Client, its license is available here: https://github.com/facebookresearch/aepsych/blob/main/LICENSE
The server configurations were copied from https://github.com/facebookresearch/aepsych/tree/main/clients/unity/Assets/StreamingAssets/configs
The rest of the files are subject to the license provided in this repository