<jupyter_start><jupyter_text>FABSO Quickstart---Quickstart of the Fitness-Distance-Ratio Archive-Based Swarm Optimization (FABSO) algorithm<jupyter_code># Import modules from fabso
from fabso.topology import Space
from fabso.optimizer import FABSO
from fabso.utils import viz
# Libraries
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline<jupyter_output><empty_output><jupyter_text>Fitness function--- De Jong's function 1Sum of the square of each value where the value. Defined as ![equation](./images/equation.png)<jupyter_code># Fitness function
# returning a negative value as we want to minimize the
# objective function using a maximizing algorithm.

def fitness(x):
    x = [i**2 for i in x]
    return -sum(x)
# Initial Parameters
bounds = (-5.12, 5.12)
n_particles = 20
n_dimensions = 5
# Algorithm Parameters
objective = fitness

params = {'w': 0.9, 'c1': 1, 'c2': 0, 'c3': 2}
generations = 50
archive_size = 5
restart_freq = 20
# Generate random particles
particles = np.random.randn(n_particles, n_dimensions)
# Initialize search space
space = Space(bounds, objective, n_particles, n_dimensions)
space.generate_particles(particles)
# Initialize algorithms with parameters
fabso = FABSO(space, bounds, params, objective, generations,
        n_particles, n_dimensions, archive_size, restart_freq)

# Optimize objective function
result = fabso.optimize()
print('Optimal value achieved: ', result[-1])
# Generate plot
fig = viz(result)
fig.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09707446808510638, 'fraction_numerical': 0.016622340425531915, 'mean_word_length': 5.629955947136564, 'pattern_counts': {'":': 0, '<': 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}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '60148', 'license': 'MIT', 'n_tokens_mistral': 497, 'n_tokens_neox': 472, 'n_words': 153, 'path': 'example.ipynb', 'repo_name': 'nishnash54/FABSO', 'size': '1504'}