Python numpy.alen() Examples

The following are 30 code examples for showing how to use numpy.alen(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module numpy , or try the search function .

Example 1
Project: FitML   Author: FitMachineLearning   File: ROBOTIC_Template_Experimental_v0.1.py    License: MIT License 6 votes vote down vote up
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 
Example 2
Project: FitML   Author: FitMachineLearning   File: ROBOTIC_Template_Experimental_v0.1.py    License: MIT License 6 votes vote down vote up
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 
Example 3
Project: FitML   Author: FitMachineLearning   File: Walker2D.v2.0.py    License: MIT License 6 votes vote down vote up
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 
Example 4
Project: FitML   Author: FitMachineLearning   File: AntBulletEnv.py    License: MIT License 6 votes vote down vote up
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 
Example 5
Project: FitML   Author: FitMachineLearning   File: BipedalWalker_v3.0.py    License: MIT License 6 votes vote down vote up
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 
Example 6
Project: FitML   Author: FitMachineLearning   File: Hopper_v1.0.py    License: MIT License 6 votes vote down vote up
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 
Example 7
Project: FitML   Author: FitMachineLearning   File: MainAlgo_PR_v1.0.py    License: MIT License 6 votes vote down vote up
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 
Example 8
Project: FitML   Author: FitMachineLearning   File: RoboschoolHalfCheetah_v1.py    License: MIT License 6 votes vote down vote up
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 
Example 9
Project: FitML   Author: FitMachineLearning   File: _MainAlgo_v4.2.py    License: MIT License 6 votes vote down vote up
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 
Example 10
Project: FitML   Author: FitMachineLearning   File: Main_algo.py    License: MIT License 6 votes vote down vote up
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 
Example 11
Project: FitML   Author: FitMachineLearning   File: Main_algo.py    License: MIT License 6 votes vote down vote up
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 
Example 12
Project: FitML   Author: FitMachineLearning   File: LunarLanderContinuous_v1.0.py    License: MIT License 6 votes vote down vote up
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 
Example 13
Project: FitML   Author: FitMachineLearning   File: LunarLanderContinuous_v1.0.py    License: MIT License 6 votes vote down vote up
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 
Example 14
Project: recruit   Author: Frank-qlu   File: fromnumeric.py    License: Apache License 2.0 5 votes vote down vote up
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)) 
Example 15
Project: lambda-packs   Author: ryfeus   File: fromnumeric.py    License: MIT License 5 votes vote down vote up
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)) 
Example 16
Project: auto-alt-text-lambda-api   Author: abhisuri97   File: fromnumeric.py    License: MIT License 5 votes vote down vote up
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)) 
Example 17
Project: vnpy_crypto   Author: birforce   File: fromnumeric.py    License: MIT License 5 votes vote down vote up
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)) 
Example 18
Project: Mastering-Elasticsearch-7.0   Author: PacktPublishing   File: fromnumeric.py    License: MIT License 5 votes vote down vote up
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)) 
Example 19
Project: PYRO-NN   Author: csyben   File: filters.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 20
Project: PYRO-NN   Author: csyben   File: filters.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 21
Project: PYRO-NN   Author: csyben   File: filters.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 22
Project: PYRO-NN   Author: csyben   File: filters.py    License: Apache License 2.0 5 votes vote down vote up
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 
Example 23
Project: GraphicDesignPatternByPython   Author: Relph1119   File: fromnumeric.py    License: MIT License 5 votes vote down vote up
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)) 
Example 24
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)) 
Example 25
Project: pySINDy   Author: luckystarufo   File: fromnumeric.py    License: MIT License 5 votes vote down vote up
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)) 
Example 26
Project: FitML   Author: FitMachineLearning   File: ROBOTIC_Template_Experimental_v0.1.py    License: MIT License 5 votes vote down vote up
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 
Example 27
Project: FitML   Author: FitMachineLearning   File: ROBOTIC_Template_Experimental_v0.1.py    License: MIT License 5 votes vote down vote up
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) 
Example 28
Project: FitML   Author: FitMachineLearning   File: ROBOTIC_Template_Experimental_v0.1.py    License: MIT License 5 votes vote down vote up
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) 
Example 29
Project: FitML   Author: FitMachineLearning   File: Walker2D.v2.0.py    License: MIT License 5 votes vote down vote up
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 
Example 30
Project: FitML   Author: FitMachineLearning   File: Walker2D.v2.0.py    License: MIT License 5 votes vote down vote up
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)