Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
deepwalker
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
deepwalker
Commits
c5cd949e
Commit
c5cd949e
authored
Apr 09, 2018
by
Jan Wijffels
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed verse to verse_pagerank
parent
82b9da19
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
89 additions
and
65 deletions
+89
-65
R/RcppExports.R
+2
-2
R/deepwalker_verse.R
+37
-4
man/deepwalker_verse.Rd
+21
-3
src/RcppExports.cpp
+11
-6
src/makefile
+0
-26
src/verse.cpp
+18
-24
No files found.
R/RcppExports.R
View file @
c5cd949e
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393
embeddings_verse
<-
function
(
dgrmatrix_p
,
dgrmatrix_j
,
n_epochs
=
100000
L
)
{
embeddings_verse
_pagerank
<-
function
(
dgrmatrix_p
,
dgrmatrix_j
,
dimension
=
128L
,
epochs
=
100000L
,
learning_rate
=
0.0025
,
samples
=
3L
,
alpha
=
0.85
,
threads
=
1
L
)
{
.Call
(
'_deepwalker_embeddings_verse
'
,
PACKAGE
=
'deepwalker'
,
dgrmatrix_p
,
dgrmatrix_j
,
n_epoch
s
)
.Call
(
'_deepwalker_embeddings_verse
_pagerank'
,
PACKAGE
=
'deepwalker'
,
dgrmatrix_p
,
dgrmatrix_j
,
dimension
,
epochs
,
learning_rate
,
samples
,
alpha
,
thread
s
)
}
}
R/deepwalker_verse.R
View file @
c5cd949e
...
@@ -2,7 +2,19 @@
...
@@ -2,7 +2,19 @@
#' @description This function calculates node embeddings in a graph by using
#' @description This function calculates node embeddings in a graph by using
#' VERSE (Versatile Graph Embeddings from Similarity Measures)
#' VERSE (Versatile Graph Embeddings from Similarity Measures)
#' @param x an object of class dgRMatrix
#' @param x an object of class dgRMatrix
#' @return TODO
#' @param dimension integer with the dimension of the embedding
#' @param epochs number of epochs
#' @param learning_rate the learning rate of the algorithm
#' @param samples integer
#' @param alpha the alpha parameter of the algorithm
#' @return
#' a list with elements
#' \enumerate{
#' \item{vertices: }{the number of vertices in the graph}
#' \item{edges: }{the number of edges (links) between the vertices in the graph}
#' \item{embedding: }{the embeddings of the vertices}
#' \item{edges_data and offsets_data: }{for debugging purposes now}
#' }
#' @export
#' @export
#' @examples
#' @examples
#' library(igraphdata)
#' library(igraphdata)
...
@@ -13,8 +25,28 @@
...
@@ -13,8 +25,28 @@
#' x <- as_adj(karate)
#' x <- as_adj(karate)
#' x <- as(x, "RsparseMatrix")
#' x <- as(x, "RsparseMatrix")
#'
#'
#' embeddings <- deepwalker_verse(x)
#' embeddings <- deepwalker_verse(x, dimension = 64, epochs = 1000)
deepwalker_verse
<-
function
(
x
){
deepwalker_verse
<-
function
(
x
,
emb
<-
embeddings_verse
(
x
@
p
,
x
@
j
,
n_epochs
=
10
)
similarity
=
c
(
"pagerank"
,
"adjacency"
,
"simrank"
),
dimension
=
128
,
epochs
=
100000
,
learning_rate
=
0.0025
,
samples
=
3
,
alpha
=
0.85
){
stopifnot
(
inherits
(
x
,
"dgRMatrix"
))
similarity
<-
match.arg
(
similarity
)
if
(
similarity
==
"pagerank"
){
emb
<-
embeddings_verse_pagerank
(
x
@
p
,
x
@
j
,
dimension
=
dimension
,
epochs
=
epochs
,
learning_rate
=
learning_rate
,
samples
=
samples
,
alpha
=
alpha
)
}
else
if
(
similarity
==
"adjacency"
){
}
else
if
(
similarity
==
"simrank"
){
}
emb
emb
}
}
\ No newline at end of file
man/deepwalker_verse.Rd
View file @
c5cd949e
...
@@ -4,13 +4,31 @@
...
@@ -4,13 +4,31 @@
\alias{deepwalker_verse}
\alias{deepwalker_verse}
\title{Versatile Graph Embeddings from Similarity Measures}
\title{Versatile Graph Embeddings from Similarity Measures}
\usage{
\usage{
deepwalker_verse(x)
deepwalker_verse(x, similarity = c("pagerank", "adjacency", "simrank"),
dimension = 128, epochs = 1e+05, learning_rate = 0.0025, samples = 3,
alpha = 0.85)
}
}
\arguments{
\arguments{
\item{x}{an object of class dgRMatrix}
\item{x}{an object of class dgRMatrix}
\item{dimension}{integer with the dimension of the embedding}
\item{epochs}{number of epochs}
\item{learning_rate}{the learning rate of the algorithm}
\item{samples}{integer}
\item{alpha}{the alpha parameter of the algorithm}
}
}
\value{
\value{
TODO
a list with elements
\enumerate{
\item{vertices: }{the number of vertices in the graph}
\item{edges: }{the number of edges (links) between the vertices in the graph}
\item{embedding: }{the embeddings of the vertices}
\item{edges_data and offsets_data: }{for debugging purposes now}
}
}
}
\description{
\description{
This function calculates node embeddings in a graph by using
This function calculates node embeddings in a graph by using
...
@@ -25,5 +43,5 @@ data(karate, package = "igraphdata")
...
@@ -25,5 +43,5 @@ data(karate, package = "igraphdata")
x <- as_adj(karate)
x <- as_adj(karate)
x <- as(x, "RsparseMatrix")
x <- as(x, "RsparseMatrix")
embeddings <- deepwalker_verse(x)
embeddings <- deepwalker_verse(x
, dimension = 64, epochs = 1000
)
}
}
src/RcppExports.cpp
View file @
c5cd949e
...
@@ -5,22 +5,27 @@
...
@@ -5,22 +5,27 @@
using
namespace
Rcpp
;
using
namespace
Rcpp
;
// embeddings_verse
// embeddings_verse
_pagerank
SEXP
embeddings_verse
(
Rcpp
::
IntegerVector
dgrmatrix_p
,
Rcpp
::
IntegerVector
dgrmatrix_j
,
int
n_epoch
s
);
SEXP
embeddings_verse
_pagerank
(
Rcpp
::
IntegerVector
dgrmatrix_p
,
Rcpp
::
IntegerVector
dgrmatrix_j
,
int
dimension
,
int
epochs
,
float
learning_rate
,
int
samples
,
float
alpha
,
int
thread
s
);
RcppExport
SEXP
_deepwalker_embeddings_verse
(
SEXP
dgrmatrix_pSEXP
,
SEXP
dgrmatrix_jSEXP
,
SEXP
n_epoch
sSEXP
)
{
RcppExport
SEXP
_deepwalker_embeddings_verse
_pagerank
(
SEXP
dgrmatrix_pSEXP
,
SEXP
dgrmatrix_jSEXP
,
SEXP
dimensionSEXP
,
SEXP
epochsSEXP
,
SEXP
learning_rateSEXP
,
SEXP
samplesSEXP
,
SEXP
alphaSEXP
,
SEXP
thread
sSEXP
)
{
BEGIN_RCPP
BEGIN_RCPP
Rcpp
::
RObject
rcpp_result_gen
;
Rcpp
::
RObject
rcpp_result_gen
;
Rcpp
::
RNGScope
rcpp_rngScope_gen
;
Rcpp
::
RNGScope
rcpp_rngScope_gen
;
Rcpp
::
traits
::
input_parameter
<
Rcpp
::
IntegerVector
>::
type
dgrmatrix_p
(
dgrmatrix_pSEXP
);
Rcpp
::
traits
::
input_parameter
<
Rcpp
::
IntegerVector
>::
type
dgrmatrix_p
(
dgrmatrix_pSEXP
);
Rcpp
::
traits
::
input_parameter
<
Rcpp
::
IntegerVector
>::
type
dgrmatrix_j
(
dgrmatrix_jSEXP
);
Rcpp
::
traits
::
input_parameter
<
Rcpp
::
IntegerVector
>::
type
dgrmatrix_j
(
dgrmatrix_jSEXP
);
Rcpp
::
traits
::
input_parameter
<
int
>::
type
n_epochs
(
n_epochsSEXP
);
Rcpp
::
traits
::
input_parameter
<
int
>::
type
dimension
(
dimensionSEXP
);
rcpp_result_gen
=
Rcpp
::
wrap
(
embeddings_verse
(
dgrmatrix_p
,
dgrmatrix_j
,
n_epochs
));
Rcpp
::
traits
::
input_parameter
<
int
>::
type
epochs
(
epochsSEXP
);
Rcpp
::
traits
::
input_parameter
<
float
>::
type
learning_rate
(
learning_rateSEXP
);
Rcpp
::
traits
::
input_parameter
<
int
>::
type
samples
(
samplesSEXP
);
Rcpp
::
traits
::
input_parameter
<
float
>::
type
alpha
(
alphaSEXP
);
Rcpp
::
traits
::
input_parameter
<
int
>::
type
threads
(
threadsSEXP
);
rcpp_result_gen
=
Rcpp
::
wrap
(
embeddings_verse_pagerank
(
dgrmatrix_p
,
dgrmatrix_j
,
dimension
,
epochs
,
learning_rate
,
samples
,
alpha
,
threads
));
return
rcpp_result_gen
;
return
rcpp_result_gen
;
END_RCPP
END_RCPP
}
}
static
const
R_CallMethodDef
CallEntries
[]
=
{
static
const
R_CallMethodDef
CallEntries
[]
=
{
{
"_deepwalker_embeddings_verse
"
,
(
DL_FUNC
)
&
_deepwalker_embeddings_verse
,
3
},
{
"_deepwalker_embeddings_verse
_pagerank"
,
(
DL_FUNC
)
&
_deepwalker_embeddings_verse_pagerank
,
8
},
{
NULL
,
NULL
,
0
}
{
NULL
,
NULL
,
0
}
};
};
...
...
src/makefile
deleted
100644 → 0
View file @
82b9da19
TARGETS
=
verse verse-neigh verse-simrank
CXXFLAGS
=
-std
=
c++11
-march
=
native
ifeq
($(CXX),
g++)
CXXFLAGS
+=
-fopenmp
-Ofast
else
ifeq
($(CXX),
icpc)
CXXFLAGS
+=
-qopenmp
-O3
-no-prec-div
-ansi-alias
-ip
-static-intel
else
ifeq
($(CXX),
clang++)
CXXFLAGS
+=
-fopenmp
=
libomp
-O3
-Wno-shift-op-parentheses
else
# use g++ by default
CXX
=
g++
CXXFLAGS
+=
-fopenmp
-Ofast
endif
all
:
$(TARGETS)
$(TARGETS)
:
$(CXX)
$(CXXFLAGS)
$(LDFLAGS)
-o
$@
$@
.cpp
clean
:
rm
-rfv
$(TARGETS)
.PHONY
:
all clean
\ No newline at end of file
src/verse.cpp
View file @
c5cd949e
...
@@ -137,17 +137,6 @@ inline int sample_rw(int node) {
...
@@ -137,17 +137,6 @@ inline int sample_rw(int node) {
return
n2
;
return
n2
;
}
}
int
ArgPos
(
char
*
str
,
int
argc
,
char
**
argv
)
{
for
(
int
a
=
1
;
a
<
argc
;
a
++
)
if
(
!
strcmp
(
str
,
argv
[
a
]))
{
if
(
a
==
argc
-
1
)
{
cout
<<
"Argument missing for "
<<
str
<<
endl
;
exit
(
1
);
}
return
a
;
}
return
-
1
;
}
inline
void
update
(
float
*
w_s
,
float
*
w_t
,
int
label
,
const
float
bias
)
{
inline
void
update
(
float
*
w_s
,
float
*
w_t
,
int
label
,
const
float
bias
)
{
float
score
=
-
bias
;
float
score
=
-
bias
;
...
@@ -182,7 +171,7 @@ void Train() {
...
@@ -182,7 +171,7 @@ void Train() {
break
;
break
;
if
(
tid
==
0
)
if
(
tid
==
0
)
if
(
!
silent
)
if
(
!
silent
)
cout
<<
fixed
<<
"
\r
Progress "
<<
std
::
setprecision
(
2
)
Rcpp
::
R
cout
<<
fixed
<<
"
\r
Progress "
<<
std
::
setprecision
(
2
)
<<
step
/
(
float
)(
total_steps
+
1
)
*
100
<<
"%"
;
<<
step
/
(
float
)(
total_steps
+
1
)
*
100
<<
"%"
;
last_ncount
=
ncount
;
last_ncount
=
ncount
;
}
}
...
@@ -203,16 +192,21 @@ void Train() {
...
@@ -203,16 +192,21 @@ void Train() {
// [[Rcpp::export]]
// [[Rcpp::export]]
SEXP
embeddings_verse
(
Rcpp
::
IntegerVector
dgrmatrix_p
,
Rcpp
::
IntegerVector
dgrmatrix_j
,
SEXP
embeddings_verse_pagerank
(
Rcpp
::
IntegerVector
dgrmatrix_p
,
Rcpp
::
IntegerVector
dgrmatrix_j
,
int
n_epochs
=
100000
)
{
int
dimension
=
128
,
int
epochs
=
100000
,
float
learning_rate
=
0.0025
,
int
samples
=
3
,
float
alpha
=
0.85
,
int
threads
=
1
)
{
step
=
0
;
step
=
0
;
silent
=
false
;
silent
=
false
;
n_threads
=
1
;
n_threads
=
threads
;
global_lr
=
0.0025
f
;
global_lr
=
learning_rate
;
//n_epochs =
;
n_epochs
=
epochs
;
n_hidden
=
128
;
n_hidden
=
dimension
;
n_samples
=
3
;
n_samples
=
samples
;
ppralpha
=
0.85
f
;
ppralpha
=
alpha
;
//
//
// Set random nr
// Set random nr
...
@@ -249,12 +243,12 @@ SEXP embeddings_verse(Rcpp::IntegerVector dgrmatrix_p, Rcpp::IntegerVector dgrma
...
@@ -249,12 +243,12 @@ SEXP embeddings_verse(Rcpp::IntegerVector dgrmatrix_p, Rcpp::IntegerVector dgrma
for
(
int
i
=
0
;
i
<
(
int
)
nv
;
i
++
)
for
(
int
i
=
0
;
i
<
(
int
)
nv
;
i
++
)
degrees
[
i
]
=
offsets
[
i
+
1
]
-
offsets
[
i
];
degrees
[
i
]
=
offsets
[
i
+
1
]
-
offsets
[
i
];
total_steps
=
n_epochs
*
(
long
long
)
nv
;
total_steps
=
n_epochs
*
(
long
long
)
nv
;
cout
<<
"Total steps (mil): "
<<
total_steps
/
1000000.
<<
endl
;
Rcpp
::
R
cout
<<
"Total steps (mil): "
<<
total_steps
/
1000000.
<<
endl
;
chrono
::
steady_clock
::
time_point
begin
=
chrono
::
steady_clock
::
now
();
chrono
::
steady_clock
::
time_point
begin
=
chrono
::
steady_clock
::
now
();
Train
();
Train
();
chrono
::
steady_clock
::
time_point
end
=
chrono
::
steady_clock
::
now
();
chrono
::
steady_clock
::
time_point
end
=
chrono
::
steady_clock
::
now
();
cout
<<
endl
Rcpp
::
R
cout
<<
endl
<<
"Calculations took "
<<
"Calculations took "
<<
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
float
>>
(
end
-
begin
)
<<
chrono
::
duration_cast
<
std
::
chrono
::
duration
<
float
>>
(
end
-
begin
)
.
count
()
.
count
()
...
@@ -277,8 +271,8 @@ SEXP embeddings_verse(Rcpp::IntegerVector dgrmatrix_p, Rcpp::IntegerVector dgrma
...
@@ -277,8 +271,8 @@ SEXP embeddings_verse(Rcpp::IntegerVector dgrmatrix_p, Rcpp::IntegerVector dgrma
}
}
*/
*/
Rcpp
::
NumericMatrix
embeddings
(
nv
,
n_hidden
);
Rcpp
::
NumericMatrix
embeddings
(
nv
,
n_hidden
);
for
(
int
i
=
0
;
i
<
nv
;
i
++
){
for
(
int
i
=
0
;
i
<
(
int
)
nv
;
i
++
){
for
(
int
j
=
0
;
j
<
n_hidden
;
j
++
){
for
(
int
j
=
0
;
j
<
(
int
)
n_hidden
;
j
++
){
embeddings
(
i
,
j
)
=
w0
[
i
*
nv
+
j
];
embeddings
(
i
,
j
)
=
w0
[
i
*
nv
+
j
];
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment