- Timestamp:
- 11/19/12 17:05:38 (3 years ago)
- Location:
- branches/decorate
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/decorate/surrogate.py
r535 r591 64 64 65 65 from memoize import memoized0_round, memoized0_nopickle_round 66 from memoize import memoized0_archived, memoized0_nopickle_archived 66 67 #@memoized0_round(0) # slower, but more robust 67 @memoized0_nopickle_round(0) 68 #@memoized0_nopickle_round(0) 69 #@memoized0_archived() # slower, but more robust 70 @memoized0_nopickle_archived() 68 71 def marc_surr(x): 69 72 """calculate perforation area using a tanh-based model surrogate -
branches/decorate/test_timed_monitor.py
r579 r591 174 174 print " upper bounds: %s" % upper_bounds 175 175 # print " ..." 176 try: model.load('surrogate.pkl') 177 except: pass 176 178 diameter = UQ(RVstart,RVend,lower_bounds,upper_bounds) 179 try: model.dump('surrogate.pkl') 180 except: pass 177 181 178 182 # EOF -
branches/decorate/test_wrapper.py
r580 r591 128 128 129 129 130 def test_discrete(): 131 132 @discrete([1.0, 3.5, 5.5, 7.0]) 133 def discrete_squared(x): 134 return x**2 135 136 assert discrete_squared(5.6) == 5.5**2 137 assert discrete_squared([1, 3]) == asarray([1.0, 3.5])**2 138 discrete_squared.samples([1.0, 7.0]) 139 assert discrete_squared(5.6) == 7.0**2 140 141 130 142 131 143 if __name__ is '__main__': … … 138 150 test_bounded() 139 151 test_mixedin() 152 test_discrete() 140 153 141 154 -
branches/decorate/wrapper.py
r580 r591 50 50 51 51 52 from numpy import asarray, any, inf 52 from numpy import asarray, any, inf, vectorize 53 53 def bounded(min=None, max=None): 54 54 """impose an infinite barrier box constraint on a function … … 107 107 108 108 109 #from random import sample, choice 110 def discrete(samples): 111 """impose a discrete set of input values for the selected function 112 113 The function's input will be mapped to the given discrete set 114 115 >>> @decorate([1.0, 2.0]) 116 ... def identity(x): 117 ... return x 118 119 >>> identity([0.123, 1.789, 4.000]) 120 [1.0, 2.0, 2.0]""" #FIXME: should return same type as input 121 samples = [asarray(samples)] 122 samples[0].sort() 123 124 #XXX: refactor to use points_factory(samples) 125 def _points(alist): 126 alist = asarray(alist) 127 alist.sort() 128 samples[0] = alist 129 130 #XXX: refactor to use argnear_factory(samples) 131 def _argnear(xi): 132 arghi = sum(xi > samples[0]) 133 arglo = max(0, arghi - 1) # minimum = x[0] 134 if arghi == len(samples[0]): 135 arghi = arglo # maximum = x[-1] 136 return arglo, arghi 137 138 def _near(xi, lo, hi): 139 if hi - xi < xi - lo: 140 return hi 141 return lo 142 143 argnear = vectorize(_argnear) 144 near = vectorize(_near) 145 146 def dec(f): 147 def func(x, *args, **kwds): 148 arglo, arghi = argnear(x) 149 xp = near(x, samples[0][arglo], samples[0][arghi]) 150 return f(xp, *args, **kwds) 151 func.samples = _points 152 return func 153 return dec 154 155 109 156 # EOF
Note: See TracChangeset
for help on using the changeset viewer.