Changeset 733


Ignore:
Timestamp:
07/28/14 08:40:55 (22 months ago)
Author:
mmckerns
Message:

moved pyre examples to examples_other; cleaned up imports on scemtools

Location:
mystic
Files:
2 edited
6 moved

Legend:

Unmodified
Added
Removed
  • mystic/examples/README

    r723 r733  
    11== 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). 
     2Dependencies: 
     3 - Several of the examples require matplotlib to be installed. 
     4 - For the examples that use matplotlib, see trac ticket #36 for more details. 
    55 
    6 Dependencies: 
    7  - All examples with prefix "example" should run without new dependencies, and are intended as a tutorial (i.e. TRY THESE FIRST). 
     6Other 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. 
    89 - All examples with prefix "test_" should run without new dependencies. 
    9  - All examples with prefix "gplot_" requres gnuplot-py to be installed. 
     10 - All examples with prefix "gplot_" requre gnuplot-py for visualization. 
    1011 
    1112Exceptions 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, 
    1716 
    1817Special examples: 
    1918 - 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'. 
    2119 
    2220 
     
    3331Notes on the "mogi" tests/examples: 
    3432 - 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 matlab 
    3633 - test_mogi_anneal.py: tests with scipy simulated annealing, but hasn't been tuned, so again, doesn't work at all. 
    3734 - test_mogi2.py: two mogi sources 
  • mystic/mystic/scemtools.py

    r732 r733  
    2626""" 
    2727 
    28 from numpy import mean, cov, array, zeros, identity, transpose 
    29 from numpy.random import multivariate_normal 
    3028import numpy 
    3129try: 
     
    3937def multinormal_pdf(mean, var): 
    4038    """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() 
    4542    n = len(mu) 
    4643 
    4744    # 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)) 
    5148    def _(x): 
    52         xm = array(x) - mu 
    53         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)) ) 
    5451    return _ 
    5552 
     
    7673 
    7774    """ 
    78     from numpy import array, transpose 
    79     cards = array(inarray) 
     75    import numpy 
     76    cards = numpy.array(inarray) 
    8077    N = len(cards) 
    8178    # this bit of numpy will give, for N=20, n = 5 
    8279    # 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)) 
    8481    return [cards[x] for x in ord]  
    8582 
    8683def sort_and_deal(cards, target, nplayers): 
    87     from numpy import argsort 
    88     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))) 
    9087    # from best to worst 
    9188    sorted_deck = cards[o] 
     
    9592    """default is descending...""" 
    9693    import numpy 
    97     aa,bb = array(a), array(b) 
     94    aa,bb = numpy.array(a), numpy.array(b) 
    9895    if ord == -1: 
    9996        o = list(reversed(bb.argsort())) 
     
    106103    # should use the one below instead. 
    107104    # this is faster than sort_complex 
    108     b = array(a) 
     105    import numpy 
     106    b = numpy.array(a) 
    109107    o = list(reversed(b.argsort())) 
    110108    return c[o], list(b[o]) 
     
    113111    # this is dumb, because c (i.e., a, are almost sorted) 
    114112    # should use the one below instead. 
     113    import numpy 
    115114    D = zip(a,c) 
    116115    def mycmp(x,y): 
     
    201200 
    202201    """ 
    203  
     202    import numpy 
    204203    # function level constants 
    205204    T = 100000. # predefined likelihood ratio. Paragraph 45 of [1.] 
    206205 
    207     from numpy import mean, cov, array, zeros, identity, transpose 
    208      
    209206    # Sort Ck according to ak 
    210207    #Ck, ak = sort_complex0(Ck, ak)  
     
    217214    M = Ck.shape[0] 
    218215 
    219     mu = mean(Ck,0) # row mean 
     216    mu = numpy.mean(Ck,0) # row mean 
    220217 
    221218    # (numpy.cov takes data in columns) 
    222     Sigma = cov(transpose(Ck))  
     219    Sigma = numpy.cov(numpy.transpose(Ck))  
    223220 
    224221    # Gamma (line 35 of [1]. Best to Worst) 
     
    226223    
    227224    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) 
    232229   
    233230    if alpha_k < T: 
    234231         # Paragraph 37 of [1] 
    235232         basept = Sk[-1] 
    236     else: # mean(asak) is very close to zero. 
     233    else: # numpy.mean(asak) is very close to zero. 
    237234         # Paragraph 38 of [1] 
    238235         basept = mu 
    239236 
    240237    # TODO should take a proposal instead ! 
    241     Yt = multivariate_normal(basept,  cn*cn * Sigma) 
     238    Yt = numpy.random.multivariate_normal(basept,  cn*cn * Sigma) 
    242239    cY = target(Yt)     
    243240 
Note: See TracChangeset for help on using the changeset viewer.