def after_run(self, run_context, run_values):
    del run_context
    global_step = run_values.results['global_step']
    feature_names = run_values.results['feature_names']
    feature_usage_counts = run_values.results['feature_usage_counts']
    feature_gains = run_values.results['feature_gains']
    if ((self._last_triggered_step is not None) and (global_step < (self._last_triggered_step + self._every_n_steps))):
        return
    if ((len(feature_names) != len(feature_usage_counts)) or (len(feature_names) != len(feature_gains))):
        raise RuntimeError('Feature names and importance measures have inconsistent lengths.')
    total_usage_count = 0.0
    for usage_count in feature_usage_counts:
        total_usage_count += usage_count
    usage_count_norm = ((1.0 / total_usage_count) if total_usage_count else 1.0)
    total_gain = 0.0
    for gain in feature_gains:
        total_gain += gain
    gain_norm = ((1.0 / total_gain) if total_gain else 1.0)
    self._last_triggered_step = global_step
    for (name, usage_count, gain) in zip(feature_names, feature_usage_counts, feature_gains):
        output_dir = os.path.join(self._model_dir, name.decode('utf-8'))
        summary_writer = SummaryWriterCache.get(output_dir)
        usage_count_summary = Summary(value=[Summary.Value(tag='feature_importance/usage_counts', simple_value=usage_count)])
        usage_fraction_summary = Summary(value=[Summary.Value(tag='feature_importance/usage_fraction', simple_value=(usage_count * usage_count_norm))])
        summary_writer.add_summary(usage_count_summary, global_step)
        summary_writer.add_summary(usage_fraction_summary, global_step)
        gains_summary = Summary(value=[Summary.Value(tag='feature_importance/gains', simple_value=gain)])
        gains_fraction_summary = Summary(value=[Summary.Value(tag='feature_importance/gains_fraction', simple_value=(gain * gain_norm))])
        summary_writer.add_summary(gains_summary, global_step)
        summary_writer.add_summary(gains_fraction_summary, global_step)
def after_run(self, run_context, run_values):
    del run_context
    global_step = run_values.results['global_step']
    feature_names = run_values.results['feature_names']
    feature_usage_counts = run_values.results['feature_usage_counts']
    feature_gains = run_values.results['feature_gains']
    if ((self._last_triggered_step is not None) and (global_step < (self._last_triggered_step + self._every_n_steps))):
        return
    if ((len(feature_names) != len(feature_usage_counts)) or (len(feature_names) != len(feature_gains))):
        raise RuntimeError('Feature names and importance measures have inconsistent lengths.')
    total_usage_count = 0.0
    for usage_count in feature_usage_counts:
        total_usage_count += usage_count
    usage_count_norm = ((1.0 / total_usage_count) if total_usage_count else 1.0)
    total_gain = 0.0
    for gain in feature_gains:
        total_gain += gain
    gain_norm = ((1.0 / total_gain) if total_gain else 1.0)
    self._last_triggered_step = global_step
    for (name, usage_count, gain) in zip(feature_names, feature_usage_counts, feature_gains):
        output_dir = os.path.join(self._model_dir, name.decode('utf-8'))
        summary_writer = SummaryWriterCache.get(output_dir)
        usage_count_summary = Summary(value=[Summary.Value(tag='feature_importance/usage_counts', simple_value=usage_count)])
        usage_fraction_summary = Summary(value=[Summary.Value(tag='feature_importance/usage_fraction', simple_value=(usage_count * usage_count_norm))])
        summary_writer.add_summary(usage_count_summary, global_step)
        summary_writer.add_summary(usage_fraction_summary, global_step)
        gains_summary = Summary(value=[Summary.Value(tag='feature_importance/gains', simple_value=gain)])
        gains_fraction_summary = Summary(value=[Summary.Value(tag='feature_importance/gains_fraction', simple_value=(gain * gain_norm))])
        summary_writer.add_summary(gains_summary, global_step)
        summary_writer.add_summary(gains_fraction_summary, global_step)