def _config(self, top_k, seed): model = rs.EigenFactorModel(**self.parameter_defaults( begin_min=-0.01, begin_max=0.01, dimension=10, seed=67439852, )) offline_learner = rs.OfflineEigenFactorModelALSLearner( **self.parameter_defaults( number_of_iterations=15, regularization_lambda=1e-3, alpha=40, implicit=1, clear_before_fit=1, )) offline_learner.set_model(model) 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, [])
def _config(self, top_k, seed): model = rs.ExternalModel(**self.parameter_defaults(mode="write", )) offline_learner = rs.OfflineExternalModelLearner( **self.parameter_defaults( out_name_base="batch", in_name_base="", mode="write", )) offline_learner.set_model(model) 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, [])
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, [])
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, [])