Commit d2d637d4 authored by Doucet, Mathieu's avatar Doucet, Mathieu
Browse files

Merge branch 'nxt_ver_0_3_2' into 'master'

Nxt ver 0 3 2

See merge request !27
parents ffe79b0e 5d8732f4
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line

from sasmodels.core import load_model_info
from sasmodels.sasview_model import make_model_from_info

model_info = load_model_info('fractal+mono_gauss_coil')
model_info.name = 'addition_example'
model_info.description = 'fractal + mono_gauss_coil'
Model = make_model_from_info(model_info)
+42 −0
Original line number Diff line number Diff line
file: 
    name: sphere_nz_unc.txt
    qmin: 0.01
    qmax: 0.30
    
output_files: addition_example

sa_parameters: 
    temperatures: 100
    temperature_rate: 0.90
    parameter_rate: 0.95
    iterations: 1000
    models_to_generate: 5

model:
    name: addition_example.py
    category: shape-independent
    scale:
        fixed: [1.00]
    background: 
        linear: [0.000, 0.10]
    A_scale:
        linear: [0.001, 1.0]
    A_radius:
        linear: [100.0, 200.0]
    A_fractal_dim:
        linear: [1.0, 4.0]
    A_cor_length:
        linear: [100.0, 500.0]
    A_sld_block:
        linear: [2.0, 4.0]
    A_sld_solvent:
        fixed: [6.4]
    B_scale:
        linear: [0.001, 0.10]
    B_i_zero:
        fixed: [1.0]
    B_rg:
        linear: [20.0, 50.0]
        
    
+14 −4
Original line number Diff line number Diff line
@@ -219,7 +219,17 @@ def define_model(schedule, modconf, temperature, rval, current):

# perform the traditional estimation of the uncertainties in the
# fitting parameters by looking at the partial derivatives using the
# approach that is used in Paul Kienzle's "bump", as is noted below.    
# Jacobian matrix.  The approach is not perfect, and can give odd
# values that do not seem consistent with what a person using it 
# might expect.  This may be removed from future releases, or it will
# only be available if a single model is being generated.
#
# This approach to the estimation is one of a few that is implemented in bumps.
# bumps is by Paul Kienzle, who works at NIST's NCNR
# https://github.com/bumps/
# see https://github.com/bumps/bumps/blob/master/bumps/lsqerror.py 
# bumps is the fitting engine that Sasview uses with sasmodels,
# but it is an independent package.
def est_uncerts(d, f, modconf, best_model):
    # this is our ugly way of getting at this matrix of derivatives
    loc = modelconfig.ModelConfig(f.name,f.category,f.params,f.sq)
@@ -326,10 +336,10 @@ def est_uncerts(d, f, modconf, best_model):
    # print("Jacobian")
    # print(J)
    
    # this is the singlular value decomposition of J
    # see https://github.com/bumps/bumps/blob/master/bumps/lsqerror.py lines 237-239
    # This is the singlular value decomposition of J.
        
    # The tolerance shown cuts down on singlular values
    # bumps as a whole may not use this directly.  have to give it a try, though
    # bumps as a whole may not use this directly.
    U, S, V = np.linalg.svd(J, 0)
    tol = 1e-8
    S[S <= tol] = tol