Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LMBooth committed Nov 29, 2023
1 parent 72cfefd commit ab44809
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Tests/test_Pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def PyTorchModel(x_train, x_test, y_train, y_test):

#@pytest.mark.timeout(300) # Extended timeout to 5 minutes
def test_run_bci():
bci = PyBCI(minimumEpochsRequired = 3, createPseudoDevice=True, torchModel=PyTorchModel)
bci = PyBCI(minimumEpochsRequired = 2, createPseudoDevice=True, torchModel=PyTorchModel)
while not bci.connected:
bci.Connect()
time.sleep(1)
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_Simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
gs = GlobalEpochSettings()
gs.tmax = 1 # grab 1 second after marker
gs.tmin = 0 # grab 0 seconds before marker
gs.splitCheck = True # splits samples between tmin and tmax
gs.splitCheck = False # splits samples between tmin and tmax
gs.windowLength = 0.5 #
gs.windowOverlap = 0.5 # windows overap by 50%, so for a total len

def test_run_bci():
bci = PyBCI(minimumEpochsRequired = 3, createPseudoDevice=True, globalEpochSettings=gs, loggingLevel = "TIMING")
bci = PyBCI(minimumEpochsRequired = 2, createPseudoDevice=True, globalEpochSettings=gs, loggingLevel = "TIMING")

while not bci.connected:
bci.Connect()
Expand All @@ -32,7 +32,6 @@ def test_run_bci():
if accuracy > 0:
# set to above 0 to show some accuracy was retruend from model
accuracy_achieved = True
bci.StopThreads()
bci.TestMode()
break
#if min([currentMarkers[key][1] for key in currentMarkers]) > bci.minimumEpochsRequired+4:
Expand All @@ -42,6 +41,7 @@ def test_run_bci():
guess = [key for key, value in currentMarkers.items() if value[0] == markerGuess]
in_test_mode = True
time.sleep(1)
bci.StopThreads()
break
#print("Current marker estimation: " + str(guess), end=" \r")
assert accuracy_achieved and marker_received and in_test_mode
2 changes: 1 addition & 1 deletion Tests/test_Sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
def test_run_bci():
clf = MLPClassifier(max_iter = 1000, solver ="lbfgs")#solver=clf, alpha=alpha,hidden_layer_sizes=hid)

bci = PyBCI(minimumEpochsRequired = 3, clf = clf, createPseudoDevice=True)
bci = PyBCI(minimumEpochsRequired = 2, clf = clf, createPseudoDevice=True)

while not bci.connected:
bci.Connect()
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_Tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#@pytest.mark.timeout(300) # Extended timeout to 5 minutes
def test_run_bci():
bci = PyBCI(minimumEpochsRequired = 3, model = model, createPseudoDevice=True)
bci = PyBCI(minimumEpochsRequired = 2, model = model, createPseudoDevice=True)

while not bci.connected:
bci.Connect()
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_zDualStream.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_run_dual():
pd2.BeginStreaming()
time.sleep(5)

bci = PyBCI(minimumEpochsRequired = 3, createPseudoDevice=False)
bci = PyBCI(minimumEpochsRequired = 2, createPseudoDevice=False)

while not bci.connected:
bci.Connect()
Expand Down
41 changes: 35 additions & 6 deletions Tests/test_zSimpleOtherFeatures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from pybci import PyBCI
from pybci.Configuration.FeatureSettings import GeneralFeatureChoices
from pybci.Configuration.EpochSettings import IndividualEpochSetting
from pybci.Utils.FeatureExtractor import GenericFeatureExtractor
import time

Expand All @@ -21,22 +22,50 @@ def test_run_bci():
features.zeroCross = True
features.slopeSignChange = True

markerSettings = {}
markerSettings["baseline"] = IndividualEpochSetting()
markerSettings["baseline"].splitCheck = False
markerSettings["baseline"].tmin = 0 # time in seconds to capture samples before trigger
markerSettings["baseline"].tmax= 2 # time in seconds to capture samples after trigger

markerSettings["Marker1"] = IndividualEpochSetting()
markerSettings["Marker1"].splitCheck = True
markerSettings["Marker1"].tmin = 0 # time in seconds to capture samples before trigger
markerSettings["Marker1"].tmax= 2 # time in seconds to capture samples after trigger

extractor = GenericFeatureExtractor(featureChoices=features)
bci = PyBCI(minimumEpochsRequired = 3, createPseudoDevice= True, streamCustomFeatureExtract={"PyBCIPseudoDataStream":extractor})
bci = PyBCI(minimumEpochsRequired = 2, createPseudoDevice= True, customEpochSettings=markerSettings, streamCustomFeatureExtract={"PyBCIPseudoDataStream":extractor})

while not bci.connected:
bci.Connect()
time.sleep(1)
bci.TrainMode()
marker_received = False
in_test_mode = False
accuracy_achieved = False
accuracy= 0
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) > 2: # check there is more then one marker type received
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
marker_received = True
bci.StopThreads()
break
if min([currentMarkers[key][1] for key in currentMarkers]) > bci.minimumEpochsRequired:
classInfo = bci.CurrentClassifierInfo() # hangs if called too early
accuracy = classInfo["accuracy"]###
if accuracy > 0:
# set to above 0 to show some accuracy was retruend from model
accuracy_achieved = True
bci.TestMode()
break
#if min([currentMarkers[key][1] for key in currentMarkers]) > bci.minimumEpochsRequired+4:
# break
assert marker_received
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]
in_test_mode = True
time.sleep(1)
bci.StopThreads()
break
#print("Current marker estimation: " + str(guess), end=" \r")
assert accuracy_achieved and marker_received and in_test_mode
2 changes: 1 addition & 1 deletion pybci/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '1.4.3'
__version__ = '1.4.4'

0 comments on commit ab44809

Please sign in to comment.