Kaggle competition: Abstraction and Reasoning Challenge
<SOS> metric: MeanBestErrorAtK Kaggle data source: abstraction-and-reasoning-challenge<prepare_x_and_y>
import numpy as np
import pandas as pd
import os
import json
from pathlib import Path
import matplotlib.pyplot as plt
from matplotlib import colors
import numpy as np
def get_moore_neighbours(color, cur_row, cur_col, nrows, ncols):
if(cur_row<=0)or(cur_col>ncols-1): top = -1
else: top = color[cur_row-1][cur_col]
if(cur_row>=nrows-1)or(cur_col>ncols-1): bottom = -1
else: bottom = color[cur_row+1][cur_col]
if(cur_col<=0)or(cur_row>nrows-1): left = -1
else: left = color[cur_row][cur_col-1]
if(cur_col>=ncols-1)or(cur_row>nrows-1): right = -1
else: right = color[cur_row][cur_col+1]
return top, bottom, left, right
def get_tl_tr(color, cur_row, cur_col, nrows, ncols):
if cur_row==0:
top_left = -1
top_right = -1
else:
if cur_col==0: top_left=-1
else: top_left = color[cur_row-1][cur_col-1]
if cur_col==ncols-1: top_right=-1
else: top_right = color[cur_row-1][cur_col+1]
return top_left, top_right
def get_vonN_neighbours(color, cur_row, cur_col, nrows, ncols):
if cur_row==0:
top_left = -1
top_right = -1
else:
if cur_col==0: top_left=-1
else: top_left = color[cur_row-1][cur_col-1]
if cur_col==ncols-1: top_right=-1
else: top_right = color[cur_row-1][cur_col+1]
if cur_row==nrows-1:
bottom_left = -1
bottom_right = -1
else:
if cur_col==0: bottom_left=-1
else: bottom_left = color[cur_row+1][cur_col-1]
if cur_col==ncols-1: bottom_right=-1
else: bottom_right = color[cur_row+1][cur_col+1]
return top_left, top_right, bottom_left, bottom_right 
<feature_engineering>
def model_1(input, task_id=''):
input = np.asarray(input)
 if input.shape !=(2,2):
return input.tolist()
output = np.zeros(( 6,6))
output[0,:] = np.array(input[0,:].tolist() *3)
 output[1,:] = np.array(input[1,:].tolist() *3)
 output[2,:] = np.array(input[0,:].tolist() [::-1]*3)
 output[3,:] = np.array(input[1,:].tolist() [::-1]*3)
 output[4,:] = np.array(input[0,:].tolist() *3)
 output[5,:] = np.array(input[1,:].tolist() *3)
 print('model1', task_id)
 return output.astype(int ).tolist()
def model_2(task, task_id=''):
train_data = task['train']
test_data = task['test']
for data in train_data:
input = data['input']
output = data['output']
if np.asarray(input ).shape !=np.asarray(output ).shape :
return input
color_map = dict()
for item in train_data:
input = item['input']
output = item['output']
for x,y in zip(input[0],output[0]):
color_map[x] = y
for data in test_data:
input = data['input']
output = np.array(input, dtype='int')
 for i in range(output.shape[0]):
for j in range(output.shape[1]):
output[i,j] = color_map.get(output[i,j], 0)
 print(task_id, 'model2 predict')
 return output.tolist()
def make_features(input_color, nfeat):
nrows, ncols = input_color.shape
feat = np.zeros(( nrows*ncols,nfeat))
cur_idx = 0
for i in range(nrows):
for j in range(ncols):
feat[cur_idx,0] = i
feat[cur_idx,1] = j
feat[cur_idx,2] = input_color[i][j]
feat[cur_idx,3:7] = get_moore_neighbours(input_color, i, j, nrows, ncols)
 try:
