Skip to content

Commit 6cdfdf7

Browse files
committed
Started adding documentation for classes and methods as well as creating new validation and custom exceptions
1 parent fa9c06f commit 6cdfdf7

33 files changed

+2848
-99
lines changed

src/AiDotNet.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
<Folder Include="Evaluation\" />
5151
<Folder Include="Caching\" />
5252
<Folder Include="GaussianProcesses\" />
53+
<Folder Include="Exceptions\" />
54+
<Folder Include="Validation\" />
5355
<Folder Include="WindowFunctions\" />
5456
<Folder Include="WaveletFunctions\" />
5557
</ItemGroup>

src/DocumentationProcess.md

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
```markdown
2+
# Documentation Process for AiDotNet
3+
4+
This document outlines the process for systematically documenting all classes in the AiDotNet project.
5+
6+
## Documentation Workflow
7+
8+
1. **Prioritize Classes**:
9+
- Start with core classes that are most frequently used
10+
- Then move to supporting classes
11+
- Finally document utility and helper classes
12+
13+
2. **Documentation Checklist for Each Class**:
14+
- [ ] Class-level documentation
15+
- [ ] Property documentation
16+
- [ ] Constructor documentation
17+
- [ ] Public method documentation
18+
- [ ] Protected/internal method documentation if relevant for extenders
19+
- [ ] Examples of usage in complex cases
20+
21+
3. **Review Process**:
22+
- Self-review: Check for clarity, completeness, and accuracy
23+
- Peer review: Have another team member review the documentation
24+
- Beginner review (if possible): Have someone unfamiliar with the code read the documentation to verify clarity
25+
26+
## Documentation Tools
27+
28+
- Use Visual Studio's built-in XML documentation features
29+
- Consider using GhostDoc extension for Visual Studio to generate initial documentation templates
30+
- Use DocFX to generate documentation websites from XML comments
31+
32+
## Tracking Progress
33+
34+
Create a documentation tracking spreadsheet with the following columns:
35+
- Class name
36+
- Namespace
37+
- Documentation status (Not Started, In Progress, Complete)
38+
- Reviewer
39+
- Review status
40+
- Priority (High, Medium, Low)
41+
42+
## Documentation Automation
43+
44+
Consider creating a script to:
45+
1. Identify classes without proper documentation
46+
2. Generate basic documentation templates
47+
3. Report on documentation coverage
48+
49+
Example PowerShell script to find classes with missing documentation:
50+
51+
```powershell
52+
Get-ChildItem -Path "C:\Users\yolan\source\repos\AiDotNet\src" -Filter "*.cs" -Recurse |
53+
ForEach-Object {
54+
$content = Get-Content $_.FullName -Raw
55+
if ($content -match "public class" -and $content -notmatch "/// <summary>") {
56+
Write-Output "Missing documentation: $($_.FullName)"
57+
}
58+
}

