# 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.

***


---

# 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.sov.ai/api-reference/extensions/pairwise.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.
