{"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,"sourceType":"competition"}],"dockerImageVersionId":31012,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport os\nimport seaborn as sns\n\nimport matplotlib.pyplot as plt\nfrom scipy.fft import fft, fftfreq\nimport numpy as np","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"execution":{"iopub.status.busy":"2025-04-29T03:15:28.464541Z","iopub.execute_input":"2025-04-29T03:15:28.464850Z","iopub.status.idle":"2025-04-29T03:15:32.319939Z","shell.execute_reply.started":"2025-04-29T03:15:28.464820Z","shell.execute_reply":"2025-04-29T03:15:32.318955Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"def first_eigenvector_weightage(data):\n    wlst = []\n    for i in range(len(data)):\n        x = data[i][0]\n        x = (x-3000)/1000\n        U, S, Vt = np.linalg.svd(x)\n        wlst.append(\n            np.abs(S[0])/np.sum(np.abs(S))\n        )\n    return wlst","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T03:43:59.667212Z","iopub.execute_input":"2025-04-29T03:43:59.667549Z","iopub.status.idle":"2025-04-29T03:43:59.674030Z","shell.execute_reply.started":"2025-04-29T03:43:59.667525Z","shell.execute_reply":"2025-04-29T03:43:59.672903Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"curve_faultb = np.load(\"/kaggle/input/waveform-inversion/train_samples/CurveFault_B/vel8_1_0.npy\")\ncurve_velb = np.load(\"/kaggle/input/waveform-inversion/train_samples/CurveVel_B/model/model2.npy\")\nflatfaultb = np.load(\"/kaggle/input/waveform-inversion/train_samples/FlatFault_B/vel8_1_0.npy\")\nflatvelb = np.load(\"/kaggle/input/waveform-inversion/train_samples/FlatVel_B/model/model2.npy\")\nstyleb = np.load(\"/kaggle/input/waveform-inversion/train_samples/Style_B/model/model2.npy\")\n\nprint(curve_velb.shape, curve_faultb.shape)\nprint()\nprint(flatfaultb.shape, flatvelb.shape)\nprint()\nprint(styleb.shape)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T03:43:27.101284Z","iopub.execute_input":"2025-04-29T03:43:27.101585Z","iopub.status.idle":"2025-04-29T03:43:27.140407Z","shell.execute_reply.started":"2025-04-29T03:43:27.101564Z","shell.execute_reply":"2025-04-29T03:43:27.139516Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"curve_faulta = np.load(\"/kaggle/input/waveform-inversion/train_samples/CurveFault_A/vel4_1_0.npy\")\ncurve_vela = np.load(\"/kaggle/input/waveform-inversion/train_samples/CurveVel_A/model/model2.npy\")\nflatfaulta = np.load(\"/kaggle/input/waveform-inversion/train_samples/FlatFault_A/vel4_1_0.npy\")\nflatvela = np.load(\"/kaggle/input/waveform-inversion/train_samples/FlatVel_A/model/model2.npy\")\nstylea = np.load(\"/kaggle/input/waveform-inversion/train_samples/Style_A/model/model2.npy\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T03:43:14.073995Z","iopub.execute_input":"2025-04-29T03:43:14.074353Z","iopub.status.idle":"2025-04-29T03:43:14.284239Z","shell.execute_reply.started":"2025-04-29T03:43:14.074328Z","shell.execute_reply":"2025-04-29T03:43:14.283255Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"curvevelb_weightage = first_eigenvector_weightage(curve_velb)\ncurve_faultb_weightage = first_eigenvector_weightage(curve_faultb)\n\nflatfaultb_weightage = first_eigenvector_weightage(flatfaultb)\nflatvelb_weightage = first_eigenvector_weightage(flatvelb)\nstyleb_weightage = first_eigenvector_weightage(styleb)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T03:44:06.036847Z","iopub.execute_input":"2025-04-29T03:44:06.037145Z","iopub.status.idle":"2025-04-29T03:44:08.167838Z","shell.execute_reply.started":"2025-04-29T03:44:06.037126Z","shell.execute_reply":"2025-04-29T03:44:08.167002Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"curvevela_weightage = first_eigenvector_weightage(curve_vela)\ncurve_faulta_weightage = first_eigenvector_weightage(curve_faulta)\n\nflatfaulta_weightage = first_eigenvector_weightage(flatfaulta)\nflatvela_weightage = first_eigenvector_weightage(flatvela)\nstylea_weightage = first_eigenvector_weightage(stylea)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T03:44:59.979576Z","iopub.execute_input":"2025-04-29T03:44:59.979920Z","iopub.status.idle":"2025-04-29T03:45:01.968304Z","shell.execute_reply.started":"2025-04-29T03:44:59.979899Z","shell.execute_reply":"2025-04-29T03:45:01.967325Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"#### First Eigen Value weightage","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 3, figsize=(16, 5))\n\nax[0].hist(flatfaulta_weightage)\nax[1].hist(flatvela_weightage)\nax[2].hist(stylea_weightage)\n\nax[0].set_title(\"Flat Fault - A\")\nax[1].set_title(\"Flat Vel-A\")\nax[2].set_title(\"Style-A\")\n\nplt.show()\n\n\nfig, ax = plt.subplots(1, 2, figsize=(16, 5))\nax[0].hist(curvevela_weightage)\nax[1].hist(curve_faulta_weightage)\n\nax[0].set_title(\"Curve Vel-A\")\nax[1].set_title(\"Curve Fault-A\")\n\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T03:45:28.580410Z","iopub.execute_input":"2025-04-29T03:45:28.580725Z","iopub.status.idle":"2025-04-29T03:45:29.494639Z","shell.execute_reply.started":"2025-04-29T03:45:28.580701Z","shell.execute_reply":"2025-04-29T03:45:29.493668Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 3, figsize=(16, 5))\n\nax[0].hist(flatfaultb_weightage)\nax[1].hist(flatvelb_weightage)\nax[2].hist(styleb_weightage)\n\nax[0].set_title(\"Flat Fault-B\")\nax[1].set_title(\"Flat Vel-B\")\nax[2].set_title(\"Style-B\")\n\nplt.show()\n\n\nfig, ax = plt.subplots(1, 2, figsize=(16, 5))\nax[0].hist(curvevelb_weightage)\nax[1].hist(curve_faultb_weightage)\n\nax[0].set_title(\"Curve Vel-B\")\nax[1].set_title(\"Curve Fault-B\")\n\nplt.show()\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T03:45:57.193244Z","iopub.execute_input":"2025-04-29T03:45:57.193538Z","iopub.status.idle":"2025-04-29T03:45:57.979686Z","shell.execute_reply.started":"2025-04-29T03:45:57.193520Z","shell.execute_reply":"2025-04-29T03:45:57.978927Z"}},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"##### check how many components will cover 85% of the weightage","metadata":{}},{"cell_type":"code","source":"def eigenvalue_count_by_threshold(data, th=0.85):\n    count_list = []\n    for i in range(len(data)):\n        x = data[i][0]\n        x = (x-3000)/1000\n        U, S, Vt = np.linalg.svd(x)\n        W = np.abs(S)/np.sum(np.abs(S))\n        W = np.cumsum(W)\n        \n        count_list.append( (W<=th).sum()+1 )\n        \n    return count_list","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T03:57:47.523659Z","iopub.execute_input":"2025-04-29T03:57:47.524068Z","iopub.status.idle":"2025-04-29T03:57:47.530544Z","shell.execute_reply.started":"2025-04-29T03:57:47.524044Z","shell.execute_reply":"2025-04-29T03:57:47.529366Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"curvevelb_counts = eigenvalue_count_by_threshold(curve_velb ,0.7)\ncurve_faultb_counts = eigenvalue_count_by_threshold(curve_faultb,0.7)\n\nflatfaultb_counts = eigenvalue_count_by_threshold(flatfaultb,0.7)\nflatvelb_counts = eigenvalue_count_by_threshold(flatvelb,0.7)\nstyleb_counts = eigenvalue_count_by_threshold(styleb,0.7)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T04:02:20.085286Z","iopub.execute_input":"2025-04-29T04:02:20.085609Z","iopub.status.idle":"2025-04-29T04:02:22.306052Z","shell.execute_reply.started":"2025-04-29T04:02:20.085587Z","shell.execute_reply":"2025-04-29T04:02:22.305032Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"fig, ax = plt.subplots(1, 3, figsize=(16, 5))\n\nax[0].hist(flatfaultb_counts)\nax[1].hist(flatvelb_counts)\nax[2].hist(styleb_counts)\n\nax[0].set_title(\"Flat Fault-B Counts\")\nax[1].set_title(\"Flat Vel-B Counts\")\nax[2].set_title(\"Style-B Counts\")\n\nplt.show()\n\n\nfig, ax = plt.subplots(1, 2, figsize=(16, 5))\nax[0].hist(curvevelb_counts)\nax[1].hist(curve_faultb_counts)\n\nax[0].set_title(\"Curve Vel-B Counts\")\nax[1].set_title(\"Curve Fault-B Counts\")\n\nplt.show()","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2025-04-29T04:02:24.856379Z","iopub.execute_input":"2025-04-29T04:02:24.856672Z","iopub.status.idle":"2025-04-29T04:02:25.685243Z","shell.execute_reply.started":"2025-04-29T04:02:24.856649Z","shell.execute_reply":"2025-04-29T04:02:25.684458Z"}},"outputs":[],"execution_count":null},{"cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}