- Timestamp:
- 01/03/15 09:21:20 (17 months ago)
- Location:
- mystic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
mystic/_math/measures.py
r776 r777 174 174 return mean(svar, weights) 175 175 176 def std(samples, weights=None): #, _mean=None): 177 """calculate the (weighted) standard deviation for a list of points 178 179 Inputs: 180 samples -- a list of sample points 181 weights -- a list of sample weights 182 """ 183 from numpy import sqrt 184 return sqrt(variance(samples, weights)) # _mean) 185 176 186 177 187 ##### coordinate shift methods ##### … … 218 228 # ...so likely, must scale the weights... or scale each point differently 219 229 230 def impose_std(s, samples, weights=None): 231 """impose a standard deviation on a list of (weighted) points 232 (this function is 'mean-preserving') 233 234 Inputs: 235 s -- the target standard deviation 236 samples -- a list of sample points 237 weights -- a list of sample weights 238 """ 239 return impose_variance(s**2, samples, weights) 220 240 221 241 def impose_spread(r, samples, weights=None): #FIXME: fails if len(samples) = 1 … … 482 502 return samples, wts # "mean-preserving" 483 503 504 def impose_reweighted_std(s, samples, weights=None, solver=None): 505 """impose a standard deviation on a list of points, using reweighting""" 506 return impose_reweighted_variance(s**2, samples, weights, solver) 484 507 485 508 ##### misc methods ##### -
mystic/mystic/constraints.py
r776 r777 146 146 return factory 147 147 return decorate 148 149 150 def with_std(target): 151 """bind a standard deviation constraint to a given constraints function. 152 153 Inputs: 154 target -- the target standard deviation 155 156 A constraints function takes an iterable x as input, returning a modified x. 157 This function is an "outer" coupling of "impose_std" onto another 158 constraints function c(x), such that: x' = impose_std(target, c(x)). 159 160 For example: 161 >>> @with_std(1.0) 162 ... def constraint(x): 163 ... x[-1] = x[0] 164 ... return x 165 ... 166 >>> x = constraint([1,2,3]) 167 >>> print x 168 [0.6262265521467858, 2.747546895706428, 0.6262265521467858] 169 >>> std(x) 170 0.99999999999999956 171 """ 172 return with_variance(target**2) 148 173 149 174
Note: See TracChangeset
for help on using the changeset viewer.