File: modelPropertiesDialog.C

package info (click to toggle)
ball 1.4.3~beta1-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 318,984 kB
  • sloc: cpp: 346,579; ansic: 4,097; python: 2,664; yacc: 1,778; lex: 1,099; xml: 964; sh: 688; sql: 316; awk: 118; makefile: 108
file content (133 lines) | stat: -rw-r--r-- 3,014 bytes parent folder | download | duplicates (2)
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
/* TRANSLATOR BALL::QSAR

		Necessary for lupdate.
*/

#include <modelPropertiesDialog.h>
#include <QtGui/QPushButton>
#include <QtGui/QMessageBox>
#include <QtGui/QCheckBox>

#include <iostream>

using namespace BALL::VIEW;

ModelPropertiesDialog::ModelPropertiesDialog(RegistryEntry* entry)
	: entry_(entry)
{
	num_of_parameters_ = entry_->parameterNames.size();
	QGridLayout *layout = new QGridLayout;

	QDialogButtonBox* Buttons = new QDialogButtonBox(QDialogButtonBox::Ok |QDialogButtonBox::Cancel);

	QPushButton* applyButton = new QPushButton(tr("Apply"));
	QPushButton* optimizeButton = new QPushButton(tr("Optimize Parameters"));
	optimizeButton->setEnabled(false);

	Buttons->addButton(applyButton, QDialogButtonBox::ApplyRole);
	Buttons->addButton(optimizeButton, QDialogButtonBox::ActionRole);

	QLabel* klabel = new QLabel(tr("k-fold cross validation"));
	kedit_ = new QLineEdit(); 
	kedit_->setEnabled(false);

	for (int i=0; i < num_of_parameters_; i++)
	{
		QLabel* label = new QLabel;	
		label->setText(QString(entry_->parameterNames[i].c_str()));
		edit_ = new QLineEdit();
		edits_.push_back(edit_);
		layout->addWidget(label, i,1);
		layout->addWidget(edit_, i ,2);
	}

	layout->addWidget(Buttons,num_of_parameters_,3);
	layout->addWidget(kedit_, num_of_parameters_,2);
	layout->addWidget(klabel, num_of_parameters_,1);

	this->setLayout(layout);

	std::string ab_name = entry->name_abreviation;
	std::string name = entry->name;
	
	this->setWindowTitle("Model Properties: " + QString(name.c_str()) + " (" + QString(ab_name.c_str()) + ") ");

	connect(Buttons, SIGNAL(accepted()), this, SLOT(accept()));
	connect(Buttons, SIGNAL(rejected()), this, SLOT(reject()));
	connect(applyButton, SIGNAL(clicked()), this, SLOT(apply()));
	connect(optimizeButton, SIGNAL(clicked()), this, SLOT(optimizeParameters()));
	connect(Buttons, SIGNAL(accepted()), this, SLOT(apply()));
}

ModelPropertiesDialog::ModelPropertiesDialog()
{
}

ModelPropertiesDialog::~ModelPropertiesDialog()
{
}

std::vector<double> ModelPropertiesDialog::parameters()
{
	return parameters_;
}

int ModelPropertiesDialog::k()
{
	return k_;
}

void ModelPropertiesDialog::apply()
{	
	parameters_.clear();
	bool ok;
	double num = 0.;
	for (unsigned int i=0; i < edits_.size(); i++)
	{
		num = edits_[i]->text().toDouble(&ok);
		if (ok)
		{	
			parameters_.push_back(num);
		}
		else 
		{	
			QMessageBox::about(this, tr("Error"),tr("Invalid parameter"));
			parameters_.push_back(0);
		}
	}
	int k = kedit_->text().toInt(&ok);
	if (ok)
	{
		k_ = k;
	}
	else
	{
		QMessageBox::about(this, tr("Error"),tr("Invalid k"));
	}
	
}

void ModelPropertiesDialog::optimizeParameters()
{
	
	if(entry_->optimizable)
	{	
		/*
		entry_->optimizeParameters();
	
		parameters_ = entry_->getParameters();
		for (int i=0; i< parameters_.size(); i++)
		{
			edits_[i]->setText(QString::number(parameters_[i]));
			edits_[i]->update();
		}
		*/
		std::cout << "Optimizable" << std::endl;
	}
	else 
	{
		std::cout << "Not optimizable" << std::endl;
	}

}