SuperNet<T>
Models & Types · AiDotNet.NeuralNetworks
SuperNet implementation for gradient-based neural architecture search (DARTS). Implements a differentiable architecture search by maintaining architecture parameters (alpha) and network weights simultaneously.
Inheritance: ModelBase<T, Tensor<T>, Tensor<T>> → SuperNet<T>
Implements: IGeneratedParameterRegistrar<T>
For Beginners
A SuperNet is a “network of all possible networks.” It contains every candidate architecture within a single large network, with learnable weights that determine which operations are most important. During architecture search, the SuperNet trains these weights using gradient descent, and the final architecture is derived by selecting the operations with the highest weights. This is the core mechanism behind DARTS-style neural architecture search.
Example
var searchSpace = new SearchSpaceBase<float>();
var trainX = Tensor<float>.CreateRandom(4, 8);
var trainY = Tensor<float>.CreateRandom(4, 2);
var result = new AiModelBuilder<float, Tensor<float>, Tensor<float>>()
.ConfigureModel(new SuperNet<float>(searchSpace, numNodes: 4))
.Build(trainX, trainY);
var inputTensor = Tensor<float>.CreateRandom(2, 4);
result.Predict(inputTensor);
// The winning design, ready to train on its own.
var architecture = result.DeriveArchitecture();
Constructors
| Constructor | Summary |
|---|---|
SuperNet(SearchSpaceBase<T> searchSpace, int numNodes, ILossFunction<T> lossFunction) |
Initializes a new SuperNet for differentiable architecture search. |
Properties
| Property | Summary |
|---|---|
ILossFunction<T> DefaultLossFunction { get; } |
Gets the default loss function used by this model for gradient computation. |
string[] FeatureNames { get; set; } |
Methods
| Method | Summary |
|---|---|
Architecture<T> DeriveArchitecture() |
Derives discrete architecture from continuous parameters (argmax selection) |
Dictionary<string, T> GetFeatureImportance() |
|
Dictionary<string, Vector<T>> GetWeightGradients() |
Gets weight gradients |
Dictionary<string, Vector<T>> GetWeightParameters() |
Gets weight parameters for optimization |
IEnumerable<int> GetActiveFeatureIndices() |
|
IFullModel<T, Tensor<T>, Tensor<T>> WithParameters(Vector<T> parameters) |
|
List<Matrix<T>> GetArchitectureGradients() |
Gets architecture gradients |
List<Matrix<T>> GetArchitectureParameters() |
Gets architecture parameters for optimization |
ModelMetadata<T> GetModelMetadata() |
|
T ComputeTrainingLoss(Tensor<T> trainData, Tensor<T> trainLabels) |
Computes training loss for weight updates |
T ComputeValidationLoss(Tensor<T> valData, Tensor<T> valLabels) |
Computes validation loss for architecture parameter updates |
Task<AnchorExplanation<T>> GetAnchorExplanationAsync(Tensor<T> input, T threshold) |
Gets anchor explanation for a given input. |
Task<CounterfactualExplanation<T>> GetCounterfactualAsync(Tensor<T> input, Tensor<T> desiredOutput, int maxChanges) |
Gets counterfactual explanation for a given input and desired output. |
Task<Dictionary<int, T>> GetGlobalFeatureImportanceAsync(Tensor<T> inputs) |
Gets the operation importance for SuperNet architecture search. |
Task<Dictionary<int, T>> GetLocalFeatureImportanceAsync(Tensor<T> input) |
Gets the local feature importance for a specific input. |
Task<Dictionary<string, object>> GetModelSpecificInterpretabilityAsync() |
Gets model-specific interpretability information for SuperNet. |
Task<FairnessMetrics<T>> ValidateFairnessAsync(Tensor<T> inputs, int sensitiveFeatureIndex) |
Validates fairness metrics for the given inputs. |
Task<LimeExplanation<T>> GetLimeExplanationAsync(Tensor<T> input, int numFeatures) |
Gets LIME explanation for a specific input. |
Task<Matrix<T>> GetShapValuesAsync(Tensor<T> inputs) |
Gets SHAP values for the given inputs. |
Task<PartialDependenceData<T>> GetPartialDependenceAsync(Vector<int> featureIndices, int gridResolution) |
Gets partial dependence data for specified features. |
Task<T> GetFeatureInteractionAsync(int feature1Index, int feature2Index) |
Gets feature interaction effects between two features. |
Task<string> GenerateTextExplanationAsync(Tensor<T> input, Tensor<T> prediction) |
Generates a text explanation for a prediction. |
Tensor<T> Predict(Tensor<T> input) |
Forward pass through the SuperNet with mixed operations |
ValueTuple<T, T> TrainStep(Tensor<T> trainInput, Tensor<T> trainTarget, Tensor<T> validationInput, Tensor<T> validationTarget) |
One step of first-order DARTS: the architecture on the validation batch, then the weights on the training batch (Liu et al. |
Vector<T> ComputeGradients(Tensor<T> input, Tensor<T> target, ILossFunction<T> lossFunction) |
Computes gradients of the loss function with respect to model parameters WITHOUT updating parameters. |
bool IsFeatureUsed(int featureIndex) |
|
void ApplyGradients(Vector<T> gradients, T learningRate) |
Applies pre-computed gradients to update the model parameters. |
void BackwardArchitecture(Tensor<T> input, Tensor<T> target) |
Computes the exact gradient of the loss with respect to the architecture parameters, into GetArchitectureGradients. |
void BackwardWeights(Tensor<T> input, Tensor<T> target, ILossFunction<T> lossFunction) |
Computes the exact gradient of lossFunction with respect to the operation weights, into GetWeightGradients. |
void ConfigureFairness(Vector<int> sensitiveFeatures, FairnessMetric[] fairnessMetrics) |
Configures fairness evaluation settings. |
void EnableMethod(InterpretationMethod[] methods) |
Enables specific interpretation methods. |
void LoadModel(string filePath) |
|
void LoadState(Stream stream) |
Loads the SuperNet’s state (architecture parameters and weights) from a stream. |
void SaveModel(string filePath) |
|
void SaveState(Stream stream) |
Saves the SuperNet’s current state (architecture parameters and weights) to a stream. |
void SetActiveFeatureIndices(IEnumerable<int> featureIndices) |
|
void SetBaseModel(IModel<Tensor<T>, Tensor<T>, ModelMetadata<T>> model) |
Sets the base model for interpretability analysis. |
void Train(Tensor<T> input, Tensor<T> expectedOutput) |
One step of first-order differentiable architecture search on a single batch. |