예제 #1
0
        public MjudRelevanceEstimator(IEnumerable <Run> runs, IEnumerable <Metadata> metadata, IEnumerable <RelevanceEstimate> judged)
        {
            // Instantiate model: fSYS, aSYS, aART
            this._model            = new OrdinalLogisticRegression(MjudRelevanceEstimator.LABELS, MjudRelevanceEstimator.ALPHAS, MjudRelevanceEstimator.BETAS);
            this._defaultEstimator = new MoutRelevanceEstimator(runs, metadata);

            // Number of systems and metadata
            int nSys = runs.Select(r => r.System).Distinct().Count();

            this._dArtists = new Dictionary <string, string>();
            foreach (var m in metadata)
            {
                this._dArtists[m.Document] = m.Artist;
            }
            // fSYS
            this._fSYS   = new Dictionary <string, double>();
            this._aSYS   = new Dictionary <string, double>();
            this._aART   = new Dictionary <string, double>();
            this._sRels  = new Dictionary <string, List <double> >();
            this._qaRels = new Dictionary <string, List <double> >();
            foreach (var run in runs)
            {
                string query = run.Query;
                foreach (string doc in run.Documents)
                {
                    string id = RelevanceEstimate.GetId(query, doc);
                    // fSYS
                    double fSYS = 0;
                    this._fSYS.TryGetValue(id, out fSYS);
                    this._fSYS[id] = fSYS + 1.0 / nSys;

                    this._aSYS[id] = 0;
                    this._aART[id] = 0;
                    // sRels
                    if (!this._sRels.ContainsKey(run.System))
                    {
                        this._sRels[run.System] = new List <double>();
                    }
                    // qaRels
                    string artist = null;
                    if (this._dArtists.TryGetValue(doc, out artist) && !this._qaRels.ContainsKey(query + "\t" + artist))
                    {
                        this._qaRels[query + "\t" + artist] = new List <double>();
                    }
                }
            }
            // OV
            this._OV = ((double)this._fSYS.Count) / (nSys * (runs.Count() / nSys) * runs.First().Documents.Count());

            this._qdsRanks = jurbano.Allcea.Cli.AbstractCommand.ToQueryDocumentSystemRanks(runs);

            // Incorporate known judgments
            foreach (var est in judged)
            {
                this.Update(est);
            }
            this._needsUpdate = true;
        }
예제 #2
0
        protected Dictionary<string, List<double>> _sRels; // [sys, [rel]]

        #endregion Fields

        #region Constructors

        public MjudRelevanceEstimator(IEnumerable<Run> runs, IEnumerable<Metadata> metadata, IEnumerable<RelevanceEstimate> judged)
        {
            // Instantiate model: fSYS, aSYS, aART
            this._model = new OrdinalLogisticRegression(MjudRelevanceEstimator.LABELS, MjudRelevanceEstimator.ALPHAS, MjudRelevanceEstimator.BETAS);
            this._defaultEstimator = new MoutRelevanceEstimator(runs, metadata);

            // Number of systems and metadata
            int nSys = runs.Select(r => r.System).Distinct().Count();
            this._dArtists = new Dictionary<string, string>();
            foreach (var m in metadata) {
                this._dArtists[m.Document] = m.Artist;
            }
            // fSYS
            this._fSYS = new Dictionary<string, double>();
            this._aSYS = new Dictionary<string, double>();
            this._aART = new Dictionary<string, double>();
            this._sRels = new Dictionary<string, List<double>>();
            this._qaRels = new Dictionary<string, List<double>>();
            foreach (var run in runs) {
                string query = run.Query;
                foreach (string doc in run.Documents) {
                    string id = RelevanceEstimate.GetId(query, doc);
                    // fSYS
                    double fSYS = 0;
                    this._fSYS.TryGetValue(id, out fSYS);
                    this._fSYS[id] = fSYS + 1.0 / nSys;

                    this._aSYS[id] = 0;
                    this._aART[id] = 0;
                    // sRels
                    if (!this._sRels.ContainsKey(run.System)) {
                        this._sRels[run.System] = new List<double>();
                    }
                    // qaRels
                    string artist = null;
                    if (this._dArtists.TryGetValue(doc, out artist) && !this._qaRels.ContainsKey(query + "\t" + artist)) {
                        this._qaRels[query + "\t" + artist] = new List<double>();
                    }
                }
            }
            // OV
            this._OV = ((double)this._fSYS.Count) / (nSys * (runs.Count()/nSys) * runs.First().Documents.Count());

            this._qdsRanks = jurbano.Allcea.Cli.AbstractCommand.ToQueryDocumentSystemRanks(runs);

            // Incorporate known judgments
            foreach (var est in judged) {
                this.Update(est);
            }
            this._needsUpdate = true;
        }
