Skip to content

Commit be8692f

Browse files
committed
To First Real Release
1 parent 2eccdc0 commit be8692f

13 files changed

Lines changed: 110 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.0.0] - 2023-05-04
11+
12+
### Added
13+
14+
- Regularization to the Networking (Dropout, L1 and L2)
15+
- Newtonsoft.Json dll to allow Architecture gathering
16+
1017
## [0.8.0] - 2023-05-03
1118

1219
### Changed
@@ -122,7 +129,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
122129
- PointComputations.cs, to facilitate convex hull computation, point cloud simplification, and continuing on, any solely point-based methods.
123130
- Conversion.cs, to allow conversion of Vector types.
124131

125-
[unreleased]: https://github.com/IrishFix/Computational-Geometry/compare/v0.8.0...HEAD
132+
[unreleased]: https://github.com/IrishFix/Computational-Geometry/compare/v1.0.0...HEAD
133+
[0.8.0]: https://github.com/IrishFix/Computational-Geometry/compare/v0.8.0...v1.0.0
126134
[0.8.0]: https://github.com/IrishFix/Computational-Geometry/compare/v0.7.0...v0.8.0
127135
[0.7.0]: https://github.com/IrishFix/Computational-Geometry/compare/v0.6.0...v0.7.0
128136
[0.6.0]: https://github.com/IrishFix/Computational-Geometry/compare/v0.5.0...v0.6.0

Runtime/Networking/Layers/Dense.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using UniversalNumerics.Networking.Activations;
5+
using UniversalNumerics.Networking.Regularizers;
56

67
// ReSharper disable MemberCanBePrivate.Global
78
// ReSharper disable once CheckNamespace
@@ -13,6 +14,7 @@ public class Dense : ILayer {
1314
public int OutputCount;
1415

1516
public IActivationFunction Activation;
17+
public IRegularizer Regularization;
1618

1719
public double[][] Weights;
1820
public double[] Biases;
@@ -23,10 +25,11 @@ public class Dense : ILayer {
2325
public double[][] WeightsGradients;
2426
public double[] BiasesGradients;
2527

26-
public Dense(int NumNeurons, IActivationFunction ActivationFunc) {
28+
public Dense(int NumNeurons, IActivationFunction ActivationFunc, IRegularizer Regularizer=null) {
2729
InputCount = 0;
2830
OutputCount = NumNeurons;
2931
Activation = ActivationFunc;
32+
Regularization = Regularizer;
3033
}
3134

3235
public double[][] Forward(double[][] Batch) {
@@ -49,6 +52,7 @@ public double[][] Forward(double[][] Batch) {
4952

5053
Outputs = Activation.BatchActivate(preActivation);;
5154
Inputs = Batch;
55+
5256
return Outputs;
5357
}
5458

Runtime/Networking/MLP.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public MLP(MLP templateNetwork) {
3737
}
3838
}
3939

40-
Dense clonedLayer = new Dense(layer.OutputCount, layer.Activation) {
40+
Dense clonedLayer = new Dense(layer.OutputCount, layer.Activation, layer.Regularization) {
4141
InputCount = layer.InputCount,
4242
Weights = clonedWeights,
4343
Biases = layer.Biases.ToArray()
@@ -81,6 +81,10 @@ public MLP Fit(double[][][] X, double[][][] y, int Epochs, IOptimizer Optimizer)
8181
for (int Epoch = 0; Epoch < Epochs; Epoch++) {
8282
double epochError = 0;
8383
for (int i = 0; i < inputCount; i++) {
84+
foreach (Dense Layer in Layers) {
85+
Layer.Regularization?.Regularize(Layer);
86+
}
87+
8488
double[][] output = Forward(X[i]);
8589
double error = Loss.MSE(y[i], output);
8690

Runtime/Networking/Regularizers.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using UniversalNumerics.Networking.Layers;
3+
4+
// ReSharper disable once CheckNamespace
5+
namespace UniversalNumerics.Networking.Regularizers {
6+
public class Dropout : IRegularizer {
7+
private readonly double DropoutRate;
8+
private readonly Random Rand;
9+
10+
public Dropout(double dropoutRate) {
11+
DropoutRate = dropoutRate;
12+
Rand = new Random();
13+
}
14+
15+
public void Regularize(Dense layer) {
16+
for (int i = 0; i < layer.OutputCount; i++) {
17+
for (int j = 0; j < layer.InputCount; j++) {
18+
if (Rand.NextDouble() < DropoutRate) {
19+
layer.Weights[i][j] = 0;
20+
}
21+
}
22+
}
23+
}
24+
}
25+
}

Runtime/Networking/Regularizers/Dropout.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using UniversalNumerics.Networking.Layers;
2+
3+
// ReSharper disable once CheckNamespace
4+
namespace UniversalNumerics.Networking.Regularizers {
5+
public interface IRegularizer {
6+
public void Regularize(Dense Layer);
7+
}
8+
}

Runtime/Networking/Regularizers/IRegularizer.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using UniversalNumerics.Networking.Layers;
3+
4+
// ReSharper disable once CheckNamespace
5+
namespace UniversalNumerics.Networking.Regularizers {
6+
public class L1: IRegularizer {
7+
private readonly double Strength;
8+
9+
public L1(double strength) {
10+
Strength = strength;
11+
}
12+
13+
public void Regularize(Dense layer) {
14+
for (int i = 0; i < layer.OutputCount; i++) {
15+
for (int j = 0; j < layer.InputCount; j++) {
16+
double sign = Math.Sign(layer.Weights[i][j]);
17+
layer.Weights[i][j] -= Strength * sign;
18+
}
19+
}
20+
}
21+
}
22+
}

Runtime/Networking/Regularizers/L1.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)