@@ -103,23 +103,33 @@ def various_doctests():
103
103
104
104
A simple first overall test:
105
105
106
- >>> import cma
107
- >>> res = cma.fmin(cma.ff.elli, 3*[1], 1,
108
- ... {'CMA_diagonal':2, 'seed':1, 'verb_time':0})
109
- ... # doctest: +ELLIPSIS
110
- (3_w,7)-aCMA-ES (mu_w=2.3,w_1=58%) in dimension 3 (seed=1,...)
111
- Covariance matrix is diagonal for 2 iterations (1/ccov=6...
112
- Iterat #Fevals function value axis ratio sigma ...
113
- >>> assert res[1] < 1e-6
114
- >>> assert res[2] < 2000
106
+ >>> import cma
107
+ >>> res = cma.fmin(cma.ff.elli, 3*[1], 1,
108
+ ... {'CMA_diagonal':2, 'seed':1, 'verbose':-9})
109
+ >>> assert res[1] < 1e-6
110
+ >>> assert res[2] < 2000
111
+
112
+ Testing `args` argument:
113
+
114
+ >>> def maxcorr(m):
115
+ ... val = 0
116
+ ... for i in range(len(m)):
117
+ ... for j in range(i + 1, len(m)):
118
+ ... val = max((val, abs(m[i, j])))
119
+ ... return val
120
+ >>> x, es = cma.fmin2(cma.ff.elli, [1, 0, 0], 0.5, {'verbose':-9}, args=[True]) # rotated
121
+ >>> assert maxcorr(es.sm.correlation_matrix) > 0.9, es.sm.correlation_matrix
122
+ >>> es = cma.CMAEvolutionStrategy([1, 0, 0], 0.5,
123
+ ... {'verbose':-9}).optimize(cma.ff.elli, args=[1])
124
+ >>> assert maxcorr(es.sm.correlation_matrix) > 0.9, es.sm.correlation_matrix
115
125
116
126
Testing output file consistency with diagonal option:
117
127
118
- >>> import cma
119
- >>> for val in (0, True, 2, 3):
120
- ... _ = cma.fmin(cma.ff.sphere, 3 * [1], 1,
121
- ... {'verb_disp':0, 'CMA_diagonal':val, 'maxiter':5})
122
- ... _ = cma.CMADataLogger().load()
128
+ >>> import cma
129
+ >>> for val in (0, True, 2, 3):
130
+ ... _ = cma.fmin(cma.ff.sphere, 3 * [1], 1,
131
+ ... {'verb_disp':0, 'CMA_diagonal':val, 'maxiter':5})
132
+ ... _ = cma.CMADataLogger().load()
123
133
124
134
Test on the Rosenbrock function with 3 restarts. The first trial only
125
135
finds the local optimum, which happens in about 20% of the cases.
0 commit comments