feat[cur_idx,7] = len(np.unique(input_color[i-1,:]))
feat[cur_idx,8] = len(np.unique(input_color[:,j-1]))
except IndexError:
pass
feat[cur_idx,9] = len(np.unique(input_color[i,:]))
feat[cur_idx,10] = len(np.unique(input_color[:,j]))
feat[cur_idx,11] = len(np.unique(input_color[i-local_neighb:i+local_neighb,
j-local_neighb:j+local_neighb]))
feat[cur_idx,12:16] = get_moore_neighbours(input_color, i+1, j, nrows, ncols)
 feat[cur_idx,16:20] = get_moore_neighbours(input_color, i-1, j, nrows, ncols)
 feat[cur_idx,20:24] = get_moore_neighbours(input_color, i, j+1, nrows, ncols)
 feat[cur_idx,24:28] = get_moore_neighbours(input_color, i, j-1, nrows, ncols)
 feat[cur_idx,28] = len(np.unique(feat[cur_idx,3:7]))
try:
feat[cur_idx,29] = len(np.unique(input_color[i+1,:]))
feat[cur_idx,30] = len(np.unique(input_color[:,j+1]))
except IndexError:
pass
cur_idx += 1
return feat<define_variables>
data_path = Path('/kaggle/input/abstraction-and-reasoning-challenge/')
 training_path = data_path / 'training'
evaluation_path = data_path / 'evaluation'
test_path = data_path / 'test'
def features(task):
global local_neighb, nfeat
mode = 'train'
cur_idx = 0
num_train_pairs = len(task[mode])
 feat, target = [], []
for task_num in range(num_train_pairs):
for a in range(3):
input_color = np.array(task[mode][task_num]['input'])
 target_color = task[mode][task_num]['output']
if a==1:
input_color = np.fliplr(input_color)
 target_color = np.fliplr(target_color)
 if a==2:
input_color = np.flipud(input_color)
 target_color = np.flipud(target_color)
 nrows, ncols = len(task[mode][task_num]['input']), len(task[mode][task_num]['input'][0])
 target_rows, target_cols = len(task[mode][task_num]['output']), len(task[mode][task_num]['output'][0])
 if(target_rows!=nrows)or(target_cols!=ncols):
print('Number of input rows:',nrows,'cols:',ncols)
 print('Number of target rows:',target_rows,'cols:',target_cols)
 not_valid=1
return None, None, 1
imsize = nrows*ncols
offset = imsize*task_num*3
feat.extend(make_features(input_color, nfeat))
target.extend(np.array(target_color ).reshape(-1,))
cur_idx += 1
return np.array(feat), np.array(target), 0<define_variables>
ret = []
for file in training_tasks:
task = load_task(file, 0)
 x = task['train'][0]['input']
x = np.asarray(x)
 ret.append(( file, str(x.shape)))
 df_shape = pd.DataFrame(ret, columns=['filename','shape'] )
mode = 'test'
if mode=='eval':
task_path = evaluation_path
elif mode=='train':
task_path = training_path
elif mode=='test':
task_path = test_path
all_task_ids = sorted(os.listdir(task_path))
nfeat = 31
local_neighb = 5
valid_scores = {}
model_accuracies = {'ens': []}
pred_taskids = []
for task_id in all_task_ids:
task_file = str(task_path / task_id)
 with open(task_file, 'r')as f:
task = json.load(f)
 feat, target, not_valid = features(task)
 if not_valid:
print('ignoring task', task_file)
 print()
not_valid = 0
continue
estimators = [ 
('xgb', XGBClassifier(n_estimators=1000)) , 
('lgb', LGBMClassifier(n_estimators=1000)) , 
('catboost', CatBoostClassifier(n_estimators=1000)) , 
('extra_trees', ExtraTreesClassifier(n_estimators=1000)) , 
('bagging', BaggingClassifier(n_estimators=1000)) , 
('gbc', GradientBoostingClassifier(n_estimators=1000)) , 
('random_forest', RandomForestClassifier(n_estimators=1000)) , 
('stacking', StackingClassifier(estimators=1000)) , 
('LogisticRegression',LogisticRegression())
 ]
clf = StackingClassifier(
 estimators=estimators, final_estimator=XGBClassifier(n_estimators=10, n_jobs=-1)
)
 clf.fit(feat, target)
 num_test_pairs = len(task['test'])
 cur_idx = 0
