File: featureSelectionDialog.C

package info (click to toggle)
ball 1.4.2%2B20140406-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 316,064 kB
  • ctags: 38,021
  • sloc: cpp: 341,838; ansic: 4,096; python: 2,645; yacc: 1,778; lex: 1,089; xml: 964; sh: 688; sql: 316; makefile: 150; awk: 118
file content (199 lines) | stat: -rw-r--r-- 6,761 bytes parent folder | download
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
/* featureSelectionDialog.C
 * 
 * Copyright (C) 2009 Marcel Schumann
 * 
 * This file is part of QuEasy -- A Toolbox for Automated QSAR Model
 * Construction and Validation.
 * QuEasy is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or (at
 * your option) any later version.
 * 
 * QuEasy is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include <featureSelectionDialog.h>
#include <iostream>
#include <BALL/QSAR/exception.h>
#include <exception.h>
#include <mainWindow.h>
#include <QtGui/QMessageBox>
#include <QtGui/QPushButton>
#include <iterator>

using namespace BALL::QSAR;

namespace BALL
{
	namespace VIEW
	{

		FeatureSelectionDialog::FeatureSelectionDialog(FeatureSelectionItem* fsitem, ModelItem* model):
			fs_item_(fsitem)
		{
			Registry* reg = model->getRegistryEntry()->getRegistry();
			
			QVBoxLayout* main_layout = new QVBoxLayout(this);
			QHBoxLayout* layout1 = new QHBoxLayout;
			QHBoxLayout* layout2 = NULL;
			QDialogButtonBox* buttons = new QDialogButtonBox(QDialogButtonBox::Cancel);
			QPushButton* applyButton = new QPushButton("OK");
			buttons->addButton(applyButton, QDialogButtonBox::ApplyRole);
			checkbox_post_optimization_model_par_ =0;
			checkbox_post_optimization_kernel_par_=0;
			cutoff_ = 0;
			edit_ = new QLineEdit(this);
			edit2_ = NULL;
			
			if((fsitem->getType()>0&&fsitem->getType()<4) || fsitem->getType()==6)
			{
				edit_->setText(String(reg->default_k).c_str());	
				QLabel* klabel = new QLabel("k for k-fold cross validation",this);
				
				QHBoxLayout* cutoff_layout = new QHBoxLayout;
				QLabel* cutoff_label = new QLabel("quality increase cutoff");
				cutoff_ = new QLineEdit(this);
				cutoff_->setText("0.001");
				cutoff_layout->addWidget(cutoff_label);
				cutoff_layout->addWidget(cutoff_);
				
				layout1->addWidget(klabel);
				layout1->addWidget(edit_);
			
				//QHBoxLayout* layout2 = new QHBoxLayout();
				//layout2->addWidget(checkbox_post_optimization_model_par_);
				//layout2->addWidget(checkbox_post_optimization_kernel_par_);
				
				main_layout->addLayout(layout1);
				main_layout->addLayout(cutoff_layout);
				statistic_box_ = NULL;
				
				// let user select validation statistic
				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);
				}

				if(statistics->size()>2) statistic_box_->setCurrentIndex(2); // use overall ACC as default
				layout3->addWidget(label3);layout3->addWidget(statistic_box_);
				main_layout->addLayout(layout3);
				
			}
			else   // no validation statistics for removal of colineal features
			{
				double cor = reg->default_correlation_cutoff;
				edit_->setText(String(cor).c_str());
				QLabel* label = NULL;
				if(fsitem->getType()==0) label = new QLabel("max correlation between features");
				else if(fsitem->getType()==4)
				{
					label = new QLabel("min correlation with response");
					edit_->setText(String(0.15).c_str());			
				}
				else if(fsitem->getType()==5) 
				{
					QLabel* description = new QLabel("Remove each feature whose absolut coefficient value\nis smaller than d times its standard deviation.");
					label = new QLabel("d = ",this);
					edit_->setText("2");
					main_layout->addWidget(description);
					edit2_ = new QLineEdit(this);
					QString t;
					t.setNum(model->view()->data_scene->main_window->registry()->default_no_boostrap_samples);
					edit2_->setText(t);
					QLabel* label2 = new QLabel("number of bootstrap samples",this);
					layout2 = new QHBoxLayout;
					layout2->addWidget(label2);
					layout2->addWidget(edit2_);
				}
			
				layout1->addWidget(label);
				layout1->addWidget(edit_);		
				main_layout->addLayout(layout1);
				if(layout2!=NULL) main_layout->addLayout(layout2);
			}
			
			checkbox_post_optimization_model_par_ = new QCheckBox("optimize model parameters afterwards", this);
			if(!model->optimize_model_parameters || model->k_fold<2)
			{
				checkbox_post_optimization_model_par_->setEnabled(0);
			}
			checkbox_post_optimization_kernel_par_ = new QCheckBox("optimize kernel parameters afterwards", this);
			if(!model->optimize_kernel_parameters || model->k_fold<2)
			{
				checkbox_post_optimization_kernel_par_->setEnabled(0);
			}
			main_layout->addWidget(checkbox_post_optimization_model_par_);
			main_layout->addWidget(checkbox_post_optimization_kernel_par_);
			
			main_layout->addWidget(buttons);
			setLayout(main_layout);
			setWindowTitle(fs_item_->name());

			connect(applyButton, SIGNAL(clicked()), this, SLOT(accept()));
			connect(buttons, SIGNAL(rejected()), this, SLOT(reject()));
		}


		FeatureSelectionDialog::FeatureSelectionDialog():
			edit_(NULL)
		{
			post_optimization_model_par_ = 0;
			post_optimization_kernel_par_ = 0;
		}

		FeatureSelectionDialog::~FeatureSelectionDialog()
		{
 			delete edit_;
 			delete checkbox_post_optimization_model_par_;
			delete checkbox_post_optimization_kernel_par_;
		}	

		void FeatureSelectionDialog::applyInput()
		{
			bool ok = 0;
			post_optimization_model_par_ = checkbox_post_optimization_model_par_->isChecked();
			post_optimization_kernel_par_ = checkbox_post_optimization_kernel_par_->isChecked();
			fs_item_->post_optimization_model_par_ = post_optimization_model_par_;
			fs_item_->post_optimization_kernel_par_ = post_optimization_kernel_par_;
			
			if((fs_item_->getType()>0&&fs_item_->getType()<4)||fs_item_->getType()==6) // no validation statistics for removal of colineal features
			{
				k_ =  edit_->text().toInt(&ok);
				fs_item_->setK(k_);
				
				statistic_ = -1;
				if(statistic_box_!=NULL)
				{
					statistic_ = statistic_box_->currentIndex();
				}
				if(cutoff_!=NULL)
				{
					fs_item_->setQualityIncreaseCutoff(cutoff_->text().toDouble(&ok));
				}
			}
			else
			{
				fs_item_->cor_threshold_=edit_->text().toDouble(&ok);
				statistic_ = -1;
				if(fs_item_->getType()==5) fs_item_->setK(edit2_->text().toInt(&ok));
				else k_ = 0;
			}
		}

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