Skip to content

Commit e6cd6a8

Browse files
cademackapbassett
andauthored
23032: Adds new parameter to react methods, "feature_post_process_code_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 <[email protected]>
1 parent c0691be commit e6cd6a8

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

howso/client/base.py

+25
Original file line numberDiff line numberDiff line change
@@ -1463,6 +1463,7 @@ def react( # noqa: C901
14631463
details: t.Optional[Mapping] = None,
14641464
exclude_novel_nominals_from_uniqueness_check: bool = False,
14651465
feature_bounds_map: t.Optional[Mapping] = None,
1466+
feature_post_process_code_map: t.Optional[Mapping] = None,
14661467
generate_new_cases: GenerateNewCases = "no",
14671468
goal_features_map: t.Optional[Mapping] = None,
14681469
initial_batch_size: t.Optional[int] = None,
@@ -1932,6 +1933,15 @@ def react( # noqa: C901
19321933
"feature_c": {"max": 1}
19331934
}
19341935
1936+
feature_post_process_code_map : dict of str, optional
1937+
A mapping of feature name to custom code strings that will be
1938+
evaluated to update the value of the feature they are mapped from.
1939+
The custom code is evaluated just after a feature value is predicted
1940+
or synthesized to update the value of the feature, meaning that the
1941+
resulting value will be used as part of the context for following
1942+
action features. The custom code will have access to all context
1943+
feature values and previously generated action feature values.
1944+
19351945
generate_new_cases : {"always", "attempt", "no"}, default "no"
19361946
(Optional) Whether to generate new cases.
19371947
@@ -2158,6 +2168,7 @@ def react( # noqa: C901
21582168
"action_features": action_features,
21592169
"derived_context_features": derived_context_features,
21602170
"derived_action_features": derived_action_features,
2171+
"feature_post_process_code_map": feature_post_process_code_map,
21612172
"goal_features_map": goal_features_map,
21622173
"post_process_features": post_process_features,
21632174
"post_process_values": post_process_values,
@@ -2199,6 +2210,7 @@ def react( # noqa: C901
21992210
"action_features": action_features,
22002211
"derived_context_features": derived_context_features,
22012212
"derived_action_features": derived_action_features,
2213+
"feature_post_process_code_map": feature_post_process_code_map,
22022214
"post_process_features": post_process_features,
22032215
"post_process_values": post_process_values,
22042216
"use_regional_residuals": use_regional_residuals,
@@ -2595,6 +2607,7 @@ def react_series( # noqa: C901
25952607
details: t.Optional[Mapping] = None,
25962608
exclude_novel_nominals_from_uniqueness_check: bool = False,
25972609
feature_bounds_map: t.Optional[Mapping[str, Mapping[str, t.Any]]] = None,
2610+
feature_post_process_code_map: t.Optional[Mapping] = None,
25982611
final_time_steps: t.Optional[list[t.Any]] = None,
25992612
generate_new_cases: GenerateNewCases = "no",
26002613
goal_features_map: t.Optional[Mapping] = None,
@@ -2695,6 +2708,16 @@ def react_series( # noqa: C901
26952708
If True, will exclude features which have a subtype defined in their feature
26962709
attributes from the uniqueness check that happens when ``generate_new_cases``
26972710
is True. Only applies to generative reacts.
2711+
feature_post_process_code_map : dict of str, optional
2712+
A mapping of feature name to custom code strings that will be
2713+
evaluated to update the value of the feature they are mapped from.
2714+
The custom code is evaluated just after a feature value is predicted
2715+
or synthesized to update the value of the feature, meaning that the
2716+
resulting value will be used as part of the context for following
2717+
action features. The custom code will have access to all context
2718+
feature values and previously generated action feature values of
2719+
the timestep being generated, as well as the feature values of all
2720+
previously generated timesteps.
26982721
series_context_features : iterable of str, optional
26992722
List of context features corresponding to ``series_context_values``.
27002723
series_context_values : list of list of list of object or list of DataFrame, optional
@@ -2864,6 +2887,7 @@ def react_series( # noqa: C901
28642887
react_params = {
28652888
"action_features": action_features,
28662889
"continue_series": continue_series,
2890+
"feature_post_process_code_map": feature_post_process_code_map,
28672891
"final_time_steps": final_time_steps,
28682892
"init_time_steps": init_time_steps,
28692893
"series_stop_maps": series_stop_maps,
@@ -2913,6 +2937,7 @@ def react_series( # noqa: C901
29132937
"num_series_to_generate": num_series_to_generate,
29142938
"action_features": action_features,
29152939
"continue_series": continue_series,
2940+
"feature_post_process_code_map": feature_post_process_code_map,
29162941
"final_time_steps": final_time_steps,
29172942
"init_time_steps": init_time_steps,
29182943
"series_stop_maps": series_stop_maps,

howso/engine/trainee.py

+23
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,7 @@ def react(
11791179
details: t.Optional[Mapping[str, t.Any]] = None,
11801180
exclude_novel_nominals_from_uniqueness_check: bool = False,
11811181
feature_bounds_map: t.Optional[Mapping[str, Mapping[str, t.Any]]] = None,
1182+
feature_post_process_code_map: t.Optional[Mapping] = None,
11821183
generate_new_cases: GenerateNewCases = "no",
11831184
goal_features_map: t.Optional[Mapping] = None,
11841185
initial_batch_size: t.Optional[int] = None,
@@ -1599,6 +1600,15 @@ def react(
15991600
"feature_c": {"max": 1}
16001601
}
16011602
1603+
feature_post_process_code_map : dict of str, optional
1604+
A mapping of feature name to custom code strings that will be
1605+
evaluated to update the value of the feature they are mapped from.
1606+
The custom code is evaluated just after a feature value is predicted
1607+
or synthesized to update the value of the feature, meaning that the
1608+
resulting value will be used as part of the context for following
1609+
action features. The custom code will have access to all context
1610+
feature values and previously generated action feature values.
1611+
16021612
generate_new_cases : {"always", "attempt", "no"}, default "no"
16031613
This parameter takes in a string that may be one of the following:
16041614
@@ -1721,6 +1731,7 @@ def react(
17211731
details=details,
17221732
exclude_novel_nominals_from_uniqueness_check=exclude_novel_nominals_from_uniqueness_check,
17231733
feature_bounds_map=feature_bounds_map,
1734+
feature_post_process_code_map=feature_post_process_code_map,
17241735
generate_new_cases=generate_new_cases,
17251736
goal_features_map=goal_features_map,
17261737
initial_batch_size=initial_batch_size,
@@ -1753,6 +1764,7 @@ def react_series(
17531764
details: t.Optional[Mapping[str, t.Any]] = None,
17541765
exclude_novel_nominals_from_uniqueness_check: bool = False,
17551766
feature_bounds_map: t.Optional[Mapping[str, Mapping[str, t.Any]]] = None,
1767+
feature_post_process_code_map: t.Optional[Mapping] = None,
17561768
final_time_steps: t.Optional[list[t.Any]] = None,
17571769
generate_new_cases: GenerateNewCases = "no",
17581770
goal_features_map: t.Optional[Mapping] = None,
@@ -1820,6 +1832,16 @@ def react_series(
18201832
is True. Only applies to generative reacts.
18211833
feature_bounds_map : map of str -> map of str -> object, optional
18221834
See parameter ``feature_bounds_map`` in :meth:`react`.
1835+
feature_post_process_code_map : dict of str, optional
1836+
A mapping of feature name to custom code strings that will be
1837+
evaluated to update the value of the feature they are mapped from.
1838+
The custom code is evaluated just after a feature value is predicted
1839+
or synthesized to update the value of the feature, meaning that the
1840+
resulting value will be used as part of the context for following
1841+
action features. The custom code will have access to all context
1842+
feature values and previously generated action feature values of
1843+
the timestep being generated, as well as the feature values of all
1844+
previously generated timesteps.
18231845
final_time_steps: list of object, optional
18241846
The time steps at which to end synthesis. Time-series only.
18251847
Time-series only. Must provide either one for all series, or
@@ -1938,6 +1960,7 @@ def react_series(
19381960
details=details,
19391961
exclude_novel_nominals_from_uniqueness_check=exclude_novel_nominals_from_uniqueness_check,
19401962
feature_bounds_map=feature_bounds_map,
1963+
feature_post_process_code_map=feature_post_process_code_map,
19411964
final_time_steps=final_time_steps,
19421965
generate_new_cases=generate_new_cases,
19431966
goal_features_map=goal_features_map,

0 commit comments

Comments
 (0)