support/parse_data.py
def toyReg():
    '''
    Data preparation function, for a small toy set of data,
    to be solved using a linear regression model.
    '''
    dataset = "toyReg"
    dinfo = classes.DataInfo()
    dinfo.mname = "LinReg" # hard-coded model name.

    print("Preparation (", dataset, ")...")

    n = 15 # training set size
    m = 10 # testing set size
    d = 3 # number of inputs

    # Hand-prepared data, used below.
    w_true = np.array([3.1415, 1.414214, 2.718282]).reshape((d,1))
    X_tr = np.random.normal(loc=0.0, scale=0.5, size=n*d).reshape((n,d))
    noise_tr = np.random.normal(loc=0.0, scale=1.0, size=n).reshape((n,1))
    X_te = np.random.normal(loc=0.0, scale=0.5, size=m*d).reshape((m,d))
    noise_te = np.random.normal(loc=0.0, scale=1.0, size=m).reshape((m,1))
    
    # Inputs (training)
    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)

    # Inputs (testing)
    towrite = os.path.join("data", dataset, ("X_te" + ".dat"))
    data_arr = X_te
    dinfo.X_te["shape"] = data_arr.shape
    dinfo.X_te["path"] = towrite
    dinfo.X_te["dtype"] = data_arr.dtype    
    with open(towrite, mode="bw") as g_bin:
        data_arr.tofile(g_bin)

    # Outputs (training)
    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)

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

    # 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

    Data preparation function, for a small toy set of data,
    to be solved using a linear regression model.
    
Data preparation function, for a small toy set of data,
to be solved using a linear regression model.
Data preparation function for a small toy set of data to be solved using a linear regression model .
def toyReg():
    dataset = "toyReg"
    dinfo = classes.DataInfo()
    dinfo.mname = "LinReg" 
    print("Preparation (", dataset, ")...")
    n = 15 
    m = 10 
    d = 3 
    w_true = np.array([3.1415, 1.414214, 2.718282]).reshape((d,1))
    X_tr = np.random.normal(loc=0.0, scale=0.5, size=n*d).reshape((n,d))
    noise_tr = np.random.normal(loc=0.0, scale=1.0, size=n).reshape((n,1))
    X_te = np.random.normal(loc=0.0, scale=0.5, size=m*d).reshape((m,d))
    noise_te = np.random.normal(loc=0.0, scale=1.0, size=m).reshape((m,1))
    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, ("X_te" + ".dat"))
    data_arr = X_te
    dinfo.X_te["shape"] = data_arr.shape
    dinfo.X_te["path"] = towrite
    dinfo.X_te["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)
    towrite = os.path.join("data", dataset, ("y_te" + ".dat"))
    data_arr = (np.dot(X_te,w_true)+noise_te).reshape((X_te.shape[0],1))
    dinfo.y_te["shape"] = data_arr.shape
    dinfo.y_te["path"] = towrite
    dinfo.y_te["dtype"] = data_arr.dtype
    with open(towrite, mode="bw") as g_bin:
        data_arr.tofile(g_bin)
    towrite = os.path.join("data", dataset, "info.dat")
    with open(towrite, mode="wb") as f:
        pickle.dump(dinfo, f)
    return dinfo
def toyReg ( ) : dataset = "toyReg" dinfo = classes . DataInfo ( ) dinfo . mname = "LinReg" print ( "Preparation (" , dataset , ")..." ) n = 15 m = 10 d = 3 w_true = np . array ( [ 3.1415 , 1.414214 , 2.718282 ] ) . reshape ( ( d , 1 ) ) X_tr = np . random . normal ( loc = 0.0 , scale = 0.5 , size = n * d ) . reshape ( ( n , d ) ) noise_tr = np . random . normal ( loc = 0.0 , scale = 1.0 , size = n ) . reshape ( ( n , 1 ) ) X_te = np . random . normal ( loc = 0.0 , scale = 0.5 , size = m * d ) . reshape ( ( m , d ) ) noise_te = np . random . normal ( loc = 0.0 , scale = 1.0 , size = m ) . reshape ( ( m , 1 ) ) 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 , ( "X_te" + ".dat" ) ) data_arr = X_te dinfo . X_te [ "shape" ] = data_arr . shape dinfo . X_te [ "path" ] = towrite dinfo . X_te [ "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 ) towrite = os . path . join ( "data" , dataset , ( "y_te" + ".dat" ) ) data_arr = ( np . dot ( X_te , w_true ) + noise_te ) . reshape ( ( X_te . shape [ 0 ] , 1 ) ) dinfo . y_te [ "shape" ] = data_arr . shape dinfo . y_te [ "path" ] = towrite dinfo . y_te [ "dtype" ] = data_arr . dtype with open ( towrite , mode = "bw" ) as g_bin : data_arr . tofile ( g_bin ) towrite = os . path . join ( "data" , dataset , "info.dat" ) with open ( towrite , mode = "wb" ) as f : pickle . dump ( dinfo , f ) return dinfo
Data preparation function, for a small toy set of data,
to be solved using a linear regression model.
Data preparation function for a small toy set of data to be solved using a linear regression model .
'''
    Data preparation function, for a small toy set of data,
    to be solved using a linear regression model.
    ''' # hard-coded model name. # training set size # testing set size # number of inputs # Hand-prepared data, used below. # Inputs (training) # Inputs (testing) # Outputs (training) # Outputs (testing) # Save the dinfo dictionary for future use (so we don't have to read # the original data every time). # Finally, return the dinfo dict.