def visualize_error(learner: str, mode: str, path='try_1/', run=False, block=100) -> bool: """visualizing error""" manager = Mg.TestLearner(block_train=block) if mode == 'binary': labels = 1 bits = 2 elif mode == 'ternary': labels = 1 bits = 3 elif mode == 'quaternary': labels = 2 bits = 4 elif mode == 'sixteen': labels = 2 bits = 16 else: RuntimeError('mode=' + mode + ' is not defined!') return False file = mode + '/' + path data = manager.get_error(learner=learner, file=file, bits=bits, labels=labels, run=run) if learner == 'ml': title = 'Maximum Likelihood' elif learner == 'map': title = 'Maximum A Posterior' elif learner == 'bayes': title = 'Bayes Classifier' elif learner == 'logistic': title = 'Logistic Regression' elif learner == 'tree': title = 'Decision Tree Classifier' elif learner == 'vector': title = 'Support Vector Machines Classifier' elif learner == 'forest': title = 'Random Forests Classifier' elif learner == 'nnet': title = 'Neural Networks Classifier' else: RuntimeError('learner=' + learner + ' is not defined') return False points, min_power, max_power = Mg.get_power() plot = IO.Plotter(dark=True, x_title='1 / En (dB)', y_title='Error') power_set = np.logspace(min_power, max_power, points) power_set = [10 * np.log10(x_power) for x_power in power_set] plot.to_log(x=power_set, y=data, color='blue', label=title) plot.show() return True
def test_output(): wb = xlwt.Workbook() sheet1 = wb.add_sheet('Channel Use #' + str(1)) sheet1.write(0, 0, 'user id') sheet1.write(0, 1, 'channel tap') sheet1.write(0, 2, 'transmitter id') sheet1.write(0, 3, 'channel') sheet1.write(0, 4, 'time lot') sheet1.write(0, 5, 'input') sheet1.write(0, 6, 'desired') sheet1.write(0, 7, 'output') d = IO.DataWriter() d.data_to_xl(wb, 'testing') return
def __create_train_data(self, power: float, mode: str): """creating data set to train models""" writer = IO.DataWriter() gen = self.__model_train if mode == 'binary': data_set = gen.record_data_set_binary(power=power, factors=self.__factor, line=b_line) elif mode == 'ternary': data_set = gen.record_data_set_ternary(power=power, factors=self.__factor, line=t_line) elif mode == 'quaternary': data_set = gen.record_data_set_quadrature(power=power, factors=self.__factor, line=q_line) else: data_set = gen.record_data_set_sixteen(power=power, factors=self.__factor, line=s_line) name = 'train_set' # comment = self.__get_comment_train(power=power) writer.frame_to_csv(data_set, name) # writer.comment_csv(comment, name) return
def __create_test_data(self, powers, mode: str): """creating data set to test models""" writer = IO.DataWriter() gen = self.__model_test for power in powers: if mode == 'binary': data_set = gen.record_data_set_binary(power=power, factors=self.__factor, line=b_line) elif mode == 'ternary': data_set = gen.record_data_set_ternary(power=power, factors=self.__factor, line=t_line) elif mode == 'quaternary': data_set = gen.record_data_set_quadrature(power=power, factors=self.__factor, line=q_line) else: data_set = gen.record_data_set_sixteen(power=power, factors=self.__factor, line=s_line) name = 'test_' + ('%.2f' % power) # comment = self.__get_comment_test(power=power) writer.frame_to_csv(data_set, name) # writer.comment_csv(comment, name) return
def __get_distribution_sixteen(path: str, file: str, rows: int, alpha: float, labeled: bool) -> bool: """visualizing the distribution of data""" data = 'sixteen/' + path + file data_set = read_file(file=data, rows=rows) x1 = data_set['out #1'] x2 = data_set['out #2'] plot = IO.Plotter(dark=False, x_title='bit #1', y_title='bit #2') if labeled: y1 = data_set['bit #1'] y2 = data_set['bit #2'] s00 = -3 s01 = -1 s10 = +1 s11 = +3 index_00 = np.where((y1 == s00) & (y2 == s00))[0] index_01 = np.where((y1 == s00) & (y2 == s01))[0] index_02 = np.where((y1 == s00) & (y2 == s10))[0] index_03 = np.where((y1 == s00) & (y2 == s11))[0] index_04 = np.where((y1 == s01) & (y2 == s00))[0] index_05 = np.where((y1 == s01) & (y2 == s01))[0] index_06 = np.where((y1 == s01) & (y2 == s10))[0] index_07 = np.where((y1 == s01) & (y2 == s11))[0] index_08 = np.where((y1 == s10) & (y2 == s00))[0] index_09 = np.where((y1 == s10) & (y2 == s01))[0] index_10 = np.where((y1 == s10) & (y2 == s10))[0] index_11 = np.where((y1 == s10) & (y2 == s11))[0] index_12 = np.where((y1 == s11) & (y2 == s00))[0] index_13 = np.where((y1 == s11) & (y2 == s01))[0] index_14 = np.where((y1 == s11) & (y2 == s10))[0] index_15 = np.where((y1 == s11) & (y2 == s11))[0] c = np.random.uniform(0, 1, size=(16, 3)) plot.to_scatter(x1[index_00], x2[index_00], edge_color=c[0], label='0000', marker='v', alpha=alpha) plot.to_scatter(x1[index_01], x2[index_01], edge_color=c[1], label='0001', marker='o', alpha=alpha) plot.to_scatter(x1[index_02], x2[index_02], edge_color=c[2], label='0010', marker='*', alpha=alpha) plot.to_scatter(x1[index_03], x2[index_03], edge_color=c[3], label='0011', marker='p', alpha=alpha) plot.to_scatter(x1[index_04], x2[index_04], edge_color=c[4], label='0100', marker='s', alpha=alpha) plot.to_scatter(x1[index_05], x2[index_05], edge_color=c[5], label='0101', marker='<', alpha=alpha) plot.to_scatter(x1[index_06], x2[index_06], edge_color=c[6], label='0110', marker='P', alpha=alpha) plot.to_scatter(x1[index_07], x2[index_07], edge_color=c[7], label='0111', marker='h', alpha=alpha) plot.to_scatter(x1[index_08], x2[index_08], edge_color=c[8], label='1000', marker='o', alpha=alpha) plot.to_scatter(x1[index_09], x2[index_09], edge_color=c[9], label='1001', marker='D', alpha=alpha) plot.to_scatter(x1[index_10], x2[index_10], edge_color=c[10], label='1010', marker='^', alpha=alpha) plot.to_scatter(x1[index_11], x2[index_11], edge_color=c[11], label='1011', marker='8', alpha=alpha) plot.to_scatter(x1[index_12], x2[index_12], edge_color=c[12], label='1100', marker='X', alpha=alpha) plot.to_scatter(x1[index_13], x2[index_13], edge_color=c[13], label='1101', marker='d', alpha=alpha) plot.to_scatter(x1[index_14], x2[index_14], edge_color=c[14], label='1110', marker='*', alpha=alpha) plot.to_scatter(x1[index_15], x2[index_15], edge_color=c[15], label='1111', marker='>', alpha=alpha) else: plot.to_scatter(x1, x2, edge_color='black', marker='o', in_color='blue', alpha=alpha) plot.show() return True
def read_file(file: str, rows=None): """reading file""" reader = IO.DataReader() data_set = reader.read_data(data_name=file, rows=rows) return data_set
def get_distribution(mode='quaternary', path='try_1/', file='test_1.00', rows=300, alpha=1.0, labeled=False) -> bool: """visualizing the distribution of data""" if mode == 'sixteen': return __get_distribution_sixteen(path=path, file=file, rows=rows, alpha=alpha, labeled=labeled) if mode != 'quaternary': RuntimeError('mode=' + mode + ' is not an option!') return False data = mode + '/' + path + file data_set = read_file(file=data, rows=rows) x1 = data_set['out #1'] x2 = data_set['out #2'] plot = IO.Plotter(dark=False, x_title='bit #1', y_title='bit #2') if labeled: y1 = data_set['bit #1'] y2 = data_set['bit #2'] s0 = -1 s1 = +1 index_0 = np.where((y1 == s0) & (y2 == s0))[0] index_1 = np.where((y1 == s0) & (y2 == s1))[0] index_2 = np.where((y1 == s1) & (y2 == s0))[0] index_3 = np.where((y1 == s1) & (y2 == s1))[0] plot.to_scatter(x1[index_0], x2[index_0], edge_color='purple', label='00', marker='o', alpha=alpha) plot.to_scatter(x1[index_1], x2[index_1], edge_color='red', label='01', marker='^', alpha=alpha) plot.to_scatter(x1[index_2], x2[index_2], edge_color='blue', label='10', marker='d', alpha=alpha) plot.to_scatter(x1[index_3], x2[index_3], edge_color='green', label='11', marker='s', alpha=alpha) else: plot.to_scatter(x1, x2, edge_color='black', marker='o', alpha=alpha, in_color='blue') plot.show() return True
def __init__(self, block_train=100): """initializing testing class""" self.__reader = IO.DataReader() self.__block_train = block_train return