Exemplo n.º 1
0
# local
import utils

# convert test statistic to a p-value for a given point
pVal_func = lambda TS, dec: -np.log10(0.5 * (chi2(len(llh.params)).sf(TS)
                                             + chi2(len(llh.params)).cdf(-TS)))

label = dict(TS=r"$\mathcal{TS}$",
             nsources=r"$n_S$",
             gamma=r"$\gamma$",
             )

if __name__=="__main__":

    plt = utils.plotting(backend="pdf")

    llh, mc = utils.startup(Nsrc=10)

    print(llh)

    # iterator of all-sky scan with follow up scans of most interesting points
    for i, (scan, hotspot) in enumerate(llh.all_sky_scan(
                                nside=2**6, follow_up_factor=1,
                                pVal=pVal_func,
                                decRange=np.radians([-90., 90.]))):

        if i > 0:
            # break after first follow up
            break
Exemplo n.º 2
0
logging.getLogger("skylab.psLLH.PointSourceLLH").setLevel(logging.INFO)

# convert test statistic to a p-value for a given point
pVal_func = lambda TS, dec: -np.log10(0.5 * (chi2(len(llh.params)).sf(TS)
                                             + chi2(len(llh.params)).cdf(-TS)))

label = dict(TS=r"$\mathcal{TS}$",
             nsources=r"$n_S$",
             gamma=r"$\gamma$",
             )


if __name__=="__main__":

    plt = utils.plotting(backend="pdf")

    llh, mc = utils.startup(Nsrc=10)

    print(llh)

    # iterator of all-sky scan with follow up scans of most interesting points
    for i, (scan, hotspot) in enumerate(llh.all_sky_scan(
                                nside=2**6, follow_up_factor=1,
                                pVal=pVal_func,
                                hemispheres=dict(Full=np.radians([-90., 90.])))):

        if i > 0:
            # break after first follow up
            break
Exemplo n.º 3
0
from scipy.interpolate import interp1d
from sklearn.linear_model import LinearRegression
from sklearn.preprocessing import PolynomialFeatures
from sklearn.metrics import mean_squared_error, r2_score
from sklearn.metrics import accuracy_score

samplerate, samples = wavfile.read('canciones/hakuna_matata.wav')
samples = samples[5000000:5000100]

newsamples = samples.copy()
damage.noiseadd(newsamples, 0.7, 0.3)
matches = recognize.cheat(samples,
                          newsamples,
                          false_positives=0.04,
                          false_negatives=0.1)
matchesSD = recognize.cheat(samples,
                            samples,
                            false_positives=0.04,
                            false_negatives=0.1)
x, y = utils.tovalidxy(newsamples, matches)
xSD, ySD = utils.tovalidxy(samples, matchesSD)
x = np.array(x).reshape((-1, 1))
y = np.array(y)
xSD = np.array(xSD).reshape((-1, 1))
ySD = np.array(ySD)

xP, yP, xSD, ySD = utils.partir(x, y, xSD, ySD, 10)
polynomial_features = PolynomialFeatures(degree=10)
y_poly_pred = utils.polinomialR(xP, yP, ySD, polynomial_features)
utils.plotting(xP, yP, samples, y_poly_pred)
Exemplo n.º 4
0
def map_states(a):   
    set_a = np.array(list(set(a)))
    for ii in range(len(set_a)):
        a = np.where(a==set_a[ii],ii+1,a)
    return a

if __name__ == '__main__':
    for target in targets:             
        out_dir = os.path.join(ouput_prefix, target)
        if not os.path.exists(out_dir):
            os.makedirs(out_dir)
            
        out_edf_data = load_edf_data(input_prefix, target) 
        counter_data = 1
        Theta = None
        U = None
        for data_all, file_name, seizure_start_time_offsets, seizure_lengths in out_edf_data:
#             plot_eeg(data_all, seizure_start_time_offsets, seizure_lengths)
            counter_data, weight_matrices_features, weight_matrices,intervals_seizures, Theta, U  = \
                        W_generator(data_all, file_name, seizure_start_time_offsets, seizure_lengths, target, out_dir, out_edf_data, counter_data, flag_normalized, Theta_in=Theta, U_in=U)
            estimated_states = None
            for appr in range(num_approaches):
