List
nia github pagenia downloads per month

Nature-inspired optimization is a very popular subject in engineering, terms heuristic algorithms or metaheuristic algorithms are also common to refer to nature-inspired algorithms. The most famous algorithms are probably Genetic Algorithm, Particle Swarm Optimization, Ant Colony Optimization, and Artificial Bee Colony.

What is NIA?

As a part of a project on Bio-Inspired Computational Methods, we produced a python package called NIA, which stands for Nature-Inspired Algorithms. NIA is tried to be a very simple and standard package, we have planned to include about 30 different algorithms in this package. It was our goal to make NIA very simple to use, to start you can install NIA by simply running pip install nia that’s it! the example below shows you that how simple is solving the famous benchmark function, Ackley:

from nia.algorithms import GeneticAlgorithm

def ackley(X):
    x = X[0]
    y = X[1]
    return -20 * np.exp(-0.2 * np.sqrt(0.5 * (x**2 + y**2))) - np.exp(0.5 *
        (np.cos(2 * np.pi * x) + np.cos(2 * np.pi * y))) + np.e + 20

nia = GeneticAlgorithm(cost_function=ackley,
                       lower_bond=[-5,-5],
                       upper_bond=[5,5],
                                )
nia.run()
print(nia.message);

The above example is the easiest way to use NIA, obviously, it uses the least parameters, if you want to customize it, there is a full example with all available options:

from nia.algorithms import GeneticAlgorithm

from nia.selections import Tournament
from nia.crossovers import RandomSBX
from nia.mutations import Uniform
import numpy as np

def ackley(X):
    x = X[0]
    y = X[1]
    return -20 * np.exp(-0.2 * np.sqrt(0.5 * (x**2 + y**2))) - np.exp(0.5 *
        (np.cos(2 * np.pi * x) + np.cos(2 * np.pi * y))) + np.e + 20

def log(ga):
  print(ga.best)

lower = np.array([-5,-5])
upper = np.array([5,5])

nia = GeneticAlgorithm(cost_function=ackley,
                       iteration_function=log,
                       lower_bond=lower,
                       upper_bond=upper,
                       quit_criteria = 0.0001,
                       num_variable = 2,
                       num_population = 20,
                       max_iteration = 100,
                       crossover = RandomSBX(2),
                       mutation = Uniform(0.05),
                       selection = Tournament(20)
                                )
nia.run()
print(nia.message);

According to the above example, you can see that NIA supports different mutation, crossover, and selection functions. Which can be easily imported from separate classes. Instead of the cost function, you can pass an iteration function, which would call in each iteration with the main algorithm object. So you have full control over the algorithm, for example, you may change the population, crossover, bonds, and even cost function. In the above example, we just log the best answer in each iteration. You may want to create a plot using matplotlib to show the progress in each iteration:

Solving Ackley with Genetic algorithm using NIA python package

List of Algorithms

Here you can find the list of selected algorithms that would be included in NIA:

  • Genetic algorithm (GeneticAlgorithm)
  • Differential Evolution
  • Evolutionary Programming
  • Artificial Immune System
  • Clonal Selection Algorithm
  • Biogeography-based
  • Symbiotic Organisms Search
  • Ant Colony Optimization
  • Artificial Bee Colony (ArtificialBeeColony)
  • Moth Flame Optimization Algorithm
  • Cuckoo Search
  • Green Herons Optimization Algorithm
  • Bat Algorithm
  • Whale Optimization Algorithm
  • Krill Herd
  • Fish-swarm Algorithm
  • Grey Wolf Optimizer
  • Shuffle frog-leaping Algorithm
  • Cat Swarm Optimization
  • Flower Pollination Algorithm
  • Invasive Weed Optimization
  • Water Cycle Algorithm
  • Teaching–Learning-Based Optimization
  • Particle Swarm Optimization (ParticleSwarmOptimization)
  • Simulated Annealing Algorithm
  • Gravitational Search Algorithm
  • Big Bang – Big Crunch

Open-Source

for more information, source codes, and versions you can take a look at the git repository of the NIA and the PyPI page. We welcome any contributions, bug reports, and suggestions.

  Posts

June 30th, 2023

Nature-inspired algorithms and Aerospace

This week my latest paper “Nature-Inspired Algorithms from Oceans to Space: A Comprehensive Review of Heuristic and Meta-Heuristic Optimization Algorithms

May 29th, 2023

A quick start with LaTeX for academic purposes

Painful Word! If you have ever worked on a large publication in Microsoft Word, you may have experienced the pain

April 29th, 2022

Best Thesis of The Year Award

I am pleased to announce that my master’s thesis titled “Control Design and Stability Proof of a Moving Mass Controlled

April 29th, 2022

Outstanding Student Award

I am pleased to announce that I have been selected a the Outstanding Master’s student of the K. N. Toosi

December 21st, 2021

Best Researcher Award of KNTU

I am pleased to announce that I have been selected as the Best Researcher of the K. N. Toosi University

October 2nd, 2021

NIA, Nature-Inspired Optimization Python Package

Nature-inspired optimization is a very popular subject in engineering, terms heuristic algorithms or metaheuristic algorithms are also common to refer

April 29th, 2021

Model Predictive Control (MPC) in Aerospace Systems

Model predictive control is an advanced method of process control that is used to control a process while satisfying a

January 31st, 2021

Web Based Flight Platform

Web Based Flight Platform is a project which focuses on developing a hardware platform for web-based swarm of drones, this

December 12th, 2020

UAVs; Classification and Flight Mechanisms

Unmanned Aerial Systems (UAS, UAVs, or drones) have a variety of applications in our daily life that have attracted the

September 28th, 2020

Moving Mass Controlled bi-rotor UAV

As a part of my MSc thesis, I have introduced a novel UAV configuration based on the Moving Mass Control