# cnCompare: Network Comparison In sdnet: Soft-Discretization-Based Bayesian Network Inference

## Description

Compares two `catNetwork` objects by several criteria

## Usage

 `1` ```cnCompare(object1, object2, extended = FALSE) ```

## Arguments

 `object1` a `catNetwork` object `object2` a `catNetwork` object, `matrix`, `list` of `catNetwork`s or `catNetworkEvaluate` object `extended` a `logical` parameter, specifying whether basic but quicker or extended comparison to be performed

## Details

Comparison can be performed only between networks with the same sets of nodes. The function considers several topology-related comparison metrics.

First, directed edge comparison is performed and the true positives (TP), the false positive (FP) and the false negatives (FN) are reported assuming `object1` to be the 'true' network.

Second, the difference between the binary parent matrices of the two objects is measured as the number of positions at which they differ. This is the so called Hamming distance and it is coded as `hamm`. Also, when `extended` parameter is set to TRUE, the difference between the exponents of the parent matrices is calculated, `hammexp`.

Third, the node order difference between the two networks is measured as follows. Let us call 'order pair' a pair of indices (i,j) such that there is a directed path from j-th node to i-th node in the network, which sometimes is denoted by j>i. The order comparison is done by counting the false positive and false negative order pairs.

The fourth criteria accounts for the so called 'Markov blanket'. The term 'Markov pair' is used to denote a pair of indices which corresponding nodes have a common child. In case of extended comparison, the numbers of false positive and false negative Markov pairs are calculated.

The `cnCompare` function returns an object with the following slots: 1) the number of true positive edges `tp`; 2) the number of false positive edges `fp`; 3) the number of false negative edges `fn`; 4) precision `pr`; 5) specificity `sp`; 6) sensitivity(recall) `sn`; 7) the F-score, which is the harmonic average of precision and recall 8) the number of different elements in the corresponding parent matrices `hamm`; 9) the total number of different elements between all powers of the parent matrices `hammexp`;

Next three numbers identify the difference in the objects' skeletons (undirected graph structure)

7) the number of true positive undirected edges `tp`; 8) the number of false positive undirected edges `fp`; 9) the number of false negative undirected edges `fn`;

10) the number of false positive order pairs `order.fp`; 11) the number of false negative order pairs `order.fn`; 12) the number of false positive Markov pairs `markov.fp`; and 13) the number of false positive Markov pairs `markov.fn`. It is assumed that the first object represents the ground truth with respect to which the comparison is performed.

If `extended` is set off (FALSE) only the edge (TP, FP, FN) and skeleton (TP, FP, FN) numbers are reported, otherwise all distance parameters are calculated. Turning off the `extended` option is recommended for very large networks (e.g. with number of nodes > 500), since the calculation of some of the distance metrics involve matrix calculations for which the function is not optimized and can be very slow.

## Value

A `catNetworkDistance` if `object2` is `catNetwork` and `catNetworkEvaluate` otherwise.

## Author(s)

N. Balov

`catNetworkEvaluate-class`
 ```1 2 3 4``` ``` cnet1 <- cnRandomCatnet(numnodes=10, maxpars=2, numcats=2) cnet2 <- cnRandomCatnet(numnodes=10, maxpars=2, numcats=2) dist <- cnCompare(object1=cnet1, object2=cnet2) dist ```