<commit_before># -*- coding: utf-8 -*-

"""
This example shows how to optimize a benchmark function using an evolutionary
algorithm.

Author: <NAME> <<EMAIL>>
License: MIT
"""

from time import time
try:
    from stochopy import Evolutionary, BenchmarkFunction
except ImportError:
    import sys
    sys.path.append("../")
    from stochopy import Evolutionary, BenchmarkFunction


if __name__ == "__main__":
    # Parameters
    func = "rastrigin"
    
    # Initialize function
    bf = BenchmarkFunction(func, n_dim = 30)
    
    # Initialize solver
    ea = Evolutionary(popsize = 30, max_iter = 2000, constrain = False, random_state = -1, **bf.get())
    
    # Solve
    starttime = time()
    ea.optimize(solver = "cpso", sync = True)
    
    # Print solution
    print(ea)
    print("Elapsed time: %.2f seconds" % (time() - starttime))<commit_msg>update example<commit_after># -*- coding: utf-8 -*-

"""
This example shows how to optimize a benchmark function using an evolutionary
algorithm.

Author: <NAME> <<EMAIL>>
License: MIT
"""

from time import time
try:
    from stochopy import Evolutionary, BenchmarkFunction
except ImportError:
    import sys
    sys.path.append("../")
    from stochopy import Evolutionary, BenchmarkFunction


if __name__ == "__main__":
    # Parameters
    func = "sphere"
    
    # Initialize function
    bf = BenchmarkFunction(func, n_dim = 10)
    
    # Initialize solver
    ea = Evolutionary(popsize = 10, max_iter = 200, constrain = True, random_state = -1, **bf.get())
    
    # Solve
    starttime = time()
    ea.optimize(solver = "pso", sync = False)
    
    # Print solution
    print(ea)
    print("Elapsed time: %.2f seconds" % (time() - starttime))
{'fraction_non_alphanumeric': 0.11812865497076024, 'fraction_numerical': 0.012280701754385965, 'mean_word_length': 3.0933014354066986, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '646422', 'n_tokens_mistral': 566, 'n_tokens_neox': 521, 'n_words': 162}