Metadata-Version: 2.4
Name: GOBC_PA
Version: 2.0
Summary: A new unconstrained global optimization method based on clustering and parabolic approximation
Author-email: Ihsan Pence <ihsanpence@mehmetakif.edu.tr>
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.11
Description-Content-Type: text/markdown

## Table of contents
* [Updates](#Updates)
* [General Info](#general-info)
* [Technologies](#technologies)
* [Setup](#setup)
* [How to use](#how-to-use)
* [Example (CPU)](#Example)
* [Example 2 (CPU)](#Example2)
* [Example 3 (GPU)](#Example3)
* [Cite](#Cite)

## Updates
* GPU support has been added.

The updated methodology is a GPU-accelerated, tensor-based reformulation of 
the Global Optimization based on Clustering and Parabolic Approximation (GOBC-PA) algorithm, 
developed in TensorFlow to enable end-to-end parallel execution across high-dimensional optimization landscapes.

## General Info
GOBC-PA: A new unconstrained global optimization method based on clustering and parabolic approximation
 (GOBC-PA) is proposed. Although the proposed method is basically similar to other
 evolutionary and stochastic methods, it represents a significant advancement of global optimization
 technology for four important reasons. First, it is orders of magnitude faster than existing optimization
 methods for global optimization of unconstrained problems. Second, it has significantly better repeatability,
 numerical stability, and robustness than current methods in dealing with high dimensionally
 and many local minima functions. Third, it can easily and faster find the local minimums using the
 parabolic approximation instead of gradient descent or crossover operations. Fourth, it can easily
 adapted to any theoretical or industrial systems which are using the heuristic methods as an intelligent
 system. In this study, we assume that the best cluster center gives the
 position of the possible global optimum. The usage of clustering and curve fitting techniques brings
 multi-start and local search properties to the proposed method. The experimental studies show that
 the proposed methodology is simple, faster and, it demonstrates a superior performance
 when compared with some state of the art methods.

Args:
* func         - Objective function. If device='gpu' or 'mps', this must be a batched TF function.
              If device='cpu', it should be a standard Python function taking a 1D NumPy array.
* dim         - Dimensionality of the problem.
* pop_size         - Population size.
* max_iter         - Maximum number of iterations.
* bounds         - A tuple (min, max) or a list of tuples for each dimension.
* device         - 'cpu', 'gpu', or 'mps'. Default is 'cpu'
* seed         - Random seed (GPU only).
        
Returns:
* best_pos          - Global minimum point
* best_score        - Global minimum value on global minimum point
* additional_metrics_dict    - best points and their objective value on each epoch

## Technologies
Project is created with:
* Python 3.11
	
## Setup
To run this project, install it locally using pip:

```
$ pip install GOBC-PA
```

## How to use

```
from GOBC_PA.GOBC_PA import GOBC_PA
Best_point, Best_result, performance = GOBC_PA(func,dim,pop_size,max_iter,bounds,device)
 
```

## Example (CPU) 

```
import numpy as np
from GOBC_PA.GOBC_PA import GOBC_PA

def func(x):  # Rastrigin function
    y= x[0]**2+x[1]**2-np.cos(18*x[0])-np.cos(18*x[1])
    return y

dim,pop_size,max_iter = 2,60,1000
bounds = (-1,1)
Best_point, Best_result, performance = GOBC_PA(func,dim,pop_size,max_iter,bounds)
 
```

## Example 2 (CPU)

```
import numpy as np
from GOBC_PA.GOBC_PA import GOBC_PA

def func2(x):  # Goldstein-Price's Function
    y = (1 + ((x[0] + x[1] + 1) ** 2) * (
                19 - 14 * x[0] + 3 * x[0] ** 2 - 14 * x[1] + 6 * x[0] * x[1] + 3 * x[1] ** 2)) * (
                    30 + ((2 * x[0] - 3 * x[1]) ** 2) * (
                        18 - 32 * x[0] + 12 * x[0] ** 2 + 48 * x[1] - 36 * x[0] * x[1] + 27 * x[1] ** 2))
    return y

dim,pop_size,max_iter = 2,60,1000
bounds = (-2,2)
Best_point, Best_result, performance = GOBC_PA(func2,dim,pop_size,max_iter,bounds,device='cpu')
 
```

## Example 3 (GPU)

```
import tensorflow as tf
import numpy as np
from GOBC_PA.GOBC_PA import GOBC_PA

# Styblinski-Tang Function
@tf.function
def styblinski_tang_tf(pop):
    term = tf.pow(pop, 4) - 16.0 * tf.square(pop) + 5.0 * pop
    return 0.5 * tf.reduce_sum(term, axis=1)

def styblinski_tang_np(x):
    return 0.5 * np.sum(x ** 4 - 16.0 * x ** 2 + 5.0 * x)

dim,pop_size,max_iter = 100,300,1000
bounds = (-5,5)
Best_point, Best_result, performance = GOBC_PA(styblinski_tang_tf,dim,pop_size,max_iter,bounds,device='gpu')
Best_point, Best_result, performance = GOBC_PA(styblinski_tang_np,dim,pop_size,max_iter,bounds,device='cpu')
 
```

## Cite

Pence, I., Cesmeli, M. S., Senel, F. A., & Cetisli, B. (2016). A new unconstrained global optimization method based on clustering and parabolic approximation. Expert Systems with Applications, 55, 493-507.
