當前位置: 首頁>>代碼示例>>Python>>正文


Python core.Env方法代碼示例

本文整理匯總了Python中gym.core.Env方法的典型用法代碼示例。如果您正苦於以下問題:Python core.Env方法的具體用法?Python core.Env怎麽用?Python core.Env使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gym.core的用法示例。


在下文中一共展示了core.Env方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: serialize

# 需要導入模塊: from gym import core [as 別名]
# 或者: from gym.core import Env [as 別名]
def serialize(obj):
    """
        Serialize any object to a dictionary, so that it can be dumped easily to a JSON file.

     Four rules are applied:
        - To be able to recreate the object, specify its class, or its spec id if the object is an Env.
        - If the object has a config dictionary field, use it. It is assumed that this config suffices to recreate a
        similar object.
        - If the object is Serializable, use its recursive conversion to a dictionary.
        - Else, use its __dict__ by applying repr() on its values
    :param obj: an object
    :return: a dictionary describing the object
    """
    if hasattr(obj, "config"):
        d = obj.config
    elif isinstance(obj, Serializable):
        d = obj.to_dict()
    else:
        d = {key: repr(value) for (key, value) in obj.__dict__.items()}
    d['__class__'] = repr(obj.__class__)
    if isinstance(obj, Env):
        d['id'] = obj.spec.id
        d['import_module'] = getattr(obj, "import_module", None)
    return d 
開發者ID:eleurent,項目名稱:rl-agents,代碼行數:26,代碼來源:configuration.py

示例2: __init__

# 需要導入模塊: from gym import core [as 別名]
# 或者: from gym.core import Env [as 別名]
def __init__(self, task=None):
        super(Env, self).__init__()
        if task is None:
            task = self.sample_tasks(1)[0]
        self.set_task(task) 
開發者ID:learnables,項目名稱:learn2learn,代碼行數:7,代碼來源:meta_env.py


注:本文中的gym.core.Env方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。