Skip to content

Commit a43b126

Browse files
committed
add debug info
1 parent e8cf826 commit a43b126

14 files changed

+172
-168
lines changed

BayesNetGUI.pro.user

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE QtCreatorProject>
3-
<!-- Written by QtCreator 4.6.0, 2018-05-04T20:37:27. -->
3+
<!-- Written by QtCreator 4.6.0, 2018-05-06T09:08:31. -->
44
<qtcreator>
55
<data>
66
<variable>EnvironmentId</variable>
@@ -190,7 +190,7 @@
190190
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">BayesNetGUI.pro</value>
191191
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
192192
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
193-
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default">/home/nguyennd/workspace/build-BayesNetGUI-Debug</value>
193+
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory.default"></value>
194194
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
195195
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
196196
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ bayesian network gui tool
44
###### - Graphical creating bayesian network.
55
###### - Inference based on probability, statiscal theory.
66
###### - Learning with complete and uncomplete data.
7-
##### This version have improvement of speed on infering and learning with algorithm of belief propagation by NguyenND ([email protected])
7+
##### This version have improvement by NguyenND ([email protected])
8+
###### - Increase speed on infering and learning with algorithm of belief propagation.
9+
###### - Can solve the big size of network and loopy graph.

bayesnet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ void BayesNet::updateMul(vector<uint> eIndice, vector<int> eVals)
436436
mBeliefs, mEvidences);
437437
for(uint j=0; j<loopCut.size(); j++)
438438
{
439-
// cout << "\tloopCut:" << loopCut.at(j) << endl;
439+
cout << "\tloopCut:" << loopCut.at(j) << endl;
440440
vector<double> bel = bayesNet->getBeliefs().at(loopCut.at(j));
441441
jointProb *= bel.at(jointIns.at(j));
442442

bngraphicsscene.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ void BnGraphicsScene::loadFromText(QString *text)
2626
double px, py;
2727
QString label;
2828

29-
numNodes = 0;
30-
strScene >> numNodes;
31-
for (uint i = 0; i < numNodes; ++i) {
29+
mNumNodes = 0;
30+
strScene >> mNumNodes;
31+
for (uint i = 0; i < mNumNodes; ++i) {
3232
strScene >> nodeIndex;
3333
strScene >> label;
3434
strScene >> px;
@@ -44,7 +44,7 @@ void BnGraphicsScene::loadFromText(QString *text)
4444
// newNode->setIsSelected(false);
4545
connect(newNode, SIGNAL(nodeDeleted()), this, SLOT(onNodeDeleted()));
4646
connect(newNode, SIGNAL(positionChanged(QPointF)), this, SIGNAL(nodePositionChanged()));
47-
mapBayes.insert(newNode, QList<QBayesEdge*>());
47+
mMapBayes.insert(newNode, QList<QBayesEdge*>());
4848
}
4949

5050
uint nodeIndex1, nodeIndex2;
@@ -65,28 +65,28 @@ void BnGraphicsScene::loadFromText(QString *text)
6565
connect(parentNode, SIGNAL(nodeDeleted()), newEdge, SLOT(onNodeDeleted()));
6666
connect(childNode, SIGNAL(nodeDeleted()), newEdge, SLOT(onNodeDeleted()));
6767
connect(newEdge, SIGNAL(edgeDeleted()), this, SLOT(onEdgeDeleted()));
68-
mapBayes[parentNode].append(newEdge);
69-
mapBayes[childNode].append(newEdge);
70-
listEdges.push_back(newEdge);
68+
mMapBayes[parentNode].append(newEdge);
69+
mMapBayes[childNode].append(newEdge);
70+
mListEdges.push_back(newEdge);
7171
}
7272
}
7373

