support/parse_data.py
def NoisyOpt_SmallSparse():
    '''
    A small simulated data set based on a linear regression model
    with additive noise and a sparse underlying model vector. This
    comes from the Elements of Statistical Learning (ESL2) text,
    in Figure 3.6 on page 59 (with n=300), and again (with n=100)
    on page 78 in Figure 3.16.
    NOTE: since most of the methods we shall be using involve a
    centering and standardizing of the data, we elect to do this
    here, at the time of generation. That is, the sample given
    has EMPIRICAL mean of zero and EMPIRICAL variance of one.
    '''
    dataset = "NoisyOpt_SmallSparse"
    dinfo = classes.DataInfo()

    n = 100 # training set size
    d = 31 # number of inputs
    d0 = 10 # number of *active* inputs
    sigma_X = 1.0 # unit variance
    corr = 0.85 # pairwise correlation coefficient
    sigma_noise = math.sqrt(6.25) # stdev of additive noise
    sigma_weights = math.sqrt(0.4) # stdev of randomly generated weights
    dinfo.misc["sigma_noise"] = sigma_noise
    
    cov_X = np.zeros(d*d).reshape((d,d)) + corr # prepare cov mtx
    np.fill_diagonal(cov_X, sigma_X)
    dinfo.misc["cov_X"] = cov_X # cov mtx of inputs

    w_true = np.zeros(d).reshape((d,1)) # prepare the model vec
    idx_on = np.random.choice(d, size=d0, replace=False)
    w_true[idx_on,:] = np.random.normal(loc=0.0,
                                        scale=sigma_weights,
                                        size=d0).reshape((d0,1))
    dinfo.misc["w_true"] = w_true # store the true model paras.

    # Generate the actual data.
    X_tr = np.random.multivariate_normal(mean=np.zeros(d), cov=cov_X, size=n)
    noise_tr = np.random.normal(loc=0.0,
                                scale=sigma_noise,
                                size=n).reshape((n,1))
    
    y_tr = np.dot(X_tr,w_true) + noise_tr

    # Standardize the inputs to have unit (empirical) variance.
    X_tr = (X_tr-np.mean(X_tr,axis=0)) / np.sqrt(np.var(X_tr,axis=0))
    
    # Remaining parameters for the model object.
    delta = sigma_noise * 1 # the amount of displacement of initial value
    dinfo.misc["w_init"] = w_true + delta # store a fixed initial value
    dinfo.mname = "NoisyOpt" # hard-coded model name.
    dinfo.misc["nsub"] = n # no sub-sampling, use whole batch.
    
    # Inputs
    towrite = os.path.join("data", dataset, ("X_tr" + ".dat"))
    data_arr = X_tr
    dinfo.X_tr["shape"] = data_arr.shape
    dinfo.X_tr["path"] = towrite
    dinfo.X_tr["dtype"] = data_arr.dtype
    with open(towrite, mode="bw") as g_bin:
        data_arr.tofile(g_bin)

    # Outputs
    towrite = os.path.join("data", dataset, ("y_tr" + ".dat"))
    data_arr = (np.dot(X_tr,w_true)+noise_tr).reshape((X_tr.shape[0],1))
    dinfo.y_tr["shape"] = data_arr.shape
    dinfo.y_tr["path"] = towrite
    dinfo.y_tr["dtype"] = data_arr.dtype
    with open(towrite, mode="bw") as g_bin:
        data_arr.tofile(g_bin)

    dinfo.X_te = None # Have an oracle
    dinfo.y_te = None

    # Save the dinfo dictionary for future use (so we don't have to read
    # the original data every time).
    towrite = os.path.join("data", dataset, "info.dat")
    with open(towrite, mode="wb") as f:
        pickle.dump(dinfo, f)

    # Finally, return the dinfo dict.
    return dinfo

    A small simulated data set based on a linear regression model
    with additive noise and a sparse underlying model vector. This
    comes from the Elements of Statistical Learning (ESL2) text,
    in Figure 3.6 on page 59 (with n=300), and again (with n=100)
    on page 78 in Figure 3.16.
    NOTE: since most of the methods we shall be using involve a
    centering and standardizing of the data, we elect to do this
    here, at the time of generation. That is, the sample given
    has EMPIRICAL mean of zero and EMPIRICAL variance of one.
    
