Skip to content

Commit b786ab5

Browse files
committed
New API indicating the total number of network parameters
1 parent 9e7176e commit b786ab5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

NeuralNetwork.NET/APIs/Interfaces/INeuralNetwork.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public interface INeuralNetwork : IEquatable<INeuralNetwork>, IClonable<INeuralN
2929
[NotNull, ItemNotNull]
3030
IReadOnlyList<INetworkLayer> Layers { get; }
3131

32+
/// <summary>
33+
/// Gets the total number of parameters in the current network layer
34+
/// </summary>
35+
int Parameters { get; }
36+
3237
#endregion
3338

3439
#region Methods

NeuralNetwork.NET/Networks/Implementations/NeuralNetwork.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,17 @@ public sealed class NeuralNetwork : INeuralNetwork
4040
/// <inheritdoc/>
4141
public IReadOnlyList<INetworkLayer> Layers => _Layers;
4242

43+
/// <inheritdoc/>
44+
[JsonProperty(nameof(Parameters), Order = 3)]
45+
public int Parameters => Layers.Sum(l => l is WeightedLayerBase weighted ? weighted.Weights.Length + weighted.Biases.Length : 0);
46+
4347
#endregion
4448

4549
/// <summary>
4650
/// The list of layers that make up the neural network
4751
/// </summary>
4852
[NotNull, ItemNotNull]
49-
[JsonProperty(nameof(Layers), Order = 3)]
53+
[JsonProperty(nameof(Layers), Order = 4)]
5054
internal readonly NetworkLayerBase[] _Layers;
5155

5256
// The list of layers with weights to update

0 commit comments

Comments
 (0)