├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── docs └── api_docs │ └── python │ ├── recsim_ng.md │ └── recsim_ng │ ├── _redirects.yaml │ ├── _toc.yaml │ ├── all_symbols.md │ ├── api_report.pb │ ├── applications.md │ ├── applications │ ├── cav_synthetic_model.md │ ├── cav_synthetic_model │ │ ├── corpus.md │ │ ├── corpus │ │ │ └── SoftAttributeCorpus.md │ │ ├── user.md │ │ └── user │ │ │ ├── ConceptActivationVectorUser.md │ │ │ └── Constructor.md │ ├── ecosystem_simulation.md │ ├── ecosystem_simulation │ │ ├── corpus.md │ │ ├── corpus │ │ │ └── ViableCorpus.md │ │ ├── ecosystem_simulation.md │ │ ├── ecosystem_simulation │ │ │ └── run_simulation.md │ │ ├── metrics.md │ │ ├── metrics │ │ │ └── UtilityAsRewardMetrics.md │ │ ├── recommender.md │ │ ├── recommender │ │ │ └── MyopicRecommender.md │ │ ├── simulation_config.md │ │ ├── simulation_config │ │ │ └── create_viable_provider_simulation_network.md │ │ ├── user.md │ │ └── user │ │ │ ├── ClusteredNormalUser.md │ │ │ ├── ClusteredNormalUserCoreDispersion.md │ │ │ └── init_random_provider_clusters.md │ ├── latent_variable_model_learning.md │ ├── latent_variable_model_learning │ │ ├── recommender.md │ │ ├── recommender │ │ │ └── SimpleNormalRecommender.md │ │ ├── simulation_config.md │ │ ├── simulation_config │ │ │ └── create_latent_variable_model_network.md │ │ ├── user.md │ │ └── user │ │ │ └── ModelLearningDemoUser.md │ ├── recsys_partially_observable_rl.md │ └── recsys_partially_observable_rl │ │ ├── corpus.md │ │ ├── corpus │ │ ├── CorpusWithTopicAndQuality.md │ │ └── StaticCorpus.md │ │ ├── interest_evolution_simulation.md │ │ ├── interest_evolution_simulation │ │ ├── distributed_train_step.md │ │ ├── make_runtime.md │ │ ├── make_train_step.md │ │ ├── reset_optimizer.md │ │ └── run_simulation.md │ │ ├── metrics.md │ │ ├── metrics │ │ └── ConsumedTimeAsRewardMetrics.md │ │ ├── recommender.md │ │ ├── recommender │ │ ├── CollabFilteringModel.md │ │ └── CollabFilteringRecommender.md │ │ ├── simulation_config.md │ │ ├── simulation_config │ │ └── create_interest_evolution_simulation_network.md │ │ ├── user.md │ │ └── user │ │ ├── InterestEvolutionUser.md │ │ └── tensor_space.md │ ├── core.md │ ├── core │ ├── network.md │ ├── network │ │ ├── Network.md │ │ ├── NetworkValue.md │ │ ├── find_field.md │ │ └── find_unique_field.md │ ├── value.md │ ├── value │ │ ├── Config.md │ │ ├── FieldSpec.md │ │ └── Value.md │ ├── variable.md │ └── variable │ │ ├── Dependency.md │ │ ├── ValueDef.md │ │ ├── Variable.md │ │ └── value.md │ ├── entities.md │ ├── entities │ ├── bandits.md │ ├── bandits │ │ ├── algorithm.md │ │ ├── algorithm │ │ │ └── BanditAlgorithm.md │ │ ├── context.md │ │ ├── context │ │ │ └── BanditContext.md │ │ ├── generator.md │ │ ├── generator │ │ │ └── BanditGenerator.md │ │ ├── metrics.md │ │ ├── metrics │ │ │ └── BanditMetrics.md │ │ ├── problem.md │ │ └── problem │ │ │ └── BanditProblem.md │ ├── choice_models.md │ ├── choice_models │ │ ├── affinities.md │ │ ├── affinities │ │ │ └── TargetPointSimilarity.md │ │ ├── selectors.md │ │ └── selectors │ │ │ ├── ChoiceModel.md │ │ │ ├── IteratedMultinomialLogitChoiceModel.md │ │ │ ├── MultinomialLogitChoiceModel.md │ │ │ └── get_chosen.md │ ├── recommendation.md │ ├── recommendation │ │ ├── corpus.md │ │ ├── corpus │ │ │ ├── Corpus.md │ │ │ └── CorpusConstructor.md │ │ ├── metrics.md │ │ ├── metrics │ │ │ ├── MetricsConstructor.md │ │ │ └── RecsMetricsBase.md │ │ ├── recommender.md │ │ ├── recommender │ │ │ ├── BaseRecommender.md │ │ │ └── RecommenderConstructor.md │ │ ├── user.md │ │ └── user │ │ │ ├── User.md │ │ │ └── UserConstructor.md │ ├── state_models.md │ └── state_models │ │ ├── dynamic.md │ │ ├── dynamic │ │ ├── ControlledLinearGaussianStateModel.md │ │ ├── ControlledLinearScaledGaussianStateModel.md │ │ ├── FiniteStateMarkovModel.md │ │ ├── LinearGaussianStateModel.md │ │ ├── LinearOpCtor.md │ │ ├── NoOPOrContinueStateModel.md │ │ ├── RNNCellStateModel.md │ │ ├── ResetOrContinueStateModel.md │ │ └── SwitchingDynamicsStateModel.md │ │ ├── estimation.md │ │ ├── estimation │ │ └── FiniteHistoryStateModel.md │ │ ├── state.md │ │ ├── state │ │ └── StateModel.md │ │ ├── static.md │ │ └── static │ │ ├── GMMVector.md │ │ ├── HierarchicalStaticTensor.md │ │ ├── StaticMixtureSameFamilyModel.md │ │ ├── StaticStateModel.md │ │ └── StaticTensor.md │ ├── lib.md │ ├── lib │ ├── data.md │ ├── data │ │ ├── DataSequence.md │ │ ├── OutputFunction.md │ │ ├── SlicedValue.md │ │ ├── StaticSlicedValue.md │ │ ├── TimeSteps.md │ │ ├── data_variable.md │ │ ├── remove_data_index.md │ │ └── replace_data_sequence.md │ ├── jax.md │ ├── jax │ │ ├── runtime.md │ │ └── runtime │ │ │ └── JAXRuntime.md │ ├── python.md │ ├── python │ │ ├── runtime.md │ │ └── runtime │ │ │ └── PythonRuntime.md │ ├── runtime.md │ ├── runtime │ │ └── Runtime.md │ ├── tensorflow.md │ └── tensorflow │ │ ├── data.md │ │ ├── data │ │ └── TFDataset.md │ │ ├── entity.md │ │ ├── entity │ │ ├── Entity.md │ │ ├── EntityMap.md │ │ ├── Story.md │ │ ├── TrainableVariables.md │ │ └── story_with_trainable_variables.md │ │ ├── field_spec.md │ │ ├── field_spec │ │ ├── DynamicFieldSpec.md │ │ ├── FieldSpec.md │ │ ├── Space.md │ │ └── TFInvariant.md │ │ ├── log_probability.md │ │ ├── log_probability │ │ ├── log_prob_accumulator_variable.md │ │ ├── log_prob_accumulator_variables.md │ │ ├── log_prob_variables_from_direct_output.md │ │ ├── log_prob_variables_from_observation.md │ │ ├── log_probability.md │ │ ├── log_probability_from_value_trajectory.md │ │ ├── replay_variables.md │ │ └── total_log_prob_accumulator_variable.md │ │ ├── runtime.md │ │ ├── runtime │ │ └── TFRuntime.md │ │ ├── util.md │ │ └── util │ │ ├── initialize_platform.md │ │ └── pickle_to_network_value_trajectory.md │ ├── stories.md │ └── stories │ ├── bandit_simulation.md │ ├── bandit_simulation │ ├── Config.md │ └── bandit_story.md │ ├── recommendation_simulation.md │ ├── recommendation_simulation │ ├── recs_story.md │ ├── recs_story_using_logged_slate_docs.md │ └── simplified_recs_story.md │ ├── static_recs_simulation.md │ └── static_recs_simulation │ └── static_recs_story.md ├── recsim_ng ├── __init__.py ├── applications │ ├── __init__.py │ ├── cav_synthetic_model │ │ ├── __init__.py │ │ ├── corpus.py │ │ ├── user.py │ │ └── user_test.py │ ├── demo.py │ ├── ecosystem_simulation │ │ ├── __init__.py │ │ ├── corpus.py │ │ ├── corpus_test.py │ │ ├── ecosystem_simulation.py │ │ ├── ecosystem_simulation_demo.py │ │ ├── ecosystem_simulation_test.py │ │ ├── metrics.py │ │ ├── metrics_test.py │ │ ├── recommender.py │ │ ├── recommender_test.py │ │ ├── simulation_config.py │ │ ├── trajectory.pickle │ │ ├── user.py │ │ └── user_test.py │ ├── latent_variable_model_learning │ │ ├── __init__.py │ │ ├── latent_variable_model_demo.py │ │ ├── latent_variable_model_test.py │ │ ├── recommender.py │ │ ├── recommender_test.py │ │ ├── simulation_config.py │ │ ├── trajectory.pickle │ │ ├── user.py │ │ └── user_test.py │ └── recsys_partially_observable_rl │ │ ├── __init__.py │ │ ├── corpus.py │ │ ├── corpus_test.py │ │ ├── interest_evolution_simulation.py │ │ ├── interest_evolution_simulation_demo.py │ │ ├── interest_evolution_simulation_test.py │ │ ├── metrics.py │ │ ├── metrics_test.py │ │ ├── recommender.py │ │ ├── recommender_test.py │ │ ├── simulation_config.py │ │ ├── trajectory.pickle │ │ ├── user.py │ │ └── user_test.py ├── colab │ ├── RecSim_NG_Basics.ipynb │ └── RecSim_NG_Dealing_With_Uncertainty.ipynb ├── core │ ├── __init__.py │ ├── network.py │ ├── value.py │ ├── value_test.py │ └── variable.py ├── entities │ ├── __init__.py │ ├── bandits │ │ ├── __init__.py │ │ ├── algorithm.py │ │ ├── context.py │ │ ├── generator.py │ │ ├── metrics.py │ │ └── problem.py │ ├── choice_models │ │ ├── __init__.py │ │ ├── affinities.py │ │ ├── affinities_test.py │ │ ├── selectors.py │ │ └── selectors_test.py │ ├── recommendation │ │ ├── __init__.py │ │ ├── corpus.py │ │ ├── metrics.py │ │ ├── recommender.py │ │ └── user.py │ └── state_models │ │ ├── __init__.py │ │ ├── dynamic.py │ │ ├── dynamic_test.py │ │ ├── estimation.py │ │ ├── estimation_test.py │ │ ├── state.py │ │ ├── state_test.py │ │ ├── static.py │ │ ├── static_test.py │ │ └── test_util.py ├── lib │ ├── __init__.py │ ├── data.py │ ├── data_test.py │ ├── jax │ │ ├── __init__.py │ │ ├── runtime.py │ │ └── runtime_test.py │ ├── python │ │ ├── __init__.py │ │ ├── runtime.py │ │ └── runtime_test.py │ ├── runtime.py │ └── tensorflow │ │ ├── __init__.py │ │ ├── data.py │ │ ├── data_test.py │ │ ├── entity.py │ │ ├── entity_test.py │ │ ├── field_spec.py │ │ ├── field_spec_test.py │ │ ├── log_probability.py │ │ ├── log_probability_test.py │ │ ├── runtime.py │ │ ├── runtime_test.py │ │ └── util.py └── stories │ ├── __init__.py │ ├── bandit_simulation.py │ ├── recommendation_simulation.py │ └── static_recs_simulation.py └── setup.py /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution, 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. 24 | 25 | ## Community Guidelines 26 | 27 | This project follows 28 | [Google's Open Source Community Guidelines](https://opensource.google.com/conduct/). 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng.md: -------------------------------------------------------------------------------- 1 | description: Module importing the RecSim NG package. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing the RecSim NG package. 20 | 21 | ## Modules 22 | 23 | [`applications`](./recsim_ng/applications.md) module 24 | 25 | [`core`](./recsim_ng/core.md) module: Module importing the core library. 26 | 27 | [`entities`](./recsim_ng/entities.md) module 28 | 29 | [`lib`](./recsim_ng/lib.md) module 30 | 31 | [`stories`](./recsim_ng/stories.md) module: Module importing stories various 32 | simulation. 33 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/_redirects.yaml: -------------------------------------------------------------------------------- 1 | redirects: 2 | - from: /recsim_ng/api_docs/python/recsim_ng/applications/ecosystem_simulation/user/Constructor 3 | to: /recsim_ng/api_docs/python/recsim_ng/applications/cav_synthetic_model/user/Constructor 4 | - from: /recsim_ng/api_docs/python/recsim_ng/applications/latent_variable_model_learning/user/Constructor 5 | to: /recsim_ng/api_docs/python/recsim_ng/applications/cav_synthetic_model/user/Constructor 6 | - from: /recsim_ng/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/user/Constructor 7 | to: /recsim_ng/api_docs/python/recsim_ng/applications/cav_synthetic_model/user/Constructor 8 | - from: /recsim_ng/api_docs/python/recsim_ng/core/value/ValueSpec 9 | to: /recsim_ng/api_docs/python/recsim_ng/core/value/Value 10 | - from: /recsim_ng/api_docs/python/recsim_ng/entities/state_models/estimation/LinearOpCtor 11 | to: /recsim_ng/api_docs/python/recsim_ng/entities/state_models/dynamic/LinearOpCtor 12 | - from: /recsim_ng/api_docs/python/recsim_ng/lib/jax/runtime/NetworkValue 13 | to: /recsim_ng/api_docs/python/recsim_ng/core/network/NetworkValue 14 | - from: /recsim_ng/api_docs/python/recsim_ng/lib/jax/runtime/NetworkValueTrajectory 15 | to: /recsim_ng/api_docs/python/recsim_ng/core/network/NetworkValue 16 | - from: /recsim_ng/api_docs/python/recsim_ng/lib/python/runtime/NetworkValue 17 | to: /recsim_ng/api_docs/python/recsim_ng/core/network/NetworkValue 18 | - from: /recsim_ng/api_docs/python/recsim_ng/lib/runtime/NetworkValue 19 | to: /recsim_ng/api_docs/python/recsim_ng/core/network/NetworkValue 20 | - from: /recsim_ng/api_docs/python/recsim_ng/lib/tensorflow/log_probability/NetworkValue 21 | to: /recsim_ng/api_docs/python/recsim_ng/core/network/NetworkValue 22 | - from: /recsim_ng/api_docs/python/recsim_ng/lib/tensorflow/log_probability/NetworkValueTrajectory 23 | to: /recsim_ng/api_docs/python/recsim_ng/core/network/NetworkValue 24 | - from: /recsim_ng/api_docs/python/recsim_ng/lib/tensorflow/runtime/NetworkValue 25 | to: /recsim_ng/api_docs/python/recsim_ng/core/network/NetworkValue 26 | - from: /recsim_ng/api_docs/python/recsim_ng/lib/tensorflow/runtime/NetworkValueTrajectory 27 | to: /recsim_ng/api_docs/python/recsim_ng/core/network/NetworkValue 28 | - from: /recsim_ng/api_docs/python/recsim_ng/lib/tensorflow/util/NetworkValueTrajectory 29 | to: /recsim_ng/api_docs/python/recsim_ng/core/network/NetworkValue 30 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/api_report.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-research/recsim_ng/6df34cf87111da366923793ddba81a0b50e41242/docs/api_docs/python/recsim_ng/api_report.pb -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # Module: recsim_ng.applications 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | View 15 | source 16 | 17 | ## Modules 18 | 19 | [`cav_synthetic_model`](../recsim_ng/applications/cav_synthetic_model.md) 20 | module: Module importing the CAV synthetic model. 21 | 22 | [`ecosystem_simulation`](../recsim_ng/applications/ecosystem_simulation.md) 23 | module: Module importing the application modeling ecosytem. 24 | 25 | [`latent_variable_model_learning`](../recsim_ng/applications/latent_variable_model_learning.md) 26 | module: Module importing the application learning latent variable models. 27 | 28 | [`recsys_partially_observable_rl`](../recsim_ng/applications/recsys_partially_observable_rl.md) 29 | module: Module importing the application modeling a partially observable RL 30 | problem. 31 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/cav_synthetic_model.md: -------------------------------------------------------------------------------- 1 | description: Module importing the CAV synthetic model. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.cav_synthetic_model 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing the CAV synthetic model. 20 | 21 | ## Modules 22 | 23 | [`corpus`](../../recsim_ng/applications/cav_synthetic_model/corpus.md) module: 24 | Corpus entity for generating synthetic data with soft attributes. 25 | 26 | [`user`](../../recsim_ng/applications/cav_synthetic_model/user.md) module: User 27 | entity for generating synthetic data with soft attributes. 28 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/cav_synthetic_model/corpus.md: -------------------------------------------------------------------------------- 1 | description: Corpus entity for generating synthetic data with soft attributes. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.cav_synthetic_model.corpus 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Corpus entity for generating synthetic data with soft attributes. 20 | 21 | ## Classes 22 | 23 | [`class SoftAttributeCorpus`](../../../recsim_ng/applications/cav_synthetic_model/corpus/SoftAttributeCorpus.md): 24 | Defines a corpus with soft attribute documents. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/cav_synthetic_model/user.md: -------------------------------------------------------------------------------- 1 | description: User entity for generating synthetic data with soft attributes. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.cav_synthetic_model.user 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | User entity for generating synthetic data with soft attributes. 20 | 21 | ## Classes 22 | 23 | [`class ConceptActivationVectorUser`](../../../recsim_ng/applications/cav_synthetic_model/user/ConceptActivationVectorUser.md): 24 | Users that are clustered around creators that focus on certain topics. 25 | 26 | ## Type Aliases 27 | 28 | [`Constructor`](../../../recsim_ng/applications/cav_synthetic_model/user/Constructor.md) 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/cav_synthetic_model/user/Constructor.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.applications.cav_synthetic_model.user.Constructor 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/ecosystem_simulation.md: -------------------------------------------------------------------------------- 1 | description: Module importing the application modeling ecosytem. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.ecosystem_simulation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing the application modeling ecosytem. 20 | 21 | ## Modules 22 | 23 | [`corpus`](../../recsim_ng/applications/ecosystem_simulation/corpus.md) module: 24 | Corpus entity for welfare simulation. 25 | 26 | [`ecosystem_simulation`](../../recsim_ng/applications/ecosystem_simulation/ecosystem_simulation.md) 27 | module: For measuring social welfare of an ecosystem. 28 | 29 | [`metrics`](../../recsim_ng/applications/ecosystem_simulation/metrics.md) 30 | module: Definitions for recs metrics entities. 31 | 32 | [`recommender`](../../recsim_ng/applications/ecosystem_simulation/recommender.md) 33 | module: A recommender recommends the closest documents based on some affinity. 34 | 35 | [`simulation_config`](../../recsim_ng/applications/ecosystem_simulation/simulation_config.md) 36 | module: Configuration parameters for running ecosystem simulation. 37 | 38 | [`user`](../../recsim_ng/applications/ecosystem_simulation/user.md) module: User 39 | entity for welfare simulation. 40 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/ecosystem_simulation/corpus.md: -------------------------------------------------------------------------------- 1 | description: Corpus entity for welfare simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.ecosystem_simulation.corpus 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Corpus entity for welfare simulation. 20 | 21 | ## Classes 22 | 23 | [`class ViableCorpus`](../../../recsim_ng/applications/ecosystem_simulation/corpus/ViableCorpus.md): 24 | Defines a corpus with state transition simulating viable content providers. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/ecosystem_simulation/ecosystem_simulation.md: -------------------------------------------------------------------------------- 1 | description: For measuring social welfare of an ecosystem. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.ecosystem_simulation.ecosystem_simulation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | For measuring social welfare of an ecosystem. 20 | 21 | ## Functions 22 | 23 | [`run_simulation(...)`](../../../recsim_ng/applications/ecosystem_simulation/ecosystem_simulation/run_simulation.md): 24 | Runs ecosystem simulation multiple times and measures social welfare. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/ecosystem_simulation/metrics.md: -------------------------------------------------------------------------------- 1 | description: Definitions for recs metrics entities. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.ecosystem_simulation.metrics 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Definitions for recs metrics entities. 20 | 21 | ## Classes 22 | 23 | [`class UtilityAsRewardMetrics`](../../../recsim_ng/applications/ecosystem_simulation/metrics/UtilityAsRewardMetrics.md): 24 | A minimal implementation of recs metrics. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/ecosystem_simulation/recommender.md: -------------------------------------------------------------------------------- 1 | description: A recommender recommends the closest documents based on some 2 | affinity. 3 | 4 |
5 | 6 | 7 |
8 | 9 | # Module: recsim_ng.applications.ecosystem_simulation.recommender 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | A recommender recommends the closest documents based on some affinity. 21 | 22 | ## Classes 23 | 24 | [`class MyopicRecommender`](../../../recsim_ng/applications/ecosystem_simulation/recommender/MyopicRecommender.md): 25 | A recommender recommends the closest documents based on some affinity. 26 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/ecosystem_simulation/simulation_config.md: -------------------------------------------------------------------------------- 1 | description: Configuration parameters for running ecosystem simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.ecosystem_simulation.simulation_config 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Configuration parameters for running ecosystem simulation. 20 | 21 | ## Functions 22 | 23 | [`create_viable_provider_simulation_network(...)`](../../../recsim_ng/applications/ecosystem_simulation/simulation_config/create_viable_provider_simulation_network.md): 24 | Returns a network for the ecosystem simulation with viable corpus. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/ecosystem_simulation/simulation_config/create_viable_provider_simulation_network.md: -------------------------------------------------------------------------------- 1 | description: Returns a network for the ecosystem simulation with viable corpus. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.applications.ecosystem_simulation.simulation_config.create_viable_provider_simulation_network 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Returns a network for the ecosystem simulation with viable corpus. 20 | 21 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/ecosystem_simulation/user.md: -------------------------------------------------------------------------------- 1 | description: User entity for welfare simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.ecosystem_simulation.user 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | User entity for welfare simulation. 20 | 21 | ## Classes 22 | 23 | [`class ClusteredNormalUser`](../../../recsim_ng/applications/ecosystem_simulation/user/ClusteredNormalUser.md): 24 | Users that are clustered around providers that focus on certain topics. 25 | 26 | [`class ClusteredNormalUserCoreDispersion`](../../../recsim_ng/applications/ecosystem_simulation/user/ClusteredNormalUserCoreDispersion.md): 27 | A model where interest variance decreases with distance from origin. 28 | 29 | ## Functions 30 | 31 | [`init_random_provider_clusters(...)`](../../../recsim_ng/applications/ecosystem_simulation/user/init_random_provider_clusters.md): 32 | Initializes a set of providers over different topics for mixtures. 33 | 34 | ## Type Aliases 35 | 36 | [`Constructor`](../../../recsim_ng/applications/cav_synthetic_model/user/Constructor.md) 37 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/ecosystem_simulation/user/init_random_provider_clusters.md: -------------------------------------------------------------------------------- 1 | description: Initializes a set of providers over different topics for mixtures. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.applications.ecosystem_simulation.user.init_random_provider_clusters 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Initializes a set of providers over different topics for mixtures. 20 | 21 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/latent_variable_model_learning.md: -------------------------------------------------------------------------------- 1 | description: Module importing the application learning latent variable models. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.latent_variable_model_learning 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing the application learning latent variable models. 20 | 21 | ## Modules 22 | 23 | [`recommender`](../../recsim_ng/applications/latent_variable_model_learning/recommender.md) 24 | module: A recommender recommends normally distributed documents. 25 | 26 | [`simulation_config`](../../recsim_ng/applications/latent_variable_model_learning/simulation_config.md) 27 | module: Configuration parameters for learning latent variable models. 28 | 29 | [`user`](../../recsim_ng/applications/latent_variable_model_learning/user.md) 30 | module: User entity for the simulation of learning latent variable models. 31 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/latent_variable_model_learning/recommender.md: -------------------------------------------------------------------------------- 1 | description: A recommender recommends normally distributed documents. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.latent_variable_model_learning.recommender 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | A recommender recommends normally distributed documents. 20 | 21 | ## Classes 22 | 23 | [`class SimpleNormalRecommender`](../../../recsim_ng/applications/latent_variable_model_learning/recommender/SimpleNormalRecommender.md): 24 | A recommender recommends normally distributed documents. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/latent_variable_model_learning/simulation_config.md: -------------------------------------------------------------------------------- 1 | description: Configuration parameters for learning latent variable models. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.latent_variable_model_learning.simulation_config 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Configuration parameters for learning latent variable models. 20 | 21 | ## Functions 22 | 23 | [`create_latent_variable_model_network(...)`](../../../recsim_ng/applications/latent_variable_model_learning/simulation_config/create_latent_variable_model_network.md): 24 | Returns a network for learning latent variable models. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/latent_variable_model_learning/simulation_config/create_latent_variable_model_network.md: -------------------------------------------------------------------------------- 1 | description: Returns a network for learning latent variable models. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.applications.latent_variable_model_learning.simulation_config.create_latent_variable_model_network 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Returns a network for learning latent variable models. 20 | 21 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/latent_variable_model_learning/user.md: -------------------------------------------------------------------------------- 1 | description: User entity for the simulation of learning latent variable models. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.latent_variable_model_learning.user 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | User entity for the simulation of learning latent variable models. 20 | 21 | ## Classes 22 | 23 | [`class ModelLearningDemoUser`](../../../recsim_ng/applications/latent_variable_model_learning/user/ModelLearningDemoUser.md): 24 | User model with embedding target intent and satisfaction. 25 | 26 | ## Type Aliases 27 | 28 | [`Constructor`](../../../recsim_ng/applications/cav_synthetic_model/user/Constructor.md) 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl.md: -------------------------------------------------------------------------------- 1 | description: Module importing the application modeling a partially observable RL 2 | problem. 3 | 4 |
5 | 6 | 7 |
8 | 9 | # Module: recsim_ng.applications.recsys_partially_observable_rl 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | Module importing the application modeling a partially observable RL problem. 21 | 22 | ## Modules 23 | 24 | [`corpus`](../../recsim_ng/applications/recsys_partially_observable_rl/corpus.md) 25 | module: Corpus entity for partially observable RL simulation. 26 | 27 | [`interest_evolution_simulation`](../../recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation.md) 28 | module: WIP: For testing differentiable interest evolution networks. 29 | 30 | [`metrics`](../../recsim_ng/applications/recsys_partially_observable_rl/metrics.md) 31 | module: Definitions for recs metrics entities. 32 | 33 | [`recommender`](../../recsim_ng/applications/recsys_partially_observable_rl/recommender.md) 34 | module: Recommendation agents. 35 | 36 | [`simulation_config`](../../recsim_ng/applications/recsys_partially_observable_rl/simulation_config.md) 37 | module: Configuration parameters for running recs simulation. 38 | 39 | [`user`](../../recsim_ng/applications/recsys_partially_observable_rl/user.md) 40 | module: User entity for long-term interests evolution simulation. 41 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/corpus.md: -------------------------------------------------------------------------------- 1 | description: Corpus entity for partially observable RL simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.recsys_partially_observable_rl.corpus 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Corpus entity for partially observable RL simulation. 20 | 21 | ## Classes 22 | 23 | [`class CorpusWithTopicAndQuality`](../../../recsim_ng/applications/recsys_partially_observable_rl/corpus/CorpusWithTopicAndQuality.md): 24 | Defines a corpus with static topic and quality distributions. 25 | 26 | [`class StaticCorpus`](../../../recsim_ng/applications/recsys_partially_observable_rl/corpus/StaticCorpus.md): 27 | Defines a static corpus with state passed from outside. 28 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation.md: -------------------------------------------------------------------------------- 1 | description: WIP: For testing differentiable interest evolution networks. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.recsys_partially_observable_rl.interest_evolution_simulation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | WIP: For testing differentiable interest evolution networks. 20 | 21 | ## Functions 22 | 23 | [`distributed_train_step(...)`](../../../recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/distributed_train_step.md): 24 | Extracts gradient update and training variables for updating network. 25 | 26 | [`make_runtime(...)`](../../../recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/make_runtime.md): 27 | Makes simulation + policy log-prob runtime. 28 | 29 | [`make_train_step(...)`](../../../recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/make_train_step.md): 30 | Wraps a traced training step function for use in learning loops. 31 | 32 | [`reset_optimizer(...)`](../../../recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/reset_optimizer.md) 33 | 34 | [`run_simulation(...)`](../../../recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/run_simulation.md): 35 | Runs simulation over multiple horizon steps while learning policy vars. 36 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/distributed_train_step.md: -------------------------------------------------------------------------------- 1 | description: Extracts gradient update and training variables for updating 2 | network. 3 | 4 |
5 | 6 | 7 |
8 | 9 | # recsim_ng.applications.recsys_partially_observable_rl.interest_evolution_simulation.distributed_train_step 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | Extracts gradient update and training variables for updating network. 21 | 22 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/make_runtime.md: -------------------------------------------------------------------------------- 1 | description: Makes simulation + policy log-prob runtime. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.applications.recsys_partially_observable_rl.interest_evolution_simulation.make_runtime 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Makes simulation + policy log-prob runtime. 20 | 21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/make_train_step.md: -------------------------------------------------------------------------------- 1 | description: Wraps a traced training step function for use in learning loops. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.applications.recsys_partially_observable_rl.interest_evolution_simulation.make_train_step 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Wraps a traced training step function for use in learning loops. 20 | 21 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/reset_optimizer.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.applications.recsys_partially_observable_rl.interest_evolution_simulation.reset_optimizer 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | View 15 | source 16 | 17 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation/run_simulation.md: -------------------------------------------------------------------------------- 1 | description: Runs simulation over multiple horizon steps while learning policy 2 | vars. 3 | 4 |
5 | 6 | 7 |
8 | 9 | # recsim_ng.applications.recsys_partially_observable_rl.interest_evolution_simulation.run_simulation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | Runs simulation over multiple horizon steps while learning policy vars. 21 | 22 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/metrics.md: -------------------------------------------------------------------------------- 1 | description: Definitions for recs metrics entities. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.recsys_partially_observable_rl.metrics 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Definitions for recs metrics entities. 20 | 21 | ## Classes 22 | 23 | [`class ConsumedTimeAsRewardMetrics`](../../../recsim_ng/applications/recsys_partially_observable_rl/metrics/ConsumedTimeAsRewardMetrics.md): 24 | A minimal implementation of recs metrics. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/recommender.md: -------------------------------------------------------------------------------- 1 | description: Recommendation agents. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.recsys_partially_observable_rl.recommender 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Recommendation agents. 20 | 21 | ## Classes 22 | 23 | [`class CollabFilteringModel`](../../../recsim_ng/applications/recsys_partially_observable_rl/recommender/CollabFilteringModel.md): 24 | A tf.keras model that returns score for each (user, document) pair. 25 | 26 | [`class CollabFilteringRecommender`](../../../recsim_ng/applications/recsys_partially_observable_rl/recommender/CollabFilteringRecommender.md): 27 | A collaborative filtering based recommender implementation. 28 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/simulation_config.md: -------------------------------------------------------------------------------- 1 | description: Configuration parameters for running recs simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.recsys_partially_observable_rl.simulation_config 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Configuration parameters for running recs simulation. 20 | 21 | ## Functions 22 | 23 | [`create_interest_evolution_simulation_network(...)`](../../../recsim_ng/applications/recsys_partially_observable_rl/simulation_config/create_interest_evolution_simulation_network.md): 24 | Returns a network for interests evolution simulation. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/simulation_config/create_interest_evolution_simulation_network.md: -------------------------------------------------------------------------------- 1 | description: Returns a network for interests evolution simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.applications.recsys_partially_observable_rl.simulation_config.create_interest_evolution_simulation_network 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Returns a network for interests evolution simulation. 20 | 21 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/user.md: -------------------------------------------------------------------------------- 1 | description: User entity for long-term interests evolution simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.applications.recsys_partially_observable_rl.user 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | User entity for long-term interests evolution simulation. 20 | 21 | ## Classes 22 | 23 | [`class InterestEvolutionUser`](../../../recsim_ng/applications/recsys_partially_observable_rl/user/InterestEvolutionUser.md): 24 | Dynamics of a user whose interests evolve over time. 25 | 26 | ## Functions 27 | 28 | [`tensor_space(...)`](../../../recsim_ng/applications/recsys_partially_observable_rl/user/tensor_space.md) 29 | 30 | ## Type Aliases 31 | 32 | [`Constructor`](../../../recsim_ng/applications/cav_synthetic_model/user/Constructor.md) 33 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/applications/recsys_partially_observable_rl/user/tensor_space.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.applications.recsys_partially_observable_rl.user.tensor_space 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | View 15 | source 16 | 17 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core.md: -------------------------------------------------------------------------------- 1 | description: Module importing the core library. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.core 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing the core library. 20 | 21 | ## Modules 22 | 23 | [`network`](../recsim_ng/core/network.md) module: Network of Variables. 24 | 25 | [`value`](../recsim_ng/core/value.md) module: Variable values. 26 | 27 | [`variable`](../recsim_ng/core/variable.md) module: Variables. 28 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/network.md: -------------------------------------------------------------------------------- 1 | description: Network of Variables. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.core.network 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Network of Variables. 20 | 21 | ## Classes 22 | 23 | [`class Network`](../../recsim_ng/core/network/Network.md): A collection of 24 | `Variable`s that may depend on each other. 25 | 26 | ## Functions 27 | 28 | [`find_field(...)`](../../recsim_ng/core/network/find_field.md): Looks up the 29 | value(s) of a given field name across a network. 30 | 31 | [`find_unique_field(...)`](../../recsim_ng/core/network/find_unique_field.md): 32 | Like `find_field`, but requires that `field_name` be unique. 33 | 34 | ## Type Aliases 35 | 36 | [`NetworkValue`](../../recsim_ng/core/network/NetworkValue.md) 37 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/network/NetworkValue.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.core.network.NetworkValue 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/network/find_field.md: -------------------------------------------------------------------------------- 1 | description: Looks up the value(s) of a given field name across a network. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.core.network.find_field 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Looks up the value(s) of a given field name across a network. 20 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 39 | 42 | 43 | 46 | 49 | 50 |
37 | `network_value` 38 | 40 | A `NetworkValue`; see `Network`. 41 |
44 | `field_name` 45 | 47 | The name of a `Value` field. 48 |
51 | 52 | 53 | 54 | 55 | 56 | 57 | 61 | 62 | 63 |
58 | A mapping, from each variable name in `network_value` whose `Value` has a 59 | field named `field_name`, to the value of that field. This could be empty. 60 |
64 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/network/find_unique_field.md: -------------------------------------------------------------------------------- 1 | description: Like find_field, but requires that field_name be unique. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.core.network.find_unique_field 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Like `find_field`, but requires that `field_name` be unique. 20 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 39 | 42 | 43 | 46 | 49 | 50 |
37 | `network_value` 38 | 40 | A `NetworkValue`; see `Network`. 41 |
44 | `field_name` 45 | 47 | The name of a `Value` field. 48 |
51 | 52 | 53 | 54 | 55 | 56 | 57 | 61 | 62 | 63 |
58 | A pair of (1) the `Variable` in `network_value` with a field named 59 | `field_name` and (2) the value of that field. 60 |
64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 74 | 78 | 79 |
72 | `ValueError` 73 | 75 | If there is not exactly one `Variable` in `network_value` that 76 | has a field named `field_name`. 77 |
80 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/value.md: -------------------------------------------------------------------------------- 1 | description: Variable values. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.core.value 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Variable values. 20 | 21 | A `Value` is a collection of named fields. It is implemented as an object with 22 | one attribute per field. The value of a field is often an `ed.RandomVariable`. 23 | 24 | Values are declared with a `ValueSpec` providing the name and specification of 25 | each field. `ValueSpec` is an alias for `Value`; it is by convention a `Value` 26 | whose field values are `FieldSpec` objects. 27 | 28 | ## Classes 29 | 30 | [`class FieldSpec`](../../recsim_ng/core/value/FieldSpec.md): The specification 31 | of one field in a `ValueSpec`. 32 | 33 | [`class Value`](../../recsim_ng/core/value/Value.md): A mapping from field name 34 | to `FieldValue`. 35 | 36 | [`class ValueSpec`](../../recsim_ng/core/value/Value.md): A mapping from field 37 | name to `FieldValue`. 38 | 39 | ## Type Aliases 40 | 41 | [`Config`](../../recsim_ng/core/value/Config.md) 42 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/value/Config.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.core.value.Config 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/variable.md: -------------------------------------------------------------------------------- 1 | description: Variables. 2 | 3 |
4 | 5 | 6 | 7 |
8 | 9 | # Module: recsim_ng.core.variable 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | Variables. 21 | 22 | Here is an example of a dynamic `Variable` whose `Value` has two fields, `n0` 23 | and `n1`, that hold the last two elements of the Fibonacci sequence. Its `Value` 24 | at a given step depends on its `Value` from the previous step. ``` def 25 | fib_init(): return Value(n0=0, n1=1) 26 | 27 | def fib_next(previous_value): return Value(n0=previous_value.get("n1"), 28 | n1=previous_value.get("n0") + previous_value.get("n1") 29 | 30 | fibonacci = Variable(name="fib", spec=ValueSpec(n0=..., n1=...)) 31 | fibonacci.initial_value = value(fib_init) fibonacci.value = value(fib_next, 32 | (fibonacci.previous,)) ``` 33 | 34 | ## Classes 35 | 36 | [`class Dependency`](../../recsim_ng/core/variable/Dependency.md): Represents a 37 | Dependency of one `Variable` on another (or itself). 38 | 39 | [`class ValueDef`](../../recsim_ng/core/variable/ValueDef.md): Defines a `Value` 40 | in terms of other `Value`s. 41 | 42 | [`class Variable`](../../recsim_ng/core/variable/Variable.md): Variables. 43 | 44 | ## Functions 45 | 46 | [`value(...)`](../../recsim_ng/core/variable/value.md): Convenience function for 47 | constructing a `ValueDef`. 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 58 | 61 | 62 |
56 | UNDEFINED 57 | 59 | Instance of recsim_ng.core.variable.ValueDef 60 |
63 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/variable/Dependency.md: -------------------------------------------------------------------------------- 1 | description: Represents a Dependency of one Variable on another (or itself). 2 | 3 |
4 | 5 | 6 | 7 | 8 |
9 | 10 | # recsim_ng.core.variable.Dependency 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | View 19 | source 20 | 21 | Represents a Dependency of one `Variable` on another (or itself). 22 | 23 | 28 | 29 | 30 | 31 | The current `Value` of a `Variable` has zero or more dependencies. There are two 32 | kinds of dependencies: * The current `Value` of some other `Variable`. * The 33 | previous `Value` of itself or some other `Variable`. The `on_current_value` 34 | boolean attribute disambiguates between these. 35 | 36 | The initial `Value` of a `Variable` can only have "current" dependencies. See 37 | `Variable` for more details. 38 | 39 | Note that if `var` is a `Variable` then `var.previous` is shorthand for 40 | `Dependency(variable_name=var.name, on_current_value=False)`. Finally, see the 41 | `value` function for another convenient way to form dependencies. 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 52 | 55 | 56 | 59 | 62 | 63 |
50 | `variable_name` 51 | 53 | Dataclass field 54 |
57 | `on_current_value` 58 | 60 | Dataclass field 61 |
64 | 65 | ## Methods 66 | 67 |

