Replies: 2 comments
-
This is the answer I got from Olivier (@oboulant if you want to re-answer this here I'll delete this) Hi Rowan, Thanks a lot for your interest in ruptures ! Since this is a discussion rather than an issue, could you please move this to the discussion section ? I will answer here and close this issue in few days. I will also post the same answer in the discussion section if you create a new one. In order to illustrate/understand/showcase how this cost function can capture as well changes in the mean, let's take an example where only the mean signal changes, for instance : a 1D signal with 500 points No change point One change point, at an non-optimal position One change point, at optimal position Please, find below a code sample you can run to illustrate this 🔽
Hope I am clear enough and that you get the intuition behind it ? The logic is exactly the same for multidimensional signals and for several change points. Best, Olivier |
Beta Was this translation helpful? Give feedback.
-
[posting this in the discussion section, coming initially from an issue ] Hi Rowan, Thanks a lot for your interest in In order to illustrate/understand/showcase how this cost function can capture as well changes in the mean, let's take an example where only the mean signal changes, for instance :
We explore three scenarios :
Please, find below a code sample you can run to illustrate this 🔽 import numpy as np
import matplotlib.pylab as plt
import ruptures as rpt
n, dim = 500, 1 # number of samples, dimension
n_bkps, sigma = 1, 1 # number of change points, noise standart deviation
signal, bkps = rpt.pw_constant(n, dim, n_bkps, noise_std=sigma, delta=(4, 5), seed=1234)
# Create cost object
c = rpt.costs.CostNormal().fit(signal)
# No change point
print("No change points:")
print(f"\tTotal cost:\t{c.error(0, 500):.2f}")
figure, axs = rpt.display(signal, bkps)
figure.show()
# 1 change point, at an non-optimal position
print("One non-optimal change points:")
print(f"\tCost on segment 1:\t{c.error(0, 100):.2f}")
print(f"\tCost on segment 2:\t{c.error(100, 500):.2f}")
print(f"\tTotal cost:\t{c.sum_of_costs([100, 500]):.2f}")
figure, axs = rpt.display(signal, bkps, [100, 500])
figure.show()
# 1 change point, at the optimal position
print("One optimal change points:")
print(f"\tCost on segment 1:\t{c.error(0, bkps[0]):.2f}")
print(f"\tCost on segment 2:\t{c.error(bkps[0], 500):.2f}")
print(f"\tTotal cost:\t{c.sum_of_costs(bkps):.2f}")
figure, axs = rpt.display(signal, bkps, bkps)
figure.show() Hope I am clear enough and that you get the intuition behind it ? The logic is exactly the same for multidimensional signals and for several change points. Best, Olivier |
Beta Was this translation helpful? Give feedback.
-
Copied this from Issues as requested
Hi guys,
Love your work!
I'd just like to clarify something with the Normal cost function as mentioned in the User guide here
It says
"This cost function detects changes in the mean and covariance matrix of a sequence of multivariate Gaussian random variables"
But I can't see how the function detects changes in the mean?
This
cov = np.cov(sub.T)
_, val = slogdet(cov)
return val * (end - start)
Calculates the covariance and then its log.
I'm just wondering, where is the change in mean taken into account?
EDIT:
I can see Lavielle 2006 uses the same formula and mentions it detects changes in mean:
"For the detection of changes in the mean vector and/or the covariance matrix of a multivariate
sequence of random variables, this contrast also reduces to"
image
Thanks,
Rowan
Beta Was this translation helpful? Give feedback.
All reactions