#                 estimated_states = state_estimation(weight_matrices_features[appr,:,:], file_name, state_estimation_mode)
#                 estimated_states = map_states(estimated_states)
                plotting(out_dir + '/' + name_weight_matrices[appr], file_name, weight_matrices[appr], intervals_seizures = intervals_seizures, estimated_states = estimated_states)
                 



Exemplo n.º 5
0
def main_():
    N = 15
    #Sector Basic Materials
    syms = BM
    sect = sector(syms)
    syms = random.sample(syms, N)
    plotting((pre_main_(syms)), sect)

    #'''
    #Sector Communication Services
    syms = CS
    sect = sector(syms)
    syms = random.sample(syms, N)
    plotting((pre_main_(syms)), sect)

    #Sector Consumer Defensive
    syms = CD
    sect = sector(syms)
    syms = random.sample(syms, N)
    plotting((pre_main_(syms)), sect)

    #Sector Energy
    syms = Eneg
    sect = sector(syms)
    syms = random.sample(syms, N)
    plotting((pre_main_(syms)), sect)

    #Sector Real Estate
    syms = RE
    sect = sector(syms)
    plotting((pre_main_(syms)), sect)

    #Sector Industrials
    syms = Ind
    sect = sector(syms)
    syms = random.sample(syms, N)
    plotting((pre_main_(syms)), sect)

    ######################
    #Sector Consumer Cyclical
    syms = CC
    sect = sector(syms)
    syms = random.sample(syms, N)
    plotting((pre_main_(syms)), sect)

    #Sector Financial Services
    syms = FS
    sect = sector(syms)
    syms = random.sample(syms, N)
    plotting((pre_main_(syms)), sect)

    #Sector Health Care
    syms = HC
    sect = sector(syms)
    syms = random.sample(syms, N)
    plotting((pre_main_(syms)), sect)

    #Sector Technology
    syms = Techn
    sect = sector(syms)
    syms = random.sample(syms, N)
    plotting((pre_main_(syms)), sect)
Exemplo n.º 6
0
            df_ts = utils.rm_early_zeros(df_ts)
            #if max_display_length > 0:
            #    df_ts = df_ts[-max_display_length:]

            results, model = utils.process_geounit(df_ts, window_length, exp_or_lin)
            print()
            utils.print_results(selection, results.iloc[0, 0:8], normalise_by, pop_csv,
                                results.iloc[0,8], results.iloc[0,9], case, lang)

            if save_not_show in [0, 1]:
                country = selection + ' '
                if case=='confirmed':
                    country += 'Fallzahl'
                else:
                    country += 'Todesfälle'
                utils.plotting(df_ts, model, save_not_show, country, results.iloc[0,8],
                               results.iloc[0,9], lang, panels)

    else: # analysis of all counties and complete BW

        for case in cases_list:
            if max_display_length > 0:
                figures[case] = figures[case].iloc[-max_display_length:,:]
            results_list = list()
            #for selection in allowed_values[:3]:
            for selection in allowed_values[:-1]:
                print(selection)
                df_ts = figures[case][selection]
                df_ts = utils.rm_early_zeros(df_ts)
                results, model = utils.process_geounit(df_ts, window_length, exp_or_lin)

                results = results.assign(selection=selection)
Exemplo n.º 7
0
if __name__ == '__main__':
    pop_csv = 'world'
    df = utils.open_csvs() # filename is used to create name of image file if saving plot

    results_list = list()
    for country in countries:
        print(country)

        df_ts = utils.data_preparation(df, country, cases)
        if max_display_length > 0:
            df_ts = df_ts[-max_display_length:]
        results, model = utils.process_geounit(df_ts, window_length, exp_or_lin)
        results = results.assign(country=country)
        results = results.set_index('country')
        results_list.append(results)

        if save_plots == 1:
            utils.plotting(df_ts, model, 1, country, results.iloc[0,8], results.iloc[0,9], lang, panels)

    utils.print_header(normalise_by, pop_csv)
    df_results = pd.concat(results_list)
    df_results = df_results.sort_values(3, ascending=False)

    for country in df_results.index:
        if window_length > 0:
            utils.print_results(country, df_results.loc[country,:].iloc[0:8], normalise_by, pop_csv,
                                window_length, df_results.loc[country,:].iloc[9], cases, lang)
        else:
            utils.print_results(country, df_results.loc[country,:].iloc[0:8], normalise_by, pop_csv,
                      df_results.loc[country,:].iloc[8], df_results.loc[country,:].iloc[9], cases, lang)