7474
void BnGraphicsScene::clearNetwork()
7575
{
76-
if (!listEdges.isEmpty()) {
77-
qDeleteAll(listEdges);
78-
listEdges.clear();
76+
if (!mListEdges.isEmpty()) {
77+
qDeleteAll(mListEdges);
78+
mListEdges.clear();
7979
}
80-
if (!mapBayes.isEmpty()) {
81-
foreach (auto list, mapBayes.values()) {
80+
if (!mMapBayes.isEmpty()) {
81+
foreach (auto list, mMapBayes.values()) {
8282
list.clear();
8383
}
84-
foreach (auto key, mapBayes.keys()) {
84+
foreach (auto key, mMapBayes.keys()) {
8585
delete key;
8686
}
87-
mapBayes.clear();
87+
mMapBayes.clear();
8888
}
89-
numNodes = 0;
89+
mNumNodes = 0;
9090
clear();
9191
clearFocus();
9292
clearSelection();
@@ -95,7 +95,7 @@ void BnGraphicsScene::clearNetwork()
9595
BnGraphicsScene::BnGraphicsScene(QObject *parent)
9696
: QGraphicsScene(parent)
9797
{
98-
numNodes = 0;
98+
mNumNodes = 0;
9999
}
100100

101101
BnGraphicsScene::~BnGraphicsScene()
@@ -135,7 +135,7 @@ QBayesEdge *BnGraphicsScene::getSelectedEdge()
135135

136136
QBayesNode *BnGraphicsScene::getNodeAt(uint index) const
137137
{
138-
foreach (auto node, mapBayes.keys()) {
138+
foreach (auto node, mMapBayes.keys()) {
139139
if (node->getIndex() == index) {
140140
return node;
141141
}
@@ -146,19 +146,19 @@ QBayesNode *BnGraphicsScene::getNodeAt(uint index) const
146146
QString BnGraphicsScene::toString() const
147147
{
148148
QString rs = "";
149-
rs += QString::number(numNodes);
149+
rs += QString::number(mNumNodes);
150150
rs += "\t";
151151
rs += "\n";
152-
auto listKeys = mapBayes.keys();
152+
auto listKeys = mMapBayes.keys();
153153
qSort(listKeys.begin(), listKeys.end(), PtrLess<QBayesNode>());
154154
foreach (QBayesNode* node, listKeys) {
155155
rs += node->toString();
156156
rs += "\n";
157157
}
158-
rs += QString::number(listEdges.size());
158+
rs += QString::number(mListEdges.size());
159159
rs += "\t";
160160
rs += "\n";
161-
foreach (QBayesEdge* edge, listEdges) {
161+
foreach (QBayesEdge* edge, mListEdges) {
162162
rs += edge->toString();
163163
rs += "\n";
164164
}
@@ -171,26 +171,26 @@ void BnGraphicsScene::onNodeDeleted()
171171
auto dNode = getSelectedNode();
172172

173173
/// delete related edges
174-
foreach (QBayesEdge* edge, mapBayes[dNode]) {
175-
mapBayes[edge->getParentNode()].removeOne(edge);
176-
mapBayes[edge->getChildNode()].removeOne(edge);
177-
listEdges.removeOne(edge);
174+
foreach (QBayesEdge* edge, mMapBayes[dNode]) {
175+
mMapBayes[edge->getParentNode()].removeOne(edge);
176+
mMapBayes[edge->getChildNode()].removeOne(edge);
177+
mListEdges.removeOne(edge);
178178
this->removeItem(edge);
179179
}
180-
mapBayes[dNode].clear();
181-
mapBayes.remove(dNode);
180+
mMapBayes[dNode].clear();
181+
mMapBayes.remove(dNode);
182182
///
183183

184184
emit nodeDeleted(dNode->getIndex());
185185

186186
/// decrease node's index
187187
auto index = dNode->getIndex();
188-
foreach (QBayesNode* node, mapBayes.keys()) {
188+
foreach (QBayesNode* node, mMapBayes.keys()) {
189189
if (node->getIndex() > index) {
190190
node->setIndex(node->getIndex()-1);
191191
}
192192
}
193-
numNodes--;
193+
mNumNodes--;
194194
///
195195

196196
this->removeItem(dNode);
@@ -200,9 +200,9 @@ void BnGraphicsScene::onNodeDeleted()
200200
void BnGraphicsScene::onEdgeDeleted()
201201
{
202202
auto dEdge = getSelectedEdge();
203-
mapBayes[dEdge->getParentNode()].removeOne(dEdge);
204-
mapBayes[dEdge->getChildNode()].removeOne(dEdge);
205-
listEdges.removeOne(dEdge);
203+
mMapBayes[dEdge->getParentNode()].removeOne(dEdge);
204+
mMapBayes[dEdge->getChildNode()].removeOne(dEdge);
205+
mListEdges.removeOne(dEdge);
206206
this->removeItem(dEdge);
207207
auto paIndex = dEdge->getParentNode()->getIndex();
208208
auto cIndex = dEdge->getChildNode()->getIndex();
@@ -233,7 +233,7 @@ void BnGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
233233
auto parentNode = getSelectedNode();
234234
if (childNode && parentNode) {
235235
/// check edge alredy exist
236-
foreach (QBayesEdge* edge, mapBayes[parentNode]) {
236+
foreach (QBayesEdge* edge, mMapBayes[parentNode]) {
237237
if (edge->getChildNode() == childNode) {
238238
return;
239239
}
@@ -250,14 +250,14 @@ void BnGraphicsScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
250250

251251
void BnGraphicsScene::addNode(QString label, QPointF pos)
252252
{
253-
QBayesNode *newNode = new QBayesNode(numNodes, label);
253+
QBayesNode *newNode = new QBayesNode(mNumNodes, label);
254254
newNode->setPos(pos);
255255
this->addItem(newNode);
256256
newNode->setSelected(true);
257257
connect(newNode, SIGNAL(nodeDeleted()), this, SLOT(onNodeDeleted()));
258258
connect(newNode, SIGNAL(positionChanged(QPointF)), this, SIGNAL(nodePositionChanged()));
259-
mapBayes.insert(newNode, QList<QBayesEdge*>());
260-
++numNodes;
259+
mMapBayes.insert(newNode, QList<QBayesEdge*>());
260+
++mNumNodes;
261261
emit nodeAdded();
262262
}
263263

@@ -272,9 +272,9 @@ void BnGraphicsScene::addEdge(QBayesNode* parentNode, QBayesNode* childNode)
272272
connect(parentNode, SIGNAL(nodeDeleted()), newEdge, SLOT(onNodeDeleted()));
273273
connect(childNode, SIGNAL(nodeDeleted()), newEdge, SLOT(onNodeDeleted()));
274274
connect(newEdge, SIGNAL(edgeDeleted()), this, SLOT(onEdgeDeleted()));
275-
mapBayes[parentNode].append(newEdge);
276-
mapBayes[childNode].append(newEdge);
277-
listEdges.push_back(newEdge);
275+
mMapBayes[parentNode].append(newEdge);
276+
mMapBayes[childNode].append(newEdge);
277+
mListEdges.push_back(newEdge);
278278
emit edgeAdded(parentNode->getIndex(), childNode->getIndex());
279279
}
280280

bngraphicsscene.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ public slots:
5656
void mousePressEvent(QGraphicsSceneMouseEvent *event);
5757

5858
private:
59-
uint numNodes;
60-
QMap<QBayesNode*, QList<QBayesEdge*>> mapBayes; /// map each node to all edge related to it
61-
QList<QBayesEdge*> listEdges;
59+
uint mNumNodes;
60+
QMap<QBayesNode*, QList<QBayesEdge*>> mMapBayes; /// map each node to all edge related to it
61+
QList<QBayesEdge*> mListEdges;
6262
};
6363

6464
#endif // MYGRAPHICSSCENE_H

cptmodel.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
CptModel::CptModel(QObject* parent)
1616
: QAbstractTableModel(parent)
1717
{
18-
values = nullptr;
18+
mValues = nullptr;
1919
initValues(1, 2, 0);
2020
}
2121

@@ -26,10 +26,10 @@ QVariant CptModel::data(const QModelIndex &index, int role) const
2626
if (index.isValid())
2727
{
2828
if (role == Qt::DisplayRole) {
29-
return values[row][col];
29+
return mValues[row][col];
3030
} else if (role == Qt::TextAlignmentRole) {
3131
return Qt::AlignCenter;
32-
} else if (role == Qt::BackgroundRole && col < nparents) {
32+
} else if (role == Qt::BackgroundRole && col < mNodeparents) {
3333
return QColor(180,255,255);
3434
}
3535
}
@@ -43,13 +43,13 @@ bool CptModel::setData(const QModelIndex &index, const QVariant &value, int role
4343
return false;
4444
}
4545
double newValue = value.toDouble();
46-
if (newValue == values[index.row()][index.column()] || index.column() < nparents) {
46+
if (newValue == mValues[index.row()][index.column()] || index.column() < mNodeparents) {
4747
return false;
4848
}
49-
values[index.row()][index.column()] = newValue;
50-
if (ncolumns-nparents == 2)
49+
mValues[index.row()][index.column()] = newValue;
50+
if (mNColumns-mNodeparents == 2)
5151
{
52-
values[index.row()][ncolumns-1-(index.column()-nparents)] = 1 - newValue;
52+
mValues[index.row()][mNColumns-1-(index.column()-mNodeparents)] = 1 - newValue;
5353
}
5454
emit dataChanged(index, index);
5555
return true;
@@ -85,14 +85,14 @@ QVariant CptModel::headerData(int section, Qt::Orientation orientation, int role
8585
if (role == Qt::DisplayRole) {
8686
if (orientation == Qt::Horizontal)
8787
{
88-
if(section >=0 && section < headers.count())
89-
return headers[section];
88+
if(section >=0 && section < mHeaders.count())
89+
return mHeaders[section];
9090
}
9191
} else if (role == Qt::TextAlignmentRole) {
9292
return Qt::AlignCenter;
9393
} else if (role == Qt::BackgroundRole) {
9494
if (orientation == Qt::Horizontal) {
95-
if (section < nparents) {
95+
if (section < mNodeparents) {
9696
return QColor(120,210,210);
9797
} else {
9898
return QColor(150,150,250);
@@ -104,12 +104,12 @@ QVariant CptModel::headerData(int section, Qt::Orientation orientation, int role
104104

105105
int CptModel::rowCount(const QModelIndex &parent) const
106106
{
107-
return nrows;
107+
return mNRows;
108108
}
109109

110110
int CptModel::columnCount(const QModelIndex &parent) const
111111
{
112-
return ncolumns;
112+
return mNColumns;
113113
}
114114

115115
bool CptModel::insertRows(int row, int count, const QModelIndex &parent)
@@ -140,15 +140,15 @@ void CptModel::initValues(int nrows, int ncolumns, int nparents)
140140
clear();
141141
///
142142

143-
this->nrows = nrows;
144-
this->ncolumns = ncolumns;
145-
this->nparents = nparents;
146-
values = new double*[nrows];
143+
this->mNRows = nrows;
144+
this->mNColumns = ncolumns;
145+
this->mNodeparents = nparents;
146+
mValues = new double*[nrows];
147147
for (int i = 0; i < nrows; ++i) {
148-
values[i] = new double[ncolumns];
148+
mValues[i] = new double[ncolumns];
149149
for (int j = 0; j < ncolumns; ++j) {
150-
values[i][j] = 0;
151-
// values[i][j] = 1.0 / ncolumns;
150+
mValues[i][j] = 0;
151+
// mValues[i][j] = 1.0 / mNColumns;
152152
}
153153
// values[i][0] = 1;
154154
}
@@ -157,32 +157,32 @@ void CptModel::initValues(int nrows, int ncolumns, int nparents)
157157

158158
void CptModel::setValue(int row, int column, double value)
159159
{
160-
values[row][column] = value;
160+
mValues[row][column] = value;
161161
}
162162

163163
double CptModel::getValue(int row, int column)
164164
{
165-
if (0 <= row && row < nrows && 0 <= column && column < ncolumns)
166-
return values[row][column];
165+
if (0 <= row && row < mNRows && 0 <= column && column < mNColumns)
166+
return mValues[row][column];
167167
else
168168
return 0;
169169
}
170170

171171
void CptModel::setHeader(int column, QString value)
172172
{
173-
headers.insert(column, value);
173+
mHeaders.insert(column, value);
174174
}
175175

176176
void CptModel::clear()
177177
{
178-
if (values) {
179-
for (int i = 0; i < this->nrows; ++i) {
180-
delete values[i];
181-
values[i] = nullptr;
178+
if (mValues) {
179+
for (int i = 0; i < this->mNRows; ++i) {
180+
delete mValues[i];
181+
mValues[i] = nullptr;
182182
}
183-
delete values;
184-
values = nullptr;
183+
delete mValues;
184+
mValues = nullptr;
185185
}
186-
headers.clear();
187-
nrows = ncolumns = nparents = 0;
186+
mHeaders.clear();
187+
mNRows = mNColumns = mNodeparents = 0;
188188
}

0 commit comments

Comments
 (0)