Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solving mixer ties with runtime as second criteria #1192

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lightwood/api/json_ai.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ def add_implicit_values(json_ai: JsonAI) -> JsonAI:
'fit': json_ai.model["args"].get("fit", True),
'args': json_ai.model["args"].get("args", "$pred_args"),
'accuracy_functions': json_ai.model["args"].get("accuracy_functions", "$accuracy_functions"),
'runtime_log': json_ai.model["args"].get("runtime_log", "$runtime_log"),
'ts_analysis': json_ai.model["args"].get("ts_analysis", "self.ts_analysis" if is_ts else None),
'dtype_dict': json_ai.model["args"].get("dtype_dict", "$dtype_dict"),
}
Expand Down
12 changes: 9 additions & 3 deletions lightwood/ensemble/best_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BestOf(BaseEnsemble):
indexes_by_accuracy: List[float]

def __init__(self, target, mixers: List[BaseMixer], data: EncodedDs, accuracy_functions,
args: PredictionArguments, ts_analysis: Optional[dict] = None, fit: bool = True) -> None:
args: PredictionArguments,runtime_log: Optional[dict] = None, ts_analysis: Optional[dict] = None, fit: bool = True) -> None:
super().__init__(target, mixers, data, fit=False)
self.special_dispatch_list = [GluonTSMixer]

Expand Down Expand Up @@ -55,9 +55,15 @@ def __init__(self, target, mixers: List[BaseMixer], data: EncodedDs, accuracy_fu
is_best=False
))

score_list.append(avg_score)
if runtime_log is not None:
score_list.append((avg_score, -1 * runtime_log[type(mixer).__name__ + '.fit_mixer'][0][0]))
else:
score_list.append(avg_score)

self.indexes_by_accuracy = list(reversed(np.array(score_list).argsort()))
if runtime_log is not None:
self.indexes_by_accuracy = list(reversed(np.array(score_list, dtype=[('x', np.float32),('y', np.float32)]).argsort(order=('x', 'y'))))
else:
self.indexes_by_accuracy = list(reversed(np.array(score_list).argsort()))
self.supports_proba = self.mixers[self.indexes_by_accuracy[0]].supports_proba
log.info(f'Picked best mixer: {type(self.mixers[self.indexes_by_accuracy[0]]).__name__}')
self.prepared = True
Expand Down
6 changes: 5 additions & 1 deletion lightwood/helpers/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ def wrap(predictor, *args, **kw):
result = f(predictor, *args, **kw)
te = time()
log.debug(f' `{f.__name__}` runtime: {round(te - ts, 2)} seconds')
name_ = f.__name__ if f.__name__ != 'fit_mixer' else type(args[0]).__name__ + '.fit_mixer'
if hasattr(predictor, 'runtime_log'):
predictor.runtime_log[(f.__name__, datetime.fromtimestamp(ts))] = round(te - ts, 2)
if name_ not in predictor.runtime_log:
predictor.runtime_log[name_] = [(round(te - ts, 2), datetime.fromtimestamp(ts))]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the structure in which runtime logs were being stored let me know if the previous structure is being utilised anywhere will think of something else.

else:
predictor.runtime_log[name_].append((round(te - ts, 2), datetime.fromtimestamp(ts)))
return result
return wrap

Expand Down
Loading