本文整理汇总了Python中numpy.alen方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.alen方法的具体用法?Python numpy.alen怎么用?Python numpy.alen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.alen方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_noise_to_model
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def add_noise_to_model(targetModel,largeNoise = False):
#noisy_model = keras.models.clone_model(action_predictor_model)
#noisy_model.set_weights(action_predictor_model.get_weights())
#print("Adding Noise to actor")
#largeNoise = last_game_average < memoryR.mean()
sz = len(noisy_model.layers)
#if largeNoise:
# print("Setting Large Noise!")
for k in range(sz):
w = targetModel.layers[k].get_weights()
if np.alen(w) >0 :
#print("k==>",k)
w[0] = add_noise(w[0],largeNoise)
targetModel.layers[k].set_weights(w)
return targetModel
示例2: reset_noisy_model
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def reset_noisy_model():
sz = len(noisy_model.layers)
#if largeNoise:
# print("Setting Large Noise!")
for k in range(sz):
w = noisy_model.layers[k].get_weights()
apW = action_predictor_model.layers[k].get_weights()
if np.alen(w) >0:
w[0] = reset_noisy_model_weights_to_apWeights(apW[0])
noisy_model.layers[k].set_weights(w)
#print("w",w)
#print("apW",apW)
# --- Parameter Noising
示例3: add_noise_to_model
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def add_noise_to_model(largeNoise = False):
#noisy_model = keras.models.clone_model(action_predictor_model)
#noisy_model.set_weights(action_predictor_model.get_weights())
#print("Adding Noise to actor")
#largeNoise = last_game_average < memoryR.mean()
sz = len(noisy_model.layers)
#if largeNoise:
# print("Setting Large Noise!")
for k in range(sz):
w = noisy_model.layers[k].get_weights()
#print("w ==>", w)
if np.alen(w) >0:
w[0] = add_noise_simple(w[0],largeNoise)
noisy_model.layers[k].set_weights(w)
return noisy_model
# --- Parameter Noising
示例4: add_noise_to_model
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def add_noise_to_model(targetModel,largeNoise = False):
#noisy_model = keras.models.clone_model(action_predictor_model)
#noisy_model.set_weights(action_predictor_model.get_weights())
#print("Adding Noise to actor")
#largeNoise = last_game_average < memoryR.mean()
sz = len(noisy_model.layers)
#if largeNoise:
# print("Setting Large Noise!")
for k in range(sz):
w = targetModel.layers[k].get_weights()
if np.alen(w) >0 :
#print("k==>",k)
if USE_GAUSSIAN_NOISE:
w[0] = add_gaussian_noise(w[0],big_sigma,largeNoise)
else:
w[0] = add_noise_simple(w[0],largeNoise)
targetModel.layers[k].set_weights(w)
return targetModel
示例5: alen
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def alen(a):
"""
Return the length of the first dimension of the input array.
Parameters
----------
a : array_like
Input array.
Returns
-------
alen : int
Length of the first dimension of `a`.
See Also
--------
shape, size
Examples
--------
>>> a = np.zeros((7,4,5))
>>> a.shape[0]
7
>>> np.alen(a)
7
"""
try:
return len(a)
except TypeError:
return len(array(a, ndmin=1))
示例6: ramp_2D
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def ramp_2D(geometry):
detector_width = geometry.detector_shape[np.alen(geometry.detector_shape) - 1]
filter = [
np.reshape(
ramp(detector_width),
(1, detector_width)
)
for i in range(0, geometry.number_of_projections)
]
filter = np.concatenate(filter)
return filter
示例7: ramp_3D
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def ramp_3D(geometry):
detector_width = geometry.detector_shape[np.alen(geometry.detector_shape) - 1]
filter = [
np.reshape(
ramp(detector_width),
(1, 1, detector_width)
)
for i in range(0, geometry.number_of_projections)
]
filter = np.concatenate(filter)
return filter
示例8: ram_lak_2D
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def ram_lak_2D(geometry):
detector_width = geometry.detector_shape[np.alen(geometry.detector_shape) - 1]
detector_spacing_width = geometry.detector_spacing[np.alen(geometry.detector_spacing) - 1]
filter = [
np.reshape(
ram_lak(detector_width, detector_spacing_width),
(1, detector_width)
)
for i in range(0, geometry.number_of_projections)
]
filter = np.concatenate(filter)
return filter
示例9: ram_lak_3D
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def ram_lak_3D(geometry):
detector_width = geometry.detector_shape[np.alen(geometry.detector_shape) - 1]
detector_spacing_width = geometry.detector_spacing[np.alen(geometry.detector_spacing) - 1]
filter = [
np.reshape(
ram_lak(detector_width, detector_spacing_width),
(1, 1, detector_width)
)
for i in range(0, geometry.number_of_projections)
]
filter = np.concatenate(filter)
return (1 / 1.0) * filter
示例10: scale_weights
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def scale_weights(memR,memW):
rmax = memR.max()
rmin = memR.min()
reward_range = math.fabs(rmax - rmin )
if reward_range == 0:
reward_range = 10
for i in range(np.alen(memR)):
memW[i][0] = math.fabs(memR[i][0]-rmin)/reward_range
memW[i][0] = max(memW[i][0],0.001)
#print("memW %5.2f reward %5.2f rmax %5.2f rmin %5.2f "%(memW[i][0],memR[i][0],rmax,rmin))
#print("memW",memW)
return memW
示例11: pr_actor_experience_replay
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def pr_actor_experience_replay(memSA,memR,memS,memA,memW,num_epochs=1):
tSA = (memSA)
tR = (memR)
tX = (memS)
tY = (memA)
tW = (memW)
tX_train = np.zeros(shape=(1,num_env_variables))
tY_train = np.zeros(shape=(1,num_env_actions))
for i in range(np.alen(tR)):
pr = predictTotalRewards(tX[i],GetRememberedOptimalPolicy(tX[i]))
#print ("tR[i]",tR[i],"pr",pr)
d = math.fabs( memoryR.max() - pr)
tW[i]= 0.0000000000000005
if (tR[i]>pr):
tW[i]=0.15
if (tR[i]>pr+d/2):
tW[i] = 1
if tW[i]> np.random.rand(1):
tX_train = np.vstack((tX_train,tX[i]))
tY_train = np.vstack((tY_train,tY[i]))
tX_train = tX_train[1:]
tY_train = tY_train[1:]
print("%8d were better After removing first element"%np.alen(tX_train))
if np.alen(tX_train)>0:
action_predictor_model.fit(tX_train,tY_train, batch_size=mini_batch, nb_epoch=num_epochs,verbose=0)
示例12: train_noisy_actor
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import alen [as 别名]
def train_noisy_actor():
tX = (memoryS)
tY = (memoryA)
tW = (memoryW)
train_A = np.random.randint(tY.shape[0],size=int(min(experience_replay_size,np.alen(tY) )))
tX = tX[train_A,:]
tY = tY[train_A,:]
tW = tW[train_A,:]
noisy_model.fit(tX,tY, batch_size=mini_batch, nb_epoch=training_epochs,verbose=0)