Exemple #1
0
Histogram Histogram::operator-(const Histogram& h2)
{
	Histogram& h1=*this;
	Histogram res;

	Histogram::Iterator it1 = h1.begin();
	Histogram::Iterator it2 = h2.begin();

	while (it1 != h1.end() && it2 != h2.end())
	{
		keydata key1 = it1.getKey();
		keydata key2 = it2.getKey();

		if (key1 < key2)
		{
			res.setValue(key1,it1.getVal());
			++it1;
		}

		else if (key1 == key2)
		{
			valdata val1 = it1.getVal();
			valdata val2 = it2.getVal();
			if (val1 > val2) res.setValue(key1, val1-val2);
			++it1;
			++it2;
		}
		else ++it2;
	}

	while (it1 != h1.end()) { res.setValue(it1.getKey(),it1.getVal()); ++it1; };
	return res;
}
Exemple #2
0
/** Compute the log likelihood that these samples came from the
 * specified distribution shifted by the parameter theta.
 * @param theta the parameter of the PMF, f_theta(x)
 * @param samples the samples
 * @param pmf the probability mass function
 * @return the log likelihood
 */
static pair<double, unsigned>
computeLikelihood(int theta, const Histogram& samples, const PMF& pmf)
{
	double likelihood = 0;
	unsigned nsamples = 0;
	for (Histogram::const_iterator it = samples.begin();
			it != samples.end(); ++it) {
		double p = pmf[it->first + theta];
		unsigned n = it->second;
		likelihood += n * log(p);
		if (p > pmf.minProbability())
			nsamples += n;
	}
	return make_pair(likelihood, nsamples);
}
Exemple #3
0
void ClassResultOp::operator()(const imagein::Image* img, const std::map<const imagein::Image*, std::string>&) {

    QDialog* dialog = new QDialog(QApplication::activeWindow());
    QVBoxLayout* layout = new QVBoxLayout(dialog);
    QFormLayout* formLayout = new QFormLayout();
    QSpinBox* innerBox = new QSpinBox();
    QSpinBox* borderBox = new QSpinBox();
    innerBox->setRange(0, img->getWidth());
    borderBox->setRange(0, img->getWidth());
    innerBox->setSuffix(" px");
    borderBox->setSuffix(" px");
    innerBox->setValue(8);
    borderBox->setValue(2);
    formLayout->insertRow(0, qApp->translate("ClassResult", "Critère de zone intérieure : "), innerBox);
    formLayout->insertRow(1, qApp->translate("ClassResult", "Critère de zone frontière : "), borderBox);
    layout->addWidget(new QLabel(qApp->translate("ClassResult", "<b>Critère de zones (relatifs aux zones totales) : </b>")));
    layout->addLayout(formLayout);
    layout->addWidget(new QLabel(qApp->translate("ClassResult", "<b>Select the image's classes zones : </b>")));
    ImageZoneSelector* zoneSelector = new ImageZoneSelector(dialog, img);
    layout->addWidget(zoneSelector);
    QDialogButtonBox* buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel, Qt::Horizontal, dialog);
    layout->addWidget(buttonBox);
    QObject::connect(buttonBox, SIGNAL(accepted()), dialog, SLOT(accept()));
    QObject::connect(buttonBox, SIGNAL(rejected()), dialog, SLOT(reject()));
    QDialog::DialogCode code = static_cast<QDialog::DialogCode>(dialog->exec());

    if(code!=QDialog::Accepted) return;

    string returnval;

    int param1 = 2;
    int param2 = 8;
    vector<Rectangle> selection = zoneSelector->getSelections();
    int K = selection.size();
    int* classes = new int[K];
    outText(qApp->translate("ClassResult", "Voici les résultats du classement : \n").toStdString());
    outText(qApp->translate("ClassResult", "\nNombre de classes = %1 ").arg(K).toStdString());
    for(int i = 0; i < K; ++i) {
        Histogram histo = img->getHistogram(0, selection.at(i));
        classes[i] = (uint8_t) (std::max_element(histo.begin(), histo.end()) - histo.begin());
        outText(qApp->translate("ClassResult", "Valeur de la classe %1 = %2").arg(i+1).arg(classes[i]).toStdString());
    }


    //Zone frontire
    double *tauxF = new double[K];
    double *tauxI = new double[K];
    for(int i = 0; i < K; ++i){
        tauxF[i] = 0.;
        tauxI[i] = 0.;
    }

    for(int n = 0; n < K; ++n) {
        Rectangle zone = selection.at(n);
        for(unsigned int j = zone.top(); j < zone.bottom(); ++j) {
            for(unsigned int i = zone.left(); i < zone.right(); ++i) {
                if(img->getPixelAt(i, j) == classes[n]) {
                    if( i >= zone.left() + param2 && i < zone.right() - param2 && j >= zone.top() + param2 && j < zone.bottom() - param2 ) {
                        tauxI[n]++;
                    }
                    if( i < zone.left() + param1 || i >= zone.right() - param1 || j < zone.top() + param1 || j >= zone.bottom() - param1 ) {
                        tauxF[n]++;
                    }
                }
            }
        }
    }

    for(int n = 0; n < K; ++n) {
        Rectangle zone = selection.at(n);
        const double areaI = (zone.h - 2*param2) * (zone.w - 2*param2);
        const double areaF = (zone.h * zone.w) - (zone.h - 2*param1) * (zone.w - 2*param1);
        tauxI[n] = tauxI[n] * 100. / areaI;
        tauxF[n] = tauxF[n] * 100. / areaF;
    }
    for(int n = 0; n < K; ++n) {
        outText(qApp->translate("ClassResult", "Le taux de bon classement en zone intérieure %1 vaut: %2\%").arg(n+1).arg(tauxI[n], 0, 'f', 2).toStdString());
    }
    for(int n = 0; n < K; ++n) {
        outText(qApp->translate("ClassResult", "Le taux de bon classement en zone frontière %1 vaut: %2\%").arg(n+1).arg(tauxF[n], 0, 'f', 2).toStdString());
    }

    double tauxGI = 0., tauxGF = 0.;
    for(int i = 0; i < K; ++i){
        tauxGI += tauxI[i];
        tauxGF += tauxF[i];
    }
    tauxGI /= K;
    tauxGF /= K;

    outText(qApp->translate("ClassResult", "Le taux de bon classement en zone intérieure globale vaut: %1\%").arg(tauxGI, 0, 'f', 2).toStdString());
    outText(qApp->translate("ClassResult", "Le taux de bon classement en zone frontière globale vaut: %1\%").arg(tauxGF, 0, 'f', 2).toStdString());

    outText(returnval);
}
Exemple #4
0
 void print(std::ostream &o) const {
     o <<"Total syscalls called:\t" <<ncalls <<"\n";
     o <<"By call number:\n";
     for (Histogram::const_iterator ci=calls.begin(); ci!=calls.end(); ++ci)
         o <<"  " <<ci->first <<":\t" <<ci->second <<"\n";
 }