__eq__

68 | 69 | 74 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/variable/ValueDef.md: -------------------------------------------------------------------------------- 1 | description: Defines a Value in terms of other Values. 2 | 3 |
4 | 5 | 6 | 7 | 8 |
9 | 10 | # recsim_ng.core.variable.ValueDef 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | View 19 | source 20 | 21 | Defines a `Value` in terms of other `Value`s. 22 | 23 | 29 | 30 | 31 | 32 | See `value` for more information. 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 44 | 47 | 48 | 51 | 54 | 55 |
42 | `fn` 43 | 45 | Dataclass field 46 |
49 | `dependencies` 50 | 52 | Dataclass field 53 |
56 | 57 | ## Methods 58 | 59 |

__eq__

60 | 61 | 66 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/core/variable/value.md: -------------------------------------------------------------------------------- 1 | description: Convenience function for constructing a ValueDef. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.core.variable.value 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Convenience function for constructing a `ValueDef`. 20 | 21 | 27 | 28 | 29 | 30 | See example in the module docs. 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 45 | 46 | 49 | 56 | 57 |
39 | `fn` 40 | 42 | A function that takes `Value` arguments `(v_1, ..., v_k)` corresponding 43 | to the `dependencies` sequence `(d_1, ..., d_k)`. 44 |
47 | `dependencies` 48 | 50 | A sequence of dependencies corresponding to the arguments of 51 | `fn`. Each element must be either a `Dependency` object or a `Variable`. 52 | The latter option is a convenience shorthand for 53 | `Dependency(variable_name=name, on_current_value=True)` where `name` is 54 | the name of the `Variable`. 55 |
58 | 59 | 60 | 61 | 62 | 63 | 64 | 67 | 68 | 69 |
65 | A `ValueDef`. 66 |
70 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # Module: recsim_ng.entities 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | View 15 | source 16 | 17 | ## Modules 18 | 19 | [`bandits`](../recsim_ng/entities/bandits.md) module: Module importing entities 20 | for bandits. 21 | 22 | [`choice_models`](../recsim_ng/entities/choice_models.md) module: Module 23 | importing the choice model entities. 24 | 25 | [`recommendation`](../recsim_ng/entities/recommendation.md) module: Module 26 | importing entities for recs. 27 | 28 | [`state_models`](../recsim_ng/entities/state_models.md) module: Module importing 29 | the state model entities. 30 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/bandits.md: -------------------------------------------------------------------------------- 1 | description: Module importing entities for bandits. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.bandits 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing entities for bandits. 20 | 21 | ## Modules 22 | 23 | [`algorithm`](../../recsim_ng/entities/bandits/algorithm.md) module: Algorithm 24 | entity for bandit simulation. 25 | 26 | [`context`](../../recsim_ng/entities/bandits/context.md) module: Context entity 27 | for bandit simulation. 28 | 29 | [`generator`](../../recsim_ng/entities/bandits/generator.md) module: Generator 30 | entity for bandit simulation. 31 | 32 | [`metrics`](../../recsim_ng/entities/bandits/metrics.md) module: Metrics entity 33 | for bandit simulation. 34 | 35 | [`problem`](../../recsim_ng/entities/bandits/problem.md) module: Problem entity 36 | for bandit simulation. 37 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/bandits/algorithm.md: -------------------------------------------------------------------------------- 1 | description: Algorithm entity for bandit simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.bandits.algorithm 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Algorithm entity for bandit simulation. 20 | 21 | ## Classes 22 | 23 | [`class BanditAlgorithm`](../../../recsim_ng/entities/bandits/algorithm/BanditAlgorithm.md): 24 | An abstract algorithm entity responsible for pulling an arm. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/bandits/context.md: -------------------------------------------------------------------------------- 1 | description: Context entity for bandit simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.bandits.context 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Context entity for bandit simulation. 20 | 21 | ## Classes 22 | 23 | [`class BanditContext`](../../../recsim_ng/entities/bandits/context/BanditContext.md): 24 | A basic context entity generating contexts and other world states. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/bandits/generator.md: -------------------------------------------------------------------------------- 1 | description: Generator entity for bandit simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.bandits.generator 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Generator entity for bandit simulation. 20 | 21 | ## Classes 22 | 23 | [`class BanditGenerator`](../../../recsim_ng/entities/bandits/generator/BanditGenerator.md): 24 | An abstract generator entity responsible for parameters in the environment. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/bandits/metrics.md: -------------------------------------------------------------------------------- 1 | description: Metrics entity for bandit simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.bandits.metrics 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Metrics entity for bandit simulation. 20 | 21 | ## Classes 22 | 23 | [`class BanditMetrics`](../../../recsim_ng/entities/bandits/metrics/BanditMetrics.md): 24 | The base entity for bandit metrics. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/bandits/problem.md: -------------------------------------------------------------------------------- 1 | description: Problem entity for bandit simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.bandits.problem 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Problem entity for bandit simulation. 20 | 21 | ## Classes 22 | 23 | [`class BanditProblem`](../../../recsim_ng/entities/bandits/problem/BanditProblem.md): 24 | An abstract problem entity for randomizing and returning rewards. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/choice_models.md: -------------------------------------------------------------------------------- 1 | description: Module importing the choice model entities. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.choice_models 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing the choice model entities. 20 | 21 | ## Modules 22 | 23 | [`affinities`](../../recsim_ng/entities/choice_models/affinities.md) module: 24 | Classes that define a user's affinities over a slate of documents. 25 | 26 | [`selectors`](../../recsim_ng/entities/choice_models/selectors.md) module: 27 | Classes that define a user's choice behavior over a slate of documents. 28 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/choice_models/affinities.md: -------------------------------------------------------------------------------- 1 | description: Classes that define a user's affinities over a slate of documents. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.choice_models.affinities 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Classes that define a user's affinities over a slate of documents. 20 | 21 | ## Classes 22 | 23 | [`class TargetPointSimilarity`](../../../recsim_ng/entities/choice_models/affinities/TargetPointSimilarity.md): 24 | Utility model based on item similarity to a target item. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/choice_models/selectors.md: -------------------------------------------------------------------------------- 1 | description: Classes that define a user's choice behavior over a slate of 2 | documents. 3 | 4 |
5 | 6 | 7 |
8 | 9 | # Module: recsim_ng.entities.choice_models.selectors 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | Classes that define a user's choice behavior over a slate of documents. 21 | 22 | ## Classes 23 | 24 | [`class ChoiceModel`](../../../recsim_ng/entities/choice_models/selectors/ChoiceModel.md): 25 | Meta class for choice models. 26 | 27 | [`class IteratedMultinomialLogitChoiceModel`](../../../recsim_ng/entities/choice_models/selectors/IteratedMultinomialLogitChoiceModel.md): 28 | A multinomial logit choice model for multiple choices from a fixed slate. 29 | 30 | [`class MultinomialLogitChoiceModel`](../../../recsim_ng/entities/choice_models/selectors/MultinomialLogitChoiceModel.md): 31 | A multinomial logit choice model. 32 | 33 | ## Functions 34 | 35 | [`get_chosen(...)`](../../../recsim_ng/entities/choice_models/selectors/get_chosen.md): 36 | Gets the chosen features from a slate of document features. 37 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/choice_models/selectors/get_chosen.md: -------------------------------------------------------------------------------- 1 | description: Gets the chosen features from a slate of document features. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.entities.choice_models.selectors.get_chosen 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Gets the chosen features from a slate of document features. 20 | 21 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 44 | 45 | 48 | 51 | 52 | 55 | 58 | 59 | 62 | 65 | 66 |
39 | `features` 40 | 42 | A `Value` representing a batch of document slates. 43 |
46 | `choices` 47 | 49 | A tensor with shape [b1, ..., bk] containing a batch of choices. 50 |
53 | `batch_dims` 54 | 56 | An integer specifying the number of batch dimension k. 57 |
60 | `nochoice_value` 61 | 63 | the value representing the no-choice option. 64 |
67 | 68 | 69 | 70 | 71 | 72 | 73 | 76 | 77 | 78 |
74 | A `Value` containing a batch of the chosen document. 75 |
79 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/recommendation.md: -------------------------------------------------------------------------------- 1 | description: Module importing entities for recs. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.recommendation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing entities for recs. 20 | 21 | ## Modules 22 | 23 | [`corpus`](../../recsim_ng/entities/recommendation/corpus.md) module: Corpus 24 | entity for recommendation simulation. 25 | 26 | [`metrics`](../../recsim_ng/entities/recommendation/metrics.md) module: Metrics 27 | entity for recommendation simulation. 28 | 29 | [`recommender`](../../recsim_ng/entities/recommendation/recommender.md) module: 30 | Recommender entity for recommendation simulation. 31 | 32 | [`user`](../../recsim_ng/entities/recommendation/user.md) module: User entity 33 | for recommendation simulation. 34 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/recommendation/corpus.md: -------------------------------------------------------------------------------- 1 | description: Corpus entity for recommendation simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.recommendation.corpus 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Corpus entity for recommendation simulation. 20 | 21 | ## Classes 22 | 23 | [`class Corpus`](../../../recsim_ng/entities/recommendation/corpus/Corpus.md): 24 | An abstract corpus entity. 25 | 26 | ## Type Aliases 27 | 28 | [`CorpusConstructor`](../../../recsim_ng/entities/recommendation/corpus/CorpusConstructor.md) 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/recommendation/corpus/CorpusConstructor.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.entities.recommendation.corpus.CorpusConstructor 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/recommendation/metrics.md: -------------------------------------------------------------------------------- 1 | description: Metrics entity for recommendation simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.recommendation.metrics 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Metrics entity for recommendation simulation. 20 | 21 | ## Classes 22 | 23 | [`class RecsMetricsBase`](../../../recsim_ng/entities/recommendation/metrics/RecsMetricsBase.md): 24 | An abstract recommendation metrics entity. 25 | 26 | ## Type Aliases 27 | 28 | [`MetricsConstructor`](../../../recsim_ng/entities/recommendation/metrics/MetricsConstructor.md) 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/recommendation/metrics/MetricsConstructor.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.entities.recommendation.metrics.MetricsConstructor 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/recommendation/recommender.md: -------------------------------------------------------------------------------- 1 | description: Recommender entity for recommendation simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.recommendation.recommender 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Recommender entity for recommendation simulation. 20 | 21 | ## Classes 22 | 23 | [`class BaseRecommender`](../../../recsim_ng/entities/recommendation/recommender/BaseRecommender.md): 24 | An abstract recommender entity. 25 | 26 | ## Type Aliases 27 | 28 | [`RecommenderConstructor`](../../../recsim_ng/entities/recommendation/recommender/RecommenderConstructor.md) 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/recommendation/recommender/RecommenderConstructor.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.entities.recommendation.recommender.RecommenderConstructor 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/recommendation/user.md: -------------------------------------------------------------------------------- 1 | description: User entity for recommendation simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.recommendation.user 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | User entity for recommendation simulation. 20 | 21 | ## Classes 22 | 23 | [`class User`](../../../recsim_ng/entities/recommendation/user/User.md): An 24 | abstract user entity. 25 | 26 | ## Type Aliases 27 | 28 | [`UserConstructor`](../../../recsim_ng/entities/recommendation/user/UserConstructor.md) 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/recommendation/user/UserConstructor.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.entities.recommendation.user.UserConstructor 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/state_models.md: -------------------------------------------------------------------------------- 1 | description: Module importing the state model entities. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.state_models 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing the state model entities. 20 | 21 | ## Modules 22 | 23 | [`dynamic`](../../recsim_ng/entities/state_models/dynamic.md) module: State 24 | models of variables evolving over time as a function of inputs. 25 | 26 | [`estimation`](../../recsim_ng/entities/state_models/estimation.md) module: 27 | State models computing sufficient statistics for unobserved quantities. 28 | 29 | [`state`](../../recsim_ng/entities/state_models/state.md) module: State 30 | representations API. 31 | 32 | [`static`](../../recsim_ng/entities/state_models/static.md) module: State 33 | representations that remain static over the trajectory. 34 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/state_models/dynamic.md: -------------------------------------------------------------------------------- 1 | description: State models of variables evolving over time as a function of 2 | inputs. 3 | 4 |
5 | 6 | 7 |
8 | 9 | # Module: recsim_ng.entities.state_models.dynamic 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | State models of variables evolving over time as a function of inputs. 21 | 22 | ## Classes 23 | 24 | [`class ControlledLinearGaussianStateModel`](../../../recsim_ng/entities/state_models/dynamic/ControlledLinearGaussianStateModel.md): 25 | A controlled linear Gaussian state transition model. 26 | 27 | [`class ControlledLinearScaledGaussianStateModel`](../../../recsim_ng/entities/state_models/dynamic/ControlledLinearScaledGaussianStateModel.md): 28 | A controlled linear Gaussian state model with scaling operators. 29 | 30 | [`class FiniteStateMarkovModel`](../../../recsim_ng/entities/state_models/dynamic/FiniteStateMarkovModel.md): 31 | A finite-state controlled Markov chain state model. 32 | 33 | [`class LinearGaussianStateModel`](../../../recsim_ng/entities/state_models/dynamic/LinearGaussianStateModel.md): 34 | An autonomous (uncontrolled) linear Gaussian state transition model. 35 | 36 | [`class NoOPOrContinueStateModel`](../../../recsim_ng/entities/state_models/dynamic/NoOPOrContinueStateModel.md): 37 | A meta model that conditionally evolves the state of a base state model. 38 | 39 | [`class RNNCellStateModel`](../../../recsim_ng/entities/state_models/dynamic/RNNCellStateModel.md): 40 | Deterministic RNN state transition model. 41 | 42 | [`class ResetOrContinueStateModel`](../../../recsim_ng/entities/state_models/dynamic/ResetOrContinueStateModel.md): 43 | A meta model that either evolves or resets the state of a base state model. 44 | 45 | [`class SwitchingDynamicsStateModel`](../../../recsim_ng/entities/state_models/dynamic/SwitchingDynamicsStateModel.md): 46 | A meta model that alternates between two state models of the same family. 47 | 48 | ## Type Aliases 49 | 50 | [`LinearOpCtor`](../../../recsim_ng/entities/state_models/dynamic/LinearOpCtor.md) 51 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/state_models/dynamic/LinearOpCtor.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.entities.state_models.dynamic.LinearOpCtor 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/state_models/estimation.md: -------------------------------------------------------------------------------- 1 | description: State models computing sufficient statistics for unobserved 2 | quantities. 3 | 4 |
5 | 6 | 7 |
8 | 9 | # Module: recsim_ng.entities.state_models.estimation 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | State models computing sufficient statistics for unobserved quantities. 21 | 22 | ## Classes 23 | 24 | [`class FiniteHistoryStateModel`](../../../recsim_ng/entities/state_models/estimation/FiniteHistoryStateModel.md): 25 | State model containing an obervation history as sufficient statistics. 26 | 27 | ## Type Aliases 28 | 29 | [`LinearOpCtor`](../../../recsim_ng/entities/state_models/dynamic/LinearOpCtor.md) 30 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/state_models/state.md: -------------------------------------------------------------------------------- 1 | description: State representations API. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.state_models.state 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | State representations API. 20 | 21 | ## Classes 22 | 23 | [`class StateModel`](../../../recsim_ng/entities/state_models/state/StateModel.md): 24 | State model interface API. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/entities/state_models/static.md: -------------------------------------------------------------------------------- 1 | description: State representations that remain static over the trajectory. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.entities.state_models.static 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | State representations that remain static over the trajectory. 20 | 21 | ## Classes 22 | 23 | [`class GMMVector`](../../../recsim_ng/entities/state_models/static/GMMVector.md): 24 | Picks a vector from a Gaussian mixture model (GMM). 25 | 26 | [`class HierarchicalStaticTensor`](../../../recsim_ng/entities/state_models/static/HierarchicalStaticTensor.md): 27 | Picks a cluster according to logits, then uniformly picks a member tensor. 28 | 29 | [`class StaticMixtureSameFamilyModel`](../../../recsim_ng/entities/state_models/static/StaticMixtureSameFamilyModel.md): 30 | Base class for mixture model entities. 31 | 32 | [`class StaticStateModel`](../../../recsim_ng/entities/state_models/static/StaticStateModel.md): 33 | An abstract class for non-evolving state models. 34 | 35 | [`class StaticTensor`](../../../recsim_ng/entities/state_models/static/StaticTensor.md): 36 | Picks from a dictionary of tensors according to a categorical distribution. 37 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # Module: recsim_ng.lib 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | View 15 | source 16 | 17 | ## Modules 18 | 19 | [`data`](../recsim_ng/lib/data.md) module: Tools to import data and convert them 20 | to Variables. 21 | 22 | [`jax`](../recsim_ng/lib/jax.md) module: Module importing 23 | recsim_ng.lib.tensorflow.*. 24 | 25 | [`python`](../recsim_ng/lib/python.md) module: Module importing 26 | recsim_ng.lib.python.*. 27 | 28 | [`runtime`](../recsim_ng/lib/runtime.md) module: Interface for runtimes. 29 | 30 | [`tensorflow`](../recsim_ng/lib/tensorflow.md) module: Module importing 31 | recsim_ng.lib.tensorflow.*. 32 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/data.md: -------------------------------------------------------------------------------- 1 | description: Tools to import data and convert them to Variables. 2 | 3 |
4 | 5 | 6 | 7 |
8 | 9 | # Module: recsim_ng.lib.data 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | Tools to import data and convert them to Variables. 21 | 22 | ## Classes 23 | 24 | [`class DataSequence`](../../recsim_ng/lib/data/DataSequence.md): Abstract 25 | interface for input data. 26 | 27 | [`class SlicedValue`](../../recsim_ng/lib/data/SlicedValue.md): A `DataSequence` 28 | that divides a `Value` into a sequence of `Value`s. 29 | 30 | [`class StaticSlicedValue`](../../recsim_ng/lib/data/StaticSlicedValue.md): 31 | Static version of SlicedValue with sequence length being one. 32 | 33 | [`class TimeSteps`](../../recsim_ng/lib/data/TimeSteps.md): A `DataSequence` 34 | that yields the numbers `0, 1, 2, ...`. 35 | 36 | ## Functions 37 | 38 | [`data_variable(...)`](../../recsim_ng/lib/data/data_variable.md): A `Variable` 39 | whose value maps a function over a sequence of data elements. 40 | 41 | [`remove_data_index(...)`](../../recsim_ng/lib/data/remove_data_index.md): 42 | Removes the bookkeeping information from a `data_variable` value. 43 | 44 | [`replace_data_sequence(...)`](../../recsim_ng/lib/data/replace_data_sequence.md): 45 | A helper function for data_variable() to use a new data_sequence. 46 | 47 | ## Type Aliases 48 | 49 | [`OutputFunction`](../../recsim_ng/lib/data/OutputFunction.md) 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 60 | 63 | 64 |
58 | DEFAULT_DATA_INDEX_FIELD 59 | 61 | `'__data_index'` 62 |
65 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/data/OutputFunction.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.lib.data.OutputFunction 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/data/TimeSteps.md: -------------------------------------------------------------------------------- 1 | description: A DataSequence that yields the numbers 0, 1, 2, .... 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | # recsim_ng.lib.data.TimeSteps 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | View 20 | source 21 | 22 | A `DataSequence` that yields the numbers `0, 1, 2, ...`. 23 | 24 | Inherits From: [`DataSequence`](../../../recsim_ng/lib/data/DataSequence.md) 25 | 26 | 27 | 28 | ## Methods 29 | 30 |

first_index

31 | 32 | View 33 | source 34 | 35 | 38 | 39 | Returns the index of the first data element of the sequence. 40 | 41 |

get

42 | 43 | View 44 | source 45 | 46 | 51 | 52 | Returns the data element at `index`. 53 | 54 |

next_index

55 | 56 | View 57 | source 58 | 59 | 64 | 65 | Returns the index of the data element immediately after `index`. 66 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/data/remove_data_index.md: -------------------------------------------------------------------------------- 1 | description: Removes the bookkeeping information from a data_variable value. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.lib.data.remove_data_index 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Removes the bookkeeping information from a `data_variable` value. 20 | 21 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 39 | 42 | 43 | 46 | 50 | 51 |
37 | `value` 38 | 40 | Any `Value`. 41 |
44 | `data_index_field` 45 | 47 | The name of the bookkeeping field; see above. Defaults to 48 | `DEFAULT_DATA_INDEX_FIELD`. 49 |
52 | 53 | 54 | 55 | 56 | 57 | 58 | 63 | 64 | 65 |
59 | If `value` was output by a `Variable` created with `data_variable`, returns 60 | a `Value` equivalent to `value` but without its `data_index_field`. 61 | Otherwise, returns `value`. 62 |
66 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/data/replace_data_sequence.md: -------------------------------------------------------------------------------- 1 | description: A helper function for data_variable() to use a new data_sequence. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.lib.data.replace_data_sequence 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | A helper function for data_variable() to use a new data_sequence. 20 | 21 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/jax.md: -------------------------------------------------------------------------------- 1 | description: Module importing recsim_ng.lib.tensorflow.*. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.jax 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing recsim_ng.lib.tensorflow.*. 20 | 21 | ## Modules 22 | 23 | [`runtime`](../../recsim_ng/lib/jax/runtime.md) module: TensorFlow-based 24 | runtime. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/jax/runtime.md: -------------------------------------------------------------------------------- 1 | description: TensorFlow-based runtime. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.jax.runtime 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | TensorFlow-based runtime. 20 | 21 | ## Classes 22 | 23 | [`class JAXRuntime`](../../../recsim_ng/lib/jax/runtime/JAXRuntime.md): A 24 | JAX-based runtime for a `Network` of `Variable`s. 25 | 26 | ## Type Aliases 27 | 28 | [`NetworkValue`](../../../recsim_ng/core/network/NetworkValue.md) 29 | 30 | [`NetworkValueTrajectory`](../../../recsim_ng/core/network/NetworkValue.md) 31 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/python.md: -------------------------------------------------------------------------------- 1 | description: Module importing recsim_ng.lib.python.*. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.python 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing recsim_ng.lib.python.*. 20 | 21 | ## Modules 22 | 23 | [`runtime`](../../recsim_ng/lib/python/runtime.md) module: Python-based runtime. 24 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/python/runtime.md: -------------------------------------------------------------------------------- 1 | description: Python-based runtime. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.python.runtime 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Python-based runtime. 20 | 21 | ## Classes 22 | 23 | [`class PythonRuntime`](../../../recsim_ng/lib/python/runtime/PythonRuntime.md): 24 | A Python-based runtime for a `Network` of `Variable`s. 25 | 26 | ## Type Aliases 27 | 28 | [`NetworkValue`](../../../recsim_ng/core/network/NetworkValue.md) 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/python/runtime/PythonRuntime.md: -------------------------------------------------------------------------------- 1 | description: A Python-based runtime for a Network of Variables. 2 | 3 |
4 | 5 | 6 | 7 | 8 |
9 | 10 | # recsim_ng.lib.python.runtime.PythonRuntime 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | View 19 | source 20 | 21 | A Python-based runtime for a `Network` of `Variable`s. 22 | 23 | Inherits From: [`Runtime`](../../../../recsim_ng/lib/runtime/Runtime.md) 24 | 25 | 30 | 31 | 32 | 33 | ## Methods 34 | 35 |

