Exemplo n.º 1
0
DuplicateDialog::DuplicateDialog(QWidget *parent) :
	QDialog(parent),
	ui(new Ui::DuplicateDialog)
{
	ui->setupUi(this);
	connect(ui->search, SIGNAL(clicked(bool)), this, SLOT(search()));
	connect(&worker_, SIGNAL(finished(bool)), this, SLOT(workerFinished()));
	connect(&worker_, SIGNAL(message(QString)), this, SLOT(showMessage(QString)));
	connect(this, SIGNAL(checkPairs()), this, SLOT(showPairs()));
	connect(ui->browse, SIGNAL(clicked(bool)), this, SLOT(browse()));
}
Exemplo n.º 2
0
void AMTSimulation::simulateScores(int user, int triplet){


    // Gather all documents into a set
    int index = 0;
    vector<int> rand_numbers;
    map<Document, int>::iterator it = _qrels.relDocs.begin();
    for(;it != _qrels.relDocs.end(); it++){
        allDocs.push_back((*it).first);
        rand_numbers.push_back(index);
        doc_index_map.insert(make_pair((*it).first, index));

        // Initialize
        string code; ostringstream convert;
        convert << index;
        code = convert.str();
        _utilScores[code] = arma::zeros(_qrels.relDocs.size());
        _appearanceCounts[code] = arma::zeros(_qrels.relDocs.size());

        index++;
    }
    set<Document>::iterator itnonrel = _qrels.nonRelDocs.begin();
    for(;itnonrel != _qrels.nonRelDocs.end(); itnonrel++){
        //allDocs.push_back((*itnonrel));
        rand_numbers.push_back(index);
        //doc_index_map.insert(make_pair((*itnonrel), index));

        // Initialize
        string code; ostringstream convert;
        convert << index;
        code = convert.str();
        _utilScores[code] = arma::zeros(_qrels.relDocs.size() );
        _appearanceCounts[code] = arma::zeros(_qrels.relDocs.size());

        index++;
    }




    _utilScores[""] = arma::zeros(_qrels.relDocs.size());
    _appearanceCounts[""] = arma::zeros(_qrels.relDocs.size());

    if( _qrels.relDocs.size() < 3){
        int numOfSubtopics = int(*_qrels.subtopics.rbegin());
        arma::rowvec seen = arma::zeros<arma::rowvec>(numOfSubtopics);
        if(get_preference(_qrels.matrix.row(rand_numbers.at(0)), _qrels.matrix.row(rand_numbers.at(1)), seen)){
            _utilScores[""](0) += 1;
        }else
            _utilScores[""](1) += 1;
        _appearanceCounts[""](0) += 1;
        _appearanceCounts[""](1) += 1;
        _utilScores[""] /= _appearanceCounts[""];
        return;
    }

    // Simulate the preferences for only these 1000 triplets randomly

    vector<Qrels>::iterator qrels_iterator = _qrels_vector.begin();

    for(int users=0;users < user; users++){
        std::random_shuffle ( _qrels_vector.begin(), _qrels_vector.end() );

        Qrels currentQrels = _qrels_vector.at(0);

        // Generate triplets and sample 1000 triplets randomly
        map<Triplet, int, triplet_comparison> triplets = sampleTriplets(rand_numbers, triplet);
        map<Triplet, int, triplet_comparison>::iterator triplet_iterator = triplets.begin();
        map<Triplet, int, triplet_comparison> seen_pairs;

        set<int> relevantDocIndices;
        for(;triplet_iterator != triplets.end(); triplet_iterator++){

            Triplet triplet = (*triplet_iterator).first;

            int numOfSubtopics = int(*currentQrels.subtopics.rbegin());
            arma::rowvec seen = arma::zeros<arma::rowvec>(numOfSubtopics);



            if(arma::sum(currentQrels.matrix.row(triplet.topDoc)) <= 0 || triplet.topDoc >=  currentQrels.matrix.n_rows )
                triplet.topDoc = -1;
            if(arma::sum(currentQrels.matrix.row(triplet.leftDoc)) <= 0 || triplet.leftDoc >=  currentQrels.matrix.n_rows)
                    triplet.leftDoc = -1;
            if(arma::sum(currentQrels.matrix.row(triplet.rightDoc)) <= 0 || triplet.rightDoc >=  currentQrels.matrix.n_rows)
                    triplet.rightDoc = -1;


            // Update the scores



            // Keep Track of level 1 pairs for this user profile
            if(triplet.topDoc == -1){
                if(triplet.leftDoc != -1 && triplet.rightDoc != -1){
                    if(checkPairs(seen_pairs, triplet.leftDoc, triplet.rightDoc))
                            continue;
                }else
                    continue;
            }else if(triplet.topDoc != -1){
                seen += currentQrels.matrix.row(triplet.topDoc);
            }



            if(triplet.leftDoc != -1 && triplet.rightDoc != -1){
                if(get_preference(currentQrels.matrix.row(triplet.leftDoc), currentQrels.matrix.row(triplet.rightDoc), seen))
                    updateScores(triplet.topDoc, triplet.leftDoc, triplet.rightDoc, true);
                else
                    updateScores(triplet.topDoc, triplet.leftDoc, triplet.rightDoc, false);
            }
            if(relevantDocIndices.find(triplet.topDoc) == relevantDocIndices.end() && triplet.topDoc != -1)
                relevantDocIndices.insert(triplet.topDoc);
            if(relevantDocIndices.find(triplet.leftDoc) == relevantDocIndices.end() && triplet.leftDoc != -1)
                relevantDocIndices.insert(triplet.leftDoc);
            if(relevantDocIndices.find(triplet.rightDoc) == relevantDocIndices.end() && triplet.rightDoc != -1)
                relevantDocIndices.insert(triplet.rightDoc);

        }
        /*map<string, arma::vec>::iterator codes = _utilScores.begin();
        for(;codes!= _utilScores.end(); codes++){
            set<int>::iterator relevantDocIterator = relevantDocIndices.begin();

            for(; relevantDocIterator != relevantDocIndices.end(); relevantDocIterator++){
                if((*codes).first != ""){
                    if((*relevantDocIterator) != atoi((*codes).first.c_str()))
                        _utilScores[(*codes).first](*relevantDocIterator) += 1;
                }else
                    _utilScores[(*codes).first](*relevantDocIterator) += 1;
            }
            _appearanceCounts[(*codes).first] += 2;
        }*/

    }


    map<string, arma::vec>::iterator codes = _utilScores.begin();
    for(;codes!= _utilScores.end(); codes++){

        _utilScores[(*codes).first] /= (_appearanceCounts[(*codes).first] + 2);

    }
}