for task_num in range(num_test_pairs):
input_color = np.array(task['test'][task_num]['input'])
 nrows, ncols = len(task['test'][task_num]['input']), len(
 task['test'][task_num]['input'][0])
 feat = make_features(input_color, nfeat)
 print('Made predictions for ', task_id[:-5])
 preds = clf.predict(feat ).reshape(nrows,ncols)
 if(mode=='train')or(mode=='eval'):
ens_acc =(np.array(task['test'][task_num]['output'])==preds ).sum() /(nrows*ncols)
 model_accuracies['ens'].append(ens_acc)
 pred_taskids.append(f'{task_id[:-5]}_{task_num}')
 print('ensemble accuracy',(np.array(task['test'][task_num]['output'])==preds ).sum() /(nrows*ncols))
print()
preds = preds.astype(int ).tolist()
plot_test(preds, task_id)
 if mode=='test':
sample_sub.loc[f'{task_id[:-5]}_{task_num}',
'output'] = flattener(preds)
<save_to_csv>
df_shape['shape'].value_counts()
if(mode=='train')or(mode=='eval'):
df = pd.DataFrame(model_accuracies, index=pred_taskids)
 print(df.head(10))
print(df.describe())
 for c in df.columns:
print(f'for {c} no.of complete tasks is',(df.loc[:, c]==1 ).sum())
 df.to_csv('ens_acc.csv' )<save_to_csv>
file1 = df_shape[df_shape['shape']=='(2, 2)']
display(file1 )
sample_sub.to_csv('submission.csv' )<import_modules>
file1 = df_shape[df_shape['shape']=='(3, 3)']
display(file1 )
import numpy as np
import pandas as pd
import itertools
import random
import os
import json
from pathlib import Path
from tqdm.notebook import tqdm
import matplotlib.pyplot as plt
from matplotlib import colors<define_variables>
pred = model_2(task)
 print(pred)
 print(task['test'][0]['output'] )
data_path = Path('/kaggle/input/abstraction-and-reasoning-challenge/')
 training_path = data_path / 'training'
training_tasks = sorted(os.listdir(training_path))
evaluation_path = data_path / 'evaluation'
evaluation_tasks = sorted(os.listdir(evaluation_path))
test_path = data_path / 'test'
test_tasks = sorted(os.listdir(test_path))<categorify>
submission = pd.read_csv(data_path / 'sample_submission.csv', index_col='output_id')
 display(submission.head() )
def identity(x: [np.array]):
return x
def tail(x):
if len(x)> 1:
return x[1:]
else:
return x
def init(x):
if len(x)> 1:
return x[:1]
else:
return x
def union(x):

 if len(x)< 2:
return x
first_shape = tuple(x[0].shape)
 for pixmap in x[1:]:
if first_shape != tuple(pixmap.shape):
return []
return [np.bitwise_or.reduce(np.array(x ).astype(int)) ]
def intersect(x):

 if len(x)< 2:
return x
first_shape = tuple(x[0].shape)
 for pixmap in x[1:]:
if first_shape != tuple(pixmap.shape):
return []
return [(np.prod(np.array(x), axis=0)> 0 ).astype(int)]
def sortByColor(xs):

 xs = [x for x in xs if len(x.reshape(-1)) > 0]
return list(sorted(xs, key=lambda x: x.max()))
def sortByWeight(xs):

 xs = [x for x in xs if len(x.reshape(-1)) > 0]
return list(sorted(xs, key=lambda x:(x>0 ).sum()))
def reverse(x):

 return x[::-1]
def sortByNumberOfColors(xs):

 return list(sorted(xs, key=lambda x: len(np.unique(x))))
def xor(x):

 if len(x)< 2:
return x
first_shape = tuple(x[0].shape)
 for pixmap in x[1:]:
if first_shape != tuple(pixmap.shape):
return []
return [np.bitwise_xor.reduce(np.array(x ).astype(int)) ]<load_pretrained>
def flattener(pred):
str_pred = str([row for row in pred])
 str_pred = str_pred.replace(', ', '')
 str_pred = str_pred.replace('[[', '|')
 str_pred = str_pred.replace('][', '|')
 str_pred = str_pred.replace(']]', '|')
 return str_pred
