Documentation for mutax
Enabling parallel execution on CPU
By default, JAX on CPU only uses a single core. To enable parallel execution on all available CPU cores, set the jax_num_cpu_devices configuration option appropriately. This should be done at the beginning of your code as follows:
import multiprocessing
import jax
jax.config.update("jax_num_cpu_devices", multiprocessing.cpu_count())
mutax.differential_evolution(func: Callable[[jax.Array], jax.Array], /, bounds: jax.Array, *, key: jax.Array | None = None, strategy: Literal['rand1bin', 'best1bin'] = 'best1bin', maxiter: int = 1000, popsize: int = 15, tol: float = 0.01, atol: float = 0, mutation: float | tuple[float, float] = (0.5, 1.0), recombination: float = 0.8, disp: bool = False, polish: bool = True, updating: Literal['immediate', 'deferred'] = 'immediate', workers: int | Callable[[Callable[[jax.Array], jax.Array], jax.Array], jax.Array] = 1, x0: jax.Array | None = None, vectorized: bool = False) -> OptimizeResults
Find the global minimum of a multivariate function.
Uses the Differential Evolution algorithm to find the global minimum of the given objective function within the specified bounds.
Arguments:
func: The objective function to be minimized. It must take a single argument (a 1D array) and return a scalar.bounds: A 2D array specifying the lower and upper bounds for each dimension of the input space.key: A JAX random key for stochastic operations. You can use e.g.jax.random.key(seed)to generate a key. If not given, a default key is used, which may change between runs.strategy: The differential evolution strategy to use. Can be either "rand1bin" or "best1bin". The "rand1bin" strategy uses a randomly selected population member as the base vector, while "best1bin" uses the best population member found so far.maxiter: The maximum number of generations to evolve the population.popsize: Multiplier for setting the total population size. The population size is determined bypopsize * dim.tol: Relative tolerance for convergence.atol: Absolute tolerance for convergence.mutation: A float or a tuple of two floats specifying the mutation factor. If a tuple is provided, the mutation factor is sampled uniformly from this range for each mutation.recombination: A float in [0, 1] specifying the recombination probability.disp: Whether to print progress messages at each iteration.polish: Whether to perform a local optimization using BFGS at the end of the evolution process to attempt to refine the best solution found. For this local optimization to be effective, the objective function should be differentiable.updating: Strategy for updating the population. Can be either "immediate" or "deferred". "immediate" updates individuals as soon as a better trial vector is found, while "deferred" updates the population after all trial vectors have been evaluated.workers: Number of JAX devices (CPUs/GPUs/TPUs) used for evaluating the objective function. Uses Parajax for parallelization. If set to -1, uses all available JAX devices. Alternatively, if a callable is provided, it should be a callable asworkers(func, x), wherexis a 2D array with each row being a different input to be evaluated. The callable should return a 1D array of function values. Setting this argument to a value other than 1 will overrideupdatingto "deferred".x0: Optional initial guess.vectorized: IfTrue, indicates thatfuncaccepts a 2D array where each column is a different input to be evaluated. If used, it will overrideupdatingto "deferred".
Returns:
An OptimizeResults object containing the optimization results.
Reference:
R. Storn and K. Price, “Differential Evolution - A Simple and Efficient Heuristic for global Optimization over Continuous Spaces,” Journal of Global Optimization, vol. 11, no. 4, pp. 341-359, Dec. 1997, doi: 10.1023/a:1008202821328.
Source code in mutax/__init__.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 | |
mutax.OptimizeResults = jax.scipy.optimize.OptimizeResults
module-attribute
Object holding optimization results.
Attributes:
x: final solution.success: whether the optimization succeeded.status: integer solver specific return code. 0 means converged (nominal), 1=max number of iterations reached.fun: final function value.nfev: integer number of function calls used.njev: integer number of Jacobian evaluations used (only ifpolishwas set toTrue).nit: integer number of iterations of the optimization algorithm.jac: final Jacobian (only if the solution was polished).hess_inv: inverse of the final Hessian (only if the solution was polished).