def _setup_directories(config):
    file_util.makedirs(config['results_dir'])
    with file_util.open(
            os.path.join(config['results_dir'],
                         config['experiment_name'] + '_info.txt'),
            'w') as outfile:
        outfile.write(fg_core.to_json(config))
Exemple #2
0
def _setup_directories(config):
    try:
        file_util.makedirs(config['results_dir'])
        file_util.makedirs('./runs/{}'.format(config['experiment_name']))
    except FileExistsError:
        pass
    with file_util.open(
            os.path.join(config['results_dir'],
                         config['experiment_name'] + '_info.txt'),
            'w') as outfile:
        outfile.write(fg_core.to_json(config))
Exemple #3
0
def write_csv_output(dataframes, directory):
    """Write csv file outputs."""
    movies, users, ratings = dataframes
    file_util.makedirs(directory)

    del movies['tag_id']  # This column isn't necessary.

    users.to_csv(file_util.open(os.path.join(directory, 'users.csv'), 'w'),
                 index=False,
                 columns=['userId'])
    movies.to_csv(file_util.open(os.path.join(directory, 'movies.csv'), 'w'),
                  index=False)
    ratings.to_csv(file_util.open(os.path.join(directory, 'ratings.csv'), 'w'),
                   index=False)
def write_csv_output(dataframe, filename, directory):
    """Write dataframe to CSV.

  Args:
    dataframe: pandas DataFrame
    filename: name of the file (should end in ".csv")
    directory: directory to write to
  """
    if not filename.endswith('.csv'):
        raise ValueError('Filename does not end in .csv')
    file_util.makedirs(directory)

    dataframe.to_csv(file_util.open(os.path.join(directory, filename), 'w'),
                     index=False)
def main(argv):
  if len(argv) > 1:
    raise app.UsageError('Too many command-line arguments.')

  plotting_dir = os.path.join(FLAGS.plotting_dir, '%d' % FLAGS.seed)
  file_util.makedirs(plotting_dir)
  lending_plots.plot_steady_state_distribution(plotting_dir)

  experiment_fn = functools.partial(
      lending.Experiment,
      cluster_probabilities=DELAYED_IMPACT_CLUSTER_PROBS,
      group_0_prob=0.5,
      interest_rate=1.0,
      bank_starting_cash=10000,
      seed=FLAGS.seed,
      num_steps=FLAGS.num_steps,
      # No need for burn in since the agent is an oracle agent.
      burnin=1,
      cluster_shift_increment=FLAGS.cluster_shift_increment,
      include_cumulative_loans=True,
      return_json=False)

  logging.info(
      'experiment params %s %s',
      experiment_fn(threshold_policy=lending.EQUALIZE_OPPORTUNITY).asdict(),
      experiment_fn(threshold_policy=lending.MAXIMIZE_REWARD).asdict())
  env, agent = experiment_fn(
      threshold_policy=lending.EQUALIZE_OPPORTUNITY).scenario_builder()
  logging.info('environment params %s', env.initial_params.asdict())
  logging.info('agent params %s', agent.params.asdict())

  # Run two long-running experiments and then use the results for all further
  # plotting.
  equality_of_opportunity_result = experiment_fn(
      threshold_policy=lending.EQUALIZE_OPPORTUNITY).run()
  # The static experiment removes the delayed effects of defaulting on future
  # credit scores.
  static_equality_of_opportunity_result = experiment_fn(
      threshold_policy=lending.EQUALIZE_OPPORTUNITY,
      cluster_shift_increment=0).run()
  maximize_reward_result = experiment_fn(
      threshold_policy=lending.MAXIMIZE_REWARD).run()

  lending_plots.do_plotting(
      maximize_reward_result,
      equality_of_opportunity_result,
      static_equality_of_opportunity_result,
      plotting_dir,
      options=ACM_FAT_2020_PLOTS)
Exemple #6
0
 def test_delete_recursively(self):
   test_root = self.create_tempdir().full_path
   file_util.makedirs('%s/my/favorite/multilevel/directory' % test_root)
   file_util.delete_recursively('%s/my/favorite' % test_root)
   self.assertTrue(file_util.exists('%s/my' % test_root))
   self.assertFalse(file_util.exists('%s/my/favorite' % test_root))
Exemple #7
0
 def test_makedirs(self):
   test_root = self.create_tempdir().full_path
   file_util.makedirs('%s/my/multilevel/directory' % test_root)
   self.assertTrue(file_util.exists('%s/my/multilevel/directory' % test_root))