{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.11.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":39763,"databundleVersionId":11756775,"isSourceIdPinned":false,"sourceType":"competition"},{"sourceId":247897800,"sourceType":"kernelVersion"},{"sourceId":247975958,"sourceType":"kernelVersion"},{"sourceId":248005622,"sourceType":"kernelVersion"},{"sourceId":248103679,"sourceType":"kernelVersion"}],"dockerImageVersionId":31040,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport pickle\nimport matplotlib.pyplot as plt","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:23:34.098859Z","iopub.execute_input":"2025-06-30T10:23:34.099080Z","iopub.status.idle":"2025-06-30T10:23:36.221454Z","shell.execute_reply.started":"2025-06-30T10:23:34.099060Z","shell.execute_reply":"2025-06-30T10:23:36.220552Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"indices_32_36 = [32,33,34,35,36]\nindices_37_42 = [37,38,39,41,42]\nindices_43_45 = [43,44,45]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:25:53.590217Z","iopub.execute_input":"2025-06-30T10:25:53.591210Z","iopub.status.idle":"2025-06-30T10:25:53.597398Z","shell.execute_reply.started":"2025-06-30T10:25:53.591171Z","shell.execute_reply":"2025-06-30T10:25:53.596389Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"val_labels = pickle.load(open('/kaggle/input/gwi-preds-37-52-ds-to-notebook/val_labels.p', 'br'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:23:36.232311Z","iopub.execute_input":"2025-06-30T10:23:36.232640Z","iopub.status.idle":"2025-06-30T10:23:37.476819Z","shell.execute_reply.started":"2025-06-30T10:23:36.232609Z","shell.execute_reply":"2025-06-30T10:23:37.476018Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"vals_preds = ([pickle.load(open(f'/kaggle/input/gwi-preds-32-36-flip-ds-to-notebook/{x}/val_preds.p', 'br')) for x in indices_32_36]+\n              [pickle.load(open(f'/kaggle/input/gwi-preds-37-42-flip-ds-to-notebook/{x}/val_preds.p', 'br')) for x in indices_37_42]+\n              [pickle.load(open(f'/kaggle/input/gwi-preds-43-45-flip-ds-to-notebook/{x}/val_preds.p', 'br')) for x in indices_43_45])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:26:11.233024Z","iopub.execute_input":"2025-06-30T10:26:11.233371Z","iopub.status.idle":"2025-06-30T10:26:17.543714Z","shell.execute_reply.started":"2025-06-30T10:26:11.233347Z","shell.execute_reply":"2025-06-30T10:26:17.542756Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"vals_preds = vals_preds[::-1]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:26:17.545348Z","iopub.execute_input":"2025-06-30T10:26:17.545667Z","iopub.status.idle":"2025-06-30T10:26:17.550129Z","shell.execute_reply.started":"2025-06-30T10:26:17.545639Z","shell.execute_reply":"2025-06-30T10:26:17.549277Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ensemble = np.median(vals_preds[:4], axis = 0)\nensemble = np.flip(ensemble, axis = 2)\nsub_dataset_scores = []\nfor i in range(10):\n    score = np.mean(np.abs(ensemble-val_labels)[i*1000:(i+1)*1000])\n    print(score)\n    sub_dataset_scores.append(score)\nprint(np.mean(sub_dataset_scores))\nweighted_score = (np.sum(sub_dataset_scores[:4])*3+\n                  np.sum(sub_dataset_scores[4:8])*5.4+\n                  np.sum(sub_dataset_scores[8:10])*6.7)/(4*3+4*5.4+2*6.7)\nprint(weighted_score)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:26:17.551110Z","iopub.execute_input":"2025-06-30T10:26:17.551373Z","iopub.status.idle":"2025-06-30T10:26:23.707715Z","shell.execute_reply.started":"2025-06-30T10:26:17.551353Z","shell.execute_reply":"2025-06-30T10:26:23.706714Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"ensemble = (vals_preds[0]*10 + vals_preds[1]*10 + vals_preds[2]*10 + vals_preds[3]*10 +\n            vals_preds[4]*10 + vals_preds[5]*10 + vals_preds[6]*10)/(10+10+10+10+10+10+10)\nensemble = np.flip(ensemble, axis = 2)\nsub_dataset_scores = []\nfor i in range(10):\n    score = np.mean(np.abs(ensemble-val_labels)[i*1000:(i+1)*1000])\n    print(score)\n    sub_dataset_scores.append(score)\nprint(np.mean(sub_dataset_scores))\nweighted_score = (np.sum(sub_dataset_scores[:4])*3+\n                  np.sum(sub_dataset_scores[4:8])*5.4+\n                  np.sum(sub_dataset_scores[8:10])*6.7)/(4*3+4*5.4+2*6.7)\nprint(weighted_score)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:31:07.148743Z","iopub.execute_input":"2025-06-30T10:31:07.149400Z","iopub.status.idle":"2025-06-30T10:31:08.800510Z","shell.execute_reply.started":"2025-06-30T10:31:07.149374Z","shell.execute_reply":"2025-06-30T10:31:08.799613Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"0.0097023295\n0.013783836\n0.024504352\n0.074791074\n0.019639257\n0.037010346\n0.030843332\n0.16126105\n0.10437015\n0.26010755\n0.07360133\n0.08837482574138236","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.056426Z","iopub.status.idle":"2025-06-30T10:24:00.056726Z","shell.execute_reply.started":"2025-06-30T10:24:00.056592Z","shell.execute_reply":"2025-06-30T10:24:00.056608Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def get_test(test_sets_path, weights):\n    test = pickle.load(open(test_sets_path[0], 'br'))\n    \n    test = test*weights[0]\n    \n    def update_test(test, path, weight):\n        test_temp = pickle.load(open(path, 'br'))\n        test_temp = test_temp*weight\n        return test+test_temp\n        \n    for i in range(1,len(test_sets_path)):\n        test = update_test(test, test_sets_path[i], weights[i])\n    \n    test = np.flip(test, axis = 2)\n    test = test/np.sum(weights)\n    return test","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:32:45.372597Z","iopub.execute_input":"2025-06-30T10:32:45.373127Z","iopub.status.idle":"2025-06-30T10:32:45.378709Z","shell.execute_reply.started":"2025-06-30T10:32:45.373101Z","shell.execute_reply":"2025-06-30T10:32:45.377825Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_sets_path = ['/kaggle/input/gwi-preds-37-42-flip-ds-to-notebook/38/val_preds.p',\n                  '/kaggle/input/gwi-preds-37-42-flip-ds-to-notebook/39/val_preds.p',\n                  '/kaggle/input/gwi-preds-37-42-flip-ds-to-notebook/41/val_preds.p',\n                  '/kaggle/input/gwi-preds-37-42-flip-ds-to-notebook/42/val_preds.p',\n                  '/kaggle/input/gwi-preds-43-45-flip-ds-to-notebook/43/val_preds.p',\n                  '/kaggle/input/gwi-preds-43-45-flip-ds-to-notebook/44/val_preds.p',\n                  '/kaggle/input/gwi-preds-43-45-flip-ds-to-notebook/45/val_preds.p']\nweights = [1,1,1,1,1,1,1]\n\ntest = get_test(test_sets_path, weights)\nensemble = test\n\nsub_dataset_scores = []\nfor i in range(10):\n    score = np.mean(np.abs(ensemble-val_labels)[i*1000:(i+1)*1000])\n    print(score)\n    sub_dataset_scores.append(score)\nprint(np.mean(sub_dataset_scores))\nweighted_score = (np.sum(sub_dataset_scores[:4])*3+\n                  np.sum(sub_dataset_scores[4:8])*5.4+\n                  np.sum(sub_dataset_scores[8:10])*6.7)/(4*3+4*5.4+2*6.7)\nprint(weighted_score)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:32:48.105649Z","iopub.execute_input":"2025-06-30T10:32:48.105995Z","iopub.status.idle":"2025-06-30T10:32:50.783572Z","shell.execute_reply.started":"2025-06-30T10:32:48.105972Z","shell.execute_reply":"2025-06-30T10:32:50.782577Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pickle.dump(ensemble, open('val_ensemble.p', 'bw'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.061384Z","iopub.status.idle":"2025-06-30T10:24:00.061643Z","shell.execute_reply.started":"2025-06-30T10:24:00.061521Z","shell.execute_reply":"2025-06-30T10:24:00.061533Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test_sets_path = ['/kaggle/input/gwi-preds-37-42-flip-ds-to-notebook/38/test_preds.p',\n                  '/kaggle/input/gwi-preds-37-42-flip-ds-to-notebook/39/test_preds.p',\n                  '/kaggle/input/gwi-preds-37-42-flip-ds-to-notebook/41/test_preds.p',\n                  '/kaggle/input/gwi-preds-37-42-flip-ds-to-notebook/42/test_preds.p',\n                  '/kaggle/input/gwi-preds-43-45-flip-ds-to-notebook/43/test_preds.p',\n                  '/kaggle/input/gwi-preds-43-45-flip-ds-to-notebook/44/test_preds.p',\n                  '/kaggle/input/gwi-preds-43-45-flip-ds-to-notebook/45/test_preds.p']\nweights = [1,1,1,1,1,1,1]\ntest = get_test(test_sets_path, weights)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:33:09.929744Z","iopub.execute_input":"2025-06-30T10:33:09.930054Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"test.shape","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.063866Z","iopub.status.idle":"2025-06-30T10:24:00.064173Z","shell.execute_reply.started":"2025-06-30T10:24:00.064000Z","shell.execute_reply":"2025-06-30T10:24:00.064015Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"plt.imshow(test[0])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.065180Z","iopub.status.idle":"2025-06-30T10:24:00.065550Z","shell.execute_reply.started":"2025-06-30T10:24:00.065359Z","shell.execute_reply":"2025-06-30T10:24:00.065374Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"sample_submission = pd.read_csv('/kaggle/input/waveform-inversion/sample_submission.csv')\nsample_submission.head()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.067067Z","iopub.status.idle":"2025-06-30T10:24:00.067448Z","shell.execute_reply.started":"2025-06-30T10:24:00.067285Z","shell.execute_reply":"2025-06-30T10:24:00.067304Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"all_preds = np.zeros((4607260,35))\nbatch_size = 128\nx_odds = np.asarray(range(1,71,2))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.068943Z","iopub.status.idle":"2025-06-30T10:24:00.069450Z","shell.execute_reply.started":"2025-06-30T10:24:00.069258Z","shell.execute_reply":"2025-06-30T10:24:00.069277Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"for i in range(65818//batch_size+1):\n    if i%10==0:\n        print(i)\n    preds = test[i*batch_size:(i+1)*batch_size]\n    preds = preds*100+3000\n    all_preds[i*70*batch_size:(i+1)*70*batch_size] = np.reshape(np.asarray(preds)[:, :, x_odds], [-1,35])","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.070442Z","iopub.status.idle":"2025-06-30T10:24:00.070781Z","shell.execute_reply.started":"2025-06-30T10:24:00.070608Z","shell.execute_reply":"2025-06-30T10:24:00.070623Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"pickle.dump(test, open('test_ensemble.p', 'bw'))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.071995Z","iopub.status.idle":"2025-06-30T10:24:00.072364Z","shell.execute_reply.started":"2025-06-30T10:24:00.072159Z","shell.execute_reply":"2025-06-30T10:24:00.072176Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\nsample_submission.iloc[:, -35:] = all_preds","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.073263Z","iopub.status.idle":"2025-06-30T10:24:00.073601Z","shell.execute_reply.started":"2025-06-30T10:24:00.073429Z","shell.execute_reply":"2025-06-30T10:24:00.073444Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"%%time\nsample_submission.to_parquet('submission.parquet', index=False)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.074919Z","iopub.status.idle":"2025-06-30T10:24:00.075274Z","shell.execute_reply.started":"2025-06-30T10:24:00.075077Z","shell.execute_reply":"2025-06-30T10:24:00.075092Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"submission = pd.read_parquet('/kaggle/working/submission.parquet')\nplt.imshow(np.asarray(submission[:70])[:, 1:].astype(float))","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-06-30T10:24:00.076793Z","iopub.status.idle":"2025-06-30T10:24:00.077124Z","shell.execute_reply.started":"2025-06-30T10:24:00.076930Z","shell.execute_reply":"2025-06-30T10:24:00.076945Z"}},"outputs":[],"execution_count":null}]}