Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Aero-Spec authored Sep 22, 2024
1 parent a9abf8e commit e86b3ca
Showing 1 changed file with 31 additions and 106 deletions.
137 changes: 31 additions & 106 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# DividedRectangles.jl
# DividedRectangles.jl

[![CI](https://github.com/sisl/DividedRectangles.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/sisl/DividedRectangles.jl/actions/workflows/CI.yml)
[![Documentation Status](https://img.shields.io/badge/docs-latest-blue.svg)](https://sisl.github.io/DividedRectangles.jl/)
[![codecov](https://codecov.io/gh/sisl/DividedRectangles.jl/graph/badge.svg?token=YALXFAP7UO)](https://codecov.io/gh/sisl/DividedRectangles.jl)
---

**Important Note**: The content in this package is borrowed from Chapter 7, "Direct Methods," of the forthcoming second edition of "Algorithms for Optimization" by Mykel Kochenderfer and Tim Wheeler.

**DividedRectangles.jl** provides an implementation of the DIRECT (DIvided RECTangles) [algorithm for global optimization](https://scholar.google.com/scholar?hl=en&as_sdt=0%2C5&q=Lipschitzian+optimization+without+the+Lipschitz+constant&btnG=). The DIRECT algorithm is particularly useful for optimizing functions where the Lipschitz constant is unknown. This package allows users to perform both univariate and multivariate optimization efficiently.

### Key Equation:
The algorithm is guided by the following fundamental equation:
---

```math
f(x) = \sum_{i=1}^{n} c_i x_i
```
Example Objective Function:
As an example of an objective function, consider:

```julia
f(x) = dot(coeffs, x)
```
where:
- $x_i$ represents the variables.
- $c_i$ represents the coefficients corresponding to each variable.
- `x`: represents the variables.
- `coeffs`: represents the coefficients corresponding to each variable.

This equation forms the basis for dividing the search space into smaller rectangles, optimizing the function by evaluating it at specific points.
This is just one possible objective function that could be optimized using the DIRECT algorithm. The algorithm works by dividing the search space into smaller rectangles and evaluating the function at specific points within these rectangles to find the optimal solution.

---

Expand All @@ -33,8 +36,8 @@ using Pkg
Pkg.add(url="https://github.com/sisl/DividedRectangles.jl")

```
## Usage

# Usage
To use the `DividedRectangles` module, start your code with:

```julia
Expand All @@ -51,12 +54,17 @@ To use the `optimize` function with a custom mathematical function:
using DividedRectangles

# Define the objective function
f(x) = sum(c * xi for (c, xi) in zip(coeffs, x))
f(x) = dot([1.0, 2.0, 3.0], x) # Example objective function with coefficients

# Set the search bounds
a = [0.0, 0.0, 0.0]
b = [1.0, 1.0, 1.0]

# Call the optimization function
result = optimize(f, a, b)

println("Optimal value found at: ", result)
println("Best design found: ", result)

```

**Arguments:**
Expand All @@ -67,27 +75,8 @@ println("Optimal value found at: ", result)
- `min_radius`: (Optional) The minimum radius of hyper-rectangles (default: 1e-5).

**Returns:**
- A vector representing the coordinates of the optimal point found.

### Example: Univariate Optimization

The following example demonstrates how to use the DIRECT algorithm to find the minimum of a univariate function:

```julia
using DividedRectangles

# Define the objective function
f(x) = sin(5 * x) + cos(2 * x)

# Set the search bounds
a = [-1.0]
b = [2.0]

# Optimize
result = DividedRectangles.optimize(f, a, b)

println("Optimal value found at: ", result)
```
- The best design 𝑥 found by DIRECT.
---

### Example: Multivariate Optimization

Expand All @@ -106,87 +95,23 @@ b = [2.0, 2.0]
# Optimize
result = DividedRectangles.optimize(f, a, b)

println("Optimal value found at: ", result)
println("Best design found: ", result)
```

### Parameters
- `f`: This is the objective function to minimize. Should be an operation that accepts a vector of Float64 values.
- `a`: A vector with the lower bounds to be used in the search space.
- `b`: An upper-bound vector for the search space.
- `max_iterations`: Maximum number of iterations to run the optimization. The default is 100.
- `min_radius`: The minimum allowable size of a hyper-rectangle (default: '1e-5').

# Theory

The DIRECT (DIvided RECTangles) algorithm is a global optimization method that does not require a known Lipschitz constant. This characteristic makes it particularly robust and versatile, applicable to a wide range of optimization problems. The algorithm operates by dividing the search space into smaller hyper-rectangles and evaluating the function at the center of each rectangle.

---
### Key Concepts of the DIRECT Algorithm

1. **Division of Search Space**:
- The algorithm begins by treating the entire feasible region as a single hyper-rectangle.
- This hyper-rectangle is then divided into smaller rectangles by splitting the dimensions.

2. **Function Evaluation**:
- The function is evaluated at the center of each hyper-rectangle.
- This evaluation helps in identifying the most promising regions for further exploration.

3. **Selection of Potentially Optimal Rectangles**:
- After evaluation, the algorithm identifies potentially optimal rectangles. A rectangle is considered potentially optimal if it could contain the global minimum based on the evaluations performed so far.

4. **Recursive Division**:
- The selected rectangles are further divided, and the process repeats.
- The algorithm continues to refine the search by focusing more on regions that are likely to contain the global minimum.

---

## Mathematical Formulation
The algorithm relies on the following core mathematical principles:

**Evaluation Function**:
The objective function $f(x)$ is evaluated at the center of each hyper-rectangle:

```math
f(x) = \sum_{i=1}^{n} c_i x_i
```

where $x_i$ are the variables, and $c_i$ are the corresponding coefficients.

- **Rectangle Selection Criterion**:
A rectangle ($R$) is considered potentially optimal if:
```math
f(x_R) - L \cdot r_R \leq f(x) - L \cdot r_x \quad \text{for all } x \in R
```
where:
- $f(x_R)$ is the function value at the center of the rectangle.
- $r_R$ is the radius of the rectangle.
- $L$ is the Lipschitz constant.

**Recursive Division**:
The hyper-rectangles are recursively divided along their longest dimension:

```math
x_R = \frac{a_i + b_i}{2}
```

where $a_i$ and $b_i$ are the bounds of the rectangle along the $i$-th dimension.

---

### Strengths of the DIRECT Algorithm

The strength of the DIRECT algorithm lies in its ability to systematically explore the entire search space while focusing on the most promising areas. This systematic coverage helps the algorithm escape local minima, making it particularly effective for objective functions with multiple local minima.

By not requiring the Lipschitz constant, the DIRECT algorithm is adaptable to various optimization problems, including those where the smoothness of the objective function is not well understood.
- `a`: Vector representing the lower bounds of the search space.
- `b`: Vector representing the upper bounds of the search space.
- `max_iterations`: Maximum number of iterations for the optimization (default: 100).
- `min_radius`: Minimum size of hyper-rectangles (`default: 1e-5`).

## Advanced Usage
### Fine-Tuning Optimization:
The `optimize` function offers several parameters for fine-tuning the optimization process:

- `max_iterations`: Sets the maximum number of iterations to perform. Increasing this value may improve the accuracy of the result but will require more computational time.
- `min_radius`: Specifies the minimum allowable size of the hyper-rectangles. This can be adjusted to control the granularity of the search.
Example with custom parameters:

- `max_iterations`: Sets the maximum number of iterations. Increasing this value can improve accuracy but requires more computational time.
- `min_radius`: Specifies the minimum size of hyper-rectangles to control the granularity of the search.

```julia
result = DividedRectangles.optimize(f, a, b, max_iterations=500, min_radius=1e-6)
```
Expand Down

0 comments on commit e86b3ca

Please sign in to comment.