Skip to content

Commit

Permalink
23032: Adds new parameter to react methods, "feature_post_process_cod…
Browse files Browse the repository at this point in the history
…e_map". MINOR (#370)

Adds new parameter, "feature_post_process_code_map" to all react*
method. This parameter takes a mapping feature name to custom code
string that is used to derive an updated feature value based on whatever
code is defined. At the time of execution, the code will have access to
all context features and previously generated action features (including
the feature itself).

Co-authored-by: Andrew Bassett <43486400+apbassett@users.noreply.github.com>
  • Loading branch information
cademack and apbassett authored Feb 28, 2025
1 parent c0691be commit e6cd6a8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
25 changes: 25 additions & 0 deletions howso/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ def react( # noqa: C901
details: t.Optional[Mapping] = None,
exclude_novel_nominals_from_uniqueness_check: bool = False,
feature_bounds_map: t.Optional[Mapping] = None,
feature_post_process_code_map: t.Optional[Mapping] = None,
generate_new_cases: GenerateNewCases = "no",
goal_features_map: t.Optional[Mapping] = None,
initial_batch_size: t.Optional[int] = None,
Expand Down Expand Up @@ -1932,6 +1933,15 @@ def react( # noqa: C901
"feature_c": {"max": 1}
}
feature_post_process_code_map : dict of str, optional
A mapping of feature name to custom code strings that will be
evaluated to update the value of the feature they are mapped from.
The custom code is evaluated just after a feature value is predicted
or synthesized to update the value of the feature, meaning that the
resulting value will be used as part of the context for following
action features. The custom code will have access to all context
feature values and previously generated action feature values.
generate_new_cases : {"always", "attempt", "no"}, default "no"
(Optional) Whether to generate new cases.
Expand Down Expand Up @@ -2158,6 +2168,7 @@ def react( # noqa: C901
"action_features": action_features,
"derived_context_features": derived_context_features,
"derived_action_features": derived_action_features,
"feature_post_process_code_map": feature_post_process_code_map,
"goal_features_map": goal_features_map,
"post_process_features": post_process_features,
"post_process_values": post_process_values,
Expand Down Expand Up @@ -2199,6 +2210,7 @@ def react( # noqa: C901
"action_features": action_features,
"derived_context_features": derived_context_features,
"derived_action_features": derived_action_features,
"feature_post_process_code_map": feature_post_process_code_map,
"post_process_features": post_process_features,
"post_process_values": post_process_values,
"use_regional_residuals": use_regional_residuals,
Expand Down Expand Up @@ -2595,6 +2607,7 @@ def react_series( # noqa: C901
details: t.Optional[Mapping] = None,
exclude_novel_nominals_from_uniqueness_check: bool = False,
feature_bounds_map: t.Optional[Mapping[str, Mapping[str, t.Any]]] = None,
feature_post_process_code_map: t.Optional[Mapping] = None,
final_time_steps: t.Optional[list[t.Any]] = None,
generate_new_cases: GenerateNewCases = "no",
goal_features_map: t.Optional[Mapping] = None,
Expand Down Expand Up @@ -2695,6 +2708,16 @@ def react_series( # noqa: C901
If True, will exclude features which have a subtype defined in their feature
attributes from the uniqueness check that happens when ``generate_new_cases``
is True. Only applies to generative reacts.
feature_post_process_code_map : dict of str, optional
A mapping of feature name to custom code strings that will be
evaluated to update the value of the feature they are mapped from.
The custom code is evaluated just after a feature value is predicted
or synthesized to update the value of the feature, meaning that the
resulting value will be used as part of the context for following
action features. The custom code will have access to all context
feature values and previously generated action feature values of
the timestep being generated, as well as the feature values of all
previously generated timesteps.
series_context_features : iterable of str, optional
List of context features corresponding to ``series_context_values``.
series_context_values : list of list of list of object or list of DataFrame, optional
Expand Down Expand Up @@ -2864,6 +2887,7 @@ def react_series( # noqa: C901
react_params = {
"action_features": action_features,
"continue_series": continue_series,
"feature_post_process_code_map": feature_post_process_code_map,
"final_time_steps": final_time_steps,
"init_time_steps": init_time_steps,
"series_stop_maps": series_stop_maps,
Expand Down Expand Up @@ -2913,6 +2937,7 @@ def react_series( # noqa: C901
"num_series_to_generate": num_series_to_generate,
"action_features": action_features,
"continue_series": continue_series,
"feature_post_process_code_map": feature_post_process_code_map,
"final_time_steps": final_time_steps,
"init_time_steps": init_time_steps,
"series_stop_maps": series_stop_maps,
Expand Down
23 changes: 23 additions & 0 deletions howso/engine/trainee.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,7 @@ def react(
details: t.Optional[Mapping[str, t.Any]] = None,
exclude_novel_nominals_from_uniqueness_check: bool = False,
feature_bounds_map: t.Optional[Mapping[str, Mapping[str, t.Any]]] = None,
feature_post_process_code_map: t.Optional[Mapping] = None,
generate_new_cases: GenerateNewCases = "no",
goal_features_map: t.Optional[Mapping] = None,
initial_batch_size: t.Optional[int] = None,
Expand Down Expand Up @@ -1599,6 +1600,15 @@ def react(
"feature_c": {"max": 1}
}
feature_post_process_code_map : dict of str, optional
A mapping of feature name to custom code strings that will be
evaluated to update the value of the feature they are mapped from.
The custom code is evaluated just after a feature value is predicted
or synthesized to update the value of the feature, meaning that the
resulting value will be used as part of the context for following
action features. The custom code will have access to all context
feature values and previously generated action feature values.
generate_new_cases : {"always", "attempt", "no"}, default "no"
This parameter takes in a string that may be one of the following:
Expand Down Expand Up @@ -1721,6 +1731,7 @@ def react(
details=details,
exclude_novel_nominals_from_uniqueness_check=exclude_novel_nominals_from_uniqueness_check,
feature_bounds_map=feature_bounds_map,
feature_post_process_code_map=feature_post_process_code_map,
generate_new_cases=generate_new_cases,
goal_features_map=goal_features_map,
initial_batch_size=initial_batch_size,
Expand Down Expand Up @@ -1753,6 +1764,7 @@ def react_series(
details: t.Optional[Mapping[str, t.Any]] = None,
exclude_novel_nominals_from_uniqueness_check: bool = False,
feature_bounds_map: t.Optional[Mapping[str, Mapping[str, t.Any]]] = None,
feature_post_process_code_map: t.Optional[Mapping] = None,
final_time_steps: t.Optional[list[t.Any]] = None,
generate_new_cases: GenerateNewCases = "no",
goal_features_map: t.Optional[Mapping] = None,
Expand Down Expand Up @@ -1820,6 +1832,16 @@ def react_series(
is True. Only applies to generative reacts.
feature_bounds_map : map of str -> map of str -> object, optional
See parameter ``feature_bounds_map`` in :meth:`react`.
feature_post_process_code_map : dict of str, optional
A mapping of feature name to custom code strings that will be
evaluated to update the value of the feature they are mapped from.
The custom code is evaluated just after a feature value is predicted
or synthesized to update the value of the feature, meaning that the
resulting value will be used as part of the context for following
action features. The custom code will have access to all context
feature values and previously generated action feature values of
the timestep being generated, as well as the feature values of all
previously generated timesteps.
final_time_steps: list of object, optional
The time steps at which to end synthesis. Time-series only.
Time-series only. Must provide either one for all series, or
Expand Down Expand Up @@ -1938,6 +1960,7 @@ def react_series(
details=details,
exclude_novel_nominals_from_uniqueness_check=exclude_novel_nominals_from_uniqueness_check,
feature_bounds_map=feature_bounds_map,
feature_post_process_code_map=feature_post_process_code_map,
final_time_steps=final_time_steps,
generate_new_cases=generate_new_cases,
goal_features_map=goal_features_map,
Expand Down

0 comments on commit e6cd6a8

Please sign in to comment.