> ## Documentation Index
> Fetch the complete documentation index at: https://docs.graphext.com/llms.txt
> Use this file to discover all available pages before exploring further.

# add_noise

> Add noise to a column with numbers or lists of numbers. 

Given a distribution name with a scale and loc parameters,
the step optionally applies another scaling to it either based on the standard deviation of the column or a proportionally to each point through
the `relative` parameter in order to preserve the underlying structure of the data. Then the computation is carried as follows:

new value = original value + relative scaling factor \* random sample from the distribution.

If this `relative` parameter is not given or is set to `abs`, then the relative scaling factor is 1.

## Usage

The following examples show how the step can be used in a recipe.

<Accordion title="Examples" icon="code" defaultOpen="true">
  <Tabs>
    <Tab title="Example 1">
      Add white noise to a column of embeddings

      ```stan theme={null}
      add_noise(ds.embeddings) -> (ds.embeddings_with_noise)
      ```
    </Tab>

    <Tab title="Example 2">
      Add std-dependant noise to a numerical column

      ```stan theme={null}
      add_noise(ds.number, {"relative": "std"}) -> (ds.number_with_noise)
      ```
    </Tab>

    <Tab title="Signature">
      General syntax for using the step in a recipe. Shows the inputs and outputs the step is expected to receive and will produce respectively. For futher details see sections below.

      ```stan theme={null}
      add_noise(input_column: number|list[number], {
          "param": value,
          ...
      }) -> (result: column)
      ```
    </Tab>
  </Tabs>
</Accordion>

## Inputs & Outputs

The following are the inputs expected by the step and the outputs it produces. These are generally
columns (`ds.first_name`), datasets (`ds` or `ds[["first_name", "last_name"]]`) or models (referenced
by name e.g. `"churn-clf"`).

<Accordion title="Inputs" icon="right-to-bracket">
  <ParamField path="input_column" type="column[number|list[number]]" required>
    The original column.
  </ParamField>
</Accordion>

<Accordion title="Outputs" icon="right-from-bracket">
  <ParamField path="result" type="column" required>
    The result of applying noise to it.
  </ParamField>
</Accordion>

## Configuration

The following parameters can be used to configure the behaviour of the step by including them in
a json object as the last "input" to the step, i.e. `step(..., {"param": "value", ...}) -> (output)`.

<Accordion title="Parameters" defaultOpen="true" icon="sliders">
  <ParamField path="relative" type="[number, string]" default="abs">
    Mode to use.
    Either set to "std" to use the standard deviation, or use a number to scale the sampling.

    <Accordion title="Options">
      <Tabs>
        <Tab title="number">
          <ParamField path="{_}" type="number">
            number.
          </ParamField>
        </Tab>

        <Tab title="string">
          <ParamField path="{_}" type="string">
            string.

            Values must be one of the following:

            * `std`
            * `abs`
          </ParamField>
        </Tab>
      </Tabs>
    </Accordion>
  </ParamField>

  <ParamField path="dist_name" type="string" default="normal">
    Distribution Function that noise is sampled from.

    Values must be one of the following:

    * `gumbel`
    * `laplace`
    * `logistic`
    * `normal`
  </ParamField>

  <ParamField path="loc" type="number" default="0.0">
    Mean ("centre") of the chosen distribution.
  </ParamField>

  <ParamField path="scale" type="number" default="1.0">
    Standard deviation (spread or "width") of the distribution.
  </ParamField>

  <ParamField path="seed" type="[number, null]">
    The seed to use for the random distribution, if you wish to get reproducibility in your results.
  </ParamField>
</Accordion>
