Skip to content

[WIP] Update docstrings for social-inspired algorithms#107

Merged
Anselmoo merged 7 commits intomainfrom
copilot/update-docstrings-social-algorithms
Dec 24, 2025
Merged

[WIP] Update docstrings for social-inspired algorithms#107
Anselmoo merged 7 commits intomainfrom
copilot/update-docstrings-social-algorithms

Conversation

Copy link
Contributor

Copilot AI commented Dec 23, 2025

  • Update teaching_learning.py with complete COCO/BBOB docstring
    • Replace FIXME placeholders with actual algorithm details
    • Add proper mathematical formulation for TLBO
    • Complete hyperparameters section with BBOB recommendations
    • Add social behavior analogies (teacher-learner metaphor)
    • Fix Google style docstring indentation
    • Add inline summaries to Args/Attributes sections
    • Add seed parameter for BBOB compliance
  • Update political_optimizer.py with complete COCO/BBOB docstring
    • Replace FIXME placeholders with actual algorithm details
    • Add proper mathematical formulation for PO
    • Complete hyperparameters section with BBOB recommendations
    • Add social behavior analogies (political strategies)
    • Fix Google style docstring indentation
    • Add inline summaries to Args/Attributes sections
    • Add seed parameter for BBOB compliance
  • Update social_group_optimizer.py with complete COCO/BBOB docstring
    • Replace FIXME placeholders with actual algorithm details
    • Add proper mathematical formulation for SGO
    • Complete hyperparameters section with BBOB recommendations
    • Add social behavior analogies (social interactions)
    • Fix Google style docstring indentation
    • Add inline summaries to Args/Attributes sections
    • Add seed parameter for BBOB compliance
  • Update soccer_league_optimizer.py with complete COCO/BBOB docstring
    • Replace FIXME placeholders with actual algorithm details
    • Add proper mathematical formulation for SLC
    • Complete hyperparameters section with BBOB recommendations
    • Add social behavior analogies (soccer league dynamics)
    • Fix Google style docstring indentation
    • Add inline summaries to Args/Attributes sections
    • Add seed parameter for BBOB compliance
  • Run linting on all 4 files with uv run ruff check opt/social_inspired/
  • Verify all docstrings pass validation (ruff, pydocstyle, custom validators, COCO/BBOB validator)
Original prompt

This section details on the original issue you should resolve

<issue_title>Update Optimizer Docstrings - Social-Inspired Category (4 files)</issue_title>
<issue_description>## Problem
4 social-inspired algorithms lack COCO/BBOB compliant docstrings.

Files to Update

  • opt/social_inspired/teaching_learning_optimization.py
  • opt/social_inspired/political_optimizer.py
  • And 2 additional social-inspired files

Implementation

Follow template emphasizing social behavior analogies.

Acceptance Criteria

  • All 4 files completed with COCO/BBOB compliance
  • All pass uv run ruff check opt/social_inspired/
  • Social behavior analogies clearly explained
  • Category validation passes

Complexity

Low - Small category with clear social metaphors

Dependencies

Depends on: #4 (validation checkpoints establish pattern)</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 23, 2025
Co-authored-by: Anselmoo <13209783+Anselmoo@users.noreply.github.com>
Copy link
Owner

@Anselmoo Anselmoo left a comment

Choose a reason for hiding this comment

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

Comment on lines 200 to 202
- Randomly alternates between constituency and campaign phases
- Adaptive party switching probability decreases over time
- BBOB: Returns final best solution after max_iter
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot wrong indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 5f5aaac - corrected indentation to match Google Python Style Guide.

Comment on lines 191 to 194
Returns:
tuple[np.ndarray, float]:
Best solution found and its fitness value
tuple[np.ndarray, float]:
- best_solution (np.ndarray): Best solution found, shape (dim,)
- best_fitness (float): Fitness value at best_solution
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot not google style conform

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 5f5aaac - updated to Google style conform format with proper indentation.

Comment on lines 198 to 201
Returns:
tuple[np.ndarray, float]:
Best solution found and its fitness value
tuple[np.ndarray, float]:
- best_solution (np.ndarray): Best solution found, shape (dim,)
- best_fitness (float): Fitness value at best_solution
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot not google style conform

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 5f5aaac - updated to Google style conform format with proper indentation.

