├── tools ├── README.md └── tensorflow │ ├── README.md │ ├── src │ ├── datasets │ │ ├── __init__.py │ │ ├── json_list.py │ │ └── json_files.py │ ├── models │ │ ├── __init__.py │ │ ├── user_model.py │ │ ├── sequence_user_model.py │ │ ├── svdpp_user_model.py │ │ ├── context_metrics.py │ │ ├── composite_prediction_model.py │ │ ├── regression_prediction_model.py │ │ ├── ctr_prediction_model.py │ │ ├── layers.py │ │ ├── bpr_prediction_model.py │ │ ├── metrics_test.py │ │ └── sampled_bpr_model.py │ ├── __init__.py │ ├── dataset.py │ └── builder.py │ └── requirements.txt ├── _config.yml ├── server ├── conf │ ├── application.prod.conf │ ├── starter.conf │ └── routes ├── activator-launch-1.3.7.jar ├── public │ └── main.css ├── project │ ├── plugins.sbt │ └── build.properties ├── app │ ├── views │ │ ├── main.scala.html │ │ └── Application │ │ │ └── index.scala.html │ └── org │ │ └── grouplens │ │ └── samantha │ │ ├── modeler │ │ ├── solver │ │ │ ├── RegularizedDualAveraging.java │ │ │ ├── ObjectiveRunnable.java │ │ │ ├── ObjectiveFunction.java │ │ │ ├── OnlineOptimizationMethod.java │ │ │ ├── Regularizer.java │ │ │ ├── OptimizationMethod.java │ │ │ ├── IdentityFunction.java │ │ │ ├── L2NormLoss.java │ │ │ ├── EvaluateRunnable.java │ │ │ ├── HingeLoss.java │ │ │ └── SGDRunnable.java │ │ ├── model │ │ │ ├── UncollectableModel.java │ │ │ ├── SpaceModel.java │ │ │ ├── LatentLearningModel.java │ │ │ ├── SpaceMode.java │ │ │ ├── SpaceUtilities.java │ │ │ ├── IndexSpace.java │ │ │ └── SpaceProducer.java │ │ ├── tree │ │ │ ├── ClassificationCriterion.java │ │ │ ├── RegressionCriterion.java │ │ │ ├── TreeKey.java │ │ │ ├── TreeLearningMethod.java │ │ │ ├── AbstractTreeLearningMethod.java │ │ │ ├── SplittingCriterion.java │ │ │ └── DecisionTree.java │ │ ├── ranking │ │ │ ├── RankingLoss.java │ │ │ ├── LambdaLoss.java │ │ │ └── RankingUtilities.java │ │ ├── reinforce │ │ │ └── LinearUCBKey.java │ │ ├── featurizer │ │ │ ├── SelfPlusOneRatioFunction.java │ │ │ ├── Feature.java │ │ │ └── Featurizer.java │ │ ├── svdfeature │ │ │ ├── SVDFeatureKey.java │ │ │ └── SVDFeatureInstanceList.java │ │ ├── metric │ │ │ ├── Metric.java │ │ │ └── MetricResult.java │ │ ├── boosting │ │ │ ├── BoostedPredictiveModel.java │ │ │ └── GBCent.java │ │ ├── instance │ │ │ ├── AbstractLearningInstance.java │ │ │ └── StandardListLearningData.java │ │ └── dao │ │ │ ├── EntityListDAO.java │ │ │ ├── ItemIDListDAO.java │ │ │ └── JsonDirDAO.java │ │ └── server │ │ ├── evaluator │ │ ├── Evaluator.java │ │ ├── EvaluatorConfig.java │ │ ├── metric │ │ │ └── MetricConfig.java │ │ └── Evaluation.java │ │ ├── common │ │ ├── ModelOperator.java │ │ ├── DataOperation.java │ │ ├── Filters.java │ │ ├── AbstractComponentConfig.java │ │ ├── LoggingFilter.scala │ │ └── ModelManager.java │ │ ├── config │ │ ├── ComponentGetter.java │ │ ├── EngineConfigLoader.java │ │ └── EngineConfig.java │ │ ├── retriever │ │ ├── Retriever.java │ │ ├── RetrieverConfig.java │ │ └── RetrievedResult.java │ │ ├── space │ │ ├── SpaceType.java │ │ └── RedisSpace.java │ │ ├── featurizer │ │ ├── FeaturizerConfigParser.java │ │ └── FeatureExtractorConfig.java │ │ ├── ranker │ │ ├── Ranker.java │ │ └── RankerConfig.java │ │ ├── router │ │ ├── RouterConfig.java │ │ ├── Router.java │ │ └── BasicRouterConfig.java │ │ ├── indexer │ │ ├── IndexerConfig.java │ │ ├── Indexer.java │ │ ├── NullIndexer.java │ │ └── LoggerBasedIndexer.java │ │ ├── recommender │ │ ├── Recommender.java │ │ └── RecommenderConfig.java │ │ ├── scheduler │ │ └── SchedulerConfig.java │ │ ├── predictor │ │ ├── PredictorConfig.java │ │ └── Predictor.java │ │ ├── solver │ │ ├── LearningMethodConfig.java │ │ └── ExactGreedyConfig.java │ │ ├── dao │ │ ├── EntityDAOConfig.java │ │ ├── IndexerBasedDAO.java │ │ ├── JsonDirDAOConfig.java │ │ ├── JsonFileDAOConfig.java │ │ └── JsonFileListDAOConfig.java │ │ ├── objective │ │ ├── ObjectiveFunctionConfig.java │ │ ├── HingleLossConfig.java │ │ ├── L2NormLossConfig.java │ │ ├── LogisticLossConfig.java │ │ └── NDCGLossConfig.java │ │ ├── exception │ │ ├── BadRequestException.java │ │ └── ConfigurationException.java │ │ ├── io │ │ ├── RequestParser.java │ │ └── RequestContext.java │ │ ├── expander │ │ └── EntityExpander.java │ │ └── reinforce │ │ └── Transitioner.java ├── test │ └── org │ │ └── grouplens │ │ └── samantha │ │ ├── modeler │ │ └── featurizer │ │ │ ├── SeparatedStringExtractorTest.java │ │ │ ├── SeparatedStringSizeExtractorTest.java │ │ │ └── SeparatedStringGroupExtractorTest.java │ │ └── FakeApplication.java └── build.sbt ├── docs ├── Chapter-1-Introduction.pdf └── Chapter-2-Setup.md ├── .gitignore ├── CONTRIBUTORS.md └── LICENSE /tools/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/tensorflow/README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /tools/tensorflow/src/datasets/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tools/tensorflow/requirements.txt: -------------------------------------------------------------------------------- 1 | tensorflow==1.4.1 2 | -------------------------------------------------------------------------------- /server/conf/application.prod.conf: -------------------------------------------------------------------------------- 1 | 2 | include "application" 3 | -------------------------------------------------------------------------------- /docs/Chapter-1-Introduction.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grouplens/samantha/HEAD/docs/Chapter-1-Introduction.pdf -------------------------------------------------------------------------------- /server/activator-launch-1.3.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/grouplens/samantha/HEAD/server/activator-launch-1.3.7.jar -------------------------------------------------------------------------------- /tools/tensorflow/src/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | import sys 3 | import logging 4 | 5 | logging.basicConfig(stream=sys.stdout, level=logging.INFO) 6 | -------------------------------------------------------------------------------- /server/public/main.css: -------------------------------------------------------------------------------- 1 | .h1024 { 2 | height: 1024px; 3 | } 4 | .h500 { 5 | height: 500px; 6 | } 7 | .dn { 8 | display: none; 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/user_model.py: -------------------------------------------------------------------------------- 1 | 2 | 3 | class UserModel(object): 4 | 5 | def __init__(self): 6 | pass 7 | 8 | def get_user_model(self, max_seq_len, sequence_length, attr2embedding, attr2config): 9 | raise Exception('This must be overridden.') 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.pyc 3 | 4 | docs/.ipynb_checkpoints 5 | 6 | server/logs 7 | server/project 8 | server/target 9 | server/lib 10 | server/data 11 | server/conf/local.application.conf 12 | 13 | server/.idea 14 | server/.idea_modules 15 | server/.classpath 16 | server/.project 17 | server/.settings 18 | 19 | /RUNNING_PID 20 | -------------------------------------------------------------------------------- /tools/tensorflow/src/dataset.py: -------------------------------------------------------------------------------- 1 | 2 | class DataSet(object): 3 | 4 | def __init__(self): 5 | pass 6 | 7 | """A batch generator that generates a batch of data points in the same dict as feed_dict of TensorFlow.""" 8 | def next_batch(self): 9 | feed_dict = {} 10 | yield feed_dict 11 | 12 | def reset(self): 13 | pass -------------------------------------------------------------------------------- /server/conf/starter.conf: -------------------------------------------------------------------------------- 1 | samantha.starter { 2 | engineType = "RECOMMENDER" 3 | indexers = { 4 | loggerBasedIndexer { 5 | configClass = "org.grouplens.samantha.server.indexer.LoggerBasedIndexerConfig" 6 | } 7 | } 8 | retrievers = {} 9 | predictors = {} 10 | rankers = {} 11 | recommenders = {} 12 | router { 13 | configClass = "org.grouplens.samantha.server.router.BasicRouterConfig" 14 | recommenderKey = "recommender" 15 | predictorKey = "predictor" 16 | } 17 | evaluators = {} 18 | schedulers = {} 19 | } 20 | -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Samantha Contributors and Organizations 2 | 3 | This file documents contributors to Samantha and the copyright ownership of 4 | their contributions. To find the author of any particular contribution, review 5 | the Git commit history for Samantha. 6 | 7 | ## University of Minnesota 8 | 9 | Copyright on contributions from University of Minnesota contributors is held by 10 | the Regents of the University of Minnesota, unless otherwise noted. 11 | 12 | These contributions do not represent the position of the University of Minnesota. 13 | -------------------------------------------------------------------------------- /tools/tensorflow/src/datasets/json_list.py: -------------------------------------------------------------------------------- 1 | 2 | from src.dataset import DataSet 3 | 4 | class JsonListDataSet(DataSet): 5 | 6 | def __init__(self, batches): 7 | self._batches = batches 8 | self._idx = 0 9 | 10 | def next_batch(self): 11 | while self._idx < len(self._batches): 12 | obj = self._batches[self._idx] 13 | feed_dict = {} 14 | for key, val in obj.iteritems(): 15 | feed_dict['%s:0' % key] = val 16 | self._idx += 1 17 | yield feed_dict 18 | 19 | def reset(self): 20 | self._idx = 0 21 | -------------------------------------------------------------------------------- /docs/Chapter-2-Setup.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ### Development mode 4 | 5 | * download jdk 8 and set up JAVA_HOME and PATH=$PATH:$JAVA_HOME/bin 6 | * git clone git@github.com:grouplens/samantha.git 7 | * cd samantha/server && mkdir -p data/learning data/models data/indexed data/backup 8 | * ./activator -jvm-debug 9999 -Dhttp.port=9100 -J-Xmx4g run 9 | * go to browser and access: http://localhost:9100 10 | 11 | ### Deployment mode 12 | 13 | * set up JAVA_HOME and PATH=$PATH:$JAVA_HOME/bin 14 | * go to your deployment path (denoted as $deployment_path) 15 | * git clone git@github.com:grouplens/samantha.git 16 | * cd samantha/server && mkdir -p data/learning data/models data/indexed data/backup 17 | * ./activator clean stage 18 | * cd target/universal/stage && ln -s $deployment_path/samantha/server/data data 19 | * bin/samantha-server -Dhttp.port=9100 -J-Xmx4g & 20 | * disown 21 | * go to browser and access: http://localhost:9100 22 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/sequence_user_model.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | 4 | from src.models import layers 5 | from src.models.user_model import UserModel 6 | 7 | 8 | class SequenceUserModel(UserModel): 9 | 10 | def __init__(self, rnn_size, use_relu=True, cell_type='lstm'): 11 | self._rnn_size = rnn_size 12 | self._use_relu = use_relu 13 | self._cell_type = cell_type 14 | 15 | def get_user_model(self, max_seq_len, sequence_length, attr2embedding, attr2config): 16 | concatenated = layers.get_concat_embeddings(max_seq_len, attr2embedding, attr2config) 17 | if self._use_relu: 18 | rnn_input = layers.step_wise_relu(concatenated, self._rnn_size) 19 | else: 20 | rnn_input = concatenated 21 | if self._cell_type == 'lstm': 22 | rnn_output = layers.get_lstm_output(rnn_input, self._rnn_size) 23 | elif self._cell_type == 'gru': 24 | rnn_output = layers.get_gru_output(rnn_input, self._rnn_size) 25 | return rnn_output 26 | 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-2018 GroupLens Research at the University of Minnesota 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/svdpp_user_model.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | 4 | from src.models import layers 5 | from src.models.user_model import UserModel 6 | 7 | 8 | class SVDPPUserModel(UserModel): 9 | 10 | def __init__(self, user_attr='user', item_attrs=None, relu_size=0): 11 | self._relu_size = relu_size 12 | self._user_attr = user_attr 13 | if item_attrs is None: 14 | self._item_attrs = ['item'] 15 | else: 16 | self._item_attrs = item_attrs 17 | 18 | def get_user_model(self, max_seq_len, sequence_length, attr2embedding, attr2config): 19 | if self._relu_size > 0: 20 | concatenated = layers.get_concat_embeddings(max_seq_len, attr2embedding, attr2config) 21 | relu_output = layers.step_wise_relu(concatenated, self._relu_size) 22 | user_model = layers.get_normalized_sum(relu_output) 23 | else: 24 | user_model = tf.tile( 25 | attr2embedding[self._user_attr], [1, max_seq_len, 1]) 26 | for attr in self._item_attrs: 27 | user_model += layers.get_normalized_sum(attr2embedding[attr]) 28 | return user_model 29 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/context_metrics.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | 4 | 5 | def compute_shown_auc_metric(predictions, labels, indices, ori_batch_idx, config, context): 6 | display = context[config['ShownAUC']['context']] 7 | used_display = tf.gather_nd(display, indices) 8 | preds_idx = tf.concat([ 9 | tf.expand_dims(ori_batch_idx, 1), 10 | tf.expand_dims(used_display, 1)], 1) 11 | eval_preds = tf.gather_nd(predictions, preds_idx) 12 | eval_labels = tf.gather_nd(labels, indices) 13 | mask = used_display > 0 14 | auc_value, auc_update = tf.metrics.auc( 15 | tf.boolean_mask(eval_labels > 0, mask), 16 | tf.boolean_mask(eval_preds, mask), 17 | num_thresholds=1000) 18 | tf.summary.scalar('ShownAUC', auc_value) 19 | return auc_value, auc_update 20 | 21 | 22 | def compute_per_batch_eval_metrics(metrics, predictions, labels, indices, ori_batch_idx, config, context): 23 | updates = [] 24 | for metric in metrics.split(' '): 25 | if 'ShownAUC' == metric: 26 | updates.append(compute_shown_auc_metric(predictions, labels, indices, ori_batch_idx, config, context)[1]) 27 | return updates 28 | 29 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/composite_prediction_model.py: -------------------------------------------------------------------------------- 1 | 2 | from src.models.prediction_model import PredictionModel 3 | from src.models.softmax_prediction_model import SoftmaxPredictionModel 4 | 5 | class CompositePredictionModel(PredictionModel): 6 | 7 | def __init__(self, target2model=None): 8 | if target2model is None: 9 | self._target2model = { 10 | 'item': SoftmaxPredictionModel() 11 | } 12 | else: 13 | self._target2model = target2model 14 | 15 | def get_target_paras(self, target, config): 16 | return self._target2model[target].get_target_paras(target, config) 17 | 18 | def get_target_loss(self, used_model, labels, indices, user_model, 19 | paras, target, config, mode, context): 20 | return self._target2model[target].get_target_loss(used_model, labels, indices, user_model, 21 | paras, target, config, mode, context) 22 | 23 | def get_target_prediction(self, used_model, indices, paras, target, config, context): 24 | return self._target2model[target].get_target_prediction(used_model, indices, paras, target, config, context) 25 | 26 | -------------------------------------------------------------------------------- /server/project/plugins.sbt: -------------------------------------------------------------------------------- 1 | // The Play plugin 2 | addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.6") 3 | 4 | // Web plugins 5 | addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0") 6 | addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.6") 7 | addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3") 8 | addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7") 9 | addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0") 10 | addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0") 11 | 12 | // Play enhancer - this automatically generates getters/setters for public fields 13 | // and rewrites accessors of these fields to use the getters/setters. Remove this 14 | // plugin if you prefer not to have this feature, or disable on a per project 15 | // basis using disablePlugins(PlayEnhancer) in your build.sbt 16 | addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0") 17 | 18 | // Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using 19 | // enablePlugins(PlayEbean). Note, uncommenting this line will automatically bring in 20 | // Play enhancer, regardless of whether the line above is commented out or not. 21 | // addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0") 22 | -------------------------------------------------------------------------------- /tools/tensorflow/src/datasets/json_files.py: -------------------------------------------------------------------------------- 1 | 2 | import json 3 | import logging 4 | 5 | from src.dataset import DataSet 6 | 7 | logger = logging.getLogger('json_files') 8 | 9 | 10 | class JsonFilesDataSet(DataSet): 11 | 12 | def __init__(self, files=None, includes=None, excludes=None): 13 | if files is None: 14 | self._files = [] 15 | else: 16 | self._files = files 17 | self._includes = includes 18 | if excludes is None: 19 | self._excludes = [] 20 | else: 21 | self._excludes = excludes 22 | 23 | def next_batch(self): 24 | for afile in self._files: 25 | with open(afile) as fin: 26 | logger.info('Reading from %s.' % afile) 27 | for line in fin: 28 | obj = json.loads(line.strip()) 29 | feed_dict = {} 30 | for key, val in obj.iteritems(): 31 | if (self._includes is None or key in self._includes) and (key not in self._excludes): 32 | feed_key = '%s:0' % key 33 | feed_dict[feed_key] = val 34 | yield feed_dict 35 | 36 | def reset(self): 37 | pass 38 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/regression_prediction_model.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | 4 | from src.models.prediction_model import BasicPredictionModel 5 | 6 | 7 | class RegressionPredictionModel(BasicPredictionModel): 8 | 9 | def __init__(self, config=None): 10 | super(RegressionPredictionModel, self).__init__(config=config) 11 | 12 | def get_target_loss(self, used_model, labels, indices, user_model, 13 | paras, target, config, mode, context): 14 | context_attr = self._config[target]['context'] 15 | contexts = context[context_attr] 16 | mask = tf.gather_nd(contexts, indices) > 0 17 | indices = tf.boolean_mask(indices, mask) 18 | used_model = tf.boolean_mask(used_model, mask) 19 | used_contexts = tf.gather_nd(contexts, indices) 20 | used_labels = tf.gather_nd(labels, indices) 21 | weights = tf.gather(paras['weights'], used_contexts) 22 | biases = tf.gather(paras['biases'], used_contexts) 23 | preds = tf.reduce_sum(used_model * weights, axis=1) + biases 24 | preds = self._get_display_preds(preds, indices, paras, target, context) 25 | loss = tf.nn.l2_loss(used_labels - preds) 26 | return tf.shape(used_labels)[0], loss, [] 27 | 28 | -------------------------------------------------------------------------------- /server/app/views/main.scala.html: -------------------------------------------------------------------------------- 1 | @(title: String = "Welcome to Samantha Server!")(content: Html) 2 | 3 | 4 | 5 | 6 | 7 | @title 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | @content 22 | 23 | -------------------------------------------------------------------------------- /server/project/build.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) [2016-2017] [University of Minnesota] 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | 23 | #Activator-generated Properties 24 | #Wed Feb 24 21:37:05 CST 2016 25 | template.uuid=b508c9a8-ce44-4f1b-8ab0-11ffc31ae19a 26 | sbt.version=0.13.8 27 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/ctr_prediction_model.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | 4 | from src.models.prediction_model import SigmoidPredictionModel 5 | 6 | 7 | class CTRPredictionModel(SigmoidPredictionModel): 8 | 9 | def __init__(self, display_attr, config=None): 10 | super(CTRPredictionModel, self).__init__(config=config) 11 | self._display_attr = display_attr 12 | 13 | def get_target_loss(self, used_model, labels, indices, user_model, 14 | paras, target, config, mode, context): 15 | display = context[self._display_attr] 16 | mask = tf.gather_nd(display, indices) > 0 17 | indices = tf.boolean_mask(indices, mask) 18 | used_model = tf.boolean_mask(used_model, mask) 19 | used_display = tf.gather_nd(display, indices) 20 | weights = tf.gather(paras['weights'], used_display) 21 | biases = tf.gather(paras['biases'], used_display) 22 | logits = tf.reduce_sum(used_model * weights, axis=1) + biases 23 | logits = self._get_display_preds(logits, indices, paras, target, context) 24 | used_labels = tf.gather_nd(labels, indices) 25 | used_labels = tf.cast(used_labels > 0, tf.float32) 26 | losses = tf.nn.sigmoid_cross_entropy_with_logits(labels=used_labels, logits=logits) 27 | loss = tf.reduce_sum(losses) 28 | return tf.size(losses), loss, [] 29 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/RegularizedDualAveraging.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | public class RegularizedDualAveraging { 26 | } 27 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/model/UncollectableModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.model; 24 | 25 | public interface UncollectableModel { 26 | void destroyModel(); 27 | } 28 | -------------------------------------------------------------------------------- /server/test/org/grouplens/samantha/modeler/featurizer/SeparatedStringExtractorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.featurizer; 24 | 25 | public class SeparatedStringExtractorTest { 26 | } 27 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/tree/ClassificationCriterion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.tree; 24 | 25 | public interface ClassificationCriterion extends SplittingCriterion { 26 | } 27 | -------------------------------------------------------------------------------- /server/test/org/grouplens/samantha/modeler/featurizer/SeparatedStringSizeExtractorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.featurizer; 24 | 25 | public class SeparatedStringSizeExtractorTest { 26 | } 27 | -------------------------------------------------------------------------------- /server/test/org/grouplens/samantha/modeler/featurizer/SeparatedStringGroupExtractorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.featurizer; 24 | 25 | public class SeparatedStringGroupExtractorTest { 26 | } 27 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/ObjectiveRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | public interface ObjectiveRunnable extends Runnable { 26 | double getObjVal(); 27 | } 28 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/model/SpaceModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.model; 24 | 25 | import java.io.Serializable; 26 | 27 | public interface SpaceModel extends Serializable { 28 | void publishModel(); 29 | } 30 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/ranking/RankingLoss.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.ranking; 24 | 25 | import org.grouplens.samantha.modeler.solver.ObjectiveFunction; 26 | 27 | public interface RankingLoss extends ObjectiveFunction { 28 | } 29 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/evaluator/Evaluator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.evaluator; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | 27 | public interface Evaluator { 28 | Evaluation evaluate(RequestContext requestContext); 29 | } 30 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/tree/RegressionCriterion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.tree; 24 | 25 | import com.google.inject.ImplementedBy; 26 | 27 | @ImplementedBy(MeanDivergence.class) 28 | public interface RegressionCriterion extends SplittingCriterion { 29 | } 30 | -------------------------------------------------------------------------------- /tools/tensorflow/src/builder.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | 4 | 5 | class ModelBuilder(object): 6 | 7 | def __init__(self): 8 | pass 9 | 10 | """ The method to construct a TensorFlow model in the default graph and return the loss to optimize. 11 | 12 | This is the interface for building a TensorFlow model and should be overridden. 13 | 14 | Returns: 15 | train_loss: A scalar Tensor with the loss of the model to optimize. 16 | eval_loss: A scalar Tensor with the testing loss of the batch, used by the trainer to decide on early stopping. 17 | updates: A list of update operations for computing metrics. Can be empty. 18 | """ 19 | def build_model(self): 20 | raise Exception('This method must be overridden.') 21 | 22 | def test_tensors(self): 23 | return {} 24 | 25 | def build_optimizer(self, loss, learning_rate): 26 | return tf.train.AdagradOptimizer(learning_rate).minimize(loss, name='update_op') 27 | 28 | def dump_graph(self, file_path, learning_rate): 29 | graph = tf.Graph() 30 | with graph.as_default(): 31 | loss, _ = self.build_model() 32 | self.build_optimizer(loss, learning_rate) 33 | tf.group( 34 | tf.global_variables_initializer(), tf.local_variables_initializer(), 35 | name='init_op' 36 | ) 37 | with open(file_path, 'w') as fout: 38 | fout.write(graph.as_graph_def().SerializeToString()) 39 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/common/ModelOperator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.common; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | 27 | interface ModelOperator { 28 | Object operate(ModelManager modelManager, RequestContext requestContext); 29 | } 30 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/model/LatentLearningModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.model; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningInstance; 26 | 27 | public interface LatentLearningModel { 28 | double expectation(LearningInstance ins); 29 | LearningModel maximization(); 30 | } 31 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/config/ComponentGetter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.config; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | 27 | interface ComponentGetter { 28 | void getComponent(SamanthaConfigService configService, String componentName, RequestContext requestContext); 29 | } 30 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/tree/TreeKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.tree; 24 | 25 | public enum TreeKey { 26 | TREE("TREE"); 27 | 28 | private final String key; 29 | 30 | TreeKey(String key) { 31 | this.key = key; 32 | } 33 | 34 | public String get() { 35 | return key; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/retriever/Retriever.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.retriever; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import play.Configuration; 27 | 28 | public interface Retriever { 29 | RetrievedResult retrieve(RequestContext requestContext); 30 | Configuration getConfig(); 31 | } 32 | -------------------------------------------------------------------------------- /server/conf/routes: -------------------------------------------------------------------------------- 1 | # Routes 2 | # This file defines all application routes (Higher priority routes first) 3 | # ~~~~ 4 | 5 | # home 6 | GET / controllers.AdminHandlers.index() 7 | 8 | # assets 9 | GET /assets/*file controllers.Assets.at(path="/public", file) 10 | 11 | # global 12 | GET /config controllers.AdminHandlers.getConfig() 13 | POST /config/set controllers.AdminHandlers.setConfig() 14 | POST /config/reload controllers.AdminHandlers.reloadConfig() 15 | 16 | # engine 17 | POST /:engine/recommendation controllers.EngineHandlers.getRecommendation(engine: String) 18 | POST /:engine/prediction controllers.EngineHandlers.getPrediction(engine: String) 19 | POST /:engine/evaluate controllers.EngineHandlers.evaluate(engine: String) 20 | POST /:engine/index/data controllers.EngineHandlers.indexData(engine: String) 21 | POST /:engine/predictor/model controllers.EngineHandlers.predictorModel(engine: String) 22 | POST /:engine/retriever/model controllers.EngineHandlers.retrieverModel(engine: String) 23 | POST /:engine/ranker/model controllers.EngineHandlers.rankerModel(engine: String) 24 | POST /:engine/indexer/model controllers.EngineHandlers.indexerModel(engine: String) 25 | POST /:engine/schedule controllers.EngineHandlers.schedule(engine: String) 26 | 27 | 28 | # Add your own urls and handlers here 29 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/space/SpaceType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.space; 24 | 25 | public enum SpaceType { 26 | INDEX("index"), 27 | VARIABLE("variable"); 28 | 29 | private final String key; 30 | 31 | SpaceType(String key) { 32 | this.key = key; 33 | } 34 | 35 | public String get() { 36 | return key; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/model/SpaceMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.model; 24 | 25 | public enum SpaceMode { 26 | BUILDING("building"), 27 | DEFAULT("default"); 28 | 29 | private final String key; 30 | 31 | SpaceMode(String key) { 32 | this.key = key; 33 | } 34 | 35 | public String get() { 36 | return key; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/layers.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | 4 | 5 | def step_wise_relu(inputs, relu_size): 6 | relu_layer = tf.keras.layers.Dense(relu_size, activation='relu', dtype=tf.float32) 7 | return relu_layer(inputs) 8 | 9 | 10 | def get_concat_embeddings(max_seq_len, attr2embedding, attr2config): 11 | embeddings = [] 12 | for attr, embedding in attr2embedding.iteritems(): 13 | config = attr2config[attr] 14 | if config['level'] == 'user': 15 | embedding = tf.tile( 16 | embedding, [1, max_seq_len, 1]) 17 | embeddings.append(embedding) 18 | concatenated = tf.concat(embeddings, 2) 19 | return concatenated 20 | 21 | 22 | def get_normalized_sum(embedding): 23 | cum_sum = tf.cumsum(embedding, axis=1) 24 | num = tf.expand_dims(tf.range(1, tf.shape(embedding)[1] + 1), 1) 25 | tiled_num = tf.tile(num, [1, tf.shape(embedding)[2]]) 26 | return cum_sum / tf.cast(tiled_num, tf.float32) 27 | 28 | 29 | def get_gru_output(inputs, rnn_size): 30 | rnn_layer = tf.keras.layers.GRU(rnn_size, return_sequences=True, dtype=tf.float32) 31 | return tf.cond(tf.shape(inputs)[1] > 0, 32 | lambda: rnn_layer(inputs), 33 | lambda: tf.zeros([tf.shape(inputs)[0], 0, rnn_size])) 34 | 35 | 36 | def get_lstm_output(inputs, rnn_size): 37 | rnn_layer = tf.keras.layers.LSTM(rnn_size, return_sequences=True, dtype=tf.float32) 38 | return tf.cond(tf.shape(inputs)[1] > 0, 39 | lambda: rnn_layer(inputs), 40 | lambda: tf.zeros([tf.shape(inputs)[0], 0, rnn_size])) 41 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/reinforce/LinearUCBKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.reinforce; 24 | 25 | public enum LinearUCBKey { 26 | BIASES("BIASES"), 27 | A("A"), 28 | B("B"); 29 | 30 | private final String key; 31 | 32 | LinearUCBKey(String key) { 33 | this.key = key; 34 | } 35 | 36 | public String get() { 37 | return key; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/featurizer/FeaturizerConfigParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.featurizer; 24 | 25 | import org.grouplens.samantha.server.exception.ConfigurationException; 26 | import play.Configuration; 27 | 28 | import java.util.List; 29 | 30 | public interface FeaturizerConfigParser { 31 | List parse(Configuration config) throws ConfigurationException; 32 | } 33 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/featurizer/SelfPlusOneRatioFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.featurizer; 24 | 25 | import org.apache.commons.math3.analysis.UnivariateFunction; 26 | 27 | import static java.lang.Math.abs; 28 | 29 | public class SelfPlusOneRatioFunction implements UnivariateFunction { 30 | 31 | public double value(double val) { 32 | return val / (1.0 + abs(val)); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/common/DataOperation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.common; 24 | 25 | public enum DataOperation { 26 | UPSERT("UPSERT"), 27 | INSERT("INSERT"), 28 | DELETE("DELETE"), 29 | ; 30 | private final String key; 31 | 32 | DataOperation(String key) { 33 | this.key = key; 34 | } 35 | 36 | public String get() { 37 | return key; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/ranker/Ranker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.ranker; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import org.grouplens.samantha.server.retriever.RetrievedResult; 27 | import play.Configuration; 28 | 29 | public interface Ranker { 30 | RankedResult rank(RetrievedResult retrievedResult, RequestContext requestContext); 31 | Configuration getConfig(); 32 | } 33 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/svdfeature/SVDFeatureKey.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.svdfeature; 24 | 25 | public enum SVDFeatureKey { 26 | BIASES("BIASES"), 27 | FACTORS("FACTORS"), 28 | SUPPORT("SUPPORT"); 29 | 30 | private final String key; 31 | 32 | SVDFeatureKey(String key) { 33 | this.key = key; 34 | } 35 | 36 | public String get() { 37 | return key; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/config/EngineConfigLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.config; 24 | 25 | import org.grouplens.samantha.server.exception.ConfigurationException; 26 | import play.Configuration; 27 | import play.inject.Injector; 28 | 29 | interface EngineConfigLoader { 30 | EngineConfig loadConfig(String engineName, Configuration engineConfig, Injector injector) 31 | throws ConfigurationException; 32 | } 33 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/tree/TreeLearningMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.tree; 24 | 25 | import com.google.inject.ImplementedBy; 26 | import org.grouplens.samantha.modeler.common.LearningData; 27 | import org.grouplens.samantha.modeler.common.LearningMethod; 28 | 29 | @ImplementedBy(ExactGreedy.class) 30 | public interface TreeLearningMethod extends LearningMethod { 31 | void learn(DecisionTree tree, LearningData learningData); 32 | } 33 | -------------------------------------------------------------------------------- /server/test/org/grouplens/samantha/FakeApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha; 24 | 25 | import play.Application; 26 | 27 | import static play.test.Helpers.fakeApplication; 28 | 29 | public class FakeApplication { 30 | private static Application application; 31 | 32 | public static Application instance() { 33 | if (application == null) { 34 | application = fakeApplication(); 35 | } 36 | return application; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/ranker/RankerConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.ranker; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import play.Configuration; 27 | import play.inject.Injector; 28 | 29 | public interface RankerConfig { 30 | Ranker getRanker(RequestContext requestContext); 31 | static RankerConfig getRankerConfig(Configuration rankerConfig, 32 | Injector injector) {return null;} 33 | } 34 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/router/RouterConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.router; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import play.Configuration; 27 | import play.inject.Injector; 28 | 29 | public interface RouterConfig { 30 | static RouterConfig getRouterConfig(Configuration routerConfig, 31 | Injector injector) {return null;} 32 | Router getRouter(RequestContext requestContext); 33 | } 34 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/indexer/IndexerConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.indexer; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import play.Configuration; 27 | import play.inject.Injector; 28 | 29 | public interface IndexerConfig { 30 | static IndexerConfig getIndexerConfig(Configuration indexerConfig, 31 | Injector injector) {return null;} 32 | Indexer getIndexer(RequestContext requestContext); 33 | } 34 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/ObjectiveFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | import com.google.inject.ImplementedBy; 26 | 27 | import java.io.Serializable; 28 | import java.util.List; 29 | 30 | @ImplementedBy(L2NormLoss.class) 31 | public interface ObjectiveFunction extends Serializable { 32 | List wrapOracle(List oracles); 33 | default double wrapOutput(double modelOutput) { 34 | return modelOutput; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/OnlineOptimizationMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | import com.google.inject.ImplementedBy; 26 | import org.grouplens.samantha.modeler.common.LearningData; 27 | import org.grouplens.samantha.modeler.model.LearningModel; 28 | 29 | @ImplementedBy(StochasticGradientDescent.class) 30 | public interface OnlineOptimizationMethod extends OptimizationMethod { 31 | double update(LearningModel learningModel, LearningData learningData); 32 | } 33 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/evaluator/EvaluatorConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.evaluator; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import play.Configuration; 27 | import play.inject.Injector; 28 | 29 | public interface EvaluatorConfig { 30 | static EvaluatorConfig getEvaluatorConfig(Configuration evalConfig, 31 | Injector injector) {return null;} 32 | Evaluator getEvaluator(RequestContext requestContext); 33 | } 34 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/recommender/Recommender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.recommender; 24 | 25 | import org.grouplens.samantha.server.exception.BadRequestException; 26 | import org.grouplens.samantha.server.io.RequestContext; 27 | import org.grouplens.samantha.server.ranker.RankedResult; 28 | import play.Configuration; 29 | 30 | public interface Recommender { 31 | RankedResult recommend(RequestContext requestContext) throws BadRequestException; 32 | Configuration getConfig(); 33 | } 34 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/retriever/RetrieverConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.retriever; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import play.Configuration; 27 | import play.inject.Injector; 28 | 29 | public interface RetrieverConfig { 30 | static RetrieverConfig getRetrieverConfig(Configuration retrieverConfig, 31 | Injector injector) {return null;} 32 | Retriever getRetriever(RequestContext requestContext); 33 | } 34 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/Regularizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | import org.apache.commons.math3.linear.RealVector; 26 | 27 | import java.util.List; 28 | 29 | public interface Regularizer { 30 | double getValue(double var); 31 | double getGradient(double var); 32 | RealVector addGradient(RealVector grad, RealVector var, double coef); 33 | double getObjective(double coef, RealVector var); 34 | double getObjective(double coef, List vars); 35 | } 36 | -------------------------------------------------------------------------------- /server/build.sbt: -------------------------------------------------------------------------------- 1 | name := """samantha-server""" 2 | 3 | version := "1.0.0-SNAPSHOT" 4 | 5 | lazy val root = (project in file(".")).enablePlugins(PlayJava) 6 | 7 | // sources in (Compile, doc) <<= sources in (Compile, doc) map { _.filterNot(_.getName endsWith ".scala") } 8 | 9 | scalaVersion := "2.11.6" 10 | 11 | // resolvers += Resolver.mavenLocal 12 | 13 | libraryDependencies ++= Seq( 14 | javaJdbc, 15 | cache, 16 | javaWs, 17 | "junit" % "junit" % "4.11", 18 | "org.elasticsearch" % "elasticsearch" % "2.2.0", 19 | "it.unimi.dsi" % "fastutil" % "7.0.11", 20 | "com.google.guava" % "guava" % "19.0", 21 | "org.apache.commons" % "commons-math3" % "3.6.1", 22 | "org.apache.commons" % "commons-io" % "1.3.2", 23 | "com.fasterxml.jackson.dataformat" % "jackson-dataformat-csv" % "2.7.0", 24 | "biz.paluch.redis" % "lettuce" % "4.2.2.Final", 25 | "org.quartz-scheduler" % "quartz" % "2.2.1", 26 | "org.quartz-scheduler" % "quartz-jobs" % "2.2.1", 27 | "org.tensorflow" % "tensorflow" % "1.4.0", 28 | "org.jooq" % "jooq" % "3.9.1", 29 | "mysql" % "mysql-connector-java" % "5.1.18", 30 | "commons-dbutils" % "commons-dbutils" % "1.6", 31 | "org.bouncycastle" % "bcprov-jdk15" % "1.44", 32 | "org.bouncycastle" % "bcmail-jdk15" % "1.44", 33 | "ml.dmlc" % "xgboost4j" % "0.72", 34 | "org.webjars" % "jquery" % "3.3.1", 35 | "org.webjars" % "bootstrap" % "4.1.1", 36 | "org.webjars.npm" % "jsoneditor" % "5.17.1", 37 | "org.webjars" % "ace" % "1.2.8" 38 | ) 39 | 40 | // Play provides two styles of routers, one expects its actions to be injected, the 41 | // other, legacy style, accesses its actions statically. 42 | routesGenerator := InjectedRoutesGenerator 43 | 44 | Keys.fork in Test := false 45 | Keys.parallelExecution in Test := false 46 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/recommender/RecommenderConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.recommender; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import play.Configuration; 27 | import play.inject.Injector; 28 | 29 | public interface RecommenderConfig { 30 | static RecommenderConfig getRecommenderConfig(Configuration recommenderConfig, 31 | Injector injector) {return null;} 32 | Recommender getRecommender(RequestContext requestContext); 33 | } 34 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/scheduler/SchedulerConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.scheduler; 24 | 25 | import play.Configuration; 26 | import play.inject.Injector; 27 | 28 | public interface SchedulerConfig { 29 | static SchedulerConfig getSchedulerConfig(String engineName, String schedulerName, 30 | Configuration schedulerConfig, 31 | Injector injector) {return null;} 32 | void scheduleJobs(); 33 | void runJobs(); 34 | } 35 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/tree/AbstractTreeLearningMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.tree; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningData; 26 | import org.grouplens.samantha.modeler.common.PredictiveModel; 27 | 28 | abstract public class AbstractTreeLearningMethod implements TreeLearningMethod { 29 | public void learn(PredictiveModel model, LearningData learningData, LearningData validData) { 30 | DecisionTree tree = (DecisionTree) model; 31 | learn(tree, learningData); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/evaluator/metric/MetricConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.evaluator.metric; 24 | 25 | import org.grouplens.samantha.modeler.metric.Metric; 26 | import org.grouplens.samantha.server.io.RequestContext; 27 | import play.Configuration; 28 | import play.inject.Injector; 29 | 30 | public interface MetricConfig { 31 | static MetricConfig getMetricConfig(Configuration metricConfig, 32 | Injector injector) {return null;} 33 | Metric getMetric(RequestContext requestContext); 34 | } 35 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/OptimizationMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | import com.google.inject.ImplementedBy; 26 | import org.grouplens.samantha.modeler.common.LearningData; 27 | import org.grouplens.samantha.modeler.common.LearningMethod; 28 | import org.grouplens.samantha.modeler.model.LearningModel; 29 | 30 | @ImplementedBy(StochasticGradientDescent.class) 31 | public interface OptimizationMethod extends LearningMethod { 32 | double minimize(LearningModel model, LearningData learningData, LearningData validData); 33 | } 34 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/predictor/PredictorConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.predictor; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import play.Configuration; 27 | import play.inject.Injector; 28 | 29 | //TODO: add model evaluation support for all kinds of predictors 30 | public interface PredictorConfig { 31 | Predictor getPredictor(RequestContext requestContext); 32 | static PredictorConfig getPredictorConfig(Configuration predictorConfig, 33 | Injector injector) {return null;} 34 | } 35 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/metric/Metric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.metric; 24 | 25 | import com.fasterxml.jackson.databind.node.ObjectNode; 26 | import org.grouplens.samantha.server.predictor.Prediction; 27 | 28 | import java.util.List; 29 | 30 | //TODO: split this into several interfaces: RegressionMetric, ClassificationMetric, RankingMetric, RecommendationMetric 31 | //TODO: use raw data type instead of Json or Prediction 32 | public interface Metric { 33 | void add(List groundTruth, List results); 34 | MetricResult getResults(); 35 | } 36 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/common/Filters.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.common; 24 | 25 | import play.api.mvc.EssentialFilter; 26 | import play.http.HttpFilters; 27 | import javax.inject.Inject; 28 | 29 | public class Filters implements HttpFilters { 30 | private final LoggingFilter loggingFilter; 31 | 32 | @Inject 33 | public Filters(LoggingFilter loggingFilter) { 34 | this.loggingFilter = loggingFilter; 35 | } 36 | 37 | @Override 38 | public EssentialFilter[] filters() { 39 | return new EssentialFilter[] {loggingFilter}; 40 | } 41 | } -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/solver/LearningMethodConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.solver; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningMethod; 26 | import org.grouplens.samantha.server.io.RequestContext; 27 | import play.Configuration; 28 | import play.inject.Injector; 29 | 30 | public interface LearningMethodConfig { 31 | static LearningMethod getLearningMethod(Configuration methodConfig, 32 | Injector injector, 33 | RequestContext requestContext) {return null;} 34 | } 35 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/ranking/LambdaLoss.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.ranking; 24 | 25 | import org.grouplens.samantha.modeler.solver.StochasticOracle; 26 | 27 | import java.util.List; 28 | 29 | public interface LambdaLoss extends RankingLoss { 30 | /** 31 | * @param scores the length should be the length of relevance + 1 where the last element is used for storing useful information. 32 | */ 33 | double getDelta(int i, int j, double[] scores, double[] relevance); 34 | double getMetric(int maxN, List topN, double[] scores, double[] relevance); 35 | } 36 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/dao/EntityDAOConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.dao; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import org.grouplens.samantha.modeler.dao.EntityDAO; 27 | import org.grouplens.samantha.server.io.RequestContext; 28 | import play.Configuration; 29 | import play.inject.Injector; 30 | 31 | public interface EntityDAOConfig { 32 | static EntityDAOConfig getEntityDAOConfig(Configuration daoConfig, 33 | Injector injector) {return null;} 34 | EntityDAO getEntityDAO(RequestContext requestContext, JsonNode reqDao); 35 | } 36 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/featurizer/FeatureExtractorConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.featurizer; 24 | 25 | import org.grouplens.samantha.modeler.featurizer.FeatureExtractor; 26 | import org.grouplens.samantha.server.io.RequestContext; 27 | import play.Configuration; 28 | import play.inject.Injector; 29 | 30 | public interface FeatureExtractorConfig { 31 | FeatureExtractor getFeatureExtractor(RequestContext requestContext); 32 | static FeatureExtractorConfig getFeatureExtractorConfig(Configuration predictorConfig, 33 | Injector injector) {return null;} 34 | } 35 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/objective/ObjectiveFunctionConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.objective; 24 | 25 | import org.grouplens.samantha.modeler.solver.ObjectiveFunction; 26 | import org.grouplens.samantha.server.io.RequestContext; 27 | import play.Configuration; 28 | import play.inject.Injector; 29 | 30 | public interface ObjectiveFunctionConfig { 31 | static ObjectiveFunction getObjectiveFunction(Configuration objectiveConfig, 32 | Injector injector, 33 | RequestContext requestContext){return null;} 34 | } 35 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/boosting/BoostedPredictiveModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.boosting; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningMethod; 26 | import org.grouplens.samantha.modeler.common.PredictiveModel; 27 | import org.grouplens.samantha.modeler.solver.ObjectiveFunction; 28 | 29 | public interface BoostedPredictiveModel extends PredictiveModel { 30 | ObjectiveFunction getObjectiveFunction(); 31 | PredictiveModel getPredictiveModel(); 32 | LearningMethod getLearningMethod(); 33 | void addPredictiveModel(PredictiveModel model); 34 | void setBestIteration(int iter); 35 | } 36 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/exception/BadRequestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.exception; 24 | 25 | public class BadRequestException extends RuntimeException { 26 | private static final long serialVersionUID = 1L; 27 | 28 | public BadRequestException() { 29 | super(); 30 | } 31 | 32 | public BadRequestException(String message) { 33 | super(message); 34 | } 35 | 36 | public BadRequestException(Throwable cause) { 37 | super(cause); 38 | } 39 | 40 | public BadRequestException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/router/Router.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.router; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import org.grouplens.samantha.server.predictor.Predictor; 27 | import org.grouplens.samantha.server.recommender.Recommender; 28 | 29 | import java.util.Map; 30 | 31 | public interface Router { 32 | Recommender routeRecommender(Map recommenders, 33 | RequestContext requestContext); 34 | Predictor routePredictor(Map predictors, 35 | RequestContext requestContext); 36 | } 37 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/instance/AbstractLearningInstance.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.instance; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningInstance; 26 | 27 | abstract public class AbstractLearningInstance implements LearningInstance { 28 | protected String group; 29 | 30 | public AbstractLearningInstance() {} 31 | 32 | public AbstractLearningInstance(String group) { 33 | this.group = group; 34 | } 35 | 36 | public String getGroup() { 37 | return group; 38 | } 39 | 40 | public void setGroup(String group) { 41 | this.group = group; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/IdentityFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | import java.util.List; 26 | 27 | public class IdentityFunction implements ObjectiveFunction { 28 | private static final long serialVersionUID = 1L; 29 | 30 | public IdentityFunction() {} 31 | 32 | public List wrapOracle(List oracles) { 33 | for (StochasticOracle orc : oracles) { 34 | double weight = orc.getWeight(); 35 | orc.setObjVal(orc.getModelOutput() * weight); 36 | orc.setGradient(weight); 37 | } 38 | return oracles; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/exception/ConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.exception; 24 | 25 | public class ConfigurationException extends RuntimeException { 26 | private static final long serialVersionUID = 1L; 27 | 28 | public ConfigurationException() { 29 | super(); 30 | } 31 | 32 | public ConfigurationException(Throwable cause) { 33 | super(cause); 34 | } 35 | 36 | public ConfigurationException(String message) { 37 | super(message); 38 | } 39 | 40 | public ConfigurationException(String message, Throwable cause) { 41 | super(message, cause); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/predictor/Predictor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.predictor; 24 | 25 | import com.fasterxml.jackson.databind.node.ObjectNode; 26 | import org.grouplens.samantha.server.io.RequestContext; 27 | import play.Configuration; 28 | 29 | import java.util.List; 30 | 31 | public interface Predictor { 32 | /** 33 | * The size of List must be consistent with the size List entityList. 34 | */ 35 | List predict(List entityList, RequestContext requestContext); 36 | List predict(RequestContext requestContext); 37 | Configuration getConfig(); 38 | } 39 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/io/RequestParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.io; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | 27 | import org.grouplens.samantha.server.exception.BadRequestException; 28 | 29 | import javax.inject.Inject; 30 | import javax.inject.Singleton; 31 | 32 | @Singleton 33 | public class RequestParser { 34 | 35 | @Inject 36 | private RequestParser() {} 37 | 38 | public RequestContext getJsonRequestContext(String engine, JsonNode requestBody) 39 | throws BadRequestException { 40 | RequestContext requestContext = new RequestContext(requestBody, engine); 41 | return requestContext; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/indexer/Indexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.indexer; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import com.fasterxml.jackson.databind.node.ObjectNode; 27 | import org.grouplens.samantha.modeler.dao.EntityDAO; 28 | import org.grouplens.samantha.server.io.RequestContext; 29 | import play.Configuration; 30 | 31 | public interface Indexer { 32 | void index(RequestContext requestContext); 33 | void index(JsonNode data, RequestContext requestContext); 34 | ObjectNode getIndexedDataDAOConfig(RequestContext requestContext); 35 | EntityDAO getEntityDAO(RequestContext requestContext); 36 | Configuration getConfig(); 37 | } 38 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/common/AbstractComponentConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.common; 24 | 25 | import org.grouplens.samantha.server.expander.ExpanderUtilities; 26 | import play.Configuration; 27 | 28 | import java.util.List; 29 | 30 | abstract public class AbstractComponentConfig { 31 | final protected Configuration config; 32 | final protected List expandersConfig; 33 | 34 | public AbstractComponentConfig(Configuration config) { 35 | this.config = config; 36 | this.expandersConfig = ExpanderUtilities.getEntityExpandersConfig(config); 37 | } 38 | 39 | public Configuration getConfig() { 40 | return config; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/boosting/GBCent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.boosting; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningData; 26 | import org.grouplens.samantha.modeler.common.PredictiveModel; 27 | import org.grouplens.samantha.modeler.svdfeature.SVDFeature; 28 | import org.grouplens.samantha.modeler.instance.StandardLearningInstance; 29 | 30 | import java.util.List; 31 | 32 | public interface GBCent extends PredictiveModel { 33 | SVDFeature getSVDFeatureModel(); 34 | LearningData getLearningData(List treeInstances); 35 | PredictiveModel getNumericalTree(int treeIdx); 36 | void setNumericalTree(int treeIdx, PredictiveModel tree); 37 | } 38 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/objective/HingleLossConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.objective; 24 | 25 | import org.grouplens.samantha.modeler.solver.HingeLoss; 26 | import org.grouplens.samantha.modeler.solver.ObjectiveFunction; 27 | import org.grouplens.samantha.server.io.RequestContext; 28 | import play.Configuration; 29 | import play.inject.Injector; 30 | 31 | public class HingleLossConfig { 32 | static public ObjectiveFunction getObjectiveFunction(Configuration objectiveConfig, 33 | Injector injector, 34 | RequestContext requestContext) { 35 | return new HingeLoss(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/objective/L2NormLossConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.objective; 24 | 25 | import org.grouplens.samantha.modeler.solver.L2NormLoss; 26 | import org.grouplens.samantha.modeler.solver.ObjectiveFunction; 27 | import org.grouplens.samantha.server.io.RequestContext; 28 | import play.Configuration; 29 | import play.inject.Injector; 30 | 31 | public class L2NormLossConfig { 32 | static public ObjectiveFunction getObjectiveFunction(Configuration objectiveConfig, 33 | Injector injector, 34 | RequestContext requestContext) { 35 | return new L2NormLoss(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/io/RequestContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.io; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | 27 | import javax.inject.Inject; 28 | 29 | public class RequestContext { 30 | 31 | final private String engineName; 32 | final private JsonNode requestBody; 33 | 34 | @Inject 35 | public RequestContext(JsonNode requestBody, 36 | String engineName) { 37 | this.requestBody = requestBody; 38 | this.engineName = engineName; 39 | } 40 | 41 | public String getEngineName() { 42 | return engineName; 43 | } 44 | 45 | public JsonNode getRequestBody() { 46 | return requestBody; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/objective/LogisticLossConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.objective; 24 | 25 | import org.grouplens.samantha.modeler.solver.LogisticLoss; 26 | import org.grouplens.samantha.modeler.solver.ObjectiveFunction; 27 | import org.grouplens.samantha.server.io.RequestContext; 28 | import play.Configuration; 29 | import play.inject.Injector; 30 | 31 | public class LogisticLossConfig { 32 | static public ObjectiveFunction getObjectiveFunction(Configuration objectiveConfig, 33 | Injector injector, 34 | RequestContext requestContext) { 35 | return new LogisticLoss(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/metric/MetricResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.metric; 24 | 25 | import com.fasterxml.jackson.annotation.JsonProperty; 26 | import com.fasterxml.jackson.databind.node.ObjectNode; 27 | 28 | import java.util.List; 29 | 30 | public class MetricResult { 31 | @JsonProperty 32 | private final List values; 33 | @JsonProperty 34 | private final boolean pass; 35 | 36 | public MetricResult(List values, boolean pass) { 37 | this.values = values; 38 | this.pass = pass; 39 | } 40 | 41 | public List getValues() { 42 | return values; 43 | } 44 | 45 | public boolean getPass() { 46 | return pass; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/tree/SplittingCriterion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.tree; 24 | 25 | import it.unimi.dsi.fastutil.ints.IntList; 26 | 27 | import java.io.Serializable; 28 | import java.util.List; 29 | 30 | public interface SplittingCriterion extends Serializable { 31 | void add(IntList idxList, List resps); 32 | void add(int idx, List resps); 33 | void remove(IntList idxList, List resps); 34 | void remove(int idx, List resps); 35 | double getValue(List resps); 36 | double getSplittingGain(double beforeValue, SplittingCriterion leftSplit, 37 | SplittingCriterion rightSplit, List resps); 38 | SplittingCriterion create(); 39 | } 40 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/model/SpaceUtilities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.model; 24 | 25 | import java.util.List; 26 | import java.util.concurrent.locks.Lock; 27 | import java.util.concurrent.locks.ReentrantReadWriteLock; 28 | 29 | public class SpaceUtilities { 30 | static void fillReadWriteLocks(List readLocks, 31 | List writeLocks, 32 | int curSize, int size) { 33 | if (curSize < size) { 34 | for (int i=curSize; i wrapOracle(List oracles) { 33 | for (StochasticOracle orc : oracles) { 34 | double modelOutput = orc.getModelOutput(); 35 | double label = orc.getLabel(); 36 | double weight = orc.getWeight(); 37 | double err = modelOutput - label; 38 | orc.setObjVal(err * err * weight); 39 | orc.setGradient(err * weight); 40 | } 41 | return oracles; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/bpr_prediction_model.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | 4 | from src.models.prediction_model import SigmoidPredictionModel 5 | 6 | 7 | class BPRPredictionModel(SigmoidPredictionModel): 8 | 9 | def __init__(self, display_attr, display_size, config=None): 10 | super(BPRPredictionModel, self).__init__(config=config) 11 | self._display_attr = display_attr 12 | self._display_size = display_size 13 | 14 | def get_target_loss(self, used_model, labels, indices, user_model, 15 | paras, target, config, mode, context): 16 | mask = tf.gather_nd(labels, indices) > 0 17 | indices = tf.boolean_mask(indices, mask) 18 | used_model = tf.boolean_mask(used_model, mask) 19 | used_labels = tf.gather_nd(labels, indices) 20 | display = context[self._display_attr] 21 | batch_step = tf.slice(indices, 22 | begin=[0, 0], 23 | size=[tf.shape(indices)[0], 2]) 24 | used_display = tf.reshape( 25 | tf.gather_nd(display, batch_step), 26 | [tf.shape(batch_step)[0], self._display_size]) 27 | tiled_labels = tf.tile( 28 | tf.expand_dims(used_labels, axis=1), 29 | [1, self._display_size]) 30 | tiled_model = tf.tile( 31 | tf.expand_dims(used_model, axis=1), 32 | [1, self._display_size, 1]) 33 | 34 | weights = tf.gather(paras['weights'], tiled_labels) - tf.gather(paras['weights'], used_display) 35 | biases = tf.gather(paras['biases'], tiled_labels) - tf.gather(paras['biases'], used_display) 36 | logits = tf.reduce_sum(tiled_model * weights, axis=2) + biases 37 | 38 | loss_mask = tf.not_equal(tiled_labels, used_display) 39 | losses = tf.nn.sigmoid_cross_entropy_with_logits(labels=tf.ones_like(logits), logits=logits) 40 | losses = tf.boolean_mask(losses, loss_mask) 41 | loss = tf.reduce_sum(losses) 42 | return tf.size(losses), loss, [] 43 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/featurizer/Feature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.featurizer; 24 | 25 | import java.io.Serializable; 26 | 27 | public class Feature implements Serializable { 28 | private double value; 29 | private int index; 30 | 31 | public Feature() { 32 | value = 0; 33 | index = 0; 34 | } 35 | 36 | public Feature(int index, double value) { 37 | this.value = value; 38 | this.index = index; 39 | } 40 | 41 | public int getIndex() { 42 | return index; 43 | } 44 | 45 | public void setIndex(int index) { 46 | this.index = index; 47 | } 48 | 49 | public double getValue() { 50 | return value; 51 | } 52 | 53 | public void setValue(double value) { 54 | this.value = value; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/expander/EntityExpander.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.expander; 24 | 25 | import com.fasterxml.jackson.databind.node.ObjectNode; 26 | import org.grouplens.samantha.server.io.RequestContext; 27 | import play.Configuration; 28 | import play.inject.Injector; 29 | 30 | import java.util.List; 31 | 32 | /*** 33 | * This does not guarantee the expanded fields are complete and leave to the downstream feature extractors to deal with. 34 | */ 35 | public interface EntityExpander { 36 | static EntityExpander getExpander(Configuration expanderConfig, 37 | Injector injector, RequestContext requestContext) {return null;} 38 | List expand(List initialResult, 39 | RequestContext requestContext); 40 | } 41 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/EvaluateRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningData; 26 | import org.grouplens.samantha.modeler.model.LearningModel; 27 | 28 | public class EvaluateRunnable implements ObjectiveRunnable { 29 | private final LearningModel learningModel; 30 | private final LearningData learningData; 31 | private double objVal = 0.0; 32 | 33 | EvaluateRunnable(LearningModel learningModel, LearningData learningData) { 34 | this.learningData = learningData; 35 | this.learningModel = learningModel; 36 | } 37 | 38 | public void run() { 39 | objVal = SolverUtilities.evaluate(learningModel, learningData); 40 | } 41 | 42 | public double getObjVal() { 43 | return objVal; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/metrics_test.py: -------------------------------------------------------------------------------- 1 | 2 | import unittest 3 | import random 4 | import numpy as np 5 | import tensorflow as tf 6 | 7 | from src.models.metrics import * 8 | 9 | 10 | class MetricsTest(unittest.TestCase): 11 | 12 | def test_compute_map_metrics(self): 13 | graph = tf.Graph() 14 | with graph.as_default(): 15 | session = tf.Session(graph=graph) 16 | with session.as_default(): 17 | with tf.variable_scope('test1'): 18 | labels = tf.constant([2], dtype=tf.int64) 19 | preds = tf.constant([[0.01, 0.4, 0.1]]) 20 | values, updates = compute_map_metrics(labels, preds, 'MAP@1,2') 21 | session.run([tf.global_variables_initializer(), tf.local_variables_initializer()]) 22 | session.run(updates) 23 | maps = session.run(values) 24 | self.assertEqual(maps[0], 0.0) 25 | self.assertEqual(maps[1], 0.5) 26 | with tf.variable_scope('test2'): 27 | labels = tf.SparseTensor( 28 | tf.constant([[0, 2], [0, 5], [1, 0], [1, 2], [1, 4]], dtype=tf.int64), 29 | tf.constant([2, 3, 0, 7, 1], dtype=tf.int64), 30 | tf.constant([2, 6], dtype=tf.int64)) 31 | preds = tf.constant([ 32 | [0.3, 0.1, 0.9, 0.10, 0.2, 0.01, 0.003, 0.14], 33 | [0.01, 0.9, 0.1, 0.2, 0.38, 0.2, 0.48, 0.04]]) 34 | values, updates = compute_map_metrics(labels, preds, 'MAP@1,7,8') 35 | session.run([tf.global_variables_initializer(), tf.local_variables_initializer()]) 36 | session.run(updates) 37 | maps = session.run(values) 38 | self.assertAlmostEqual(maps[0], 1.000, delta=0.001) 39 | self.assertAlmostEqual(maps[1], 0.547, delta=0.001) 40 | self.assertAlmostEqual(maps[2], 0.610, delta=0.001) 41 | 42 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/reinforce/Transitioner.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.reinforce; 24 | 25 | import com.fasterxml.jackson.databind.node.ObjectNode; 26 | import org.grouplens.samantha.server.io.RequestContext; 27 | import play.Configuration; 28 | import play.inject.Injector; 29 | 30 | import java.util.List; 31 | 32 | public interface Transitioner { 33 | static Transitioner getTransitioner(Configuration config, 34 | Injector injector, 35 | RequestContext requestContext) {return null;} 36 | /** 37 | * Set the current state and set the probability of each new state in the attribute of the 38 | * returned ObjectNode with given key in ConfigKey 39 | */ 40 | List transition(ObjectNode currentState, ObjectNode action); 41 | } 42 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/dao/EntityListDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.dao; 24 | 25 | import com.fasterxml.jackson.databind.node.ObjectNode; 26 | 27 | import java.util.List; 28 | 29 | public class EntityListDAO implements EntityDAO { 30 | private int iter = 0; 31 | private final List entityList; 32 | 33 | public EntityListDAO(List entityList) { 34 | this.entityList = entityList; 35 | } 36 | 37 | public boolean hasNextEntity() { 38 | if (iter >= entityList.size()) { 39 | return false; 40 | } else { 41 | return true; 42 | } 43 | } 44 | 45 | public ObjectNode getNextEntity() { 46 | return entityList.get(iter++); 47 | } 48 | 49 | public void restart() { 50 | iter = 0; 51 | } 52 | 53 | public void close() {} 54 | } 55 | -------------------------------------------------------------------------------- /server/app/views/Application/index.scala.html: -------------------------------------------------------------------------------- 1 | @main() { 2 |
Welcome to Samantha! Edit below to customize the server for you.
3 |
4 | 5 | Success! 6 |
7 |
8 | 9 | Error! 10 |
11 |
12 |
13 | 26 |
27 |
28 | 41 |
42 |
43 | } 44 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/indexer/NullIndexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.indexer; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import org.grouplens.samantha.server.config.SamanthaConfigService; 27 | import org.grouplens.samantha.server.io.RequestContext; 28 | import play.Configuration; 29 | import play.inject.Injector; 30 | 31 | public class NullIndexer extends AbstractIndexer { 32 | 33 | public NullIndexer(Configuration config, 34 | SamanthaConfigService configService, 35 | Injector injector, String daoConfigKey, 36 | Configuration daoConfigs, int batchSize, 37 | RequestContext requestContext) { 38 | super(config, configService, daoConfigs, daoConfigKey, batchSize, requestContext, injector); 39 | } 40 | 41 | public void index(JsonNode data, RequestContext requestContext) {} 42 | } 43 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/retriever/RetrievedResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.retriever; 24 | 25 | import com.fasterxml.jackson.databind.node.ObjectNode; 26 | 27 | import java.util.List; 28 | 29 | public class RetrievedResult { 30 | private List entityList; 31 | private long maxHits; 32 | 33 | public RetrievedResult(List entityList, long maxHits) { 34 | this.entityList = entityList; 35 | this.maxHits = maxHits; 36 | } 37 | 38 | public List getEntityList() { 39 | return entityList; 40 | } 41 | 42 | List setEntityList(List newList) { 43 | this.entityList = newList; 44 | return newList; 45 | } 46 | 47 | public void setMaxHits(long maxHits) { 48 | this.maxHits = maxHits; 49 | } 50 | 51 | public long getMaxHits() { 52 | return maxHits; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/model/SpaceProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.model; 24 | 25 | import javax.inject.Inject; 26 | 27 | public class SpaceProducer { 28 | @Inject 29 | private IndexSpace indexSpace; 30 | @Inject 31 | private VariableSpace variableSpace; 32 | 33 | @Inject 34 | private SpaceProducer() { 35 | } 36 | 37 | public SpaceProducer(IndexSpace indexSpace, VariableSpace variableSpace) { 38 | this.indexSpace = indexSpace; 39 | this.variableSpace = variableSpace; 40 | } 41 | 42 | public IndexSpace getIndexSpace(String spaceName, SpaceMode spaceMode) { 43 | indexSpace.setSpaceState(spaceName, spaceMode); 44 | return indexSpace; 45 | } 46 | 47 | public VariableSpace getVariableSpace(String spaceName, SpaceMode spaceMode) { 48 | variableSpace.setSpaceState(spaceName, spaceMode); 49 | return variableSpace; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/space/RedisSpace.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.space; 24 | 25 | import org.grouplens.samantha.modeler.model.SpaceMode; 26 | import org.grouplens.samantha.server.common.RedisService; 27 | 28 | abstract public class RedisSpace { 29 | protected SpaceMode spaceMode; 30 | protected String spaceVersion; 31 | protected String spaceName; 32 | protected SpaceType spaceType; 33 | protected String spaceIdentifier; 34 | protected final RedisService redisService; 35 | 36 | public RedisSpace(RedisService redisService) { 37 | this.redisService = redisService; 38 | } 39 | 40 | synchronized public void publishSpaceVersion() { 41 | redisService.set(spaceName + "_" + spaceType.get(), SpaceMode.DEFAULT.get(), spaceVersion); 42 | redisService.del(spaceName + "_" + spaceType.get(), SpaceMode.BUILDING.get()); 43 | spaceMode = SpaceMode.DEFAULT; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/common/LoggingFilter.scala: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.common 24 | 25 | import play.api.Logger 26 | import play.api.mvc._ 27 | import scala.concurrent.Future 28 | import play.api.libs.concurrent.Execution.Implicits.defaultContext 29 | 30 | class LoggingFilter extends Filter { 31 | 32 | def apply(nextFilter: RequestHeader => Future[Result]) 33 | (requestHeader: RequestHeader): Future[Result] = { 34 | 35 | val startTime = System.currentTimeMillis 36 | 37 | nextFilter(requestHeader).map { result => 38 | 39 | val endTime = System.currentTimeMillis 40 | val requestTime = endTime - startTime 41 | 42 | Logger.info(s"${requestHeader.remoteAddress}" + 43 | s" - ${requestHeader.method} ${requestHeader.uri}" + 44 | s" - ${requestTime}ms" + 45 | s" - ${result.header.status}") 46 | 47 | result.withHeaders("Request-Time" -> requestTime.toString) 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/tree/DecisionTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.tree; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import it.unimi.dsi.fastutil.ints.IntList; 27 | import org.grouplens.samantha.modeler.featurizer.Feature; 28 | import org.grouplens.samantha.modeler.common.LearningInstance; 29 | import org.grouplens.samantha.modeler.common.PredictiveModel; 30 | import org.grouplens.samantha.modeler.instance.StandardLearningInstance; 31 | 32 | import java.util.List; 33 | 34 | public interface DecisionTree extends PredictiveModel { 35 | StandardLearningInstance getLearningInstance(LearningInstance ins); 36 | SplittingCriterion createSplittingCriterion(); 37 | int predictLeaf(JsonNode entity); 38 | 39 | /** 40 | * @return The newly created node index. 41 | */ 42 | int createNode(int parentNode, boolean left, IntList relevant, 43 | List respList, Feature bestSplit); 44 | } 45 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/common/ModelManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.common; 24 | 25 | import org.grouplens.samantha.modeler.model.SpaceMode; 26 | import org.grouplens.samantha.server.io.RequestContext; 27 | 28 | public interface ModelManager { 29 | Object manage(RequestContext requestContext); 30 | Object createModel(RequestContext requestContext, SpaceMode spaceMode); 31 | Object resetModel(RequestContext requestContext); 32 | Object buildModel(RequestContext requestContext); 33 | Object buildModel(Object model, RequestContext requestContext); 34 | Object evaluateModel(RequestContext requestContext); 35 | boolean passModel(Object model, RequestContext requestContext); 36 | Object updateModel(RequestContext requestContext); 37 | Object updateModel(Object model, RequestContext requestContext); 38 | Object dumpModel(RequestContext requestContext); 39 | Object loadModel(RequestContext requestContext); 40 | } 41 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/HingeLoss.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | import java.util.List; 26 | 27 | public class HingeLoss implements ObjectiveFunction { 28 | private static final long serialVersionUID = 1L; 29 | 30 | public HingeLoss() { } 31 | 32 | private double getLoss(double wrappedOutput, double label, double weight) { 33 | return (1 - wrappedOutput * label) * weight; 34 | } 35 | 36 | public List wrapOracle(List oracles) { 37 | for (StochasticOracle orc : oracles) { 38 | double label = orc.getLabel(); 39 | if (label == 0) { 40 | label = -1; 41 | } 42 | double loss = getLoss(orc.getModelOutput(), label, orc.getWeight()); 43 | orc.setObjVal((loss < 0) ? 0 : loss); 44 | orc.setGradient((loss == 0) ? 0 : -label); 45 | } 46 | return oracles; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/dao/IndexerBasedDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.dao; 24 | 25 | import com.fasterxml.jackson.databind.node.ObjectNode; 26 | import org.grouplens.samantha.modeler.dao.EntityDAO; 27 | import org.grouplens.samantha.server.indexer.Indexer; 28 | import org.grouplens.samantha.server.io.RequestContext; 29 | 30 | public class IndexerBasedDAO implements EntityDAO { 31 | private final EntityDAO entityDAO; 32 | 33 | public IndexerBasedDAO(Indexer indexer, RequestContext requestContext) { 34 | this.entityDAO = indexer.getEntityDAO(requestContext); 35 | } 36 | 37 | public boolean hasNextEntity() { 38 | return entityDAO.hasNextEntity(); 39 | } 40 | 41 | public ObjectNode getNextEntity() { 42 | return entityDAO.getNextEntity(); 43 | } 44 | 45 | public void restart() { 46 | entityDAO.restart(); 47 | } 48 | 49 | public void close() { 50 | entityDAO.close(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/evaluator/Evaluation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.evaluator; 24 | 25 | import com.fasterxml.jackson.annotation.JsonProperty; 26 | import org.grouplens.samantha.modeler.metric.MetricResult; 27 | 28 | import java.util.List; 29 | 30 | public class Evaluation { 31 | @JsonProperty 32 | private final List metrics; 33 | @JsonProperty 34 | private final boolean pass; 35 | 36 | Evaluation(List metrics, boolean pass) { 37 | this.metrics = metrics; 38 | this.pass = pass; 39 | } 40 | 41 | Evaluation(List metrics) { 42 | this.metrics = metrics; 43 | boolean pass = true; 44 | for (MetricResult metric : metrics) { 45 | if (!metric.getPass()) { 46 | pass = false; 47 | } 48 | } 49 | this.pass = pass; 50 | } 51 | 52 | public boolean getPass() { 53 | return pass; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/svdfeature/SVDFeatureInstanceList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.svdfeature; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningData; 26 | import org.grouplens.samantha.modeler.common.LearningInstance; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | public class SVDFeatureInstanceList implements LearningData { 32 | private int iter = 0; 33 | private final List insList; 34 | 35 | public SVDFeatureInstanceList(List insList) { 36 | this.insList = insList; 37 | } 38 | 39 | public List getLearningInstance() { 40 | List instances = new ArrayList<>(1); 41 | if (iter >= insList.size()) { 42 | return instances; 43 | } 44 | instances.add(insList.get(iter++)); 45 | return instances; 46 | } 47 | 48 | public void startNewIteration() { 49 | iter = 0; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/router/BasicRouterConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.router; 24 | 25 | import org.grouplens.samantha.server.io.RequestContext; 26 | import play.Configuration; 27 | import play.inject.Injector; 28 | 29 | public class BasicRouterConfig implements RouterConfig { 30 | private final String recommenderKey; 31 | private final String predictorKey; 32 | 33 | private BasicRouterConfig(String recommenderKey, String predictorKey) { 34 | this.recommenderKey = recommenderKey; 35 | this.predictorKey = predictorKey; 36 | } 37 | 38 | public static RouterConfig getRouterConfig(Configuration routerConfig, 39 | Injector injector) { 40 | return new BasicRouterConfig(routerConfig.getString("recommenderKey"), 41 | routerConfig.getString("predictorKey")); 42 | } 43 | 44 | public Router getRouter(RequestContext requestContext) { 45 | return new BasicRouter(recommenderKey, predictorKey); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/solver/ExactGreedyConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.solver; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningMethod; 26 | import org.grouplens.samantha.modeler.tree.ExactGreedy; 27 | import org.grouplens.samantha.server.io.RequestContext; 28 | import play.Configuration; 29 | import play.inject.Injector; 30 | 31 | public class ExactGreedyConfig implements LearningMethodConfig { 32 | private ExactGreedyConfig() {} 33 | 34 | public static LearningMethod getLearningMethod(Configuration methodConfig, 35 | Injector injector, 36 | RequestContext requestContext) { 37 | int minNodeSplit = 50; 38 | if (methodConfig.asMap().containsKey("minNodeSplit")) { 39 | minNodeSplit = methodConfig.getInt("minNodeSplit"); 40 | } 41 | int maxTreeDepth = methodConfig.getInt("maxTreeDepth"); 42 | return new ExactGreedy(minNodeSplit, maxTreeDepth); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/instance/StandardListLearningData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.instance; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningData; 26 | import org.grouplens.samantha.modeler.common.LearningInstance; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | public class StandardListLearningData implements LearningData { 32 | private final List instances; 33 | private int idx = 0; 34 | 35 | //TODO: support grouping learning instance according to group info. 36 | public StandardListLearningData(List instances) { 37 | this.instances = instances; 38 | } 39 | 40 | public List getLearningInstance() { 41 | List curList = new ArrayList<>(1); 42 | if (idx < instances.size()) { 43 | curList.add(instances.get(idx++)); 44 | } 45 | return curList; 46 | } 47 | 48 | public void startNewIteration() { 49 | idx = 0; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/dao/ItemIDListDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.dao; 24 | 25 | import com.fasterxml.jackson.databind.node.ArrayNode; 26 | import com.fasterxml.jackson.databind.node.ObjectNode; 27 | import play.libs.Json; 28 | 29 | public class ItemIDListDAO implements EntityDAO { 30 | private int iter = 0; 31 | private final ArrayNode itemList; 32 | private final String attrName; 33 | 34 | public ItemIDListDAO(ArrayNode itemList, String attrName) { 35 | this.itemList = itemList; 36 | this.attrName = attrName; 37 | } 38 | 39 | public boolean hasNextEntity() { 40 | if (iter >= itemList.size()) { 41 | return false; 42 | } else { 43 | return true; 44 | } 45 | } 46 | 47 | public ObjectNode getNextEntity() { 48 | ObjectNode obj = Json.newObject(); 49 | obj.set(attrName, itemList.get(iter++)); 50 | return obj; 51 | } 52 | 53 | public void restart() { 54 | iter = 0; 55 | } 56 | 57 | public void close() {} 58 | } 59 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/featurizer/Featurizer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.featurizer; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import org.grouplens.samantha.modeler.common.LearningInstance; 27 | 28 | //TODO: warn or error if label is not present when update is true 29 | /** 30 | * The interface representing the process of transforming a raw data point in JSON to be a numerical {@link LearningInstance}. 31 | */ 32 | public interface Featurizer { 33 | /** 34 | * Featurize the raw data point/entity in JSON format to be a {@link LearningInstance}, typically by calling a series 35 | * of {@link FeatureExtractor}s. 36 | * 37 | * @param entity The JSON format representation of the raw data point. 38 | * @param update whether update the model (index space etc.). In training a model, this should be true, while in 39 | * predicting, this should be false. 40 | * @return The numerical learning instance representation of the data point. 41 | */ 42 | LearningInstance featurize(JsonNode entity, boolean update); 43 | } 44 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/dao/JsonDirDAOConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.dao; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import org.grouplens.samantha.modeler.dao.EntityDAO; 27 | import org.grouplens.samantha.modeler.dao.JsonDirDAO; 28 | import org.grouplens.samantha.server.common.JsonHelpers; 29 | import org.grouplens.samantha.server.io.RequestContext; 30 | import play.Configuration; 31 | import play.inject.Injector; 32 | 33 | public class JsonDirDAOConfig implements EntityDAOConfig { 34 | final private String dirPathKey; 35 | 36 | private JsonDirDAOConfig(String dirPathKey) { 37 | this.dirPathKey = dirPathKey; 38 | } 39 | 40 | public static EntityDAOConfig getEntityDAOConfig(Configuration daoConfig, 41 | Injector injector) { 42 | return new JsonDirDAOConfig(daoConfig.getString("dirPathKey")); 43 | } 44 | 45 | public EntityDAO getEntityDAO(RequestContext requestContext, JsonNode daoConfig) { 46 | return new JsonDirDAO(JsonHelpers.getRequiredString(daoConfig, dirPathKey)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/indexer/LoggerBasedIndexer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.indexer; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import org.grouplens.samantha.server.config.SamanthaConfigService; 27 | import org.grouplens.samantha.server.io.RequestContext; 28 | import play.Configuration; 29 | import play.Logger; 30 | import play.inject.Injector; 31 | 32 | public class LoggerBasedIndexer extends AbstractIndexer { 33 | 34 | public LoggerBasedIndexer(Configuration config, SamanthaConfigService configService, 35 | String daoConfigKey, Configuration daoConfigs, Injector injector, 36 | int batchSize, RequestContext requestContext) { 37 | super(config, configService, daoConfigs, daoConfigKey, batchSize, requestContext, injector); 38 | } 39 | 40 | public void index(JsonNode documents, RequestContext requestContext) { 41 | Logger.info(documents.toString()); 42 | } 43 | 44 | public void index(RequestContext requestContext) { 45 | Logger.info(requestContext.getRequestBody().toString()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/objective/NDCGLossConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.objective; 24 | 25 | import org.grouplens.samantha.modeler.ranking.NDCGLoss; 26 | import org.grouplens.samantha.modeler.solver.ObjectiveFunction; 27 | import org.grouplens.samantha.server.io.RequestContext; 28 | import org.grouplens.samantha.server.ranker.RankerUtilities; 29 | import play.Configuration; 30 | import play.inject.Injector; 31 | 32 | public class NDCGLossConfig { 33 | static public ObjectiveFunction getObjectiveFunction(Configuration objectiveConfig, 34 | Injector injector, 35 | RequestContext requestContext) { 36 | double sigma = 1.0; 37 | int N = RankerUtilities.defaultPageSize; 38 | if (objectiveConfig.asMap().containsKey("sigma")) { 39 | sigma = objectiveConfig.getDouble("sigma"); 40 | } 41 | if (objectiveConfig.asMap().containsKey("N")) { 42 | N = objectiveConfig.getInt("N"); 43 | } 44 | return new NDCGLoss(N, sigma); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/dao/JsonFileDAOConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.dao; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import org.grouplens.samantha.modeler.dao.EntityDAO; 27 | import org.grouplens.samantha.modeler.dao.JsonFileDAO; 28 | import org.grouplens.samantha.server.common.JsonHelpers; 29 | import org.grouplens.samantha.server.io.RequestContext; 30 | import play.Configuration; 31 | import play.inject.Injector; 32 | 33 | public class JsonFileDAOConfig implements EntityDAOConfig { 34 | final private String filePathKey; 35 | 36 | private JsonFileDAOConfig(String filePathKey) { 37 | this.filePathKey = filePathKey; 38 | } 39 | 40 | public static EntityDAOConfig getEntityDAOConfig(Configuration daoConfig, 41 | Injector injector) { 42 | return new JsonFileDAOConfig(daoConfig.getString("filePathKey")); 43 | } 44 | 45 | public EntityDAO getEntityDAO(RequestContext requestContext, JsonNode daoConfig) { 46 | return new JsonFileDAO(JsonHelpers.getRequiredString(daoConfig, filePathKey)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /tools/tensorflow/src/models/sampled_bpr_model.py: -------------------------------------------------------------------------------- 1 | 2 | import tensorflow as tf 3 | 4 | from src.models.prediction_model import SigmoidPredictionModel 5 | 6 | 7 | class SampledBPRModel(SigmoidPredictionModel): 8 | 9 | def __init__(self, config=None): 10 | super(SampledBPRModel, self).__init__(config=config) 11 | 12 | def get_target_loss(self, used_model, labels, indices, user_model, 13 | paras, target, config, mode, context): 14 | target_config = self._config[target] 15 | mask = tf.gather_nd(labels, indices) > 0 16 | indices = tf.boolean_mask(indices, mask) 17 | used_labels = tf.gather_nd(labels, indices) 18 | used_model = tf.boolean_mask(used_model, mask) 19 | vocab_size = target_config['vocab_size'] 20 | if 'num_sampled' in target_config: 21 | num_sampled = target_config['num_sampled'] 22 | else: 23 | num_sampled = vocab_size 24 | if num_sampled >= vocab_size - 1: 25 | num_ids = vocab_size 26 | uniq_ids = tf.range(vocab_size) 27 | else: 28 | sampled_ids = tf.random_uniform([num_sampled], 29 | dtype=tf.int32, maxval=vocab_size - 1) 30 | all_ids = tf.concat([sampled_ids, used_labels], axis=0) 31 | uniq_ids, idx = tf.unique(all_ids) 32 | num_ids = tf.shape(uniq_ids)[0] 33 | tiled_uniqs = tf.tile( 34 | tf.expand_dims(uniq_ids, axis=0), 35 | [tf.shape(used_labels)[0], 1]) 36 | tiled_labels = tf.tile( 37 | tf.expand_dims(used_labels, axis=1), 38 | [1, num_ids]) 39 | tiled_model = tf.tile( 40 | tf.expand_dims(used_model, axis=1), 41 | [1, num_ids, 1]) 42 | weights = tf.gather(paras['weights'], tiled_labels) - tf.gather(paras['weights'], tiled_uniqs) 43 | biases = tf.gather(paras['biases'], tiled_labels) - tf.gather(paras['biases'], tiled_uniqs) 44 | logits = tf.reduce_sum(tiled_model * weights, axis=2) + biases 45 | loss_mask = tf.not_equal(tiled_labels, tiled_uniqs) 46 | losses = tf.nn.sigmoid_cross_entropy_with_logits(labels=tf.ones_like(logits), logits=logits) 47 | losses = tf.boolean_mask(losses, loss_mask) 48 | loss = tf.reduce_sum(losses) 49 | return tf.size(losses), loss, [] 50 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/dao/JsonFileListDAOConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.dao; 24 | 25 | import com.fasterxml.jackson.databind.JsonNode; 26 | import org.grouplens.samantha.modeler.dao.EntityDAO; 27 | import org.grouplens.samantha.modeler.dao.JsonFileListDAO; 28 | import org.grouplens.samantha.server.common.JsonHelpers; 29 | import org.grouplens.samantha.server.io.RequestContext; 30 | import play.Configuration; 31 | import play.inject.Injector; 32 | 33 | public class JsonFileListDAOConfig implements EntityDAOConfig { 34 | final private String filesKey; 35 | 36 | private JsonFileListDAOConfig(String filesKey) { 37 | this.filesKey = filesKey; 38 | } 39 | 40 | public static EntityDAOConfig getEntityDAOConfig(Configuration daoConfig, 41 | Injector injector) { 42 | return new JsonFileListDAOConfig(daoConfig.getString("filesKey")); 43 | } 44 | 45 | public EntityDAO getEntityDAO(RequestContext requestContext, JsonNode daoConfig) { 46 | return new JsonFileListDAO(JsonHelpers.getRequiredStringList(daoConfig, filesKey)); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/ranking/RankingUtilities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.ranking; 24 | 25 | import com.google.common.collect.Ordering; 26 | import org.grouplens.samantha.modeler.solver.StochasticOracle; 27 | import org.grouplens.samantha.modeler.tree.SortingUtilities; 28 | 29 | public class RankingUtilities { 30 | private RankingUtilities() {} 31 | 32 | static public Ordering stochasticOracleOrdering() { 33 | return new Ordering() { 34 | @Override 35 | public int compare(StochasticOracle left, StochasticOracle right) { 36 | return SortingUtilities.compareValues(left.getModelOutput(), right.getModelOutput()); 37 | } 38 | }; 39 | } 40 | 41 | static public Ordering stochasticOracleLabelOrdering() { 42 | return new Ordering() { 43 | @Override 44 | public int compare(StochasticOracle left, StochasticOracle right) { 45 | return SortingUtilities.compareValues(left.getLabel(), right.getLabel()); 46 | } 47 | }; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/server/config/EngineConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.server.config; 24 | 25 | import org.grouplens.samantha.server.evaluator.EvaluatorConfig; 26 | import org.grouplens.samantha.server.indexer.IndexerConfig; 27 | import org.grouplens.samantha.server.predictor.PredictorConfig; 28 | import org.grouplens.samantha.server.ranker.RankerConfig; 29 | import org.grouplens.samantha.server.recommender.RecommenderConfig; 30 | import org.grouplens.samantha.server.retriever.RetrieverConfig; 31 | import org.grouplens.samantha.server.router.RouterConfig; 32 | import org.grouplens.samantha.server.scheduler.SchedulerConfig; 33 | 34 | import java.util.Map; 35 | 36 | interface EngineConfig { 37 | Map getIndexerConfigs(); 38 | Map getRetrieverConfigs(); 39 | Map getPredictorConfigs(); 40 | Map getRankerConfigs(); 41 | Map getEvaluatorConfigs(); 42 | Map getRecommenderConfigs(); 43 | Map getSchedulerConfigs(); 44 | RouterConfig getRouterConfig(); 45 | } 46 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/solver/SGDRunnable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.solver; 24 | 25 | import org.grouplens.samantha.modeler.common.LearningData; 26 | import org.grouplens.samantha.modeler.model.LearningModel; 27 | 28 | public class SGDRunnable implements ObjectiveRunnable { 29 | private final LearningModel learningModel; 30 | private final LearningData learningData; 31 | private final double l2coef; 32 | private final double lr; 33 | private double objVal = 0.0; 34 | 35 | SGDRunnable(LearningModel learningModel, LearningData learningData, double l2coef, double lr) { 36 | this.learningData = learningData; 37 | this.learningModel = learningModel; 38 | this.l2coef = l2coef; 39 | this.lr = lr; 40 | } 41 | 42 | public void run() { 43 | L2Regularizer l2term = new L2Regularizer(); 44 | ObjectiveFunction objFunc = learningModel.getObjectiveFunction(); 45 | objVal += SolverUtilities.stochasticGradientDescentUpdate(learningModel, objFunc, 46 | learningData, l2term, l2coef, lr); 47 | } 48 | 49 | public double getObjVal() { 50 | return objVal; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /server/app/org/grouplens/samantha/modeler/dao/JsonDirDAO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) [2016-2018] [University of Minnesota] 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy 5 | * of this software and associated documentation files (the "Software"), to deal 6 | * in the Software without restriction, including without limitation the rights 7 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | * copies of the Software, and to permit persons to whom the Software is 9 | * furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in all 12 | * copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | * SOFTWARE. 21 | */ 22 | 23 | package org.grouplens.samantha.modeler.dao; 24 | 25 | import com.fasterxml.jackson.databind.node.ObjectNode; 26 | import org.apache.commons.io.FileUtils; 27 | 28 | import java.io.File; 29 | import java.util.ArrayList; 30 | import java.util.Collection; 31 | import java.util.List; 32 | 33 | public class JsonDirDAO implements EntityDAO { 34 | private final EntityDAO entityDAO; 35 | 36 | public JsonDirDAO(String dirPath) { 37 | Collection fileList = FileUtils.listFiles(new File(dirPath), null, true); 38 | List fileNames = new ArrayList<>(fileList.size()); 39 | for (File file : fileList) { 40 | fileNames.add(file.getAbsolutePath()); 41 | } 42 | this.entityDAO = new JsonFileListDAO(fileNames); 43 | } 44 | 45 | public boolean hasNextEntity() { 46 | return entityDAO.hasNextEntity(); 47 | } 48 | 49 | public ObjectNode getNextEntity() { 50 | return entityDAO.getNextEntity(); 51 | } 52 | 53 | public void restart() { 54 | entityDAO.restart(); 55 | } 56 | 57 | public void close() { 58 | entityDAO.close(); 59 | } 60 | } 61 | --------------------------------------------------------------------------------