def lift(fct):
def lifted_function(xs):
list_of_results = [fct(x)for x in xs]
return list(itertools.chain(*list_of_results))
lifted_function.__name__ = re.sub('_unlifted$', '_lifted', fct.__name__)
 return lifted_function
def lift_functions_list(unlifted_functions):
lifted_functions=[]
for fct in unlifted_functions:
def lifted_function(xs):
list_of_results = [fct(x)for x in xs]
return list(itertools.chain(*list_of_results))
lifted_function.__name__ = re.sub('_unlifted$', '_lifted', fct.__name__)
 lifted_functions.append(lifted_function)
 return lifted_functions<load_pretrained>
example_grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
display(example_grid)
 print(flattener(example_grid))
cropToContent = lift(cropToContent_unlifted)
 groupByColor = lift(groupByColor_unlifted)
 splitH = lift(splitH_unlifted)
 negative = lift(negative_unlifted)
 initial_functions=[tail, init, union, intersect, sortByColor, sortByWeight, reverse,\
cropToContent, groupByColor, splitH, negative]
to_c0=lift(to_c0_unlifted)
 to_c1=lift(to_c1_unlifted)
 to_c2=lift(to_c2_unlifted)
 to_c3=lift(to_c3_unlifted)
 to_c4=lift(to_c4_unlifted)
 to_c5=lift(to_c5_unlifted)
 to_c6=lift(to_c6_unlifted)
 to_c7=lift(to_c7_unlifted)
 to_c8=lift(to_c8_unlifted)
 to_c9=lift(to_c9_unlifted)
 single_color_functions=[to_c1,to_c2, to_c3, to_c4, to_c5, to_c6, to_c7, to_c8, to_c9]
