Skip to content

Commit

Permalink
Update Introduction.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
LMBooth authored Sep 3, 2023
1 parent f2d626f commit 69f22bd
Showing 1 changed file with 32 additions and 27 deletions.
59 changes: 32 additions & 27 deletions docs/BackgroundInformation/Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,38 @@ Simple Implementation:
===================
For example:

>>> import time
>>> from pybci import PyBCI
>>> bci = PyBCI(createPseudoDevice=True)
>>> while not bci.connected:
>>> bci.Connect()
>>> time.sleep(1)
>>> bci.TrainMode()
>>> accuracy = 0
>>> try:
>>> while(True):
>>> currentMarkers = bci.ReceivedMarkerCount() # check to see how many received epochs, if markers sent to close together will be ignored till done processing
>>> time.sleep(0.5) # wait for marker updates
>>> print("Markers received: " + str(currentMarkers) +" Class accuracy: " + str(accuracy), end="\r")
>>> if len(currentMarkers) > 1: # check there is more then one marker type received
>>> if min([currentMarkers[key][1] for key in currentMarkers]) > bci.minimumEpochsRequired:
>>> classInfo = bci.CurrentClassifierInfo() # hangs if called too early
>>> accuracy = classInfo["accuracy"]
>>> if min([currentMarkers[key][1] for key in currentMarkers]) > bci.minimumEpochsRequired+1:
>>> bci.TestMode()
>>> break
>>> while True:
>>> markerGuess = bci.CurrentClassifierMarkerGuess() # when in test mode only y_pred returned
>>> guess = [key for key, value in currentMarkers.items() if value[0] == markerGuess]
>>> print("Current marker estimation: " + str(guess), end="\r")
>>> time.sleep(0.1)
>>> except KeyboardInterrupt: # allow user to break while loop
>>> pass
.. code-block:: python
from pybci import PyBCI
import time
if __name__ == '__main__': # Note: this line is needed when calling pseudoDevice as by default runs in a multiprocessed operation
bci = PyBCI(minimumEpochsRequired = 5, createPseudoDevice=True)
while not bci.connected: # check to see if lsl marker and datastream are available
bci.Connect()
time.sleep(1)
bci.TrainMode() # now both marker and datastreams available start training on received epochs
accuracy = 0
try:
while(True):
currentMarkers = bci.ReceivedMarkerCount() # check to see how many received epochs, if markers sent to close together will be ignored till done processing
time.sleep(0.5) # wait for marker updates
print("Markers received: " + str(currentMarkers) +" Accuracy: " + str(round(accuracy,2)), end=" \r")
if len(currentMarkers) > 1: # check there is more then one marker type received
if min([currentMarkers[key][1] for key in currentMarkers]) > bci.minimumEpochsRequired:
classInfo = bci.CurrentClassifierInfo() # hangs if called too early
accuracy = classInfo["accuracy"]
if min([currentMarkers[key][1] for key in currentMarkers]) > bci.minimumEpochsRequired+10:
bci.TestMode()
break
while True:
markerGuess = bci.CurrentClassifierMarkerGuess() # when in test mode only y_pred returned
guess = [key for key, value in currentMarkers.items() if value[0] == markerGuess]
print("Current marker estimation: " + str(guess), end=" \r")
time.sleep(0.2)
except KeyboardInterrupt: # allow user to break while loop
print("\nLoop interrupted by user.")
What is PyBCI?
===================
Expand Down

0 comments on commit 69f22bd

Please sign in to comment.