예제 #3
0
        public MoutRelevanceEstimator(IEnumerable <Run> runs, IEnumerable <Metadata> metadata)
        {
            // Instantiate model: fSYS, OV, fSYS:OV, fART, sGEN, fGEN, sGEN:fGEN
            this._model            = new OrdinalLogisticRegression(MoutRelevanceEstimator.LABELS, MoutRelevanceEstimator.ALPHAS, MoutRelevanceEstimator.BETAS);
            this._defaultEstimator = new UniformRelevanceEstimator(100);
            // Number of systems and metadata
            int nSys = runs.Select(r => r.System).Distinct().Count();
            Dictionary <string, string> artists = new Dictionary <string, string>(); // [doc, artist]
            Dictionary <string, string> genres  = new Dictionary <string, string>(); // [doc, genre]

            foreach (var m in metadata)
            {
                artists[m.Document] = m.Artist;
                genres[m.Document]  = m.Genre;
            }
            // Auxiliary structure for easier computation of fGEN and fART
            Dictionary <string, HashSet <string> > qDocs = new Dictionary <string, HashSet <string> >();

            // fSYS and OV
            this._fSYS = new Dictionary <string, double>();
            foreach (var run in runs)
            {
                string           query = run.Query;
                HashSet <string> docs  = null;
                if (!qDocs.TryGetValue(query, out docs))
                {
                    docs = new HashSet <string>();
                    qDocs.Add(query, docs);
                }
                foreach (string doc in run.Documents)
                {
                    string id = RelevanceEstimate.GetId(query, doc);
                    // fSYS
                    double fSYS = 0;
                    this._fSYS.TryGetValue(id, out fSYS);
                    this._fSYS[id] = fSYS + 1.0 / nSys;
                    docs.Add(doc);
                }
            }
            // OV
            this._OV = ((double)this._fSYS.Count) / (nSys * qDocs.Count * runs.First().Documents.Count());
            // sGEN, fGEN and fART, traverse qDocs
            this._sGEN = new Dictionary <string, bool>();
            this._fGEN = new Dictionary <string, double>();
            this._fART = new Dictionary <string, double>();
            foreach (var docs in qDocs)
            {
                string query = docs.Key;
                foreach (string doc in docs.Value)
                {
                    string id = RelevanceEstimate.GetId(query, doc);
                    // sGEN and fGEN
                    if (genres.ContainsKey(doc))
                    {
                        string docGEN = genres[doc];
                        // sGEN
                        if (genres.ContainsKey(query))
                        {
                            this._sGEN[id] = docGEN == genres[query];
                        }
                        // fGEN
                        double docfGEN        = 0;
                        int    docfGENnotnull = 0;
                        // traverse all documents individually
                        foreach (string doc2 in docs.Value)
                        {
                            if (genres.ContainsKey(doc2))
                            {
                                string doc2GEN = genres[doc2];
                                if (docGEN == doc2GEN)
                                {
                                    docfGEN++;
                                }
                                docfGENnotnull++;
                            }
                        }
                        this._fGEN[id] = docfGEN / docfGENnotnull;
                    }
                    // fART
                    if (artists.ContainsKey(doc))
                    {
                        string docART         = artists[doc];
                        double docfART        = 0;
                        int    docfARTnotnull = 0;
                        // traverse all documents individually
                        foreach (string doc2 in docs.Value)
                        {
                            if (artists.ContainsKey(doc2))
                            {
                                string doc2ART = artists[doc2];
                                if (docART == doc2ART)
                                {
                                    docfART++;
                                }
                                docfARTnotnull++;
                            }
                        }
                        this._fART[id] = docfART / docfARTnotnull;
                    }
                }
            }
        }
