def __init__(self, M, data_store, num_latent=ScoringParams.num_latent_factors):
        """Construct a new instance.

        :M: This parameter controls the number of recommendations that will
            be served by the PMF model.
        """
        AbstractRecommender.__init__(self)
        self._M = M
        self.num_latent = num_latent
        self.user_matrix = None
        self.latent_item_rep_mat = None
        self.weight_matrix = None
        self.s3_client = data_store

        self._load_model_output_matrices(model_path=PMF_MODEL_PATH)
        self._load_package_id_to_name_map()
        self._package_tag_map = self.s3_client.read_json_file(PACKAGE_TAG_MAP)
        self.item_ratings = load_rating(TRAINING_DATA_ITEMS, data_store)
        self.user_stacks = load_rating(PRECOMPUTED_STACKS, data_store)
        _logger.info("Created an instance of pmf-recommendation, loaded data from S3")
 def test_load_rating(self):
     """Test the load_rating method."""
     path = 'test_load_rating.txt'
     test_datastore = LocalDataStore('tests/test_data')
     r = load_rating(path, test_datastore)
     self.assertListEqual(r, [[5409, 2309, 54909, 2054], list()])
        # train the auto-encoder
        cvae_model.fit(data, epochs=params_training.num_epochs,
                       batch_size=params_training.batch_size,
                       callbacks=[saver, tensorboard_config])
        return self.encoder_z_mean


if __name__ == '__main__':
    p = TrainNetwork()
    logger.info("Preprocessing of data started.")
    p.get_preprocess_data.preprocess_data()
    x_train = np.load(os.path.join(TEMPORARY_DATA_PATH, 'content_matrix.npz'))
    x_train = x_train['matrix']
    input_dim = x_train.shape[1]
    logger.info("size of training file is: ".format(len(x_train), len(x_train[0])))
    user_to_item_matrix = load_rating(TEMPORARY_USER_ITEM_FILEPATH, TEMPORARY_DATASTORE)
    item_to_user_matrix = load_rating(TEMPORARY_ITEM_USER_FILEPATH, TEMPORARY_DATASTORE)
    logger.info("Shape of User and Item matrices:".format(np.shape(user_to_item_matrix),
                                                          np.shape(item_to_user_matrix)))
    pretrain.fit(x_train)
    encoder_weights = p.train(x_train)
    logger.info("Shape of encoder weights are: ".format(tf.shape(encoder_weights),
                                                        len(encoder_weights),
                                                        len(encoder_weights[0])))
    pmf_obj = PMFTraining(len(user_to_item_matrix), len(item_to_user_matrix), encoder_weights)
    logger.debug("PMF model has been initialised")
    pmf_obj(user_to_item_matrix=user_to_item_matrix,
            item_to_user_matrix=item_to_user_matrix)
    logger.debug("PMF model has been trained.")
    pmf_obj.save_model()
    p.get_preprocess_data.obj_.save_on_s3(TEMPORARY_DATA_PATH)