1
0
mirror of https://github.com/microsoft/qlib.git synced 2026-07-15 16:56:54 +08:00

bug fixed & code format

This commit is contained in:
lzh222333
2021-03-31 03:08:48 +00:00
parent 3724273d73
commit edcd7b1ff9
8 changed files with 28 additions and 32 deletions

View File

@@ -73,7 +73,7 @@ def reset(task_pool, exp_name):
print("========== reset ==========") print("========== reset ==========")
TaskManager(task_pool=task_pool).remove() TaskManager(task_pool=task_pool).remove()
exp, _ = R.get_exp(experiment_name=exp_name) exp = R.get_exp(experiment_name=exp_name)
for rid in exp.list_recorders(): for rid in exp.list_recorders():
exp.delete_recorder(rid) exp.delete_recorder(rid)
@@ -115,7 +115,7 @@ def task_collecting(task_pool, exp_name):
task_config = recorder.load_object("task") task_config = recorder.load_object("task")
model_key = task_config["model"]["class"] model_key = task_config["model"]["class"]
rolling_key = task_config["dataset"]["kwargs"]["segments"]["test"] rolling_key = task_config["dataset"]["kwargs"]["segments"]["test"]
return model_key, model_key, rolling_key return model_key, rolling_key
def my_filter(recorder): def my_filter(recorder):
# only choose the results of "LGBModel" # only choose the results of "LGBModel"

View File

@@ -117,7 +117,7 @@ def task_collecting():
task_config = recorder.load_object("task") task_config = recorder.load_object("task")
model_key = task_config["model"]["class"] model_key = task_config["model"]["class"]
rolling_key = task_config["dataset"]["kwargs"]["segments"]["test"] rolling_key = task_config["dataset"]["kwargs"]["segments"]["test"]
return model_key, model_key, rolling_key return model_key, rolling_key
def my_filter(recorder): def my_filter(recorder):
# only choose the results of "LGBModel" # only choose the results of "LGBModel"
@@ -136,7 +136,7 @@ def task_collecting():
def reset(): def reset():
print("========== reset ==========") print("========== reset ==========")
task_manager.remove() task_manager.remove()
exp, _ = R.get_exp(experiment_name=exp_name) exp = R.get_exp(experiment_name=exp_name)
for rid in exp.list_recorders(): for rid in exp.list_recorders():
exp.delete_recorder(rid) exp.delete_recorder(rid)

View File

@@ -7,8 +7,7 @@ from qlib.workflow.task.utils import list_recorders
class Collector: class Collector:
"""The collector to collect different results based on experiment backend and ensemble method """The collector to collect different results based on experiment backend and ensemble method"""
"""
def collect(self, ensemble, get_group_key_func, *args, **kwargs): def collect(self, ensemble, get_group_key_func, *args, **kwargs):
"""To collect the results, we need to get the experiment record firstly and divided them into """To collect the results, we need to get the experiment record firstly and divided them into
@@ -64,7 +63,6 @@ class RecorderCollector(Collector):
artifact = rec.load_object(self.artifacts_path[key]) artifact = rec.load_object(self.artifacts_path[key])
ensemble_dict[key][group_key] = artifact ensemble_dict[key][group_key] = artifact
if isinstance(artifacts_key, str): if isinstance(artifacts_key, str):
return ensemble(ensemble_dict[artifacts_key]) return ensemble(ensemble_dict[artifacts_key])
@@ -72,4 +70,3 @@ class RecorderCollector(Collector):
for key in artifacts_key: for key in artifacts_key:
collect_dict[key] = ensemble(ensemble_dict[key]) collect_dict[key] = ensemble(ensemble_dict[key])
return collect_dict return collect_dict

View File

