00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 # include <qstring.h>
00014 # include <qlineedit.h>
00015 # include <qslider.h>
00016 # include <qfile.h>
00017 # include <qtextstream.h>
00018 # include <qcanvas.h>
00019 # include <qfiledialog.h>
00020 # include <qstatusbar.h>
00021 # include <qtextedit.h>
00022 # include <qspinbox.h>
00023 # include <randomc.h>
00024 # include <inn.h>
00025 # include <learningThread.h>
00026 # include <network.h>
00027
00028 extern Inn * inn ;
00029 extern Network * network;
00030 extern TRandomMersenne *rg ;
00031 extern int32 seed ;
00032
00033 vector<double> exampleIn;
00034
00035 void TestingDialog::init() {
00036 }
00037
00038 void TestingDialog::slotBrowse( void ) {
00039 QString filename = QFileDialog::getOpenFileName(
00040 ".",
00041 "CSV file (*.csv)",
00042 this,
00043 "open file a teaching file",
00044 "Choose a file to open" ) ;
00045
00046 QFile *file;
00047 QTextStream *filetext;
00048 file = new QFile(filename);
00049 if ( !file->open( IO_ReadOnly ) ) {
00050 QMessageBox::warning(0, "Warning", "The specified file cannot be opened...");
00051 return;
00052 }
00053
00054 lineEdit1->setText(filename);
00055 filetext = new QTextStream(file);
00056 exampleIn = network->readTestFile(filetext);
00057 file->close();
00058 delete file;
00059 delete filetext;
00060 network->resetAllValues();
00061 network->initLayerIn(exampleIn);
00062 }
00063
00064
00065 void TestingDialog::slotStartTesting( void ) {
00066 network->resetAllValues();
00067 network->initLayerIn(exampleIn);
00068 network->forwardPropagation();
00069 }
00070
00071
00072 void TestingDialog::slotAddNoise() {
00073 int howmuch = spinBox->text().toInt() ;
00074 int card = exampleIn.size() ;
00075 int howmany = card*howmuch/100 ;
00076 for( int i = 0 ; i < howmany ; i++ ) {
00077 int random = rg->IRandom(0,card-1);
00078 float value = rg->Random();
00079 int sign = rg->IRandom(0, 10) ;
00080 if( sign>5 ) value *= -1 ;
00081 exampleIn[random] = value ;
00082 }
00083 network->resetAllValues();
00084 network->initLayerIn(exampleIn);
00085 }
00086
00087
00088 void TestingDialog::slotReloadExample() {
00089 if (!(lineEdit1->displayText() == "")) {
00090 QFile *file;
00091 QTextStream *filetext;
00092 file = new QFile(lineEdit1->text());
00093 if ( !file->open( IO_ReadOnly ) ) {
00094 QMessageBox::warning(0, "Warning", "The specified file cannot be opened...");
00095 return;
00096 }
00097 filetext = new QTextStream(file);
00098 exampleIn = network->readTestFile(filetext);
00099 file->close();
00100 delete file;
00101 delete filetext;
00102 network->resetAllValues();
00103 network->initLayerIn(exampleIn);
00104 } else {
00105 QMessageBox::warning(0, "Warning", "You must first select a test file...");
00106 }
00107 }