> For the complete documentation index, see [llms.txt](https://docs.sov.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sov.ai/api-reference/extensions/pairwise.md).

# Pairwise

**Module:** `sovai.extensions.pairwise`

## Functions

### `estimate_rank()`

```python
def estimate_rank(tensor_data, explained_var_threshold = 0.95)
```

Estimate rank for each mode based on explained variance.

**Parameters**

| Parameter                 | Type | Description     |
| ------------------------- | ---- | --------------- |
| `tensor_data`             | —    | —               |
| `explained_var_threshold` | —    | Default: `0.95` |

***

### `relative_distance_calc()`

```python
def relative_distance_calc(
    df_factors,
    orient = 'cross-sectional',
    on = 'date',
    distance = 'cosine',
    metric = 'pearson',
    calculations = ['mean'],
)
```

Calculates the relative distance matrix based on the initial distance calculation and then computes the bar S matrix.

**Parameters**

| Parameter      | Type | Description                                               |
| -------------- | ---- | --------------------------------------------------------- |
| `df_factors`   | —    | DataFrame containing the data.                            |
| `orient`       | —    | Orientation for the initial distance calculation.         |
| `on`           | —    | The level to group on ('ticker' or 'date').               |
| `distance`     | —    | The distance metric to use ('cosine', 'euclidean', etc.). |
| `metric`       | —    | The metric to use for time-series distance calculation.   |
| `calculations` | —    | List of calculations to perform in distance\_cross.       |

**Returns**

: DataFrame representing the normalized bar S matrix.

***
