Skip to content

Commit ada040c

Browse files
committed
Add draft of 4th exercise
1 parent fd3c2da commit ada040c

2 files changed

Lines changed: 53 additions & 57 deletions

File tree

images/reactiontime.svg

Lines changed: 0 additions & 53 deletions
This file was deleted.

tutorials/hobgoblin-reaction.md

Lines changed: 53 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
# Reaction Time Task
22

3-
In this tutorial, you will learn how to use the [Harp Hobgoblin](https://github.com/harp-tech/device.hobgoblin) to implement a simple reaction time task, which will serve as our model systems neuroscience experiment. In this task, the subject needs to press a button as fast as possible following a stimulus, as described in the following diagram:
3+
In this tutorial, you will learn how to use the [Harp Hobgoblin](https://github.com/harp-tech/device.hobgoblin) to implement a reaction time task which can be easily adapted and modified to model a wide range of systems neuroscience experiments.
44

5-
:::diagram
6-
![State Machine Diagram](../images/reactiontime.svg)
7-
:::
5+
When designing operant behaviour assays, it is useful to describe the task as a sequence of states the system goes through (e.g. stimulus on, stimulus off, reward, inter-trial interval, etc). Progression through these states is driven by events, which can be either internal or external to the system (e.g. button press, timeout, stimulus offset, movement onset). It is common to describe the interplay between states and events in the form of a finite-state machine diagram, or graph, where nodes are states, and arrows are events.
6+
7+
A reaction time task, where the subject needs to press a button as fast as possible following a stimulus, is described in the following diagram:
8+
9+
```mermaid
10+
stateDiagram-v2
11+
direction LR
12+
[*] --> ITI
13+
ITI --> ON: elapsed
14+
ON --> Reward: hit
15+
ON --> Fail: miss
16+
Reward --> [*]
17+
Fail --> [*]
18+
```
819

920
The task begins with an inter-trial interval (`ITI`), followed by stimulus presentation (`ON`). After stimulus onset, advancement to the next state can happen only when the subject presses the button (`success`) or a timeout elapses (`miss`). Depending on which event is triggered first, the task advances either to the `Reward` state, or `Fail` state. At the end, the task goes back to the beginning of the ITI state for the next trial.
1021

@@ -112,6 +123,43 @@ print(f"There were {num_valid_responses} valid responses out of {num_total_trial
112123
pd.Series(valid_response_times).plot(kind="box", ylim=(0,1), ylabel = "Response Times (seconds)", title = "Boxplot of valid response times")
113124
```
114125

126+
### Exercise 4: Driving state transitions with external behaviour events
127+
128+
In order to translate our simple reaction time task in the previous exercises into a proper state machine, we need to split up the fixed interval stimulus into different states. It is often convenient to consider the inter-trial interval period as the initial state, followed by stimulus presentation. We will begin with the workflow portion from the end of [Exercise 1](#exercise-1-generating-a-fixed-interval-stimulus).
129+
130+
:::workflow
131+
![Stimulus presentation](../workflows/hobgoblin-reactiontime-stimulus-response.bonsai)
132+
:::
133+
134+
- Select the [`Timer`] operator and set its `DueTime` property to 3 second.
135+
- Click and drag to select both the [`CreateMessage`]([`DigitalOutputSetPayload`]) and `Hobgoblin Commands` operators.
136+
- Right-click, select `Group` > `Sink (Reactive)`. Set the `Name` property to `StimOn`.
137+
- Click and drag to select both the [`CreateMessage`]([`DigitalOutputClearPayload`]) and `Hobgoblin Commands` operators.
138+
- Right-click, select `Group` > `Sink (Reactive)`. Set the `Name` property to `StimOff`.
139+
140+
> [!Note]
141+
> The `Sink` operator allows you to specify arbitrary processing side-effects without affecting the original flow of events. It is often used to trigger and control stimulus presentation in response to events in the task. Inside the nested specification, `Source1` represents input events arriving at the sink. In the specific case of `Sink` operators, the `WorkflowOutput` node can be safely ignored.
142+
143+
- Delete the [`Delay`] operator.
144+
- Insert a [`SelectMany`] operator after `StimOn`, and set its `Name` property to `Response`.
145+
- Double-click on the [`SelectMany`] node to open up its internal specification.
146+
147+
:::workflow
148+
![Stimulus presentation](../workflows/hobgoblin-reactiontime-stimulus-response.bonsai)
149+
:::
150+
151+
- Insert a [`SubscribeSubject`] operator. Configure the `Name` property to `Hobgoblin Events`.
152+
- Insert a [`Parse`] operator after `Hobgoblin Events`. Configure the `Register` property to [`TimestampedDigitalInputState`].
153+
154+
155+
156+
157+
158+
159+
160+
161+
162+
115163
<!--Reference Style Links -->
116164
<!-- [`AnalogData`]: xref:Harp.Hobgoblin.AnalogData -->
117165
<!-- [`AnalogDataPayload`]: xref:Harp.Hobgoblin.AnalogDataPayload -->
@@ -131,6 +179,7 @@ pd.Series(valid_response_times).plot(kind="box", ylim=(0,1), ylabel = "Response
131179
[`MulticastSubject`]: xref:Bonsai.Expressions.MulticastSubject
132180
[`PublishSubject`]: xref:Bonsai.Reactive.PublishSubject
133181
[`Repeat`]: xref:Bonsai.Reactive.Repeat
182+
[`Sink`]: xref:Bonsai.Reactive.Sink
134183
[`SubscribeSubject`]: xref:Bonsai.Expressions.SubscribeSubject
135184
[`Timer`]: xref:Bonsai.Reactive.Timer
136185
<!-- [`TimestampedAnalogData`]: xref:Harp.Hobgoblin.TimestampedAnalogData -->

0 commit comments

Comments
 (0)