Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing strange issues caused by the recent merge conflict #76

Merged
merged 1 commit into from
Mar 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/FitDetectors/DefaultFitDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

public class DefaultFitDetector<T> : FitDetectorBase<T>
{
private readonly INumericOperations<T> _numOps;

public DefaultFitDetector()
{
_numOps = MathHelper.GetNumericOperations<T>();
}

public override FitDetectorResult<T> DetectFit(ModelEvaluationData<T> evaluationData)
Expand Down
16 changes: 7 additions & 9 deletions src/NeuralNetworks/ConvolutionalNeuralNetwork.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

namespace AiDotNet.NeuralNetworks;

public class ConvolutionalNeuralNetwork<T> : NeuralNetworkBase<T>
Expand All @@ -8,7 +7,7 @@ public ConvolutionalNeuralNetwork(NeuralNetworkArchitecture<T> architecture) : b
if (architecture.InputType != InputType.ThreeDimensional)
{
throw new ArgumentException("Convolutional Neural Network requires three-dimensional input.");
}
}
}

protected override void InitializeLayers()
Expand All @@ -23,20 +22,18 @@ protected override void InitializeLayers()
{
// Use default layer configuration if no layers are provided
Layers.AddRange(LayerHelper<T>.CreateDefaultCNNLayers(Architecture));
}
}
}

public override Vector<T> Predict(Vector<T> input)
{
{
// Convert the input Vector to a Tensor with the correct shape
var inputShape = Architecture.GetInputShape();
var totalSize = inputShape.Aggregate(1, (a, b) => a * b);

if (input.Length != totalSize)
{
{
throw new ArgumentException("Input vector length must match the product of input dimensions.");
}
}
}

var inputTensor = new Tensor<T>(inputShape, input);
Expand All @@ -51,7 +48,7 @@ public override Vector<T> Predict(Vector<T> input)
public Tensor<T> Forward(Tensor<T> input)
{
if (!input.Shape.SequenceEqual(Architecture.GetInputShape()))
{
{
throw new ArgumentException("Input shape does not match the expected input shape.");
}

Expand All @@ -60,7 +57,8 @@ public Tensor<T> Forward(Tensor<T> input)
{
output = layer.Forward(output);
}
return output;

return output;
}

public Tensor<T> Backward(Tensor<T> outputGradient)
Expand Down
2 changes: 0 additions & 2 deletions src/NeuralNetworks/Layers/BatchNormalizationLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class BatchNormalizationLayer<T> : LayerBase<T>
private Vector<T>? _lastVariance;
private Vector<T>? _gammaGradient;
private Vector<T>? _betaGradient;
private bool _isTraining;

public override bool SupportsTraining => true;

Expand All @@ -27,7 +26,6 @@ public BatchNormalizationLayer(int featureSize, double epsilon = 1e-5, double mo
_beta = new Vector<T>(featureSize);
_runningMean = new Vector<T>(featureSize);
_runningVariance = Vector<T>.CreateDefault(featureSize, NumOps.One);
_isTraining = true;
}

public override Tensor<T> Forward(Tensor<T> input)
Expand Down
2 changes: 0 additions & 2 deletions src/NeuralNetworks/Layers/ConvLSTMLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,6 @@ private Tensor<T> ApplyActivationDerivative(Tensor<T> input)
return (dxt, dprevH, dprevC, cellGrads);
}

private readonly SigmoidActivation<T> _sigmoidActivation = new SigmoidActivation<T>();

private (Tensor<T> f, Tensor<T> i, Tensor<T> c, Tensor<T> o, Tensor<T> newC, Tensor<T> newH) ForwardStep(
Tensor<T> xt, Tensor<T> prevH, Tensor<T> prevC)
{
Expand Down
2 changes: 0 additions & 2 deletions src/NeuralNetworks/Layers/DropoutLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ public class DropoutLayer<T> : LayerBase<T>
private readonly T _scale;
private Tensor<T>? _lastInput;
private Tensor<T>? _dropoutMask;
private bool _isTraining;

public override bool SupportsTraining => true;

Expand All @@ -18,7 +17,6 @@ public DropoutLayer(double dropoutRate = 0.5)

_dropoutRate = NumOps.FromDouble(dropoutRate);
_scale = NumOps.FromDouble(1.0 / (1.0 - dropoutRate));
_isTraining = true;
}

public override Tensor<T> Forward(Tensor<T> input)
Expand Down
14 changes: 0 additions & 14 deletions src/NeuralNetworks/Layers/GaussianNoiseLayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ public class GaussianNoiseLayer<T> : LayerBase<T>
private readonly T _mean;
private readonly T _standardDeviation;
private Tensor<T>? _lastNoise;
private readonly Random _random;
private bool _isTraining;

public override bool SupportsTraining => false;

Expand All @@ -18,18 +16,6 @@ public GaussianNoiseLayer(
{
_mean = NumOps.FromDouble(mean);
_standardDeviation = NumOps.FromDouble(standardDeviation);
_random = new Random();
_isTraining = true;
}

public void SetTrainingMode(bool isTraining)
{
_isTraining = isTraining;
}

public bool IsTraining()
{
return _isTraining;
}

public override Tensor<T> Forward(Tensor<T> input)
Expand Down
10 changes: 2 additions & 8 deletions src/NeuralNetworks/NeuralNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ protected override void InitializeLayers()
Layers.AddRange(Architecture.Layers);
ValidateCustomLayers(Layers);
}

for (int i = 0; i < Architecture.LayerSizes.Count - 1; i++)
else
{
if (Architecture.CustomLayers != null && i < Architecture.CustomLayers.Count)
{
Layers.Add(Architecture.CustomLayers[i]);
}
else
{
// Use default layer configuration if no layers are provided
Layers.AddRange(LayerHelper<T>.CreateDefaultNeuralNetworkLayers(Architecture));
}
Expand All @@ -36,6 +29,7 @@ public override Vector<T> Predict(Vector<T> input)
{
current = layer.Forward(Tensor<T>.FromVector(current)).ToVector();
}

return current;
}

Expand Down
Loading