Exemple #5
0
 void print(std::ostream &o) const {
     o <<"Total instructions executed:\t" <<ninsns <<"\n";
     o <<"By instruction:\n";
     for (Histogram::const_iterator ii=insns.begin(); ii!=insns.end(); ++ii)
         o <<"  " <<ii->first <<":\t" <<ii->second <<"\n";
 }
void readInAndAccumulate(const string& path, Histogram& histogram)
{
    std::string line;

    vector<string> lineParts; 
    vector<string> outboundLinkParts;
    long nodeId;
    vector<long>   outboundLinks;

    outboundLinks.reserve(100);
    lineParts.reserve(100);
    outboundLinkParts.reserve(100);

    ifstream file;
    file.open(path.c_str());
    while (!file.eof())
    {
        // Clear last lines state 
        lineParts.clear(); 
        outboundLinkParts.clear(); 
        outboundLinks.clear();
        line = "";
        nodeId = 0;

        getline(file, line);
        // A line looks like:
        // 0 : 1 2 3 4 5
        split(lineParts, line, boost::is_any_of(":"));

        trim(lineParts[0]);

        if (lineParts.size() != 2 || lineParts.front().empty())
        {
            continue;
        }
        nodeId = lexical_cast<long>(lineParts.front());

//        cout << "node = "  << nodeId <<  endl;
        split(outboundLinkParts, lineParts.back(), boost::is_space());

        // Remove any empty tokens we parsed.
        outboundLinkParts.erase(remove_if(outboundLinkParts.begin(),
                                         outboundLinkParts.end(),
                                         bind(&string::empty,_1)),
                        outboundLinkParts.end());
      //  cout << "num parsed edges " << outboundLinkParts.size() << endl;
        // Parse and store the links of this node.
        BOOST_FOREACH(string & link, outboundLinkParts)
        {
            trim(link);
            outboundLinks.push_back(lexical_cast<long>(link));
  //          cout << outboundLinks.back() <<" ";
        }
        // Push the links into our histogram
        BOOST_FOREACH(long link, outboundLinks) 
        {
            if(histogram.find(link) == histogram.end())
            {
                histogram[link] = 1;
            }
            else 
            {
                ++histogram[link];
            }
        }
    }