(problem, SA, Em, d, alpha, maxorder, RT, Y_em, bootstrap_idx, X, Y)
return Si
Creates ResultDict to be returned.
Creates ResultDict to be returned.
Creates ResultDict to be returned .
def _finalize(problem, SA, Em, d, alpha, maxorder, RT, Y_em, bootstrap_idx, X, Y):
    """Creates ResultDict to be returned."""

    # Create Sensitivity Indices Result Dictionary
    keys = ('Sa', 'Sa_conf', 'Sb', 'Sb_conf', 'S', 'S_conf', 'select',
            'Sa_sum', 'Sa_sum_conf', 'Sb_sum', 'Sb_sum_conf', 'S_sum', 'S_sum_conf')
    Si = ResultDict((k, np.zeros(Em['n'])) for k in keys)
    Si['Term'] = [None] * Em['n']
    Si['ST'] = [np.nan, ] * Em['n']
    Si['ST_conf'] = [np.nan, ] * Em['n']

    # Z score
    def z(p): return (-1) * np.sqrt(2) * special.erfcinv(p * 2)

    # Multiplier for confidence interval
    mult = z(alpha + (1 - alpha) / 2)

    # Compute the total sensitivity of each parameter/coefficient
    for r in range(Em['n1']):
        if maxorder == 1:
            TS = SA['S'][r, :]
        elif maxorder == 2:
            ij = Em['n1'] + np.where(np.sum(Em['c2'] == r, axis=1) == 1)[0]
            TS = np.sum(SA['S'][np.append(r, ij), :], axis=0)
        elif maxorder == 3:
            ij = Em['n1'] + np.where(np.sum(Em['c2'] == r, axis=1) == 1)[0]
            ijk = Em['n1'] + Em['n2'] + \
                np.where(np.sum(Em['c3'] == r, axis=1) == 1)[0]
            TS = np.sum(SA['S'][np.append(r, np.append(ij, ijk)), :], axis=0)
        Si['ST'][r] = np.mean(TS)
        Si['ST_conf'][r] = mult * np.std(TS)

    # Fill Expansion Terms
    ct = 0
    for i in range(Em['n1']):
        Si['Term'][ct] = problem['names'][i]
        ct += 1

    for i in range(Em['n2']):
        Si['Term'][ct] = '/'.join([problem['names'][Em['c2'][i, 0]],
                                   problem['names'][Em['c2'][i, 1]]])
        ct += 1

    for i in range(Em['n3']):
        Si['Term'][ct] = '/'.join([problem['names'][Em['c3'][i, 0]],
                                   problem['names'][Em['c3'][i, 1]], problem['names'][Em['c3'][i, 2]]])
        ct += 1

    # Assign Bootstrap Results to Si Dict
    Si['Sa'] = np.mean(SA['Sa'], axis=1)
    Si['Sb'] = np.mean(SA['Sb'], axis=1)
    Si['S'] = np.mean(SA['S'], axis=1)
    Si['Sa_sum'] = np.mean(np.sum(SA['Sa'], axis=0))
    Si['Sb_sum'] = np.mean(np.sum(SA['Sb'], axis=0))
    Si['S_sum'] = np.mean(np.sum(SA['S'], axis=0))

    # Compute Confidence Interval
    Si['Sa_conf'] = mult * np.std(SA['Sa'], axis=1)
    Si['Sb_conf'] = mult * np.std(SA['Sb'], axis=1)
    Si['S_conf'] = mult * np.std(SA['S'], axis=1)
    Si['Sa_sum_conf'] = mult * np.std(np.sum(SA['Sa']))
    Si['Sb_sum_conf'] = mult * np.std(np.sum(SA['Sb']))
    Si['S_sum_conf'] = mult * np.std(np.sum(SA['S']))

    # F-test # of selection to print out
    Si['select'] = Em['select'].flatten()

    Si['names'] = Si['Term']

    # Additional data for plotting.
    Si['Em'] = Em
    Si['RT'] = RT
    Si['Y_em'] = Y_em
    Si['idx'] = bootstrap_idx
    Si['X'] = X
    Si['Y'] = Y

    Si.problem = problem
    Si.to_df = MethodType(to_df, Si)

    Si._plot = Si.plot
    Si.plot = MethodType(plot, Si)

    Si.emulate = MethodType(emulate, Si)

    return Si
