Skip to content

[US-IF-005]: Implement cross-domain transfer learning - #170

Merged
ooples merged 35 commits into
merge-dev2-to-masterfrom
fix/us-if-005-transfer-learning
Oct 23, 2025
Merged

ooples merged 35 commits into
merge-dev2-to-masterfrom
fix/us-if-005-transfer-learning

Conversation

@ooples

@ooples ooples commented Oct 23, 2025

Copy link
Copy Markdown
Owner

Summary

  • Implemented TransferCrossDomain method for TransferNeuralNetwork with feature mapping and knowledge distillation
  • Implemented TransferCrossDomain method for TransferRandomForest with domain adaptation and model wrapping
  • Fixed pre-existing syntax error in BayesianOptimizerOptions.cs (missing Kernel property declaration)

Implementation Details

TransferNeuralNetwork

  • Validates that FeatureMapper is set and trained before proceeding
  • Maps target data to source feature space using the trained mapper
  • Applies knowledge distillation by combining source model predictions with true labels
  • Trains a new model on the target domain with combined labels

TransferRandomForest

  • Validates that FeatureMapper is set and trained before proceeding
  • Maps target features to source feature space
  • Optionally applies domain adaptation if DomainAdapter is available and trained
  • Uses knowledge distillation with pseudo-labels from source model
  • Wraps the resulting model in MappedRandomForestModel for proper feature handling

Additional Fix

  • Fixed corrupted property declaration in BayesianOptimizerOptions.cs that was causing build errors

🤖 Generated with Claude Code

ooples and others added 12 commits October 22, 2025 00:38
…ialize; map feature importance keys via mapper reflection when available
…ove duplication and validate target features
…agic constant, fix brace formatting, improve LoadModel error handling
…rithms

- Implement TransferCrossDomain for TransferNeuralNetwork with feature mapping and knowledge distillation
- Implement TransferCrossDomain for TransferRandomForest with domain adaptation and model wrapping
- Fix syntax error in BayesianOptimizerOptions.cs (missing Kernel property declaration)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 23, 2025 03:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements cross-domain transfer learning capabilities for neural networks and random forests by replacing placeholder NotImplementedException code with functional implementations using feature mapping and knowledge distillation techniques. A pre-existing syntax error in BayesianOptimizerOptions.cs has also been fixed.

Key changes:

  • Implemented TransferCrossDomain methods for both TransferNeuralNetwork and TransferRandomForest classes with feature mapping validation and knowledge distillation
  • Enhanced MappedRandomForestModel with serialization, feature importance mapping, and model persistence capabilities
  • Fixed corrupted property declaration in BayesianOptimizerOptions.cs

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
src/TransferLearning/Algorithms/TransferRandomForest.cs Implements cross-domain transfer with feature mapping, domain adaptation, and knowledge distillation; adds full serialization and model persistence to MappedRandomForestModel wrapper
src/TransferLearning/Algorithms/TransferNeuralNetwork.cs Implements cross-domain transfer using feature mapping and label combination for knowledge distillation
src/Models/Options/BayesianOptimizerOptions.cs Repairs malformed property declaration by moving misplaced code fragment to correct location

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/TransferLearning/Algorithms/TransferRandomForest.cs Outdated
Comment thread src/TransferLearning/Algorithms/TransferRandomForest.cs Outdated
Comment thread src/TransferLearning/Algorithms/TransferRandomForest.cs Outdated
Comment thread src/TransferLearning/Algorithms/TransferRandomForest.cs Outdated
Comment thread src/TransferLearning/Algorithms/TransferRandomForest.cs Outdated
ooples and others added 2 commits October 22, 2025 23:52
- Add periods to all inline comments for consistency
- Replace unused exception variables with discard pattern

Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…s-if-005-transfer-learning

# Conflicts:
#	src/Models/Options/BayesianOptimizerOptions.cs
#	src/TransferLearning/Algorithms/TransferRandomForest.cs
Copilot AI review requested due to automatic review settings October 23, 2025 04:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/TransferLearning/Algorithms/TransferNeuralNetwork.cs Outdated
ooples and others added 2 commits October 23, 2025 00:24
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
…soft labels

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 23, 2025 04:55

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/TransferLearning/Algorithms/TransferNeuralNetwork.cs Outdated
ooples and others added 2 commits October 23, 2025 01:07
…tion weight

- Train on mappedTargetData instead of targetData to match feature space used for soft label generation
- Extract magic number 0.7 to KnowledgeDistillationWeight constant with documentation
- Ensures consistency between soft label generation and model training

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 23, 2025 05:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/TransferLearning/Algorithms/TransferNeuralNetwork.cs Outdated
ooples and others added 3 commits October 23, 2025 01:56
Create PredictionModelResult class implementing IPredictiveModel and IFullModel
interfaces. This class wraps a trained model with optimization results and
normalization information, delegating all interface methods to the inner model.

Implemented methods include:
- IModel: Train, Predict, GetModelMetaData
- IModelSerializer: Serialize, Deserialize, SaveModel, LoadModel
- IParameterizable: GetParameters, SetParameters, ParameterCount, WithParameters
- IFeatureAware: GetActiveFeatureIndices, SetActiveFeatureIndices, IsFeatureUsed
- IFeatureImportance: GetFeatureImportance
- ICloneable: DeepCopy, Clone

All methods properly delegate to the inner model and include null checks with
appropriate error messages.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Change training to use mappedTargetData instead of targetData for consistency
  with knowledge distillation predictions
- Add clarifying comments explaining the 0.7 weight and feature space matching
- Resolve data inconsistency between distillation and training steps

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 23, 2025 06:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

ooples and others added 7 commits October 23, 2025 02:37
- Replace default instance creation with proper validation exceptions
- Throw InvalidOperationException when metadata is missing instead of silently creating empty instances
- Prevent loss of important OptimizationResult and NormalizationInfo metadata
- Add exception documentation for better clarity

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Remove unused exception variables from TransferRandomForest catch blocks
- Change ArgumentException to InvalidOperationException in BayesianOptimizer for configuration state validation

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Fix FeatureCount to count unique features using HashSet instead of highest index + 1
- Change Train validation from != to < to allow extra unused features
- Change Predict validation from != to < for consistency

Resolves all 3 unresolved Copilot comments in PR #173
Address Copilot PR comments:
1. Replace Dictionary<string, object> with strongly-typed SerializationDto class
   - Prevents type reconstruction issues during deserialization
   - Adds proper typed properties for Model, OptimizationResult, NormalizationInfo

2. Add validation in Serialize method to prevent metadata loss
   - Throw InvalidOperationException if OptimizationResult is null
   - Throw InvalidOperationException if NormalizationInfo is null

3. Replace default return values with exceptions when model is null
   - ParameterCount: throw instead of returning 0
   - GetActiveFeatureIndices: throw instead of returning empty enumerable
   - GetFeatureImportance: throw instead of returning empty dictionary

These changes ensure metadata is never silently lost and deserialization
uses proper type information for reconstruction.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The model should train on the original target domain feature space (targetData),
not the mapped source feature space (mappedTargetData). The mapping is only needed
to get predictions from the source model for knowledge distillation, not for training
the target model. Training on mapped data would result in double-mapping issues.

Addresses Copilot review comment in PR #170

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 23, 2025 12:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/TransferLearning/Algorithms/TransferNeuralNetwork.cs Outdated
ooples and others added 3 commits October 23, 2025 08:55
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Resolves conflict from merging latest changes by accepting the simplified catch block
(without unused Exception variable) from commit 8347f1f.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 23, 2025 13:18

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/LinearAlgebra/ExpressionTree.cs Outdated
Comment thread src/Models/Results/PredictionModelResult.cs Outdated
Copilot AI review requested due to automatic review settings October 23, 2025 13:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread src/Optimizers/BayesianOptimizer.cs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

ooples and others added 2 commits October 23, 2025 14:21
- Change NotImplementedException to NotSupportedException in PredictionModelResult.Deserialize with clear message explaining limitation
- Change InvalidOperationException to ArgumentException in BayesianOptimizer.UpdateOptions for invalid parameter type
- Add nameof(options) to ArgumentException for better error context

Resolves PR #170 review comments about exception semantics.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings October 23, 2025 18:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ooples
ooples merged commit 1d6e531 into merge-dev2-to-master Oct 23, 2025
0 of 2 checks passed
@ooples
ooples deleted the fix/us-if-005-transfer-learning branch October 23, 2025 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants