{"cells":[{"metadata":{},"cell_type":"markdown","source":"Step 1: Load `time_to_failure` from training dataset"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nfrom tqdm.auto import tqdm\n\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\ntrain = pd.read_csv('../input/train.csv', dtype={'time_to_failure': np.float32}, usecols=[1])\ntrain.head()","execution_count":1,"outputs":[{"output_type":"execute_result","execution_count":1,"data":{"text/plain":"   time_to_failure\n0           1.4691\n1           1.4691\n2           1.4691\n3           1.4691\n4           1.4691","text/html":"<div>\n<style scoped>\n    .dataframe tbody tr th:only-of-type {\n        vertical-align: middle;\n    }\n\n    .dataframe tbody tr th {\n        vertical-align: top;\n    }\n\n    .dataframe thead th {\n        text-align: right;\n    }\n</style>\n<table border=\"1\" class=\"dataframe\">\n  <thead>\n    <tr style=\"text-align: right;\">\n      <th></th>\n      <th>time_to_failure</th>\n    </tr>\n  </thead>\n  <tbody>\n    <tr>\n      <th>0</th>\n      <td>1.4691</td>\n    </tr>\n    <tr>\n      <th>1</th>\n      <td>1.4691</td>\n    </tr>\n    <tr>\n      <th>2</th>\n      <td>1.4691</td>\n    </tr>\n    <tr>\n      <th>3</th>\n      <td>1.4691</td>\n    </tr>\n    <tr>\n      <th>4</th>\n      <td>1.4691</td>\n    </tr>\n  </tbody>\n</table>\n</div>"},"metadata":{}}]},{"metadata":{},"cell_type":"markdown","source":"Step 2: Define bin (chunk) duration and determine sample (frame) duration from it. Define more precise intervals between earthquakes."},{"metadata":{"trusted":true,"_uuid":"c75419ee4ed2379cf915773b48ba68da0a3cdfe5"},"cell_type":"code","source":"T_chunk = 0.001064\nS_block = 1280\nS_chunk = 4096\nframes_per_chunk = S_chunk - 1/S_block\nT_frame = T_chunk/frames_per_chunk\nttf_diffs = [1.4697, 11.54102, 14.18108, 8.85708, 12.69404, 8.056066, 7.05905, 16.10807, 7.906067, 9.63804, 11.42708, 11.02503, 8.829078, 8.56705, 14.75209345, 9.4601, 11.619]\nttf_lower_bound = 0.000556\n\nepsilon = 0.00063","execution_count":13,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Step 3: Validate that we can asssume equal time between samples (`T_frame`) and times calculated with this assumption are always within 0.63 milliseconds from `time_to_faulure` values in training dataset. (Print failing samples otherwise, empty log is expected, exept for maybe earthquake moments)"},{"metadata":{"trusted":true},"cell_type":"code","source":"#size = 150000\nsize = 4096\nsegments = (train.shape[0]) // size\n\n#Y_tr = pd.DataFrame(index=range(segments), dtype=np.float64, columns=['time_to_failure'])\n\nttf_idx = 0\ny = 0\nstart = 0\nfor segment in tqdm(range(segments)):\n    seg = train.iloc[start:start+size]\n    y -= size * T_frame\n    while y < ttf_lower_bound:\n        y += ttf_diffs[ttf_idx]\n        ttf_idx += 1\n    start += size\n\n    diff = y - seg['time_to_failure'].values[-1]\n    if abs(diff) > epsilon:\n        print(ttf_idx, segment, diff, y, seg['time_to_failure'].values)\n#    Y_tr.loc[segment, 'time_to_failure'] = y\n\n#Y_tr.to_csv('time_prediction.csv', index=False)","execution_count":14,"outputs":[{"output_type":"display_data","data":{"text/plain":"HBox(children=(IntProgress(value=0, max=153599), HTML(value='')))","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"429680cf8a1b4724964447cb2e3725a1"}},"metadata":{}}]},{"metadata":{},"cell_type":"markdown","source":"Conclusion:\n- time in training dataset can be considered contiguous with 0.63 milliseconds precision.\n- time between bins is 1.064 milliseconds. 1ms and 1.1ms differences seen in source data are not randomly spread, but distributed corresponding to rounding to 0.1 precision."}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}