You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

classification.py 4.1KB

3 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #######################################################################
  2. # Software License Agreement (AGPL-3 License)
  3. #
  4. # OpenViBE SDK Test Software
  5. # Based on OpenViBE V1.1.0, Copyright (C) Inria, 2006-2015
  6. # Copyright (C) Inria, 2015-2017,V1.0
  7. #
  8. # This program is free software: you can redistribute it and/or modify
  9. # it under the terms of the GNU Affero General Public License version 3,
  10. # as published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program.
  19. # If not, see <http://www.gnu.org/licenses/>.
  20. #######################################################################
  21. #######################################################################
  22. # Script description
  23. # Goal: check if the number of stimuations present after classification
  24. # is identical to a reference result.
  25. #
  26. # Step 1: Define time windows between 2 stimulation id in the file before the classification,
  27. # the first stimulation ID will be the reference stimulation ID.
  28. # Step 2: Count how many time you get the reference stimulation ID in the time windows.
  29. # Step 3: Compute the number of success and provide a ratio.
  30. # Step 4: Compare the ratio to a reference value compute from previous test.
  31. #######################################################################
  32. import csv
  33. import sys
  34. from itertools import islice
  35. # assign arguments to variables
  36. #arg 1 csv file recorded from ov file before the classification
  37. #arg 2 csv file recorded after the classification
  38. #arg 3 reference classification result
  39. if len(sys.argv) < 4 :
  40. print('incorrect args')
  41. sys.exit(101)
  42. # open files associated with the varaibles
  43. with open(sys.argv[1], 'r') as fileReferenceData :
  44. readerReferenceData = csv.reader(fileReferenceData, delimiter=',')
  45. inputData = [rowReference for rowReference in readerReferenceData if rowReference[4] != ""]
  46. if len(inputData) == 0:
  47. print('The lenght of the file reference data: %s is equal to 0 or lower'%sys.argv[1])
  48. sys.exit(109)
  49. with open(sys.argv[2], 'r') as fileTestData :
  50. readerTestData = csv.reader(fileTestData, delimiter=',')
  51. next(readerTestData)
  52. outputData = [rowReference for rowReference in readerTestData if rowReference[3] != ""]
  53. if len(outputData) == 0:
  54. print('The lenght of the test data: %s is equal to 0 or lower'%sys.argv[2])
  55. sys.exit(109)
  56. with open(sys.argv[3], 'r') as fileClassificationReference :
  57. classificationReferenceData = [fileIndex for fileIndex in fileClassificationReference]
  58. # Select into input data the signal with good stimulation marker
  59. referenceData = [rowReference for rowReference in inputData if rowReference[3] in ['33026', '33027', '33025']]
  60. referenceData.append(inputData[-1])
  61. # Check in a time window define by two timestamp the number of stimuation
  62. for firstLineReference, secondLineReference, classificationLine in zip(referenceData, islice(referenceData, 1, None), classificationReferenceData) :
  63. # Create the first timestamp referenc
  64. stimulationReference = firstLineReference[3]
  65. firstTimeReference = float(firstLineReference[0])
  66. # Create the second timestamp reference
  67. secondTimeReference = float(secondLineReference[0])
  68. stimulationCount = 0
  69. numberOfStimulation = 0
  70. # Create the time window between the first and second time stamp reference
  71. #Count the reference stimulation ID
  72. ref_list = [index.count(stimulationReference) for index in outputData if firstTimeReference < float(index[0]) < secondTimeReference]
  73. print(ref_list)
  74. #Compute the percentage of success
  75. classificationEvaluation = (sum(ref_list)/len(ref_list))*100
  76. # Compare to the reference value
  77. if abs(classificationEvaluation - float(classificationLine)) > sys.float_info.epsilon:
  78. print('Classification reference value:%s'%classificationLine)
  79. print('Classification evaluation value:%s'%classificationEvaluation)
  80. sys.exit(108)
  81. sys.exit()