c1_to_c0=lift(c1_to_c0_unlifted)
 c1_to_c2=lift(c1_to_c2_unlifted)
 c1_to_c3=lift(c1_to_c3_unlifted)
 c1_to_c4=lift(c1_to_c4_unlifted)
 c1_to_c5=lift(c1_to_c5_unlifted)
 c1_to_c6=lift(c1_to_c6_unlifted)
 c1_to_c7=lift(c1_to_c7_unlifted)
 c1_to_c8=lift(c1_to_c8_unlifted)
 c1_to_c9=lift(c1_to_c9_unlifted)
 c2_to_c0=lift(c2_to_c0_unlifted)
 c2_to_c1=lift(c2_to_c1_unlifted)
 c2_to_c3=lift(c2_to_c3_unlifted)
 c2_to_c4=lift(c2_to_c4_unlifted)
 c2_to_c5=lift(c2_to_c5_unlifted)
 c2_to_c6=lift(c2_to_c6_unlifted)
 c2_to_c7=lift(c2_to_c7_unlifted)
 c2_to_c8=lift(c2_to_c8_unlifted)
 c2_to_c9=lift(c2_to_c9_unlifted)
 c3_to_c0=lift(c3_to_c0_unlifted)
 c3_to_c1=lift(c3_to_c1_unlifted)
 c3_to_c2=lift(c3_to_c2_unlifted)
 c3_to_c4=lift(c3_to_c4_unlifted)
 c3_to_c5=lift(c3_to_c5_unlifted)
 c3_to_c6=lift(c3_to_c6_unlifted)
 c3_to_c7=lift(c3_to_c7_unlifted)
 c3_to_c8=lift(c3_to_c8_unlifted)
 c3_to_c9=lift(c3_to_c9_unlifted)
 c4_to_c0=lift(c4_to_c0_unlifted)
 c4_to_c1=lift(c4_to_c1_unlifted)
 c4_to_c2=lift(c4_to_c2_unlifted)
 c4_to_c3=lift(c4_to_c3_unlifted)
 c4_to_c5=lift(c4_to_c5_unlifted)
 c4_to_c6=lift(c4_to_c6_unlifted)
 c4_to_c7=lift(c4_to_c7_unlifted)
 c4_to_c8=lift(c4_to_c8_unlifted)
 c4_to_c9=lift(c4_to_c9_unlifted)
 c5_to_c0=lift(c5_to_c0_unlifted)
 c5_to_c1=lift(c5_to_c1_unlifted)
 c5_to_c2=lift(c5_to_c2_unlifted)
 c5_to_c3=lift(c5_to_c3_unlifted)
 c5_to_c4=lift(c5_to_c4_unlifted)
 c5_to_c6=lift(c5_to_c6_unlifted)
 c5_to_c7=lift(c5_to_c7_unlifted)
 c5_to_c8=lift(c5_to_c8_unlifted)
 c5_to_c9=lift(c5_to_c9_unlifted)
 c6_to_c0=lift(c6_to_c0_unlifted)
 c6_to_c1=lift(c6_to_c1_unlifted)
 c6_to_c2=lift(c6_to_c2_unlifted)
 c6_to_c3=lift(c6_to_c3_unlifted)
 c6_to_c4=lift(c6_to_c4_unlifted)
 c6_to_c5=lift(c6_to_c5_unlifted)
 c6_to_c7=lift(c6_to_c7_unlifted)
 c6_to_c8=lift(c6_to_c8_unlifted)
 c6_to_c9=lift(c6_to_c9_unlifted)
 c7_to_c0=lift(c7_to_c0_unlifted)
 c7_to_c1=lift(c7_to_c1_unlifted)
 c7_to_c2=lift(c7_to_c2_unlifted)
 c7_to_c3=lift(c7_to_c3_unlifted)
 c7_to_c4=lift(c7_to_c4_unlifted)
 c7_to_c5=lift(c7_to_c5_unlifted)
 c7_to_c6=lift(c7_to_c6_unlifted)
 c7_to_c8=lift(c7_to_c8_unlifted)
 c7_to_c9=lift(c7_to_c9_unlifted)
 c1_to_c0=lift(c1_to_c0_unlifted)
 c8_to_c0=lift(c8_to_c0_unlifted)
 c8_to_c1=lift(c8_to_c1_unlifted)
 c8_to_c2=lift(c8_to_c2_unlifted)
 c8_to_c3=lift(c8_to_c3_unlifted)
 c8_to_c4=lift(c8_to_c4_unlifted)
 c8_to_c5=lift(c8_to_c5_unlifted)
 c8_to_c6=lift(c8_to_c6_unlifted)
 c8_to_c7=lift(c8_to_c7_unlifted)
 c8_to_c9=lift(c8_to_c9_unlifted)
 c9_to_c0=lift(c9_to_c0_unlifted)
 c9_to_c1=lift(c9_to_c1_unlifted)
 c9_to_c2=lift(c9_to_c2_unlifted)
 c9_to_c3=lift(c9_to_c3_unlifted)
 c9_to_c4=lift(c9_to_c4_unlifted)
 c9_to_c5=lift(c9_to_c5_unlifted)
 c9_to_c6=lift(c9_to_c6_unlifted)
 c9_to_c7=lift(c9_to_c7_unlifted)
 c9_to_c8=lift(c9_to_c8_unlifted)
 color_switch_functions = [c1_to_c0, c1_to_c2, c1_to_c3, c1_to_c4, c1_to_c5, c1_to_c6,\
c1_to_c7, c1_to_c8, c1_to_c9, c2_to_c0, c2_to_c1, c2_to_c3,\
c2_to_c4, c2_to_c5, c2_to_c6, c2_to_c7, c2_to_c8,\
c2_to_c9, c3_to_c0, c3_to_c1, c3_to_c2, c3_to_c4, c3_to_c5,\
c3_to_c6, c3_to_c7, c3_to_c8, c3_to_c9, c4_to_c0, c4_to_c1,\
c4_to_c2, c4_to_c3, c4_to_c5, c4_to_c6, c4_to_c7,\
c4_to_c8, c4_to_c9, c5_to_c0, c5_to_c1, c5_to_c2, c5_to_c3,\
c5_to_c4, c5_to_c6, c5_to_c7, c5_to_c8, c5_to_c9, c6_to_c0,\
c6_to_c1, c6_to_c2, c6_to_c3, c6_to_c4, c6_to_c5,\
c6_to_c7, c6_to_c8, c6_to_c9, c7_to_c0, c7_to_c1, c7_to_c2,\
c7_to_c3, c7_to_c4, c7_to_c5, c7_to_c6, c7_to_c8,\
c7_to_c9, c8_to_c0, c8_to_c1, c8_to_c2, c8_to_c3, c8_to_c4,\
c8_to_c5, c8_to_c6, c8_to_c7, c8_to_c9, c9_to_c0, c9_to_c1,\
c9_to_c2, c9_to_c3, c9_to_c4, c9_to_c5, c9_to_c6,\
c9_to_c7, c9_to_c8]
unite_c1_horizontally=lift(unite_c1_horizontally_unlifted)
 unite_c2_horizontally=lift(unite_c2_horizontally_unlifted)
 unite_c3_horizontally=lift(unite_c3_horizontally_unlifted)
 unite_c4_horizontally=lift(unite_c4_horizontally_unlifted)
 unite_c5_horizontally=lift(unite_c5_horizontally_unlifted)
 unite_c6_horizontally=lift(unite_c6_horizontally_unlifted)
 unite_c7_horizontally=lift(unite_c7_horizontally_unlifted)
 unite_c8_horizontally=lift(unite_c8_horizontally_unlifted)
 unite_c9_horizontally=lift(unite_c9_horizontally_unlifted)
 unite_c1_vertically=lift(unite_c1_vertically_unlifted)
 unite_c2_vertically=lift(unite_c2_vertically_unlifted)
 unite_c3_vertically=lift(unite_c3_vertically_unlifted)
 unite_c4_vertically=lift(unite_c4_vertically_unlifted)
 unite_c5_vertically=lift(unite_c5_vertically_unlifted)
 unite_c6_vertically=lift(unite_c6_vertically_unlifted)
 unite_c7_vertically=lift(unite_c7_vertically_unlifted)
 unite_c8_vertically=lift(unite_c8_vertically_unlifted)
 unite_c9_vertically=lift(unite_c9_vertically_unlifted)
 unite_colors_functions=[unite_c1_horizontally, unite_c2_horizontally, unite_c3_horizontally,\
unite_c4_horizontally, unite_c5_horizontally, unite_c6_horizontally,\
unite_c7_horizontally, unite_c8_horizontally, unite_c9_horizontally,\
unite_c1_vertically, unite_c2_vertically, unite_c3_vertically,\
unite_c4_vertically, unite_c5_vertically, unite_c6_vertically,\
unite_c7_vertically, unite_c8_vertically, unite_c9_vertically]
add_c1_frame_to_single_squares=lift(add_c1_frame_to_single_squares_unlifted)
 add_c2_frame_to_single_squares=lift(add_c2_frame_to_single_squares_unlifted)
 add_c3_frame_to_single_squares=lift(add_c3_frame_to_single_squares_unlifted)
 add_c4_frame_to_single_squares=lift(add_c4_frame_to_single_squares_unlifted)
 add_c5_frame_to_single_squares=lift(add_c5_frame_to_single_squares_unlifted)
 add_c6_frame_to_single_squares=lift(add_c6_frame_to_single_squares_unlifted)
 add_c7_frame_to_single_squares=lift(add_c7_frame_to_single_squares_unlifted)
 add_c8_frame_to_single_squares=lift(add_c8_frame_to_single_squares_unlifted)
 add_c9_frame_to_single_squares=lift(add_c9_frame_to_single_squares_unlifted)
 add_frame_colors_functions= [add_c1_frame_to_single_squares, add_c2_frame_to_single_squares, add_c3_frame_to_single_squares, add_c4_frame_to_single_squares, add_c5_frame_to_single_squares, add_c6_frame_to_single_squares, add_c7_frame_to_single_squares, add_c8_frame_to_single_squares, add_c9_frame_to_single_squares]