Comment on lines 207 to 210
- Each iteration simulates matches between weighted opponents
- Training phase (20% probability) adds exploration
- Transfer window (10% probability) enables dimension exchange
- BBOB: Returns final best solution after max_iter
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot wrong indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 5f5aaac - corrected indentation to match Google Python Style Guide.

Comment on lines 228 to 230
tuple[np.ndarray, float]:
- best_solution (np.ndarray): Best solution found, shape (dim,)
- best_fitness (float): Fitness value at best_solution
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot not google style conform

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 5f5aaac - updated to Google style conform format with proper indentation.

Comment on lines 236 to 239
- Executes improving, acquiring, and introspection phases per iteration
- Self-introspection coefficient adapts linearly: $c \cdot (1 - t)$
- Supports early stopping and convergence tracking
- BBOB: Returns final best solution after max_iter or early stop
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot wrong indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 5f5aaac - corrected indentation to match Google Python Style Guide.

Comment on lines 170 to 173
Returns:
tuple[np.ndarray, float]:
Best solution found and its fitness value
tuple[np.ndarray, float]:
- best_solution (np.ndarray): Best solution found, shape (dim,)
- best_fitness (float): Fitness value at best_solution
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot not google style conform

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 5f5aaac - updated to Google style conform format with proper indentation.

Comment on lines 179 to 181
- Executes both teacher and learner phases in each iteration
- Uses greedy selection for accepting new solutions
- BBOB: Returns final best solution after max_iter
Copy link
Owner

Choose a reason for hiding this comment

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

@copilot wrong indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in commit 5f5aaac - corrected indentation to match Google Python Style Guide (8 spaces from base for Returns/Raises/Notes sections).

…tes sections

Co-authored-by: Anselmoo <13209783+Anselmoo@users.noreply.github.com>
Copy link
Owner

@Anselmoo Anselmoo left a comment

Choose a reason for hiding this comment

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

@copilot there are several linting issues left

Co-authored-by: Anselmoo <13209783+Anselmoo@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 24, 2025

@copilot there are several linting issues left

Fixed in commit 3bdd274. The linting issues were from the custom Google docstring validator (scripts/check_google_docstring_inline_descriptions.py) which requires inline summaries after type annotations in Args/Attributes sections. All validators now pass:

  • ✅ ruff check
  • ✅ pydocstyle
  • ✅ custom Google docstring validator

Copy link
Owner

@Anselmoo Anselmoo left a comment

Choose a reason for hiding this comment

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

@copilot

opt/social_inspired/teaching_learning.py: Args section should document 'seed' parameter for BBOB compliance
opt/social_inspired/teaching_learning.py: Attributes section should document 'seed' attribute (REQUIRED for BBOB)
opt/social_inspired/political_optimizer.py: Args section should document 'seed' parameter for BBOB compliance
opt/social_inspired/political_optimizer.py: Attributes section should document 'seed' attribute (REQUIRED for BBOB)
opt/social_inspired/soccer_league_optimizer.py: Args section should document 'seed' parameter for BBOB compliance
opt/social_inspired/soccer_league_optimizer.py: Attributes section should document 'seed' attribute (REQUIRED for BBOB)

Found 6 COCO/BBOB compliance issue(s)
opt/social_inspired/social_group_optimizer.py: Args section should document 'seed' parameter for BBOB compliance
opt/social_inspired/social_group_optimizer.py: Attributes section should document 'seed' attribute (REQUIRED for BBOB)

Found 2 COCO/BBOB compliance issue(s)

…ompliance

Co-authored-by: Anselmoo <13209783+Anselmoo@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 24, 2025

@copilot

Fixed in commit aed1b35. Added seed parameter to all 4 social-inspired optimizers:

  • Updated Args sections to document the seed parameter (BBOB requires seeds 0-14 for 15 runs)
  • Updated Attributes sections to document the seed attribute as REQUIRED for BBOB compliance
  • Modified init methods to accept seed parameter and pass it to parent AbstractOptimizer
  • All COCO/BBOB compliance checks now pass ✅

