Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Create a NetGraph with a simplified rule-based interface
ResourceFunction["RuleNetGraph"][layer1→layer2→…→layern] creates a NetGraph object from the specified layers. | |
Build a simple NetGraph using a list of rules:
In[1]:= | ![]() |
Use lists of NetPort objects and layers for more complicated networks:
In[2]:= | ![]() |
Use string subscripts to manually specify layer names:
In[3]:= | ![]() |
Out[3]= | ![]() |
In[4]:= | ![]() |
Out[4]= | ![]() |
The above is equivalent to:
In[5]:= | ![]() |
And is also equivalent to:
In[6]:= | ![]() |
A list of rules can be used to specify network connections in any order:
In[7]:= | ![]() |
Out[7]= | ![]() |
Networks can be specified with multiple inputs and outputs:
In[8]:= | ![]() |
Out[8]= | ![]() |
Additional arguments are passed through RuleNetGraph to NetGraph (for example, input port size):
In[9]:= | ![]() |
RuleNetGraph can easily describe networks with complicated data flow:
In[10]:= | ![]() |
Out[11]= | ![]() |
Multiple layers cannot be declared with the same manually-assigned name:
In[12]:= | ![]() |
Out[12]= | ![]() |
You cannot reuse layers in a way that causes the output of a layer to depend on itself:
In[13]:= | ![]() |
Out[13]= | ![]() |
Manual layer names must be specified with a string subscript; non-strings prompt a message:
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
All layers must be properly declared:
In[16]:= | ![]() |
Out[16]= | ![]() |
Calling the layer with zero arguments works:
In[17]:= | ![]() |
Out[17]= | ![]() |
The first argument of RuleNetGraph must contain at least one Rule ( →):
In[18]:= | ![]() |
Out[18]= | ![]() |
In[19]:= | ![]() |
Out[19]= | ![]() |
You cannot use string subscripts on NetPort or any other parameter that is not a manually named layer:
In[20]:= | ![]() |
Out[20]= | ![]() |
You will get errors if you try to use a function that cannot be automatically converted to a neural network layer:
In[21]:= | ![]() |
Out[21]= | ![]() |
In[22]:= | ![]() |
Out[22]= | ![]() |
Be careful to properly group symbols. This gives an error:
In[23]:= | ![]() |
Out[23]= | ![]() |
Giving the pure function proper precedence with parentheses fixes it:
In[24]:= | ![]() |
Out[24]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License