# compute positions eyebrow
dyn_eyebrow_pos = calculate_position(dyn_eyebrow_preds,
                                     mode="weighted average",
                                     return_mode="xy float flat")
nb_model_eyebrow.n_features = np.shape(dyn_eyebrow_pos)[
    -1]  # todo add this to init
# train manually ref vector
nb_model_eyebrow.r = np.zeros(nb_model_eyebrow.n_features)
nb_model_eyebrow._fit_reference([dyn_eyebrow_pos, data[1]],
                                config['batch_size'])
# train manually tuning vector
nb_model_eyebrow.t = np.zeros(
    (nb_model_eyebrow.n_category, nb_model_eyebrow.n_features))
nb_model_eyebrow.t_mean = np.zeros(
    (nb_model_eyebrow.n_category, nb_model_eyebrow.n_features))
nb_model_eyebrow._fit_tuning([dyn_eyebrow_pos, data[1]], config['batch_size'])
# get it resp for eyebrows
it_train_eyebrow = nb_model_eyebrow._get_it_resp(dyn_eyebrow_pos)
print("[TRAIN] finished computing eyebrow positions")
print()

# compute positions lips
dyn_lips_pos = calculate_position(dyn_lips_preds[1:],
                                  mode="weighted average",
                                  return_mode="xy float flat")
nb_model_lips.n_features = np.shape(dyn_lips_pos)[-1]  # todo add this to init
# train manually ref vector
nb_model_lips.r = np.zeros(nb_model_lips.n_features)
nb_model_lips._fit_reference([dyn_lips_pos, data[1][1:]], config['batch_size'])
# train manually tuning vector
nb_model_lips.t = np.zeros(
# add weights
pos_weights = np.ones(np.shape(dyn_pos)[-1])
pos_weights[:8] = 1 / (2 * 2 * len(best_eyebrow_IoU_ft)
                       )  # num_concept * x/y * num_ft/concept
pos_weights[8:] = 1 / (2 * 2 * len(best_lips_IoU_ft))
dyn_pos = np.multiply(dyn_pos, pos_weights)

nb_model.n_features = np.shape(dyn_pos)[-1]  # todo add this to init
# train manually ref vector
nb_model.r = np.zeros(nb_model.n_features)
nb_model._fit_reference([dyn_pos, data[1]], config['batch_size'])
# train manually tuning vector
nb_model.t = np.zeros((nb_model.n_category, nb_model.n_features))
nb_model.t_mean = np.zeros((nb_model.n_category, nb_model.n_features))
nb_model._fit_tuning([dyn_pos, data[1]], config['batch_size'])
# get it resp for eyebrows
it_train = nb_model._get_it_resp(dyn_pos)
print("[TRAIN] finished computing positions")
print()

# -------------------------------------------------------------------------------------------------------------------
# test monkey

# load data
test_data = load_data(config, train=False)
# predict
test_preds = v4_model.predict(test_data[0], verbose=1)
print("[PREDS] shape test_preds", np.shape(test_preds))

# get feature maps that mimic a semantic selection pipeline
                         return_mode="xy float flat")
print("[TRAIN] shape pos", np.shape(pos))
print(pos)
print()

nb_model.n_features = np.shape(pos)[-1]
# train manually ref vector
nb_model.r = np.zeros(nb_model.n_features)
nb_model._fit_reference([pos, labels], config['batch_size'])
print("model reference")
print(nb_model.r)
print()
# train manually tuning vector
nb_model.t = np.zeros((nb_model.n_category, nb_model.n_features))
nb_model.t_mean = np.zeros((nb_model.n_category, nb_model.n_features))
nb_model._fit_tuning([pos, labels], config['batch_size'])
nb_model.t[3:] = 0
print("model tuning")
print(nb_model.t)
print()
# get it resp for eyebrows
it_train = nb_model._get_it_resp(pos, weights='ones')
print("[TRAIN] shape it_train", np.shape(it_train))
print("it_train[:, 1]")
print(it_train[:, 1])
print("it_train[:, 2]")
print(it_train[:, 2])

# --------------------------------------------------------------------------------------------------------------------
# plot it responses for eyebrow model
nb_model.plot_it_neurons(it_train,