Example #1
0
  seed       = {seed}
  width_i    = {width_i}
  num_layers = {num_layers}
  max_epochs = {max_epochs}
=====================================================================
""".format(split_type = SPLIT_TYPE, 
           num_train  = NUM_TRAIN_EXAMPLE,
           num_test   = NUM_TEST_EXAMPLE,
           seed       = SEED,
           width_i    = WIDTH,
           num_layers = NUM_LAYERS, 
           max_epochs = MAX_EPOCHS)

    # DR10 qso dataset and spec files
    qso_psf_flux, qso_psf_flux_ivar, qso_psf_flux_mags, qso_z, spec_files, train_idx, test_idx = \
        ru.load_DR10QSO_train_test_idx(split_type = SPLIT_TYPE)
    spec_ids = [os.path.splitext(os.path.basename(sf))[0] for sf in spec_files]

    ## randomly subselect NUM_TRAIN
    np.random.seed(SEED)
    rand_idx      = np.random.permutation(len(train_idx))
    train_idx_sub = train_idx[rand_idx[0:NUM_TRAIN_EXAMPLE]]
    rand_idx      = np.random.permutation(len(test_idx))
    test_idx_sub  = test_idx[rand_idx[0:NUM_TEST_EXAMPLE]]
    test_spec_ids = np.array(spec_ids)[test_idx_sub]

    # create data matrix and fit model
    if FLUX_UNITS == "nanos":
        data = np.column_stack((qso_psf_flux, qso_z))
    else:
        data = np.column_stack((qso_psf_mags, qso_z))
Example #2
0
                                            x0=np.log(w),
                                            n=100,
                                            delta=.01)
        fig = plt.figure()
        plt.plot(ll_rand)
        plt.title(" Random direction for fit_weights_given_basis loss")
        plt.show()
        test_idxs = [0, 10, 95, 139]
        plot_fits(qtest, test_idxs, refit_w=True)


if __name__ == "__main__":

    # DR10 qso dataset and spec files
    qso_psf_flux, qso_z, spec_files, train_idx, test_idx = \
        ru.load_DR10QSO_train_test_idx(split_type = "random")

    ## randomly subselect NUM_TRAIN
    np.random.seed(SEED)
    rand_idx = np.random.permutation(len(train_idx))
    train_idx_sub = train_idx[rand_idx[0:NUM_TRAIN_EXAMPLE]]

    #rand_idx      = np.random.permutation(len(test_idx))
    #test_idx_sub  = test_idx[rand_idx[0:NUM_TEST_EXAMPLE]]

    ## only load in NUM_TRAIN spec files
    train_spec_files = np.array(spec_files)[train_idx_sub]
    #test_spec_files  = np.array(spec_files)[test_idx]
    spec_grid, spec_ivar_grid, spec_mod_grid, unique_lams, spec_zs, spec_ids, badids = \
        ru.load_specs_from_disk(train_spec_files)
Example #3
0
    lam0, lam0_delta = ru.get_lam0(lam_subsample=LAM_SUBSAMPLE)
    def get_basis_sample(idx, mle = False): 
        """ Method to return a basis sample to condition on 
        (or the MLE if specified) """
        if mle: 
            return B_mle
        else:
            return B_samps[idx]

    ##########################################################################
    ## Load in spectroscopically measured quasars + fluxes
    ##########################################################################
    # DR10 qso dataset and spec files
    qso_psf_flux, qso_psf_flux_ivar, qso_psf_mags, qso_z, \
    spec_files, train_idx, test_idx = \
        ru.load_DR10QSO_train_test_idx(split_type = SPLIT_TYPE)

    ## subselect train/test to match other experiments
    if NUM_TRAIN_EXAMPLE == "all": 
        NUM_TRAIN_EXAMPLE = len(train_idx)
    if NUM_TEST_EXAMPLE == "all":
        NUM_TEST_EXAMPLE = len(test_idx)
    np.random.seed(SEED)
    rand_idx      = np.random.permutation(len(train_idx))
    train_idx_sub = train_idx[rand_idx[0:NUM_TRAIN_EXAMPLE]]
    rand_idx      = np.random.permutation(len(test_idx))
    test_idx_sub  = test_idx[rand_idx[0:NUM_TEST_EXAMPLE]]

    ## grab the we're sampling
    n             = test_idx_sub[test_n]
    spec_id       = os.path.basename(spec_files[n])
Example #4
0
                                             qtrain['Z'][n], 
                                             lam_obs, return_loss=True, sgd_iter=1000)
        ll_rand = evaluate_random_direction(fun = lfun, x0=np.log(w), n = 100, delta=.01)
        fig = plt.figure()
        plt.plot(ll_rand)
        plt.title(" Random direction for fit_weights_given_basis loss")
        plt.show()
        test_idxs = [0, 10, 95, 139]
        plot_fits(qtest, test_idxs, refit_w = True)


if __name__=="__main__":

    # DR10 qso dataset and spec files
    qso_psf_flux, qso_z, spec_files, train_idx, test_idx = \
        ru.load_DR10QSO_train_test_idx(split_type = "random")

    ## randomly subselect NUM_TRAIN
    np.random.seed(SEED)
    rand_idx      = np.random.permutation(len(train_idx))
    train_idx_sub = train_idx[rand_idx[0:NUM_TRAIN_EXAMPLE]]

    #rand_idx      = np.random.permutation(len(test_idx))
    #test_idx_sub  = test_idx[rand_idx[0:NUM_TEST_EXAMPLE]]

    ## only load in NUM_TRAIN spec files
    train_spec_files = np.array(spec_files)[train_idx_sub]
    #test_spec_files  = np.array(spec_files)[test_idx]
    spec_grid, spec_ivar_grid, spec_mod_grid, unique_lams, spec_zs, spec_ids, badids = \
        ru.load_specs_from_disk(train_spec_files)