deepcharles / ruptures

ruptures: change point detection in Python
BSD 2-Clause "Simplified" License
1.54k stars 160 forks source link

Trying to add ruptures code #267

Closed waad876 closed 1 year ago

waad876 commented 1 year ago

I am trying to add the ruptures code but unfortunately i couldn't get any result.

here is the code :

@app.callback( dash.dependencies.Output(component_id='chart_1', component_property="figure"), [dash.dependencies.Input('btn-nclicks-1', 'n_clicks')], [dash.dependencies.State('drop_down_1', 'value')], [dash.dependencies.State('drop_down_2', 'value')], [dash.dependencies.State('drop_down_3', 'value')], [dash.dependencies.State('drop_down_4', 'value')], prevent_initial_call=True ) def update_valuesapp1(, regions, indicators, start_date, end_date): fig = go.Figure()

max_value_dict = dict()

if type(regions) == str:
    regions = [regions]

for region in regions:
    cd = global_df.loc[(global_df.loc[:, "country_region"] == region)]
    cd = cd.loc[((cd.loc[:, "date"] >= start_date) & (cd.loc[:, "date"] <= end_date))]
    x = cd["date"].values

    for iid, indicator in enumerate(indicators):
        y = cd[indicator].values
        notna_mask = ~np.isnan(y)

        if notna_mask.sum() == 0:
            max_value = 1
        else:
            max_value = max(abs(np.nanmax(y)), abs(np.nanmin(y)))

        if indicator not in max_value_dict:
            max_value_dict[indicator] = max_value
        else:
            max_value_dict[indicator] = max(max_value, max_value_dict[indicator])

        if iid == 0:
            fig = fig.add_trace(
                go.Scatter(x=x, y=y, mode='lines', name=region + " " + indicator,
                           line=dict(width=4)))
        else:
            fig = fig.add_trace(
                go.Scatter(x=x, y=y, mode='lines', name=region + " " + indicator, yaxis='y{}'.format(iid + 2),
                           line=dict(width=4)))

fig.update_layout(title="", xaxis_title="Date", yaxis_title="", legend_title="Indicators",
                  font=dict(family="Arial", size=20, color="dark blue"))

y_axis_label_width = 0.08

fig.update_layout(xaxis=dict(domain=[y_axis_label_width * (len(indicators) - 1), 1.0]))

for iid, indicator in enumerate(indicators):
    y_range = [-max_value_dict[indicator], max_value_dict[indicator]]
    if iid == 0:
        fig.update_layout({'yaxis': dict(title=indicator, constraintoward='center', position=0,
                                         range=y_range)})
    else:
        fig.update_layout({'yaxis{}'.format(iid + 2): dict(title=indicator, overlaying="y", side="left",
                                                           constraintoward='center', position=y_axis_label_width * iid,
                                                           range=y_range)})

fig.update_layout(legend=dict(font=dict(family="Arial", size=30, color="black")),
                  legend_title=dict(font=dict(family="Arial", size=35, color="blue")))
fig.update_layout(legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1))

fig.update_layout(margin=dict(t=250))
fig.update_layout(xaxis_tickangle=0)
fig.update_xaxes(showline=True, linewidth=2, linecolor='black')
fig.update_yaxes(showline=True, linewidth=2, linecolor='black')
fig.update_xaxes(zeroline=True, zerolinewidth=2, zerolinecolor='red')
fig.update_yaxes(zeroline=True, zerolinewidth=2, zerolinecolor='red')

return fig
deepcharles commented 1 year ago

Hi, please paste the error so that we can understand your problem. Also there is a lot of code not related to ruptures, can you please remove anything that is not related this library?

waad876 commented 1 year ago

Actually iam trying to add the ruptures to the code .. but there is no ruptures code on it

Regards

Get Outlook for iOShttps://aka.ms/o0ukef


From: Charles T. @.> Sent: Wednesday, October 5, 2022 11:42:41 AM To: deepcharles/ruptures @.> Cc: wadha @.>; Author @.> Subject: Re: [deepcharles/ruptures] Trying to add ruptures code (Issue #267)

Hi, please paste the error so that we can understand your problem. Also there is a lot of code not related to ruptures, can you please remove anything that is not related this library?

— Reply to this email directly, view it on GitHubhttps://github.com/deepcharles/ruptures/issues/267#issuecomment-1268068870, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AT2FJQ3UH2HKNIGZCEXB5VDWBUWPDANCNFSM6AAAAAAQ3YJMJQ. You are receiving this because you authored the thread.Message ID: @.***>

deepcharles commented 1 year ago

Ok. Can you give more details about what you are trying to achieve?

waad876 commented 1 year ago

I will tell you the important variables in the code : fig : is the figure i need to show cd : is saving excel file data like the one here https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fowid%2Fcovid-19-data%2Ftree%2Fmaster%2Fpublic%2Fdata&data=05%7C01%7C201802419%40uaeu.ac.ae%7C18714388a0c24849aa6008da91ea159e%7C97a92b044c8743419b08d8051ef8dce2%7C0%7C0%7C637982731846079860%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=jhiQTWsIo%2FmhC1yh%2FG3rXdiIz3ZhLic7qAKT6Jt3tB8%3D&reserved=0

Then after showing the data in the figure i need to show change points in the figure

Please find attached photo : it contains the summary ; the user will select country,indicator,start date , end date Then the signal will be shown with cahnge points if the ruptures code will be added

Best regards

Get Outlook for iOShttps://aka.ms/o0ukef


From: Charles T. @.> Sent: Wednesday, October 5, 2022 11:59:25 AM To: deepcharles/ruptures @.> Cc: wadha @.>; Author @.> Subject: Re: [deepcharles/ruptures] Trying to add ruptures code (Issue #267)

Ok. Can you give more details about what you are trying to achieve?

— Reply to this email directly, view it on GitHubhttps://github.com/deepcharles/ruptures/issues/267#issuecomment-1268083877, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AT2FJQ2R3WI35IGOIZO6J73WBUYN3ANCNFSM6AAAAAAQ3YJMJQ. You are receiving this because you authored the thread.Message ID: @.***>

deepcharles commented 1 year ago

Please look at the examples in the documentation to help you start with the code. The most simple example would be

# `signal` contains your signal
algo = rpt.Pelt(model="rbf").fit(signal)
result = algo.predict(pen=10)  # penalty of 10
# `result` is the list of changes
waad876 commented 1 year ago

Well received,thank You

Get Outlook for iOShttps://aka.ms/o0ukef


From: Charles T. @.> Sent: Thursday, October 6, 2022 9:56:21 AM To: deepcharles/ruptures @.> Cc: wadha @.>; Author @.> Subject: Re: [deepcharles/ruptures] Trying to add ruptures code (Issue #267)

Please look at the examples in the documentationhttps://centre-borelli.github.io/ruptures-docs/examples/introduction/ to help you start with the code. The most simple example would be

signal contains your signal

algo = rpt.Pelt(model="rbf").fit(signal) result = algo.predict(pen=10) # penalty of 10

result is the list of changes

— Reply to this email directly, view it on GitHubhttps://github.com/deepcharles/ruptures/issues/267#issuecomment-1269367277, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AT2FJQ2IYDDWRGD36BJACYDWBZSYLANCNFSM6AAAAAAQ3YJMJQ. You are receiving this because you authored the thread.Message ID: @.***>

deepcharles commented 1 year ago

Closing now. Feel free to reopen.