MCPcopy
hub / github.com/stumpy-dev/stumpy / mpdist_snippets

Function mpdist_snippets

tests/naive.py:1585–1664  ·  view source on GitHub ↗
(
    T,
    m,
    k,
    percentage=1.0,
    s=None,
    mpdist_percentage=0.05,
    mpdist_k=None,
    mpdist_T_subseq_isconstant=None,
)

Source from the content-addressed store, hash-verified

1583
1584
1585def mpdist_snippets(
1586 T,
1587 m,
1588 k,
1589 percentage=1.0,
1590 s=None,
1591 mpdist_percentage=0.05,
1592 mpdist_k=None,
1593 mpdist_T_subseq_isconstant=None,
1594):
1595 D = get_all_mpdist_profiles(
1596 T,
1597 m,
1598 percentage,
1599 s,
1600 mpdist_percentage,
1601 mpdist_k,
1602 mpdist_T_subseq_isconstant=mpdist_T_subseq_isconstant,
1603 )
1604
1605 snippets = np.empty((k, m))
1606 snippets_indices = np.empty(k, dtype=np.int64)
1607 snippets_profiles = np.empty((k, D.shape[-1]))
1608 snippets_fractions = np.empty(k)
1609 snippets_areas = np.empty(k)
1610 Q = np.inf
1611 indices = np.arange(0, D.shape[0] * m, m)
1612 snippets_regimes_list = []
1613
1614 for snippet_idx in range(k):
1615 min_area = np.inf
1616 for i in range(D.shape[0]):
1617 profile_area = np.sum(np.minimum(D[i], Q))
1618 if min_area > profile_area:
1619 min_area = profile_area
1620 idx = i
1621
1622 snippets[snippet_idx] = T[indices[idx] : indices[idx] + m]
1623 snippets_indices[snippet_idx] = indices[idx]
1624 snippets_profiles[snippet_idx] = D[idx]
1625 snippets_areas[snippet_idx] = np.sum(np.minimum(D[idx], Q))
1626
1627 Q = np.minimum(D[idx], Q)
1628
1629 total_min = np.min(snippets_profiles, axis=0)
1630
1631 for i in range(k):
1632 mask = snippets_profiles[i] <= total_min
1633 snippets_fractions[i] = np.sum(mask) / total_min.shape[0]
1634 total_min = total_min - mask.astype(float)
1635 slices = _get_mask_slices(mask)
1636 snippets_regimes_list.append(slices)
1637
1638 n_slices = []
1639 for regime in snippets_regimes_list:
1640 n_slices.append(regime.shape[0])
1641
1642 snippets_regimes = np.empty((sum(n_slices), 3), dtype=np.int64)

Callers

nothing calls this directly

Calls 2

get_all_mpdist_profilesFunction · 0.85
_get_mask_slicesFunction · 0.70

Tested by

no test coverage detected