summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/analyze-archive.py34
-rwxr-xr-xlib/dfatool.py1
-rwxr-xr-xlib/plotter.py30
3 files changed, 51 insertions, 14 deletions
diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py
index 14cc67e..f203038 100755
--- a/bin/analyze-archive.py
+++ b/bin/analyze-archive.py
@@ -156,8 +156,9 @@ if __name__ == '__main__':
if 'plot-unparam' in opts:
for kv in opts['plot-unparam'].split(';'):
- state_or_trans, attribute = kv.split(' ')
- plotter.plot_y(model.by_name[state_or_trans][attribute])
+ state_or_trans, attribute, ylabel = kv.split(':')
+ fname = 'param_y_{}_{}.pdf'.format(state_or_trans,attribute)
+ plotter.plot_y(model.by_name[state_or_trans][attribute], xlabel = 'measurement #', ylabel = ylabel, output = fname)
if len(show_models):
print('--- simple static model ---')
@@ -191,15 +192,40 @@ if __name__ == '__main__':
if len(show_models):
print('--- param model ---')
+
param_model, param_info = model.get_fitted(safe_functions_enabled = safe_functions_enabled)
+
+ if 'paramdetection' in show_models or 'all' in show_models:
+ for state in model.states_and_transitions():
+ for attribute in model.attributes(state):
+ info = param_info(state, attribute)
+ print('{:10s} {:10s} non-param stddev {:f}'.format(
+ state, attribute, model.stats[state][attribute]['std_static']
+ ))
+ print('{:10s} {:10s} param-lut stddev {:f}'.format(
+ state, attribute, model.stats[state][attribute]['std_param_lut']
+ ))
+ for param in sorted(model.stats[state][attribute]['std_by_param'].keys()):
+ print('{:10s} {:10s} {:10s} stddev {:f}'.format(
+ state, attribute, param, model.stats[state][attribute]['std_by_param'][param]
+ ))
+ if info != None:
+ for param_name in sorted(info['fit_result'].keys(), key=str):
+ param_fit = info['fit_result'][param_name]['results']
+ for function_type in sorted(param_fit.keys()):
+ function_rmsd = param_fit[function_type]['rmsd']
+ print('{:10s} {:10s} {:10s} mean {:10s} RMSD {:.0f}'.format(
+ state, attribute, str(param_name), function_type, function_rmsd
+ ))
+
if 'param' in show_models or 'all' in show_models:
for state in model.states():
for attribute in model.attributes(state):
if param_info(state, attribute):
print('{:10s}: {}'.format(state, param_info(state, attribute)['function']._model_str))
print('{:10s} {}'.format('', param_info(state, attribute)['function']._regression_args))
- for trans in model.attributes(trans):
- for attribute in ['energy', 'rel_energy_prev', 'rel_energy_next', 'duration', 'timeout']:
+ for trans in model.transitions():
+ for attribute in model.attributes(trans):
if param_info(trans, attribute):
print('{:10s}: {:10s}: {}'.format(trans, attribute, param_info(trans, attribute)['function']._model_str))
print('{:10s} {:10s} {}'.format('', '', param_info(trans, attribute)['function']._regression_args))
diff --git a/lib/dfatool.py b/lib/dfatool.py
index b23d02f..a19ba13 100755
--- a/lib/dfatool.py
+++ b/lib/dfatool.py
@@ -14,6 +14,7 @@ import tarfile
from multiprocessing import Pool
from automata import PTA
from functions import analytic
+from functions import AnalyticFunction
from utils import is_numeric
arg_support_enabled = True
diff --git a/lib/plotter.py b/lib/plotter.py
index 2ec635f..24e2197 100755
--- a/lib/plotter.py
+++ b/lib/plotter.py
@@ -80,10 +80,10 @@ def plot_substate_thresholds_p(model, aggregate):
data = [aggregate[key]['sub_thresholds'] for key in keys]
boxplot(keys, None, None, data, 'Zustand', '% Clipping')
-def plot_y(Y, ylabel = None, title = None):
- plot_xy(np.arange(len(Y)), Y, ylabel = ylabel, title = title)
+def plot_y(Y, **kwargs):
+ plot_xy(np.arange(len(Y)), Y, **kwargs)
-def plot_xy(X, Y, xlabel = None, ylabel = None, title = None):
+def plot_xy(X, Y, xlabel = None, ylabel = None, title = None, output = None):
fig, ax1 = plt.subplots(figsize=(10,6))
if title != None:
fig.canvas.set_window_title(title)
@@ -91,14 +91,21 @@ def plot_xy(X, Y, xlabel = None, ylabel = None, title = None):
ax1.set_xlabel(xlabel)
if ylabel != None:
ax1.set_ylabel(ylabel)
- plt.subplots_adjust(left = 0.05, bottom = 0.05, right = 0.99, top = 0.99)
- plt.plot(X, Y, "rx")
- plt.show()
+ plt.subplots_adjust(left = 0.1, bottom = 0.1, right = 0.99, top = 0.99)
+ plt.plot(X, Y, "bo", markersize=2)
+ if output:
+ plt.savefig(output)
+ with open('{}.txt'.format(output), 'w') as f:
+ print('X Y', file=f)
+ for i in range(len(X)):
+ print('{} {}'.format(X[i], Y[i]), file=f)
+ else:
+ plt.show()
def _param_slice_eq(a, b, index):
return (*a[1][:index], *a[1][index+1:]) == (*b[1][:index], *b[1][index+1:]) and a[0] == b[0]
-def plot_param(model, state_or_trans, attribute, param_idx, xlabel = None, ylabel = None, title = None, extra_function = None):
+def plot_param(model, state_or_trans, attribute, param_idx, xlabel = None, ylabel = None, title = None, extra_function = None, output = None):
fig, ax1 = plt.subplots(figsize=(10,6))
if title != None:
fig.canvas.set_window_title(title)
@@ -106,7 +113,7 @@ def plot_param(model, state_or_trans, attribute, param_idx, xlabel = None, ylabe
ax1.set_xlabel(xlabel)
if ylabel != None:
ax1.set_ylabel(ylabel)
- plt.subplots_adjust(left = 0.05, bottom = 0.05, right = 0.99, top = 0.99)
+ plt.subplots_adjust(left = 0.1, bottom = 0.1, right = 0.99, top = 0.99)
param_name = model.param_name(param_idx)
@@ -143,7 +150,7 @@ def plot_param(model, state_or_trans, attribute, param_idx, xlabel = None, ylabe
v = by_other_param[k]
v['X'] = np.array(v['X'])
v['Y'] = np.array(v['Y'])
- plt.plot(v['X'], v['Y'], "rx", color=cm(i))
+ plt.plot(v['X'], v['Y'], "ro", color=cm(i), markersize=3)
YY2_legend.append(legend_sanitizer.sub('_', 'X_{}'.format(k)))
YY2.append(v['X'])
YY2_legend.append(legend_sanitizer.sub('_', 'Y_{}'.format(k)))
@@ -181,7 +188,10 @@ def plot_param(model, state_or_trans, attribute, param_idx, xlabel = None, ylabe
print(' '.join(map(str, elem)), file=f)
print(data_filename_base, function_filename)
- plt.show()
+ if output:
+ plt.savefig(output)
+ else:
+ plt.show()
def plot_param_fit(function, name, fitfunc, funp, parameters, datatype, index, X, Y, xaxis=None, yaxis=None):