Episode 5: Visual Categorization
Flash checkerboards and faces, group two codes into one category with a Trigger, and compare the average response to faces against the rest.
The brain sorts what it sees within a fraction of a second, and a face draws a response that differs from a pattern’s. This episode flashes checkerboards and faces, and compares the average response to each kind. It is Episode 3’s pipeline again, with the paradigm and the triggers changed, and it needs Paradigm Presenter, so runs on Windows only.
CheckerboardFace.xml flashes 300 images for 0.15 s each: checkerboards of a low spatial frequency (code 1) and of a high one (code 2), and photographs of faces (code 3), in random order and in the ratio 20 : 20 : 10. A rest image stays up for 0.6, 0.7 or 0.8 s between flashes. With 20 s of rest first, a run takes about four and a half minutes and gives about 240 checkerboards and 60 faces.
12PARADIGM = os.path.join(os.path.dirname(os.path.abspath(__file__)),
13 "paradigms", "CheckerboardFace.xml")
14CHANNELS = 8
15LOW = 1 # a checkerboard of low spatial frequency
16HIGH = 2 # one of high spatial frequency
17FACE = 3 # a photograph of a face
One Trigger takes both checkerboard codes, target=[LOW, HIGH], so the two kinds are averaged as one category; another takes the faces. The TriggerScope is given plots=["face", "checkerboard", "face-checkerboard"], and the last curve is the difference between the two averages.
65 # One trigger per category: both checkerboard codes go into one
66 # average, the faces into the other
67 checkerboard = gp.Trigger(time_pre=0.2, time_post=0.7,
68 target=[LOW, HIGH])
69 face = gp.Trigger(time_pre=0.2, time_post=0.7, target=FACE)
70 average = gp.TriggerScope(amplitude_limit=5,
71 plots=["face", "checkerboard",
72 "face-checkerboard"])
73 p.connect(notch60, checkerboard)
74 p.connect(presenter, checkerboard[gp.Trigger.PORT_TRIGGER])
75 p.connect(notch60, face)
76 p.connect(presenter, face[gp.Trigger.PORT_TRIGGER])
77 p.connect(checkerboard, average["checkerboard"])
78 p.connect(face, average["face"])
Three marker colours for the three codes, and the file is CheckerboardFace.csv.
43 mk = gp.TimeSeriesScope.Markers
44 markers = [mk(color="g", label="low SF", channel=CHANNELS, value=LOW),
45 mk(color="r", label="high SF", channel=CHANNELS, value=HIGH),
46 mk(color="c", label="face", channel=CHANNELS, value=FACE),
47 mk(color="m", label="M key", channel=CHANNELS + 1, value=77)]
Run the script and press Start. Faces are the rare category, so their average is the noisier one: 60 face epochs keep twice the noise of 240 checkerboard epochs, the square root of 240 / 60. Read the difference wave as the response to faces against patterns, not as a face-specific component: the faces are also the rare category and differ from the checkerboards in contrast and spatial frequency, so rarity and low-level differences are in the wave too. A design that isolates the face response compares faces with equally frequent houses or scrambled faces.
Figure 39: Faces, checkerboards and their difference, three minutes into a run on a BCI Core-8.
In this episode, you learned how to:
group several codes into one category with one Trigger
compare a category against another in one TriggerScope
change one paradigm and two triggers, and keep the rest
Proceed to Episode 6, where how much averaging helps is measured rather than assumed.
Nodes in this episode: Generator, Bandpass, Bandstop, Keyboard, Router, TimeSeriesScope, CsvWriter, Trigger, TriggerScope, ParadigmPresenter
File s5e5_visual_categorization.py – View file on GitHub
1"""Season 5, Episode 5: faces among checkerboards, two averages by category.
2
3Windows only: it needs Paradigm Presenter, see Episode 1. The generator
4stands in for an amplifier; to record a person, uncomment one amplifier
5line and comment out the generator.
6"""
7
8import os
9
10import gpype as gp
11
12PARADIGM = os.path.join(os.path.dirname(os.path.abspath(__file__)),
13 "paradigms", "CheckerboardFace.xml")
14CHANNELS = 8
15LOW = 1 # a checkerboard of low spatial frequency
16HIGH = 2 # one of high spatial frequency
17FACE = 3 # a photograph of a face
18
19if __name__ == "__main__":
20
21 app = gp.MainApp()
22 p = gp.Pipeline()
23
24 # amp = gp.BCICore(channel_count=CHANNELS)
25 # amp = gp.GNautilus(sampling_rate=250, channel_count=CHANNELS)
26 amp = gp.Generator(sampling_rate=250, channel_count=CHANNELS,
27 signal_frequency=10, signal_amplitude=15,
28 noise_amplitude=10)
29
30 # Filtered for display and epoching: 1 to 30 Hz, both mains notches
31 bandpass = gp.Bandpass(f_lo=1, f_hi=30)
32 notch50 = gp.Bandstop(f_lo=48, f_hi=52)
33 notch60 = gp.Bandstop(f_lo=58, f_hi=62)
34 p.connect(amp, bandpass)
35 p.connect(bandpass, notch50)
36 p.connect(notch50, notch60)
37
38 # The presenter receives the codes; the M key (77) marks by hand
39 presenter = gp.ParadigmPresenter(PARADIGM)
40 keyboard = gp.Keyboard()
41
42 # Filtered signal, codes and key presses side by side on one scope
43 mk = gp.TimeSeriesScope.Markers
44 markers = [mk(color="g", label="low SF", channel=CHANNELS, value=LOW),
45 mk(color="r", label="high SF", channel=CHANNELS, value=HIGH),
46 mk(color="c", label="face", channel=CHANNELS, value=FACE),
47 mk(color="m", label="M key", channel=CHANNELS + 1, value=77)]
48 scope = gp.TimeSeriesScope(amplitude_limit=50, time_window=10,
49 markers=markers,
50 hidden_channels=[CHANNELS, CHANNELS + 1])
51 shown = gp.Router(input_channels=[gp.Router.ALL] * 3)
52 p.connect(notch60, shown["in1"])
53 p.connect(presenter, shown["in2"])
54 p.connect(keyboard, shown["in3"])
55 p.connect(shown, scope)
56
57 # The recording keeps the unfiltered signal, with the same two beside
58 # it, in a file named after the paradigm
59 kept = gp.Router(input_channels=[gp.Router.ALL] * 3)
60 p.connect(amp, kept["in1"])
61 p.connect(presenter, kept["in2"])
62 p.connect(keyboard, kept["in3"])
63 p.connect(kept, gp.CsvWriter(file_name="CheckerboardFace.csv"))
64
65 # One trigger per category: both checkerboard codes go into one
66 # average, the faces into the other
67 checkerboard = gp.Trigger(time_pre=0.2, time_post=0.7,
68 target=[LOW, HIGH])
69 face = gp.Trigger(time_pre=0.2, time_post=0.7, target=FACE)
70 average = gp.TriggerScope(amplitude_limit=5,
71 plots=["face", "checkerboard",
72 "face-checkerboard"])
73 p.connect(notch60, checkerboard)
74 p.connect(presenter, checkerboard[gp.Trigger.PORT_TRIGGER])
75 p.connect(notch60, face)
76 p.connect(presenter, face[gp.Trigger.PORT_TRIGGER])
77 p.connect(checkerboard, average["checkerboard"])
78 p.connect(face, average["face"])
79
80 app.add_widget(presenter)
81 app.add_widget(scope)
82 app.add_widget(average)
83
84 p.start()
85 app.run()
86 p.stop()
87 p.close()