Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rand ESU, ESU and some optimizations on counting

  • Loading branch information...
commit 7c25ba6a0550a94033944984f9a9abbb90cdacc2 1 parent 327c196
@ruiaf authored
View
18 src/Motif.cpp → src/ConnectedVertexSetMotif.cpp
@@ -1,10 +1,14 @@
-#include "Motif.h"
+#include "ConnectedVertexSetMotif.h"
-Motif::Motif() {
+ConnectedVertexSetMotif::ConnectedVertexSetMotif() {
n_incident_edges=0;
}
-void Motif::add(Edge *e) {
+ConnectedVertexSetMotif * ConnectedVertexSetMotif::clone() {
+ return new ConnectedVertexSetMotif(*this);
+}
+
+void ConnectedVertexSetMotif::add(Edge *e) {
bool is_new_e = false;
if (this->node_ids.find(e->u->id) == this->node_ids.end()){
@@ -31,15 +35,19 @@ void Motif::add(Edge *e) {
if (is_new_e) {
this->edges.push_back(e);
+ //std::cout << "added_edge" << *e;
}
}
-bool Motif::operator<(const Motif &other) const {
+bool ConnectedVertexSetMotif::operator<(const ConnectedVertexSetMotif &other) const {
return label_count < other.label_count;
}
+void ConnectedVertexSetMotif::print( std::ostream &out ) const {
+ out << nodes.size() << " " << edges.size();
+}
-unsigned Motif::hash(int seed, int maxval) {
+unsigned ConnectedVertexSetMotif::hash(int seed, int maxval) {
unsigned key = seed;
//TODO: extend this for an unlimited number of labels
View
32 src/ConnectedVertexSetMotif.h
@@ -0,0 +1,32 @@
+#ifndef _CVS_MOTIF_H_
+#define _CVS_MOTIF_H_
+
+class ConnectedVertexSetMotif;
+
+#include <set>
+#include <vector>
+#include <map>
+#include <iostream>
+#include "Graph.h"
+#include "Motif.h"
+
+class ConnectedVertexSetMotif: public Motif {
+ public:
+ ConnectedVertexSetMotif();
+ ConnectedVertexSetMotif * clone();
+ void add(Edge *e);
+ unsigned hash(int seed, int maxval);
+ bool operator<(const ConnectedVertexSetMotif &other) const;
+
+
+ std::map<int,int> label_count;
+ std::set<int> node_ids;
+ std::vector<Vertex *> nodes;
+ std::vector<Edge *> edges;
+ int n_incident_edges;
+
+ private:
+ void print( std::ostream &out ) const;
+};
+
+#endif
View
48 src/CountMinSketch.cpp
@@ -1,12 +1,9 @@
#include "CountMinSketch.h"
-Sketch::Sketch(int n_top_items, float epsilon, float delta) {
- k = n_top_items;
- exact_min_threshold = 0;
-
+Sketch::Sketch(float epsilon, float delta) {
// init sketch
- this->epsilon = epsilon;
- this->delta = delta;
+ epsilon = epsilon;
+ delta = delta;
d= ceil(log(1.0/delta));
w= ceil(M_E/epsilon);
@@ -25,13 +22,8 @@ Sketch::Sketch(int n_top_items, float epsilon, float delta) {
std::cerr << "Done\n";
}
-void Sketch::countMotif(Motif &m, int weight) {
- countMotifApproximate(m,weight);
- countMotifExact(m,weight);
-}
-
-float Sketch::countMotifApproximate(Motif &m, int weight) {
- int min = INT_MAX;
+float Sketch::countMotif(Motif &m, int weight) {
+ unsigned min = UINT_MAX;
unsigned hash;
for (int i=0; i<d; i++) {
hash = m.hash(counter_seeds[i],w);
@@ -43,33 +35,3 @@ float Sketch::countMotifApproximate(Motif &m, int weight) {
return min;
}
-
-int Sketch::countMotifExact(Motif &m, int weight) {
- if (exact_counter.find(m) == exact_counter.end()) {
- exact_counter[m]=0;
- }
- exact_counter[m]+=weight;
-
- if (exact_counter[m] > exact_min_threshold) {
- exact_top_k.push_back(std::pair<int,Motif>(int(exact_counter[m]),Motif(m)));
- exact_top_k.sort();
- if (exact_top_k.size()>k) {
- exact_top_k.pop_front();
- }
- exact_min_threshold = exact_top_k.front().first;
- }
-
- return exact_counter[m];
-}
-
-int Sketch::getTop() {
- std::cerr << "TOP (exact=" << exact_top_k.back().first << ", ";
- std::cerr << "approximate=" << countMotifApproximate(exact_top_k.back().second,0) << ")";
- return exact_top_k.back().first;
-}
-
-/*
-std::vector<Motif> getTopK() {
- return top_k;
-}
-*/
View
16 src/CountMinSketch.h
@@ -19,23 +19,11 @@ class Sketch;
class Sketch {
public:
- Sketch(int n_top_items,float epsilon,float delta);
- std::vector<Motif> getTopK();
- int getTop();
+ Sketch(float epsilon,float delta);
- void countMotif(Motif &m, int weight=1);
- float countMotifApproximate(Motif &m, int weight=1);
- int countMotifExact(Motif &m, int weight=1);
+ float countMotif(Motif &m, int weight=1);
private:
- unsigned k;
-
- // exact counting, just for debug
- std::list< std::pair<int,Motif> > exact_top_k;
- std::map<Motif,int> exact_counter;
- int exact_min_threshold;
-
- // approximate_counting
float epsilon;
float delta;
int w;
View
1  src/Graph.h
@@ -12,7 +12,6 @@ class Graph;
#include <fstream>
#include <string>
#include <sstream>
-#include "MotifSampler.h"
class Edge {
public:
View
6 src/Makefile
@@ -3,10 +3,10 @@ CFLAGS= -O4 -ansi -Wall -g
all:
g++ $(CFLAGS) -c Graph.cpp
g++ $(CFLAGS) -c Motif.cpp
- g++ $(CFLAGS) -c MotifSampler.cpp
- g++ $(CFLAGS) -c MotifLister.cpp
+ g++ $(CFLAGS) -c ConnectedVertexSetMotif.cpp
+ g++ $(CFLAGS) -c RandESUMotifSampler.cpp
g++ $(CFLAGS) -c CountMinSketch.cpp
g++ $(CFLAGS) -c motivos.cpp
- g++ $(CFLAGS) -o motivos Graph.o Motif.o MotifLister.o MotifSampler.o CountMinSketch.o motivos.o
+ g++ $(CFLAGS) -o motivos Graph.o Motif.o ConnectedVertexSetMotif.o RandESUMotifSampler.o CountMinSketch.o motivos.o
clean:
rm *.o
View
25 src/Motif.h
@@ -1,25 +0,0 @@
-#ifndef _MOTIF_H_
-#define _MOTIF_H_
-
-class Motif;
-
-#include <set>
-#include <vector>
-#include <map>
-#include "Graph.h"
-
-class Motif {
- public:
- Motif();
- void add(Edge *e);
- unsigned hash(int seed, int maxval);
- bool operator<(const Motif &other) const;
-
- std::map<int,int> label_count;
- std::set<int> node_ids;
- std::vector<Vertex *> nodes;
- std::vector<Edge *> edges;
- int n_incident_edges;
-};
-
-#endif
View
16 src/MotifLister.cpp
@@ -1,16 +0,0 @@
-#include "MotifLister.h"
-
-MotifLister::MotifLister(Graph *g, unsigned motif_size, float percent) {
- this->g = g;
- this->motif_size = motif_size;
- this->percent = percent;
-}
-
-
-Motif * MotifLister::next() {
- Motif *m = new Motif();
-
-
-
- return m;
-}
View
20 src/MotifLister.h
@@ -1,20 +0,0 @@
-#ifndef _MOTIFLISTER_H_
-#define _MOTIFLISTER_H_
-
-#include <iostream>
-#include <set>
-#include <vector>
-#include "Graph.h"
-#include "Motif.h"
-
-class MotifLister {
- public:
- MotifLister(Graph *g, unsigned motif_size, float percent);
- Motif *next();
- private:
- Graph *g;
- unsigned motif_size;
- float percent;
-};
-
-#endif
View
28 src/MotifSampler.cpp
@@ -1,28 +0,0 @@
-#include "MotifSampler.h"
-
-MotifSampler::MotifSampler(Graph *g) {
- this->g = g;
-}
-
-
-Motif * MotifSampler::sample(unsigned motif_size) {
- Motif *m = new Motif();
-
- Edge *e = g->edges[rand() % g->edges.size()];
- m->add(e);
-
- while (m->nodes.size()<=motif_size) {
- unsigned counter = 0;
- unsigned index_i = rand()%(m->n_incident_edges);
- for (std::vector<Vertex *>::iterator i= m->nodes.begin(); i != m->nodes.end(); i++) {
- if ((*i)->edges.size() > (index_i-counter)) {
- e = (*i)->edges[index_i-counter];
- }
- counter+=(*i)->edges.size();
- }
-
- m->add(e);
- }
-
- return m;
-}
View
9 src/MotifSampler.h
@@ -3,19 +3,12 @@
class MotifSampler;
-#include <iostream>
-#include <set>
-#include <vector>
#include "Graph.h"
#include "Motif.h"
class MotifSampler {
public:
- MotifSampler(Graph *g);
- Motif* sample(unsigned motif_size);
-
- private:
- Graph *g;
+ virtual Motif* next() = 0;
};
#endif
View
23 src/motivos.cpp
@@ -1,23 +1,22 @@
#include "Graph.h"
+#include "Motif.h"
#include "MotifSampler.h"
-#include "MotifLister.h"
+#include "RandESUMotifSampler.h"
#include "CountMinSketch.h"
int main(void) {
Graph *g = new Graph();
- g->importSIF("../datasets/DM_Torque.sif");
+ g->importSIF("../datasets/SC_Torque.sif");
- Sketch *sketch = new Sketch(10,0.01,0.01);
- MotifLister *s = new MotifLister(g,200,0.1);
+ //Sketch *sketch = new Sketch(0.01,0.01);
- for (int i=0; i<100000; i++) {
- Motif * m = s->next();
- sketch->countMotif(*m);
- delete m;
- if (i%1000==0) {
- std::cout << i << ' ' << sketch->getTop() << '\n';
- }
- }
+ int k = 100;
+ float p=0.1;
+
+ RandESUMotifSampler *s;
+
+ s = new RandESUMotifSampler(g,k,p);
+ s->outputAllSubgraphs();
return 0;
}
Please sign in to comment.
Something went wrong with that request. Please try again.