Exemplo n.º 1
0
    def _fit(self, recommender_data, users, items, matrix):
        model = rs.FactorModel(**self.parameter_defaults(
            begin_min=-0.01,
            begin_max=0.01,
            dimension=10,
            initialize_all=False,
            seed=self.parameter_default('factor_seed', 67439852),
        ))

        updater = rs.FactorModelGradientUpdater(**self.parameter_defaults(
            learning_rate=0.05, regularization_rate=0.0))
        updater.set_model(model)

        point_wise = rs.ObjectiveMSE()
        gradient_computer = rs.GradientComputerPointWise()
        gradient_computer.set_objective(point_wise)
        gradient_computer.set_model(model)
        gradient_computer.add_gradient_updater(updater)

        negative_sample_generator = rs.UniformNegativeSampleGenerator(
            **self.parameter_defaults(
                negative_rate=0, initialize_all=False, max_item=-1))
        negative_sample_generator.set_train_matrix(matrix)
        negative_sample_generator.set_items(items)
        negative_sample_generator.add_updater(gradient_computer)

        learner = rs.OfflineIteratingOnlineLearnerWrapper(
            **self.parameter_defaults(
                seed=self.parameter_default('learner_seed', 254938879),
                number_of_iterations=9,
                shuffle=True,
            ))
        learner.add_iterate_updater(negative_sample_generator)

        return (model, learner)
Exemplo n.º 2
0
    def _fit(self, recommender_data, users, items, matrix):
        model = rs.PopularityModel()

        updater = rs.PopularityModelUpdater()
        updater.set_model(model)

        learner = rs.OfflineIteratingOnlineLearnerWrapper(
            seed=0,
            number_of_iterations=0,
            shuffle=False,
        )
        learner.add_updater(updater)

        return (model, learner)
Exemplo n.º 3
0
    def _fit(self, recommender_data, users, items, matrix):
        model = rs.SvdppModel(**self.parameter_defaults(
            begin_min=self.parameter_default("begin_min", -0.01),
            begin_max=self.parameter_default("begin_max", 0.01),
            dimension=self.parameter_default("dimension", 10),
            use_sigmoid=False,
            norm_type="constant",
            gamma=1,
            user_vector_weight=0.5,
            history_weight=0.5))

        gradient_updater = rs.SvdppModelGradientUpdater(
            **self.parameter_defaults(
                learning_rate=0.05,
                cumulative_item_updates=False,
            ))
        gradient_updater.set_model(model)
        simple_updater = rs.SvdppModelUpdater()
        simple_updater.set_model(model)

        point_wise = rs.ObjectiveMSE()
        gradient_computer = rs.GradientComputerPointWise()
        gradient_computer.set_objective(point_wise)
        gradient_computer.set_model(model)
        gradient_computer.add_gradient_updater(gradient_updater)

        negative_sample_generator = rs.UniformNegativeSampleGenerator(
            **self.parameter_defaults(
                negative_rate=9, initialize_all=False, max_item=-1))
        negative_sample_generator.set_train_matrix(matrix)
        negative_sample_generator.set_items(items)
        negative_sample_generator.add_updater(gradient_computer)

        learner = rs.OfflineIteratingOnlineLearnerWrapper(
            **self.parameter_defaults(
                seed=254938879,
                number_of_iterations=20,
                shuffle=True,
            ))
        learner.add_early_updater(simple_updater)
        learner.add_iterate_updater(negative_sample_generator)

        return (model, learner)
