00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "holisticviewer.h"
00025
00026 namespace farsa {
00027
00028 HolisticViewer::HolisticViewer(Evonet* network, QWidget* parent, Qt::WindowFlags flags)
00029 : QWidget(parent, flags),
00030 labels() {
00031 net = network;
00032
00033 mainLayout = new QVBoxLayout(this);
00034
00035 grid = new QGridLayout();
00036 grid->setSpacing(0);
00037 mainLayout->addLayout(grid);
00038
00039 neuronChoice = new QHBoxLayout();
00040 neuronX = new QComboBox(this);
00041 neuronY = new QComboBox(this);
00042 neuronChoice->addWidget(neuronX);
00043 neuronChoice->addWidget(neuronY);
00044 mainLayout->addLayout(neuronChoice);
00045
00046 }
00047
00048
00049 int HolisticViewer::getNeuronAct(int n)
00050 {
00051 double act = net->getNeuron(n);
00052 double min = net->neuronrange[n][0];
00053 double max = net->neuronrange[n][1];
00054
00055 act = linearMap(act,min,max,0,255);
00056 return (int)ceil(act);
00057 }
00058
00059 void HolisticViewer::updateGrid()
00060 {
00061 int neuronsPerRow = ceil(sqrt((double)net->getNoNeurons()));
00062
00063
00064 if(labels.size() == 0)
00065 {
00066 QFont font;
00067 QString name, color;
00068
00069 for(int r=0; r<neuronsPerRow; r++)
00070 {
00071 for(int c=0; c<neuronsPerRow; c++)
00072 {
00073 int index = r*neuronsPerRow+c;
00074
00075 if(index < net->getNoNeurons())
00076 {
00077 name = net->neuronl[index];
00078
00079
00080 neuronX->addItem(name);
00081 neuronY->addItem(name);
00082
00083
00084 color = "yellow";
00085 if(index < net->getNoInputs())
00086 color = "red";
00087 if(index > net->getNoInputs()+net->getNoHiddens())
00088 color = "blue";
00089
00090 labels.append( new QLabel(this) );
00091 labels[index]->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
00092 labels[index]->setFont(font);
00093 labels[index]->setText("<font color='"+ color + "';>" + name + "</font>");
00094
00095 grid->addWidget(labels[index], r, c);
00096 }
00097 }
00098 }
00099 }
00100
00101
00102 for(int r=0; r<neuronsPerRow; r++)
00103 {
00104 for(int c=0; c<neuronsPerRow; c++)
00105 {
00106 int index = r*neuronsPerRow+c;
00107 if(index < net->getNoNeurons())
00108 {
00109 labels[index]->setAutoFillBackground(true);
00110 int act256 = getNeuronAct(index);
00111 labels[index]->setPalette(QPalette(QColor(act256,act256,act256, 255)));
00112
00113 int fontSize = (int)(width()+height())/70;
00114 if(fontSize > 30)
00115 fontSize = 30;
00116 QFont font = labels[index]->font();
00117 font.setPointSize(fontSize);
00118 labels[index]->setFont(font);
00119 }
00120 }
00121 }
00122 }
00123
00124 void HolisticViewer::updatePlot()
00125 {
00126
00127
00128
00129 }
00130
00131 void HolisticViewer::paintEvent(QPaintEvent* )
00132 {
00133 QPainter painter(this);
00134
00135 QPen blackPen(Qt::black);
00136 QPen bluePen(Qt::blue);
00137 QPen greenPen(Qt::green);
00138 QPen redPen(Qt::red);
00139
00140 painter.drawRect(0,0,100,100);
00141
00142 painter.fillRect(0,0,width(),height(),Qt::white);
00143 painter.setPen(blackPen);
00144 painter.setRenderHint(QPainter::Antialiasing, false);
00145 }
00146
00147 }