Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'kernel_hyper' object has no attribute 'signal' #274

Closed
943fansi opened this issue Nov 6, 2022 · 6 comments
Closed

AttributeError: 'kernel_hyper' object has no attribute 'signal' #274

943fansi opened this issue Nov 6, 2022 · 6 comments

Comments

@943fansi
Copy link

943fansi commented Nov 6, 2022

import ruptures as rpt
print(rpt.__version__)

1.1.7

lst_cp_det = list(np.sort(cp_detector.predict(n_bkps=n_cp)))
ruptures\detection\dynp.py", line 132, in predict n_samples=self.cost.signal.shape[0],
AttributeError: 'kernel_hyper' object has no attribute 'signal'

@oboulant
Copy link
Collaborator

oboulant commented Nov 7, 2022

Hi @943fansi ,

Thx for your interest in ruptures !

Could you share with us the whole code snippet. Indeed, here we do not see how you created cp_detector . Please find some documentation on how to use Dynamic Programming search method that you seem to use.
has no attribute 'signal' also tells you that maybe you did not perform the .fit(signal) before calling predict().

Hope it helps !

@943fansi
Copy link
Author

943fansi commented Nov 7, 2022

Hi @943fansi ,

Thx for your interest in ruptures !

Could you share with us the whole code snippet. Indeed, here we do not see how you created cp_detector . Please find some documentation on how to use Dynamic Programming search method that you seem to use. has no attribute 'signal' also tells you that maybe you did not perform the .fit(signal) before calling predict().

Hope it helps !

I uninstalled 1.1.7 version, and installed version 1.0.3 ruptures. Then it works well.

# define and fit costum cost object
custom_cost = kernel_hyper(dct_config['kernel'], dct_config['bandwidth']).fit(ar_signal)

# define and fit search method
cp_detector = rpt.Dynp(custom_cost=custom_cost, jump=1).fit(ar_signal)

where
dct_config = dict({ # data intake settings
'load_sample_data': True, # True, False
'signal_id': 1, # 0,1,2,3,4,5,6,7,8,9,10

# kernel configuration for cost function
'kernel': 'laplace', # 'gaussian', 'linear', 'laplace'
'bandwidth': 'sig_std_batch_max', # 'median', 'sig_std',
# 'sig_std_batch_max'

# penalty heuristic configuration
'pen_heur': 'cost', # 'cost', 'slope'
'alpha': 150, # opt range cost_heur ~75-150 / slope_heur ~4-12
'n_cp_max': 10, # maximum number of cps considered
'D_max': 10, # max number of segments considered =<n_cp_max
`'D_min': 6}) # min number of segments for slope heuristics``

@oboulant
Copy link
Collaborator

oboulant commented Nov 7, 2022

Thx !

Btw, I forgot to paste the link to the documentation about Dynamic Programming : https://centre-borelli.github.io/ruptures-docs/user-guide/detection/dynp/

Now, about your code, in the implementation of the .fit() method of your custom cost kernel_hyper , do you have the instruction self.signal = signal (see here for examples ) ?

Moreover, you do not have to call custom_cost = kernel_hyper(dct_config['kernel'], dct_config['bandwidth']).fit(ar_signal) because when you call cp_detector = rpt.Dynp(custom_cost=custom_cost, jump=1).fit(ar_signal), then the .fit() call is forwarded to the cost class (see here in ruptures codebase).

@943fansi
Copy link
Author

943fansi commented Nov 7, 2022

Thx !

Btw, I forgot to paste the link to the documentation about Dynamic Programming : https://centre-borelli.github.io/ruptures-docs/user-guide/detection/dynp/

Now, about your code, in the implementation of the method of your custom cost , do you have the instruction (see here for examples ) ?.fit()``kernel_hyper ``self.signal = signal

Moreover, you do not have to call because when you call , then the call is forwarded to the cost class (see here in codebase).custom_cost = kernel_hyper(dct_config['kernel'], dct_config['bandwidth']).fit(ar_signal)``cp_detector = rpt.Dynp(custom_cost=custom_cost, jump=1).fit(ar_signal)``.fit()``ruptures

Thank you very much for your explanation. I am studying anomaly monitoring of time series. An application paper I found uses change point detection to make exception judgments, and its open-source code uses ruptures package. I'm a novice at change point detection, so I sincerely thank you again.

@oboulant
Copy link
Collaborator

oboulant commented Nov 7, 2022

In that case, @deepcharles 's article might be a good start : http://www.laurentoudre.fr/publis/TOG-SP-19.pdf
Basically, ruptures started as an implementation of this article !

@deepcharles
Copy link
Owner

Closing for now. Feel free to reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants