Exemple #1
0
    def random_env(nb_keywords: int = 10,
                   nb_users: int = 10,
                   ku_ratio: int = 3,
                   nb_channels: int = 10,
                   vc_ratio: int = 3,
                   kv_ratio: int = 3,
                   evolutive: bool = False,
                   seed: int = 0):
        """ Returns a random environment.
        :param nb_keywords: total number of possible keywords
        :param nb_users: int, number of users
        :param ku_ratio: int, number of keywords per user
        :param nb_channels: int, number of channels
        :param vc_ratio: int, number of videos per channel
        :param kv_ratio: int, number of keywords per video
        :param evolutive: boolean, if True, tastes or the users evolve over time
        :param seed: int, random seed to use
        """

        # Type-checking
        if not isinstance(nb_users, int):
            raise TypeError
        if not isinstance(ku_ratio, int):
            raise TypeError
        if not isinstance(nb_channels, int):
            raise TypeError
        if not isinstance(vc_ratio, int):
            raise TypeError
        if not isinstance(kv_ratio, int):
            raise TypeError
        if not isinstance(evolutive, bool):
            raise TypeError
        if not isinstance(seed, int):
            raise TypeError

        users = []
        channels = []
        seed_0 = seed

        for user_id in range(nb_users):
            seed += 1
            users.append(User.random_user(nb_keywords, ku_ratio, user_id,
                                          seed))

        for channel_id in range(nb_channels):
            channels.append(
                Channel.random_channel(nb_keywords, vc_ratio, kv_ratio,
                                       channel_id))

        return YoutubeEnv(users, channels, evolutive, seed_0)