---
sidebar:
  hidden: true
title: roboto.analytics.signal_similarity.match
---
## Module Contents

### Match

```python
class roboto.analytics.signal_similarity.match.Match
```

`from roboto.analytics import Match`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/analytics/signal_similarity/match.py#L108-L198)

Consecutive messages of a topic whose data is similar to a query.

[`find_similar_signals()`](/docs/reference/python-sdk/roboto/analytics/signal_similarity/signal_similarity#roboto.analytics.signal_similarity.signal_similarity.find_similar_signals) returns these. `start_idx` and `end_idx` count rows of the topic's data from 0, after rows with a missing or non-numeric value are dropped.

**Attributes**

- **Match.context** (`MatchContext`): Topic, message paths, dataset and file the match was found in.

- **Match.distance** (`float`): Distance between the query and the match. A smaller distance means a closer match.

  It is the Euclidean distance between the query and the match, summed over the message paths when the query has several. When [`find_similar_signals()`](/docs/reference/python-sdk/roboto/analytics/signal_similarity/signal_similarity#roboto.analytics.signal_similarity.signal_similarity.find_similar_signals) is called with `normalize=True`, each message path's values are first rescaled to a mean of 0 and a standard deviation of 1, so each message path adds at most `2·√N`, where `N` is the number of rows in the query.

  When it is called with `scale`, the query is resampled to `M` rows at each scale factor, and the distance is multiplied by `√N / √M`. This makes distances at different scale factors comparable with each other and with a search without `scale`, so a `max_distance` chosen for one kind of search works unchanged for the other.

- **Match.end_idx** (`int`): Position of the match's last row in the topic's data.

- **Match.end_time** (`pandas.Timestamp`): Timestamp of the match's last message, in UTC.

- **Match.scale** (`float`) = `1.0`: Scale factor at which the match was found, relative to the query's length.

  At `1.0` the match has as many rows as the query. Above `1.0` it has proportionally more (the motion happened more slowly than in the query), and below `1.0` proportionally fewer (more quickly). Always `1.0` when [`find_similar_signals()`](/docs/reference/python-sdk/roboto/analytics/signal_similarity/signal_similarity#roboto.analytics.signal_similarity.signal_similarity.find_similar_signals) is called without `scale`.

- **Match.start_idx** (`int`): Position of the match's first row in the topic's data.

- **Match.start_time** (`pandas.Timestamp`): Timestamp of the match's first message, in UTC.

- **Match.subsequence** (`pandas.DataFrame`): Rows of the topic's data from `start_idx` through `end_idx` inclusive, one column per message path.

  It is indexed by message timestamp, in UTC.

#### Match.to_event()

```python
def to_event(
    name: str = 'Signal Similarity Match Result',
    caller_org_id: Optional[str] = None,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
) -> roboto.domain.events.Event
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/analytics/signal_similarity/match.py#L157-L198)

Create an event on the match's topic that spans the match's first to last message.

The event's description is `"Match score: <distance>"`, and its metadata holds `distance`, `message_paths`, `start_index`, `end_index` and `scale`. Reading the event's data leaves out the match's last message, because a read of an event's data excludes its end time.

**Parameters**

- **name** (`str`): Human-readable name of the event.
- **caller_org_id** (`Optional[str]`): Organization to create the event in. Required when the caller belongs to more than one organization; otherwise the caller's only organization.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).

**Returns**

- `roboto.domain.events.Event`: The new event.

**Raises**

- [`RobotoInvalidRequestException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoInvalidRequestException): The match's topic no longer exists, or belongs to an organization other than the one the event is created in.

### MatchContext

```python
class roboto.analytics.signal_similarity.match.MatchContext
```

`from roboto.analytics import MatchContext`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/analytics/signal_similarity/match.py#L85-L104)

Topic, message paths, dataset and file a match was found in.

Carried in `Match.context`.

**Attributes**

- **MatchContext.dataset_id** (`str | None`) = `None`: ID of the dataset the topic or its file belongs to, or `None` if the topic belongs to neither.
- **MatchContext.file_id** (`str | None`) = `None`: ID of the file the topic belongs to, or `None` if the topic does not belong to a file.
- **MatchContext.message_paths** (`collections.abc.Sequence[str]`): Message paths whose data was compared with the query: the query's column names.
- **MatchContext.topic_id** (`str`): ID of the topic the match was found in.
- **MatchContext.topic_name** (`str`): Name of the topic the match was found in.

### Scale

```python
class roboto.analytics.signal_similarity.match.Scale
```

`from roboto.analytics import Scale`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/analytics/signal_similarity/match.py#L22-L81)

Range of time scales to search for a query at, so a motion is found whether it happens faster or slower.

Pass it as `scale` to [`find_similar_signals()`](/docs/reference/python-sdk/roboto/analytics/signal_similarity/signal_similarity#roboto.analytics.signal_similarity.signal_similarity.find_similar_signals), which resamples the query to the length each scale factor gives and searches at each length. A scale factor is relative to the query's length: at `2.0` the search looks for matches twice as long as the query (the motion happened at half the speed), and at `0.5` for matches half as long (twice the speed). A robot that lifts a cup in 1 second and one that lifts it in 3 seconds are then both found.

`Scale.any()` covers a wide range. Bounds that fit the motion, such as `Scale(min=0.5, max=3.0)` for one that can take from half to three times as long as in the query, place the scale factors closer together where matches are plausible and need fewer of them, so the search finds better matches with less computation.

**Raises**

- `ValueError`: `min` or `max` is not positive, `min` is greater than `max`, or `steps` is less than 1.

**Attributes**

- **Scale.max** (`float`): Largest scale factor to search at. Must be at least `min`.

- **Scale.min** (`float`): Smallest scale factor to search at. Must be positive.

- **Scale.spacing** (`Literal['log', 'linear']`) = `'log'`: How the scale factors are spread from `min` to `max`:

  - `"log"`: with an equal ratio between adjacent factors, so 0.5, 1 and 2 are evenly spaced. This suits speed ratios.
  - `"linear"`: with an equal difference between adjacent factors.

- **Scale.steps** (`int`) = `10`: Number of scale factors to search at, from `min` to `max` inclusive. Must be at least 1.

#### Scale.any()

```python
@classmethod
def any() -> Scale
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/analytics/signal_similarity/match.py#L65-L70)

Build a scale that searches at 30 scale factors from 0.1 to 10, log-spaced.

It finds matches from a tenth of the query's length to ten times its length.

**Returns**

- `Scale`

#### Scale.factors()

```python
def factors() -> list[float]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/analytics/signal_similarity/match.py#L72-L81)

Return the `steps` scale factors from `min` to `max` inclusive, spread as `spacing` sets.

**Raises**

- `ImportError`: The `roboto[analytics]` extra is not installed.

**Returns**

- `list[float]`