def _finalize ( problem , SA , Em , d , alpha , maxorder , RT , Y_em , bootstrap_idx , X , Y ) : # Create Sensitivity Indices Result Dictionary keys = ( 'Sa' , 'Sa_conf' , 'Sb' , 'Sb_conf' , 'S' , 'S_conf' , 'select' , 'Sa_sum' , 'Sa_sum_conf' , 'Sb_sum' , 'Sb_sum_conf' , 'S_sum' , 'S_sum_conf' ) Si = ResultDict ( ( k , np . zeros ( Em [ 'n' ] ) ) for k in keys ) Si [ 'Term' ] = [ None ] * Em [ 'n' ] Si [ 'ST' ] = [ np . nan , ] * Em [ 'n' ] Si [ 'ST_conf' ] = [ np . nan , ] * Em [ 'n' ] # Z score def z ( p ) : return ( - 1 ) * np . sqrt ( 2 ) * special . erfcinv ( p * 2 ) # Multiplier for confidence interval mult = z ( alpha + ( 1 - alpha ) / 2 ) # Compute the total sensitivity of each parameter/coefficient for r in range ( Em [ 'n1' ] ) : if maxorder == 1 : TS = SA [ 'S' ] [ r , : ] elif maxorder == 2 : ij = Em [ 'n1' ] + np . where ( np . sum ( Em [ 'c2' ] == r , axis = 1 ) == 1 ) [ 0 ] TS = np . sum ( SA [ 'S' ] [ np . append ( r , ij ) , : ] , axis = 0 ) elif maxorder == 3 : ij = Em [ 'n1' ] + np . where ( np . sum ( Em [ 'c2' ] == r , axis = 1 ) == 1 ) [ 0 ] ijk = Em [ 'n1' ] + Em [ 'n2' ] + np . where ( np . sum ( Em [ 'c3' ] == r , axis = 1 ) == 1 ) [ 0 ] TS = np . sum ( SA [ 'S' ] [ np . append ( r , np . append ( ij , ijk ) ) , : ] , axis = 0 ) Si [ 'ST' ] [ r ] = np . mean ( TS ) Si [ 'ST_conf' ] [ r ] = mult * np . std ( TS ) # Fill Expansion Terms ct = 0 for i in range ( Em [ 'n1' ] ) : Si [ 'Term' ] [ ct ] = problem [ 'names' ] [ i ] ct += 1 for i in range ( Em [ 'n2' ] ) : Si [ 'Term' ] [ ct ] = '/' . join ( [ problem [ 'names' ] [ Em [ 'c2' ] [ i , 0 ] ] , problem [ 'names' ] [ Em [ 'c2' ] [ i , 1 ] ] ] ) ct += 1 for i in range ( Em [ 'n3' ] ) : Si [ 'Term' ] [ ct ] = '/' . join ( [ problem [ 'names' ] [ Em [ 'c3' ] [ i , 0 ] ] , problem [ 'names' ] [ Em [ 'c3' ] [ i , 1 ] ] , problem [ 'names' ] [ Em [ 'c3' ] [ i , 2 ] ] ] ) ct += 1 # Assign Bootstrap Results to Si Dict Si [ 'Sa' ] = np . mean ( SA [ 'Sa' ] , axis = 1 ) Si [ 'Sb' ] = np . mean ( SA [ 'Sb' ] , axis = 1 ) Si [ 'S' ] = np . mean ( SA [ 'S' ] , axis = 1 ) Si [ 'Sa_sum' ] = np . mean ( np . sum ( SA [ 'Sa' ] , axis = 0 ) ) Si [ 'Sb_sum' ] = np . mean ( np . sum ( SA [ 'Sb' ] , axis = 0 ) ) Si [ 'S_sum' ] = np . mean ( np . sum ( SA [ 'S' ] , axis = 0 ) ) # Compute Confidence Interval Si [ 'Sa_conf' ] = mult * np . std ( SA [ 'Sa' ] , axis = 1 ) Si [ 'Sb_conf' ] = mult * np . std ( SA [ 'Sb' ] , axis = 1 ) Si [ 'S_conf' ] = mult * np . std ( SA [ 'S' ] , axis = 1 ) Si [ 'Sa_sum_conf' ] = mult * np . std ( np . sum ( SA [ 'Sa' ] ) ) Si [ 'Sb_sum_conf' ] = mult * np . std ( np . sum ( SA [ 'Sb' ] ) ) Si [ 'S_sum_conf' ] = mult * np . std ( np . sum ( SA [ 'S' ] ) ) # F-test # of selection to print out Si [ 'select' ] = Em [ 'select' ] . flatten ( ) Si [ 'names' ] = Si [ 'Term' ] # Additional data for plotting. Si [ 'Em' ] = Em Si [ 'RT' ] = RT Si [ 'Y_em' ] = Y_em Si [ 'idx' ] = bootstrap_idx Si [ 'X' ] = X Si [ 'Y' ] = Y Si . problem = problem Si . to_df = MethodType ( to_df , Si ) Si . _plot = Si . plot Si . plot = MethodType ( plot , Si ) Si . emulate = MethodType ( emulate , Si ) return Si