Exemplo n.º 4
0
    def _fit(self, recommender_data, users, items, matrix):
        model = rs.NearestNeighborModel(
            gamma=1,
            norm="off",
            direction="both",
            gamma_threshold=0,
            num_of_neighbors=self.parameter_default("num_of_neighbors", 10),
        )

        updater = rs.NearestNeighborModelUpdater(
            period_mode="off",
        )
        updater.set_model(model)

        learner = rs.OfflineIteratingOnlineLearnerWrapper(
            seed=254938879,
            number_of_iterations=0,
            shuffle=False,
        )
        learner.add_updater(updater)

        return (model, learner)
    def _config(self, top_k, seed):

        model = rs.FactorModel(**self.parameter_defaults(
            begin_min=-0.01,
            begin_max=0.01,
            dimension=10,
            initialize_all=False,
        ))

        #
        # batch
        #

        # updater
        batch_updater = rs.FactorModelGradientUpdater(
            **self.parameter_defaults(learning_rate=self.parameter_default(
                'batch_learning_rate', 0.05),
                                      regularization_rate=0.0))
        batch_updater.set_model(model)

        # objective
        point_wise = rs.ObjectiveMSE()
        batch_gradient_computer = rs.GradientComputerPointWise()
        batch_gradient_computer.set_objective(point_wise)
        batch_gradient_computer.set_model(model)
        batch_gradient_computer.add_gradient_updater(batch_updater)

        # negative sample generator
        batch_negative_sample_generator = rs.UniformNegativeSampleGenerator(
            **self.parameter_defaults(
                negative_rate=self.parameter_default('batch_negative_rate',
                                                     70),
                initialize_all=False,
                seed=67439852,
                filter_repeats=False,
            ))
        batch_negative_sample_generator.add_updater(batch_gradient_computer)

        batch_offline_learner = rs.OfflineIteratingOnlineLearnerWrapper(
            **self.parameter_defaults(
                seed=254938879,
                number_of_iterations=3,
                shuffle=True,
            ))
        batch_offline_learner.add_iterate_updater(
            batch_negative_sample_generator)

        batch_online_learner = rs.PeriodicOfflineLearnerWrapper(
            **self.parameter_defaults(
                write_model=False,
                read_model=False,
                clear_model=False,
                learn=True,
                base_out_file_name="",
                base_in_file_name="",
            ))
        batch_online_learner.set_model(model)
        batch_online_learner.add_offline_learner(batch_offline_learner)

        batch_data_generator_parameters = self.parameter_defaults(
            timeframe_length=0, )
        if (batch_data_generator_parameters['timeframe_length'] == 0):
            print("Full experiment")
            batch_data_generator = rs.CompletePastDataGenerator()
        else:
            print("Timeframe experiment")
            batch_data_generator = rs.TimeframeDataGenerator(
                **batch_data_generator_parameters)
        batch_online_learner.set_data_generator(batch_data_generator)
        batch_period_computer = rs.PeriodComputer(**self.parameter_defaults(
            period_length=86400,
            start_time=-1,
            period_mode="time",
        ))
        batch_online_learner.set_period_computer(batch_period_computer)

        #
        # online
        #

        # updater
        online_updater = rs.FactorModelGradientUpdater(
            **self.parameter_defaults(learning_rate=self.parameter_default(
                'online_learning_rate', 0.2),
                                      regularization_rate=0.0))
        online_updater.set_model(model)

        # objective
        point_wise = rs.ObjectiveMSE()
        online_gradient_computer = rs.GradientComputerPointWise()
        online_gradient_computer.set_objective(point_wise)
        online_gradient_computer.set_model(model)
        online_gradient_computer.add_gradient_updater(online_updater)

        # negative sample generator
        online_negative_sample_generator = rs.UniformNegativeSampleGenerator(
            **self.parameter_defaults(
                negative_rate=self.parameter_default('online_negative_rate',
                                                     100),
                initialize_all=False,
                seed=67439852,
                filter_repeats=False,
            ))
        online_negative_sample_generator.add_updater(online_gradient_computer)

        learner = [batch_online_learner, online_negative_sample_generator]

        return (model, learner, [])
Exemplo n.º 6
0
    def _config(self, top_k, seed):
        model = rs.FactorModel(**self.parameter_defaults(
            begin_min=-0.01,
            begin_max=0.01,
            dimension=10,
            initialize_all=False,
        ))

        updater = rs.FactorModelGradientUpdater(**self.parameter_defaults(
            learning_rate=0.05, regularization_rate=0.0))
        updater.set_model(model)

        point_wise = rs.ObjectiveMSE()
        gradient_computer = rs.GradientComputerPointWise()
        gradient_computer.set_objective(point_wise)
        gradient_computer.set_model(model)
        gradient_computer.add_gradient_updater(updater)

        negative_sample_generator = rs.UniformNegativeSampleGenerator(
            **self.parameter_defaults(
                negative_rate=0,
                initialize_all=False,
                seed=67439852,
                filter_repeats=False,
            ))
        negative_sample_generator.add_updater(gradient_computer)

        offline_learner = rs.OfflineIteratingOnlineLearnerWrapper(
            **self.parameter_defaults(
                seed=254938879,
                number_of_iterations=3,
                shuffle=True,
            ))
        offline_learner.add_iterate_updater(negative_sample_generator)

        online_learner = rs.PeriodicOfflineLearnerWrapper(
            **self.parameter_defaults(
                write_model=False,
                read_model=False,
                clear_model=False,
                learn=True,
                base_out_file_name="",
                base_in_file_name="",
            ))
        online_learner.set_model(model)
        online_learner.add_offline_learner(offline_learner)

        data_generator_parameters = self.parameter_defaults(
            timeframe_length=0, )
        if (data_generator_parameters['timeframe_length'] == 0):
            data_generator = rs.CompletePastDataGenerator()
        else:
            data_generator = rs.TimeframeDataGenerator(
                **data_generator_parameters)
        online_learner.set_data_generator(data_generator)
        period_computer = rs.PeriodComputer(**self.parameter_defaults(
            period_length=86400,
            start_time=-1,
            period_mode="time",
        ))
        online_learner.set_period_computer(period_computer)

        return (model, online_learner, [])