<jupyter_start><jupyter_text>- 1. [Question] ResNet has form $In+N(In, \theta)$, when the output is close to $In$, the nn $N(In, \theta)$ quickly **converge** to $0.0$.- 2. [Discovery] Adding the- 3. [Discovery]<jupyter_code># ============
# save and load: json
# ============

def save_json(save_path, data):
    assert save_path.split('.')[-1] == 'json'
    with open(save_path,'w+') as file:
        json.dump(data,file)

def load_json(file_path):
    assert file_path.split('.')[-1] == 'json'
    with open(file_path,'r') as file:
        data = json.load(file)
    return data

# ============
# save and load: csv
# ============

def save_csv(save_path, data):
    with open(save_path, "w+") as f:
        writer = csv.writer(f)
        writer.writerows(data)

def load_csv(file_path):
    string = []
    with open(file_path, 'r') as f:
        reader = csv.reader(f)
        for i, row in enumerate(reader):
            if i%2==0:
                string.append(row)
    ret = []
    for p in string:
        ret.append(np.array([float(i) for i in p]))
    return ret

# ==============
# save and load: normal
# ==============

def save_list(save_path, data):
    file = open(save_path, 'w+')
    for value in data:
        file.write(str(value)+" ")
    file.close()

# def load_list(file_path):

# ==========
# make directory
# ==========

def mkdir(folder_name):
    folder = os.path.exists(folder_name)
    if not folder:
        os.makedirs(folder_name)
def graphing_prediction(path_x, path_p):
    prediction = load_csv(path)
    x = load_csv(path_x)[0][:-1]
    plt.figure(figsize = (18,12))
    for i in range(len(prediction)-1):
        plt.plot(x, prediction[i])
prediction = load_csv("20 20 control group lr=0.00001 [x4000]/prediction.csv")
solution = load_csv("20 20 control group lr=0.00001 [x4000]/actual solution.csv")

np_prediction = np.array(prediction)
np_solu = np.array(solution)

L1 = np.sqrt(1/20) * np.linalg.norm(np_prediction-np_solu, ord=1)
L2 = np.sqrt(1/20) * np.linalg.norm(np_prediction-np_solu, ord=2)
Li = np.absolute(np_prediction-np_solu).max()
L_data = {
    'L1': L1,
    'L2': L2,
    'Li': Li
}
save_json("20 20 control group lr=0.00001 [x4000]/L.json", L_data)

x = load_csv("20 20 control group lr=0.00001 [x4000]/x.csv")[0][:-1]
plt.figure(figsize = (18,12))
for i in range(len(prediction)-1):
    plt.plot(x, prediction[i])
prediction = load_csv("20 20 control group [Hardtanh(-1, 1)] [x1000]/prediction.csv")
solution = load_csv("20 20 control group [Hardtanh(-1, 1)] [x1000]/actual solution.csv")

np_prediction = np.array(prediction)
np_solu = np.array(solution)

L1 = np.sqrt(1/20) * np.linalg.norm(np_prediction-np_solu, ord=1)
L2 = np.sqrt(1/20) * np.linalg.norm(np_prediction-np_solu, ord=2)
Li = np.absolute(np_prediction-np_solu).max()
L_data = {
    'L1': L1,
    'L2': L2,
    'Li': Li
}

save_json("20 20 control group [Hardtanh(-1, 1)] [x1000]/L.json", L_data)

x = load_csv("20 20 control group [Hardtanh(-1, 1)] [x1000]/x.csv")[0][:-1]
plt.figure(figsize = (18,12))
for i in range(len(prediction)-1):
    plt.plot(x, prediction[i])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.19552, 'fraction_numerical': 0.04928, 'mean_word_length': 3.7363636363636363, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '662921', 'license': 'MIT', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1223, 'n_words': 265, 'path': 'ResNet + PDE --- xx [3.0] graphing.ipynb', 'repo_name': 'ZizhengYang/-Summer-ResNet-solve-PDE-research-code', 'size': '3125'}