# ❖ MixedScales

{% hint style="info" %}
❖ **SDV Enterprise Bundle**. This feature is available as part of the **CAG Bundle**, an optional add-on to SDV Enterprise. For more information, please visit the [CAG Bundle](/sdv/explore/sdv-bundles/cag.md) page.
{% endhint %}

The **MixedScales** constraint enforces that the value of a categorical column (or a combination of categorical columns) determines the scale of a numerical column.&#x20;

<figure><img src="/files/zDj9VFAQ5mzKNBf2dGdt" alt=""><figcaption><p>For example, the combined value of categorical columns <code>test_type</code> and <code>units</code> will determine the value of numerical column for <code>test_results</code>. So if test type is <code>'height'</code> and units are <code>'inches'</code> then it forces the synthesizer to learn the scale specially for this segment.</p></figcaption></figure>

## Constraint API

Create a `MixedScales` constraint.

**Parameters**

* (required) `segment_column_names`: A list of one or more categorical columns that ultimately segment the data into different groups of rows. Each group will have a different scale.
* (required) `mixed_scale_column_name`: A numerical column whose scale depends on the segment.
* `table_name`: A string with the name of the table to apply this to. Required if you have a multi-table dataset.

```python
from sdv.cag import MixedScales

my_constraint = MixedScales(
    segment_column_names=['test_type', 'units'],
    'mixed_scale_column_name'='test_results'
)
```

## Usage

Apply the constraint to any SDV synthesizer. Then fit and sample as usual.

```python
synthesizer = GaussianCopulaSynthesizer(metadata)
synthesizer.add_constraints([my_constraint])

synthesizer.fit(data)
synthetic_data = synthesizer.sample()
```

For more information about using predefined constraints, please see the [**Constraint-Augmented Generation tutorial**](https://colab.research.google.com/drive/1WCMQujfVKL5giULZXOPPIBoMfzR9Zj68?usp=sharing).

## Auto-Detection

Auto-detection is allowed for this constraint but it is not enabled by default.

If you'd like to auto-detect this constraint specifically, you can supply it in the auto-detection parameters. This will detect all instances of the constraint throughout the dataset.

```python
constraints = synthesizer.detect_constraints(
    data,
    constraint_classes=['MixedScales']
)
```

**Detection Parameters**: None

## FAQs

<details>

<summary>What if I only have one categorical column that determines the scale?</summary>

In this case, please provide a list of just one column name as your `segment_column_names`:

```python
my_constraint = {
    'constraint_class': 'MixeScales',
    'table_name': 'patient_test_results', # for multi table synthesizers
    'constraint_parameters': {
        'segment_column_names': ['test_type'],
        'mixed_scale_column_name': 'test_results'
    }
}
```

</details>

<details>

<summary>Why can't I input the scale min and max for each segment?</summary>

In this constraint, you will only define the column names. SDV synthesizers will use this information to automatically learn the scales (min/max values and distribution) for each different segment of the real data. There is no need to manually input this data.

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sdv.dev/sdv/concepts/constraint-augmented-generation-cag/predefined-constraints/mixedscales.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
