-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParticleNet.h
More file actions
137 lines (107 loc) · 3.25 KB
/
ParticleNet.h
File metadata and controls
137 lines (107 loc) · 3.25 KB
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
/*
* PhaseSeparation.h
*
* Created on: Set/10/2015
* Author: quiles
*/
#ifndef PHASESEPARATION_H_
#define PHASESEPARATION_H_
#include <iostream>
#include <vector>
#include "Snap.h"
#undef min
#undef max
using namespace std;
class TCentroid{
public:
float x, y, z;
float error;
int nparticles; // store the number of associated particles
int comm_id;
float totalR; // sum of the repulsion inside the cluster
float totalA; // sum of the attraction inside the cluster
};
class TParticle{
public:
int node_id;
// TUNGraph::TNodeI node;
float x, y, z;
int degree;
float dxA, dyA, dzA;
float dxR, dyR, dzR;
// float erro;
int cluster_id;
TCentroid *index; // community id obtained by the algorithm / pointer to the centroid
int indexReal; // real community id
vector <int> indexRealH; // real community id
};
class TParticleNet {
private:
PUNGraph Network;
vector <TCentroid> Centroids;
vector <TParticle> Particles;
vector <int> RefNodes;
float alpha; // attraction strength
float beta; // repulsion strength
float gamma; // repulsion decai, constant at 1.0
float eta; // numerical integration step (delta T), constant at 1.0
float addCentroidThreshold;
float mergeCentroidThreshold;
// int centroidTransient;
int nextComId;
int numCommunities;
vector<int> numCommunitiesH;
int numClusters;
bool toAddCentroid; // flag to add a new centroid
bool toRemoveCentroid; // flag to remove a centroid
int centroid2remove;
int idCentroidMaxError; // store the id of the centroid with the largest error
float accError;
float RR, oldRR, oldRR2;
void assignCentroids();
void computeCentroids();
void removeCentroid();
void addCentroid();
void mergeCentroids();
void fineTuning(int t);
bool ExpandCluster(TParticle *p, int clusterID);
vector<TParticle*> GetRegion(TParticle *p);
void ShrinkCentroids();
public:
TParticleNet(const char *filename);
~TParticleNet();
// format: 1 -> LFR files
// 2 -> SNAP files
void LoadCommunities(const char *filename, int format);
PUNGraph GetNetwork(){
return Network;
};
void SetModelParameters(float a, float b, float g){
alpha=a; beta=b; gamma=g; eta=1.0;
};
void SetDetectionParameters(float a, float m){
addCentroidThreshold=a; mergeCentroidThreshold=m;
};
void RunByStep();
void RunForNewNodes(int steps);
int RunModel(int maxIT, float minDR, bool verbose);
void SaveParticlePosition(const char *filename);
void SaveCommunities(const char *filename);
void SaveCentroids(const char *filename);
float NMI();
float NMI2();
float NMIH(int nivel);
void ResetParticles();
int getNumCommunities();
int getNumParticles();
void printCentroids();
float printCentroidsError();
void ReloadNetwork(const char *filename);
void AddNode(int node_id);
void AddLink(int i, int j);
void DeleteNode(int node_id);
void DeleteLink(int i,int j);
void CommunityDetection2(); // DBScan Algorithm - under development....
int CommunityDetection3(); // current clustering approach
};
#endif /* PHASESEPARATION_H_ */