diff --git a/examples/measure/calc-final-results.py b/examples/measure/calc-final-results.py index fb21c46..c9572b4 100644 --- a/examples/measure/calc-final-results.py +++ b/examples/measure/calc-final-results.py @@ -22,12 +22,14 @@ # 全ての index ディレクトリからのデータを1つに統合 combined_df = pd.concat(all_data, ignore_index=True) -# max-delay と multi-num ごとにグループ化し、elapse と stddev の平均と標準偏差を計算 +# max-delay と multi-num ごとにグループ化し、elapse, stddev, mean の平均と標準偏差を計算 grouped = combined_df.groupby(['max-delay', 'multi-num']).agg( elapse_mean=('elapse', 'mean'), elapse_std=('elapse', 'std'), stddev_mean=('stddev', 'mean'), - stddev_std=('stddev', 'std') + stddev_std=('stddev', 'std'), + mean_mean=('mean', 'mean'), + mean_std=('mean', 'std') ).reset_index() # 結果を CSV ファイルに保存 diff --git a/examples/measure/calc-result.py b/examples/measure/calc-result.py index fabde0f..2a67d47 100644 --- a/examples/measure/calc-result.py +++ b/examples/measure/calc-result.py @@ -27,9 +27,10 @@ multi_num = parts[1][1:] # 'm' の後の数値を取得 max_delay = parts[2][1:] # 'd' の後の数値を取得 - # elapse.txt と stddev.txt のファイルパス + # elapse.txt, stddev.txt, mean.txt のファイルパス elapse_file = os.path.join(folder_path, 'elapse.txt') stddev_file = os.path.join(folder_path, 'stddev.txt') + mean_file = os.path.join(folder_path, 'mean.txt') # elapse.txt の内容を読み取る if os.path.exists(elapse_file): @@ -45,15 +46,22 @@ else: stddev_content = 'N/A' + # mean.txt の内容を読み取る + if os.path.exists(mean_file): + with open(mean_file, 'r') as mf: + mean_content = mf.read().strip() + else: + mean_content = 'N/A' + # 結果をリストに追加 - results.append([max_delay, multi_num, elapse_content, stddev_content]) + results.append([max_delay, multi_num, elapse_content, stddev_content, mean_content]) # CSVファイルとして保存 csv_file = f'results/{args.index}/results.csv' with open(csv_file, mode='w', newline='') as file: writer = csv.writer(file) # ヘッダーを書き込む - writer.writerow(['max-delay', 'multi-num', 'elapse', 'stddev']) + writer.writerow(['max-delay', 'multi-num', 'elapse', 'stddev', 'mean']) # データを書き込む writer.writerows(results) diff --git a/examples/measure/final_results.csv b/examples/measure/final_results.csv new file mode 100644 index 0000000..49ce2d8 --- /dev/null +++ b/examples/measure/final_results.csv @@ -0,0 +1,26 @@ +max-delay,multi-num,elapse_mean,elapse_std,stddev_mean,stddev_std,mean_mean,mean_std +10,1,1.345,0.061508806957486416,0.0,0.0,0.0,0.0 +10,2,1.455,0.1209453503768449,0.0,0.0,0.0,0.0 +10,4,1.498,0.09150591966279188,0.0,0.0,0.0,0.0 +10,8,3.217,0.11136027618101135,0.0,0.0,0.0,0.0 +10,10,6.348,0.5858668790774915,0.0,0.0,0.0,0.0 +20,1,1.288,0.05769652406245022,0.24,0.08393118874676113,0.0064,0.003747591819348052 +20,2,1.377,0.08028421735033324,0.157,0.05907622195096771,0.003,0.0016666666666666666 +20,4,1.405,0.0981212401969001,0.202,0.04638007234913622,0.0052,0.0018287822299126934 +20,8,2.347,0.14840260554765652,0.475,0.029533408577782253,0.027581,0.0028267431200352587 +20,10,3.7800000000000002,0.19002923751652306,0.531,0.04121757985239902,0.03305,0.0045789858168715815 +40,1,1.342,0.14763317904710857,0.341,0.10450412006763711,19.9974,0.002674987019699523 +40,2,1.323,0.10044899203078153,8.325,1.5585338551914032,12.334931999999998,0.577863608817475 +40,4,1.404,0.074416246732671,8.004000000000001,0.6033093917901678,8.546217,0.498103888852516 +40,8,2.0170000000000003,0.07409453421137087,8.234,0.03777124126457452,5.798415,0.05374506659530096 +40,10,2.915,0.16834158395621948,7.882,0.03614784456460247,5.119236,0.06796787986492844 +80,1,1.288,0.09863513009515877,0.683,0.11324015777688291,59.993801,0.007938402372156407 +80,2,1.392,0.08664102184685185,21.782,2.797442482776802,39.874624,0.9986372713653355 +80,4,1.542,0.3335266106324951,15.64,5.373403638911437,24.052989,4.327821830265325 +80,8,1.8579999999999999,0.12263767773404716,22.81,0.11333333333333223,19.938176,0.6972848400793212 +80,10,2.497,0.11372969904314544,22.02,0.08511430223202486,18.047281,0.28663555805819657 +100,1,1.264,0.062039413995369865,0.942,0.1875455500227434,79.988602,0.010922129218548057 +100,2,1.3130000000000002,0.06056218108504497,30.130000000000003,2.325510696599781,55.315787,2.192565356684822 +100,4,1.4200000000000002,0.11372481406154657,27.297000000000004,3.5979223943208605,39.112477999999996,5.449785273747132 +100,8,1.8510000000000002,0.08089087299153923,29.895999999999997,0.2630673762450312,27.283742999999998,0.475126317848445 +100,10,2.4210000000000003,0.2359119421403767,28.841,0.08504247304860137,24.99906,0.3809165732808172 diff --git a/examples/measure/graph.py b/examples/measure/graph.py index cd07c80..3a6b8ea 100644 --- a/examples/measure/graph.py +++ b/examples/measure/graph.py @@ -12,15 +12,17 @@ parser.add_argument('--duration', type=int, required=False, default=-1, help='Duration for the data') parser.add_argument('--csv-dir', type=str, required=False, default='./', help='Directory containing the CSV files') parser.add_argument('--stddev-only', action='store_true', help='Output only the standard deviation mean') +parser.add_argument('--mean-only', action='store_true', help='Output only the mean value of core time - asset time') args = parser.parse_args() # グラフの初期化(複数のアセットを同じグラフにプロットするため) -if not args.stddev_only: +if not args.stddev_only and not args.mean_only: plt.figure(figsize=(10, 6)) -# 標準偏差を記録するリスト +# 標準偏差と平均を記録するリスト std_devs = [] +means = [] for i in range(0, args.multi_num): print(f"index: {i}") @@ -59,7 +61,7 @@ asset_time = df['asset-time'] / 1000.0 core_time = df['core-time'] / 1000.0 - if args.type == 'phase' and not args.stddev_only: + if args.type == 'phase' and not args.stddev_only and not args.mean_only: x_value = asset_time y_value = core_time plt.plot(x_value, y_value, label=f'asset-{i}', marker='o') @@ -71,13 +73,16 @@ elif args.type == 'time': x_value = core_time y_value = core_time - asset_time - if not args.stddev_only: + if not args.stddev_only and not args.mean_only: plt.plot(x_value, y_value, label=f'asset-{i}', marker='o') - # アセットごとの標準偏差を計算して出力 + # アセットごとの標準偏差と平均を計算して出力 std_dev = np.std(y_value) + mean_value = np.mean(y_value) std_devs.append(std_dev) + means.append(mean_value) print(f"Asset-{i} の標準偏差: {std_dev:.4f}") + print(f"Asset-{i} の平均値: {mean_value:.4f}") # 全アセットの標準偏差の平均を計算して出力 if std_devs: @@ -87,18 +92,27 @@ min_std_dev = np.min(std_devs) range_std_dev = max_std_dev - min_std_dev # 最大値と最小値の差 - if not args.stddev_only: + if not args.stddev_only and not args.mean_only: print(f"全アセットの標準偏差の平均: {mean_std_dev:.4f}") print(f"全アセットの標準偏差の分散: {variance_std_dev:.4f}") print(f"標準偏差の最大値: {max_std_dev:.4f}") print(f"標準偏差の最小値: {min_std_dev:.4f}") print(f"標準偏差の最大値と最小値の差: {range_std_dev:.4f}") - else: + elif args.stddev_only: with open(os.path.join(args.csv_dir, 'stddev.txt'), 'w') as f: f.write(f"{mean_std_dev:.2f}\n") +# 全アセットの平均値の平均を計算して出力 +if means: + mean_of_means = np.mean(means) + if not args.stddev_only and not args.mean_only: + print(f"全アセットの平均値の平均: {mean_of_means:.4f}") + elif args.mean_only: + with open(os.path.join(args.csv_dir, 'mean.txt'), 'w') as f: + f.write(f"{mean_of_means:.5f}\n") + # すべてのアセットをプロットした後にグラフを表示 -if not args.stddev_only: +if not args.stddev_only and not args.mean_only: plt.title('hako-time graph') plt.legend() plt.grid(True) diff --git a/examples/measure/mean.bash b/examples/measure/mean.bash new file mode 100644 index 0000000..b363799 --- /dev/null +++ b/examples/measure/mean.bash @@ -0,0 +1,27 @@ +#!/bin/bash +SAMPLE_NUM=10 + +function do_test() +{ + index=${1} + # Ensure results directory exists + mkdir -p results/${index} + + for multi in 1 2 4 8 10 + do + for mdelay in 10 20 40 80 100 + do + echo "DO TEST: MULTI_NUM=${multi} MAX_DELAY=${mdelay}" + DIR_NAME=results/${index}/result-m${multi}-d${mdelay} + python graph.py --multi-num ${multi} --type time --csv-dir ${DIR_NAME} --mean-only + done + done + + python calc-result.py --index ${index} +} + +# ループの回数を SAMPLE_NUM で制御 +for index in $(seq 0 $(($SAMPLE_NUM - 1))) +do + do_test ${index} +done diff --git a/examples/measure/plot-final-results.py b/examples/measure/plot-final-results.py index 702cc90..1e7e070 100644 --- a/examples/measure/plot-final-results.py +++ b/examples/measure/plot-final-results.py @@ -5,7 +5,7 @@ # コマンドライン引数を設定 parser = argparse.ArgumentParser(description='Plot final results data') parser.add_argument('--csv-file', type=str, required=True, help='Path to the CSV file containing the final results data') -parser.add_argument('--plot-type', choices=['elapse-vs-multi', 'stddev-vs-multi', 'stddev-vs-elapse'], required=True, help='Type of plot to generate') +parser.add_argument('--plot-type', choices=['elapse-vs-multi', 'stddev-vs-multi', 'stddev-vs-elapse', 'mean-vs-multi'], required=True, help='Type of plot to generate') parser.add_argument('--multi-num', type=int, help='Specify the multi-num (only for stddev-vs-elapse plot)') args = parser.parse_args() @@ -19,6 +19,8 @@ df['elapse_std'] = df['elapse_std'].astype(float) df['stddev_mean'] = df['stddev_mean'].astype(float) df['stddev_std'] = df['stddev_std'].astype(float) +df['mean_mean'] = df['mean_mean'].astype(float) +df['mean_std'] = df['mean_std'].astype(float) # 1. 横軸:multi-num、縦軸:elapse_meanとして、max-delay毎に重ねて表示 if args.plot_type == 'elapse-vs-multi': @@ -65,5 +67,18 @@ plt.grid(True) plt.tight_layout() +# 4. 横軸:multi-num、縦軸:mean_meanとして、max-delay毎に重ねて表示 +elif args.plot_type == 'mean-vs-multi': + plt.figure(figsize=(10, 6)) + for delay in sorted(df['max-delay'].unique()): + subset = df[df['max-delay'] == delay].sort_values(by='multi-num') # multi-numでソート + plt.errorbar(subset['multi-num'], subset['mean_mean'], yerr=subset['mean_std'], marker='o', label=f'max-delay={delay}') + plt.xlabel('multi-num') + plt.ylabel('mean (± std)') + plt.title('Mean vs Multi-num with Stddev for different max-delay values') + plt.legend() + plt.grid(True) + plt.tight_layout() + # グラフを表示 plt.show()