def predict_example(fd, recogniter): """ 全ての関数から得たデータをnetwrokに入力, 関数を予測する. 最終的に, 関数毎の平均正解率と入力に対する正解率を表示する. neuronの選択性が得られているかを表示. """ plotter = Plotter() result = defaultdict(list) plotter.initialize({ 'xy_value':{ 'ylim': [0,100], 'sub_title': ['value']}, 'likelihood':{ 'ylim': [0,1], 'sub_title': fd.function_list.keys()}, }, movable=False) for ftype in fd.function_list.keys(): print ftype data = fd.get_data(ftype) for x, y in data: input_data = { 'xy_value': [x, y], 'x_value': x, 'y_value': y, 'ftype': None } inferences = recogniter.run(input_data, learn=False) # print input_data['ftype'] = ftype recogniter.print_inferences(input_data, inferences) # for result summary tmp = inferences[ "classifier_" + recogniter.selectivity]['likelihoodsDict'][ftype] result[ftype].append(tmp) # for plot plotter.write(title="xy_value", x_value={'value': x}, y_value={'value': y}) plotter.write(title="likelihood", y_value=inferences[ "classifier_" + recogniter.selectivity]['likelihoodsDict']) plotter.show(save_dir='./docs/images/multi_layer/', file_name='2layer-'+ftype+'.png') plotter.reset() # write result summary import numpy print '### result' for title , data in result.items(): print title , " : ", print numpy.mean(data) # print evaluation summary for name in recogniter.dest_resgion_data.keys(): print '### ', name recogniter.evaluation[name].print_summary()
def main(): type_a_data = [2] * 10 + [50] * 30 type_b_data = [1] * 10 + [50] * 30 data_set = {'a': type_a_data, 'b': type_b_data} recogniter = FunctionRecogniter() plotter = Plotter() result = defaultdict(list) plotter.initialize( { 'anomaly': { 'ylim': [0, 1], 'sub_title': ['a', 'b'] }, 'output-differ': { 'ylim': [0, 1], 'sub_title': ['a', 'b'] }, 'first': { 'ylim': [0, 100], 'sub_title': ['a', 'b'] }, }, movable=True) # トレーニング for i in range(100): anomaly_mean = {} output_differ_mean = {} first_input = {} for ftype, data in data_set.items(): tmp_anomaly = [] tmp_output_differ = [] first_input_cnt = 0 for x, y in enumerate(data): input_data = { 'xy_value': [x, y], 'x_value': x, 'y_value': y, 'ftype': ftype } inferences = recogniter.run(input_data, learn=True) # for plot tmp_anomaly.append(inferences['anomaly']['region1']) if len(inferences["output_differ"]) == 0: first_input_cnt += 1 else: tmp_output_differ.append( inferences["output_differ"]['region1']) # print #recogniter.print_inferences(input_data, inferences) recogniter.reset() # for plot anomaly_mean[ftype] = sum(tmp_anomaly) / len(tmp_anomaly) output_differ_mean[ftype] = sum(tmp_output_differ) / len( tmp_output_differ) first_input[ftype] = first_input_cnt plotter.write_draw(title='anomaly', x_value={ 'a': i, 'b': i }, y_value=anomaly_mean) plotter.write_draw(title='output-differ', x_value={ 'a': i, 'b': i }, y_value=output_differ_mean) plotter.write_draw(title='first', x_value={ 'a': i, 'b': i }, y_value=first_input) # 予測 #if i % 10 == 0: print print '##################### ', i predict_example_4(data_set, recogniter) plotter.show()
def main(): type_a_data = [2] * 10 + [50] * 30 type_b_data = [1] * 10 + [50] * 30 data_set = {'a': type_a_data, 'b':type_b_data} recogniter = FunctionRecogniter() plotter = Plotter() result = defaultdict(list) plotter.initialize({ 'anomaly':{ 'ylim': [0,1], 'sub_title': ['a', 'b']}, 'output-differ':{ 'ylim': [0,1], 'sub_title': ['a', 'b']}, 'first':{ 'ylim': [0,100], 'sub_title': ['a', 'b']}, }, movable=True) # トレーニング for i in range(100): anomaly_mean = {} output_differ_mean = {} first_input = {} for ftype, data in data_set.items(): tmp_anomaly = [] tmp_output_differ = [] first_input_cnt = 0 for x, y in enumerate(data): input_data = { 'xy_value': [x, y], 'x_value': x, 'y_value': y, 'ftype': ftype } inferences = recogniter.run(input_data, learn=True) # for plot tmp_anomaly.append(inferences['anomaly']['region1'] ) if len(inferences["output_differ"]) == 0: first_input_cnt += 1 else: tmp_output_differ.append(inferences["output_differ"]['region1']) # print #recogniter.print_inferences(input_data, inferences) recogniter.reset() # for plot anomaly_mean[ftype] = sum(tmp_anomaly) / len(tmp_anomaly) output_differ_mean[ftype] = sum(tmp_output_differ) / len(tmp_output_differ) first_input[ftype] = first_input_cnt plotter.write_draw(title='anomaly', x_value={'a':i, 'b':i}, y_value=anomaly_mean) plotter.write_draw(title='output-differ', x_value={'a':i, 'b':i}, y_value=output_differ_mean) plotter.write_draw(title='first', x_value={'a':i, 'b':i}, y_value=first_input) # 予測 #if i % 10 == 0: print print '##################### ', i predict_example_4(data_set, recogniter) plotter.show()
def predict_example_3(fd, recogniter): """ 各層の統計的特徴を比較する. 1. 各層のclassifier結果のgraph表示. 2. """ plotter = Plotter() result = defaultdict(lambda: defaultdict(list)) plotter.initialize({ # 'selectivity_center':{ # 'ylim': [0,100], # 'sub_title': recogniter.dest_resgion_data.keys() }, # 'selectivity_outside':{ # 'ylim': [0,100], # 'sub_title': recogniter.dest_resgion_data.keys() }, 'xy_value':{ 'ylim': [0,100], 'sub_title': ['value']}, 'likelihood':{ 'ylim': [0,1], 'sub_title': recogniter.dest_resgion_data.keys() }, }, movable=False) for ftype in fd.function_list.keys(): print ftype data = fd.get_data(ftype) for x, y in data: input_data = { 'xy_value': [x, y], 'x_value': x, 'y_value': y, 'ftype': None } inferences = recogniter.run(input_data, learn=False) # print input_data['ftype'] = ftype recogniter.print_inferences(input_data, inferences) # for result summary for name in recogniter.dest_resgion_data.keys(): tmp = inferences[ "classifier_" + name ]['likelihoodsDict'][ftype] result[name][ftype].append(tmp) # for plot plotter.write(title="xy_value", x_value={'value': x}, y_value={'value': y}) tmp = {} for name in recogniter.dest_resgion_data.keys(): class_name = "classifier_" + name tmp[name] = inferences[class_name]['likelihoodsDict'][ftype] plotter.write(title="likelihood", y_value=tmp) # # for plot # x_tmp = {} # y_tmp = {} # for name in recogniter.dest_resgion_data.keys(): # x_tmp[name] = recogniter.evaluation[name].get_selectivity()[ftype]['x'] # y_tmp[name] = recogniter.evaluation[name].get_selectivity()[ftype]['y'] # plotter.add(title="selectivity_center", x_values=x_tmp, y_values=y_tmp) # # x_tmp2 = {} # y_tmp2 = {} # for name in recogniter.dest_resgion_data.keys(): # x_tmp2[name] = recogniter.evaluation_2[name].get_selectivity()[ftype]['x'] # y_tmp2[name] = recogniter.evaluation_2[name].get_selectivity()[ftype]['y'] # plotter.add(title="selectivity_outside", x_values=x_tmp2, y_values=y_tmp2) plotter.show(save_dir='./docs/images/multi_layer/', file_name='each-layer-'+ftype+'.png') plotter.reset() # write result summary import numpy print '### result' for name, datas in result.items(): print '#### ', name for title ,data in datas.items(): print title , " : ", print numpy.mean(data) # print evaluation summary for name in recogniter.dest_resgion_data.keys(): print '### ', name recogniter.evaluation[name].print_summary()