Learn R Programming

mstknnclust (version 0.3.1)

compute.costs.proximity.graph: Computes the edge costs sum of a proximity graph

Description

This function computes the edge costs (distances) overall sum of a proximity graph.

Usage

compute.costs.proximity.graph(graph.edges, distance.matrix)

Value

total.costs.graph

A numeric value representing the edge costs (distance) overall sum of a proximity graph.

Arguments

graph.edges

A object of class "matrix" with two columns (object_i, object_j) representing the objects (nodes) of a proximity graph.

distance.matrix

A distance matrix between each pair of object i,j in the proximity graph.

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)

##Generates a proximity graph (MST)
mstree <- generate.mst(cg)

##Calculate the edge cost sum of proximity graph (MST)
mstree.cost=as.numeric(compute.costs.proximity.graph(as.matrix(mstree$edges.mst.graph[,1:2]), d))
mstree.cost

##Generates a proximity graph (kNN)
knneig <- generate.knn(cg)

##Calculate the edge cost sum of proximity graph (kNN)
knneig.cost=as.numeric(compute.costs.proximity.graph(as.matrix(knneig$edges.knn.graph[,1:2]), d))
knneig.cost

Run the code above in your browser using DataLab