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

Restore Class Names in decay and mutators Folders for Backward Compatibility #9

Merged
merged 7 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ tsp_test/

# Virtual environments
venvp/

venv
# Aider tool
.aider*

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "mlrose-ky"
version = "1.0.5"
version = "1.0.6"
description = "MLROSe-ky: Machine Learning, Randomized Optimization and Search"
readme = "README.md"
requires-python = ">=3.10"
Expand Down
2 changes: 1 addition & 1 deletion src/mlrose_ky/algorithms/decay/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
from .arithmetic_decay import ArithmeticDecay
Copy link
Owner

Choose a reason for hiding this comment

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

All imported classes should be renamed to the reverted names such as ArithDecay, ExpDecay, etc.

Copy link
Owner

Choose a reason for hiding this comment

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

Still need to rename the imported GeometricDecay in src/mlrose_ky/algorithms/sa.py

from .custom_decay import CustomDecay
from .exponential_decay import ExponentialDecay
from .geometric_decay import GeometricDecay
from .geometric_decay import GeometricDecay, GeomDecay
knakamura13 marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions src/mlrose_ky/algorithms/decay/arithmetic_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# License: BSD 3-clause


class ArithmeticDecay:
class ArithDecay:
"""
Schedule for arithmetically decaying the temperature parameter T in a
simulated annealing process, calculated using the formula:
Expand Down Expand Up @@ -36,7 +36,7 @@ class ArithmeticDecay:

Examples
--------
>>> schedule = ArithmeticDecay(initial_temperature=10, decay_rate=0.95, minimum_temperature=1)
>>> schedule = ArithDecay(initial_temperature=10, decay_rate=0.95, minimum_temperature=1)
>>> schedule.evaluate(5)
5.25
"""
Expand Down Expand Up @@ -64,7 +64,7 @@ def __repr__(self) -> str:
return self.__str__()

def __eq__(self, other: object) -> bool:
if not isinstance(other, ArithmeticDecay):
if not isinstance(other, ArithDecay):
return False
return (
self.initial_temperature == other.initial_temperature
Expand Down
6 changes: 3 additions & 3 deletions src/mlrose_ky/algorithms/decay/custom_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from typing import Callable


class CustomDecay:
class CustomSchedule:
"""
Class for generating a customizable temperature schedule for simulated annealing.

Expand All @@ -24,7 +24,7 @@ class CustomDecay:
-------
>>> def custom_decay_function(time: int, offset: int) -> float: return time + offset
>>> kwargs = {'offset': 10}
>>> schedule = CustomDecay(custom_decay_function, **kwargs)
>>> schedule = CustomSchedule(custom_decay_function, **kwargs)
>>> schedule.evaluate(5)
15
"""
Expand All @@ -40,7 +40,7 @@ def __repr__(self) -> str:
return self.__str__()

def __eq__(self, other: object) -> bool:
if not isinstance(other, CustomDecay):
if not isinstance(other, CustomSchedule):
return False
return self.decay_function == other.decay_function and self.kwargs == other.kwargs

Expand Down
6 changes: 3 additions & 3 deletions src/mlrose_ky/algorithms/decay/exponential_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np


class ExponentialDecay:
class ExpDecay:
"""
Defines an exponential decay schedule for the temperature parameter T in simulated annealing,
using the formula:
Expand Down Expand Up @@ -38,7 +38,7 @@ class ExponentialDecay:

Examples
--------
>>> schedule = ExponentialDecay(initial_temperature=10, decay_rate=0.05, minimum_temperature=1)
>>> schedule = ExpDecay(initial_temperature=10, decay_rate=0.05, minimum_temperature=1)
>>> print(schedule.evaluate(5))
7.788007830714049
"""
Expand Down Expand Up @@ -66,7 +66,7 @@ def __repr__(self) -> str:
return self.__str__()

def __eq__(self, other: object) -> bool:
if not isinstance(other, ExponentialDecay):
if not isinstance(other, ExpDecay):
return False
return (
self.initial_temperature == other.initial_temperature
Expand Down
21 changes: 11 additions & 10 deletions src/mlrose_ky/algorithms/decay/geometric_decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
# License: BSD 3-clause


class GeometricDecay:

class GeomDecay:
"""
Defines a geometric decay schedule for the temperature parameter T in simulated annealing,
using the formula:
Expand Down Expand Up @@ -36,7 +37,7 @@ class GeometricDecay:

Examples
--------
>>> schedule = GeometricDecay(initial_temperature=10, decay_rate=0.95, minimum_temperature=1)
>>> schedule = GeomDecay(initial_temperature=10, decay_rate=0.95, minimum_temperature=1)
>>> print(schedule.evaluate(5))
7.737809374999998
"""
Expand Down Expand Up @@ -64,13 +65,11 @@ def __repr__(self) -> str:
return self.__str__()

def __eq__(self, other: object) -> bool:
if not isinstance(other, GeometricDecay):
if not isinstance(other, GeomDecay):
return False
return (
self.initial_temperature == other.initial_temperature
and self.decay_rate == other.decay_rate
and self.minimum_temperature == other.minimum_temperature
)
return (self.initial_temperature == other.initial_temperature
and self.decay_rate == other.decay_rate
and self.minimum_temperature == other.minimum_temperature)

def evaluate(self, time: int) -> float:
"""
Expand All @@ -86,8 +85,7 @@ def evaluate(self, time: int) -> float:
float
The temperature parameter at the given time, respecting the minimum temperature.
"""
temperature = max(self.initial_temperature * (self.decay_rate**time), self.minimum_temperature)
return temperature
return max(self.initial_temperature * (self.decay_rate ** time), self.minimum_temperature)

def get_info(self, time: int | None = None, prefix: str = "") -> dict:
"""
Expand Down Expand Up @@ -118,3 +116,6 @@ def get_info(self, time: int | None = None, prefix: str = "") -> dict:
info[f"{info_prefix}current_value"] = self.evaluate(time)

return info



2 changes: 1 addition & 1 deletion src/mlrose_ky/algorithms/mutators/discrete_mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mlrose_ky.algorithms.mutators._mutator_base import _MutatorBase


class DiscreteGeneMutator(_MutatorBase):
class DiscreteMutator(_MutatorBase):
knakamura13 marked this conversation as resolved.
Show resolved Hide resolved
"""
A mutator class that performs discrete mutation on individual genes in a genetic algorithm.

Expand Down
2 changes: 1 addition & 1 deletion src/mlrose_ky/algorithms/mutators/gene_swap_mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mlrose_ky.algorithms.mutators._mutator_base import _MutatorBase


class GeneSwapMutator(_MutatorBase):
class SwapMutator(_MutatorBase):
"""
A mutator class that implements the 'Gene Swap' mutation strategy in genetic algorithms.

Expand Down
2 changes: 1 addition & 1 deletion src/mlrose_ky/algorithms/mutators/single_gene_mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mlrose_ky.algorithms.mutators._mutator_base import _MutatorBase


class SingleGeneMutator(_MutatorBase):
class ChangeOneMutator(_MutatorBase):
"""
A mutator class that performs the 'Change One' mutation strategy in a genetic algorithm.

Expand Down
2 changes: 1 addition & 1 deletion src/mlrose_ky/algorithms/mutators/single_shift_mutator.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from mlrose_ky.algorithms.mutators._mutator_base import _MutatorBase


class SingleShiftMutator(_MutatorBase):
class ShiftOneMutator(_MutatorBase):
"""
A mutator class that implements the 'Shift One' mutation strategy in a genetic algorithm.

Expand Down