Git Product home page Git Product logo

spectralgraphtopology's Introduction

spectralGraphTopology

codecov CRAN_Status_Badge CRAN Downloads CRAN Downloads Total Rcpp

spectralGraphTopology provides estimators to learn k-component, bipartite, and k-component bipartite graphs from data by imposing spectral constraints on the eigenvalues and eigenvectors of the Laplacian and adjacency matrices. Those estimators leverage spectral properties of the graphical models as a prior information which turn out to play key roles in unsupervised machine learning tasks such as clustering.

Documentation: https://mirca.github.io/spectralGraphTopology.

Installation

From inside an R session, type:

> install.packages("spectralGraphTopology")

Alternatively, you can install the development version from GitHub:

> devtools::install_github("dppalomar/spectralGraphTopology")

Microsoft Windows

On MS Windows environments, make sure to install the most recent version of Rtools.

macOS

spectralGraphTopology depends on RcppArmadillo which requires gfortran.

Usage: clustering

We illustrate the usage of the package with simulated data, as follows:

library(spectralGraphTopology)
library(clusterSim)
library(igraph)
set.seed(42)

# generate graph and data
n <- 50  # number of nodes per cluster
twomoon <- clusterSim::shapes.two.moon(n)  # generate data points
k <- 2  # number of components

# estimate underlying graph
S <- crossprod(t(twomoon$data))
graph <- learn_k_component_graph(S, k = k, beta = .25, verbose = FALSE, abstol = 1e-3)

# plot
# build network
net <- igraph::graph_from_adjacency_matrix(graph$adjacency, mode = "undirected", weighted = TRUE)
# colorify nodes and edges
colors <- c("#706FD3", "#FF5252")
V(net)$cluster <- twomoon$clusters
E(net)$color <- apply(as.data.frame(get.edgelist(net)), 1,
                      function(x) ifelse(V(net)$cluster[x[1]] == V(net)$cluster[x[2]],
                                        colors[V(net)$cluster[x[1]]], '#000000'))
V(net)$color <- colors[twomoon$clusters]
# plot nodes
plot(net, layout = twomoon$data, vertex.label = NA, vertex.size = 3)

Contributing

We welcome all sorts of contributions. Please feel free to open an issue to report a bug or discuss a feature request.

Citation

If you made use of this software please consider citing:

In addition, consider citing the following bibliography according to their implementation:

function reference
cluster_k_component_graph N., Feiping, W., Xiaoqian, J., Michael I., and H., Heng. (2016). The Constrained Laplacian Rank Algorithm for Graph-based Clustering, AAAI’16.
learn_laplacian_gle_mm Licheng Zhao, Yiwei Wang, Sandeep Kumar, and Daniel P. Palomar, Optimization Algorithms for Graph Laplacian Estimation via ADMM and MM, IEEE Trans. on Signal Processing, vol. 67, no. 16, pp. 4231-4244, Aug. 2019
learn_laplacian_gle_admm Licheng Zhao, Yiwei Wang, Sandeep Kumar, and Daniel P. Palomar, Optimization Algorithms for Graph Laplacian Estimation via ADMM and MM, IEEE Trans. on Signal Processing, vol. 67, no. 16, pp. 4231-4244, Aug. 2019
learn_combinatorial_graph_laplacian H. E. Egilmez, E. Pavez and A. Ortega, Graph learning from data under Laplacian and structural constraints, Journal of Selected Topics in Signal Processing, vol. 11, no. 6, pp. 825-841, Sept. 2017

Links

Package: CRAN and GitHub

README file: GitHub-readme

Vignette: GitHub-html-vignette, CRAN-html-vignette, NeurIPS’19 Promotional slides, NeurIPS’19 Promotional video

spectralgraphtopology's People

Contributors

dppalomar avatar mirca avatar sandeep0kr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

spectralgraphtopology's Issues

graphical lasso example

@dppalomar I think I'm missing something on the glasso package?
The estimated covariance matrix is similiar to the sample covariance matrix, however, their generalized inverse are quite different. See the following example:

library(spectralGraphTopology)
library(glasso)

set.seed(123)
w <- c(1, 2, 3)
Lw <- L(w)
Y <- MASS::mvrnorm(100, rep(0, nrow(Lw)), MASS::ginv(Lw))

