Skip to content

Commit

Permalink
Add rosenbrock example
Browse files Browse the repository at this point in the history
  • Loading branch information
d53dave committed Nov 22, 2019
1 parent bf56ad8 commit a655d87
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
37 changes: 37 additions & 0 deletions examples/rosenbrock/drop_wave.conf
@@ -0,0 +1,37 @@
{
# This name will be used to TODO
name = langermann_5000_1000

save_to_file {
type = best # or all, none
# base_dir = /home/username/optimization_results/ # This is optional, will use cwd by default
}

model {
skip_typecheck = true
}

optimization {
max_steps = 1000
initial_temp = 100.0
thread_count = 16
}

debug {
gpu_simulator = True
}

remote {
local_docker = True
# platform = aws
# aws {
# region = eu-central-1
# # These will be picked up from ~/.aws/credentials or ENV
# # secret_key = 123
# # access_key = 123

# worker_count = 1
# timeout = 1000
# }
}
}
71 changes: 71 additions & 0 deletions examples/rosenbrock/drop_wave.py
@@ -0,0 +1,71 @@
"""Drop-Wave Function
https://www.sfu.ca/~ssurjano/drop.html
Dimensions: 2
The Drop-Wave function is multimodal and highly complex.
Input Domain:
The function is usually evaluated on the square xi in [-5.12, 5.12], for all i = 1, 2.
Global Minimum:
f(x*) = -1 at x* = (0, 0)
Reference:
Global Optimization Test Functions Index. Retrieved June 2013, from http://infinity77.net/global_optimization/test_functions.html#test-functions-index.
"""

import math

from csaopt.model import RandomDistribution, Precision
from typing import MutableSequence, Sequence, Any, Tuple
from math import pi

# Configuration


def distribution() -> RandomDistribution:
return RandomDistribution.Normal


def precision() -> Precision:
return Precision.Float32


def dimensions() -> int:
return 2


def empty_state() -> Tuple:
return (0.0, 0.0)


# Functions


def cool(initial_temp: float, old_temp: float, step: int) -> float:
return initial_temp * math.pow(0.95, step)


def acceptance_func(e1: float, e2: float, temp: float) -> bool:
return math.exp(-(e2 - e1) / temp) > 0.5


def initialize(state: MutableSequence, randoms: Sequence[float]) -> None:
for i in range(len(randoms)):
state[i] = randoms[i]
return


def evaluate(state: Sequence) -> float:
x1 = state[0]
x2 = state[1]
t1 = x1 * x1 + x2 * x2
return -((1 + math.cos(12 * math.sqrt(t1))) / (0.5 * t1 + 2))


def generate_next(state: Sequence, new_state: MutableSequence, randoms: Sequence[float]) -> Any:
for i in range(len(state)):
new_state[i] = clamp(-5.12, state[i] + randoms[i], 5.12)
return

0 comments on commit a655d87

Please sign in to comment.