execute

36 | 37 | View 38 | source 39 | 40 | 46 | 47 | Implements `Runtime`. 48 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/runtime.md: -------------------------------------------------------------------------------- 1 | description: Interface for runtimes. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.runtime 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Interface for runtimes. 20 | 21 | ## Classes 22 | 23 | [`class Runtime`](../../recsim_ng/lib/runtime/Runtime.md): A runtime for a 24 | `Network` of `Variable`s. 25 | 26 | ## Type Aliases 27 | 28 | [`NetworkValue`](../../recsim_ng/core/network/NetworkValue.md) 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/runtime/Runtime.md: -------------------------------------------------------------------------------- 1 | description: A runtime for a Network of Variables. 2 | 3 |
4 | 5 | 6 | 7 |
8 | 9 | # recsim_ng.lib.runtime.Runtime 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | A runtime for a `Network` of `Variable`s. 21 | 22 | 23 | 24 | ## Methods 25 | 26 |

execute

27 | 28 | View 29 | source 30 | 31 | 38 | 39 | The `NetworkValue` at `num_steps` steps after `starting_value`. 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 50 | 53 | 54 | 57 | 61 | 62 |
Args
48 | `num_steps` 49 | 51 | The number of steps to execute. 52 |
55 | `starting_value` 56 | 58 | The `NetworkValue` at step 0, or Network.initial_step() 59 | if not provided explicitly. 60 |
63 | 64 | 65 | 66 | 67 | 68 | 69 | 72 | 73 | 74 |
Returns
70 | The `NetworkValue` at step `num_steps`. 71 |
75 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow.md: -------------------------------------------------------------------------------- 1 | description: Module importing recsim_ng.lib.tensorflow.*. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.tensorflow 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing recsim_ng.lib.tensorflow.*. 20 | 21 | ## Modules 22 | 23 | [`data`](../../recsim_ng/lib/tensorflow/data.md) module: Tools to import data 24 | and convert them to Variables. 25 | 26 | [`entity`](../../recsim_ng/lib/tensorflow/entity.md) module: Entities base class 27 | and supporting functons. 28 | 29 | [`field_spec`](../../recsim_ng/lib/tensorflow/field_spec.md) module: 30 | Tensorflow-specific implementations of value.FieldSpec. 31 | 32 | [`log_probability`](../../recsim_ng/lib/tensorflow/log_probability.md) module: 33 | Compute the joint log-probability of a Network given an observation. 34 | 35 | [`runtime`](../../recsim_ng/lib/tensorflow/runtime.md) module: TensorFlow-based 36 | runtime. 37 | 38 | [`util`](../../recsim_ng/lib/tensorflow/util.md) module: Utilities. 39 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/data.md: -------------------------------------------------------------------------------- 1 | description: Tools to import data and convert them to Variables. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.tensorflow.data 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Tools to import data and convert them to Variables. 20 | 21 | ## Classes 22 | 23 | [`class TFDataset`](../../../recsim_ng/lib/tensorflow/data/TFDataset.md): A 24 | `DataSequence` yielding consecutive elements of a `tf.data.Dataset`. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/entity.md: -------------------------------------------------------------------------------- 1 | description: Entities base class and supporting functons. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.tensorflow.entity 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Entities base class and supporting functons. 20 | 21 | ## Classes 22 | 23 | [`class Entity`](../../../recsim_ng/lib/tensorflow/entity/Entity.md): Entities. 24 | 25 | ## Functions 26 | 27 | [`story_with_trainable_variables(...)`](../../../recsim_ng/lib/tensorflow/entity/story_with_trainable_variables.md): 28 | Returns the output of a story and trainable variables used in it. 29 | 30 | ## Type Aliases 31 | 32 | [`EntityMap`](../../../recsim_ng/lib/tensorflow/entity/EntityMap.md) 33 | 34 | [`Story`](../../../recsim_ng/lib/tensorflow/entity/Story.md) 35 | 36 | [`TrainableVariables`](../../../recsim_ng/lib/tensorflow/entity/TrainableVariables.md) 37 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/entity/EntityMap.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.lib.tensorflow.entity.EntityMap 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/entity/Story.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.lib.tensorflow.entity.Story 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/entity/TrainableVariables.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.lib.tensorflow.entity.TrainableVariables 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/entity/story_with_trainable_variables.md: -------------------------------------------------------------------------------- 1 | description: Returns the output of a story and trainable variables used in it. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.lib.tensorflow.entity.story_with_trainable_variables 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Returns the output of a story and trainable variables used in it. 20 | 21 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 38 | 42 | 43 |
36 | `story` 37 | 39 | an argumentless callable which leads to the creation of objects 40 | inheriting from Entity. 41 |
44 | 45 | 46 | 47 | 48 | 49 | 50 | 54 | 55 | 56 |
51 | a dictionary mapping entity_name to a sequence of the entity trainable 52 | variables. 53 |
57 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/field_spec.md: -------------------------------------------------------------------------------- 1 | description: Tensorflow-specific implementations of value.FieldSpec. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.tensorflow.field_spec 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Tensorflow-specific implementations of value.FieldSpec. 20 | 21 | ## Classes 22 | 23 | [`class DynamicFieldSpec`](../../../recsim_ng/lib/tensorflow/field_spec/DynamicFieldSpec.md): 24 | Field spec for tensors which may change shape across iterations. 25 | 26 | [`class FieldSpec`](../../../recsim_ng/lib/tensorflow/field_spec/FieldSpec.md): 27 | Base Tensorflow field spec; checks shape consistency. 28 | 29 | [`class Space`](../../../recsim_ng/lib/tensorflow/field_spec/Space.md): 30 | Tensorflow field spec with a Gym space. 31 | 32 | ## Type Aliases 33 | 34 | [`TFInvariant`](../../../recsim_ng/lib/tensorflow/field_spec/TFInvariant.md) 35 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/field_spec/TFInvariant.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.lib.tensorflow.field_spec.TFInvariant 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/log_probability/log_prob_accumulator_variable.md: -------------------------------------------------------------------------------- 1 | description: Temporal accumulation of log probability variables. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.lib.tensorflow.log_probability.log_prob_accumulator_variable 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Temporal accumulation of log probability variables. 20 | 21 | 26 | 27 | 28 | 29 | Given a log probability variable, outputs temporal per-field accumulator of the 30 | log probability values of the variable up to the current time instance. 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 41 | 46 | 47 |
39 | `log_prob_var` 40 | 42 | An instance of `Variable` computing the per-time-step log 43 | probability of an simulation-observation variable pair (e.g. as generated 44 | by `log_prob_variables`. 45 |
48 | 49 | 50 | 51 | 52 | 53 | 54 | 58 | 59 | 60 |
55 | A `Variable` outputting the per-field sum of all values of the input 56 | variable up to the current time-step. 57 |
61 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/log_probability/log_prob_accumulator_variables.md: -------------------------------------------------------------------------------- 1 | description: List version of log_prob_accumulator_variable. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.lib.tensorflow.log_probability.log_prob_accumulator_variables 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | List version of `log_prob_accumulator_variable`. 20 | 21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/log_probability/total_log_prob_accumulator_variable.md: -------------------------------------------------------------------------------- 1 | description: Accumulated joint log probability variable. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.lib.tensorflow.log_probability.total_log_prob_accumulator_variable 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Accumulated joint log probability variable. 20 | 21 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/runtime.md: -------------------------------------------------------------------------------- 1 | description: TensorFlow-based runtime. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.tensorflow.runtime 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | TensorFlow-based runtime. 20 | 21 | ## Classes 22 | 23 | [`class TFRuntime`](../../../recsim_ng/lib/tensorflow/runtime/TFRuntime.md): A 24 | Tensorflow-based runtime for a `Network` of `Variable`s. 25 | 26 | ## Type Aliases 27 | 28 | [`NetworkValue`](../../../recsim_ng/core/network/NetworkValue.md) 29 | 30 | [`NetworkValueTrajectory`](../../../recsim_ng/core/network/NetworkValue.md) 31 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/util.md: -------------------------------------------------------------------------------- 1 | description: Utilities. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.lib.tensorflow.util 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Utilities. 20 | 21 | ## Functions 22 | 23 | [`initialize_platform(...)`](../../../recsim_ng/lib/tensorflow/util/initialize_platform.md): 24 | Initializes tf.distribute.Strategy. 25 | 26 | [`pickle_to_network_value_trajectory(...)`](../../../recsim_ng/lib/tensorflow/util/pickle_to_network_value_trajectory.md): 27 | Returns a NetworkValueTrajectory from a pickle representation of dict. 28 | 29 | ## Type Aliases 30 | 31 | [`NetworkValueTrajectory`](../../../recsim_ng/core/network/NetworkValue.md) 32 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/util/initialize_platform.md: -------------------------------------------------------------------------------- 1 | description: Initializes tf.distribute.Strategy. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.lib.tensorflow.util.initialize_platform 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Initializes tf.distribute.Strategy. 20 | 21 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 38 | 41 | 42 | 45 | 49 | 50 |
36 | `platform` 37 | 39 | 'CPU', 'GPU', or 'TPU' 40 |
43 | `tpu_address` 44 | 46 | A string corresponding to the TPU to use. It can be the TPU 47 | name or TPU worker gRPC address. 48 |
51 | 52 | 53 | 54 | 55 | 56 | 57 | 61 | 62 | 63 |
58 | A TPUStrategy if platform is 'TPU' and MirroredStrategy otherwise. Also 59 | number of devices. 60 |
64 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/lib/tensorflow/util/pickle_to_network_value_trajectory.md: -------------------------------------------------------------------------------- 1 | description: Returns a NetworkValueTrajectory from a pickle representation of 2 | dict. 3 | 4 |
5 | 6 | 7 |
8 | 9 | # recsim_ng.lib.tensorflow.util.pickle_to_network_value_trajectory 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | View 18 | source 19 | 20 | Returns a NetworkValueTrajectory from a pickle representation of dict. 21 | 22 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/stories.md: -------------------------------------------------------------------------------- 1 | description: Module importing stories various simulation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.stories 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Module importing stories various simulation. 20 | 21 | ## Modules 22 | 23 | [`bandit_simulation`](../recsim_ng/stories/bandit_simulation.md) module: Bandit 24 | simulation story. 25 | 26 | [`recommendation_simulation`](../recsim_ng/stories/recommendation_simulation.md) 27 | module: Recs simulation stories. 28 | 29 | [`static_recs_simulation`](../recsim_ng/stories/static_recs_simulation.md) 30 | module: A story for one-shot recommendation. 31 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/stories/bandit_simulation.md: -------------------------------------------------------------------------------- 1 | description: Bandit simulation story. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.stories.bandit_simulation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Bandit simulation story. 20 | 21 | ## Functions 22 | 23 | [`bandit_story(...)`](../../recsim_ng/stories/bandit_simulation/bandit_story.md): 24 | The story implements bandit simulation. 25 | 26 | ## Type Aliases 27 | 28 | [`Config`](../../recsim_ng/stories/bandit_simulation/Config.md) 29 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/stories/bandit_simulation/Config.md: -------------------------------------------------------------------------------- 1 |
2 | 3 | 4 |
5 | 6 | # recsim_ng.stories.bandit_simulation.Config 7 | 8 | 9 | 10 | This symbol is a **type alias**. 11 | 12 | #### Source: 13 | 14 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/stories/recommendation_simulation.md: -------------------------------------------------------------------------------- 1 | description: Recs simulation stories. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.stories.recommendation_simulation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Recs simulation stories. 20 | 21 | ## Functions 22 | 23 | [`recs_story(...)`](../../recsim_ng/stories/recommendation_simulation/recs_story.md): 24 | Recommendation story. 25 | 26 | [`recs_story_using_logged_slate_docs(...)`](../../recsim_ng/stories/recommendation_simulation/recs_story_using_logged_slate_docs.md): 27 | A recommendation story to replay logged recommendations. 28 | 29 | [`simplified_recs_story(...)`](../../recsim_ng/stories/recommendation_simulation/simplified_recs_story.md): 30 | A simple recommendation story. 31 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/stories/recommendation_simulation/recs_story.md: -------------------------------------------------------------------------------- 1 | description: Recommendation story. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.stories.recommendation_simulation.recs_story 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | Recommendation story. 20 | 21 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/stories/recommendation_simulation/simplified_recs_story.md: -------------------------------------------------------------------------------- 1 | description: A simple recommendation story. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.stories.recommendation_simulation.simplified_recs_story 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | A simple recommendation story. 20 | 21 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/stories/static_recs_simulation.md: -------------------------------------------------------------------------------- 1 | description: A story for one-shot recommendation. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # Module: recsim_ng.stories.static_recs_simulation 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | A story for one-shot recommendation. 20 | 21 | ## Functions 22 | 23 | [`static_recs_story(...)`](../../recsim_ng/stories/static_recs_simulation/static_recs_story.md): 24 | A simple recommendation story with only static entities. 25 | -------------------------------------------------------------------------------- /docs/api_docs/python/recsim_ng/stories/static_recs_simulation/static_recs_story.md: -------------------------------------------------------------------------------- 1 | description: A simple recommendation story with only static entities. 2 | 3 |
4 | 5 | 6 |
7 | 8 | # recsim_ng.stories.static_recs_simulation.static_recs_story 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | View 17 | source 18 | 19 | A simple recommendation story with only static entities. 20 | 21 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /recsim_ng/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the RecSim NG package.""" 17 | -------------------------------------------------------------------------------- /recsim_ng/applications/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the RecSim NG applications.""" 17 | -------------------------------------------------------------------------------- /recsim_ng/applications/cav_synthetic_model/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the CAV synthetic model.""" 17 | from recsim_ng.applications.cav_synthetic_model import corpus 18 | from recsim_ng.applications.cav_synthetic_model import user 19 | -------------------------------------------------------------------------------- /recsim_ng/applications/ecosystem_simulation/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the application modeling ecosytem.""" 17 | from recsim_ng.applications.ecosystem_simulation import corpus 18 | from recsim_ng.applications.ecosystem_simulation import ecosystem_simulation 19 | from recsim_ng.applications.ecosystem_simulation import metrics 20 | from recsim_ng.applications.ecosystem_simulation import recommender 21 | from recsim_ng.applications.ecosystem_simulation import simulation_config 22 | from recsim_ng.applications.ecosystem_simulation import user 23 | -------------------------------------------------------------------------------- /recsim_ng/applications/ecosystem_simulation/ecosystem_simulation_demo.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Demonsrate how we run the ecosystem simulation.""" 17 | import time 18 | 19 | from absl import app 20 | from recsim_ng.applications.ecosystem_simulation import ecosystem_simulation 21 | from recsim_ng.applications.ecosystem_simulation import user as clustered_user 22 | from recsim_ng.lib.tensorflow import util 23 | 24 | 25 | def main(argv): 26 | del argv 27 | strategy, num_replicas = util.initialize_platform() 28 | num_runs = 40 29 | num_users = 2000 30 | num_provider_clusters = 40 31 | horizon = 300 32 | provider_disp = 64.0 33 | provider_fan_out = 2 34 | num_topics = 2 35 | provider_means = clustered_user.init_random_provider_clusters( 36 | provider_disp, provider_fan_out, num_provider_clusters, num_topics) 37 | 38 | t_begin = time.time() 39 | utility_mean, utility_se = ecosystem_simulation.run_simulation( 40 | strategy, num_replicas, num_runs, provider_means, num_users, horizon) 41 | print('Elapsed time: %.3f seconds' % (time.time() - t_begin)) 42 | print('Average user utility: %f +- %f' % (utility_mean, utility_se)) 43 | 44 | 45 | if __name__ == '__main__': 46 | app.run(main) 47 | -------------------------------------------------------------------------------- /recsim_ng/applications/ecosystem_simulation/metrics.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Definitions for recs metrics entities.""" 17 | 18 | import edward2 as ed # type: ignore 19 | from gym import spaces 20 | import numpy as np 21 | from recsim_ng.core import value 22 | from recsim_ng.entities.recommendation import metrics 23 | from recsim_ng.lib.tensorflow import field_spec 24 | import tensorflow as tf 25 | 26 | Value = value.Value 27 | ValueSpec = value.ValueSpec 28 | Space = field_spec.Space 29 | 30 | 31 | class UtilityAsRewardMetrics(metrics.RecsMetricsBase): 32 | """A minimal implementation of recs metrics.""" 33 | 34 | def initial_metrics(self): 35 | """The initial metrics value.""" 36 | return Value( 37 | reward=ed.Deterministic(loc=tf.zeros([self._num_users])), 38 | cumulative_reward=ed.Deterministic(loc=tf.zeros([self._num_users]))) 39 | 40 | def next_metrics(self, previous_metrics, corpus_state, 41 | user_state, user_response, 42 | slate_doc): 43 | """The metrics value after the initial value.""" 44 | del corpus_state, user_response, slate_doc 45 | reward = user_state.get("utilities") 46 | return Value( 47 | reward=ed.Deterministic(loc=reward), 48 | cumulative_reward=ed.Deterministic( 49 | loc=previous_metrics.get("cumulative_reward") + reward)) 50 | 51 | def specs(self): 52 | return ValueSpec( 53 | reward=Space( 54 | spaces.Box( 55 | low=np.zeros(self._num_users), 56 | high=np.array([np.Inf] * self._num_users))), 57 | cumulative_reward=Space( 58 | spaces.Box( 59 | low=np.zeros(self._num_users), 60 | high=np.array([np.Inf] * 61 | self._num_users)))).prefixed_with("state") 62 | -------------------------------------------------------------------------------- /recsim_ng/applications/ecosystem_simulation/metrics_test.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Tests for recsim_ng.applications.ecosystem_simulation.metrics.""" 17 | 18 | import edward2 as ed # type: ignore 19 | from recsim_ng.applications.ecosystem_simulation import metrics 20 | from recsim_ng.core import value 21 | import tensorflow as tf 22 | 23 | Value = value.Value 24 | 25 | 26 | class UtilityAsRewardMetricsTest(tf.test.TestCase): 27 | 28 | def setUp(self): 29 | super(UtilityAsRewardMetricsTest, self).setUp() 30 | self._config = { 31 | 'num_users': 3, 32 | 'num_providers': 4, 33 | } 34 | self._metrics = metrics.UtilityAsRewardMetrics(self._config) 35 | 36 | def test_next_metrics(self): 37 | init_metrics = self._metrics.initial_metrics() 38 | user_state = Value(utilities=ed.Deterministic(loc=[0.5, 0.6, 0.4])) 39 | current_metrics = self._metrics.next_metrics(init_metrics, None, user_state, 40 | None, None) 41 | current_metrics = self._metrics.next_metrics(current_metrics, None, 42 | user_state, None, None) 43 | expected_metrics = { 44 | 'reward': [0.5, 0.6, 0.4], 45 | 'cumulative_reward': [1.0, 1.2, 0.8], 46 | } 47 | self.assertAllClose(expected_metrics, 48 | self.evaluate(current_metrics.as_dict)) 49 | 50 | 51 | if __name__ == '__main__': 52 | tf.test.main() 53 | -------------------------------------------------------------------------------- /recsim_ng/applications/ecosystem_simulation/simulation_config.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Configuration parameters for running ecosystem simulation.""" 17 | from typing import Collection 18 | import gin 19 | import numpy as np 20 | from recsim_ng.applications.ecosystem_simulation import corpus 21 | from recsim_ng.applications.ecosystem_simulation import metrics 22 | from recsim_ng.applications.ecosystem_simulation import recommender 23 | from recsim_ng.applications.ecosystem_simulation import user 24 | from recsim_ng.core import variable 25 | from recsim_ng.stories import recommendation_simulation as simulation 26 | 27 | Variable = variable.Variable 28 | 29 | 30 | @gin.configurable 31 | def create_viable_provider_simulation_network( 32 | provider_means, 33 | num_users = 2000, 34 | provider_boost_cap = 1.2): 35 | """Returns a network for the ecosystem simulation with viable corpus.""" 36 | num_topics = provider_means.shape[1] 37 | num_providers = provider_means.shape[0] 38 | num_docs = num_providers * 5 39 | config = { 40 | # Common parameters 41 | 'num_topics': num_topics, 42 | 'num_users': num_users, 43 | 'num_docs': num_docs, 44 | 'slate_size': 3, 45 | 'num_providers': num_providers, 46 | 'provider_means': provider_means, 47 | 'provider_boost_cap': provider_boost_cap, 48 | } 49 | return simulation.recs_story(config, 50 | user.ClusteredNormalUserCoreDispersion, 51 | corpus.ViableCorpus, 52 | recommender.MyopicRecommender, 53 | metrics.UtilityAsRewardMetrics) 54 | -------------------------------------------------------------------------------- /recsim_ng/applications/ecosystem_simulation/trajectory.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-research/recsim_ng/6df34cf87111da366923793ddba81a0b50e41242/recsim_ng/applications/ecosystem_simulation/trajectory.pickle -------------------------------------------------------------------------------- /recsim_ng/applications/latent_variable_model_learning/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the application learning latent variable models.""" 17 | from recsim_ng.applications.latent_variable_model_learning import recommender 18 | from recsim_ng.applications.latent_variable_model_learning import simulation_config 19 | from recsim_ng.applications.latent_variable_model_learning import user 20 | -------------------------------------------------------------------------------- /recsim_ng/applications/latent_variable_model_learning/latent_variable_model_test.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Tests for recsim_ng.applications.latent_variable_model_learning.""" 17 | import os 18 | 19 | from absl.testing import parameterized 20 | from recsim_ng.applications.latent_variable_model_learning import simulation_config 21 | from recsim_ng.core import network as network_lib 22 | from recsim_ng.lib.tensorflow import log_probability 23 | from recsim_ng.lib.tensorflow import util 24 | import tensorflow as tf 25 | 26 | 27 | class LatentVariableModelTest(tf.test.TestCase, parameterized.TestCase): 28 | 29 | def setUp(self): 30 | super(LatentVariableModelTest, self).setUp() 31 | tf.random.set_seed(0) 32 | 33 | @parameterized.named_parameters(('no_graph_compile', False), 34 | ('graph_compile', True)) 35 | def test_log_probability(self, graph_compile): 36 | horizon = 6 37 | variables = simulation_config.create_latent_variable_model_network( 38 | num_users=5, num_topics=3, slate_size=4) 39 | network = network_lib.Network(variables=variables) 40 | filepath = os.path.join(os.path.dirname(__file__), 'trajectory.pickle') 41 | traj = util.pickle_to_network_value_trajectory(filepath, network) 42 | log_prob = log_probability.log_probability_from_value_trajectory( 43 | variables=variables, 44 | value_trajectory=traj, 45 | num_steps=horizon - 1, 46 | graph_compile=graph_compile) 47 | self.assertAllClose(log_prob, -223.95068359375) 48 | 49 | 50 | if __name__ == '__main__': 51 | tf.test.main() 52 | -------------------------------------------------------------------------------- /recsim_ng/applications/latent_variable_model_learning/recommender.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """A recommender recommends normally distributed documents.""" 17 | from typing import Optional 18 | 19 | import edward2 as ed # type: ignore 20 | import gin 21 | from gym import spaces 22 | import numpy as np 23 | from recsim_ng.core import value 24 | from recsim_ng.entities.recommendation import recommender 25 | from recsim_ng.lib.tensorflow import field_spec 26 | import tensorflow as tf 27 | 28 | Value = value.Value 29 | ValueSpec = value.ValueSpec 30 | Space = field_spec.Space 31 | 32 | 33 | @gin.configurable 34 | class SimpleNormalRecommender(recommender.BaseRecommender): 35 | """A recommender recommends normally distributed documents.""" 36 | 37 | def __init__(self, 38 | config, 39 | slate_doc_means = None, 40 | normal_scale = 0.5): 41 | recommender.BaseRecommender.__init__(self, config) 42 | self._num_topics = config['num_topics'] 43 | if slate_doc_means is None: 44 | slate_doc_means = np.zeros( 45 | (self._num_users, self._slate_size, self._num_topics), 46 | dtype=np.float32) 47 | self._normal_loc = tf.constant(slate_doc_means) 48 | self._normal_scale = normal_scale 49 | 50 | def slate_docs(self): 51 | slate_doc_features = ed.Normal( 52 | loc=self._normal_loc, scale=self._normal_scale) 53 | return Value(features=slate_doc_features) 54 | 55 | def initial_state(self): 56 | pass 57 | 58 | def next_state(self): 59 | pass 60 | 61 | def specs(self): 62 | output_shape = (self._num_users, self._slate_size, self._num_topics) 63 | slate_docs_spec = ValueSpec( 64 | features=Space( 65 | spaces.Box(low=-np.Inf, high=np.Inf, shape=output_shape))) 66 | return slate_docs_spec.prefixed_with('slate') 67 | -------------------------------------------------------------------------------- /recsim_ng/applications/latent_variable_model_learning/recommender_test.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Tests for recsim_ng.applications.latent_variable_model_learning.recommender.""" 17 | import numpy as np 18 | from recsim_ng.applications.latent_variable_model_learning import recommender 19 | from recsim_ng.core import value 20 | import tensorflow as tf 21 | 22 | Value = value.Value 23 | 24 | 25 | class SimpleNormalRecommenderTest(tf.test.TestCase): 26 | 27 | def setUp(self): 28 | super(SimpleNormalRecommenderTest, self).setUp() 29 | self._num_users = 4 30 | self._num_topics = 2 31 | self._slate_size = 3 32 | self._config = { 33 | 'num_users': 34 | self._num_users, 35 | 'num_docs': 36 | 0, # Unused. 37 | 'num_topics': 38 | self._num_topics, 39 | 'slate_size': 40 | self._slate_size, 41 | 'slate_doc_means': 42 | np.zeros((self._num_users, self._slate_size, self._num_topics), 43 | dtype=np.float32), 44 | } 45 | self._recommender = recommender.SimpleNormalRecommender(self._config) 46 | 47 | def test_slate_docs(self): 48 | spec = self._recommender.specs().get('slate') 49 | actual = self._recommender.slate_docs() 50 | self.assertAllEqual( 51 | spec.get('features').space.shape, 52 | (self._num_users, self._slate_size, self._num_topics)) 53 | self.assertAllEqual( 54 | actual.get('features').shape, 55 | (self._num_users, self._slate_size, self._num_topics)) 56 | 57 | 58 | if __name__ == '__main__': 59 | tf.test.main() 60 | -------------------------------------------------------------------------------- /recsim_ng/applications/latent_variable_model_learning/simulation_config.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Configuration parameters for learning latent variable models.""" 17 | import functools 18 | from typing import Collection, Optional 19 | 20 | import gin 21 | from recsim_ng.applications.latent_variable_model_learning import recommender 22 | from recsim_ng.applications.latent_variable_model_learning import user 23 | from recsim_ng.core import variable 24 | from recsim_ng.stories import recommendation_simulation as simulation 25 | import tensorflow as tf 26 | 27 | Variable = variable.Variable 28 | 29 | 30 | @gin.configurable 31 | def create_latent_variable_model_network( 32 | num_users = 2000, 33 | num_topics = 3, 34 | slate_size = 4, 35 | satisfaction_sensitivity = None 36 | ): 37 | """Returns a network for learning latent variable models.""" 38 | config = { 39 | # Common parameters 40 | 'num_topics': num_topics, 41 | 'num_users': num_users, 42 | 'slate_size': slate_size, 43 | 'num_docs': 0, # Unused. 44 | } 45 | user_ctor = functools.partial( 46 | user.ModelLearningDemoUser, 47 | satisfaction_sensitivity=satisfaction_sensitivity) 48 | return simulation.simplified_recs_story(config, user_ctor, 49 | recommender.SimpleNormalRecommender) 50 | -------------------------------------------------------------------------------- /recsim_ng/applications/latent_variable_model_learning/trajectory.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-research/recsim_ng/6df34cf87111da366923793ddba81a0b50e41242/recsim_ng/applications/latent_variable_model_learning/trajectory.pickle -------------------------------------------------------------------------------- /recsim_ng/applications/recsys_partially_observable_rl/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the application modeling a partially observable RL problem.""" 17 | from recsim_ng.applications.recsys_partially_observable_rl import corpus 18 | from recsim_ng.applications.recsys_partially_observable_rl import interest_evolution_simulation 19 | from recsim_ng.applications.recsys_partially_observable_rl import metrics 20 | from recsim_ng.applications.recsys_partially_observable_rl import recommender 21 | from recsim_ng.applications.recsys_partially_observable_rl import simulation_config 22 | from recsim_ng.applications.recsys_partially_observable_rl import user 23 | -------------------------------------------------------------------------------- /recsim_ng/applications/recsys_partially_observable_rl/interest_evolution_simulation_demo.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Train a recommender with the interest_evolution_simulation.""" 17 | from absl import app 18 | from recsim_ng.applications.recsys_partially_observable_rl import interest_evolution_simulation 19 | from recsim_ng.applications.recsys_partially_observable_rl import simulation_config 20 | 21 | 22 | def main(argv): 23 | del argv 24 | num_users = 1000 25 | variables, trainable_variables = ( 26 | simulation_config.create_interest_evolution_simulation_network( 27 | num_users=num_users)) 28 | 29 | interest_evolution_simulation.run_simulation( 30 | num_training_steps=100, 31 | horizon=100, 32 | global_batch=num_users, 33 | learning_rate=1e-4, 34 | simulation_variables=variables, 35 | trainable_variables=trainable_variables, 36 | metric_to_optimize='cumulative_reward') 37 | 38 | 39 | if __name__ == '__main__': 40 | app.run(main) 41 | -------------------------------------------------------------------------------- /recsim_ng/applications/recsys_partially_observable_rl/metrics_test.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Tests for recsim_ng.applications.recsys_partially_observable_rl.""" 17 | 18 | import edward2 as ed # type: ignore 19 | from recsim_ng.applications.recsys_partially_observable_rl import metrics 20 | from recsim_ng.core import value 21 | import tensorflow as tf 22 | 23 | Value = value.Value 24 | 25 | 26 | class ConsumedTimeAsRewardMetricsTest(tf.test.TestCase): 27 | 28 | def setUp(self): 29 | super().setUp() 30 | self._config = { 31 | 'num_users': 4, 32 | 'num_creators': 4, 33 | } 34 | self._metrics = metrics.ConsumedTimeAsRewardMetrics(self._config) 35 | 36 | def test_next_metrics(self): 37 | init_metrics = self._metrics.initial_metrics() 38 | user_response = Value( 39 | consumed_time=ed.Deterministic(loc=[-1., 0.5, 0.6, 0.4])) 40 | current_metrics = self._metrics.next_metrics(init_metrics, None, None, 41 | user_response, None) 42 | current_metrics = self._metrics.next_metrics(current_metrics, None, None, 43 | user_response, None) 44 | expected_metrics = { 45 | 'reward': [0.0, 0.5, 0.6, 0.4], 46 | 'cumulative_reward': [0.0, 1.0, 1.2, 0.8], 47 | } 48 | self.assertAllClose(expected_metrics, 49 | self.evaluate(current_metrics.as_dict)) 50 | 51 | 52 | if __name__ == '__main__': 53 | tf.test.main() 54 | -------------------------------------------------------------------------------- /recsim_ng/applications/recsys_partially_observable_rl/trajectory.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google-research/recsim_ng/6df34cf87111da366923793ddba81a0b50e41242/recsim_ng/applications/recsys_partially_observable_rl/trajectory.pickle -------------------------------------------------------------------------------- /recsim_ng/core/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the core library.""" 17 | from recsim_ng.core import network 18 | from recsim_ng.core import value 19 | from recsim_ng.core import variable 20 | -------------------------------------------------------------------------------- /recsim_ng/entities/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the RecSim NG entities.""" 17 | -------------------------------------------------------------------------------- /recsim_ng/entities/bandits/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing entities for bandits.""" 17 | from recsim_ng.entities.bandits import algorithm 18 | from recsim_ng.entities.bandits import context 19 | from recsim_ng.entities.bandits import generator 20 | from recsim_ng.entities.bandits import metrics 21 | from recsim_ng.entities.bandits import problem 22 | -------------------------------------------------------------------------------- /recsim_ng/entities/bandits/algorithm.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Algorithm entity for bandit simulation.""" 17 | import abc 18 | from typing import Text 19 | 20 | from recsim_ng.core import value 21 | from recsim_ng.lib.tensorflow import entity 22 | 23 | Value = value.Value 24 | ValueSpec = value.ValueSpec 25 | 26 | 27 | class BanditAlgorithm(entity.Entity, metaclass=abc.ABCMeta): 28 | """An abstract algorithm entity responsible for pulling an arm.""" 29 | 30 | def __init__(self, 31 | config, 32 | name = "BanditAlgorithm"): 33 | super().__init__(name=name) 34 | self._num_bandits = config["num_bandits"] 35 | self._num_arms = config["num_arms"] 36 | self._horizon = config["horizon"] 37 | if self._num_bandits < 1: 38 | raise ValueError("num_bandits must be positive.") 39 | if self._num_arms < 2: 40 | raise ValueError("num_arms must be greater than one.") 41 | if self._horizon < 1: 42 | raise ValueError("horizon must be positive.") 43 | 44 | @abc.abstractmethod 45 | def specs(self): 46 | """Returns ValueSpec for both ``choice'' and ``statistics''.""" 47 | raise NotImplementedError() 48 | 49 | @abc.abstractmethod 50 | def initial_statistics(self, context): 51 | """Initializes the statistics modeling the rewards.""" 52 | raise NotImplementedError() 53 | 54 | @abc.abstractmethod 55 | def next_statistics(self, previous_statistics, arm, 56 | reward, context): 57 | """Updates the statistics based on the pulled arm and reward revealed.""" 58 | raise NotImplementedError() 59 | 60 | @abc.abstractmethod 61 | def arm_choice(self, statistics, context): 62 | """Pulls an arm based on statistics and contexts.""" 63 | raise NotImplementedError() 64 | -------------------------------------------------------------------------------- /recsim_ng/entities/bandits/context.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Context entity for bandit simulation.""" 17 | from typing import Text 18 | 19 | from recsim_ng.core import value 20 | from recsim_ng.entities.state_models import state 21 | 22 | FieldSpec = value.FieldSpec 23 | Value = value.Value 24 | ValueSpec = value.ValueSpec 25 | 26 | 27 | class BanditContext(state.StateModel): 28 | """A basic context entity generating contexts and other world states.""" 29 | 30 | def __init__(self, 31 | config, 32 | name = "BanditContext"): 33 | super().__init__(batch_ndims=1, name=name) 34 | self._num_bandits = config["num_bandits"] 35 | if self._num_bandits < 1: 36 | raise ValueError("num_bandits must be positive.") 37 | 38 | def specs(self): 39 | """Returns ValueSpec for the only time context.""" 40 | return ValueSpec(time=FieldSpec()) 41 | 42 | def initial_state(self, parameters): 43 | """Initializes the initial context by setting time to zero.""" 44 | del parameters 45 | return Value(time=0) 46 | 47 | def next_state(self, previous_state, parameters): 48 | """Updates the next context by increasing time by one.""" 49 | del parameters 50 | return Value(time=previous_state.get("time") + 1) 51 | -------------------------------------------------------------------------------- /recsim_ng/entities/bandits/generator.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Generator entity for bandit simulation.""" 17 | import abc 18 | from typing import Text 19 | 20 | from recsim_ng.core import value 21 | from recsim_ng.lib.tensorflow import entity 22 | 23 | Value = value.Value 24 | ValueSpec = value.ValueSpec 25 | 26 | 27 | class BanditGenerator(entity.Entity, metaclass=abc.ABCMeta): 28 | """An abstract generator entity responsible for parameters in the environment. 29 | 30 | In particular, parameters of distributions randomize rewards and contexts. 31 | """ 32 | 33 | def __init__(self, 34 | config, 35 | name = "BanditGenerator"): 36 | super().__init__(name=name) 37 | self._num_bandits = config["num_bandits"] 38 | self._num_arms = config["num_arms"] 39 | if self._num_bandits < 1: 40 | raise ValueError("num_bandits must be positive.") 41 | if self._num_arms < 2: 42 | raise ValueError("num_arms must be greater than one.") 43 | 44 | @abc.abstractmethod 45 | def specs(self): 46 | """Defines ValueSpec for all parameters.""" 47 | raise NotImplementedError() 48 | 49 | @abc.abstractmethod 50 | def parameters(self): 51 | """Returns a Value containing all parameters.""" 52 | raise NotImplementedError() 53 | -------------------------------------------------------------------------------- /recsim_ng/entities/bandits/problem.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Problem entity for bandit simulation.""" 17 | import abc 18 | from typing import Text 19 | 20 | import edward2 as ed # type: ignore 21 | from recsim_ng.core import value 22 | from recsim_ng.lib.tensorflow import entity 23 | import tensorflow as tf 24 | 25 | FieldSpec = value.FieldSpec 26 | Value = value.Value 27 | ValueSpec = value.ValueSpec 28 | 29 | 30 | class BanditProblem(entity.Entity, metaclass=abc.ABCMeta): 31 | """An abstract problem entity for randomizing and returning rewards.""" 32 | 33 | def __init__(self, 34 | config, 35 | name = "BanditProblem"): 36 | super().__init__(name=name) 37 | self._num_bandits = config["num_bandits"] 38 | self._num_arms = config["num_arms"] 39 | if self._num_bandits < 1: 40 | raise ValueError("num_bandits must be positive.") 41 | if self._num_arms < 2: 42 | raise ValueError("num_arms must be greater than one.") 43 | 44 | @abc.abstractmethod 45 | def _randomize(self): 46 | """Samples rewards for all arms.""" 47 | raise NotImplementedError() 48 | 49 | def initial_state(self, parameters, context): 50 | return self._randomize() 51 | 52 | def next_state(self, parameters, context): 53 | return self._randomize() 54 | 55 | def reward(self, arm, state): 56 | """Returns instantaneous reward of the pulled arm given the state.""" 57 | rewards = tf.squeeze( 58 | tf.gather( 59 | state.get("randomized_arm_rewards"), 60 | tf.expand_dims(arm.get("choice"), axis=-1), 61 | batch_dims=1)) 62 | return Value(rewards=ed.Deterministic(loc=rewards)) 63 | 64 | def specs(self): 65 | """Defines ValueSpec for both ``reward'' and ``state''.""" 66 | return ValueSpec(rewards=FieldSpec()).prefixed_with("reward") 67 | -------------------------------------------------------------------------------- /recsim_ng/entities/choice_models/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the choice model entities.""" 17 | from recsim_ng.entities.choice_models import affinities 18 | from recsim_ng.entities.choice_models import selectors 19 | -------------------------------------------------------------------------------- /recsim_ng/entities/recommendation/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing entities for recs.""" 17 | from recsim_ng.entities.recommendation import corpus 18 | from recsim_ng.entities.recommendation import metrics 19 | from recsim_ng.entities.recommendation import recommender 20 | from recsim_ng.entities.recommendation import user 21 | -------------------------------------------------------------------------------- /recsim_ng/entities/recommendation/corpus.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Corpus entity for recommendation simulation.""" 17 | import abc 18 | from typing import Callable, Text 19 | 20 | from recsim_ng.core import value 21 | from recsim_ng.lib.tensorflow import entity 22 | 23 | Value = value.Value 24 | ValueSpec = value.ValueSpec 25 | 26 | 27 | class Corpus(entity.Entity, metaclass=abc.ABCMeta): 28 | """An abstract corpus entity.""" 29 | 30 | def __init__(self, config, name = "Corpus"): 31 | self._config = config 32 | self._num_docs = config["num_docs"] 33 | self._num_topics = config["num_topics"] 34 | super().__init__(name=name) 35 | 36 | @abc.abstractmethod 37 | def specs(self): 38 | raise NotImplementedError() 39 | 40 | @abc.abstractmethod 41 | def initial_state(self): 42 | raise NotImplementedError() 43 | 44 | @abc.abstractmethod 45 | def next_state(self, previous_state, user_response, 46 | slate_docs): 47 | raise NotImplementedError() 48 | 49 | @abc.abstractmethod 50 | def available_documents(self, corpus_state): 51 | raise NotImplementedError() 52 | 53 | CorpusConstructor = Callable[[value.Config], Corpus] 54 | -------------------------------------------------------------------------------- /recsim_ng/entities/recommendation/metrics.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Metrics entity for recommendation simulation.""" 17 | import abc 18 | from typing import Callable, Text 19 | 20 | from recsim_ng.core import value 21 | from recsim_ng.lib.tensorflow import entity 22 | 23 | Value = value.Value 24 | ValueSpec = value.ValueSpec 25 | 26 | 27 | class RecsMetricsBase(entity.Entity, metaclass=abc.ABCMeta): 28 | """An abstract recommendation metrics entity.""" 29 | 30 | def __init__(self, 31 | config, 32 | name = 'Metrics'): 33 | self._num_users = config['num_users'] 34 | super().__init__(name=name) 35 | 36 | @abc.abstractmethod 37 | def specs(self): 38 | raise NotImplementedError() 39 | 40 | @abc.abstractmethod 41 | def initial_metrics(self): 42 | raise NotImplementedError() 43 | 44 | @abc.abstractmethod 45 | def next_metrics(self, previous_metrics, corpus_state, 46 | user_state, user_response, 47 | slate_docs): 48 | raise NotImplementedError() 49 | 50 | MetricsConstructor = Callable[[value.Config], RecsMetricsBase] 51 | -------------------------------------------------------------------------------- /recsim_ng/entities/recommendation/recommender.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Recommender entity for recommendation simulation.""" 17 | import abc 18 | from typing import Callable, Text 19 | 20 | from recsim_ng.core import value 21 | from recsim_ng.lib.tensorflow import entity 22 | 23 | Value = value.Value 24 | ValueSpec = value.ValueSpec 25 | 26 | 27 | class BaseRecommender(entity.Entity, metaclass=abc.ABCMeta): 28 | """An abstract recommender entity.""" 29 | 30 | def __init__(self, 31 | config, 32 | name = "BaseRecommender"): 33 | self._slate_size = config["slate_size"] 34 | self._num_users = config["num_users"] 35 | self._num_docs = config["num_docs"] 36 | super().__init__(name=name) 37 | 38 | @abc.abstractmethod 39 | def specs(self): 40 | raise NotImplementedError() 41 | 42 | @abc.abstractmethod 43 | def initial_state(self): 44 | raise NotImplementedError() 45 | 46 | @abc.abstractmethod 47 | def next_state(self, previous_state, user_response, 48 | slate_docs): 49 | raise NotImplementedError() 50 | 51 | @abc.abstractmethod 52 | def slate_docs(self, previous_state, user_obs, 53 | available_docs): 54 | raise NotImplementedError() 55 | 56 | RecommenderConstructor = Callable[[value.Config], BaseRecommender] 57 | -------------------------------------------------------------------------------- /recsim_ng/entities/recommendation/user.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """User entity for recommendation simulation.""" 17 | import abc 18 | from typing import Callable, Text 19 | 20 | from recsim_ng.core import value 21 | from recsim_ng.lib.tensorflow import entity 22 | 23 | Value = value.Value 24 | ValueSpec = value.ValueSpec 25 | 26 | 27 | class User(entity.Entity, metaclass=abc.ABCMeta): 28 | """An abstract user entity.""" 29 | 30 | def __init__(self, config, name = "User"): 31 | self._num_users = config["num_users"] 32 | self._num_topics = config["num_topics"] 33 | super().__init__(name=name) 34 | 35 | @abc.abstractmethod 36 | def specs(self): 37 | raise NotImplementedError() 38 | 39 | @abc.abstractmethod 40 | def initial_state(self): 41 | raise NotImplementedError() 42 | 43 | @abc.abstractmethod 44 | def next_state(self, previous_state, user_response, 45 | slate_docs): 46 | raise NotImplementedError() 47 | 48 | @abc.abstractmethod 49 | def next_response(self, previous_state, slate_docs): 50 | raise NotImplementedError() 51 | 52 | @abc.abstractmethod 53 | def observation(self, user_state): 54 | raise NotImplementedError() 55 | 56 | UserConstructor = Callable[[value.Config], User] 57 | -------------------------------------------------------------------------------- /recsim_ng/entities/state_models/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing the state model entities.""" 17 | from recsim_ng.entities.state_models import dynamic 18 | from recsim_ng.entities.state_models import estimation 19 | from recsim_ng.entities.state_models import state 20 | from recsim_ng.entities.state_models import static 21 | -------------------------------------------------------------------------------- /recsim_ng/entities/state_models/estimation_test.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Tests for recsim_ng.entities.state_models.dynamic.""" 17 | 18 | from recsim_ng.core import value 19 | from recsim_ng.entities.state_models import estimation 20 | import tensorflow as tf 21 | import tensorflow_probability as tfp 22 | 23 | tfd = tfp.distributions 24 | 25 | Value = value.Value 26 | 27 | 28 | class EstimationTest(tf.test.TestCase): 29 | 30 | def test_finite_history(self): 31 | state_model = estimation.FiniteHistoryStateModel( 32 | 3, observation_shape=(2,), batch_shape=(1, 3), dtype=tf.float32) 33 | i_state = state_model.initial_state() 34 | self.assertAllEqual( 35 | i_state.get('state'), tf.zeros((1, 3, 3, 2), dtype=tf.float32)) 36 | inputs = tf.ones((1, 3, 2)) 37 | next_state = state_model.next_state(i_state, Value(input=inputs)) 38 | self.assertAllClose( 39 | next_state.get('state')[:, :, -1], tf.ones((1, 3, 2), dtype=tf.float32)) 40 | self.assertAllClose( 41 | next_state.get('state')[:, :, :-1], 42 | tf.zeros((1, 3, 2, 2), dtype=tf.float32)) 43 | inputs = 2.0 * tf.ones((1, 3, 2)) 44 | next_next_state = state_model.next_state(next_state, Value(input=inputs)) 45 | self.assertAllClose( 46 | next_next_state.get('state')[:, :, 2], 2.0 * tf.ones( 47 | (1, 3, 2), dtype=tf.float32)) 48 | self.assertAllClose( 49 | next_next_state.get('state')[:, :, 1], 50 | tf.ones((1, 3, 2), dtype=tf.float32)) 51 | self.assertAllClose( 52 | next_next_state.get('state')[:, :, 0], 53 | tf.zeros((1, 3, 2), dtype=tf.float32)) 54 | # TODO(recsim-dev): expand coverage. 55 | 56 | 57 | if __name__ == '__main__': 58 | tf.test.main() 59 | -------------------------------------------------------------------------------- /recsim_ng/entities/state_models/test_util.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Common testing code for recsim_ng.entities.state_models.""" 17 | 18 | import edward2 as ed # type: ignore 19 | from recsim_ng.core import value 20 | import tensorflow as tf 21 | 22 | Value = value.Value 23 | 24 | 25 | class StateTestCommon(tf.test.TestCase): 26 | """Common testing code for state model tests.""" 27 | 28 | def assert_log_prob_shape_compliance(self, initial_state, 29 | next_state): 30 | """Validates that initial and next state have the same log prob shape.""" 31 | for key in initial_state.as_dict.keys(): 32 | i_value = initial_state.get(key) 33 | is_i_random_var = isinstance(i_value, ed.RandomVariable) 34 | n_value = next_state.get(key) 35 | is_n_random_var = isinstance(n_value, ed.RandomVariable) 36 | # Either both or neither fields have to be a RV. 37 | self.assertEqual(is_i_random_var, is_n_random_var) 38 | if is_i_random_var: 39 | i_log_prob = i_value.distribution.log_prob(i_value) 40 | n_log_prob = n_value.distribution.log_prob(n_value) 41 | # the initial and next state have to have the same log prob shape. 42 | self.assertAllEqual(i_log_prob.shape, n_log_prob.shape) 43 | -------------------------------------------------------------------------------- /recsim_ng/lib/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing recsim_ng.lib.*.""" 17 | from recsim_ng.lib import data 18 | from recsim_ng.lib import runtime 19 | -------------------------------------------------------------------------------- /recsim_ng/lib/jax/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing recsim_ng.lib.tensorflow.*.""" 17 | from recsim_ng.lib.jax import runtime 18 | -------------------------------------------------------------------------------- /recsim_ng/lib/python/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing recsim_ng.lib.python.*.""" 17 | from recsim_ng.lib.python import runtime 18 | -------------------------------------------------------------------------------- /recsim_ng/lib/python/runtime.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Python-based runtime.""" 17 | 18 | from typing import Optional 19 | 20 | from recsim_ng.core import network as network_lib 21 | from recsim_ng.lib import runtime 22 | 23 | Network = network_lib.Network 24 | NetworkValue = network_lib.NetworkValue 25 | 26 | 27 | class PythonRuntime(runtime.Runtime): 28 | """A Python-based runtime for a `Network` of `Variable`s.""" 29 | 30 | def __init__(self, network): 31 | """Creates a `PythonRuntime` for the given `Network`.""" 32 | self._network = network 33 | 34 | def execute(self, 35 | num_steps, 36 | starting_value = None): 37 | """Implements `Runtime`.""" 38 | v = starting_value or self._network.initial_step() 39 | for _ in range(num_steps): 40 | v = self._network.step(v) 41 | return v 42 | -------------------------------------------------------------------------------- /recsim_ng/lib/runtime.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Interface for runtimes.""" 17 | 18 | import abc 19 | 20 | from typing import Optional 21 | 22 | from recsim_ng.core import network 23 | 24 | NetworkValue = network.NetworkValue 25 | 26 | 27 | class Runtime(metaclass=abc.ABCMeta): 28 | """A runtime for a `Network` of `Variable`s.""" 29 | 30 | @abc.abstractmethod 31 | def execute(self, 32 | num_steps, 33 | starting_value = None): 34 | """The `NetworkValue` at `num_steps` steps after `starting_value`. 35 | 36 | Args: 37 | num_steps: The number of steps to execute. 38 | starting_value: The `NetworkValue` at step 0, or `Network.initial_step()` 39 | if not provided explicitly. 40 | 41 | Returns: 42 | The `NetworkValue` at step `num_steps`. 43 | """ 44 | raise NotImplementedError() 45 | -------------------------------------------------------------------------------- /recsim_ng/lib/tensorflow/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing recsim_ng.lib.tensorflow.*.""" 17 | from recsim_ng.lib.tensorflow import data 18 | from recsim_ng.lib.tensorflow import entity 19 | from recsim_ng.lib.tensorflow import log_probability 20 | from recsim_ng.lib.tensorflow import runtime 21 | from recsim_ng.lib.tensorflow import util 22 | -------------------------------------------------------------------------------- /recsim_ng/lib/tensorflow/data.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Tools to import data and convert them to Variables.""" 17 | 18 | import collections 19 | 20 | from typing import cast 21 | 22 | from recsim_ng.lib import data 23 | 24 | import tensorflow as tf 25 | 26 | 27 | class TFDataset(data.DataSequence): 28 | """A `DataSequence` yielding consecutive elements of a `tf.data.Dataset`. 29 | 30 | In this example, `dataset` is a `tf.data.Dataset` providing input data, and 31 | `y` is a variable with a field named `b` whose value at time step `t` is the 32 | result of applying the function `convert` to the `t`th element of `dataset`. 33 | ``` 34 | y = data_variable( 35 | name="y", 36 | spec=ValueSpec(b=FieldSpec()), 37 | data_sequence=TFDataset(dataset), 38 | output_fn=lambda d: Value(b=convert(d))) 39 | ``` 40 | """ 41 | 42 | def __init__(self, dataset): 43 | self._dataset = dataset 44 | 45 | def first_index(self): 46 | # TF2.0 doesn't propertly export the necessary pytype stubs for 47 | # tf.data.Dataset, so iter() doesn't realize the __iter__ magic method is 48 | # implemented. Casting to Iterable fixes this, but then the tf.data.Iterator 49 | # type needs to be reassociated with the return value, hence the double use 50 | # of cast(). When the pytype stubs are propertly exported, the lines below 51 | # invoking cast() can be removed. 52 | dataset = self._dataset 53 | dataset = cast(collections.abc.Iterable, self._dataset) 54 | iterator = iter(dataset) 55 | iterator = cast(tf.data.Iterator, iterator) 56 | return iterator 57 | 58 | def next_index(self, index): 59 | return index 60 | 61 | def get(self, index): 62 | return index.get_next() 63 | -------------------------------------------------------------------------------- /recsim_ng/lib/tensorflow/data_test.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Tests for the data module.""" 17 | 18 | from absl.testing import parameterized 19 | from recsim_ng.lib import data 20 | from recsim_ng.lib.tensorflow import data as tf_data 21 | from recsim_ng.lib.tensorflow import field_spec 22 | from recsim_ng.lib.tensorflow import runtime 23 | 24 | import tensorflow as tf 25 | 26 | FieldSpec = field_spec.FieldSpec 27 | ValueSpec = data.ValueSpec 28 | Value = data.Value 29 | 30 | Network = runtime.Network 31 | TFRuntime = runtime.TFRuntime 32 | 33 | TFDataset = tf_data.TFDataset 34 | 35 | 36 | class DataTest(parameterized.TestCase, tf.test.TestCase): 37 | 38 | @parameterized.parameters(False, True) 39 | def test_tf_dataset(self, graph_compile): 40 | dataset = tf.data.Dataset.from_tensor_slices([1, 2, 3]) 41 | x = data.data_variable( 42 | name="x", 43 | spec=ValueSpec(a=FieldSpec()), 44 | data_sequence=TFDataset(dataset=dataset), 45 | output_fn=lambda t: Value(a=t * t)) 46 | r = TFRuntime(network=Network(variables=[x]), graph_compile=graph_compile) 47 | self.assertEqual(r.execute(num_steps=0)["x"].get("a"), 1) 48 | self.assertEqual(r.execute(num_steps=1)["x"].get("a"), 4) 49 | self.assertEqual(r.execute(num_steps=2)["x"].get("a"), 9) 50 | 51 | 52 | if __name__ == "__main__": 53 | tf.test.main() 54 | -------------------------------------------------------------------------------- /recsim_ng/lib/tensorflow/runtime_test.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Tests for runtime.""" 17 | 18 | from recsim_ng.core import network as network_lib 19 | from recsim_ng.core import value 20 | from recsim_ng.core import variable 21 | from recsim_ng.lib.tensorflow import field_spec 22 | from recsim_ng.lib.tensorflow import runtime 23 | import tensorflow as tf 24 | 25 | Variable = variable.Variable 26 | Value = value.Value 27 | ValueSpec = value.ValueSpec 28 | DynamicFieldSpec = field_spec.DynamicFieldSpec 29 | FieldSpec = field_spec.FieldSpec 30 | 31 | 32 | class RuntimeTest(tf.test.TestCase): 33 | 34 | def test_invariants(self): 35 | # Checks whether shape invariants are correctly piped down to the runtime 36 | # level to allow variable shapes in graph mode execution. 37 | test_var = Variable( 38 | name='TestVar', 39 | spec=ValueSpec(x=DynamicFieldSpec(2, [ 40 | 1, 41 | ]), y=FieldSpec())) 42 | test_var.initial_value = variable.value( 43 | lambda: Value(x=tf.ones((2, 1)), y=2)) 44 | test_var.value = variable.value( 45 | lambda prev: Value(x=tf.ones((2, prev.get('y'))), y=prev.get('y') + 1), 46 | (test_var.previous,)) 47 | # Check in eager mode. 48 | tf_runtime = runtime.TFRuntime( 49 | network_lib.Network([ 50 | test_var, 51 | ]), graph_compile=False) 52 | result = tf_runtime.execute(5)['TestVar'] 53 | self.assertAllEqual(result.get('x'), tf.ones((2, 6))) 54 | 55 | 56 | if __name__ == '__main__': 57 | tf.test.main() 58 | -------------------------------------------------------------------------------- /recsim_ng/stories/__init__.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """Module importing stories various simulation.""" 17 | from recsim_ng.stories import bandit_simulation 18 | from recsim_ng.stories import recommendation_simulation 19 | from recsim_ng.stories import static_recs_simulation 20 | -------------------------------------------------------------------------------- /recsim_ng/stories/static_recs_simulation.py: -------------------------------------------------------------------------------- 1 | # coding=utf-8 2 | # Copyright 2022 The RecSim Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """A story for one-shot recommendation.""" 17 | from typing import Collection 18 | from recsim_ng.core import value 19 | from recsim_ng.core import variable 20 | from recsim_ng.entities.recommendation import corpus as corpus_lib 21 | from recsim_ng.entities.recommendation import user as user_lib 22 | 23 | Variable = variable.Variable 24 | 25 | 26 | def static_recs_story( 27 | config, user_ctor, 28 | corpus_ctor): 29 | """A simple recommendation story with only static entities.""" 30 | # Construct entities. 31 | user = user_ctor(config) 32 | user_spec = user.specs() 33 | corpus = corpus_ctor(config) 34 | corpus_spec = corpus.specs() 35 | 36 | # Variables. 37 | user_response = Variable(name="user response", spec=user_spec.get("response")) 38 | user_state = Variable(name="user state", spec=user_spec.get("state")) 39 | corpus_state = Variable(name="corpus state", spec=corpus_spec.get("state")) 40 | available_docs = Variable( 41 | name="available docs", spec=corpus_spec.get("available_docs")) 42 | 43 | # 0. Initial state. 44 | corpus_state.initial_value = variable.value(corpus.initial_state) 45 | available_docs.initial_value = variable.value(corpus.available_documents, 46 | (corpus_state,)) 47 | user_state.initial_value = variable.value(user.initial_state) 48 | user_response.initial_value = variable.value(user.next_response, 49 | (user_state, available_docs)) 50 | 51 | return [user_state, user_response, corpus_state, available_docs] 52 | --------------------------------------------------------------------------------