summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2019-02-14 09:53:31 +0100
committerDaniel Friesel <derf@finalrewind.org>2019-02-14 09:53:31 +0100
commitd5ec05c3d05b560de331237a7d227965d5c398b1 (patch)
tree0f98d3eed5a29a6807359b5052c2ba717a776234 /lib
parent2cc46a9411f5545128cca800eb657dd6cb338f4e (diff)
do not print paramstats warning during crossvalidation
Diffstat (limited to 'lib')
-rwxr-xr-xlib/dfatool.py8
-rw-r--r--lib/utils.py22
2 files changed, 20 insertions, 10 deletions
diff --git a/lib/dfatool.py b/lib/dfatool.py
index c4529ce..38e140d 100755
--- a/lib/dfatool.py
+++ b/lib/dfatool.py
@@ -413,7 +413,7 @@ def _preprocess_measurement(measurement):
class ParamStats:
- def __init__(self, by_name, by_param, parameter_names, arg_count, use_corrcoef = False):
+ def __init__(self, by_name, by_param, parameter_names, arg_count, use_corrcoef = False, verbose = False):
"""
Compute standard deviation and correlation coefficient on parameterized data partitions.
@@ -444,7 +444,7 @@ class ParamStats:
for state_or_tran in by_name.keys():
self.stats[state_or_tran] = dict()
for attribute in by_name[state_or_tran]['attributes']:
- self.stats[state_or_tran][attribute] = compute_param_statistics(by_name, by_param, parameter_names, arg_count, state_or_tran, attribute)
+ self.stats[state_or_tran][attribute] = compute_param_statistics(by_name, by_param, parameter_names, arg_count, state_or_tran, attribute, verbose = verbose)
def _generic_param_independence_ratio(self, state_or_trans, attribute):
"""
@@ -950,7 +950,7 @@ class AnalyticModel:
self.parameters = sorted(parameters)
self.verbose = verbose
- self.stats = ParamStats(self.by_name, self.by_param, self.parameters, {})
+ self.stats = ParamStats(self.by_name, self.by_param, self.parameters, {}, verbose = verbose)
def _fit(self):
paramfit = ParallelParamFit(self.by_param)
@@ -1319,7 +1319,7 @@ class PTAModel:
self._num_args = arg_count
self._use_corrcoef = use_corrcoef
self.traces = traces
- self.stats = ParamStats(self.by_name, self.by_param, self._parameter_names, self._num_args, self._use_corrcoef)
+ self.stats = ParamStats(self.by_name, self.by_param, self._parameter_names, self._num_args, self._use_corrcoef, verbose = verbose)
self.cache = {}
np.seterr('raise')
self._outlier_threshold = discard_outliers
diff --git a/lib/utils.py b/lib/utils.py
index 2cf31be..e86b85d 100644
--- a/lib/utils.py
+++ b/lib/utils.py
@@ -2,6 +2,15 @@ import numpy as np
arg_support_enabled = True
+def vprint(verbose, string):
+ """
+ Print string if verbose.
+
+ Prints string if verbose is a True value
+ """
+ if verbose:
+ print(string)
+
def is_numeric(n):
"""Check if n is numeric (i.e., can be converted to int)."""
if n == None:
@@ -49,7 +58,7 @@ def param_slice_eq(a, b, index):
return True
return False
-def compute_param_statistics(by_name, by_param, parameter_names, arg_count, state_or_trans, attribute):
+def compute_param_statistics(by_name, by_param, parameter_names, arg_count, state_or_trans, attribute, verbose = False):
"""
Compute standard deviation and correlation coefficient for various data partitions.
@@ -72,6 +81,7 @@ def compute_param_statistics(by_name, by_param, parameter_names, arg_count, stat
arg_count -- dict providing the number of functions args ("local parameters") for each function.
state_or_trans -- state or transition name, e.g. 'send' or 'TX'
attribute -- model attribute, e.g. 'power' or 'duration'
+ verbose -- print warning if some parameter partitions are too small for fitting
returns a dict with the following content:
std_static -- static parameter-unaware model error: stddev of by_name[state_or_trans][attribute]
@@ -99,16 +109,16 @@ def compute_param_statistics(by_name, by_param, parameter_names, arg_count, stat
np.seterr('raise')
for param_idx, param in enumerate(parameter_names):
- ret['std_by_param'][param] = _mean_std_by_param(by_param, state_or_trans, attribute, param_idx)
+ ret['std_by_param'][param] = _mean_std_by_param(by_param, state_or_trans, attribute, param_idx, verbose)
ret['corr_by_param'][param] = _corr_by_param(by_name, state_or_trans, attribute, param_idx)
if arg_support_enabled and state_or_trans in arg_count:
for arg_index in range(arg_count[state_or_trans]):
- ret['std_by_arg'].append(_mean_std_by_param(by_param, state_or_trans, attribute, len(parameter_names) + arg_index))
+ ret['std_by_arg'].append(_mean_std_by_param(by_param, state_or_trans, attribute, len(parameter_names) + arg_index, verbose))
ret['corr_by_arg'].append(_corr_by_param(by_name, state_or_trans, attribute, len(parameter_names) + arg_index))
return ret
-def _mean_std_by_param(by_param, state_or_tran, attribute, param_index):
+def _mean_std_by_param(by_param, state_or_tran, attribute, param_index, verbose = False):
u"""
Calculate the mean standard deviation for a static model where all parameters but param_index are constant.
@@ -135,9 +145,9 @@ def _mean_std_by_param(by_param, state_or_tran, attribute, param_index):
if len(param_partition) > 1:
partitions.append(param_partition)
elif len(param_partition) == 1:
- print('[W] parameter value partition for {} contains only one element -- skipping'.format(param_value))
+ vprint(verbose, '[W] parameter value partition for {} contains only one element -- skipping'.format(param_value))
else:
- print('[W] parameter value partition for {} is empty'.format(param_value))
+ vprint(verbose, '[W] parameter value partition for {} is empty'.format(param_value))
return np.mean([np.std(partition) for partition in partitions])
def _corr_by_param(by_name, state_or_trans, attribute, param_index):