def main(): with open('cred.json') as json_file: user = json.load(json_file) cortex = Cortex(user, True) # do_stuff(cortex) record = Record(cortex) record.run()
def __init__(self): self.headers = {} self.objects = None self.count = 0 self.tick = time.time() self.maxEventsInBuffer = 100 self.stream_types = {} self.is_first_for_type = { "met": True, "eeg": True, "fac": True, "mot": True, } self.c = Cortex(user, debug_mode=False) self.c.do_prepare_steps() self.time_slice = 0 self.time_data = { 'engagement': {}, 'excitement': {}, 'stress': {}, 'relaxation': {}, 'interest': {}, 'focus': {} } self.time_slice_averages = {}
def func(self): url = "wss://localhost:6868" user = { "license": "", "client_id": "", "client_secret": "", "debit": 100, "number_row_data": 10 } self.count = 0 self.cortex = Cortex(url, user) self.headset_id = self.cortex.query_headset() self.cortex.connect_headset() self.cortex.request_access() auth = self.cortex.authorize() self.cortex.create_session(auth, self.headset_id) status = 'load' profile_name = 'skshreyas' self.cortex.setup_profile(profile_name, status) stream_list = ['com'] self.lis = [] self.cortex.subscribe(stream_list) while True: resp = self.cortex.ws.recv() res = json.loads(resp) mentalCommandList = res['com'] action = mentalCommandList[0] #print(action) self.FocusChanger(action)
def simple(): c = Cortex(input_dims, output_dims) c.PARAMS['learning_rate'] = 1e-4 c.PARAMS['gamma'] = 0.8 c.PARAMS['messagedim'] = 5 c.PARAMS['sensory_hidden'] = [10] c.PARAMS['motorM-net_hidden'] = [10] c.PARAMS['Q-net_hidden'] = [10] c.initialize() e = Environment() durs = list() lall = 0 rall = 0 while (len(durs) < 200): obs = e.observe() # model observes actions = c.learning_step( obs, reward, explore=(len(durs) < 100)) # model chooses action flag, reward = e.simulate( actions ) # environment simulates and determines reward for that action # that reward is fed in next time to instruct the model what Q should have been if flag != None: l, r = flag durs.append(l + r) lall += l rall += r print(len(durs), flag) print(lall, rall) plt.plot(durs) plt.show()
def start_chart(data): # print('received message: ' + str(data), flush=sys.stdout) chart_cortex = Cortex(user) PROFILE_NAME = "RealBCI" STREAM = "pow" chart_cortex.do_prepare_steps() chart_cortex.setup_profile(PROFILE_NAME, 'load') chart_cortex.sub_request(stream=[STREAM], emit=emit)
def propagate(console): ''' This method creates a cortex and adds some relay mappings :param console: Used by the cortex to control console logging ''' core = Cortex(debug=True, console=console) core.add_relay(1, [2, 3, 4, 5]) core.add_relay(2, [3, 4]) core.add_relay(3, [4, 5, 13]) core.add_relay(4, [7, 8, 9]) core.add_relay(9, [10]) core.add_relay(10, [11, 12]) return core
def record(): try: app.app_cortex = Cortex(user) app.app_cortex.do_prepare_steps() app.app_cortex.create_record(record_name, record_description) response = app.response_class(response=json.dumps( {"record_id": app.app_cortex.record_id}), status=200, mimetype='application/json') return response except Exception as e: print(e, flush=sys.stdout) response = app.response_class(response=json.dumps( {"error": 'Get Error'}), status=400, mimetype='applica tion/json') return response
def __init__(self): self.c = Cortex(user, debug_mode=True) self.c.do_prepare_steps()
from pyboy import PyBoy import ctypes from time import sleep import os from command_handler import command_handler from cca_handler import cca_handler from pyboy_controller import pyboy_controller import time # Initialize our variables use_csv = True # TEMP: feel free to change how I do this. I say 'if not using csv then use emotiv' here and in #EACHFRAMEPOG - Matt # NOTE: still will save a csv file even though I am reading from a csv file if not use_csv: cortex = Cortex(None) cortex.do_prepare_steps() generator = cortex.sub_request(['eeg']) # generator = cortex.sub_request_pow(['pow']) next(generator).queue data_columns = ["P7", "O1", "O2", "P8", "TIME"] # data_columns = ["O1/theta","O1/alpha","O1/betaL","O1/betaH","O1/gamma", # "O2/theta","O2/alpha","O2/betaL","O2/betaH","O2/gamma", "TIME"] # CSV CONTROL if use_csv: recording_data = pd.read_csv('old_bad_recordings/first_target_0.csv') record_length = len(recording_data.index) channels = ['P7', 'O1', 'O2', 'P8'] # only data channels row_index = 0
def test(): cortex = Cortex(None) cortex.do_prepare_steps()
init() screenSize = [1280, 720] # Set Window game size playerScore = 0 aiScore = 0 # ASCII Menus art1 = text2art("Lain BCI", font="sub-zero") art2 = text2art("Connect your brain", font="small") art3 = text2art("Training", font="sub-zero") # INSERT CODES GENERATED BY EMOTIV # First parameter is clientID # Second parameter secretID # Cortex Object initialization. Check Cortex libary I developed for more information cortex = Cortex("XX", "XX", "wss://localhost:6868") # Class used to intialiaze font objects. Font object is text that can be displayed on the game class Font(): def __init__(self, color, name, size, posX, posY): self.font = pyg.font.Font(name, size) self.color = color self.posX = posX self.posY = posY self.text = None self.rect = None def render(self, text): self.text = self.font.render(str(text), 1, self.color) self.rect = self.text.get_rect(centerx=self.posX, centery=self.posY)
import asyncio from cortex import Cortex import time import pyautogui import json import keyboard cortex = Cortex( "C:\\Users\\Siwen Wang\\Desktop\\Cursor_Control_V1\\cortex_creds.txt") async def set_up(cortex): # await cortex.inspectApi() print("** USER LOGIN **") await cortex.get_user_login() print("** GET CORTEX INFO **") await cortex.get_cortex_info() print("** HAS ACCESS RIGHT **") await cortex.has_access_right() print("** REQUEST ACCESS **") await cortex.request_access() print("** AUTHORIZE **") await cortex.authorize() print("** GET LICENSE INFO **") await cortex.get_license_info() print("** QUERY HEADSETS **") await cortex.query_headsets() if len(cortex.headsets) > 0: print("** CREATE SESSION **") await cortex.create_session(activate=True, headset_id=cortex.headsets[0])
import key import json from cortex import Cortex import matplotlib.pyplot as plt import numpy as np from liveplot import MyPlotClass, MyDataFetchClass, MyDataClass import bci_workshop_tools as BCIw from IPython.core.pylabtools import figsize import time print("licence :", key.licence) print("client_id :", key.client_id) print("client_secret :", key.client_secret) streams = ['eeg'] cortex = Cortex(key.user, debug_mode=True) cortex.do_prepare_steps() sub_request_json = { "jsonrpc": "2.0", "method": "subscribe", "params": { "cortexToken": cortex.auth, "session": cortex.session_id, "streams": streams }, "id": key.SUB_REQUEST_ID } print('subscribe request --------------------------------') cortex.ws.send(json.dumps(sub_request_json))
def muscular_detectors(self): status = 'unload' profile_name = 'shreyas' self.cortex.setup_profile(profile_name, status) cortex = Cortex(self.url, self.user) headset_id = cortex.query_headset() cortex.connect_headset() cortex.request_access() auth = cortex.authorize() cortex.create_session(auth, headset_id) cortex.setup_profile(profile_name, status) status = 'load' profile_name = 'shreyas' cortex.setup_profile(profile_name, status) stream_list = ['fac'] lis = [] cortex.subscribe(stream_list) while True: resp = self.cortex.ws.recv() res = json.loads(resp) facCommandList = res['fac'] print(facCommandList) blink = facCommandList[0] frownNsurprise = facCommandList[1] clenchNsmile = facCommandList[3] if frownNsurprise == 'frown': self.lis.append(frownNsurprise) if len(self.lis) == 3: del self.lis[0] print(self.lis) if self.lis[0] == self.lis[1]: self.count = self.count + 1 if self.count > 6: self.voicegen.say("I would like to go out") self.voicegen.runAndWait() self.count = 0 print(self.count) else: self.count = 0 if frownNsurprise == 'surprise': self.lis.append(frownNsurprise) if len(self.lis) == 3: del self.lis[0] print(self.lis) if self.lis[0] == self.lis[1]: self.count = self.count + 1 if self.count > 6: self.voicegen.say("I am excited") self.voicegen.runAndWait() self.count = 0 print(self.count) else: self.count = 0 if clenchNsmile == 'clench': self.lis.append(clenchNsmile) if len(self.lis) == 3: del self.lis[0] print(self.lis) if self.lis[0] == self.lis[1]: self.count = self.count + 1 if self.count > 6: self.voicegen.say("take me to the washroom") self.voicegen.runAndWait() print(self.count) else: self.count = 0 if clenchNsmile == 'smile': self.lis.append(clenchNsmile) if len(self.lis) == 3: del self.lis[0] print(self.lis) if self.lis[0] == self.lis[1]: self.count = self.count + 1 if self.count > 6: self.voicegen.say("I am happy") self.voicegen.runAndWait() self.count = 0 print(self.count) else: self.count = 0 if blink == 'blink': self.lis.append(clenchNsmile) if len(self.lis) == 3: del self.lis[0] print(self.lis) if self.lis[0] == self.lis[1]: self.count = self.count + 1 if self.count > 10: break print(self.count) else: self.count = 0 self.mentalComm()
def mentalComm(self): self.url = "wss://localhost:6868" self.user = { "license": "", "client_id": "", "client_secret": "", "debit": 100, "number_row_data": 10 } self.count = 0 self.cortex = Cortex(self.url, self.user) headset_id = self.cortex.query_headset() self.cortex.connect_headset() self.cortex.request_access() auth = self.cortex.authorize() self.cortex.create_session(auth, headset_id) status = 'load' profile_name = 'skshreyas' self.cortex.setup_profile(profile_name, status) stream_list = ['com'] self.lis = [] self.cortex.subscribe(stream_list) while True: resp = self.cortex.ws.recv() res = json.loads(resp) mentalCommandList = res['com'] action = mentalCommandList[0] print(action) if action == 'neutral': self.count = 0 if action == 'right': self.lis.append(action) if len(self.lis) == 3: del self.lis[0] print(self.lis) if self.lis[0] == self.lis[1]: self.count = self.count + 1 if self.count > 6: self.voicegen.say("please bring my things") self.voicegen.runAndWait() self.count = 0 print(self.count) else: self.count = 0 if action == 'lift': self.lis.append(action) if len(self.lis) == 3: del self.lis[0] print(self.lis) if self.lis[0] == self.lis[1]: self.count = self.count + 1 if self.count > 6: self.voicegen.say("I would like to go out") self.voicegen.runAndWait() self.count = 0 print(self.count) else: self.count = 0 if action == 'drop': self.lis.append(action) if len(self.lis) == 3: del self.lis[0] print(self.lis) if self.lis[0] == self.lis[1]: self.count = self.count + 1 if self.count > 6: self.voicegen.say("hi it is glad to meet you") self.voicegen.runAndWait() self.count = 0 print(self.count) else: self.count = 0 if action == 'left': self.lis.append(action) if len(self.lis) == 3: del self.lis[0] print(self.lis) if self.lis[0] == self.lis[1]: self.count = self.count + 1 if self.count > 6: break print(self.count) else: self.count = 0 self.muscular_detectors()
Alternating greedy and optimizing periods. For each period, report: Number of bounces Number of time steps Number of agent movements ''' es = [0.5] # [0.05, 0.1, 0.25] for i in range(9, 10): for nnet in nnettypes: for e in es: for learning_rate in learning_rates: for gamma in gammas: Environment.movement_cost = e c = Cortex(input_dims, output_dims) c.PARAMS['learning_rate'] = learning_rate c.PARAMS['gamma'] = gamma c.PARAMS['messagedim'] = 5 c.PARAMS['sensory_hidden'] = nnettypes[nnet] c.PARAMS['motorM-net_hidden'] = nnettypes[nnet] c.PARAMS['Q-net_hidden'] = nnettypes[nnet] c.initialize(4) env = Environment() data = np.zeros( (NUMBER, 5) ) # number left bounces, right bounces, total time, left mvmts, right mvmts path = "res3/{}".format(i)