예제 #4
0
        protected Dictionary<string, bool> _sGEN; // [querydoc, sGEN]

        #endregion Fields

        #region Constructors

        public MoutRelevanceEstimator(IEnumerable<Run> runs, IEnumerable<Metadata> metadata)
        {
            // Instantiate model: fSYS, OV, fSYS:OV, fART, sGEN, fGEN, sGEN:fGEN
            this._model = new OrdinalLogisticRegression(MoutRelevanceEstimator.LABELS, MoutRelevanceEstimator.ALPHAS, MoutRelevanceEstimator.BETAS);
            this._defaultEstimator = new UniformRelevanceEstimator(100);
            // Number of systems and metadata
            int nSys = runs.Select(r => r.System).Distinct().Count();
            Dictionary<string, string> artists = new Dictionary<string, string>();// [doc, artist]
            Dictionary<string, string> genres = new Dictionary<string, string>();// [doc, genre]
            foreach (var m in metadata) {
                artists[m.Document] = m.Artist;
                genres[m.Document] = m.Genre;
            }
            // Auxiliary structure for easier computation of fGEN and fART
            Dictionary<string, HashSet<string>> qDocs = new Dictionary<string, HashSet<string>>();
            // fSYS and OV
            this._fSYS = new Dictionary<string, double>();
            foreach (var run in runs) {
                string query = run.Query;
                HashSet<string> docs = null;
                if (!qDocs.TryGetValue(query, out docs)) {
                    docs = new HashSet<string>();
                    qDocs.Add(query, docs);
                }
                foreach (string doc in run.Documents) {
                    string id = RelevanceEstimate.GetId(query, doc);
                    // fSYS
                    double fSYS = 0;
                    this._fSYS.TryGetValue(id, out fSYS);
                    this._fSYS[id] = fSYS + 1.0 / nSys;
                    docs.Add(doc);
                }
            }
            // OV
            this._OV = ((double)this._fSYS.Count) / (nSys * qDocs.Count * runs.First().Documents.Count());
            // sGEN, fGEN and fART, traverse qDocs
            this._sGEN = new Dictionary<string, bool>();
            this._fGEN = new Dictionary<string, double>();
            this._fART = new Dictionary<string, double>();
            foreach (var docs in qDocs) {
                string query = docs.Key;
                foreach (string doc in docs.Value) {
                    string id = RelevanceEstimate.GetId(query, doc);
                    // sGEN and fGEN
                    if (genres.ContainsKey(doc)) {
                        string docGEN = genres[doc];
                        // sGEN
                        if (genres.ContainsKey(query)) {
                            this._sGEN[id] = docGEN == genres[query];
                        }
                        // fGEN
                        double docfGEN = 0;
                        int docfGENnotnull = 0;
                        // traverse all documents individually
                        foreach (string doc2 in docs.Value) {
                            if (genres.ContainsKey(doc2)) {
                                string doc2GEN = genres[doc2];
                                if (docGEN == doc2GEN) {
                                    docfGEN++;
                                }
                                docfGENnotnull++;
                            }
                        }
                        this._fGEN[id] = docfGEN / docfGENnotnull;
                    }
                    // fART
                    if (artists.ContainsKey(doc)) {
                        string docART = artists[doc];
                        double docfART = 0;
                        int docfARTnotnull = 0;
                        // traverse all documents individually
                        foreach (string doc2 in docs.Value) {
                            if (artists.ContainsKey(doc2)) {
                                string doc2ART = artists[doc2];
                                if (docART == doc2ART) {
                                    docfART++;
                                }
                                docfARTnotnull++;
                            }
                        }
                        this._fART[id] = docfART / docfARTnotnull;
                    }
                }
            }
        }