@@ -7,10 +7,8 @@ from qlib.workflow.task.utils import list_recorders
from typing import Dict from typing import Dict
class Ensemble: class Ensemble:
"""Merge the objects in an Ensemble. """Merge the objects in an Ensemble."""
"""
def __init__(self, merge_func=None, get_grouped_key_func=None) -> None: def __init__(self, merge_func=None, get_grouped_key_func=None) -> None:
"""init Ensemble """init Ensemble
@@ -135,10 +133,10 @@ class Ensemble:
grouped_dict = self.group(group_dict) grouped_dict = self.group(group_dict)
return self.reduce(grouped_dict) return self.reduce(grouped_dict)
class RollingEnsemble(Ensemble):
"""A specific implementation of Ensemble for Rolling.
""" class RollingEnsemble(Ensemble):
"""A specific implementation of Ensemble for Rolling."""
def merge_func(self, group_inner_dict): def merge_func(self, group_inner_dict):
"""merge group_inner_dict by datetime. """merge group_inner_dict by datetime.
@@ -176,5 +174,3 @@ class RollingEnsemble(Ensemble):
""" """
assert len(group_key) >= 2 assert len(group_key) >= 2
return group_key[:-1], group_key[-1] return group_key[:-1], group_key[-1]

View File

@@ -106,7 +106,9 @@ class RollingOnlineManager(OnlineManagerR):
pass pass
def prepare_tasks(self): def prepare_tasks(self):
latest_records, max_test = self.list_latest_recorders(lambda rec: self.get_online_tag(rec) == OnlineManager.ONLINE_TAG) latest_records, max_test = self.list_latest_recorders(
lambda rec: self.get_online_tag(rec) == OnlineManager.ONLINE_TAG
)
if max_test is None: if max_test is None:
self.logger.warn(f"No latest_recorders.") self.logger.warn(f"No latest_recorders.")
return return

View File

@@ -9,6 +9,7 @@ from qlib.workflow.recorder import Recorder
from qlib.workflow.task.utils import list_recorders from qlib.workflow.task.utils import list_recorders
from qlib.data.dataset.handler import DataHandlerLP from qlib.data.dataset.handler import DataHandlerLP
class ModelUpdater: class ModelUpdater:
""" """
The model updater to update model results in new data. The model updater to update model results in new data.
@@ -48,7 +49,7 @@ class ModelUpdater:
dataset.setup_data(handler_kwargs={"init_type": DataHandlerLP.IT_LS}, segments=segments) dataset.setup_data(handler_kwargs={"init_type": DataHandlerLP.IT_LS}, segments=segments)
return dataset return dataset
def update_pred(self, recorder: Recorder, frequency='day'): def update_pred(self, recorder: Recorder, frequency="day"):
"""update predictions to the latest day in Calendar based on rid """update predictions to the latest day in Calendar based on rid
Parameters Parameters
@@ -60,10 +61,10 @@ class ModelUpdater:
last_end = old_pred.index.get_level_values("datetime").max() last_end = old_pred.index.get_level_values("datetime").max()
# updated to the latest trading day # updated to the latest trading day
if frequency=='day': if frequency == "day":
cal = D.calendar(start_time=last_end + pd.Timedelta(days=1), end_time=None) cal = D.calendar(start_time=last_end + pd.Timedelta(days=1), end_time=None)
else: else:
raise NotImplementedError("Now Qlib only support update daily frequency prediction") raise NotImplementedError("Now `ModelUpdater` only support update daily frequency prediction")
if len(cal) == 0: if len(cal) == 0:
self.logger.info( self.logger.info(

View File

@@ -42,7 +42,7 @@ def list_recorders(experiment, rec_filter_func=None):
dict: a dict {rid: recorder} after filtering. dict: a dict {rid: recorder} after filtering.
""" """
if isinstance(experiment, str): if isinstance(experiment, str):
experiment, _ = R.get_exp(experiment_name=experiment) experiment = R.get_exp(experiment_name=experiment)
recs = experiment.list_recorders() recs = experiment.list_recorders()
recs_flt = {} recs_flt = {}
for rid, rec in recs.items(): for rid, rec in recs.items():