public static string MakeSnaps(ref _song_profile sp, int _snapsize, int _snapcount, string _path, bool doConsecutive) { var SR = new SoundReader(); SR.OpenFile(_path); int samplesDesired = _snapsize; //Math.Max(_snapsize, 65536); sp.snap_size = _snapsize; sp.snap_count = _snapcount; sp.total_samples = SR.FR.Length; sp.length = SR.FR.TotalTime.Seconds; sp.path = _path; long blockscount = (long)(_snapcount * ((float)sp.total_samples / 50000000)); if (!SR.CheckFile()) { SR.CloseFile(); return "Wrong format"; } SR.CloseFile(); using (SR.FR = new Mp3FileReader(_path)) { for (int i = 0; i < blockscount; i++) { var data = SR.GetNextChunk(samplesDesired, SR.FR); double[] leftd = data[0]; double[] rightd = data[1]; //for (int j = 0; j < 1; j++) /////////// int seek_counter = 0; //seek: pcm.Seek((i + 1) * (i + 1) * (i + 1) * blockscount * samplesDesired % (total_samples - samplesDesired), SeekOrigin.Begin); seek: if (!doConsecutive) SR.SetPosition((long)(0.20 * sp.total_samples) + (long)(0.70 * sp.total_samples * i / blockscount)); else SR.SetPosition((long)(0.20 * sp.total_samples) + i * _snapsize); seek_counter++; if ((leftd.Max(t => Math.Abs(t)) == 0) && (rightd.Max(t => Math.Abs(t)) == 0)) if (seek_counter > 4) return "Too much silence"; else { blockscount++; i++; goto seek; } var pow_re_im = SoundProcessing.AmplitudeFromLR(_snapsize, leftd, rightd, 4.0, MWPreCalc); sp.fft_snaps.Add(pow_re_im); } SR.CloseFile(); } return "OK"; }
/*public List<double> MakeHistogram(_song_profile sp1, _song_profile sp2, double step) * { * var ans = new List<double>(); * var interm = new List<double>(); * * List<double> avg = new List<double>(), avg_smoothed = new List<double>(); * for (int i = 0; i < sp1.fft_smoothed_snaps.Count; i++) * { * avg_smoothed.Add(sp1.fft_smoothed_snaps[i].Average()); * } * * foreach (var i in sp1.fft_smoothed_snaps) * foreach (var j in sp2.fft_smoothed_snaps) * if (i.Count != j.Count) * return ans; * else * interm.Add(Correl(i, j)); * * for (double k = 0; k <= 1; k += step) * ans.Add((double)interm.Count(t => (t > k-step)&&(t <= k)) / (double)interm.Count); * * return ans; * }*/ public double HistogramConv(_song_profile sp1, _song_profile sp2, double step) { var ans = new List <double>(); var interm = new List <double>(); List <double> avg1_smoothed = new List <double>(), avg2_smoothed = new List <double>(); for (int i = 0; i < sp1.fft_smoothed_snaps.Count; i++) { avg1_smoothed.Add(sp1.fft_smoothed_snaps[i].Average()); avg2_smoothed.Add(sp2.fft_smoothed_snaps[i].Average()); } for (int i = 0; i < sp1.fft_smoothed_snaps.Count; i++) //in sp1.fft_smoothed_snaps) { for (int j = 0; j < sp2.fft_smoothed_snaps.Count; j++) //foreach (var j in sp2.fft_smoothed_snaps) { interm.Add(Correl(sp1.fft_smoothed_snaps[i], sp2.fft_smoothed_snaps[j], avg1_smoothed[i], avg2_smoothed[j])); } } for (double k = -1; k <= 1; k += step) { ans.Add((double)interm.Count(t => (t > k - step) && (t <= k)) / (double)interm.Count); } double s = 0; for (int i = 0; i < ans.Count; i++) { s += ans[i] * ((double)(i) - 1 / step); } return(s * step); }
public Dictionary<string, double> CalcAllStats(_song_profile itm) { var ans = new Dictionary<string, double>(); //ans.Add("a_mean_ASC", itm.snap_correls.Average()); //ans.Add("a_stdev_ASC", StDev(itm.snap_correls)); //ans.Add("a_skewn_ASC", Skewness(itm.snap_correls)); //ans.Add("a_kurto_ASC", Kurtosis(itm.snap_correls)); //ans.Add("a_median_ASC", Median(itm.snap_correls)); //ans.Add("mean_ASSC", itm.snap_smoothed_correls.Average()); //ans.Add("stdev_ASSC", StDev(itm.snap_smoothed_correls)); //ans.Add("skewn_ASSC", Skewness(itm.snap_smoothed_correls)); //ans.Add("kurto_ASSC", Kurtosis(itm.snap_smoothed_correls)); //ans.Add("median_ASSC", Median(itm.snap_smoothed_correls)); //ans.Add("a_mean_ED", itm.snap_log10_energy.Average()); //ans.Add("a_stdev_ED", StDev(itm.snap_log10_energy)); //ans.Add("a_skewn_ED", Skewness(itm.snap_log10_energy)); //ans.Add("a_kurto_ED", Kurtosis(itm.snap_log10_energy)); //ans.Add("a_median_ED", Median(itm.snap_log10_energy)); if (itm.fft_downscaled_snaps[0].Count > 5) { for (int i = 1; i < itm.fft_downscaled_snaps[0].Count / 2; i++) { string a = Appdx(i, itm.fft_downscaled_snaps[0].Count); var aa = new List<double>(); for (int j = 0; j < itm.fft_downscaled_snaps.Count; j++) { aa.Add(itm.fft_downscaled_snaps[j][i]); } ans.Add("b_mean_FFT1_" + a, aa.Average()); ans.Add("b_stdev_FFT1_" + a, StDev(aa)); ans.Add("b_skewn_FFT1_" + a, Skewness(aa)); ans.Add("b_kurto_FFT1_" + a, Kurtosis(aa)); ans.Add("b_median_FFT1_" + a, Median(aa)); } /* for (int i = 0; i < itm.fft2_downscaled_snaps[0].Count / 2; i++) { double v = 0; string a = Appdx(i, itm.fft2_downscaled_snaps[0].Count); for (int j = 0; j < itm.fft2_downscaled_snaps.Count; j++) v += itm.fft2_downscaled_snaps[j][i]; ans.Add("mean_FFT2_" + a, v / itm.fft2_downscaled_snaps.Count); } */ } return ans; }
public Dictionary <string, double> CalcAllStats(_song_profile itm) { var ans = new Dictionary <string, double>(); //ans.Add("a_mean_ASC", itm.snap_correls.Average()); //ans.Add("a_stdev_ASC", StDev(itm.snap_correls)); //ans.Add("a_skewn_ASC", Skewness(itm.snap_correls)); //ans.Add("a_kurto_ASC", Kurtosis(itm.snap_correls)); //ans.Add("a_median_ASC", Median(itm.snap_correls)); //ans.Add("mean_ASSC", itm.snap_smoothed_correls.Average()); //ans.Add("stdev_ASSC", StDev(itm.snap_smoothed_correls)); //ans.Add("skewn_ASSC", Skewness(itm.snap_smoothed_correls)); //ans.Add("kurto_ASSC", Kurtosis(itm.snap_smoothed_correls)); //ans.Add("median_ASSC", Median(itm.snap_smoothed_correls)); //ans.Add("a_mean_ED", itm.snap_log10_energy.Average()); //ans.Add("a_stdev_ED", StDev(itm.snap_log10_energy)); //ans.Add("a_skewn_ED", Skewness(itm.snap_log10_energy)); //ans.Add("a_kurto_ED", Kurtosis(itm.snap_log10_energy)); //ans.Add("a_median_ED", Median(itm.snap_log10_energy)); if (itm.fft_downscaled_snaps[0].Count > 5) { for (int i = 1; i < itm.fft_downscaled_snaps[0].Count / 2; i++) { string a = Appdx(i, itm.fft_downscaled_snaps[0].Count); var aa = new List <double>(); for (int j = 0; j < itm.fft_downscaled_snaps.Count; j++) { aa.Add(itm.fft_downscaled_snaps[j][i]); } ans.Add("b_mean_FFT1_" + a, aa.Average()); ans.Add("b_stdev_FFT1_" + a, StDev(aa)); ans.Add("b_skewn_FFT1_" + a, Skewness(aa)); ans.Add("b_kurto_FFT1_" + a, Kurtosis(aa)); ans.Add("b_median_FFT1_" + a, Median(aa)); } /* * for (int i = 0; i < itm.fft2_downscaled_snaps[0].Count / 2; i++) * { * double v = 0; * string a = Appdx(i, itm.fft2_downscaled_snaps[0].Count); * for (int j = 0; j < itm.fft2_downscaled_snaps.Count; j++) * v += itm.fft2_downscaled_snaps[j][i]; * ans.Add("mean_FFT2_" + a, v / itm.fft2_downscaled_snaps.Count); * } */ } return(ans); }
private void button1_Click(object sender, EventArgs e) { listBox1.Items.Clear(); var itm = new _song_profile("", ""); itm.MakeSnaps((int)nUD2.Value, (int)nUD.Value, @"mp3\\diskord.mp3", (int)nUD3.Value); itm.CalcInternalCorrels(); var itm2 = new _song_profile("", ""); itm2.MakeSnaps((int)nUD2.Value, (int)nUD.Value, @"mp3\\diskord2.mp3", (int)nUD3.Value); itm2.CalcInternalCorrels(); itm.snap_log10_energy = Normalize(itm.snap_log10_energy); itm2.snap_log10_energy = Normalize(itm2.snap_log10_energy); listBox1.Items.Add("convoluted histogram value = " + HistogramConv(itm, itm2, 0.001)); }
private void button3_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure want to (re)create the database?", "Question", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) return; listBox1.Items.Clear(); var fll = MakeFilesList(@textBox1.Text); var fl = fll.OrderBy(t => Path.GetFileName(t).Length.ToString()).ToList(); listBox1.Items.Add("Found files: " + fl.Count); var db = new SQLiteConnection(); var cmd = db.CreateCommand(); try { db.ConnectionString = "Data Source=test.db;"; db.Open(); //cmd.CommandText = "DROP TABLE IF EXISTS MAIN;"; cmd.ExecuteNonQuery(); //cmd.CommandText = "DROP TABLE IF EXISTS STATS;"; cmd.ExecuteNonQuery(); cmd.CommandText = "CREATE TABLE MAIN (id int, name string, path string);"; cmd.ExecuteNonQuery(); cmd.CommandText = "CREATE TABLE STATS (id int, statname string, statparam1 int, statparam2 int, statvalue float);"; cmd.ExecuteNonQuery(); } catch { MessageBox.Show("Something has gone wrong with the database"); } SQLiteParameter myparam1 = new SQLiteParameter(); SQLiteParameter myparam2 = new SQLiteParameter(); SQLiteParameter myparam3 = new SQLiteParameter(); SQLiteParameter myparam2_1 = new SQLiteParameter(); SQLiteParameter myparam2_2 = new SQLiteParameter(); SQLiteParameter myparam2_3 = new SQLiteParameter(); SQLiteParameter myparam2_4 = new SQLiteParameter(); SQLiteParameter myparam2_5 = new SQLiteParameter(); List<_song_profile> splist = new List<_song_profile>(); int s_count = 0; PB1.Maximum = fl.Count; PB1.Minimum = 0; foreach (var f in fl) { //var transaction = db.BeginTransaction(); try { if (s_count % 50 == 0) { listBox1.Items.Clear(); listBox1.Items.Add("Items done: " + s_count + " of " + fl.Count); } var itm = new _song_profile(Path.GetFileName(f), f); if (!itm.MakeSnaps((int)nUD2.Value, (int)nUD.Value, f, (int)nUD3.Value)) { listBox1.Items.Add("![" + s_count + "]! Cannot make snapshots for " + itm.path); s_count++; continue; } //itm.CalcInternalCorrels(); itm.MakeDownscaledSnaps((int)nUD4.Value); //itm.MakeDownscaledSnaps2((int)nUD4.Value); var d = CalcAllStats(itm); listBox1.Items.Add("[" + s_count + "] " + Path.GetFileName(itm.path)); cmd.CommandText = "BEGIN TRANSACTION;"; cmd.ExecuteNonQuery(); foreach (var di in d) { cmd.CommandText = "INSERT INTO STATS VALUES (@id, @statname, @statparam1, @statparam2, @statvalue);"; myparam2_1.ParameterName = "@id"; myparam2_2.ParameterName = "@statname"; myparam2_3.ParameterName = "@statparam1"; myparam2_4.ParameterName = "@statparam2"; myparam2_5.ParameterName = "@statvalue"; myparam2_1.Value = s_count; myparam2_2.Value = di.Key; myparam2_3.Value = 0; myparam2_4.Value = 0; myparam2_5.Value = di.Value; cmd.Parameters.Add(myparam2_1); cmd.Parameters.Add(myparam2_2); cmd.Parameters.Add(myparam2_3); cmd.Parameters.Add(myparam2_4); cmd.Parameters.Add(myparam2_5); cmd.ExecuteNonQuery(); } //splist.Add(itm); cmd.CommandText = "INSERT INTO MAIN VALUES (@id, @name, @path);"; myparam1.ParameterName = "@id"; myparam2.ParameterName = "@name"; myparam3.ParameterName = "@path"; myparam1.Value = s_count; myparam2.Value = itm.name; myparam3.Value = itm.path; cmd.Parameters.Add(myparam1); cmd.Parameters.Add(myparam2); cmd.Parameters.Add(myparam3); cmd.ExecuteNonQuery(); PB1.Value = s_count; Application.DoEvents(); //transaction.Commit(); cmd.CommandText = "COMMIT;"; cmd.ExecuteNonQuery(); s_count++; } catch { continue; } } db.Close(); DBPostProcess("test.db"); /* var dct = new Dictionary<string, double>(); for (int i = 0; i < splist.Count; i++) { dct.Add(splist[i].path, VecDiff(splist[0].scalar_stats.Values.ToList(), splist[i].scalar_stats.Values.ToList())); } dct.OrderBy(t => t.Value); dct.ToList().OrderBy(t => t.Value).ToList().ForEach(t => listBox1.Items.Add(t.Key + " ---> [" + t.Value + "]")); */ /************************************************************************* k-means++ clusterization INPUT PARAMETERS: XY - dataset, array [0..NPoints-1,0..NVars-1]. NPoints - dataset size, NPoints>=K NVars - number of variables, NVars>=1 K - desired number of clusters, K>=1 Restarts - number of restarts, Restarts>=1 OUTPUT PARAMETERS: Info - return code: * -3, if task is degenerate (number of distinct points is less than K) * -1, if incorrect NPoints/NFeatures/K/Restarts was passed * 1, if subroutine finished successfully C - array[0..NVars-1,0..K-1].matrix whose columns store cluster's centers XYC - array[NPoints], which contains cluster indexes *************************************************************************/ /* int NPoints = splist.Count; int NVars = splist[0].scalar_stats.Count; int K = (int)Math.Sqrt(NPoints); int Restarts = 5; int Info = 0; var C = new double[NVars, K]; var XYC = new int[NPoints]; var XY = new double[NPoints, NVars]; var _XY = splist[0].scalar_stats.Values.ToArray(); for (int i = 0; i < NPoints; i++) for (int j = 0; j < NVars; j++) XY[i, j] = splist[i].scalar_stats.Values.ToArray()[j]; alglib.kmeansgenerate( XY, NPoints, NVars, K, Restarts, out Info, out C, out XYC); Info++; Application.DoEvents(); for (int i = 0; i < splist.Count; i++) { listBox1.Items.Add(Path.GetFileName(splist[i].path) + " -> cluster # " + XYC[i]); } */ /*foreach (var itm in splist) { var s1 = new List<double>(); var s2 = new List<double>(); var s3 = new List<double>(); foreach (var itm2 in splist) { /*listBox1.Items.Add(Path.GetFileName(itm.path) + " vs " + Path.GetFileName(itm2.path) + "cross_energy_correl = " + Correl(itm.snap_log10_energy, itm2.snap_log10_energy, itm.snap_log10_energy.Average(), itm2.snap_log10_energy.Average()) + " " + "cross_energy_diff = " + VecDiff(itm.snap_log10_energy, itm2.snap_log10_energy) + " " + "convoluted histogram value = " + HistogramConv(itm, itm2, 0.001) );*/ //s1.Add(Correl(itm.snap_log10_energy, itm2.snap_log10_energy, itm.snap_log10_energy.Average(), itm2.snap_log10_energy.Average())); //s2.Add(1 / Math.Log10(VecDiff(itm.snap_log10_energy, itm2.snap_log10_energy))); //s3.Add(HistogramConv(itm, itm2, 0.001)); /*s1.Add(0); s2.Add(0); s3.Add(0); } sp_CED.Add(s1); sp_CEC.Add(s2); sp_CHV.Add(s3); }*/ /*List<double> likelihood = new List<double>(); for (int i = 0; i < splist.Count; i++) { double lh = 0; //listBox1.Items.Add(Path.GetFileName(splist[i].path) + ": " + (int)(100*sp_ASC[i]) + " " + (int)(100*sp_ASSC[i]) + " " + (int)(10*sp_ED[i])); for (int j = 0; j < splist.Count; j++) { lh = sp_ASC[i] * sp_ASC[j] + sp_ASSC[i] * sp_ASSC[j] + sp_ED[i] * sp_ED[j] + sp_CED[i][j] + sp_CEC[i][j] + sp_CHV[i][j] ; likelihood.Add(lh); listBox1.Items.Add((int)(100*lh) + " : " + Path.GetFileName(splist[i].path) + " " + Path.GetFileName(splist[j].path)); } //listBox1.Items.Add("----->" + (int)(100*sp_CED[i][j]) + " " + (int)(100*sp_CEC[i][j]) + " " + (int)(100*sp_CHV[i][j]) + "; " + Path.GetFileName(splist[j].path)); }*/ }
/*public List<double> MakeHistogram(_song_profile sp1, _song_profile sp2, double step) { var ans = new List<double>(); var interm = new List<double>(); List<double> avg = new List<double>(), avg_smoothed = new List<double>(); for (int i = 0; i < sp1.fft_smoothed_snaps.Count; i++) { avg_smoothed.Add(sp1.fft_smoothed_snaps[i].Average()); } foreach (var i in sp1.fft_smoothed_snaps) foreach (var j in sp2.fft_smoothed_snaps) if (i.Count != j.Count) return ans; else interm.Add(Correl(i, j)); for (double k = 0; k <= 1; k += step) ans.Add((double)interm.Count(t => (t > k-step)&&(t <= k)) / (double)interm.Count); return ans; }*/ public double HistogramConv(_song_profile sp1, _song_profile sp2, double step) { var ans = new List<double>(); var interm = new List<double>(); List<double> avg1_smoothed = new List<double>(), avg2_smoothed = new List<double>(); for (int i = 0; i < sp1.fft_smoothed_snaps.Count; i++) { avg1_smoothed.Add(sp1.fft_smoothed_snaps[i].Average()); avg2_smoothed.Add(sp2.fft_smoothed_snaps[i].Average()); } for (int i = 0; i < sp1.fft_smoothed_snaps.Count; i++)//in sp1.fft_smoothed_snaps) for (int j = 0; j < sp2.fft_smoothed_snaps.Count; j++) //foreach (var j in sp2.fft_smoothed_snaps) interm.Add(Correl(sp1.fft_smoothed_snaps[i], sp2.fft_smoothed_snaps[j], avg1_smoothed[i], avg2_smoothed[j])); for (double k = -1; k <= 1; k += step) ans.Add((double)interm.Count(t => (t > k-step)&&(t <= k)) / (double)interm.Count); double s = 0; for (int i = 0; i < ans.Count; i++) s += ans[i] * ((double)(i) - 1/step); return s*step; }
public static string MakeSnaps2(ref _song_profile sp, int _snapsize, int _snapcount, string _path, int overlap = 2, double lowpass = 4.0, bool fullnormalize = false) { var SR = new SoundReader(); var result = SR.OpenFile(_path); if (result != "OK") return result; int samplesDesired = _snapsize; sp.snap_size = _snapsize; sp.snap_count = _snapcount; sp.total_samples = SR.FR.Length; sp.length = SR.FR.TotalTime.Seconds; sp.path = _path; int blockscount = (int)(_snapcount * ((float)sp.total_samples / (4 * 5 * 60 * 44100))); // 5 minutes song equivalent blockscount = Math.Min(blockscount, 5 * 60 * 44100 / _snapsize); // haircut to 5 minutes long (maximum) blockscount = Math.Min(blockscount, (int)(0.8 * _snapcount * ((float)sp.total_samples / (4 * 5 * 60 * 44100)))); // haircut to no more than 80% of song if (!SR.CheckFile()) { SR.CloseFile(); return "Wrong format"; } SR.CloseFile(); using (SR.FR = new Mp3FileReader(_path)) { SR.SetPosition((long)(0.20 * sp.total_samples)); double[][] alldata; try { alldata = SR.GetNextChunk(samplesDesired * blockscount, SR.FR, fullnormalize); } catch (Exception E) { return E.Message; } for (int i = 0; i < (blockscount - 1) * overlap; i++) { double[] leftd = alldata[0]; double[] rightd = leftd; var pow_re_im = SoundProcessing.AmplitudeFromLR2(_snapsize, leftd, Math.Max((int)(i * samplesDesired / overlap)-1, 0), samplesDesired, lowpass, MWPreCalc); sp.fft_snaps.Add(pow_re_im); } SR.CloseFile(); } return "OK"; }
public static string MakePCASnaps(ref _song_profile sp, ref List<List<double>> vmatrix) { sp.pca_snaps = ClusterAnalysis.PCAGetNewSpace(ref sp.fft_snaps, ref vmatrix, vmatrix.Count); sp.fft_snaps = sp.pca_snaps; return "OK"; }
private void button3_Click(object sender, EventArgs e) { if (MessageBox.Show("Are you sure want to (re)create the database?", "Question", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No) { return; } listBox1.Items.Clear(); var fll = MakeFilesList(@textBox1.Text); var fl = fll.OrderBy(t => Path.GetFileName(t).Length.ToString()).ToList(); listBox1.Items.Add("Found files: " + fl.Count); var db = new SQLiteConnection(); var cmd = db.CreateCommand(); try { db.ConnectionString = "Data Source=test.db;"; db.Open(); //cmd.CommandText = "DROP TABLE IF EXISTS MAIN;"; cmd.ExecuteNonQuery(); //cmd.CommandText = "DROP TABLE IF EXISTS STATS;"; cmd.ExecuteNonQuery(); cmd.CommandText = "CREATE TABLE MAIN (id int, name string, path string);"; cmd.ExecuteNonQuery(); cmd.CommandText = "CREATE TABLE STATS (id int, statname string, statparam1 int, statparam2 int, statvalue float);"; cmd.ExecuteNonQuery(); } catch { MessageBox.Show("Something has gone wrong with the database"); } SQLiteParameter myparam1 = new SQLiteParameter(); SQLiteParameter myparam2 = new SQLiteParameter(); SQLiteParameter myparam3 = new SQLiteParameter(); SQLiteParameter myparam2_1 = new SQLiteParameter(); SQLiteParameter myparam2_2 = new SQLiteParameter(); SQLiteParameter myparam2_3 = new SQLiteParameter(); SQLiteParameter myparam2_4 = new SQLiteParameter(); SQLiteParameter myparam2_5 = new SQLiteParameter(); List <_song_profile> splist = new List <_song_profile>(); int s_count = 0; PB1.Maximum = fl.Count; PB1.Minimum = 0; foreach (var f in fl) { //var transaction = db.BeginTransaction(); try { if (s_count % 50 == 0) { listBox1.Items.Clear(); listBox1.Items.Add("Items done: " + s_count + " of " + fl.Count); } var itm = new _song_profile(Path.GetFileName(f), f); if (!itm.MakeSnaps((int)nUD2.Value, (int)nUD.Value, f, (int)nUD3.Value)) { listBox1.Items.Add("![" + s_count + "]! Cannot make snapshots for " + itm.path); s_count++; continue; } //itm.CalcInternalCorrels(); itm.MakeDownscaledSnaps((int)nUD4.Value); //itm.MakeDownscaledSnaps2((int)nUD4.Value); var d = CalcAllStats(itm); listBox1.Items.Add("[" + s_count + "] " + Path.GetFileName(itm.path)); cmd.CommandText = "BEGIN TRANSACTION;"; cmd.ExecuteNonQuery(); foreach (var di in d) { cmd.CommandText = "INSERT INTO STATS VALUES (@id, @statname, @statparam1, @statparam2, @statvalue);"; myparam2_1.ParameterName = "@id"; myparam2_2.ParameterName = "@statname"; myparam2_3.ParameterName = "@statparam1"; myparam2_4.ParameterName = "@statparam2"; myparam2_5.ParameterName = "@statvalue"; myparam2_1.Value = s_count; myparam2_2.Value = di.Key; myparam2_3.Value = 0; myparam2_4.Value = 0; myparam2_5.Value = di.Value; cmd.Parameters.Add(myparam2_1); cmd.Parameters.Add(myparam2_2); cmd.Parameters.Add(myparam2_3); cmd.Parameters.Add(myparam2_4); cmd.Parameters.Add(myparam2_5); cmd.ExecuteNonQuery(); } //splist.Add(itm); cmd.CommandText = "INSERT INTO MAIN VALUES (@id, @name, @path);"; myparam1.ParameterName = "@id"; myparam2.ParameterName = "@name"; myparam3.ParameterName = "@path"; myparam1.Value = s_count; myparam2.Value = itm.name; myparam3.Value = itm.path; cmd.Parameters.Add(myparam1); cmd.Parameters.Add(myparam2); cmd.Parameters.Add(myparam3); cmd.ExecuteNonQuery(); PB1.Value = s_count; Application.DoEvents(); //transaction.Commit(); cmd.CommandText = "COMMIT;"; cmd.ExecuteNonQuery(); s_count++; } catch { continue; } } db.Close(); DBPostProcess("test.db"); /* * var dct = new Dictionary<string, double>(); * * for (int i = 0; i < splist.Count; i++) * { * dct.Add(splist[i].path, VecDiff(splist[0].scalar_stats.Values.ToList(), splist[i].scalar_stats.Values.ToList())); * } * * dct.OrderBy(t => t.Value); * * dct.ToList().OrderBy(t => t.Value).ToList().ForEach(t => listBox1.Items.Add(t.Key + " ---> [" + t.Value + "]")); */ /************************************************************************* * k-means++ clusterization * INPUT PARAMETERS: * XY - dataset, array [0..NPoints-1,0..NVars-1]. * NPoints - dataset size, NPoints>=K * NVars - number of variables, NVars>=1 * K - desired number of clusters, K>=1 * Restarts - number of restarts, Restarts>=1 * * OUTPUT PARAMETERS: * Info - return code: * -3, if task is degenerate (number of distinct points is * less than K) * -1, if incorrect NPoints/NFeatures/K/Restarts was passed * 1, if subroutine finished successfully * C - array[0..NVars-1,0..K-1].matrix whose columns store * cluster's centers * XYC - array[NPoints], which contains cluster indexes *************************************************************************/ /* * int NPoints = splist.Count; * int NVars = splist[0].scalar_stats.Count; * int K = (int)Math.Sqrt(NPoints); * int Restarts = 5; * int Info = 0; * * var C = new double[NVars, K]; * var XYC = new int[NPoints]; * var XY = new double[NPoints, NVars]; * * var _XY = splist[0].scalar_stats.Values.ToArray(); * for (int i = 0; i < NPoints; i++) * for (int j = 0; j < NVars; j++) * XY[i, j] = splist[i].scalar_stats.Values.ToArray()[j]; * * alglib.kmeansgenerate( * XY, * NPoints, * NVars, * K, * Restarts, * out Info, * out C, * out XYC); * * Info++; * * Application.DoEvents(); * * for (int i = 0; i < splist.Count; i++) * { * listBox1.Items.Add(Path.GetFileName(splist[i].path) + " -> cluster # " + XYC[i]); * } */ /*foreach (var itm in splist) * { * var s1 = new List<double>(); * var s2 = new List<double>(); * var s3 = new List<double>(); * * foreach (var itm2 in splist) * { * /*listBox1.Items.Add(Path.GetFileName(itm.path) + " vs " + Path.GetFileName(itm2.path) + * "cross_energy_correl = " + Correl(itm.snap_log10_energy, itm2.snap_log10_energy, itm.snap_log10_energy.Average(), itm2.snap_log10_energy.Average()) + " " + * "cross_energy_diff = " + VecDiff(itm.snap_log10_energy, itm2.snap_log10_energy) + " " + * "convoluted histogram value = " + HistogramConv(itm, itm2, 0.001) * );*/ //s1.Add(Correl(itm.snap_log10_energy, itm2.snap_log10_energy, itm.snap_log10_energy.Average(), itm2.snap_log10_energy.Average())); //s2.Add(1 / Math.Log10(VecDiff(itm.snap_log10_energy, itm2.snap_log10_energy))); //s3.Add(HistogramConv(itm, itm2, 0.001)); /*s1.Add(0); * s2.Add(0); * s3.Add(0); * } * * sp_CED.Add(s1); * sp_CEC.Add(s2); * sp_CHV.Add(s3); * }*/ /*List<double> likelihood = new List<double>(); * * for (int i = 0; i < splist.Count; i++) * { * double lh = 0; * //listBox1.Items.Add(Path.GetFileName(splist[i].path) + ": " + (int)(100*sp_ASC[i]) + " " + (int)(100*sp_ASSC[i]) + " " + (int)(10*sp_ED[i])); * for (int j = 0; j < splist.Count; j++) * { * lh = * sp_ASC[i] * sp_ASC[j] + * sp_ASSC[i] * sp_ASSC[j] + * sp_ED[i] * sp_ED[j] + * sp_CED[i][j] + sp_CEC[i][j] + sp_CHV[i][j] * ; * likelihood.Add(lh); * listBox1.Items.Add((int)(100*lh) + " : " + Path.GetFileName(splist[i].path) + " " + Path.GetFileName(splist[j].path)); * } * //listBox1.Items.Add("----->" + (int)(100*sp_CED[i][j]) + " " + (int)(100*sp_CEC[i][j]) + " " + (int)(100*sp_CHV[i][j]) + "; " + Path.GetFileName(splist[j].path)); * * }*/ }