{"cells":[{"metadata":{},"cell_type":"markdown","source":"# First look on the data","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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)\n\nimport matplotlib.pyplot as plt\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Training Data","execution_count":null},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"# read training data\ndf_train = pd.read_csv('../input/conways-reverse-game-of-life-2020/train.csv')\n# show dimensions\ndf_train.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_train.delta.value_counts().plot(kind='bar')\nplt.title('Distribution of delta')\nplt.grid()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Check transitions from start to end","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"pd.crosstab(df_train.start_0, df_train.stop_0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pd.crosstab(df_train.start_1, df_train.stop_1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"pd.crosstab(df_train.start_624, df_train.stop_624)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Select an example and display configurations","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# select an example\nsel_row = 2\nexample = df_train.iloc[sel_row,:]\nexample","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# extract start values\nstart = example[2:2+625]\nstart","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# convert to matrix\nstart = np.asarray(start)\nstart_mat = start.reshape(25,25)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# extract stop values\nstop = example[2+625:2+625+625+1]\nstop","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# convert to matrix\nstop = np.asarray(stop)\nstop_mat = stop.reshape(25,25)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# show start configuration\nplt.imshow(start_mat)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# show stop configuration\nplt.imshow(stop_mat)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Test data","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# read test data\ndf_test = pd.read_csv('../input/conways-reverse-game-of-life-2020/test.csv')\n# show dimensions\ndf_test.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df_test.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# count active cells per row\ndf_test_for_sum = df_test.copy()\ndf_test_for_sum = df_test_for_sum.drop(['id','delta'], axis=1)\nactive_count = df_test_for_sum.sum(axis=1)\nactive_count","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# show distribution of number of active cells\nplt.hist(active_count.values,50)\nplt.grid()\nplt.title('Number of active cells')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Select an example and display","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"# select an example\nsel_row = 3\nexample = df_test.iloc[sel_row,:]\nexample","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# extract stop values\nstop = example[2:2+625]\n# convert to matrix\nstop = np.asarray(stop)\nstop_mat = stop.reshape(25,25)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# show stop configuration\nplt.imshow(stop_mat)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# count active cells\nsum(stop)","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":4}