Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,6 +48,112 @@ def pw_wavy_input(n,dim,n_bkps,sigma):
|
|
48 |
input_list = ['piecewiseConstant','piecewiseLinear','piecewiseNormal','piecewiseSinusoidal']
|
49 |
generate_signal = st.selectbox(label = "Choose an input signal", options = input_list)
|
50 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
|
52 |
|
53 |
|
|
|
48 |
input_list = ['piecewiseConstant','piecewiseLinear','piecewiseNormal','piecewiseSinusoidal']
|
49 |
generate_signal = st.selectbox(label = "Choose an input signal", options = input_list)
|
50 |
|
51 |
+
n,dim,n_bkps,sigma = st.columns(4)
|
52 |
+
with n:
|
53 |
+
n= st.number_input('No of Samples',min_value=100,step=1)
|
54 |
+
with dim:
|
55 |
+
dim = st.number_input('No of dimesions',min_value=1,max_value = 5,step=1)
|
56 |
+
with n_bkps:
|
57 |
+
n_bkps = st.number_input('No of breakpoints',min_value=2,step=1)
|
58 |
+
with sigma:
|
59 |
+
sigma = st.number_input('Variance',min_value=1,max_value=4,step=1)
|
60 |
+
|
61 |
+
if generate_signal == 'piecewiseConstant':
|
62 |
+
signal,bkps = pw_constant_input(n,dim,n_bkps,sigma)
|
63 |
+
elif generate_signal== 'piecewiseLinear':
|
64 |
+
signal,bkps = pw_linear_input(n,dim,n_bkps,sigma)
|
65 |
+
elif generate_signal == 'piecewiseNormal':
|
66 |
+
signal,bkps = pw_normal_input(n,dim,n_bkps,sigma)
|
67 |
+
else:
|
68 |
+
signal,bkps= pw_wavy_input(n,dim,n_bkps,sigma)
|
69 |
+
|
70 |
+
fig, axarr = rpt.display(signal,bkps)
|
71 |
+
st.pyplot(fig)
|
72 |
+
|
73 |
+
def dynp_method(signal,bkps,n_bkps):
|
74 |
+
# change point detection
|
75 |
+
model = "l1" # "l2", "rbf"
|
76 |
+
algo = rpt.Dynp(model=model, min_size=3, jump=5).fit(signal)
|
77 |
+
my_bkps = algo.predict(n_bkps)
|
78 |
+
# show results
|
79 |
+
fig,axarr = rpt.show.display(signal, bkps, my_bkps, figsize=(10, 6))
|
80 |
+
#plt.show()
|
81 |
+
st.pyplot(fig)
|
82 |
+
return my_bkps
|
83 |
+
|
84 |
+
def pelt_method(signal,bkps,n_bkps):
|
85 |
+
# change point detection
|
86 |
+
model = "l1" # "l2", "rbf"
|
87 |
+
algo = rpt.Pelt(model=model, min_size=3, jump=5).fit(signal)
|
88 |
+
my_bkps = algo.predict(pen=3)
|
89 |
+
|
90 |
+
# show results
|
91 |
+
fig, ax_arr = rpt.display(signal, bkps, my_bkps, figsize=(10, 6))
|
92 |
+
st.pyplot(fig)
|
93 |
+
return my_bkps
|
94 |
+
|
95 |
+
|
96 |
+
def bin_seg_method(signal,bkps,n_bkps):
|
97 |
+
# change point detection
|
98 |
+
model = "l2" # "l1", "rbf", "linear", "normal", "ar",...
|
99 |
+
algo = rpt.Binseg(model=model).fit(signal)
|
100 |
+
my_bkps = algo.predict(n_bkps)
|
101 |
+
|
102 |
+
# show results
|
103 |
+
fg,axxarr = rpt.show.display(signal, bkps, my_bkps, figsize=(10, 6))
|
104 |
+
st.pyplot(fig)
|
105 |
+
return my_bkps
|
106 |
+
|
107 |
+
def bot_up_seg(signal,bkps,n_bkps):
|
108 |
+
# change point detection
|
109 |
+
model = "l2" # "l1", "rbf", "linear", "normal", "ar",...
|
110 |
+
algo = rpt.Binseg(model=model).fit(signal)
|
111 |
+
my_bkps = algo.predict(n_bkps)
|
112 |
+
|
113 |
+
# show results
|
114 |
+
fig,axxar = rpt.show.display(signal, bkps, my_bkps, figsize=(10, 6))
|
115 |
+
st.pyplot(fig)
|
116 |
+
return my_bkps
|
117 |
+
|
118 |
+
def win_sli_seg(signal,bkps,n_bkps):
|
119 |
+
# change point detection
|
120 |
+
model = "l2" # "l1", "rbf", "linear", "normal", "ar"
|
121 |
+
algo = rpt.Window(width=40, model=model).fit(signal)
|
122 |
+
my_bkps = algo.predict(n_bkps)
|
123 |
+
|
124 |
+
# show results
|
125 |
+
fig,axxar= rpt.show.display(signal, bkps, my_bkps, figsize=(10, 6))
|
126 |
+
st.pyplot(fig)
|
127 |
+
return my_bkps
|
128 |
+
|
129 |
+
|
130 |
+
searchmethod_list = ['Dynamic Programming','Pelt','Binary Segmentation','Bottom-up Segmentation','Window sliding segmentation']
|
131 |
+
detection_model = st.selectbox(label = "Choose a Detection Method",options = searchmethod_list)
|
132 |
+
|
133 |
+
if detection_model== 'Dynamic Programming':
|
134 |
+
bkps1 = dynp_method(signal,bkps,n_bkps)
|
135 |
+
|
136 |
+
elif detection_model=='Pelt':
|
137 |
+
bkps1 = pelt_method(signal,bkps,n_bkps)
|
138 |
+
elif detection_model=='Binary Segmentation':
|
139 |
+
bkps1 = bin_seg_method(signal,bkps,n_bkps)
|
140 |
+
elif detection_model=='Bottom-up Segmentation':
|
141 |
+
bkps1 = bot_up_seg(signal,bkps,n_bkps)
|
142 |
+
else:
|
143 |
+
bkps1 = win_sli_seg(signal,bkps,n_bkps)
|
144 |
+
|
145 |
+
p, r = precision_recall(bkps, bkps1)
|
146 |
+
st.header('Precision and Recall')
|
147 |
+
st.write(p, r)
|
148 |
+
|
149 |
+
st.header('Hausdorff metric')
|
150 |
+
st.write(hausdorff(bkps, bkps1))
|
151 |
+
|
152 |
+
st.header('Rand index')
|
153 |
+
|
154 |
+
|
155 |
+
st.write(randindex(bkps, bkps1))
|
156 |
+
|
157 |
|
158 |
|
159 |
|