import numpy as np import matplotlib.pylab as plt import ruptures as rpt import streamlit as st from ruptures.metrics import precision_recall from ruptures.metrics import hausdorff from ruptures.metrics import randindex st.title("Change Point Detection") # Generating Signal def pw_constant_input(n,dim,n_bkps,sigma): """Piecewise constant (pw_constant)""" # n, dim # number of samples, dimension # n_bkps, sigma # number of change points, noise standard deviation signal, bkps = rpt.pw_constant(n, dim, n_bkps, noise_std=sigma) rpt.display(signal, bkps) return signal,bkps def pw_linear_input(n,dim,n_bkps,sigma): """Piecewise Linear""" # creation of data # n, dim = 500, 3 # number of samples, dimension of the covariates # n_bkps, sigma = 3, 5 # number of change points, noise standart deviation signal, bkps = rpt.pw_linear(n, dim, n_bkps, noise_std=sigma) rpt.display(signal, bkps) return signal,bkps def pw_normal_input(n,dim,n_bkps,sigma): """Piecewise 2D Gaussian process (pw_normal)#""" # creation of data #n = 500 # number of samples #n_bkps = 3 # number of change points signal, bkps = rpt.pw_normal(n, n_bkps) rpt.display(signal, bkps) return signal,bkps def pw_wavy_input(n,dim,n_bkps,sigma): # creation of data #n, dim = 500, 3 # number of samples, dimension #n_bkps, sigma = 3, 5 # number of change points, noise standart deviation signal, bkps = rpt.pw_wavy(n, n_bkps, noise_std=sigma) rpt.display(signal, bkps) return signal,bkps input_list = ['piecewiseConstant','piecewiseLinear','piecewiseNormal','piecewiseSinusoidal'] generate_signal = st.selectbox(label = "Choose an input signal", options = input_list) n,dim,n_bkps,sigma = st.columns(4) with n: n= st.number_input('No of Samples',min_value=100,step=1) with dim: dim = st.number_input('No of dimesions',min_value=1,max_value = 5,step=1) with n_bkps: n_bkps = st.number_input('No of breakpoints',min_value=2,step=1) with sigma: sigma = st.number_input('Variance',min_value=1,max_value=4,step=1)