コード例 #1
0
            public void AddVectorsFromDB (PCAnalyzer ana)
            {
                Dictionary<int, Mirage.Vector> vectorMap = null;
                lock (BansheeLibraryAnalyzer.Singleton.db_synch) {
                    vectorMap = BansheeLibraryAnalyzer.Singleton.db.GetMirageMaxVectors ();
                }
                if (vectorMap == null)
                    throw new DatabaseException ("vectorMap is null!");

                foreach (int bid in vectorMap.Keys) {
                    try {
                        TrackInfo ti = DatabaseTrackInfo.Provider.FetchSingle (bid) as TrackInfo;

                        if (ti == null) {
                            if (!BansheeLibraryAnalyzer.Singleton.updating_db)
                                new Thread (new ThreadStart (BansheeLibraryAnalyzer.Singleton.RemoveDeletedTracks))
                                    .Start ();
                            continue;
                        }

                        if (!ana.AddEntry (bid, BansheeLibraryAnalyzer.Singleton.
                                           ConvertMirageVector (vectorMap [bid]),
                                           ti.Duration.TotalSeconds))
                            throw new Exception("AddEntry failed!");
                    } catch (Exception e) {
                        Hyena.Log.Exception ("NoNoise - PCA Problem", e);
                    }
                }
            }
コード例 #2
0
            public void AddVectorsFromDB (PCAnalyzer ana)
            {
                Dictionary<int, Mirage.Vector> vectorMap = null;
                lock (BansheeLibraryAnalyzer.Singleton.db_synch) {
                    vectorMap = BansheeLibraryAnalyzer.Singleton.db.GetMirageMaxVectors ();
                }
                if (vectorMap == null)
                    throw new DatabaseException ("vectorMap is null!");

                foreach (int bid in vectorMap.Keys) {
                    try {
                        if (!ana.AddEntry (bid, BansheeLibraryAnalyzer.Singleton.
                                           ConvertMirageVector (vectorMap [bid])))
                            throw new Exception("AddEntry failed!");
                    } catch (Exception e) {
                        Hyena.Log.Exception("NoNoise - PCA Problem", e);
                    }
                }
            }
コード例 #3
0
ファイル: NoNoiseSource.cs プロジェクト: tjom/MIRPCADB
            /// <summary>
            /// Checks for each track in the music library if there is already
            /// MIR data in the database. If not, computes the MFCC matrix and
            /// stores it in the database.
            /// </summary>
            private void PcaForMusicLibrary()
            {
                PCAnalyzer ana = new PCAnalyzer();

                //                if (gatherMIRdata) {
                Banshee.Library.MusicLibrarySource ml = ServiceManager.SourceManager.MusicLibrary;
                Mirage.Matrix mfcc;
                Dictionary<int, Mirage.Matrix> mfccMap = db.GetMirageMatrices ();

                for (int i = 0; i < ml.TrackModel.Count; i++) {
                    try {
                        TrackInfo ti = ml.TrackModel [i];
                        string absPath = ti.Uri.AbsolutePath;
                        int bid = ml.GetTrackIdForUri (ti.Uri);

                        // WARN: A bid could theoretically be inserted/deleted between GetMirageMatrices ()
                        // and CointainsMirDataForTrack () such that if and else fail
                        if (!db.ContainsMirDataForTrack (bid)) {
                            mfcc = Mirage.Analyzer.AnalyzeMFCC (absPath);

                            if (!db.InsertMatrix (mfcc, bid))
                                Hyena.Log.Error ("NoNoise - Matrix insert failed");
                        } else
                            mfcc = mfccMap[bid];

                        if (!ana.AddEntry (bid, ConvertMfccMean (mfcc.Mean ())))
                            throw new Exception("AddEntry failed!");
                //                        if (!ana.AddEntry (bid, ConvertMfccMean(mfcc.Mean()), ti.Duration.TotalSeconds))
                //                            throw new Exception("AddEntry failed!");
                //                        if (!ana.AddEntry (bid, null, ti.Bpm, ti.Duration.TotalSeconds))
                //                            throw new Exception("AddEntry failed!");
                    } catch (Exception e) {
                        Hyena.Log.Exception("NoNoise - MFCC/DB Problem", e);
                    }
                }
                //                } else {
                //                    Dictionary<int, Matrix> mfccMap = db.GetMirageMatrices ();
                //
                //                    foreach (int key in mfccMap.Keys) {
                //                        try {
                //                            if (!ana.AddEntry (key, ConvertMfccMean (mfccMap[key].Mean ())))
                //                                throw new Exception ("AddEntry failed!");
                //                        } catch (Exception e) {
                //                            Hyena.Log.Exception ("NoNoise - PCA Problem", e);
                //                        }
                //                    }
                //                }

                try {
                    ana.PerformPCA ();
                //                    Hyena.Log.Debug(ana.GetCoordinateStrings ());
                    List<DataEntry> coords = ana.Coordinates;
                    db.ClearPcaData ();
                    if (!db.InsertPcaCoordinates (coords))
                        Hyena.Log.Error ("NoNoise - PCA coord insert failed");
                } catch (Exception e) {
                    Hyena.Log.Exception("PCA Problem", e);
                }
            }
