make.crf {CRF} | R Documentation |

## Make CRF

### Description

Generate CRF from the adjacent matrix

### Usage

```
make.crf(adj.matrix = NULL, n.states = 2, n.nodes = 2)
```

### Arguments

`adj.matrix` |
The adjacent matrix of CRF network. |

`n.states` |
The state numbers of nodes. |

`n.nodes` |
The number of nodes, which is only used to generate linear chain CRF when |

### Details

The function will generate an empty CRF from a given adjacent
matrix. If the length of `nstates`

is less than `n.nodes`

, it will
be used repeatly. All node and edge potentials are initilized as 1.

Since the CRF data are often very huge, CRF is implemented as an environment.
The assignment of environments will only copy the addresses instead of real data,
therefore the variables using normal assignment will refer to the exactly same CRF.
For complete duplication of the data, please use `duplicate.crf`

.

### Value

The function will return a new CRF, which is an environment with components:

`n.nodes` |
The number of nodes. |

`n.edges` |
The number of edges. |

`n.states` |
The number of states for each node. It is a vector of length |

`max.state` |
The maximum number of states. It is equal to |

`edges` |
The node pair of each edge. It is a matrix with 2 columns and |

`n.adj` |
The number of adjacent nodes for each node. It is a vector of length |

`adj.nodes` |
The list of adjacent nodes for each
node. It is a list of length |

`adj.edges` |
The list of adjacent edges for each node. It is similiar to |

`node.pot` |
The node potentials. It is a matrix with dimmension |

`edge.pot` |
The edge potentials. It is a list of |

### See Also

`duplicate.crf`

, `clamp.crf`

, `sub.crf`

### Examples

```
library(CRF)
nNodes <- 4
nStates <- 2
adj <- matrix(0, nrow=nNodes, ncol=nNodes)
for (i in 1:(nNodes-1))
{
adj[i,i+1] <- 1
adj[i+1,i] <- 1
}
crf <- make.crf(adj, nStates)
crf$node.pot[1,] <- c(1, 3)
crf$node.pot[2,] <- c(9, 1)
crf$node.pot[3,] <- c(1, 3)
crf$node.pot[4,] <- c(9, 1)
for (i in 1:crf$n.edges)
{
crf$edge.pot[[i]][1,] <- c(2, 1)
crf$edge.pot[[i]][2,] <- c(1, 2)
}
```

*CRF*version 0.4-3 Index]