A small simulated data set based on a linear regression model
with additive noise and a sparse underlying model vector. This
comes from the Elements of Statistical Learning (ESL2) text,
in Figure 3.6 on page 59 (with n=300), and again (with n=100)
on page 78 in Figure 3.16.
NOTE: since most of the methods we shall be using involve a
centering and standardizing of the data, we elect to do this
here, at the time of generation. That is, the sample given
has EMPIRICAL mean of zero and EMPIRICAL variance of one.
A small simulated data set based on a linear regression model with additive noise and a sparse underlying model vector . This comes from the Elements of Statistical Learning ( ESL2 ) text in Figure 3 . 6 on page 59 ( with n = 300 ) and again ( with n = 100 ) on page 78 in Figure 3 . 16 . NOTE : since most of the methods we shall be using involve a centering and standardizing of the data we elect to do this here at the time of generation . That is the sample given has EMPIRICAL mean of zero and EMPIRICAL variance of one .
def NoisyOpt_SmallSparse():
    dataset = "NoisyOpt_SmallSparse"
    dinfo = classes.DataInfo()
    n = 100 
    d = 31 
    d0 = 10 
    sigma_X = 1.0 
    corr = 0.85 
    sigma_noise = math.sqrt(6.25) 
    sigma_weights = math.sqrt(0.4) 
    dinfo.misc["sigma_noise"] = sigma_noise
    cov_X = np.zeros(d*d).reshape((d,d)) + corr 
    np.fill_diagonal(cov_X, sigma_X)
    dinfo.misc["cov_X"] = cov_X 
    w_true = np.zeros(d).reshape((d,1)) 
    idx_on = np.random.choice(d, size=d0, replace=False)
    w_true[idx_on,:] = np.random.normal(loc=0.0,
                                        scale=sigma_weights,
                                        size=d0).reshape((d0,1))
    dinfo.misc["w_true"] = w_true 
    X_tr = np.random.multivariate_normal(mean=np.zeros(d), cov=cov_X, size=n)
    noise_tr = np.random.normal(loc=0.0,
                                scale=sigma_noise,
                                size=n).reshape((n,1))
    y_tr = np.dot(X_tr,w_true) + noise_tr
    X_tr = (X_tr-np.mean(X_tr,axis=0)) / np.sqrt(np.var(X_tr,axis=0))
    delta = sigma_noise * 1 
    dinfo.misc["w_init"] = w_true + delta 
    dinfo.mname = "NoisyOpt" 
    dinfo.misc["nsub"] = n 
    towrite = os.path.join("data", dataset, ("X_tr" + ".dat"))
    data_arr = X_tr
    dinfo.X_tr["shape"] = data_arr.shape
    dinfo.X_tr["path"] = towrite
    dinfo.X_tr["dtype"] = data_arr.dtype
    with open(towrite, mode="bw") as g_bin:
        data_arr.tofile(g_bin)
    towrite = os.path.join("data", dataset, ("y_tr" + ".dat"))
    data_arr = (np.dot(X_tr,w_true)+noise_tr).reshape((X_tr.shape[0],1))
    dinfo.y_tr["shape"] = data_arr.shape
    dinfo.y_tr["path"] = towrite
    dinfo.y_tr["dtype"] = data_arr.dtype
    with open(towrite, mode="bw") as g_bin:
        data_arr.tofile(g_bin)
    dinfo.X_te = None 
    dinfo.y_te = None
    towrite = os.path.join("data", dataset, "info.dat")
    with open(towrite, mode="wb") as f:
        pickle.dump(dinfo, f)
    return dinfo