# True Laplacian Matrix
Lw
#      [,1] [,2] [,3]
# [1,]    3   -1   -2
# [2,]   -1    4   -3
# [3,]   -2   -3    5

# Sample Covariance Matrix
cov(Y)
#             [,1]        [,2]        [,3]
# [1,]  0.12937250 -0.07160465 -0.05776785
# [2,] -0.07160465  0.10031397 -0.02870933
# [3,] -0.05776785 -0.02870933  0.08647718

# Naive Estimator
MASS::ginv(cov(Y))
#          [,1]      [,2]      [,3]
# [1,]  3.456331 -1.434415 -2.021916
# [2,] -1.434415  4.690137 -3.255723
# [3,] -2.021916 -3.255723  5.277639

# glasso
gl <- glasso(cov(Y), rho = 1e-2)
gl

# $w (Graphical Lasso Covariance Matrix)
#             [,1]        [,2]        [,3]
# [1,]  0.13937250 -0.06160457 -0.04776738
# [2,] -0.06160457  0.11031397 -0.01870933
# [3,] -0.04776738 -0.01870933  0.09647718
#
# $wi (Graphical Lasso Inverse Covariance Matrix)
#           [,1]      [,2]      [,3]
# [1,] 14.567376  9.676671  9.089026
# [2,]  9.676661 15.801224  7.855262
# [3,]  9.089156  7.855371 16.388597

TODO list

  • refine initial guess of w by solving the following QP: min w: ||vec(L_naive) - vec(Lw)||^2
  • add plots of the error criterion as a function of the number of observations
  • compare the performance of spectralGraphTopology against glasso(http://statweb.stanford.edu/~tibs/glasso/)
  • prepare detailed examples for Jiaxi to investigate why Situation 3 doesn't seem to occur
  • look at qgraph or similar packages to draw graphs
  • add documentation for the C++ functions
  • investigate whether there is a hack to render LaTeX's algorithm2e in the HTML version of the vignette
  • general notation improvements
  • add input validation to the exported functions

@dppalomar please do add more tasks as you see fit.

TODO for the paper

  • ISCM ---> Naive
  • LLQP ---> QP
  • SGL ---> SGL (proposed)
  • CGL(A) ---> CGL (clairvoyant)
  • N ---> n
  • T ---> p
  • Same orientation for learned graph plots
  • F-score for K > 7

Doesn't work without suggested package CVXR

Problem description

Package is declared in Suggests, but it is used on package load. As a result, it doesn't work on systems without CVXR.

Example

See the build log:

** R
** inst
** byte-compile and prepare package for lazy loading
Error in library(CVXR) : there is no package called 'CVXR'
Error: unable to load R code in package 'spectralGraphTopology'
Execution halted
ERROR: lazy loading failed for package 'spectralGraphTopology'
* removing '/builddir/build/BUILDROOT/R-CRAN-spectralGraphTopology-0.2.3-1.fc37.copr4853884.x86_64/usr/local/lib/R/library/spectralGraphTopology'
error: Bad exit status from /var/tmp/rpm-tmp.gMNrVw (%install)

Expected behavior

The package should work without CVXR, or CVXR should be promoted to Imports or Depends.

Environment:

  • platform (e.g. Linux, OSX, Windows): Linux
  • spectralGraphTopology version (e.g. 0.2): 0.2.3
  • installation method (e.g. CRAN, source): source

Error: cannot allocate vector of size

Problem description

I tested the data Lymph (number of nodes = 587) using learn_laplacian_gle_mm and got the error:
Error: cannot allocate vector of size ...

Example

library(spectralGraphTopology)
learn_laplacian_gle_mm(S, A_mask = NULL, alpha = 0, maxiter = 20000, reltol = 1e-06, record_objective = TRUE, verbose = TRUE)

Environment:

  • platform Windows workstation

Memory deallocation of Eigen types

This is a note to myself to look into proper ways on how to manage memory allocation in the C++ code. This might impose problems when we work on simulations with large (>400) number of nodes.

explore the sparse structure of the vector w

The vector w is very sparse specially when the number of components of the graph is large. I should look into exploring this fact and use more efficient data structures probably from the Matrix package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.