Changeset 733
- Timestamp:
- 07/28/14 08:40:55 (22 months ago)
- Location:
- mystic
- Files:
-
- 2 edited
- 6 moved
Legend:
- Unmodified
- Added
- Removed
-
mystic/examples/README
r723 r733 1 1 == Notes on mystic examples == 2 NOTE: for all examples that use matplotlib, please use the TKAgg backend. 3 Thus, run the examples like this: "python example04.py -dTKAgg" 4 (see ticket #36 for more details).2 Dependencies: 3 - Several of the examples require matplotlib to be installed. 4 - For the examples that use matplotlib, see trac ticket #36 for more details. 5 5 6 Dependencies: 7 - All examples with prefix "example" should run without new dependencies, and are intended as a tutorial (i.e. TRY THESE FIRST). 6 Other dependencies: 7 - Examples with prefix "example" are part of the tutorial (TRY THESE FIRST). 8 - All examples with prefix "example" should run without new dependencies. 8 9 - All examples with prefix "test_" should run without new dependencies. 9 - All examples with prefix "gplot_" requre s gnuplot-py to be installed.10 - All examples with prefix "gplot_" requre gnuplot-py for visualization. 10 11 11 12 Exceptions to the rule: 12 - The following examples also require scipy to be installed. (tested on version 0.4.8 and 0.7.0): 13 . test_lorentzian.py 14 . test_mogi_anneal.py, 15 . test_twistedgaussian.py 16 . test_twistedgaussian2.py 13 - The following examples also require scipy to be installed: 14 . test_lorentzian.py 15 . test_mogi_anneal.py, 17 16 18 17 Special examples: 19 18 - All examples with prefix "rosetta_" require park to be installed. (tests on version park-1.2). Run with "--park" to execute with park. See "--help" for more options. 20 - The derun.py example requires pyre (from pythia-0.8) to be installed, and drives the otherwise useless 'dummy.py'.21 19 22 20 … … 33 31 Notes on the "mogi" tests/examples: 34 32 - test_mogi.py: One mogi source with noise, comparison between DE and Conjugate Gradient, Simplex, and least squares (Levenberg Marquardt). CG / lsq don't work very well. lsq should work when bounds on the parameters are given, but minpack (wrapped by scipy) version doesn't seem to support bounds. 35 - sam_mogi.py: charts the progress of scipy's Nelder Mead and draws with matlab36 33 - test_mogi_anneal.py: tests with scipy simulated annealing, but hasn't been tuned, so again, doesn't work at all. 37 34 - test_mogi2.py: two mogi sources -
mystic/mystic/scemtools.py
r732 r733 26 26 """ 27 27 28 from numpy import mean, cov, array, zeros, identity, transpose29 from numpy.random import multivariate_normal30 28 import numpy 31 29 try: … … 39 37 def multinormal_pdf(mean, var): 40 38 """var must be symmetric positive definite """ 41 from numpy.linalg import inv, det 42 from numpy import transpose, array, exp, sqrt, pi, dot 43 vinv = inv(var) 44 mu = array(mean).flatten() 39 import numpy 40 vinv = numpy.linalg.inv(var) 41 mu = numpy.array(mean).flatten() 45 42 n = len(mu) 46 43 47 44 # check that var is properly sized 48 dum = dot(mu,var) -dot(var,mu)49 50 prefactor = 1./ sqrt((2 * pi)**n *det(var))45 dum = numpy.dot(mu,var) - numpy.dot(var,mu) 46 47 prefactor = 1./numpy.sqrt((2 * numpy.pi)**n * numpy.linalg.det(var)) 51 48 def _(x): 52 xm = array(x) - mu53 return prefactor * exp(-0.5 * dot(xm,dot(vinv,xm)) )49 xm = numpy.array(x) - mu 50 return prefactor * numpy.exp(-0.5 * numpy.dot(xm,numpy.dot(vinv,xm)) ) 54 51 return _ 55 52 … … 76 73 77 74 """ 78 from numpy import array, transpose79 cards = array(inarray)75 import numpy 76 cards = numpy.array(inarray) 80 77 N = len(cards) 81 78 # this bit of numpy will give, for N=20, n = 5 82 79 # ord = [ [0,5,10,15], [1,6,11,16], [2,7,12,17], [3,8,13,18], [4,9,14,19] ] 83 ord = transpose(array(range(N)).reshape(N/n, n))80 ord = numpy.transpose(numpy.array(range(N)).reshape(N/n, n)) 84 81 return [cards[x] for x in ord] 85 82 86 83 def sort_and_deal(cards, target, nplayers): 87 from numpy import argsort88 c = array(map(target, cards))89 o = list(reversed( argsort(c)))84 import numpy 85 c = numpy.array(map(target, cards)) 86 o = list(reversed(numpy.argsort(c))) 90 87 # from best to worst 91 88 sorted_deck = cards[o] … … 95 92 """default is descending...""" 96 93 import numpy 97 aa,bb = array(a),array(b)94 aa,bb = numpy.array(a), numpy.array(b) 98 95 if ord == -1: 99 96 o = list(reversed(bb.argsort())) … … 106 103 # should use the one below instead. 107 104 # this is faster than sort_complex 108 b = array(a) 105 import numpy 106 b = numpy.array(a) 109 107 o = list(reversed(b.argsort())) 110 108 return c[o], list(b[o]) … … 113 111 # this is dumb, because c (i.e., a, are almost sorted) 114 112 # should use the one below instead. 113 import numpy 115 114 D = zip(a,c) 116 115 def mycmp(x,y): … … 201 200 202 201 """ 203 202 import numpy 204 203 # function level constants 205 204 T = 100000. # predefined likelihood ratio. Paragraph 45 of [1.] 206 205 207 from numpy import mean, cov, array, zeros, identity, transpose208 209 206 # Sort Ck according to ak 210 207 #Ck, ak = sort_complex0(Ck, ak) … … 217 214 M = Ck.shape[0] 218 215 219 mu = mean(Ck,0) # row mean216 mu = numpy.mean(Ck,0) # row mean 220 217 221 218 # (numpy.cov takes data in columns) 222 Sigma = cov(transpose(Ck))219 Sigma = numpy.cov(numpy.transpose(Ck)) 223 220 224 221 # Gamma (line 35 of [1]. Best to Worst) … … 226 223 227 224 if len(Sak) >= M: 228 meansak = mean(Sak[-M:])229 else: 230 meansak = mean(Sak)231 alpha_k = mean(ak) / (meansak+TINY)225 meansak = numpy.mean(Sak[-M:]) 226 else: 227 meansak = numpy.mean(Sak) 228 alpha_k = numpy.mean(ak) / (meansak+TINY) 232 229 233 230 if alpha_k < T: 234 231 # Paragraph 37 of [1] 235 232 basept = Sk[-1] 236 else: # mean(asak) is very close to zero.233 else: # numpy.mean(asak) is very close to zero. 237 234 # Paragraph 38 of [1] 238 235 basept = mu 239 236 240 237 # TODO should take a proposal instead ! 241 Yt = multivariate_normal(basept, cn*cn * Sigma)238 Yt = numpy.random.multivariate_normal(basept, cn*cn * Sigma) 242 239 cY = target(Yt) 243 240
Note: See TracChangeset
for help on using the changeset viewer.