@Anselmoo Anselmoo marked this pull request as ready for review December 24, 2025 13:32
Copilot AI review requested due to automatic review settings December 24, 2025 13:32
@Anselmoo Anselmoo merged commit 68425ba into main Dec 24, 2025
1 of 5 checks passed
Copy link
Contributor

Copilot AI left a comment

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 updates docstrings for four social-inspired optimization algorithms to achieve COCO/BBOB compliance. The updates replace FIXME placeholders with complete algorithm metadata, mathematical formulations, hyperparameter documentation, and social behavior analogies. All four optimizers now include seed parameters for reproducibility and follow Google Python Style Guide conventions.

Key changes:

  • Complete COCO/BBOB-compliant docstrings with algorithm metadata (year, authors, complexity)
  • Mathematical formulations with LaTeX notation for all algorithm phases
  • Social behavior analogies explaining the real-world metaphors (classroom, political elections, social groups, soccer leagues)
  • Addition of seed parameter to init signatures for reproducibility

Reviewed changes

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

File Description
opt/social_inspired/teaching_learning.py Updated TLBO docstring with teacher/learner phase formulations, classroom learning analogy, and seed parameter. Fixed typo "unse" → "unseeded" needed.
opt/social_inspired/social_group_optimizer.py Added complete SGO documentation with three-phase learning (improving, acquiring, introspection), social learning analogies, and seed parameter.
opt/social_inspired/soccer_league_optimizer.py Documented SLC with match/training/transfer formulations, soccer league dynamics analogy, and seed parameter.
opt/social_inspired/political_optimizer.py Added PO documentation with constituency/campaign/switching phases, political election analogy, and seed parameter.

seed: Random seed for reproducibility.
"""
super().__init__(func, lower_bound, upper_bound, dim)
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed)
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The super().init call should include the population_size parameter to properly initialize the parent class. The AbstractOptimizer accepts population_size as a parameter, and while you're setting self.population_size separately, it's better to pass it to the parent constructor for consistency. Consider changing to: super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed, population_size)

Suggested change
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed)
super().__init__(
func,
lower_bound,
upper_bound,
dim,
max_iter,
seed,
population_size,
)

Copilot uses AI. Check for mistakes.
seed: Random seed for reproducibility.
"""
super().__init__(func, lower_bound, upper_bound, dim, max_iter)
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed)
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The super().init call should include the population_size parameter. While you're setting self.population_size separately, AbstractOptimizer accepts population_size as a parameter and it should be passed through for consistency. Consider: super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed, population_size)

Suggested change
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed)
super().__init__(
func,
lower_bound,
upper_bound,
dim,
max_iter,
seed,
population_size,
)

Copilot uses AI. Check for mistakes.
seed: Random seed for reproducibility.
"""
super().__init__(func, lower_bound, upper_bound, dim, max_iter)
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed)
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The super().init call should include the population_size parameter for consistency with AbstractOptimizer's interface. Consider: super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed, population_size)

Suggested change
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed)
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed, population_size)

Copilot uses AI. Check for mistakes.
seed: Random seed for reproducibility.
"""
super().__init__(func, lower_bound, upper_bound, dim, max_iter)
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed)
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The super().init call should include the population_size parameter for consistency with AbstractOptimizer's interface. Consider: super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed, population_size)

Suggested change
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed)
super().__init__(func, lower_bound, upper_bound, dim, max_iter, seed, population_size)

Copilot uses AI. Check for mistakes.
**Reproducibility**:
- **Deterministic**: FIXME: [Yes/No] - Same seed guarantees same results
- **BBOB compliance**: seed parameter required for 15 independent runs
- **Deterministic**: No - uses unse random number generation
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

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

The phrase "uses unse random number generation" contains a typo. It should be "uses unseeded random number generation".

Suggested change
- **Deterministic**: No - uses unse random number generation
- **Deterministic**: No - uses unseeded random number generation

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update Optimizer Docstrings - Social-Inspired Category (4 files)

2 participants

Comments