multidimensional data
waad876 opened this issue · 2 comments
waad876 commented
hello
I am wondering if the ruptures library is working with multidimensional data or not ??
please look into the uploaded image: I used ruptures in my code, and it's showing the change point lines like what is shown .
so if its working correctly with multidimensional data can you tell me how ??
regards
deepcharles commented
It does but it depends on the cost function that you used. Can you share the code that produced this image? (Only the part that does the change point detection.)
waad876 commented
I still didnt use cost functions its the basic code of fitting.
Here is the code
#my app
@app.callback(
dash.dependencies.Output(component_id='chart_5', component_property="figure"),
[dash.dependencies.Input('btn-nclicks-5', 'n_clicks')],
[dash.dependencies.State('drop_down_19', 'value')],
[dash.dependencies.State('drop_down_20', 'value')],
[dash.dependencies.State('drop_down_21', 'value')],
[dash.dependencies.State('drop_down_22', 'value')],
prevent_initial_call=True
)
def update_values_app5(_, 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))]
#cd=cd.dropna()
x = cd["date"].values
print(type(x))
print(x.shape)
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)))
#fig = px.line(df[mask], x="year", y="lifeExp", color='country')
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)))
print(type(y))
print(y.shape)
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')
print(y[7:])
algo = rpt.Pelt(model='l2').fit(y[7:])
result= algo.predict(pen=2000)#n_bkps=3,)
print(result)
fig.add_vline(x='2020-02-21',line_dash="dot")
for r in result:
fig.add_vline(x=x[r-1], line_width=3, line_dash="dash", line_color="green")
return fig
…________________________________
From: Charles T. ***@***.***>
Sent: Tuesday, November 15, 2022 6:38:25 PM
To: deepcharles/ruptures ***@***.***>
Cc: wadha ***@***.***>; Author ***@***.***>
Subject: Re: [deepcharles/ruptures] multidimensional data (Issue #277)
It does but it depends on the cost function that you used. Can you share the code that produced this image? (Only the part that does the change point detection.)
—
Reply to this email directly, view it on GitHub<#277 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AT2FJQ7LTDXTCYFSB76PS4DWION6DANCNFSM6AAAAAASA75UMA>.
You are receiving this because you authored the thread.Message ID: ***@***.***>