refactor(us-ci-018): replace empty updateparameters with invalidoperationexception in specialized networks - #250
Conversation
…tionexception in specialized networks Replace empty UpdateParameters method implementations with InvalidOperationException in neural network classes that don't support traditional gradient-based parameter updates. This provides clearer API semantics and better error messages explaining why the operation isn't supported and what alternative methods should be used instead. Changes: - EchoStateNetwork: Throw InvalidOperationException explaining that only output layer weights are trained - ExtremeLearningMachine: Throw InvalidOperationException explaining that input-to-hidden weights remain fixed - NEAT: Throw InvalidOperationException explaining to use EvolvePopulation instead - RestrictedBoltzmannMachine: Throw InvalidOperationException explaining to use Train method with Contrastive Divergence This improves code clarity by making it explicit that these methods represent design choices rather than missing implementations. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary by CodeRabbit
WalkthroughFour neural network implementations (EchoStateNetwork, ExtremeLearningMachine, NEAT, and RestrictedBoltzmannMachine) have been updated to replace no-op behavior in their UpdateParameters methods with explicit exception throwing, providing descriptive messages explaining why direct parameter updates are unsupported for each architecture. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
src/NeuralNetworks/RestrictedBoltzmannMachine.cs (1)
431-454: Fix XML documentation inconsistency with exception type.The XML documentation at line 434 references
NotImplementedException:/// <exception cref="NotImplementedException"> /// Always thrown because ELM does not support traditional parameter updates. /// </exception>However, the implementation at line 453 now throws
InvalidOperationException. Update the XML documentation to match the actual exception type.Apply this diff:
/// <param name="parameters">The vector of parameter updates to apply.</param> - /// <exception cref="NotImplementedException">Always thrown as this method is not implemented for RBMs.</exception> + /// <exception cref="InvalidOperationException">Always thrown as this method is not supported for RBMs.</exception> /// <remarks>src/NeuralNetworks/EchoStateNetwork.cs (1)
1020-1047: Fix XML documentation inconsistency with exception type.The XML documentation at line 1024 references
NotImplementedException:/// <exception cref="NotImplementedException"> /// Always thrown because ESN does not support traditional parameter updates. /// </exception>However, the implementation at line 1046 now throws
InvalidOperationException. Update the XML documentation to match.Apply this diff:
/// <param name="parameters">A vector containing the parameters to update all layers with.</param> - /// <exception cref="NotImplementedException"> + /// <exception cref="InvalidOperationException"> /// Always thrown because ESN does not support traditional parameter updates. /// </exception>src/NeuralNetworks/ExtremeLearningMachine.cs (1)
121-148: Fix XML documentation inconsistency with exception type.The XML documentation at line 125 references
NotImplementedException:/// <exception cref="NotImplementedException"> /// Always thrown because ELM does not support traditional parameter updates. /// </exception>However, the implementation at line 147 now throws
InvalidOperationException. Update the XML documentation to match.Apply this diff:
/// <param name="parameters">A vector containing the parameters to update all layers with.</param> - /// <exception cref="NotImplementedException"> + /// <exception cref="InvalidOperationException"> /// Always thrown because ELM does not support traditional parameter updates. /// </exception>src/NeuralNetworks/NEAT.cs (1)
582-612: Fix XML documentation inconsistency with exception type.The XML documentation at line 586 references
NotImplementedException:/// <exception cref="NotImplementedException">Always thrown, as this method is not applicable to NEAT.</exception>However, the implementation at line 611 now throws
InvalidOperationException. Update the XML documentation to match.Apply this diff:
/// <param name="parameters">A vector containing parameters to update.</param> - /// <exception cref="NotImplementedException">Always thrown, as this method is not applicable to NEAT.</exception> + /// <exception cref="InvalidOperationException">Always thrown, as this method is not applicable to NEAT.</exception> /// <remarks>
🧹 Nitpick comments (3)
src/NeuralNetworks/RestrictedBoltzmannMachine.cs (1)
113-113: Optional cosmetic improvement: multiplication symbol.The change from
28x28to28×28uses the proper multiplication symbol, improving readability. This is a minor refinement and acceptable.src/NeuralNetworks/ExtremeLearningMachine.cs (1)
228-291: Optional: Improved mathematical notation in comments.The use of the proper pseudoinverse symbol (A†) and multiplication symbols (·) in the comments at lines 228, 260, 271, 278, 284, and 291 improves mathematical precision and readability. These cosmetic refinements are acceptable.
src/NeuralNetworks/NEAT.cs (1)
299-299: Optional cosmetic improvement: multiplication symbol.The change from
3 inputs x 2 outputsto3 inputs × 2 outputsuses the proper multiplication symbol, consistent with the other cosmetic improvements in this PR.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
src/NeuralNetworks/EchoStateNetwork.cs(1 hunks)src/NeuralNetworks/ExtremeLearningMachine.cs(4 hunks)src/NeuralNetworks/NEAT.cs(2 hunks)src/NeuralNetworks/RestrictedBoltzmannMachine.cs(2 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/NeuralNetworks/ExtremeLearningMachine.cs (1)
src/NeuralNetworks/EchoStateNetwork.cs (3)
Matrix(629-648)Matrix(1319-1405)Matrix(1687-1703)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build All Frameworks
🔇 Additional comments (4)
src/NeuralNetworks/RestrictedBoltzmannMachine.cs (1)
453-453: Excellent error message: descriptive and actionable.The exception message clearly explains why direct parameter updates aren't supported and directs users to the appropriate alternative (Train method with Contrastive Divergence). This follows good API design practices.
src/NeuralNetworks/EchoStateNetwork.cs (1)
1046-1046: Clear and accurate exception message.The message correctly explains that ESN reservoir weights remain fixed and only output layer weights are trained via ridge regression in the Train method. This aligns well with ESN architecture principles.
src/NeuralNetworks/ExtremeLearningMachine.cs (1)
147-147: Well-crafted exception message for ELM.The message precisely describes the ELM training paradigm: fixed random input-to-hidden weights and analytically computed output weights. This provides clear guidance to users.
src/NeuralNetworks/NEAT.cs (1)
611-611: Comprehensive exception message for NEAT.The exception message effectively communicates that NEAT uses evolutionary algorithms (EvolvePopulation) rather than gradient-based parameter updates. The message is clear and actionable.
Accept master's InvalidOperationException approach for UpdateParameters in: - ExtremeLearningMachine.cs - NEAT.cs - RestrictedBoltzmannMachine.cs PR #250 (already merged) established that specialized networks should throw InvalidOperationException for UpdateParameters instead of implementing them. Critical bug fixes from this PR remain intact: - SelfOrganizingMap array comparison fix - RestrictedBoltzmannMachine weight indexing fix - EchoStateNetwork file restoration Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Resolved conflicts in UpdateParameters methods for 4 specialized neural networks - Kept master's InvalidOperationException approach (from PR #250) - These networks don't support direct parameter updates: * EchoStateNetwork - uses Train method with reservoir computing * ExtremeLearningMachine - uses analytical weight calculation * NEAT - uses EvolvePopulation with genetic algorithms * RestrictedBoltzmannMachine - uses Contrastive Divergence training Note: Pre-existing build errors in ModelIndividualTests.cs (from PR #244) remain
Summary
Replace empty
UpdateParametersmethod implementations withInvalidOperationExceptionin neural network classes that don't support traditional gradient-based parameter updates. This provides clearer API semantics and better error messages explaining why the operation isn't supported and what alternative methods should be used instead.Changes
InvalidOperationExceptionexplaining that only output layer weights are trained via Train method; reservoir weights remain fixedInvalidOperationExceptionexplaining that input-to-hidden weights are randomly initialized and remain fixed; only output layer weights are computed analyticallyInvalidOperationExceptionexplaining to useEvolvePopulationmethod instead of gradient-based updatesInvalidOperationExceptionexplaining to useTrainmethod with Contrastive DivergenceRationale
Previously, these methods had empty implementations with only comments. According to the user story US-CI-018, classes that don't use traditional parameter updates should throw
InvalidOperationExceptionwith clear explanatory messages. This change:HopfieldNetworkTesting
Related
🤖 Generated with Claude Code