private void combox_filename_SelectedIndexChanged(object sender, EventArgs e) { var data_name = System.IO.Path.GetFileNameWithoutExtension(combox_filename.Text); var extension = System.IO.Path.GetExtension(combox_filename.Text); txt_data_to_calc_W.Text = data_name + "_W" + extension; txt_stream_data.Text = data_name + "_Stream" + extension; //set default value for period_max: List <double> data_to_calc_w = IOFuncs.readStreamFile(txt_data_to_calc_W.Text); txt_period_max.Text = (data_to_calc_w.Count() / 10).ToString(); switch (this.combox_filename.SelectedItem.ToString()) { case "ECG.txt": setValues("40", "5", "371", "0.001", "0.01", "0.95", "2", "25", "12", "10"); break; case "TEK16.txt": setValues("128", "5", "1007", "0.001", "0.01", "0.85", "2", "25", "12", "2"); break; case "power_data.txt": setValues("200", "4", "672", "0.05", "0.15", "0.85", "2", "25", "12", "5"); break; case "nprs43.txt": setValues("160", "3", "40", "0.05", "0.15", "0.85", "2", "25", "12", "75"); break; case "ERP.csv": setValues("64", "4", "1280", "0.001", "0.01", "0.95", "2", "25", "12", "2"); break; } }
private void btn_statistic_Click(object sender, EventArgs e) { string file_name = combox_filename.Text; string algorithm = combox_algorithm.Text; List <double> dist = null, loc = null; double time = 0; IOFuncs.readStatisticalFile(file_name, algorithm, ref dist, ref loc, ref time); Statistical_Form new_form = new Statistical_Form(algorithm, file_name, loc, dist, time); }
private void acf_function() { List <double> data_to_calc_w = IOFuncs.readStreamFile(txt_data_to_calc_W.Text); int data_len = data_to_calc_w.Count; int period_max = Convert.ToInt16(txt_period_max.Text); //normalize data: List <double> norm_data = MathFuncs.zScoreNorm(data_to_calc_w, data_len); ACF_Form form3 = new ACF_Form(this, norm_data, 1, period_max); //txt_period.Text = period.ToString(); }
private void btn_GetW_Click(object sender, EventArgs e) { int N_LENGTH = Convert.ToInt16(txt_NLength.Text); //todo /*Duc*/ //try //{ //read file List <double> stream_data; stream_data = IOFuncs.readStreamFile(txt_data_to_calc_W.Text); stream_data = MathFuncs.zScoreNorm(stream_data, stream_data.Count); //get threshold: double threshold = Convert.ToDouble(txt_threshold.Text); /*todo*/ int result = stream_data.Count; MinHeap <SegmentNode> segment_heap = null; BottomUp.Bottom_Up(stream_data, threshold, ref result, ref segment_heap); result = (int)(N_LENGTH / result); Segment_Form form2 = new Segment_Form(stream_data, segment_heap); //form2.Show(); /*show the result:*/ txt_WLength.Text = result.ToString(); Console.WriteLine("W_LENGTH = " + result); //} //catch //{ // MessageBox.Show("re-check the parameters !", "Error", MessageBoxButtons.OK); //} }
private void form_SAX_Load(object sender, EventArgs e) { string link = System.IO.Path.Combine(System.Environment.CurrentDirectory, @"Data\"); string[] fileArray = System.IO.Directory.GetFiles(@link); /*combox_filename*/ foreach (string file in fileArray) { this.combox_filename.Items.Add(System.IO.Path.GetFileName(file));//get all data filenames in the directory } string default_file = "ECG.txt"; var match = fileArray.FirstOrDefault(stringToCheck => stringToCheck.Contains(default_file)); if (match != null) { combox_filename.Text = default_file;// set default value for the combox } /*combox_algorithm*/ string[] algorithms = { "BFHS", "HOTSAX_Stream", "HOTSAX_Squeezer_Stream", "Bounding_Box", "Sanchez_Method" }; foreach (string algorithm in algorithms) { this.combox_algorithm.Items.Add(algorithm); } string default_algorithm = "HOTSAX_Squeezer_Stream"; match = algorithms.FirstOrDefault(stringToCheck => stringToCheck.Contains(default_algorithm)); if (match != null) { combox_algorithm.Text = default_algorithm;// set default value for the combox } //set default value for period_max: List <double> data_to_calc_w = IOFuncs.readStreamFile(txt_data_to_calc_W.Text); txt_period_max.Text = (data_to_calc_w.Count() / 10).ToString(); }
/*phase coherence analysis*/ private void phaseCoherenceFuntion() { Console.WriteLine("Running phaseCohenrence..."); System.Diagnostics.Stopwatch watch2;; ///calc execution time long elapsedMs2 = 0; watch2 = System.Diagnostics.Stopwatch.StartNew(); ///calc execution time List <double> std_list = new List <double>(); //store std(s) List <double> norm_data = new List <double>(); //data after normalizing all its subsets List <double> raw_data = IOFuncs.readStreamFile(txt_data_to_calc_W.Text); int data_len = raw_data.Count; int K_MAX = Convert.ToInt16(txt_period_max.Text); for (int k = 1; k <= K_MAX; k++)//do calc std for each value of 'k' { //reset variables: norm_data.Clear(); double[] sum_subsets = new double[k]; //store k sums double[] mean_subsets = new double[k]; //store k means int len_average_subset = data_len / k; int remainder_len_subset = data_len % k; /*calc mean for each subsets:*/ //find the sum(s): for (int j = 0; j < data_len; j++) { sum_subsets[j % k] += raw_data[j]; } //calc mean(s): for (int i = 0; i < k; i++) { if (i < remainder_len_subset) { mean_subsets[i] = sum_subsets[i] / (len_average_subset + 1); } else { mean_subsets[i] = sum_subsets[i] / len_average_subset; } } for (int i = 0; i < data_len; i++) { norm_data.Add(raw_data[i] - mean_subsets[i % k]); } //calc std then append it to std_list std_list.Add(MathFuncs.CalcStdMeanZero(norm_data)); }//end for double min = std_list.Min(); int period = std_list.FindIndex(n => Math.Abs(n - min) < 0.0000001); watch2.Stop(); elapsedMs2 = watch2.ElapsedMilliseconds; //print file to check: IOFuncs.WriteFile_2(std_list, "std_list.csv"); txt_period.Text = period.ToString(); Console.WriteLine("DONE CALC PERIOD_ REF 7, time = " + elapsedMs2 + "; period = " + period); }
/*Fig. 11 ('Luo_2011' paper): Estimating period with the median gap between two neighboring local minima*/ private void Luo_2011_Period() { //get max value for p, q: List <double> data_to_calc_w = IOFuncs.readStreamFile(txt_data_to_calc_W.Text); int data_len = data_to_calc_w.Count; int N_length = Convert.ToInt16(txt_NLength.Text); //normalize data: List <double> norm_data = MathFuncs.zScoreNorm(data_to_calc_w, data_len); //create a list to restore dists(p,q): List <double> dist_pq = new List <double>(); //calc collection of gaps delta for local minima of dist(p,q), here: // p is picked randomly // q = 0 to (bufer_len - N_length) //choose a random p: Random random_obj = new Random(); int p = random_obj.Next(data_len - N_length + 1); //get segment p: List <double> p_segment = norm_data.GetRange(p, N_length); //go through all q(s), compute dist(p,q) for every q: for (int q = 0; q <= (data_len - N_length); q++) { dist_pq.Add(MathFuncs.EuDistance(p_segment, norm_data.GetRange(q, N_length))); } /* Find the lower K_LOWER_PERCENT quantile of all distances calculated in the previous step.*/ int dist_pq_len = dist_pq.Count(); // WriteFile.WriteFile_2(dist_pq); // WriteFile.WriteFile_2(norm_data, "norm_data.csv"); int k_percent_index = (int)(dist_pq_len * K_LOWER_PERCENT); var sorted_dist_pq = dist_pq.OrderBy(n => n); //lower K_LOWER_PERCENT: double cp = sorted_dist_pq.ElementAt(k_percent_index); //get all local minima q such that dist(p, q) <= cp. List <int> Q = new List <int>();//store the result for (int q = 0; q < dist_pq_len; q++) { if (dist_pq[q] <= cp) { Q.Add(q); } } //Order Q list from smallest to largest: Q.Sort(); int Q_len = Q.Count; //calc lag 1 (delta): List <int> delta = new List <int>(); for (int k = 0; k < Q_len - 1; k++) { if (Q[k + 1] - Q[k] > 2) { delta.Add(Q[k + 1] - Q[k]); } } //sort delta: delta.Sort(); int median_index = delta.Count / 2; int delta_median = delta[median_index]; txt_period.Text = delta_median.ToString(); }
private void btn_Stream_Click(object sender, EventArgs e) { is_stream_clicked = true; //read file List <double> data_to_calc_w, stream_data; int buffer_len; data_to_calc_w = IOFuncs.readStreamFile(txt_data_to_calc_W.Text); //WriteFile.rewriteStreamFile(txt_stream_data.Text, 0, 100); stream_data = IOFuncs.readStreamFile(txt_stream_data.Text); //get N_LENGTH int N_LENGTH = Convert.ToInt16(txt_NLength.Text); int period = Convert.ToInt16(txt_period.Text); buffer_len = Convert.ToInt16(txt_bufferLength.Text) * period; // get W_LENGTH int W_LENGTH = Convert.ToInt16(txt_WLength.Text); // get Threshold Mean double threshold_mean = Convert.ToDouble(txt_threshold_mean.Text); // get Threshold Std double threshold_std = Convert.ToDouble(txt_threshold_std.Text); // get algorithm String algorithm = combox_algorithm.Text; // get Threshold Similarity double threshold_sim = Convert.ToDouble(txt_threshold_sim.Text); // get parameter for RTree int R = Convert.ToInt16(txtR.Text); int maxEntry = Convert.ToInt16(txtMaxEntry.Text); int minEntry = Convert.ToInt16(txtMinEntry.Text); // get file_name String file_name = combox_filename.Text; if (buffer_len > data_to_calc_w.Count) { MessageBox.Show("buffer must be smaller than data_to_calc_w !, please modify Buffer_length."); return; } //starting: Console.WriteLine("Running Stream HOTSAX...\n"); List <double> result = new List <double>(); //result[0]: dist //result[1]: loc //get the buffer: List <double> raw_buffer = data_to_calc_w.GetRange(data_to_calc_w.Count - buffer_len, buffer_len); //normalize buffer: List <double> norm_buffer = HOTSAX.HOTSAX.normalizeData(raw_buffer, buffer_len, N_LENGTH); if (algorithm == "Bounding_Box" || algorithm == "Sanchez_Method") { //SCALE: chart_timeSeries.ChartAreas[0].AxisY.Maximum = raw_buffer.Max() * SCALE; chart_timeSeries.ChartAreas[0].AxisY.Minimum = raw_buffer.Min() / SCALE; // turn the labels off: chart_timeSeries.ChartAreas["ChartArea1"].AxisX.LabelStyle.Enabled = false; //turn off X-axis labels chart_timeSeries.ChartAreas["ChartArea1"].AxisY.LabelStyle.Enabled = false; //turn off Y-axis labels } //updateChart(raw_buffer, (int)result[1], N_LENGTH); // create a new thread to run the chart: chart_thread = new Thread(() => this.doStream(file_name, algorithm, result, norm_buffer, data_to_calc_w, stream_data, N_LENGTH, W_LENGTH, raw_buffer, threshold_mean, threshold_std, threshold_sim, R, maxEntry, minEntry, period)); chart_thread.IsBackground = true; chart_thread.Start(); }