hollow_c1=lift(hollow_c1_unlifted)
 hollow_c2=lift(hollow_c2_unlifted)
 hollow_c3=lift(hollow_c3_unlifted)
 hollow_c4=lift(hollow_c4_unlifted)
 hollow_c5=lift(hollow_c5_unlifted)
 hollow_c6=lift(hollow_c6_unlifted)
 hollow_c7=lift(hollow_c7_unlifted)
 hollow_c8=lift(hollow_c8_unlifted)
 hollow_c9=lift(hollow_c9_unlifted)
 hollow_all=lift(hollow_all_unlifted)
 hollow_functions=[hollow_c1,hollow_c2,hollow_c3,hollow_c4,hollow_c5,hollow_c6,hollow_c7,hollow_c8,hollow_c9, hollow_all]
fill_enclosed_area_c1=lift(fill_enclosed_area_c1_unlifted)
 fill_enclosed_area_c2=lift(fill_enclosed_area_c2_unlifted)
 fill_enclosed_area_c3=lift(fill_enclosed_area_c3_unlifted)
 fill_enclosed_area_c4=lift(fill_enclosed_area_c4_unlifted)
 fill_enclosed_area_c5=lift(fill_enclosed_area_c5_unlifted)
 fill_enclosed_area_c6=lift(fill_enclosed_area_c6_unlifted)
 fill_enclosed_area_c7=lift(fill_enclosed_area_c7_unlifted)
 fill_enclosed_area_c8=lift(fill_enclosed_area_c8_unlifted)
 fill_enclosed_area_c9=lift(fill_enclosed_area_c9_unlifted)
 fill_enclosed_functions=[fill_enclosed_area_c1, fill_enclosed_area_c2, fill_enclosed_area_c3, fill_enclosed_area_c4, fill_enclosed_area_c5, fill_enclosed_area_c6, fill_enclosed_area_c7, fill_enclosed_area_c8, fill_enclosed_area_c9]