コード例 #4
0
        /// <summary>
        /// Checks for each track in the music library if there is already
        /// MIR data in the database. If not, computes the MFCC matrix and
        /// stores it in the database.
        /// Vector Edition!
        /// </summary>
        /// <param name="force_new">
        /// A <see cref="System.Boolean"/> indicating whether PCA coordinates
        /// should be computed even if old ones seem to be up to date.
        /// </param>
        private void PcaForMusicLibrary (bool force_new)
        {
            if (data_up_to_date && !force_new) {
                Hyena.Log.Information ("NoNoise/BLA - Data already up2date - aborting pca.");
                return;
            }

            if (analyzing_lib) {
                Hyena.Log.Information ("NoNoise/BLA - Music library is currently beeing scanned - aborting pca.");
                return;
            }

            if (!lib_scanned) {
                Hyena.Log.Information ("NoNoise/BLA - No mirage data available for pca - aborting.");
                sc.ScannableChanged (true);
                GetPcaData ();
                Hyena.ThreadAssist.ProxyToMain (sc.PcaCoordinatesUpdated);
                return;
            }

            if (pca_adder == null) {
                Hyena.Log.Debug ("NoNoise/BLA - PCA adder is null - aborting.");
                return;
            }

            Hyena.Log.Debug ("NoNoise/BLA - PcaFor... called");

            try {
                PCAnalyzer ana = new PCAnalyzer ();
                lock (pca_synch) {
                    pca_adder.AddVectorsFromDB (ana);
                }
                ana.PerformPCA ();

                lock (db_synch) {
                    db.ClearPcaData ();
                    coords = ana.Coordinates;
                    if (!db.InsertPcaCoordinates (ana.Coordinates))
                        Hyena.Log.Error ("NoNoise/BLA - PCA coord insert failed");
                    Hyena.Log.Debug ("NoNoise/BLA - PCA inserted into db");
                }
            } catch (DatabaseException e) {
                Hyena.Log.Exception ("NoNoise/BLA - Database Problem", e);
            } catch (Exception e) {
                Hyena.Log.Exception ("NoNoise/BLA - PCA Problem", e);
            }

            Hyena.ThreadAssist.ProxyToMain (sc.PcaCoordinatesUpdated);
        }
コード例 #5
0
ファイル: NoNoiseSource.cs プロジェクト: tjom/MIRPCADB
            /// <summary>
            /// Test method to (manually) check if the pca computations are correct.
            /// Prints the base vectors computed with a mirage generated covariance
            /// matrix and with the classical self-implemented covariance computation.
            /// </summary>
            private void PcaEigenvectorBasisTest()
            {
                Mirage.Matrix m = new Mirage.Matrix (3, 5);
                m.d [0, 0] = 0.2f;
                m.d [1, 0] = 14.5f;
                m.d [2, 0] = 166.0f;
                m.d [0, 1] = 1.5f;
                m.d [1, 1] = 20.5f;
                m.d [2, 1] = 233.0f;
                m.d [0, 2] = 0.8f;
                m.d [1, 2] = 16.2f;
                m.d [2, 2] = 189.0f;
                m.d [0, 3] = 2.3f;
                m.d [1, 3] = 11.7f;
                m.d [2, 3] = 139.0f;
                m.d [0, 4] = 1.7f;
                m.d [1, 4] = 17.9f;
                m.d [2, 4] = 206.0f;

                PCAnalyzer pca = new PCAnalyzer (m.Covariance (m.Mean ()));
                pca.PcaTest ();

                int i = -1;
                double[] data = { 0.2, 14.5, 166.0 };
                PCAnalyzer ana = new PCAnalyzer ();
                ana.AddEntry (i--, data);

                data = new double[] { 1.5, 20.5, 233.0 };
                ana.AddEntry (i--, data);
                data = new double[] { 0.8, 16.2, 189.0 };
                ana.AddEntry (i--, data);
                data = new double[] { 2.3, 11.7, 139.0 };
                ana.AddEntry (i--, data);
                data = new double[] { 1.7, 17.9, 206.0 };
                ana.AddEntry (i--, data);

                ana.PerformPCA ();
            }