Esempio n. 1
0
    def _CollapseAt(inst, info=False):
        if info: info = lambda x:x
        else: info = bool
        hist = inst.energy_history
        lg = len(hist)
        if lg <= generations: return info(null)
        #XXX: might want to log/utilize *where* collapse happens...
#       if ct.collapse_at(inst._stepmon, **kwds): return info(doc)
        collapsed = ct.collapse_at(inst._stepmon, **kwds)
        if collapsed: return info(doc + ' at %s' % str(collapsed))
        # otherwise bail out
        return info(null) 
Esempio n. 2
0
# Copyright (c) 1997-2016 California Institute of Technology.
# Copyright (c) 2016-2022 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/mystic/blob/master/LICENSE

import mystic.collapse as ct
import numpy as np
import mystic as my
m = my.monitors._load('_log.py')
# cleanup *pyc
import os
try: os.remove('_log.pyc')
except OSError: pass

# at
x = ct.collapse_at(m, target=0.0, tolerance=0.05, mask=None)
assert x == set((1, 7, 8, 9, 10, 11, 12, 14))
x = ct.collapse_at(m, target=0.0, tolerance=0.05, mask=set((10,11,12)))
assert x == set((1, 7, 8, 9, 14))
try: ct.collapse_at(m, target=0.0, mask=10); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=(10,11,12)); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=[(10,11,12)])
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=[(10,11,12),(13,14,15)]); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=((10,11),(12,13))); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=(np.array((10,11)),np.array((12,13)))); raise RuntimeError()
except TypeError: pass
Esempio n. 3
0
# cleanup *pyc
import os
try:
    os.remove('_log.pyc')
except OSError:
    pass

import mystic.termination as mt
from mystic.solvers import DifferentialEvolutionSolver
solver = DifferentialEvolutionSolver(2 * sum(m._npts))
solver.SetRandomInitialPoints()
solver.SetGenerationMonitor(m)
##############################################

# print('collapse_at')
ix = ct.collapse_at(m)
# (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17)
assert not ct.collapse_at(m, mask=ix)
ix = ct.collapse_at(m, target=0.0)
# (1, 7, 8, 9, 10, 11, 12, 14)
assert not ct.collapse_at(m, target=0.0, mask=ix)
ix = ct.collapse_at(m, target=m.x[-1])
assert not ct.collapse_at(m, target=m.x[-1], mask=ix)

# print('collapse_as')
ix = ct.collapse_as(m)
# set([(10, 11), (7, 12), (10, 12), (8, 9), (11, 14), (7, 11), (1, 11), (16, 17), (8, 14), (1, 14), (8, 10), (9, 11), (7, 10), (1, 10), (7, 14), (9, 14), (12, 14), (8, 11), (9, 10), (1, 9), (11, 12), (7, 9), (1, 12), (8, 12), (3, 4), (1, 8), (10, 14), (6, 13), (1, 7), (7, 8), (9, 12)])
assert not ct.collapse_as(m, mask=ix)

# print('collapse_weight')
ix = ct.collapse_weight(m)
Esempio n. 4
0
#  - https://github.com/uqfoundation/mystic/blob/master/LICENSE

import mystic.collapse as ct
import numpy as np
import mystic as my

m = my.monitors._load('_log.py')
# cleanup *pyc
import os
try:
    os.remove('_log.pyc')
except OSError:
    pass

# at
x = ct.collapse_at(m, target=0.0, tolerance=0.05, mask=None)
assert x == set((1, 7, 8, 9, 10, 11, 12, 14))
x = ct.collapse_at(m, target=0.0, tolerance=0.05, mask=set((10, 11, 12)))
assert x == set((1, 7, 8, 9, 14))
try:
    ct.collapse_at(m, target=0.0, mask=10)
    raise RuntimeError()
except TypeError:
    pass
try:
    ct.collapse_at(m, target=0.0, mask=(10, 11, 12))
    raise RuntimeError()
except TypeError:
    pass
try:
    ct.collapse_at(m, target=0.0, mask=[(10, 11, 12)])
Esempio n. 5
0
# Copyright (c) 1997-2016 California Institute of Technology.
# Copyright (c) 2016-2019 The Uncertainty Quantification Foundation.
# License: 3-clause BSD.  The full license text is available at:
#  - https://github.com/uqfoundation/mystic/blob/master/LICENSE

import mystic.collapse as ct
import numpy as np
import mystic as my
m = my.monitors._load('_log.py')
# cleanup *pyc
import os
try: os.remove('_log.pyc')
except OSError: pass

# at
x = ct.collapse_at(m, target=0.0, tolerance=0.05, mask=None)
assert x == set((1, 7, 8, 9, 10, 11, 12, 14))
x = ct.collapse_at(m, target=0.0, tolerance=0.05, mask=set((10,11,12)))
assert x == set((1, 7, 8, 9, 14))
try: ct.collapse_at(m, target=0.0, mask=10); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=(10,11,12)); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=[(10,11,12)])
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=[(10,11,12),(13,14,15)]); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=((10,11),(12,13))); raise RuntimeError()
except TypeError: pass
try: ct.collapse_at(m, target=0.0, mask=(np.array((10,11)),np.array((12,13)))); raise RuntimeError()
except TypeError: pass
Esempio n. 6
0
import mystic as my
m = my.monitors._load('_log.py')
# cleanup *pyc
import os
try: os.remove('_log.pyc')
except OSError: pass

import mystic.termination as mt
from mystic.solvers import DifferentialEvolutionSolver
solver = DifferentialEvolutionSolver(2*sum(m._npts))
solver.SetRandomInitialPoints()
solver.SetGenerationMonitor(m)
##############################################

# print 'collapse_at'
ix = ct.collapse_at(m)
# (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17)
assert not ct.collapse_at(m, mask=ix)
ix = ct.collapse_at(m, target=0.0)
# (1, 7, 8, 9, 10, 11, 12, 14)
assert not ct.collapse_at(m, target=0.0, mask=ix)
ix = ct.collapse_at(m, target=m.x[-1]) 
assert not ct.collapse_at(m, target=m.x[-1], mask=ix)

# print 'collapse_as'
ix = ct.collapse_as(m)
# set([(10, 11), (7, 12), (10, 12), (8, 9), (11, 14), (7, 11), (1, 11), (16, 17), (8, 14), (1, 14), (8, 10), (9, 11), (7, 10), (1, 10), (7, 14), (9, 14), (12, 14), (8, 11), (9, 10), (1, 9), (11, 12), (7, 9), (1, 12), (8, 12), (3, 4), (1, 8), (10, 14), (6, 13), (1, 7), (7, 8), (9, 12)])
assert not ct.collapse_as(m, mask=ix)

# print 'collapse_weight'
ix = ct.collapse_weight(m)