Learn R Programming

mstknnclust (version 0.3.1)

generate.complete.graph: Generates a complete graph

Description

This function generates a complete graph. Where each node represents a object_i and the edges have a cost representing the distance d_ij between object_i and other object_j.

Usage

generate.complete.graph(nodes.list, distance.matrix)

Value

edges.complete.graph

A object of class "data.frame" with three columns (object_i, object_j, d_ij) representing the distance between object i and object j of the distance matrix. For instance:

object_iobject_jd_ij
121.60
130.08
141.21
.........
n-1n...

Arguments

nodes.list

A vector with a subset of nodes (objects) of the data matrix for which the complete graph must be generated.

distance.matrix

A distance matrix between each pair of objects in nodes.list. It is used as the edges costs to generate the complete graph.

Author

Mario Inostroza-Ponta, Jorge Parraga-Alava, Pablo Moscato

Examples

Run this code

set.seed(1987)

##Generates a data matrix of dimension 50X13

n=50; m=13
x <- matrix(runif(n*m, min = -5, max = 10), nrow=n, ncol=m)

##Computes a distance matrix of x.

library("stats")
d <- base::as.matrix(stats::dist(x, method="euclidean"))

##Generates complete graph (CG)

cg <- generate.complete.graph(1:nrow(x),d)

head(cg)

##Visualizing CG graph
library("igraph")
cg.network=igraph::graph.adjacency(d, mode="undirected", weighted=TRUE)
plot(cg.network, edge.label=round(E(cg.network)$weight, 2), main="Complete Graph")

Run the code above in your browser using DataLab