def _config(self, top_k, seed): model = rs.AsymmetricFactorModel( **self.parameter_defaults(begin_min=-0.01, begin_max=0.01, dimension=10, use_sigmoid=False, norm_type="exponential", gamma=0.8, initialize_all=False)) gradient_updater = rs.AsymmetricFactorModelGradientUpdater( **self.parameter_defaults( learning_rate=0.05, cumulative_item_updates=False, )) gradient_updater.set_model(model) simple_updater = rs.AsymmetricFactorModelUpdater() 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=20, initialize_all=False, seed=928357823, )) negative_sample_generator.add_updater(gradient_computer) return (model, [negative_sample_generator, simple_updater], [])
def config(self, elems): config = self.parameter_defaults( top_k=100, min_time=0, seed=0, out_file=None, filters=[], loggers=[], ) model = rs.AsymmetricFactorModel( **self.parameter_defaults(begin_min=-0.01, begin_max=0.01, dimension=10, use_sigmoid=False, norm_type="exponential", gamma=0.8)) gradient_updater = rs.AsymmetricFactorModelGradientUpdater( **self.parameter_defaults( learning_rate=0.05, cumulative_item_updates=False, )) gradient_updater.set_model(model) simple_updater = rs.AsymmetricFactorModelUpdater() simple_updater.set_model(model) learner = rs.ImplicitGradientLearner() learner.add_gradient_updater(gradient_updater) learner.add_simple_updater(simple_updater) learner.set_model(model) negative_sample_generator = rs.UniformNegativeSampleGenerator( **self.parameter_defaults( negative_rate=20, initialize_all=False, seed=928357823, )) learner.set_negative_sample_generator(negative_sample_generator) point_wise = rs.ObjectiveMSE() gradient_computer = rs.GradientComputerPointWise() gradient_computer.set_objective(point_wise) gradient_computer.set_model(model) learner.set_gradient_computer(gradient_computer) return {'config': config, 'model': model, 'learner': learner}
def _fit(self, recommender_data, users, items, matrix): model = rs.AsymmetricFactorModel( 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, initialize_all=False) updater = rs.AsymmetricFactorModelGradientUpdater( **self.parameter_defaults(learning_rate=0.05, regularization_rate=0.0)) updater.set_model(model) simple_updater = rs.AsymmetricFactorModelUpdater() 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(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=254938879, number_of_iterations=9, shuffle=True, )) learner.add_early_updater(simple_updater) learner.add_iterate_updater(negative_sample_generator) return (model, learner)