Skip to content

Uniform Noise Addition

Uniform Noise Addition

Only for use with simulated data

This method is used only when training with simulated data.

Can be used to add uniform noise by using np.random.randint() between [-250,250] for x and y, and [0,1000] for z.

Bases: BaseEstimator, TransformerMixin

Adds uniform noise to the point cloud data in cartesian coordinates.

Parameters

ratio_noise : (float) Fraction of noise to length of point cloud to be produced

Returns

new_data: (array) Data with uniform noise added event_lengths: (array) New event lengths accounting for added noise points

Source code in scripts/ml_preprocessing_steps.py
class UniformNoiseAddition(BaseEstimator,TransformerMixin):
    """
    Adds uniform noise to the point cloud data in cartesian coordinates.

    Parameters
    ----------
    ratio_noise : (float)
        Fraction of noise to length of point cloud to be produced

    Returns
    ----------
    new_data: (array)
        Data with uniform noise added
    event_lengths: (array)
        New event lengths accounting for added noise points 
    """
    def __init__(self, ratio_noise: float):
        self.ratio_noise = ratio_noise


    def fit(self,X,y=None):
        return self  

    def transform(self,X,y=None):
        """Adding uniform noise in cartesian coordinates

        Args:
            X (tuple):Packed data and event lengths np.array
            y (None): Defaults to None.

        Returns:
            (tuple): Data with noise and new event lengths
        """
        data,event_lengths = X
        skipped = 0
        for i in range(len(data)): 
            data_size = int((self.ratio_noise)*event_lengths[i])

            noise_x = np.random.randint(-250,250,(data_size,1))
            noise_y = np.random.randint(-250,250,(data_size,1))
            noise_z = np.random.randint(0,1000,(data_size,1))

            array_charge = np.zeros((data_size,1))
            noise_data = np.concatenate((noise_x,noise_y,noise_z,array_charge),axis=1)
            combined_data = np.concatenate((data[i,:event_lengths[i],:],noise_data,data[i,-2:,:]),axis=0)

            if combined_data.shape[0] > data.shape[1]:
                skipped+=1
                continue

            data[i, :combined_data.shape[0], :] = combined_data

            event_lengths[i]+=data_size


        print(f"Number of events skipped: {skipped}")
        return (data,event_lengths)

transform(X, y=None)

Adding uniform noise in cartesian coordinates

Parameters:

Name Type Description Default
X tuple

Packed data and event lengths np.array

required
y None

Defaults to None.

None

Returns:

Type Description
tuple

Data with noise and new event lengths

Source code in scripts/ml_preprocessing_steps.py
def transform(self,X,y=None):
    """Adding uniform noise in cartesian coordinates

    Args:
        X (tuple):Packed data and event lengths np.array
        y (None): Defaults to None.

    Returns:
        (tuple): Data with noise and new event lengths
    """
    data,event_lengths = X
    skipped = 0
    for i in range(len(data)): 
        data_size = int((self.ratio_noise)*event_lengths[i])

        noise_x = np.random.randint(-250,250,(data_size,1))
        noise_y = np.random.randint(-250,250,(data_size,1))
        noise_z = np.random.randint(0,1000,(data_size,1))

        array_charge = np.zeros((data_size,1))
        noise_data = np.concatenate((noise_x,noise_y,noise_z,array_charge),axis=1)
        combined_data = np.concatenate((data[i,:event_lengths[i],:],noise_data,data[i,-2:,:]),axis=0)

        if combined_data.shape[0] > data.shape[1]:
            skipped+=1
            continue

        data[i, :combined_data.shape[0], :] = combined_data

        event_lengths[i]+=data_size


    print(f"Number of events skipped: {skipped}")
    return (data,event_lengths)