Changeset 48462b0 in sasmodels for sasmodels/models


Ignore:
Timestamp:
Jul 31, 2017 1:24:42 AM (7 years ago)
Author:
Paul Kienzle <pkienzle@…>
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
109d963
Parents:
404ebbd
Message:

tuned random model generation for even more models

Location:
sasmodels/models
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/models/gauss_lorentz_gel.py

    ra807206 r48462b0  
    33but typically a physical rather than chemical network. 
    44It is modeled as a sum of a low-q exponential decay (which happens to 
    5 give a functional form similar to Guinier scattering, so interpret with  
     5give a functional form similar to Guinier scattering, so interpret with 
    66care) plus a Lorentzian at higher-q values. See also the gel_fit model. 
    77 
     
    8888 
    8989 
     90def random(): 
     91    import numpy as np 
     92    gauss_scale = 10**np.random.uniform(1, 3) 
     93    lorentz_scale = 10**np.random.uniform(1, 3) 
     94    cor_length_static = 10**np.random.uniform(0, 3) 
     95    cor_length_dynamic = 10**np.random.uniform(0, 3) 
     96    pars = dict( 
     97        #background=0, 
     98        scale=1, 
     99        gauss_scale=gauss_scale, 
     100        lorentz_scale=lorentz_scale, 
     101        cor_length_static=cor_length_static, 
     102        cor_length_dynamic=cor_length_dynamic, 
     103    ) 
     104    return pars 
     105 
     106 
    90107demo = dict(scale=1, background=0.1, 
    91108            gauss_scale=100.0, 
  • sasmodels/models/gaussian_peak.py

    ra807206 r48462b0  
    5151# VR defaults to 1.0 
    5252 
    53 demo = dict(scale=1, background=0, peak_pos=0.05, sigma=0.005) 
     53def random(): 
     54    import numpy as np 
     55    peak_pos = 10**np.random.uniform(-3, -1) 
     56    sigma = 10**np.random.uniform(-1.3, -0.3)*peak_pos 
     57    scale = 10**np.random.uniform(0, 4) 
     58    pars = dict( 
     59        #background=1e-8, 
     60        scale=scale, 
     61        peak_pos=peak_pos, 
     62        sigam=sigma, 
     63    ) 
     64    return pars 
  • sasmodels/models/gel_fit.c

    ra807206 r48462b0  
    1010    double lorentzian_term = square(q*cor_length); 
    1111    lorentzian_term = 1.0 + ((fractal_dim + 1.0)/3.0)*lorentzian_term; 
    12     lorentzian_term = pow(lorentzian_term, (fractal_dim/2.0) ); 
     12    lorentzian_term = pow(lorentzian_term, fractal_dim/2.0 ); 
    1313 
    1414    // Exponential Term 
    1515    ////////////////////////double d(x[i]*x[i]*rg*rg); 
    1616    double exp_term = square(q*rg); 
    17     exp_term = exp(-1.0*(exp_term/3.0)); 
     17    exp_term = exp(-exp_term/3.0); 
    1818 
    1919    // Scattering Law 
  • sasmodels/models/gel_fit.py

    ra807206 r48462b0  
    7171source = ["gel_fit.c"] 
    7272 
     73def random(): 
     74    import numpy as np 
     75    guinier_scale = 10**np.random.uniform(1, 3) 
     76    lorentz_scale = 10**np.random.uniform(1, 3) 
     77    rg = 10**np.random.uniform(1, 5) 
     78    fractal_dim = np.random.uniform(0, 6) 
     79    cor_length = 10**np.random.uniform(0, 3) 
     80    pars = dict( 
     81        #background=0, 
     82        scale=1, 
     83        guinier_scale=guinier_scale, 
     84        lorentz_scale=lorentz_scale, 
     85        rg=rg, 
     86        fractal_dim=fractal_dim, 
     87        cor_length=cor_length 
     88    ) 
     89    return pars 
     90 
    7391demo = dict(background=0.01, 
    7492            guinier_scale=1.7, 
  • sasmodels/models/guinier.py

    r404ebbd r48462b0  
    5151def random(): 
    5252    import numpy as np 
    53     scale = 10**np.random.uniform(1, 5) 
    54     # Note: compare.py has rg cutoff for guinier, so use that 
     53    scale = 10**np.random.uniform(1, 4) 
     54    # Note: compare.py has Rg cutoff of 1e-30 at q=1 for guinier, so use that 
     55    # log_10 Ae^(-(q Rg)^2/3) = log_10(A) - (q Rg)^2/ (3 ln 10) > -30 
     56    #   => log_10(A) > Rg^2/(3 ln 10) - 30 
    5557    q_max = 1.0 
    5658    rg_max = np.sqrt(90*np.log(10) + 3*np.log(scale))/q_max 
  • sasmodels/models/guinier_porod.py

    rcdcebf1 r48462b0  
    44and dimensionality of scattering objects, including asymmetric objects 
    55such as rods or platelets, and shapes intermediate between spheres 
    6 and rods or between rods and platelets, and overcomes some of the  
     6and rods or between rods and platelets, and overcomes some of the 
    77deficiencies of the (Beaucage) Unified_Power_Rg model (see Hammouda, 2010). 
    88 
     
    7777                        scale = Guinier Scale 
    7878                        s = Dimension Variable 
    79                         Rg = Radius of Gyration [A]  
     79                        Rg = Radius of Gyration [A] 
    8080                        porod_exp = Porod Exponent 
    8181                        background  = Background [1/cm]""" 
     
    114114Iq.vectorized = True # Iq accepts an array of q values 
    115115 
     116def random(): 
     117    import numpy as np 
     118    rg = 10**np.random.uniform(1, 5) 
     119    s = np.random.uniform(0, 3) 
     120    porod_exp = s + np.random.uniform(0, 3) 
     121    pars = dict( 
     122        #scale=1, background=0, 
     123        rg=rg, 
     124        s=s, 
     125        porod_exp=porod_exp, 
     126    ) 
     127    return pars 
     128 
    116129demo = dict(scale=1.5, background=0.5, rg=60, s=1.0, porod_exp=3.0) 
    117130 
  • sasmodels/models/line.py

    r404ebbd r48462b0  
    7070def random(): 
    7171    import numpy as np 
    72     slope = 1e5*np.random.uniform(-1, 1) 
     72    scale = 10**np.random.uniform(0, 3) 
     73    slope = np.random.uniform(-1, 1)*1e2 
    7374    offset = 1e-5 + (0 if slope > 0 else -slope) 
    74     intercept = 10**np.random.uniform(0, 5) + offset 
     75    intercept = 10**np.random.uniform(0, 1) + offset 
    7576    pars = dict( 
    76         scale=1, background=0, 
     77        #background=0, 
     78        scale=scale, 
    7779        slope=slope, 
    7880        intercept=intercept, 
  • sasmodels/models/spinodal.py

    rbba9361 r48462b0  
    33---------- 
    44 
    5 This model calculates the SAS signal of a phase separating solution under spinodal decomposition.  
     5This model calculates the SAS signal of a phase separating solution under spinodal decomposition. 
    66The scattering intensity $I(q)$ is calculated as 
    77 
    8 .. math::  
     8.. math:: 
    99    I(q) = I_{max}\frac{(1+\gamma/2)x^2}{\gamma/2+x^{2+\gamma}}+B 
    1010 
    11 where $x=q/q_0$ and $B$ is a flat background. The characteristic structure length  
    12 scales with the correlation peak at $q_0$. The exponent $\gamma$ is equal to  
     11where $x=q/q_0$ and $B$ is a flat background. The characteristic structure length 
     12scales with the correlation peak at $q_0$. The exponent $\gamma$ is equal to 
    1313$d+1$ with d the dimensionality of the off-critical concentration mixtures. 
    14 A transition to $\gamma=2d$ is seen near the percolation threshold into the  
     14A transition to $\gamma=2d$ is seen near the percolation threshold into the 
    1515critical concentration regime. 
    1616 
     
    1818---------- 
    1919 
    20 H. Furukawa. Dynamics-scaling theory for phase-separating unmixing mixtures:  
     20H. Furukawa. Dynamics-scaling theory for phase-separating unmixing mixtures: 
    2121Growth rates of droplets and scaling properties of autocorrelation functions. Physica A 123,497 (1984). 
    2222 
     
    2525 
    2626* **Author:** Dirk Honecker **Date:** Oct 7, 2016 
    27 * **Last Modified by:**  
    28 * **Last Reviewed by:**  
     27* **Last Modified by:** 
     28* **Last Reviewed by:** 
    2929""" 
    3030 
     
    4646# pylint: disable=bad-whitespace, line-too-long 
    4747#             ["name", "units", default, [lower, upper], "type", "description"], 
    48 parameters = [["scale",    "",      1.0, [-inf, inf], "", "Scale factor"], 
    49               ["gamma",      "",    3.0, [-inf, inf], "", "Exponent"], 
     48parameters = [["gamma",      "",    3.0, [-inf, inf], "", "Exponent"], 
    5049              ["q_0",  "1/Ang",     0.1, [-inf, inf], "", "Correlation peak position"] 
    5150             ] 
     
    5352 
    5453def Iq(q, 
    55        scale=1.0, 
    5654       gamma=3.0, 
    5755       q_0=0.1): 
    5856    """ 
    5957    :param q:              Input q-value 
    60     :param scale:          Scale factor 
    6158    :param gamma:          Exponent 
    6259    :param q_0:            Correlation peak position 
    6360    :return:               Calculated intensity 
    6461    """ 
    65      
     62 
    6663    with errstate(divide='ignore'): 
    6764        x = q/q_0 
    68         inten = scale * ((1 + gamma / 2) * x ** 2) / (gamma / 2 + x ** (2 + gamma))  
     65        inten = ((1 + gamma / 2) * x ** 2) / (gamma / 2 + x ** (2 + gamma)) 
    6966    return inten 
    7067Iq.vectorized = True  # Iq accepts an array of q values 
    7168 
     69def random(): 
     70    import numpy as np 
     71    pars = dict( 
     72        scale=10**np.random.uniform(1, 3), 
     73        gamma=np.random.uniform(0, 6), 
     74        q_0=10**np.random.uniform(-3, -1), 
     75    ) 
     76    return pars 
     77 
    7278demo = dict(scale=1, background=0, 
    7379            gamma=1, q_0=0.1) 
  • sasmodels/models/star_polymer.py

    r40a87fa r48462b0  
    5959source = ["star_polymer.c"] 
    6060 
    61 demo = dict(scale=1, background=0, 
    62             rg_squared=100.0, 
    63             arms=3.0) 
     61def random(): 
     62    import numpy as np 
     63    pars = dict( 
     64        #background=0, 
     65        scale=10**np.random.uniform(1, 4), 
     66        rg_squared=10**np.random.uniform(1, 8), 
     67        arms=np.random.uniform(1, 6), 
     68    ) 
     69    return pars 
    6470 
    6571tests = [[{'rg_squared': 2.0, 
  • sasmodels/models/surface_fractal.py

    r925ad6e r48462b0  
    7474source = ["lib/sas_3j1x_x.c", "lib/sas_gamma.c", "surface_fractal.c"] 
    7575 
    76 demo = dict(scale=1, background=1e-5, 
    77             radius=10, fractal_dim_surf=2.0, cutoff_length=500) 
     76def random(): 
     77    import numpy as np 
     78    radius = 10**np.random.uniform(1, 4) 
     79    fractal_dim_surf = np.random.uniform(1, 3-1e-6) 
     80    cutoff_length = 1e6  # Sets the low q limit; keep it big for sim 
     81    pars = dict( 
     82        #background=0, 
     83        scale=1, 
     84        radius=radius, 
     85        fractal_dim_surf=fractal_dim_surf, 
     86        cutoff_length=cutoff_length, 
     87    ) 
     88    return pars 
    7889 
    7990tests = [ 
  • sasmodels/models/teubner_strey.py

    r8393c74 r48462b0  
    102102Iq.vectorized = True  # Iq accepts an array of q values 
    103103 
     104def random(): 
     105    import numpy as np 
     106    d = 10**np.random.uniform(1, 4) 
     107    xi = 10**np.random.uniform(-0.3, 2)*d 
     108    pars = dict( 
     109        #background=0, 
     110        scale=100, 
     111        volfraction_a=10**np.random.uniform(-3, 0), 
     112        sld_a=np.random.uniform(-0.5, 12), 
     113        sld_b=np.random.uniform(-0.5, 12), 
     114        d=d, 
     115        xi=xi, 
     116    ) 
     117    return pars 
     118 
    104119demo = dict(scale=1, background=0, volfraction_a=0.5, 
    105                      sld_a=0.3, sld_b=6.3, 
    106                      d=100.0, xi=30.0) 
     120            sld_a=0.3, sld_b=6.3, 
     121            d=100.0, xi=30.0) 
    107122tests = [[{}, 0.06, 41.5918888453]] 
  • sasmodels/models/two_lorentzian.py

    r2c74c11 r48462b0  
    9393Iq.vectorized = True  # Iq accepts an array of q values 
    9494 
     95def random(): 
     96    import numpy as np 
     97    scale = 10**np.random.uniform(0, 4, 2) 
     98    length = 10**np.random.uniform(1, 4, 2) 
     99    expon = np.random.uniform(1, 6, 2) 
     100 
     101    pars = dict( 
     102        #background=0, 
     103        scale=1, # scale provided in model 
     104        lorentz_scale_1=scale[0], 
     105        lorentz_length_1=length[0], 
     106        lorentz_exp_1=expon[0], 
     107        lorentz_scale_2=scale[1], 
     108        lorentz_length_2=length[1], 
     109        lorentz_exp_2=expon[1], 
     110    ) 
     111    return pars 
     112 
    95113 
    96114demo = dict(scale=1, background=0.1, 
  • sasmodels/models/two_power_law.py

    rbb4b509 r48462b0  
    9898Iq.vectorized = True  # Iq accepts an array of q values 
    9999 
     100def random(): 
     101    import numpy as np 
     102    coefficient_1 = 1 
     103    crossover = 10**np.random.uniform(-3, -1) 
     104    power_1 = np.random.uniform(1, 6) 
     105    power_2 = np.random.uniform(1, 6) 
     106    pars = dict( 
     107        scale=1, #background=0, 
     108        coefficient_1=coefficient_1, 
     109        crossover=crossover, 
     110        power_1=power_1, 
     111        power_2=power_2, 
     112    ) 
     113    return pars 
     114 
    100115demo = dict(scale=1, background=0.0, 
    101116            coefficent_1=1.0, 
  • sasmodels/models/unified_power_Rg.py

    rc3ccaec r48462b0  
    33---------- 
    44 
    5 This model employs the empirical multiple level unified Exponential/Power-law  
    6 fit method developed by Beaucage. Four functions are included so that 1, 2, 3,  
    7 or 4 levels can be used. In addition a 0 level has been added which simply  
     5This model employs the empirical multiple level unified Exponential/Power-law 
     6fit method developed by Beaucage. Four functions are included so that 1, 2, 3, 
     7or 4 levels can be used. In addition a 0 level has been added which simply 
    88calculates 
    99 
     
    1616(Debye equation), ellipsoidal particles, etc. 
    1717 
    18 The model works best for mass fractal systems characterized by Porod exponents  
    19 between 5/3 and 3. It should not be used for surface fractal systems. Hammouda  
    20 (2010) has pointed out a deficiency in the way this model handles the  
    21 transitioning between the Guinier and Porod regimes and which can create  
     18The model works best for mass fractal systems characterized by Porod exponents 
     19between 5/3 and 3. It should not be used for surface fractal systems. Hammouda 
     20(2010) has pointed out a deficiency in the way this model handles the 
     21transitioning between the Guinier and Porod regimes and which can create 
    2222artefacts that appear as kinks in the fitted model function. 
    2323 
     
    8888# pylint: disable=bad-whitespace, line-too-long 
    8989parameters = [ 
    90     ["level",     "",     1,      [0, 6], "", "Level number"], 
     90    ["level",     "",     1,      [1, 6], "", "Level number"], 
    9191    ["rg[level]", "Ang",  15.8,   [0, inf], "", "Radius of gyration"], 
    9292    ["power[level]", "",  4,      [-inf, inf], "", "Power"], 
     
    118118Iq.vectorized = True 
    119119 
     120def random(): 
     121    import numpy as np 
     122    from scipy.special import gamma 
     123    level = np.minimum(np.random.poisson(0.5) + 1, 6) 
     124    n = level 
     125    power = np.random.uniform(1.6, 3, n) 
     126    rg = 10**np.random.uniform(1, 5, n) 
     127    G = np.random.uniform(0.1, 10, n)**2 * 10**np.random.uniform(0.3, 3, n) 
     128    B = G * power / rg**power * gamma(power/2) 
     129    scale = 10**np.random.uniform(1, 4) 
     130    pars = dict( 
     131        #background=0, 
     132        scale=scale, 
     133        level=level, 
     134    ) 
     135    pars.update(("power%d"%(k+1), v) for k, v in enumerate(power)) 
     136    pars.update(("rg%d"%(k+1), v) for k, v in enumerate(rg)) 
     137    pars.update(("B%d"%(k+1), v) for k, v in enumerate(B)) 
     138    pars.update(("G%d"%(k+1), v) for k, v in enumerate(G)) 
     139    return pars 
     140 
    120141demo = dict( 
    121142    level=2, 
  • sasmodels/models/vesicle.py

    r925ad6e r48462b0  
    120120    return whole, whole - core 
    121121 
     122def random(): 
     123    import numpy as np 
     124    total_radius = 10**np.random.uniform(1.3, 5) 
     125    radius = total_radius * np.random.uniform(0, 1) 
     126    thickness = total_radius - radius 
     127    volfraction = 10**np.random.uniform(-3, -1) 
     128    pars = dict( 
     129        #background=0, 
     130        scale=1,  # volfraction is part of the model, so scale=1 
     131        radius=radius, 
     132        thickness=thickness, 
     133        volfraction=volfraction, 
     134    ) 
     135    return pars 
    122136 
    123137# parameters for demo 
Note: See TracChangeset for help on using the changeset viewer.