Compute and return base model term, that is the first term in equation
        1, page 74. The calculation of this term is explained in paragraph
        'Base Model', page 75.
503018
def _compute_base_term(self, C, rup, dists):
        
        c1 = self.CONSTS['c1']
        R = np.sqrt(dists.rrup ** 2 + self.CONSTS['c4'] ** 2)

        base_term = (C['a1'] +
                     C['a8'] * ((8.5 - rup.mag) ** 2) +
                     (C['a2'] + self.CONSTS['a3'] * (rup.mag - c1)) *
                     np.log(R))

        if rup.mag <= c1:
            return base_term + self.CONSTS['a4'] * (rup.mag - c1)
        else:
            return base_term + self.CONSTS['a5'] * (rup.mag - c1)
354935
def _get_magnitude_term(self, C, mag):
        
        lny = C['C1'] + (C['C3'] * ((8.5 - mag) ** 2.))
        if mag > 6.3:
            return lny + (-C['H'] * C['C5']) * (mag - 6.3)
        else:
            return lny + C['C2'] * (mag - 6.3)
1283466
def declare_base(erroName=True):
    
    if erroName:
        class Base(Exception):
            def __str__(self):
                if len(self.args):
                    return "%s: %s" % (self.__class__.__name__, self.args[0])
                else:
                    return "%s: %s" % (self.__class__.__name__, self.default)
    else:
        class Base(Exception):
            def __str__(self):
                if len(self.args):
                    return "%s" % self.args[0]
                else:
                    return "%s" % self.default
    return Base
1331762
def _calculate(self, field):
        '''
        
        '''
        base_offset = 0
        if self.base_field is not None:
            base_offset = self.base_field.offset
        target_offset = self._field.offset
        if (target_offset is None) or (base_offset is None):
            return 0
        return target_offset - base_offset
1266311
def _compute_distance_term(self, C, mag, rrup):
        
        term1 = C['b'] * rrup
        term2 = - np.log(rrup + C['c'] * np.exp(C['d'] * mag))

        return term1 + term2
530540
def base_fields(self):
        ''''''
        if self.extensions_start is None:
            return len(self.fields)
        return len(self.fields[:self.extensions_start])
361452
def _compute_term_3(self, C, mag, R):
        
        return (
            (C['a12'] + C['a13'] * mag + C['a14'] * np.power(mag, 2) +
             C['a15'] * np.power(mag, 3)) * np.power(R, 2)
        )
53478
def base_ctx(ctx):
    """"""

    result = None

    if isclass(ctx):
        result = getattr(ctx, '__base__', None)
        if result is None:
            mro = getmro(ctx)
            if len(mro) > 1:
                result = mro[1]
    else:
        result = ctx.__class__

    return result
1088259
def model1(inps, lims, logger=None):
    
    a_arr, c_ = inps
    ilim, jlim = lims

    i_bs = sympy.symbols('i_lb i_ub', integer=True)
    i = sympy.Idx('i', i_bs)

    j_bs = sympy.symbols('j_lb j_ub', integer=True)
    j = sympy.Idx('j', j_bs)

    a = sympy.IndexedBase('a')

    c = sympy.Symbol('c', real=True)

    x = sympy.IndexedBase('x')
    y = sympy.IndexedBase('y')

    eqs = [
        sympy.Eq(x[i], (a[i]/3-1)**i+c),
        sympy.Eq(y[j], a[j]-j),
    ]

    ex_code = ExampleCode(eqs, (a[i], c), (i, j),
                          logger=logger, save_temp=True)
    x_, y_ = ex_code(inps, bounds=(ilim, jlim))
    x_ref = (a_arr/3-1)**np.arange(ilim[0], ilim[1]) + c_
    y_ref = a_arr[jlim[0]:jlim[1]] - np.arange(jlim[0], jlim[1])
    assert np.allclose(x_, x_ref)
    assert np.allclose(y_, y_ref)
266645
def _compute_distance_term(self, C, rup, rjb):
        
        return (C['c4'] + C['c5'] * rup.mag) * np.log(
            np.sqrt(rjb ** 2. + C['c6'] ** 2.)) + C['c7'] * rjb
458668
def _compute_magnitude_term(self, C, dc1, mag):
        
        base = C['theta1'] + (self.CONSTS['theta4'] * dc1)
        dmag = self.CONSTS["C1"] + dc1
        if mag > dmag:
            f_mag = (self.CONSTS['theta5'] * (mag - dmag)) +\
                C['theta13'] * ((10. - mag) ** 2.)

        else:
            f_mag = (self.CONSTS['theta4'] * (mag - dmag)) +\
                C['theta13'] * ((10. - mag) ** 2.)

        return base + f_mag
1321266
def _generateInitialModel(self, output_model_type):
        
        logger().info("Generating initial model for BHMM using MLHMM...")
        from bhmm.estimators.maximum_likelihood import MaximumLikelihoodEstimator
        mlhmm = MaximumLikelihoodEstimator(self.observations, self.nstates, reversible=self.reversible,
                                           output=output_model_type)
        model = mlhmm.fit()
        return model
475319
def initial_guesses(self):
        
        return np.array([param.value for param in self.model.params])
385518
def _compute_term2(self, C, mag, rjb):
        
        RM = np.sqrt(rjb ** 2 + (C['c7'] ** 2) *
                     np.exp(-1.25 + 0.227 * mag) ** 2)

        return (-C['c4'] * np.log(RM) -
                (C['c5'] - C['c4']) *
                np.maximum(np.log(RM / 100), 0) - C['c6'] * RM)
1218850
def get_fqn(base_fqn, delimiter, name=None):
    
    if name and name.startswith("%s%s" % (base_fqn, delimiter)):
        return name

    return delimiter.join([_f for _f in [base_fqn, name] if _f])
818968
def _compute_nonlinear_soil_term(self, C, lnSA_AB, delta_C, delta_D):
        

        lnSA_CD = (
            # line 1 equation 4 without first term (lnSA_AB)
            C['c29'] * delta_C +
            # line 2 and 3
            (C['c30as'] * np.log(np.exp(lnSA_AB) + 0.03) + C['c43']) * delta_D
            )

        return lnSA_CD
657436
def in_base(self, base):
        
        if base == self.base:
            return copy.deepcopy(self)
        (result, _) = Radices.from_rational(self.as_rational(), base)
        return result