-
Notifications
You must be signed in to change notification settings - Fork 0
/
instantAlg.h
93 lines (88 loc) · 5.59 KB
/
instantAlg.h
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
#ifndef EMBEDDING_H
#define EMBEDDING_H
#include <thread>
#include <Eigen/Dense>
#include <Eigen/Sparse>
using namespace std;
namespace propagation
{
class Instantgnn
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
uint num_threads; // Number of threads
uint num_edges, num_nodes, dimension;
string dataset;
vector<vector<uint>> adj;
uint *deg;
vector<double> weights;
double ***q;
double ***residue;
double *powdeg;
vector<double> residue_sum;
uint layer;
double r;
double init_graph(string path, string dataset, Eigen::Map<Eigen::MatrixXi> &edge_index, uint _layer, double _r, const vector<double> &_weights, uint _num_threads);
double init_push_graph(string path, string dataset, Eigen::Map<Eigen::MatrixXd> &X, Eigen::Map<Eigen::MatrixXi> &edge_index, uint _layer, double _r, const vector<double> &_weights, uint _num_threads, double rmax);
void PushMethod(Eigen::Ref<Eigen::MatrixXd> result, double rmax);
double PowerMethod(Eigen::Ref<Eigen::MatrixXd> result);
double UpdateEdges(const vector<pair<uint, uint>> &edgepairs, Eigen::Ref<Eigen::MatrixXd> result, uint update_num_threads, double rmax);
double UpdateStruct(const vector<pair<uint, uint>> &edgepairs);
double UpdateNodes(const vector<uint> &nodes, Eigen::Ref<Eigen::MatrixXd> result, uint update_num_threads, double rmax);
double UpdateFeatures(const vector<uint> &nodes, Eigen::Ref<Eigen::MatrixXd> result, uint update_num_threads, double rmax);
double GetResidueSum(Eigen::Ref<Eigen::VectorXd> res);
double UpdateStructNodes(const vector<uint> &nodes);
private:
// Eigen::MatrixXd MatrixMulMethod(Eigen::Ref<Eigen::MatrixXd> result);
// void PushMethod(Eigen::Ref<Eigen::MatrixXd> result, double rmax);
// void Push(uint times, uint start, uint ends, Eigen::Ref<Eigen::MatrixXd> result);
void Push(uint start, uint ends, double rmax, Eigen::Ref<Eigen::MatrixXd> result);
void UpdateEdgesOperator(uint start, uint ends, double rmax, vector<uint> &affectNodes, vector<vector<uint>> &affectNeighbors, Eigen::Ref<Eigen::MatrixXd> result);
void UpdateFeatureOperator(uint start, uint ends, const vector<uint> &nodes, double rmax, Eigen::Ref<Eigen::MatrixXd> result);
// void UpdateNodesOperator(uint start, uint ends, double rmax, vector<uint> &affectNodes, vector<vector<uint>> &affectNeighbors, Eigen::Ref<Eigen::MatrixXd> result);
// void UpdateFeaturesOperator(uint start, uint ends, double rmax, vector<uint> &affectNodes, vector<vector<uint>> &affectNeighbors, Eigen::Ref<Eigen::MatrixXd> result);
void Power(uint start, uint ends, Eigen::Ref<Eigen::MatrixXd> result);
void PushOperator(uint dim, double rmax, Eigen::Ref<Eigen::MatrixXd> result, vector<uint> &candidates, vector<bool> &next_indicator_candidates, vector<uint> &next_candidates, uint k);
uint GetDegree(uint node);
uint GetNeighbor(uint node, uint index);
};
class Instantgnn_transpose
{
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
uint num_threads; // Number of threads
uint num_edges, num_nodes, dimension;
string dataset;
vector<vector<uint>> adj;
uint *deg;
vector<double> weights;
vector<double> **q;
vector<double> **residue;
double *powdeg;
uint layer;
vector<double> residue_sum;
double r;
double init_graph(string path, string dataset, Eigen::Map<Eigen::MatrixXi> &edge_index, uint _layer, double _r, const vector<double> &_weights, uint _num_threads);
double init_push_graph(string path, string dataset, Eigen::Map<Eigen::MatrixXd> &X, Eigen::Map<Eigen::MatrixXi> &edge_index, uint _layer, double _r, const vector<double> &_weights, uint _num_threads, double rmax);
void PushMethod(Eigen::Ref<Eigen::MatrixXd> result, double rmax);
double PowerMethod(Eigen::Ref<Eigen::MatrixXd> result);
double UpdateEdges(const vector<pair<uint, uint>> &edgepairs, Eigen::Ref<Eigen::MatrixXd> result, uint update_num_threads, double rmax);
double UpdateStruct(const vector<pair<uint, uint>> &edgepairs);
double UpdateNodes(const vector<uint> &nodes, Eigen::Ref<Eigen::MatrixXd> result, uint update_num_threads, double rmax);
double UpdateFeatures(const vector<uint> &nodes, Eigen::Ref<Eigen::MatrixXd> result, uint update_num_threads, double rmax);
double GetResidueSum(Eigen::Ref<Eigen::VectorXd> res);
double UpdateStructNodes(const vector<uint> &nodes);
private:
// Eigen::MatrixXd MatrixMulMethod(Eigen::Ref<Eigen::MatrixXd> result);
// void PushMethod(Eigen::Ref<Eigen::MatrixXd> result, double rmax);
// void Push(uint times, uint start, uint ends, Eigen::Ref<Eigen::MatrixXd> result);
void Push(uint start, uint ends, double rmax, Eigen::Ref<Eigen::MatrixXd> result);
void UpdateEdgesOperator(uint start, uint ends, double rmax, vector<uint> &affectNodes, vector<vector<uint>> &affectNeighbors, Eigen::Ref<Eigen::MatrixXd> result);
void UpdateFeatureOperator(uint start, uint ends, const vector<uint> &nodes, double rmax, Eigen::Ref<Eigen::MatrixXd> result);
void Power(uint start, uint ends, Eigen::Ref<Eigen::MatrixXd> result);
void PushOperator(uint dim, double rmax, Eigen::Ref<Eigen::MatrixXd> result, vector<uint> &candidates, vector<bool> &next_indicator_candidates, vector<uint> &next_candidates, uint k);
uint GetDegree(uint node);
uint GetNeighbor(uint node, uint index);
};
}
#endif // EMBEDDING_H