Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
params (dict, optional): a dictionary of parameters for the cost instance.
Returns:
self
"""
self.min_size = min_size
self.jump = jump
self.width = 2 * (width // 2)
self.n_samples = None
self.signal = None
self.inds = None
if custom_cost is not None and isinstance(custom_cost, BaseCost):
self.cost = custom_cost
else:
if params is None:
self.cost = cost_factory(model=model)
else:
self.cost = cost_factory(model=model, **params)
self.score = list()
Returns:
self
"""
self.min_size = min_size
self.jump = jump
self.width = 2 * (width // 2)
self.n_samples = None
self.signal = None
self.inds = None
if custom_cost is not None and isinstance(custom_cost, BaseCost):
self.cost = custom_cost
else:
if params is None:
self.cost = cost_factory(model=model)
else:
self.cost = cost_factory(model=model, **params)
self.score = list()
def test_costs_5D_noisy(signal_bkps_5D_noisy, cost_name):
signal, bkps = signal_bkps_5D_noisy
cost = cost_factory(cost_name)
cost.fit(signal)
cost.error(0, 100)
cost.error(100, signal.shape[0])
cost.error(10, 50)
cost.sum_of_costs(bkps)
with pytest.raises(NotEnoughPoints):
cost.error(1, 2)
def test_costs_1D(signal_bkps_1D, cost_name):
signal, bkps = signal_bkps_1D
cost = cost_factory(cost_name)
cost.fit(signal)
cost.fit(signal.flatten())
cost.error(0, 100)
cost.error(100, signal.shape[0])
cost.error(10, 50)
cost.sum_of_costs(bkps)
with pytest.raises(NotEnoughPoints):
cost.error(1, 2)
def test_factory_exception():
with pytest.raises(ValueError):
cost_factory("bkd;s")
Args:
model (str, optional): segment model, ["l1", "l2", "rbf"]. Not used if ``'custom_cost'`` is not None.
custom_cost (BaseCost, optional): custom cost function. Defaults to None.
min_size (int, optional): minimum segment length.
jump (int, optional): subsample (one every *jump* points).
params (dict, optional): a dictionary of parameters for the cost instance.
Returns:
self
"""
if custom_cost is not None and isinstance(custom_cost, BaseCost):
self.cost = custom_cost
else:
if params is None:
self.cost = cost_factory(model=model)
else:
self.cost = cost_factory(model=model, **params)
self.min_size = max(min_size, self.cost.min_size)
self.jump = jump
self.n_samples = None
model (str, optional): segment model, ["l1", "l2", "rbf",...]. Not used if ``'custom_cost'`` is not None.
custom_cost (BaseCost, optional): custom cost function. Defaults to None.
min_size (int, optional): minimum segment length. Defaults to 2 samples.
jump (int, optional): subsample (one every *jump* points). Defaults to 5 samples.
params (dict, optional): a dictionary of parameters for the cost instance.
Returns:
self
"""
if custom_cost is not None and isinstance(custom_cost, BaseCost):
self.cost = custom_cost
else:
if params is None:
self.cost = cost_factory(model=model)
else:
self.cost = cost_factory(model=model, **params)
self.min_size = max(min_size, self.cost.min_size)
self.jump = jump
self.n_samples = None
self.signal = None
# cache for intermediate results
self.single_bkp = lru_cache(maxsize=None)(self._single_bkp)
min_size (int, optional): minimum segment length. Defaults to 2 samples.
jump (int, optional): subsample (one every *jump* points). Defaults to 5 samples.
params (dict, optional): a dictionary of parameters for the cost instance.
Returns:
self
"""
if custom_cost is not None and isinstance(custom_cost, BaseCost):
self.cost = custom_cost
else:
if params is None:
self.cost = cost_factory(model=model)
else:
self.cost = cost_factory(model=model, **params)
self.min_size = max(min_size, self.cost.min_size)
self.jump = jump
self.n_samples = None
self.signal = None
# cache for intermediate results
self.single_bkp = lru_cache(maxsize=None)(self._single_bkp)
custom_cost (BaseCost, optional): custom cost function. Defaults to None.
min_size (int, optional): minimum segment length.
jump (int, optional): subsample (one every *jump* points).
params (dict, optional): a dictionary of parameters for the cost instance.
Returns:
self
"""
self.seg = lru_cache(maxsize=None)(self._seg) # dynamic programming
if custom_cost is not None and isinstance(custom_cost, BaseCost):
self.cost = custom_cost
else:
if params is None:
self.cost = cost_factory(model=model)
else:
self.cost = cost_factory(model=model, **params)
self.min_size = max(min_size, self.cost.min_size)
self.jump = jump
self.n_samples = None
model (str, optional): segment model, ["l1", "l2", "rbf"]. Not used if ``'custom_cost'`` is not None.
custom_cost (BaseCost, optional): custom cost function. Defaults to None.
min_size (int, optional): minimum segment length. Defaults to 2 samples.
jump (int, optional): subsample (one every *jump* points). Defaults to 5 samples.
params (dict, optional): a dictionary of parameters for the cost instance.
Returns:
self
"""
if custom_cost is not None and isinstance(custom_cost, BaseCost):
self.cost = custom_cost
else:
if params is None:
self.cost = cost_factory(model=model)
else:
self.cost = cost_factory(model=model, **params)
self.min_size = max(min_size, self.cost.min_size)
self.jump = jump
self.n_samples = None
self.signal = None
self.leaves = None
self.merge = lru_cache(maxsize=None)(self._merge)