# Wolfram Function Repository

Instant-use add-on functions for the Wolfram Language

Function Repository Resource:

Contract a subset of vertices in a NetGraph or NetChain into a single vertex

Contributed by:
Maria Sargsyan

ResourceFunction["NetContract"][ performs all the contractions specified by the |

The patterns can be only string patterns such as RegularExpression[*regex*], *s*_{1}~~ s_{2} ~~… or pure functions which operate on strings.

In ResourceFunction["NetContract"][*net*,{*start*,*end*}, …], the {*start*, *end*} can be any *start* and *end* specified in NetTake[*net*, {*start*, *end*}].

Define a net:

In[1]:= |

Out[1]= |

Obtain a new net by contracting everything from the starting to the ending node:

In[2]:= |

Out[2]= |

Give a new name to the contracted group of vertices:

In[3]:= |

Out[3]= |

Contract all the vertices after "1/a" and before "1/c":

In[4]:= |

Out[4]= |

Contract all the vertices which start with the name "1/":

In[5]:= |

Out[5]= |

Contract all the vertices which match a RegularExpression:

In[6]:= |

Out[6]= |

Contract all the vertices which match a StringExpression:

In[7]:= |

Out[7]= |

Contract all the vertices which match a pure function:

In[8]:= |

Out[8]= |

Contract several sets of vertices:

In[9]:= |

Out[9]= |

Simplify the net by combining ThreadingLayer and LogisticSigmoid into a single layer:

In[10]:= |

Out[10]= |

Create a new net:

In[11]:= |

Out[11]= |

Note that the new net is a bit faster:

In[12]:= |

In[13]:= |

Out[13]= |

In[14]:= |

Out[14]= |

- 1.0.0 – 01 November 2022

This work is licensed under a Creative Commons Attribution 4.0 International License