Source Code for Compassion and Respect

Tim Freeman

Last modified Wed Apr 2 20:53:15 2008

Canonical URL: http://fungible.com/respect/code/index.html

Copyright (c) 2007 Tim Freeman MIT License

Contents

Introduction

This directory contains the source code for the decision procedure described in Using Compassion and Respect to Motivate an Artificial Intelligence. Since this is just a decision procedure, even on toy problems it will not terminate in the forseeable future if run on physically realizable computers. However, parts of the code can be separately tested, and in aggregate all of the unit tests listed below touch all lines of the code.

This file describes how to run the regression tests, and it provides an overview that makes it easy to browse individual source files either from the web or after downloading the sources.

Running Tests

The code was tested on a 600 MhZ Pentium system running GNU/Linux. It is written in Python, and tested against Python 2.3.5. Using GNU/Linux for testing ought to be inessential, but you will need Python, which can be downloaded from http://www.python.org. To run the tests, do the following:

If you have problems with this, or you have observed it to work with a different version of Python or a different operating system, send me email at tim@fungible.com.

Individual Source Files

We have three categories of Python source here:

The Decision Procedure

NameBytesLinesDescription
animate.py323679Draw the state of a turing machine as it executes, so they can be debugged.
bits.py6082176Low-level data manipulation. Mostly bit-picking for turing machines.
compile.py5906131Rudimentary assembler for turing machines.
compile_and_run.py246555Convenience functions to compile and run a turing machine.
constants.py135029Constants used in turing machine assembler syntax.
infer_utility.py14196269Code for inferring an agent's utility function from his voluntary behavior and perceptions. Uses mind_body to first infer the voluntary behavior.
interleave.py5511117Turing machine writing exercise. Given an input tape with bits abcd, return a tape three times as long with bits 00a00b00c00d.
machine.py5482128Turing machine interpreter.
mind_body.py12973265Infer an agent's voluntary actions and perceptions. The inputs are training data to extrapolate from and observations of the world (including the agent). Uses physics.py.
physics.py6859152General decision procedure for inferring laws of physics given observations of the world.
plan_generators.py6763160Utilities to generate plans.
planner.py13986275Given the ability to infer utility functions for the known agents in the world (typically from infer_utility.py) and a plan for combining the utilities of the individual agents into a grand total (from utility_combiners.py), figure out what to do next.
speed_prior.py4943112Speed prior explanations. These incorporate a turing machine and a runtime limit, and they present methods for running subject to the time limit and for computing the complexity.
turing_tape.py4498120The input or output tape of a Turing machine, made into an object for code readability and so we get errors sooner if we're passing the wrong data around.
utility_combiners.py358173Various ways to combine together the utilities of all of the agents other than the AI to get the AI's utility.
video_prediction.py454299A warm-up exercise in writing a decision procedure that could in principle extrapolate future frames of video based on past frames.
video_prediction_act.py4836104Like video_prediction, except the AI's past actions are given as input and therefore do not need to be explained.
total1072092344

Unit Tests

A file with a name like foo_test.py is almost always a test for foo.py.

NameBytesLinesDescription
animate_test.py230451
baby_catch_test.py31448715Test cases for the reasoning about uncertainty.
bits_test.py354691
compile_and_run_test.py5608128
compile_test.py196740
grocery_test.py17491463Test cases for respect (planner.py and utility_combiners.py) involving grocery shopping. Explanations and the world-model are represented as python code instead of turing machines.
infer_utility_test.py39892974
interleave_test.py237246
machine_test.py274858
mind_body_test.py140326
physics_test.py180237An incomplete test for physics.py. For the most part, physics.py is tested as a consequence of being used by other classes. The code here just tests a few things that were missed elsewhere.
plan_generators_test.py368595
planner_test.py142426
speed_prior_test.py268464
test_util_test.py139828
turing_tape_test.py348292
utility_combiners_test.py198952
video_prediction_act_test.py4542110
video_prediction_test.py9894224
total1396793320

Administrative Files

NameBytesLinesDescription
free_html.py9947219Script for generating the free use cases.
htmlgen.py9668245Shared code between the various HTML files.
index_html.py6390165Script for generating index.html.
license_check.py321180Check that the given files incorporate copies of the LICENSE file. If -fix is passed, modify files to make them have a license.
license_text.py189650Code for formatting the license.
paper_html.py887791935Script for generating the main paper.
redundant_html.py5125107Script for generating the redundant use cases.
regress.py3949110The top level of the test harness. Useful if you want to run many tests or run with coverage analysis.
test_util.py289274Utilities for unit tests to call.
util.py139232Utility functions for document generation.
total1332493017

Other Files

If you want to regenerate this document from source, or you want to repackage a variation on the source code, read the Makefile.

coverage.py.patch includes some workarounds for Python variable naming bugs that the coverage analyzer aggravates. These bugs exist in Python 2.3.5 and may not exist in newer versions.

License

Copyright (c) 2007 Tim Freeman

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

(This is the standard MIT License, copied from http://www.opensource.org/licenses/mit-license.php on 24 Apr 2007.)

Valid HTML 4.01 Strict