Ejemplo n.º 1
0
def read_qrnn(file, inChannels, target):

    data = iciData(test_file, inChannels, target, batch_size=batchSize)

    qrnn = QRNN.load(file)
    y_pre, y_prior, y0, y, y_pos_mean = S.predict(data, qrnn, add_noise=True)

    return y_pre, y_prior, y0, y, y_pos_mean
Ejemplo n.º 2
0
def read_qrnn(qrnn_file, test_file, inChannels, target):

    data = mwhsData(test_file, inChannels, target, ocean=False, test_data=True)

    qrnn = QRNN.load(qrnn_file)
    y_pre, y_prior, y0, y, y_pos_mean = S.predict(data, qrnn, \
                                                  add_noise = False)

    return y_pre, y_prior, y0, y, y_pos_mean
Ejemplo n.º 3
0
def read_qrnn(file, inChannels, target):

    data = iciData(test_file, inChannels, target, batch_size=batchSize)

    # read QRNN
    #    file = 'qrnn_ici_%s_%s_%s_single.nc'%(depth, width, target)
    #    print (file)
    qrnn = QRNN.load(file)
    y_pre, y_prior, y0, y, y_pos_mean = S.predict(data, qrnn, add_noise=True)

    return y_pre, y_prior, y0, y, y_pos_mean
Ejemplo n.º 4
0
    def test_save_qrnn(self, backend):
        """
        Test saving and loading of QRNNs.
        """
        set_backend(backend)
        qrnn = QRNN(self.x_train.shape[1], np.linspace(0.05, 0.95, 10))
        f = tempfile.NamedTemporaryFile()
        qrnn.save(f.name)
        qrnn_loaded = QRNN.load(f.name)

        x_pred = qrnn.predict(self.x_train)
        x_pred_loaded = qrnn.predict(self.x_train)

        if not type(x_pred) == np.ndarray:
            x_pred = x_pred.detach()

        assert np.allclose(x_pred, x_pred_loaded)
Ejemplo n.º 5
0
binstep = 0.5
bins = np.arange(-20, 15, binstep)
iq = np.argwhere(quantiles == 0.5)[0,0]

#%% Uncertainty plot
plt.rcParams.update({'font.size': 26})
inChannels = np.array([target, 'I5V' , 'I6V', 'I7V', 'I8V', 'I9V', 'I10V', 'I11V'])
i183, = np.argwhere(inChannels == target)[0]
data = iciData("TB_ICI_test.nc", 
               inChannels, target, 
               batch_size = batchSize)  

file = 'qrnn_ici_%s_%s_%s_single.nc'%(depth, width, target)
print (file)
qrnn = QRNN.load(file)

y_pre, y_prior, y0, y, y_pos_mean = S.predict(data, qrnn, add_noise = True)
fig, ax = plt.subplots(1, 1, figsize = [8, 8])
x = np.arange(-3, 4, 1)
ii = 0
y_all = []
randomList = random.sample(range(0, 24000), 1500)
for i in randomList:
    ii +=1
#for i in ind:
    y1 = y_pre[i,  :] - y_pre[i, 3]
    y_all.append(y1)
    ax.plot(x, y1, color = colors["grey"], alpha = 0.4)
#%%
y_all = np.stack(y_all)
Ejemplo n.º 6
0
        

        inChannels = np.concatenate([[target], channels])
 #       inChannels = np.array(channels)
        
        print(qrnn_dir, channels, inChannels)
            
        qrnn_file = os.path.join(qrnn_path, "qrnn_mwhs_%s.nc"%(target))
        
        print (qrnn_file)
        i183, = np.argwhere(inChannels == target)[0]
        
        data = mwhsData(test_file, 
                       inChannels, target, ocean = False, test_data = True)  
    
        qrnn = QRNN.load(qrnn_file)
        y_pre, y_prior, y0, y, y_pos_mean, x = predict(data, qrnn, \
                                                  add_noise = False)
        im = (np.abs(y_pre[:, 3] - y_prior[:, i183] )< 5) 
               
#        bia, std, ske, mae = S.calculate_statistics(y_prior, y0, y, y_pre[:, 3], im, i183)
        
        SI = np.abs(y_prior[:, 0] - y_prior[:, 1])
        
        im = SI < 5.0

        y_pre = y_prior[im, i183]
        y0    = y0[im]
        y     = y[im]
        y_prior = y_prior[im , :] 
        
Ejemplo n.º 7
0
ci_bins = np.arange(0, 40, 1)
#ci_bins = np.arange(-30, 30, 1)
center_ci_bins = (ci_bins[:-1] + ci_bins[1:]) / 2
bins = np.arange(-40, 0, 1)
center = (bins[:-1] + bins[1:]) / 2

for i, c183 in enumerate(channels):

    inChannels = np.array([c183, 'C41', 'C42', 'C43', 'C44'])

    test_data = awsTestData(os.path.expanduser(
        "~/Dendrite/Projects/AWS-325GHz/AWS/data/TB_AWS_m60_p60_noise_four_test.nc"
    ),
                            inChannels,
                            option=4)
    qrnn = QRNN.load('qrnn_4_128_%s.nc' % c183)
    y_pre, y_prior, y0, y, y_pos_mean = predict(test_data, qrnn)

    mean_ci, bins = bin_uncertainty(y_pre, y_prior[:, 0], y0)
    #mean_ci, bins = bin_errors(y_pre, y_prior[:, 0], y0)
    ax.plot(center, mean_ci, linewidth='2.5', color=colors[i])

    ax.xaxis.set_minor_locator(MultipleLocator(10))
    ax.yaxis.set_minor_locator(MultipleLocator(5))
    ax.grid(which='both', alpha=0.2)
    ci = y_pre[:, 5] - y_pre[:, 1]
    hist = histogram(ci, ci_bins)

    ax1.plot(center_ci_bins, hist, color=colors[i], linewidth=2.5)
#    ax[i].set(ylim = [0, 1])
Ejemplo n.º 8
0
    fig, ax = plt.subplots(1, 5, figsize=[50, 10])
    plt.subplots_adjust(wspace=0.001)
    for i, target in enumerate(targets):
        inChannels_single = np.array(['I1V', 'I2V', 'I3V', 'MWI-15', 'MWI-16'])
        file_single = 'qrnn_ici_%s_%s_%s_mwi-alone.nc' % (depth, width, target)
        data = iciData(test_file,
                       inChannels_single,
                       target,
                       batch_size=batchSize)

        i183, = np.argwhere(inChannels_single == target)[0]

        # read QRNN
        file_single = 'qrnn_ici_%s_%s_%s_mwi-alone.nc' % (depth, width, target)
        print(file_single)
        qrnn = QRNN.load(file_single)
        y_pre, y_prior, y0, y, y_pos_mean = S.predict(data,
                                                      qrnn,
                                                      add_noise=True)

        hist0, hist1, hist2, bins = PDF_uncertainty_bins(
            y_pre, y0, y_prior[:, i183], ulim)
        center = (bins[:-1] + bins[1:]) / 2
        ax[i].plot(center, hist0, 'k', linewidth=2.5)
        ax[i].plot(center, hist1, 'r', linewidth=2.5)
        ax[i].plot(center, hist2, 'b', linewidth=2.5)
        #    ax[i].plot(center, hist3, 'g', linewidth = 2.5)
        ax[i].xaxis.set_minor_locator(MultipleLocator(5))
        ax[i].grid(which='both', alpha=0.4)

        ax[i].set_ylim(0, 1)