def handle_message(self, mxmsg): LOGGER.info("P300EtrDecision\n") if mxmsg.type == types.ETR_ANALYSIS_RESULTS: res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) LOGGER.debug("GOT ETR ANALYSIS RESULTS: " + str(res.channels)) #self.conn.send_message(message = str(dec), type = types.DECISION_MESSAGE, flush=True) elif mxmsg.type == types.P300_ANALYSIS_RESULTS: res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) LOGGER.debug("GOT P300 ANALYSIS RESULTS: " + str(res.channels)) #self.conn.send_message(message = str(dec), type = types.DECISION_MESSAGE, flush=True) # Probabilty from etr pdf_etr = np.random.random(8) # Probability from p300 pdf_p300 = np.random.random(8) # Hybryd probability pdf = pdf_p300 * pdf_etr # Assume pdf is T distribution loc = pdf.mean() scale = pdf.std() cdf = st.t.cdf(pdf, len(pdf), loc=loc, scale=scale) # If only one value is over threshold if np.sum(cdf > self.tresholdValue) == 1: dec = int(np.arange(len(cdf))[cdf > self.tresholdValue]) SEND_DECISION(dec) self.no_response
def _send_results(self): r = variables_pb2.Sample() r.timestamp = time.time() for i in range(8): r.channels.append(random.random()) self.conn.send_message(message = r.SerializeToString(), type = types.ETR_CALIBRATION_RESULTS, flush=True)
def handle_message(self, mxmsg): if mxmsg.type == types.ETR_CALIBRATION_RESULTS: res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) data = res.channels self.logger.debug("GOT ETR CALIBRATION RESULTS: " + str(data)) self.handle_calibration_mesage(data) elif mxmsg.type == types.ETR_SIGNAL_MESSAGE: l_msg = variables_pb2.Sample2D() l_msg.ParseFromString(mxmsg.message) self.logger.debug("GOT MESSAGE: " + str(l_msg)) dec, ugm = self.handle_etr_message(l_msg) if dec >= 0: self.logger.debug("Sending dec message...") self.conn.send_message(message=str(dec), type=types.DECISION_MESSAGE, flush=True) elif ugm is not None: self.logger.debug("Sending ugm message...") ugm_helper.send_config(self.conn, ugm, 1) else: self.logger.info("Got notihing from manager...") self.no_response()
def handle_message(self, mxmsg): #~ self.logger.info("EtrAnalysis\n") if mxmsg.type == types.ETR_CALIBRATION_RESULTS: #### What to do when receive ETR_MATRIX information res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) self.logger.debug("GOT ETR CALIBRATION RESULTS: "+str(res.channels)) #process blinks only when hold_time passed if self._last_dec_time > 0: t = time.time() - self._last_dec_time if t > self.hold_after_dec: self._last_dec_time = 0 else: self.no_response() return # What to do after everything is done... if mxmsg.type == types.DECISION_MESSAGE: self._last_dec_time = time.time() if mxmsg.type == types.ETR_SIGNAL_MESSAGE: #### What to do when receive ETR_SIGNAL information msg = variables_pb2.Sample2D() msg.ParseFromString(mxmsg.message) self.logger.debug("GOT MESSAGE: "+str(msg)) # Save positions x, y = msg.x, msg.y self._update_buffor(np.array([[x],[y]])) # Turn position into heatmap m = self._calc_metric(x,y) self._update_heatmap(m) ugm = self.ugm_mgr.get_ugm_updates(self.feeds, msg) ugm_helper.send_config(self.conn, ugm, 1) self.nCount += 1 if self.nCount % self.nRefresh == 0: # Calc heatmap as probabilty density pdf = self._calc_pdf() # Send results to decision modul self._send_results() #~ elif mxmsg.type == types.BLINK_MESSAGE: #### What to do when receive BLINK_NO information #~ blink = variables_pb2.Blink() #~ blink.ParseFromString(mxmsg.message) #~ self.logger.debug("GOT BLINK: "+str(blink.index)+" / "+str(blink.timestamp)) self.no_response()
def _send_results(self): """ Sends results do decision making module. """ r = variables_pb2.Sample() t.timestamp = time.time() for i in range(8): r.channels.append(random.random()) self.conn.send_message(message=r.SerializeToString(), type=types.ETR_ANALYSIS_RESULTS, flush=True)
def _send_results(self): r = variables_pb2.Sample() r.timestamp = time.time() for val in self.invH.flatten().tolist(): r.channels.append(val) self.logger.info("sending matrix: " + str(self.invS.flatten().tolist())) print "types.ETR_CALIBRATION_RESULTS: ", types.ETR_CALIBRATION_RESULTS self.conn.send_message(message=r.SerializeToString(), type=types.ETR_CALIBRATION_RESULTS, flush=False)
def _send_results(self): """ Sends results do decision making module. """ pdf = self._getPdf() # Flip pdf matrix pdf = pdf.reshape((self.rows,self.cols))[:,::-1].flatten() r = variables_pb2.Sample() r.timestamp = time.time() for i in range(self.areaCount): r.channels.append(pdf[i]) self.conn.send_message(message = r.SerializeToString(), type = types.ETR_ANALYSIS_RESULTS, flush=True)
def send_decision(self, pdf): """Send dec message to the system (probably to LOGIC peer). dec is of integer type.""" self.logger.info("Sending dec message: " + str(pdf)) #self.buffer.clear() dont do it in p300 - just ignore some blinks sometimes ... r = variables_pb2.Sample() r.timestamp = time.time() for i in range(len(pdf)): r.channels.append(pdf[i]) self.conn.send_message(message=r.SerializeToString(), type=types.P300_ANALYSIS_RESULTS, flush=True)
def send_results(self, results): """Send dec message to the system (probably to LOGIC peer). dec is of integer type.""" LOGGER.info("Sending dec message: " + str(dec)) self._last_dec_time = time.time() #self.buffer.clear() dont do it in p300 - just ignore some blinks sometimes ... #self.buffer.clear_blinks() #ugm_helper.send_stop_blinking(self.conn) r = variables_pb2.Sample() t.timestamp = time.time() for i in range(8): r.channels.append(results[i]) self.conn.send_message(message=r.SerializeToString(), type=types.P300_ANALYSIS_RESULTS, flush=True)
def handle_message(self, mxmsg): LOGGER.info("EtrAnalysis\n") if mxmsg.type == types.ETR_CALIBRATION_RESULTS: #### What to do when receive ETR_MATRIX information res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) LOGGER.debug("GOT ETR CALIBRATION RESULTS: " + str(res.channels)) elif mxmsg.type == types.ETR_SIGNAL_MESSAGE: #### What to do when receive ETR_SIGNAL information l_msg = variables_pb2.Sample2D() l_msg.ParseFromString(mxmsg.message) LOGGER.debug("GOT MESSAGE: " + str(l_msg)) # Change shape of data x, y = l_msg.x, l_msg.y xy = np.array([[x], [y]]) self._update_buffor(xy) # Caunt metric m = self.metric(xy) self._update_heatmap(m) # Calc heatmap as probabilty density pdf = self._calc_pdf() ##self.conn.send_message(message = str(dec), type = types.DECISION_MESSAGE, flush=True) l_msg.ParseFromString(mxmsg.message) LOGGER.debug("GOT MESSAGE: " + str(l_msg)) #zrob cos z sygnalem elif mxmsg.type == types.BLINK_MESSAGE: #### What to do when receive BLINK_NO information blink = variables_pb2.Blink() blink.ParseFromString(mxmsg.message) LOGGER.debug("GOT BLINK: " + str(blink.index) + " / " + str(blink.timestamp)) self.no_response()
def handle_message(self, mxmsg): self.logger.debug("P300EtrDecision\n") if mxmsg.type == types.ETR_ANALYSIS_RESULTS: res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) self.logger.debug("GOT ETR ANALYSIS RESULTS: " + str(res.channels)) self.pdf_etr = np.array(res.channels) self.logger.debug("pdf_etr: " + str(self.pdf_etr)) #self.conn.send_message(message = str(dec), type = types.DECISION_MESSAGE, flush=True) elif mxmsg.type == types.P300_ANALYSIS_RESULTS: res = variables_pb2.Sample() res.ParseFromString(mxmsg.message) self.logger.debug("GOT P300 ANALYSIS RESULTS: " + str(res.channels)) self.pdf_p300 = np.array(res.channels) # Probabilty from etr pdf_etr = self.pdf_etr # Probability from p300 pdf_p300 = self.pdf_p300 # Hybryd probability pdf = self.alpha * pdf_etr + (1. - self.alpha) * pdf_p300 pdf *= 0.01 # Debugging leftouts... self.logger.debug("pdf_etr: " + str(pdf_etr)) self.logger.debug("pdf_p300: " + str(pdf_p300)) self.logger.debug("pdf: " + str(pdf)) dec = -1 # If both interfaces return significant value if (pdf > self.thresholdPercent).sum() == 1: dec = int(np.arange(self.cols * self.rows)[pdf == pdf.max()]) self.logger.info("Dec: " + str(dec)) # If only P300 declares significant and all ETR values are highly insignificant elif ((pdf_p300 > self.p300Tr).sum() == 1) and (pdf_etr < self.etrTr).all(): dec = int( np.arange(self.cols * self.rows)[pdf_p300 == pdf_p300.max()]) self.logger.info("Dec (only p300): " + str(dec)) # If only ETR declares significant and all P300 values are highly insignificant elif (pdf_p300 < self.p300Tr).all() and ( (pdf_etr > self.etrTr).sum() == 1): dec = int( np.arange(self.cols * self.rows)[pdf_etr == pdf_etr.max()]) self.logger.info("Dec (only etr): " + str(dec)) # If decision is to be made if dec != -1: self.conn.send_message(message=str(dec), type=types.DECISION_MESSAGE, flush=True) self.no_response()