Skip to content

Commit

Permalink
Internal change
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 426406471
  • Loading branch information
The ML Fairness Gym Team authored and yhalpern committed Feb 4, 2022
1 parent 5b1cd33 commit 38eaf45
Show file tree
Hide file tree
Showing 107 changed files with 170 additions and 158 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ [email protected].

# Versions
v0.1.0: Initial release.
v0.1.1: Update to use gym 0.19.0.
3 changes: 1 addition & 2 deletions agents/allocation_agents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

import copy
Expand Down
2 changes: 1 addition & 1 deletion agents/allocation_agents_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions agents/classifier_agents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

import collections
Expand Down
2 changes: 1 addition & 1 deletion agents/classifier_agents_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
5 changes: 2 additions & 3 deletions agents/college_admission_jury.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

import core
Expand Down Expand Up @@ -324,7 +323,7 @@ def __init__(self,
self._subsidy_beta = subsidy_beta
self._gaming_control = gaming_control

if burnin < 2:
if burnin < 2: # pytype: disable=unsupported-operands
raise ValueError(
'This agent expects a longer burnin period, to work as expected.')

Expand Down
2 changes: 1 addition & 1 deletion agents/college_admission_jury_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions agents/infectious_disease_agents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

import copy
Expand Down
2 changes: 1 addition & 1 deletion agents/infectious_disease_agents_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions agents/oracle_lending_agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

from agents import classifier_agents
Expand Down
2 changes: 1 addition & 1 deletion agents/oracle_lending_agent_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/random_agents.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/random_agents_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/batched_movielens_rnn_agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/batched_movielens_rnn_agent_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
11 changes: 8 additions & 3 deletions agents/recommenders/evaluation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -125,9 +125,14 @@ def evaluate_agent(agent, env, alpha, num_users=100, deterministic=False,


def plot_trajectories(rewards, health, figure_file_obj):
"""Create a KDE or scatter plot of health rewards vs health."""
plt.figure()
g = sns.jointplot(x=rewards, y=health, kind='kde')
g.plot_joint(plt.scatter, c='grey', s=30, linewidth=1, marker='+')
try:
g = sns.jointplot(x=rewards, y=health, kind='kde')
g.plot_joint(plt.scatter, c='grey', s=30, linewidth=1, marker='+')
except np.linalg.LinAlgError:
# If the data does not support KDE plotting, just use scatter.
g = sns.jointplot(x=rewards, y=health, kind='scatter')
g.ax_joint.collections[0].set_alpha(0)
g.set_axis_labels('$Reward$', '$Health$')
if figure_file_obj:
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/evaluation_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/model_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/rnn_agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/rnn_agent_tests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/rnn_cvar_agent.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/recommenders/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/threshold_policies.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion agents/threshold_policies_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
13 changes: 9 additions & 4 deletions core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -18,7 +18,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

import copy
Expand Down Expand Up @@ -270,11 +269,17 @@ class FairnessEnv(gym.Env):

def __init__(self,
params = None,
initialize_observation_space = True):
initialize_observation_space = True,
init_action_space_random_state = True):
self.history = [] # type: HistoryType
self.state = None # type: Optional[State]
self.reward_fn = None # type: Optional[RewardFn]

# Sometimes the action_space property is not ready here, e.g. RecsimWrapper
if init_action_space_random_state:
# gym.Space.np_random is created lazily, make sure it is created here.
_ = self.action_space.np_random

if initialize_observation_space:
self.observation_space = gym.spaces.Dict(self.observable_state_vars)
# Copy params so if environment mutates params it is contained to this
Expand Down Expand Up @@ -601,5 +606,5 @@ def seed(self, value):
def sample_from(self, space):
"""Sample from a space using the agent's own state."""
space = copy.deepcopy(space)
space.np_random = self.rng
space._np_random = self.rng # pylint: disable=protected-access
return space.sample()
2 changes: 1 addition & 1 deletion core_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions distributions.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -17,7 +17,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

from absl import logging
Expand Down
2 changes: 1 addition & 1 deletion distributions_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions environments/attention_allocation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -36,7 +36,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

import copy
Expand Down
2 changes: 1 addition & 1 deletion environments/attention_allocation_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions environments/college_admission.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -23,7 +23,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

import copy
Expand Down
2 changes: 1 addition & 1 deletion environments/college_admission_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions environments/infectious_disease.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

import copy
Expand Down
2 changes: 1 addition & 1 deletion environments/infectious_disease_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
3 changes: 1 addition & 2 deletions environments/lending.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# coding=utf-8
# Copyright 2020 The ML Fairness Gym Authors.
# Copyright 2022 The ML Fairness Gym Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,6 @@

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

import copy
Expand Down
Loading

0 comments on commit 38eaf45

Please sign in to comment.