1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
#include <validationDialog.h>
#include <exception.h>
#include <mainWindow.h>
#include <BALL/QSAR/exception.h>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
using namespace BALL::QSAR;
namespace BALL
{
namespace VIEW
{
ValidationDialog::ValidationDialog(ValidationItem* val_item, ModelItem* model):
val_item_(val_item)
{
QVBoxLayout* main_layout = new QVBoxLayout(this);
QGridLayout* layout1 = new QGridLayout;
QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Cancel,Qt::Horizontal, this);
QPushButton* applyButton = new QPushButton("OK", this);
buttons->addButton(applyButton, QDialogButtonBox::ApplyRole);
Registry* reg = model->view()->data_scene->main_window->registry();
QString default_value;
if (val_item->getValidationType() == 2)
{
QLabel* klabel = new QLabel("k for k-fold cross validation");
k_edit_ = new QLineEdit(this);
default_value.setNum(reg->default_k);
k_edit_->setText(default_value);
layout1->addWidget(klabel,1,1);
layout1->addWidget(k_edit_,1,2);
}
else if (val_item->getValidationType() == 3 || val_item->getValidationType() == 6)
{
QLabel* label = new QLabel("number of samples for bootstrapping");
n_of_samples_edit_ = new QLineEdit(this);
default_value.setNum(reg->default_no_boostrap_samples);
n_of_samples_edit_->setText(default_value);
layout1->addWidget(label,1,1);
layout1->addWidget(n_of_samples_edit_,1,2);
}
else if (val_item->getValidationType() == 4)
{
QLabel* klabel = new QLabel("k for k-fold cross validation");
QLabel* label = new QLabel("number of runs for response permutation test");
k_edit_ = new QLineEdit(this);
default_value.setNum(reg->default_k);
k_edit_->setText(default_value);
n_of_runs_edit_ = new QLineEdit(this);
default_value.setNum(reg->default_no_permutations);
n_of_runs_edit_->setText(default_value);
layout1->addWidget(label,1,1);
layout1->addWidget(n_of_runs_edit_,1,2);
layout1->addWidget(klabel,2,1);
layout1->addWidget(k_edit_,2,2);
}
else if (val_item->getValidationType() == 5)
{
QLabel* label1 = new QLabel("fraction of data to be set aside for validation");
val_fraction_edit_ = new QLineEdit(this);
val_fraction_edit_->setText("0.25");
QLabel* label2 = new QLabel("number of nested cross validation folds");
n_of_ncv_folds_edit_ = new QLineEdit(this);
n_of_ncv_folds_edit_->setText("4");
layout1->addWidget(label1,1,1);
layout1->addWidget(val_fraction_edit_,1,2);
layout1->addWidget(label2,2,1);
layout1->addWidget(n_of_ncv_folds_edit_,2,2);
}
main_layout->addLayout(layout1);
statistic_box_ = NULL;
if(val_item->getValidationType()!=6)
{
QHBoxLayout* layout3 = new QHBoxLayout;
QLabel* label3 = new QLabel("quality statistic");
statistic_box_ = new QComboBox;
const std::map<unsigned int,String>* statistics = model->getRegistryEntry()->getStatistics();
for(std::map<unsigned int,String>::const_iterator it=statistics->begin(); it!=statistics->end(); ++it)
{
statistic_box_->addItem(it->second.c_str(),it->first);
}
layout3->addWidget(label3);layout3->addWidget(statistic_box_);
main_layout->addLayout(layout3);
}
main_layout->addWidget(buttons);
this->setLayout(main_layout);
this->setWindowTitle("Model Validation");
connect(applyButton, SIGNAL(clicked()), this, SLOT(accept()));
connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
}
ValidationDialog::~ValidationDialog()
{
}
void ValidationDialog::applyInput()
{
bool ok;
int num = 0;
if (ok)
{
k_ = num;
}
if(val_item_->getValidationType()==2)
{
ok = false;
num = k_edit_->text().toInt(&ok);
if (ok)
{
k_ = num;
val_item_->setK(k_);
}
else
{
throw BALL::Exception::InvalidK(__FILE__, __LINE__);
}
}
else if(val_item_->getValidationType()==3 || val_item_->getValidationType()==6)
{
ok = false;
num = n_of_samples_edit_->text().toInt(&ok);
if (ok)
{
n_of_samples_ = num;
val_item_->setNumOfSamples(n_of_samples_);
}
else
{
throw BALL::Exception::InvalidK(__FILE__, __LINE__);
}
}
else if(val_item_->getValidationType()==4)
{
ok = false;
num = k_edit_->text().toInt(&ok);
if (ok)
{
k_ = num;
val_item_->setK(k_);
}
else
{
throw BALL::Exception::InvalidK(__FILE__, __LINE__);
}
ok = false;
num = n_of_runs_edit_ ->text().toInt(&ok);
if (ok)
{
n_of_runs_ = num;
val_item_->setNumOfRuns(n_of_runs_);
}
else
{
throw BALL::Exception::InvalidK(__FILE__, __LINE__);
}
}
else if(val_item_->getValidationType()==5)
{
ok = false;
num = n_of_ncv_folds_edit_->text().toInt(&ok);
val_fraction_ = val_fraction_edit_->text().toDouble(&ok);
if (ok)
{
n_of_ncv_folds_ = num;
val_item_->setValFraction(val_fraction_);
val_item_->setNumOfNCVFolds(n_of_ncv_folds_);
}
else
{
throw BALL::Exception::InvalidK(__FILE__, __LINE__);
}
}
statistic_ = -1;
if(statistic_box_!=NULL)
{
statistic_ = statistic_box_->currentIndex();
}
}
int ValidationDialog::k()
{
return k_;
}
}
}
|