Class Architecture<T>
Represents a neural network architecture discovered through NAS.
public class Architecture<T>
Type Parameters
TThe numeric type for calculations.
- Inheritance
-
Architecture<T>
- Inherited Members
Remarks
This class captures the structure of a neural network discovered through Neural Architecture Search (NAS). It includes the operations connecting nodes and optional channel information for cost estimation.
For Beginners: Think of this as a blueprint for a neural network. NAS algorithms explore many possible blueprints and find the best one for your task. This class stores that blueprint so you can:
- Save it to disk for later use
- Share it with others
- Load it to recreate the same network structure
Properties
NodeChannels
Optional per-node channel counts (typically output channels) used for cost estimation.
public Dictionary<int, int> NodeChannels { get; set; }
Property Value
- Dictionary<int, int>
Remarks
When provided, hardware cost models can use these values to scale operation costs more accurately (e.g., accounting for channel expansion/reduction across layers). If not provided, cost models may fall back to assuming a uniform channel count.
For Beginners: This is a simple mapping like: node 0 has 16 channels, node 1 has 32 channels, etc. Some operations change how many features (channels) flow through the network, which affects compute cost.
NodeCount
Number of nodes in the architecture
public int NodeCount { get; set; }
Property Value
Operations
Operations in the architecture: (to_node, from_node, operation)
[JsonIgnore]
public List<(int ToNode, int FromNode, string Operation)> Operations { get; set; }
Property Value
Methods
AddOperation(int, int, string)
Adds an operation to the architecture
public void AddOperation(int toNode, int fromNode, string operation)
Parameters
FromBytes(byte[])
Deserializes an architecture from a binary byte array.
public static Architecture<T> FromBytes(byte[] data)
Parameters
databyte[]The byte array to deserialize.
Returns
- Architecture<T>
The deserialized architecture.
Exceptions
- ArgumentNullException
Thrown when data is null.
- InvalidDataException
Thrown when the data format is invalid.
FromJson(string)
Deserializes an architecture from a JSON string.
public static Architecture<T> FromJson(string json)
Parameters
jsonstringThe JSON string to deserialize.
Returns
- Architecture<T>
The deserialized architecture.
Exceptions
- ArgumentNullException
Thrown when json is null.
- JsonException
Thrown when the JSON is invalid.
GetDescription()
Gets a description of the architecture.
public string GetDescription()
Returns
LoadFromFile(string)
Loads an architecture from a JSON file.
public static Architecture<T> LoadFromFile(string filePath)
Parameters
filePathstringThe path to the JSON file.
Returns
- Architecture<T>
The loaded architecture.
Exceptions
- ArgumentNullException
Thrown when filePath is null.
- FileNotFoundException
Thrown when the file doesn't exist.
- JsonException
Thrown when the JSON is invalid.
SaveToFile(string, bool)
Saves the architecture to a JSON file.
public void SaveToFile(string filePath, bool indented = true)
Parameters
Exceptions
- ArgumentNullException
Thrown when filePath is null.
- IOException
Thrown when the file cannot be written.
ToBytes()
Serializes the architecture to a binary byte array.
public byte[] ToBytes()
Returns
- byte[]
A byte array containing the serialized architecture.
Remarks
For Beginners: Binary format is more compact than JSON and faster to read/write, but you can't inspect it in a text editor. Use this for production deployments.
ToJson(bool)
Serializes the architecture to a JSON string.
public string ToJson(bool indented = true)
Parameters
indentedboolWhether to use indented formatting for readability.
Returns
- string
A JSON string representation of the architecture.
Remarks
For Beginners: JSON is a text format that's easy for both humans and computers to read. Use this method to save your architecture in a format you can inspect in a text editor.