本文整理汇总了Python中rllab.spaces.Discrete方法的典型用法代码示例。如果您正苦于以下问题:Python spaces.Discrete方法的具体用法?Python spaces.Discrete怎么用?Python spaces.Discrete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rllab.spaces
的用法示例。
在下文中一共展示了spaces.Discrete方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def __init__(
self,
env_spec,
hidden_sizes=(32, 32),
hidden_nonlinearity=NL.tanh,
output_b_init=None,
weight_signal=1.0,
weight_nonsignal=1.0,
weight_smc=1.0):
"""
:param env_spec: A spec for the mdp.
:param hidden_sizes: list of sizes for the fully connected hidden layers
:param hidden_nonlinearity: nonlinearity used for each hidden layer
:return:
"""
Serializable.quick_init(self, locals())
assert isinstance(env_spec.action_space, Discrete)
output_b_init = compute_output_b_init(env_spec.action_space.names,
output_b_init, weight_signal, weight_nonsignal, weight_smc)
prob_network = MLP(
input_shape=(env_spec.observation_space.flat_dim,),
output_dim=env_spec.action_space.n,
hidden_sizes=hidden_sizes,
hidden_nonlinearity=hidden_nonlinearity,
output_nonlinearity=NL.softmax,
output_b_init=output_b_init
)
super(InitCategoricalMLPPolicy, self).__init__(env_spec, hidden_sizes,
hidden_nonlinearity, prob_network)
# Modified from RLLab GRUNetwork
示例2: ensure_named
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def ensure_named(space):
"""Ensure that the give space is named."""
if isinstance(space, (NamedBox, NamedDiscrete)):
return space
elif isinstance(space, Box):
return NamedBox.from_unnamed(space)
elif isinstance(space, Discrete):
return NamedDiscrete.from_unnamed(space)
# elif isinstance(space, ListSpace):
# return NamedDiscrete(len(space._list), names=space._list)
else:
raise Exception("Cannot convert space of type %s into a named rllab space"
% (type(space),))
示例3: __init__
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def __init__(self, transition_matrix, reward, init_state, terminate_on_reward=False):
super(DiscreteEnv, self).__init__()
dX, dA, dXX = transition_matrix.shape
self.nstates = dX
self.nactions = dA
self.transitions = transition_matrix
self.init_state = init_state
self.reward = reward
self.terminate_on_reward = terminate_on_reward
self.__observation_space = Box(0, 1, shape=(self.nstates,))
#max_A = 0
#for trans in self.transitions:
# max_A = max(max_A, len(self.transitions[trans]))
self.__action_space = Discrete(dA)
示例4: action_space
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def action_space(self):
return spaces.Discrete(4)
示例5: observation_space
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def observation_space(self):
return spaces.Product([spaces.Discrete(self.numrow),spaces.Discrete(self.numcol),spaces.Discrete(2)])
示例6: action_space
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def action_space(self):
return spaces.Discrete(2)
示例7: observation_space
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def observation_space(self):
return spaces.Discrete(3)
示例8: __init__
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def __init__(self, ns):
self.agent_num = len(ns)
self.agent_spaces = np.array([Discrete(n) for n in ns])
示例9: action_space
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def action_space(self):
lat_dim = self.low_policy_latent_dim
if self.discrete_actions:
return spaces.Discrete(lat_dim) # the action is now just a selection
else:
ub = 1e6 * np.ones(lat_dim)
return spaces.Box(-1 * ub, ub)
示例10: action_space
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def action_space(self):
selector_dim = self.low_policy_selector_dim
if self.discrete_actions:
return spaces.Discrete(selector_dim) # the action is now just a selection
else:
ub = 1e6 * np.ones(selector_dim)
return spaces.Box(-1 * ub, ub)
示例11: __init__
# 需要导入模块: from rllab import spaces [as 别名]
# 或者: from rllab.spaces import Discrete [as 别名]
def __init__(
self,
env_spec,
latent_dim=0, # all this is fake
latent_name='categorical',
bilinear_integration=False,
resample=False, # until here
hidden_sizes=(32, 32),
hidden_nonlinearity=NL.tanh,
prob_network=None,
):
"""
:param env_spec: A spec for the mdp.
:param hidden_sizes: list of sizes for the fully connected hidden layers
:param hidden_nonlinearity: nonlinearity used for each hidden layer
:param prob_network: manually specified network for this policy, other network params
are ignored
:return:
"""
#bullshit
self.latent_dim = latent_dim ##could I avoid needing this self for the get_action?
self.latent_name = latent_name
self.bilinear_integration = bilinear_integration
self.resample = resample
self._set_std_to_0 = False
Serializable.quick_init(self, locals())
assert isinstance(env_spec.action_space, Discrete)
if prob_network is None:
prob_network = MLP(
input_shape=(env_spec.observation_space.flat_dim,),
output_dim=env_spec.action_space.n,
hidden_sizes=hidden_sizes,
hidden_nonlinearity=hidden_nonlinearity,
output_nonlinearity=NL.softmax,
)
self._l_prob = prob_network.output_layer
self._l_obs = prob_network.input_layer
self._f_prob = ext.compile_function([prob_network.input_layer.input_var], L.get_output(
prob_network.output_layer))
self._dist = Categorical(env_spec.action_space.n)
super(CategoricalMLPPolicy, self).__init__(env_spec)
LasagnePowered.__init__(self, [prob_network.output_layer])