def ICA(self, forehead, nose): # Applying ICA nose_ica = jade.main(forehead) fore_ica = jade.main(nose) # Transpose of ICA result nose_ica = nose_ica.T fore_ica = fore_ica.T self.nose_ica_g = nose_ica[1, :] self.fore_ica_g = fore_ica[1, :] nose_green = nose_ica[1, :] nose_green = numpy.ravel(nose_green) nose_green = numpy.hamming(self.n_frame) * nose_green #fore_green = fore_ica[1,:] #fore_green = numpy.ravel(fore_green) #fore_green = numpy.hamming(self.n_frame) * fore_green #Bandpass filter on the green channel on nose and forehead nose_green = self.bandpass_filter(nose_green, 0.95, 2.0, self.fs) fore_ica[1, :] = self.bandpass_filter(fore_ica[1, :], 0.75, 2.0, self.fs) #Fourier transform r_nosefft = numpy.absolute(numpy.fft.fft(nose_ica[0, :], norm="ortho")) g_nosefft = numpy.absolute(numpy.fft.fft(nose_green, norm="ortho")) b_nosefft = numpy.absolute(numpy.fft.fft(nose_ica[2, :], norm="ortho")) r_forefft = numpy.absolute(numpy.fft.fft(fore_ica[0, :], norm="ortho")) g_forefft = numpy.absolute(numpy.fft.fft(fore_ica[1, :], norm="ortho")) b_forefft = numpy.absolute(numpy.fft.fft(fore_ica[2, :], norm="ortho")) g_nosefft = numpy.ravel(g_nosefft) g_forefft = numpy.ravel(g_forefft) #Only takes de half of the data y_plot_nose = g_nosefft[:self.n_frame // 2] y_plot_fore = g_forefft[:self.n_frame // 2] self.index_nose = numpy.argmax(y_plot_nose) self.index_fore = numpy.argmax(y_plot_fore) self.bpm_a = self.xf[self.index_nose] * 60 self.bpm_b = self.xf[self.index_fore] * 60 #Gets the pulse self.window_hr = self.get_pulse(self.bpm_a) print(self.bpm_a, "BPM NARIZ") print(self.bpm_b, "BPM FORE")
def ICA(self): # Applying ICA nose_ica = jade.main(self.ica_both) nose_ica_b = self.ica_both_b nose_ica = nose_ica.T nose_green = nose_ica[0, :] nose_green = np.ravel(nose_green) nose_green = np.hamming(len(nose_green)) * nose_green nose_green_b = nose_ica_b[0, :] nose_green_b = np.ravel(nose_green_b) nose_green_b = np.hamming(len(nose_green_b)) * nose_green_b #Bandpass filter on the green channel on nose and forehead nose_green = self.bandpass_filter(nose_green, 0.90, 1.7, self.fs) #ESTA E N 0.95 a 2.0 fore_ica = self.bandpass_filter(nose_ica[1, :], 0.90, 1.7, self.fs) nose_green_b = self.bandpass_filter(nose_green_b, 0.90, 1.7, self.fs) fore_green_b = self.bandpass_filter(nose_ica_b[1, :], 0.90, 1.7, self.fs) #Fourier transform g_nosefft = np.absolute(np.fft.fft(nose_green, norm="ortho")) f_forefft = np.absolute(np.fft.fft(fore_ica, norm="ortho")) g_nosefft_b = np.absolute(np.fft.fft(nose_green_b, norm="ortho")) g_forefft_b = np.absolute(np.fft.fft(fore_green_b, norm="ortho")) g_nosefft = np.ravel(g_nosefft) g_forefft = np.ravel(f_forefft) g_nosefft_b = np.ravel(g_nosefft_b) g_forefft_b = np.ravel(g_forefft_b) #Only takes de half of the data y_plot_nose = g_nosefft[:self.n_frame // 2] y_plot_fore = g_forefft[:self.n_frame // 2] y_plot_nose_b = g_nosefft_b[:self.n_frame // 2] y_plot_fore_b = g_forefft_b[:self.n_frame // 2] self.index_nose = np.argmax(y_plot_nose) self.index_fore = np.argmax(y_plot_fore) self.index_nose_b = np.argmax(y_plot_nose_b) self.index_fore_b = np.argmax(y_plot_fore_b) #Calculates the hearth rate self.bpm_a = self.xf[self.index_nose] * 60 self.bpm_b = self.xf[self.index_fore] * 60 self.bpm_a_b = self.xf[self.index_nose_b] * 60 self.bpm_b_b = self.xf[self.index_fore_b] * 60 # cwtmatr , freqs = pywt.cwt(y_plot_nose, len(y_plot_nose) , "morl", self.fs) #Gets the pulse self.window_hr = self.get_pulse(self.bpm_a) self.window_hr_b = self.get_pulse_b(self.bpm_a_b) print(self.bpm_a, "BPM componente 1") print(self.bpm_b, "BPM componente 2") print(self.bpm_a_b, "BPM componente 1 metodo 2") print(self.bpm_b_b, "BPM componente 2 metodo 2")
def parse_RGB(message): buffer_window = message["bufferWindow"] # # ** FOR GREEN CHANNEL ONLY ** # X = np.array(message["array"]) # X = normalize_array(X) # return json.dumps(parse_ICA_results(X, buffer_window)) # ** FOR RGB CHANNELS & ICA ** X = np.ndarray(shape=(3, buffer_window), buffer=np.array(message["array"])) X = normalize_matrix(X) ICA = jade.main(X) return json.dumps(parse_ICA_results(ICA, buffer_window)) #message["time"]
def parse_RGB(message): buffer_window = message["bufferWindow"] # # ** FOR GREEN CHANNEL ONLY ** # X = np.array(message["array"]) # X = normalize_array(X) # return json.dumps(parse_ICA_results(X, buffer_window)) # ** FOR RGB CHANNELS & ICA ** X = np.ndarray(shape = (3, buffer_window), buffer= np.array(message["array"])) X = normalize_matrix(X) ICA = jade.main(X) return json.dumps(parse_ICA_results(ICA, buffer_window)) #message["time"]
def ICA(self): # Applying ICA nose_ica = jade.main(self.ica_both) # Transpose of ICA result nose_ica = nose_ica.T #nose_green = nose_ica[1,:] nose_green = nose_ica[0, :] nose_green = np.ravel(nose_green) nose_green = np.hamming(self.n_frame) * nose_green #Bandpass filter on the green channel on nose and forehead nose_green = self.bandpass_filter(nose_green, 0.95, 2.0, self.fs) fore_ica = self.bandpass_filter(nose_ica[1, :], 0.95, 2.0, self.fs) #Fourier transform g_nosefft = np.absolute(np.fft.fft(nose_green, norm="ortho")) f_forefft = np.absolute(np.fft.fft(fore_ica, norm="ortho")) g_nosefft = np.ravel(g_nosefft) g_forefft = np.ravel(f_forefft) #Only takes de half of the data y_plot_nose = g_nosefft[:self.n_frame // 2] y_plot_fore = g_forefft[:self.n_frame // 2] self.index_nose = np.argmax(y_plot_nose) self.index_fore = np.argmax(y_plot_fore) self.bpm_a = self.xf[self.index_nose] * 60 self.bpm_b = self.xf[self.index_fore] * 60 #Gets the pulse self.window_hr = self.get_pulse(self.bpm_a) print(self.bpm_a, "BPM componente 1") print(self.bpm_b, "BPM componente 2")
def parse_RGB(buffer_window, sample): X = np.ndarray(shape=(3, buffer_window), buffer=np.array(sample)) X = normalize_matrix(X) ICA = jade.main(X) signalFFT = parse_ICA_results(ICA) return signalFFT
def main(): """SETTINGS 1. Common settings: Common settings include the values or methods shared with all algorithm to solve task assignment problem(TAP), and these values and methods should be the same for evaluatate fairly. First, the basic scale of TAP should be set: ############################################ r: Number of the tasks. In this project, it recommanded set with following values: 5, 10, 15, 20, 30, 50. n: Number of the processors. In this project, it recommanded set with following values: 3, 6, 9, 12, 18 ,30. ############################################ Then, some specific parameters for TAP: ############################################ execution_cost: The matrix which represent the exact cost value for task i would cost how much on processor j. exec_cost_min: The minimal cost for the cost value. exec_cost_max: The maximal cost for the cost value. communication_cost: It would be represent as a matrix, but it's a little hard to explain which it is, so plz read the related ref or this code if you could=] comm_density: The density of the value in the matrix. It recommanded set with following values: 0.3, 0.5, 0.8. comm_cost_min: The minimal value of communication. comm_cost_max: The maximal value of communication. processing_cost: A matrix to represent the prossing cost for each task on specific processor. processing_cost_min: The minimal value of processing cost. processing_cost_max: The maximal value of processing cost. processing_limitation: The processing limitation for each processor. proc_cost_min: The minimal limitation of processing. proc_cost_max: The maximal limitation of processing. mem_cost: A matrix to represent the memory cost for each task on specific processor. mem_cost_min: The minimal value of memory cost. mem_cost_max: The maximal value of memory cost. mem_limitation: The memory limitation for each processor. mem_cost_min: The minimal limitation of memory. mem_cost_max: The maximal limitation of memory. ############################################ Last, some parameter for DE algorithm: ############################################ M: Number of individual in each iteration In this project, it recommanded set with following numbers: 15, 20, 25, 30, 35, 40 K: Iteration times In this project, it recommanded set with following numbers: 50, 100, 150, 200, 250, 300 ############################################ 2. Specific setting: 2.1 ODE Algorithm The ODE algorithm add an extra judge to expand the search. F: the F constant CR: the CR constant JR: the jump rate 2.2 JADE Algorithm 2.3. IDE Algorithm The IDE algorithm has dynamic CR value and F value while the F is depends on the values in each iteration. So only CR value should be set with some constant. cr_min: the lower limitation of the CR value. cr_max: the higher limitation of the CR value. l: the lambda value """ # Start of settings # Common settings r = 10 n = 6 M = 50 K = 80 exec_cost_min = 0 exec_cost_max = 200 execution_cost = utils.generate_common_cost(n, r, exec_cost_min, exec_cost_max) comm_density = 0.8 comm_cost_min = 0 comm_cost_max = 50 communication_cost = utils.generate_communication_cost( r, comm_density, comm_cost_min, comm_cost_max) proc_cost_min = 1 proc_cost_max = 50 processing_cost = utils.generate_common_cost(n, r, proc_cost_min, proc_cost_max) proc_limitation_min = 50 proc_limitation_max = 250 processing_limitation = utils.generate_common_limitation( n, proc_limitation_min, proc_limitation_max) mem_cost_min = 1 mem_cost_max = 50 memory_cost = utils.generate_common_cost(n, r, mem_cost_min, mem_cost_max) mem_limitation_min = 50 mem_limitation_max = 250 memory_limitation = utils.generate_common_limitation( n, mem_cost_min, mem_cost_max) # Settings for ODE Algorithm F = 1 CR = 0.8 JR = 0.5 # Settings for IDE Algorithm cr_min = 0.1 cr_max = 0.9 l = 10**10 # End of settings # ODE Algorithm ode_result = ode.main(r, n, M, K, F, CR, JR, execution_cost, communication_cost, processing_cost, processing_limitation, memory_cost, memory_limitation) # JADE Algorithm jade_result = jade.main(r, n, M, K, F, CR, execution_cost, communication_cost, processing_cost, processing_limitation, memory_cost, memory_limitation) # IDE Algorithm ide_result = ide.main(r, n, M, K, cr_min, cr_max, l, execution_cost, communication_cost, processing_cost, processing_limitation, memory_cost, memory_limitation) xAxis = numpy.linspace(0, K - 1, num=K) plt.plot(xAxis, ode_result, linewidth=2, linestyle="-", label="ODE") plt.plot(xAxis, jade_result, linewidth=2, linestyle="-", label="JADE") plt.plot(xAxis, ide_result, linewidth=2, linestyle="-", label="IDE") plt.legend() plt.title( "ODE/JADE/IDE Algorithm for task assignment problem\nParameters: number of tasks: " + str(r) + ", number of processor: " + str(n)) plt.xlabel("iteration") plt.ylabel("function value") plt.grid(True) plt.show()