00001 /**************************************************************************** 00002 ** ui.h extension file, included from the uic-generated form implementation. 00003 ** 00004 ** If you want to add, delete, or rename functions or slots, use 00005 ** Qt Designer to update this file, preserving your code. 00006 ** 00007 ** You should not define a constructor or destructor in this file. 00008 ** Instead, write your code in functions called init() and destroy(). 00009 ** These will automatically be called by the form's constructor and 00010 ** destructor. 00011 *****************************************************************************/ 00012 00013 #include <qlabel.h> 00014 #include <qtable.h> 00015 #include "Util/log.H" 00016 00017 void BayesNetworkDialog::init( Bayes &bayesNet ) 00018 { 00019 itsBayesNet = &bayesNet; 00020 setupTab(); 00021 00022 00023 itsBayesNet->import("fv.txt"); 00024 00025 } 00026 00027 00028 void BayesNetworkDialog::update() 00029 { 00030 00031 } 00032 00033 00034 void BayesNetworkDialog::setupTab() 00035 { 00036 static bool setupTab = true; 00037 00038 if (setupTab) 00039 { 00040 //remove the first dummy page 00041 QWidget *page = tabWidget->page(0); //get the first page of the tab 00042 tabWidget->removePage(page); 00043 00044 //priors statistics 00045 QWidget* statTab = new QWidget(tabWidget); 00046 QVBoxLayout* tabLayout = new QVBoxLayout(statTab, 11, 6); 00047 for (uint i=0; i<itsBayesNet->getNumClasses(); i++) 00048 { 00049 QString stat = QString("Class %1: freq %L2 Prior %L3") 00050 .arg(i) 00051 .arg(itsBayesNet->getClassFreq(i)) 00052 .arg(itsBayesNet->getClassProb(i)); 00053 00054 QLabel *label = new QLabel(stat, statTab, QString("stat Label %1").arg(i)); 00055 label->setFont(QFont("Times", 20)); 00056 tabLayout->addWidget(label); 00057 } 00058 tabWidget->insertTab(statTab,QString("Stats")); 00059 00060 00061 //Add a tab to change the mean and variance 00062 QWidget *changeParamTab = new QWidget(tabWidget); 00063 QVBoxLayout* classLayout = new QVBoxLayout(changeParamTab, 11, 6); 00064 00065 for(uint cls=0; cls<itsBayesNet->getNumClasses(); cls++) 00066 { 00067 QString className = QString("%1:%L2").arg(cls).arg(itsBayesNet->getClassName(cls)); 00068 QLabel *label = new QLabel(className, changeParamTab, className); 00069 00070 classLayout->addWidget(label); 00071 00072 QTable *paramTable = new QTable(changeParamTab, "paramTable"); 00073 paramTable->setNumRows(2); 00074 paramTable->setNumCols(itsBayesNet->getNumFeatures()); 00075 00076 //set the values 00077 for(uint fv=0; fv<itsBayesNet->getNumFeatures(); fv++) 00078 { 00079 paramTable->setText(0, fv, QString("%L1").arg(itsBayesNet->getMean(cls, fv))); 00080 paramTable->setText(1, fv, QString("%L1").arg(itsBayesNet->getStdevSq(cls, fv))); 00081 } 00082 00083 classLayout->addWidget(paramTable); 00084 } 00085 00086 tabWidget->insertTab(changeParamTab,QString("Param Change")); 00087 00088 00089 #ifdef INVT_HAVE_QWT 00090 00091 //Get the color names 00092 QStringList colorNames = QColor::colorNames(); 00093 00094 //Graph the conditional prob 00095 for (uint i=0; i<itsBayesNet->getNumFeatures(); i++) 00096 { 00097 QWidget* tab = new QWidget(tabWidget); 00098 QHBoxLayout* tabLayout = new QHBoxLayout(tab, 11, 6); 00099 00100 QString title(itsBayesNet->getFeatureName(i)); 00101 QwtPlot *qwtPlot = new QwtPlot(title, tab); 00102 //not supported in lattest qtw?? qwtPlot->setAutoLegend(true); 00103 qwtPlot->setAutoReplot(true); 00104 for (uint cls=0; cls<itsBayesNet->getNumClasses(); cls++) 00105 { 00106 LFATAL("FIXME: I need to be updated to latest qwt"); 00107 /* 00108 const double STEP = 0.1; 00109 const int XRANGE = int(50.0F/STEP); 00110 double x[XRANGE], y[XRANGE]; 00111 00112 long curve = qwtPlot->insertCurve(itsBayesNet->getClassName(cls)); 00113 00114 int colorId = (cls * 10)%colorNames.size(); 00115 qwtPlot->setCurvePen(curve, QPen(colorNames[colorId])); 00116 00117 double mean = itsBayesNet->getMean(cls, i); 00118 double stdevSq = itsBayesNet->getStdevSq(cls, i); 00119 00120 for (int xi=0; xi<XRANGE; xi++){ 00121 x[xi] = xi * STEP; 00122 y[xi] = itsBayesNet->gauss(x[xi], mean, stdevSq); 00123 } 00124 00125 qwtPlot->setCurveData(curve, x, y, XRANGE); 00126 */ 00127 } 00128 tabLayout->addWidget(qwtPlot); 00129 tabWidget->insertTab(tab,QString("Normal Dist %1").arg(i) ); 00130 00131 setupTab = false; 00132 qwtPlot->replot(); 00133 qwtPlot->show(); 00134 } 00135 00136 #else 00137 printf("Need the qwtPlot widget for graphs!!!\n"); 00138 #endif 00139 } 00140 }