예제 #1
0
파일: Form1.cs 프로젝트: samotnij/holo
        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));
        }
예제 #2
0
파일: Form1.cs 프로젝트: develop1/holo
        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));

            }*/
        }
예제 #3
0
파일: Form1.cs 프로젝트: develop1/holo
        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));
        }
예제 #4
0
파일: Form1.cs 프로젝트: samotnij/holo
        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));
             *
             * }*/
        }