src/Exceptions/AiDotNetException.cs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace AiDotNet.Exceptions;
2+
3+
/// <summary>
4+
/// Base exception for all AiDotNet-specific exceptions.
5+
/// </summary>
6+
public class AiDotNetException : Exception
7+
{
8+
/// <summary>
9+
/// Initializes a new instance of the <see cref="AiDotNetException"/> class.
10+
/// </summary>
11+
public AiDotNetException() : base() { }
12+
13+
/// <summary>
14+
/// Initializes a new instance of the <see cref="AiDotNetException"/> class with a specified error message.
15+
/// </summary>
16+
/// <param name="message">The message that describes the error.</param>
17+
public AiDotNetException(string message) : base(message) { }
18+
19+
/// <summary>
20+
/// Initializes a new instance of the <see cref="AiDotNetException"/> class with a specified error message
21+
/// and a reference to the inner exception that is the cause of this exception.
22+
/// </summary>
23+
/// <param name="message">The message that describes the error.</param>
24+
/// <param name="innerException">The exception that is the cause of the current exception.</param>
25+
public AiDotNetException(string message, Exception innerException) : base(message, innerException) { }
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace AiDotNet.Exceptions;
2+
3+
/// <summary>
4+
/// Exception thrown when an operation is attempted before a required forward pass has been completed.
5+
/// </summary>
6+
public class ForwardPassRequiredException : AiDotNetException
7+
{
8+
/// <summary>
9+
/// The name of the component where the exception occurred.
10+
/// </summary>
11+
public string ComponentName { get; }
12+
13+
/// <summary>
14+
/// The type of the component where the exception occurred.
15+
/// </summary>
16+
public string ComponentType { get; }
17+
18+
/// <summary>
19+
/// The operation that was attempted.
20+
/// </summary>
21+
public string Operation { get; }
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="ForwardPassRequiredException"/> class for a layer.
25+
/// </summary>
26+
/// <param name="layerName">The name of the layer where the exception occurred.</param>
27+
/// <param name="layerType">The type of the layer where the exception occurred.</param>
28+
public ForwardPassRequiredException(string layerName, string layerType)
29+
: base($"Forward pass must be called before backward pass in layer '{layerName}' of type {layerType}.")
30+
{
31+
ComponentName = layerName;
32+
ComponentType = layerType;
33+
Operation = "backward pass";
34+
}
35+
36+
/// <summary>
37+
/// Initializes a new instance of the <see cref="ForwardPassRequiredException"/> class.
38+
/// </summary>
39+
/// <param name="componentName">The name of the component where the exception occurred.</param>
40+
/// <param name="componentType">The type of the component where the exception occurred.</param>
41+
/// <param name="operation">The operation that was attempted.</param>
42+
public ForwardPassRequiredException(string componentName, string componentType, string operation)
43+
: base($"Forward pass must be called before {operation} in {componentType} '{componentName}'.")
44+
{
45+
ComponentName = componentName;
46+
ComponentType = componentType;
47+
Operation = operation;
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
namespace AiDotNet.Exceptions;
2+
3+
/// <summary>
4+
/// Exception thrown when input data dimensions are invalid for a specific algorithm or operation.
5+
/// </summary>
6+
public class InvalidInputDimensionException : Exception
7+
{
8+
/// <summary>
9+
/// Creates a new instance of the InvalidInputDimensionException class.
10+
/// </summary>
11+
public InvalidInputDimensionException() : base() { }
12+
13+
/// <summary>
14+
/// Creates a new instance of the InvalidInputDimensionException class with a specified error message.
15+
/// </summary>
16+
/// <param name="message">The message that describes the error.</param>
17+
public InvalidInputDimensionException(string message) : base(message) { }
18+
19+
/// <summary>
20+
/// Creates a new instance of the InvalidInputDimensionException class with a specified error message
21+
/// and a reference to the inner exception that is the cause of this exception.
22+
/// </summary>
23+
/// <param name="message">The message that describes the error.</param>
24+
/// <param name="innerException">The exception that is the cause of the current exception.</param>
25+
public InvalidInputDimensionException(string message, Exception innerException)
26+
: base(message, innerException) { }
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace AiDotNet.Exceptions;
2+
3+
/// <summary>
4+
/// Exception thrown when a neural network receives an input type that doesn't match its requirements.
5+
/// </summary>
6+
public class InvalidInputTypeException : AiDotNetException
7+
{
8+
/// <summary>
9+
/// The expected input type for the neural network.
10+
/// </summary>
11+
public InputType ExpectedInputType { get; }
12+
13+
/// <summary>
14+
/// The actual input type provided.
15+
/// </summary>
16+
public InputType ActualInputType { get; }
17+
18+
/// <summary>
19+
/// The type of neural network that requires the specific input type.
20+
/// </summary>
21+
public string NetworkType { get; }
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="InvalidInputTypeException"/> class.
25+
/// </summary>
26+
/// <param name="expectedInputType">The expected input type for the neural network.</param>
27+
/// <param name="actualInputType">The actual input type provided.</param>
28+
/// <param name="networkType">The type of neural network that requires the specific input type.</param>
29+
public InvalidInputTypeException(InputType expectedInputType, InputType actualInputType, string networkType)
30+
: base(FormatMessage(expectedInputType, actualInputType, networkType))
31+
{
32+
ExpectedInputType = expectedInputType;
33+
ActualInputType = actualInputType;
34+
NetworkType = networkType;
35+
}
36+
37+
private static string FormatMessage(InputType expectedInputType, InputType actualInputType, string networkType)
38+
{
39+
return $"{networkType} requires {expectedInputType} input, but received {actualInputType} input.";
40+
}
41+
}
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace AiDotNet.Exceptions;
2+
3+
/// <summary>
4+
/// Exception thrown when there's an error during serialization or deserialization of a neural network.
5+
/// </summary>
6+
public class SerializationException : AiDotNetException
7+
{
8+
/// <summary>
9+
/// The component where the serialization error occurred.
10+
/// </summary>
11+
public string Component { get; }
12+
13+
/// <summary>
14+
/// The operation being performed when the error was detected (e.g., "Serialize", "Deserialize").
15+
/// </summary>
16+
public string Operation { get; }
17+
18+
/// <summary>
19+
/// Initializes a new instance of the <see cref="SerializationException"/> class.
20+
/// </summary>
21+
/// <param name="message">The error message.</param>
22+
/// <param name="component">The component where the serialization error occurred.</param>
23+
/// <param name="operation">The operation being performed when the error was detected.</param>
24+
public SerializationException(string message, string component, string operation)
25+
: base(FormatMessage(message, component, operation))
26+
{
27+
Component = component;
28+
Operation = operation;
29+
}
30+
31+
/// <summary>
32+
/// Initializes a new instance of the <see cref="SerializationException"/> class with an inner exception.
33+
/// </summary>
34+
/// <param name="message">The error message.</param>
35+
/// <param name="component">The component where the serialization error occurred.</param>
36+
/// <param name="operation">The operation being performed when the error was detected.</param>
37+
/// <param name="innerException">The inner exception that caused this exception.</param>
38+
public SerializationException(string message, string component, string operation, Exception innerException)
39+
: base(FormatMessage(message, component, operation), innerException)
40+
{
41+
Component = component;
42+
Operation = operation;
43+
}
44+
45+
private static string FormatMessage(string message, string component, string operation)
46+
{
47+
return $"Serialization error in {component} during {operation}: {message}";
48+
}
49+
}
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
namespace AiDotNet.Exceptions;
2+
3+
/// <summary>
4+
/// Exception thrown when a tensor's dimension doesn't match the expected value.
5+
/// </summary>
6+
public class TensorDimensionException : AiDotNetException
7+
{
8+
/// <summary>
9+
/// The index of the dimension that doesn't match.
10+
/// </summary>
11+
public int DimensionIndex { get; }
12+
13+
/// <summary>
14+
/// The expected value of the dimension.
15+
/// </summary>
16+
public int ExpectedValue { get; }
17+
18+
/// <summary>
19+
/// The actual value of the dimension.
20+
/// </summary>
21+
public int ActualValue { get; }
22+
23+
/// <summary>
24+
/// The component where the dimension mismatch occurred.
25+
/// </summary>
26+
public string Component { get; }
27+
28+
/// <summary>
29+
/// The operation being performed when the mismatch was detected.
30+
/// </summary>
31+
public string Operation { get; }
32+
33+
/// <summary>
34+
/// Initializes a new instance of the <see cref="TensorDimensionException"/> class.
35+
/// </summary>
36+
/// <param name="dimensionIndex">The index of the dimension that doesn't match.</param>
37+
/// <param name="expectedValue">The expected value of the dimension.</param>
38+
/// <param name="actualValue">The actual value of the dimension.</param>
39+
/// <param name="component">The component where the dimension mismatch occurred.</param>
40+
/// <param name="operation">The operation being performed when the mismatch was detected.</param>
41+
public TensorDimensionException(int dimensionIndex, int expectedValue, int actualValue, string component, string operation)
42+
: base(FormatMessage(dimensionIndex, expectedValue, actualValue, component, operation))
43+
{
44+
DimensionIndex = dimensionIndex;
45+
ExpectedValue = expectedValue;
46+
ActualValue = actualValue;
47+
Component = component;
48+
Operation = operation;
49+
}
50+
51+
private static string FormatMessage(int dimensionIndex, int expectedValue, int actualValue, string component, string operation)
52+
{
53+
return $"Dimension mismatch in {component} during {operation}: " +
54+
$"Expected dimension {dimensionIndex} to be {expectedValue}, but got {actualValue}.";
55+
}
56+
}

src/Exceptions/TensorRankException.cs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
namespace AiDotNet.Exceptions;
2+
3+
/// <summary>
4+
/// Exception thrown when a tensor's rank doesn't match the expected rank.
5+
/// </summary>
6+
public class TensorRankException : AiDotNetException
7+
{
8+
/// <summary>
9+
/// The expected rank of the tensor.
10+
/// </summary>
11+
public int ExpectedRank { get; }
12+
13+
/// <summary>
14+
/// The actual rank of the tensor.
15+
/// </summary>
16+
public int ActualRank { get; }
17+
18+
/// <summary>
19+
/// The component where the rank mismatch occurred.
20+
/// </summary>
21+
public string Component { get; }
22+
23+
/// <summary>
24+
/// The operation being performed when the mismatch was detected.
25+
/// </summary>
26+
public string Operation { get; }
27+
28+
/// <summary>
29+
/// Initializes a new instance of the <see cref="TensorRankException"/> class.
30+
/// </summary>
31+
/// <param name="expectedRank">The expected rank of the tensor.</param>
32+
/// <param name="actualRank">The actual rank of the tensor.</param>
33+
/// <param name="component">The component where the rank mismatch occurred.</param>
34+
/// <param name="operation">The operation being performed when the mismatch was detected.</param>
35+
public TensorRankException(int expectedRank, int actualRank, string component, string operation)
36+
: base(FormatMessage(expectedRank, actualRank, component, operation))
37+
{
38+
ExpectedRank = expectedRank;
39+
ActualRank = actualRank;
40+
Component = component;
41+
Operation = operation;
42+
}
43+
44+
private static string FormatMessage(int expectedRank, int actualRank, string component, string operation)
45+
{
46+
return $"Rank mismatch in {component} during {operation}: " +
47+
$"Expected rank {expectedRank}, but got {actualRank}.";
48+
}
49+
}

0 commit comments

Comments
 (0)