{"cells":[{"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":null,"outputs":[]},{"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_mean = 6.4\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]\nbounds = [0, 37, 212, 333, 532, 697, 925, 1096, 1250, 1457, 1638, 1826, 2052, 2255, 2502, 2795, 3078, 3305, 3525, 3726, 3903, 4146, 4193]\nttf_durations = ttf_diffs[:]\nttf_durations[0] = np.array(ttf_diffs[1:]).mean()\nttf_lower_bound = 0.002\n\nsize = 150000\nsegments = (train.shape[0]) // size\n\nY_tr = pd.DataFrame(index=range(segments), dtype=np.float64, columns=['time_to_failure'])\n\nttf_idx = 0\ny = 0\nstart = 0\nbounds_index = 0\nfor segment in tqdm(range(segments)):\n    seg = train.iloc[start:start+size]\n    y -= size * T_frame\n    \n    #if bounds[bounds_index] == segment:\n    #    bounds_index += 1\n    #    duration = y + 4\n\n    while y < ttf_lower_bound:\n        y += ttf_diffs[ttf_idx]\n        duration = ttf_durations[ttf_idx]\n        ttf_idx += 1\n    start += size\n    \n    diff = y - seg['time_to_failure'].values[-1]\n    if abs(diff) > 0.0005985:\n        print(ttf_idx, segment, diff, y, seg['time_to_failure'].values)\n    Y_tr.loc[segment, 'time_to_failure'] = y\n    Y_tr.loc[segment, 'quake_duration'] = duration\n\nY_tr.to_csv('time_prediction.csv', index=False)","execution_count":null,"outputs":[]}],"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}