def main(): if len(sys.argv) == 3: database_filepath, model_filepath = sys.argv[1:] print('Loading data...\n DATABASE: {}'.format(database_filepath)) X, Y, category_names = load_data(database_filepath) X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.2) print('Building model...') model = build_model() print('Training model...') fs = 200. # Hz high_fq = 50.0 # Hz low_fq = 5.0 # Hz low_fq_width = 1.0 # Hz n_epochs = 3 n_points = 10000 noise_level = 0.4 low_sig = np.array([ simulate_pac(n_points=n_points, fs=fs, high_fq=high_fq, low_fq=low_fq, low_fq_width=low_fq_width, noise_level=noise_level, random_state=i) for i in range(n_epochs) ]) X = MultipleArray(low_sig, None) model.fit(X_train, Y_train) print('Evaluating model...') evaluate_model(model, X_test, Y_test, category_names) print('Saving model...\n MODEL: {}'.format(model_filepath)) save_model(model, model_filepath) print('Trained model saved!') else: print('Please provide the filepath of the disaster messages database '\ 'as the first argument and the filepath of the pickle file to '\ 'save the model to as the second argument. \n\nExample: python '\ 'train_classifier.py ../data/DisasterResponse.db classifier.pkl')
from pactools import Comodulogram, REFERENCES from pactools import simulate_pac fs = 200. # Hz high_fq = 50.0 # Hz low_fq = 5.0 # Hz low_fq_width = 1.0 # Hz n_points = 10000 noise_level = 0.4 t_plot = 2.0 # sec signal = simulate_pac(n_points=n_points, fs=fs, high_fq=high_fq, low_fq=low_fq, low_fq_width=low_fq_width, noise_level=noise_level, random_state=0) low_fq_range = np.linspace(1, 10, 50) methods = [ 'ozkurt', 'canolty', 'tort', 'penny', 'vanwijk', 'duprelatour', 'colgin', 'sigl', 'bispectrum' ] n_lines = 3 n_columns = int(np.ceil(len(methods) / float(n_lines))) fig, axs = plt.subplots(n_lines, n_columns, figsize=(4 * n_columns, 3 * n_lines))
############################################################################### # Let's first create an artificial signal with PAC. fs = 200. # Hz high_fq = 50.0 # Hz low_fq = 5.0 # Hz low_fq_width = 1.0 # Hz n_epochs = 3 n_points = 10000 noise_level = 0.4 low_sig = np.array([ simulate_pac(n_points=n_points, fs=fs, high_fq=high_fq, low_fq=low_fq, low_fq_width=low_fq_width, noise_level=noise_level, random_state=i) for i in range(n_epochs) ]) ############################################################################### # Let's define the model with a scikit-learn's pipeline. # # In a pipeline, the output of each step is given as input to the next one. # Here #we start with `ExtractDriver`, which extracs the driver with a bandpass # #filter, and removes it from #the modeled signal with a highpass filter. Then # #we follow with `AddDriverDelay`, which adds a delay between the driver and # the #modeled signal. Finally, we define the DAR model with `DARSklearn`. model = Pipeline(steps=[ ('driver', ExtractDriver(fs=fs, low_fq=4., max_low_fq=7., low_fq_width=low_fq_width, random_state=0)),
#################################################################################################### n_seconds = 20 fs = 200. # Hz n_points = int(n_seconds * fs) f_beta = (14, 28) high_fq = 80.0 # Hz; carrier frequency low_fq = 24.0 # Hz; driver frequency low_fq_width = 2.0 # Hz noise_level = 0.25 # Simulate beta-gamma pac sig_pac = simulate_pac(n_points=n_points, fs=fs, high_fq=high_fq, low_fq=low_fq, low_fq_width=low_fq_width, noise_level=noise_level) # Simulate 10 Hz spiking which couples to about 60 Hz spikes = sim_oscillation(n_seconds, fs, 10, cycle='gaussian', std=0.005) noise = normalize_variance(pink_noise(n_points, slope=1.), variance=.5) sig_spurious_pac = spikes + noise # Simulate a sine wave that is the driver frequency sig_low_fq = sim_oscillation(n_seconds, fs, low_fq) # Add the sine wave to pink noise to make a control, no pac signal sig_no_pac = sig_low_fq + noise #################################################################################################### # Check comodulogram for PAC # ~~~~~~~~~~~~~~~~~~~~~~~~~~