Diff of /cmaes/utils.py [000000] .. [077a87]

Switch to unified view

a b/cmaes/utils.py
1
# Copyright (c) 2015, Disney Research
2
# All rights reserved.
3
#
4
# Author(s): Sehoon Ha <sehoon.ha@disneyresearch.com>
5
# Disney Research Robotics Group
6
7
8
import numpy as np
9
10
11
def grad(fun, x, h):
12
    n = len(x)
13
    g = np.zeros(n)
14
    for i in range(n):
15
        dx = np.zeros(n)
16
        dx[i] = h
17
        f1 = fun(x - dx)
18
        f2 = fun(x + dx)
19
        g[i] = (0.5 * f2 - 0.5 * f1) / h
20
    return g