splitV = lift(splitV_unlifted)
 rotate_counterclockwise=lift(rotate_counterclockwise_unlifted)
 rotate_clockwise=lift(rotate_clockwise_unlifted)
 triplicate=lift(triplicate_unlifted)
 duplicate=lift(duplicate_unlifted)
 get_enclosed_area=lift(get_enclosed_area_unlifted)
 extrapolate=lift(extrapolate_unlifted)
 lower_elements=lift(lower_elements_unlifted)
 duplicate_horizontally=lift(duplicate_horizontally_unlifted)
 duplicate_horizontally_symmetrically=lift(duplicate_horizontally_symmetrically_unlifted)
 duplicate_vertically=lift(duplicate_vertically_unlifted)
 duplicate_vertically_symmetrically=lift(duplicate_vertically_symmetrically_unlifted)
 flip_horizontally=lift(flip_horizontally_unlifted)
 flip_vertically=lift(flip_vertically_unlifted)
 rotate_colors=lift(rotate_colors_unlifted)
 paint_all_most_common_color=lift(paint_all_most_common_color_unlifted)
 added_functions=[splitV, rotate_counterclockwise, rotate_clockwise, triplicate,\
duplicate, get_enclosed_area, lower_elements, sortByNumberOfColors,\
xor, duplicate_horizontally, duplicate_horizontally_symmetrically,\
duplicate_vertically, duplicate_vertically_symmetrically,\
flip_vertically, flip_horizontally, rotate_colors]
all_functions=initial_functions+single_color_functions+color_switch_functions+unite_colors_functions+add_frame_colors_functions+\
hollow_functions+fill_enclosed_functions+added_functions<categorify>
for output_id in submission.index:
task_id = output_id.split('_')[0]
pair_id = int(output_id.split('_')[1])
 f = str(test_path / str(task_id + '.json'))
with open(f, 'r')as read_file:
task = json.load(read_file)
 data = task['test'][pair_id]['input']
pred_1 = model_1(data, task_id)
 pred_1 = flattener(pred_1)
 data = model_2(task, task_id)
 pred_2 = flattener(data)
 data = [[0 for i in j] for j in data]
pred_3 = flattener(data)
 pred = pred_1 + ' ' + pred_2 + ' ' + pred_3 + ' '
submission.loc[output_id, 'output'] = pred
<train_model><EOS> 
submission.to_csv('submission.csv' )