def NoisyOpt_SmallSparse ( ) : dataset = "NoisyOpt_SmallSparse" dinfo = classes . DataInfo ( ) n = 100 d = 31 d0 = 10 sigma_X = 1.0 corr = 0.85 sigma_noise = math . sqrt ( 6.25 ) sigma_weights = math . sqrt ( 0.4 ) dinfo . misc [ "sigma_noise" ] = sigma_noise cov_X = np . zeros ( d * d ) . reshape ( ( d , d ) ) + corr np . fill_diagonal ( cov_X , sigma_X ) dinfo . misc [ "cov_X" ] = cov_X w_true = np . zeros ( d ) . reshape ( ( d , 1 ) ) idx_on = np . random . choice ( d , size = d0 , replace = False ) w_true [ idx_on , : ] = np . random . normal ( loc = 0.0 , scale = sigma_weights , size = d0 ) . reshape ( ( d0 , 1 ) ) dinfo . misc [ "w_true" ] = w_true X_tr = np . random . multivariate_normal ( mean = np . zeros ( d ) , cov = cov_X , size = n ) noise_tr = np . random . normal ( loc = 0.0 , scale = sigma_noise , size = n ) . reshape ( ( n , 1 ) ) y_tr = np . dot ( X_tr , w_true ) + noise_tr X_tr = ( X_tr - np . mean ( X_tr , axis = 0 ) ) / np . sqrt ( np . var ( X_tr , axis = 0 ) ) delta = sigma_noise * 1 dinfo . misc [ "w_init" ] = w_true + delta dinfo . mname = "NoisyOpt" dinfo . misc [ "nsub" ] = n towrite = os . path . join ( "data" , dataset , ( "X_tr" + ".dat" ) ) data_arr = X_tr dinfo . X_tr [ "shape" ] = data_arr . shape dinfo . X_tr [ "path" ] = towrite dinfo . X_tr [ "dtype" ] = data_arr . dtype with open ( towrite , mode = "bw" ) as g_bin : data_arr . tofile ( g_bin ) towrite = os . path . join ( "data" , dataset , ( "y_tr" + ".dat" ) ) data_arr = ( np . dot ( X_tr , w_true ) + noise_tr ) . reshape ( ( X_tr . shape [ 0 ] , 1 ) ) dinfo . y_tr [ "shape" ] = data_arr . shape dinfo . y_tr [ "path" ] = towrite dinfo . y_tr [ "dtype" ] = data_arr . dtype with open ( towrite , mode = "bw" ) as g_bin : data_arr . tofile ( g_bin ) dinfo . X_te = None dinfo . y_te = None towrite = os . path . join ( "data" , dataset , "info.dat" ) with open ( towrite , mode = "wb" ) as f : pickle . dump ( dinfo , f ) return dinfo
A small simulated data set based on a linear regression model
with additive noise and a sparse underlying model vector.
A small simulated data set based on a linear regression model with additive noise and a sparse underlying model vector .
'''
    A small simulated data set based on a linear regression model
    with additive noise and a sparse underlying model vector. This
    comes from the Elements of Statistical Learning (ESL2) text,
    in Figure 3.6 on page 59 (with n=300), and again (with n=100)
    on page 78 in Figure 3.16.
    NOTE: since most of the methods we shall be using involve a
    centering and standardizing of the data, we elect to do this
    here, at the time of generation. That is, the sample given
    has EMPIRICAL mean of zero and EMPIRICAL variance of one.
    ''' # training set size # number of inputs # number of *active* inputs # unit variance # pairwise correlation coefficient # stdev of additive noise # stdev of randomly generated weights # prepare cov mtx # cov mtx of inputs # prepare the model vec # store the true model paras. # Generate the actual data. # Standardize the inputs to have unit (empirical) variance. # Remaining parameters for the model object. # the amount of displacement of initial value # store a fixed initial value # hard-coded model name. # no sub-sampling, use whole batch. # Inputs # Outputs # Have an oracle # Save the dinfo dictionary for future use (so we don't have to read # the original data every time). # Finally, return the dinfo dict.