Skip to content

Commit 1a7f700

Browse files
committed
Copy go-no and CPP exercises from state machine tutorial
1 parent 8ffdd78 commit 1a7f700

3 files changed

Lines changed: 177 additions & 0 deletions

File tree

tutorials/hobgoblin-reaction.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,61 @@ _Try out your state machine and check whether you understand the behavior of the
234234

235235
_Try out your state machine and introduce variations to the task behavior and conditions._
236236

237+
### Exercise 7: Go/No-Go task
238+
239+
Implement the following trial structure for a Go/No-Go task.
240+
241+
```mermaid
242+
stateDiagram-v2
243+
direction LR
244+
NoGo: No-Go
245+
FalseAlarm: False<br>Alarm
246+
CorrectReject: Correct<br>Reject
247+
[*] --> ITI
248+
ITI --> Go: 50%
249+
ITI --> NoGo: 50%
250+
Go --> Hit
251+
Go --> Miss
252+
NoGo --> FalseAlarm
253+
NoGo --> CorrectReject
254+
```
255+
256+
- Trials should be sampled from a uniform distribution using the `Numerics` package (install from `Tools` > `Manage Packages`).
257+
- Response events should be based on a button press, and reject events on a timeout.
258+
- Make sure to implement different visual or auditory feedback for either the cue or reward/failure states.
259+
260+
> [!Tip]
261+
> To sample values from a discrete uniform distribution, you can use the following workflow:
262+
> :::workflow
263+
> ![Sampling Values](../workflows/hobgoblin-reactiontime-samplediscreteuniform.bonsai)
264+
> :::
265+
266+
- Record a timestamped chronological log of trial types and rewards into a CSV file using a [`BehaviorSubject`].
267+
268+
### Exercise 8: Conditioned place preference
269+
270+
Implement the following trial structure for conditioned place preference. `enter` and `leave` events should be triggered in real-time from the camera, by tracking an object moving in or out of a region of interest (ROI). `Reward` should be triggered once upon entering the ROI, and not repeat again until the object exits the ROI and the ITI has elapsed.
271+
272+
```mermaid
273+
stateDiagram-v2
274+
direction LR
275+
ITI --> Ready: elapsed
276+
Ready --> Reward: enter
277+
Reward --> ITI: leave
278+
```
279+
280+
> [!Tip]
281+
> There are several ways to implement ROI activation, so feel free to explore different ideas. Consider using either [`Crop`], [`RoiActivity`], or [`ContainsPoint`] as part of different strategies to implement the `enter` and `leave` events.
282+
237283
<!--Reference Style Links -->
238284
[`BehaviorSubject`]: xref:Bonsai.Reactive.BehaviorSubject
239285
[`BitwiseNot`]: xref:Bonsai.Expressions.BitwiseNotBuilder
240286
[`Boolean`]: xref:Bonsai.Expressions.BooleanProperty
241287
[`Condition`]: xref:Bonsai.Reactive.Condition
288+
[`ContainsPoint`]: xref:Bonsai.Vision.ContainsPoint
242289
[`CreateMessage`]: xref:Harp.Hobgoblin.CreateMessage
290+
[`Crop`]: xref:Bonsai.Vision.Crop
291+
[`RoiActivity`]: xref:Bonsai.Vision.RoiActivity
243292
[`Delay`]: xref:Bonsai.Reactive.Delay
244293
[`Device`]: xref:Harp.Hobgoblin.Device
245294
[`DeviceDataWriter`]: xref:Harp.Hobgoblin.DeviceDataWriter
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<WorkflowBuilder Version="2.8.5"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:num="clr-namespace:Bonsai.Numerics;assembly=Bonsai.Numerics"
5+
xmlns:p1="clr-namespace:Bonsai.Numerics.Distributions;assembly=Bonsai.Numerics"
6+
xmlns:rx="clr-namespace:Bonsai.Reactive;assembly=Bonsai.Core"
7+
xmlns="https://bonsai-rx.org/2018/workflow">
8+
<Workflow>
9+
<Nodes>
10+
<Expression xsi:type="Combinator">
11+
<Combinator xsi:type="num:CreateRandom">
12+
<num:Seed xsi:nil="true" />
13+
</Combinator>
14+
</Expression>
15+
<Expression xsi:type="Combinator">
16+
<Combinator xsi:type="p1:CreateDiscreteUniform">
17+
<p1:Lower>0</p1:Lower>
18+
<p1:Upper>1</p1:Upper>
19+
</Combinator>
20+
</Expression>
21+
<Expression xsi:type="rx:PublishSubject">
22+
<Name>Trials</Name>
23+
</Expression>
24+
<Expression xsi:type="SubscribeSubject">
25+
<Name>Trials</Name>
26+
</Expression>
27+
<Expression xsi:type="Combinator">
28+
<Combinator xsi:type="p1:Sample" />
29+
</Expression>
30+
</Nodes>
31+
<Edges>
32+
<Edge From="0" To="1" Label="Source1" />
33+
<Edge From="1" To="2" Label="Source1" />
34+
<Edge From="3" To="4" Label="Source1" />
35+
</Edges>
36+
</Workflow>
37+
</WorkflowBuilder>
Lines changed: 91 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)