From 412c349fcbdf9a4d07f640b186f1a3a825639d83 Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Mon, 12 Jun 2017 20:28:04 +0300 Subject: [PATCH 1/9] DataFile Update --- utils.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/utils.py b/utils.py index aa24a55bd..698560569 100644 --- a/utils.py +++ b/utils.py @@ -383,20 +383,13 @@ def print_table(table, header=None, sep=' ', numfmt='{}'): str(x), j)(size) for (j, size, x) in zip(justs, sizes, row))) -def AIMAFile(components, mode='r'): - """Open a file based at the AIMA root directory.""" +def open_data(name, mode='r'): aima_root = os.path.dirname(__file__) - - aima_file = os.path.join(aima_root, *components) + aima_file = os.path.join(aima_root, *['aima-data', name]) return open(aima_file) -def DataFile(name, mode='r'): - "Return a file in the AIMA /aima-data directory." - return AIMAFile(['aima-data', name], mode) - - # ______________________________________________________________________________ # Expressions From b3a52466fc8e2d3a18099cc724ac9a62a0703ab3 Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Mon, 12 Jun 2017 20:28:35 +0300 Subject: [PATCH 2/9] Update learning.py --- learning.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/learning.py b/learning.py index afc0caceb..38ae1780e 100644 --- a/learning.py +++ b/learning.py @@ -4,7 +4,7 @@ removeall, unique, product, mode, argmax, argmax_random_tie, isclose, gaussian, dotproduct, vector_add, scalar_vector_product, weighted_sample_with_replacement, weighted_sampler, num_or_str, normalize, clip, sigmoid, print_table, - DataFile, sigmoid_derivative + open_data, sigmoid_derivative ) import copy @@ -95,7 +95,7 @@ def __init__(self, examples=None, attrs=None, attrnames=None, target=-1, if isinstance(examples, str): self.examples = parse_csv(examples) elif examples is None: - self.examples = parse_csv(DataFile(name + '.csv').read()) + self.examples = parse_csv(open_data(name + '.csv').read()) else: self.examples = examples # Attrs are the indices of examples, unless otherwise stated. @@ -949,7 +949,7 @@ def cross_validation_wrapper(learner, dataset, k=10, trials=1): err_val = [] err_train = [] size = 1 - + while True: errT, errV = cross_validation(learner, size, dataset, k) # Check for convergence provided err_val is not empty From ca0f345c864ed7b9ec5110030caeb8ad3da86657 Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Mon, 12 Jun 2017 20:29:06 +0300 Subject: [PATCH 3/9] Update search.py --- search.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/search.py b/search.py index 2d5d7a127..932054874 100644 --- a/search.py +++ b/search.py @@ -6,7 +6,7 @@ from utils import ( is_in, argmin, argmax, argmax_random_tie, probability, weighted_sampler, - memoize, print_table, DataFile, Stack, FIFOQueue, PriorityQueue, name, + memoize, print_table, open_data, Stack, FIFOQueue, PriorityQueue, name, distance ) @@ -1044,7 +1044,7 @@ class BoggleFinder: def __init__(self, board=None): if BoggleFinder.wordlist is None: - BoggleFinder.wordlist = Wordlist(DataFile("EN-text/wordlist.txt")) + BoggleFinder.wordlist = Wordlist(open_data("EN-text/wordlist.txt")) self.found = {} if board: self.set_board(board) From 824d3b0580352e6ade8f4317960ddf262f9b38bf Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Mon, 12 Jun 2017 20:30:00 +0300 Subject: [PATCH 4/9] Update test_learning.py --- tests/test_learning.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_learning.py b/tests/test_learning.py index fef6ba3bb..0709d0b5a 100644 --- a/tests/test_learning.py +++ b/tests/test_learning.py @@ -1,7 +1,7 @@ import pytest import math import random -from utils import DataFile +from utils import open_data from learning import * @@ -18,6 +18,7 @@ def test_euclidean(): distance = euclidean_distance([0, 0, 0], [0, 0, 0]) assert distance == 0 + def test_rms_error(): assert rms_error([2, 2], [2, 2]) == 0 assert rms_error((0, 0), (0, 1)) == math.sqrt(0.5) @@ -25,6 +26,7 @@ def test_rms_error(): assert rms_error((0, 0), (0, -1)) == math.sqrt(0.5) assert rms_error((0, 0.5), (0, -0.5)) == math.sqrt(0.5) + def test_manhattan_distance(): assert manhattan_distance([2, 2], [2, 2]) == 0 assert manhattan_distance([0, 0], [0, 1]) == 1 @@ -32,6 +34,7 @@ def test_manhattan_distance(): assert manhattan_distance([0, 0], [0, -1]) == 1 assert manhattan_distance([0, 0.5], [0, -0.5]) == 1 + def test_mean_boolean_error(): assert mean_boolean_error([1, 1], [0, 0]) == 1 assert mean_boolean_error([0, 1], [1, 0]) == 1 @@ -39,6 +42,7 @@ def test_mean_boolean_error(): assert mean_boolean_error([0, 0], [0, 0]) == 0 assert mean_boolean_error([1, 1], [1, 1]) == 0 + def test_mean_error(): assert mean_error([2, 2], [2, 2]) == 0 assert mean_error([0, 0], [0, 1]) == 0.5 @@ -53,7 +57,7 @@ def test_exclude(): def test_parse_csv(): - Iris = DataFile('iris.csv').read() + Iris = open_data('iris.csv').read() assert parse_csv(Iris)[0] == [5.1, 3.5, 1.4, 0.2, 'setosa'] From c95947ebfdb67e465063e580bbc67a25c45a54c7 Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Mon, 12 Jun 2017 20:30:34 +0300 Subject: [PATCH 5/9] Update test_text.py --- tests/test_text.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_text.py b/tests/test_text.py index 757e6fe17..2b664cbf6 100644 --- a/tests/test_text.py +++ b/tests/test_text.py @@ -3,11 +3,11 @@ import random from text import * -from utils import isclose, DataFile +from utils import isclose, open_data def test_text_models(): - flatland = DataFile("EN-text/flatland.txt").read() + flatland = open_data("EN-text/flatland.txt").read() wordseq = words(flatland) P1 = UnigramTextModel(wordseq) P2 = NgramTextModel(2, wordseq) @@ -141,7 +141,7 @@ def test_char_models(): def test_viterbi_segmentation(): - flatland = DataFile("EN-text/flatland.txt").read() + flatland = open_data("EN-text/flatland.txt").read() wordseq = words(flatland) P = UnigramTextModel(wordseq) text = "itiseasytoreadwordswithoutspaces" @@ -158,7 +158,7 @@ def test_shift_encoding(): def test_shift_decoding(): - flatland = DataFile("EN-text/flatland.txt").read() + flatland = open_data("EN-text/flatland.txt").read() ring = ShiftDecoder(flatland) msg = ring.decode('Kyzj zj r jvtivk dvjjrxv.') @@ -166,12 +166,12 @@ def test_shift_decoding(): def test_permutation_decoder(): - gutenberg = DataFile("EN-text/gutenberg.txt").read() - flatland = DataFile("EN-text/flatland.txt").read() - + gutenberg = open_data("EN-text/gutenberg.txt").read() + flatland = open_data("EN-text/flatland.txt").read() + pd = PermutationDecoder(canonicalize(gutenberg)) assert pd.decode('aba') in ('ece', 'ete', 'tat', 'tit', 'txt') - + pd = PermutationDecoder(canonicalize(flatland)) assert pd.decode('aba') in ('ded', 'did', 'ece', 'ele', 'eme', 'ere', 'eve', 'eye', 'iti', 'mom', 'ses', 'tat', 'tit') @@ -183,7 +183,7 @@ def test_rot13_encoding(): def test_rot13_decoding(): - flatland = DataFile("EN-text/flatland.txt").read() + flatland = open_data("EN-text/flatland.txt").read() ring = ShiftDecoder(flatland) msg = ring.decode(rot13('Hello, world!')) From cc1f52d8bc2465142b88618439165ccfc33c0188 Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Mon, 12 Jun 2017 20:31:13 +0300 Subject: [PATCH 6/9] Add files via upload --- tests/pytest.ini | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/pytest.ini diff --git a/tests/pytest.ini b/tests/pytest.ini new file mode 100644 index 000000000..7043be6c8 --- /dev/null +++ b/tests/pytest.ini @@ -0,0 +1,3 @@ +[pytest] +filterwarnings = + ignore::ResourceWarning \ No newline at end of file From 9c4be7bab4d7cd5481a87a3791aa042e735080be Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Mon, 12 Jun 2017 20:39:52 +0300 Subject: [PATCH 7/9] Update text.ipynb --- text.ipynb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/text.ipynb b/text.ipynb index 0edb43b05..0376738cd 100644 --- a/text.ipynb +++ b/text.ipynb @@ -24,7 +24,7 @@ "outputs": [], "source": [ "from text import *\n", - "from utils import DataFile" + "from utils import open_data" ] }, { @@ -84,7 +84,7 @@ } ], "source": [ - "flatland = DataFile(\"EN-text/flatland.txt\").read()\n", + "flatland = open_data(\"EN-text/flatland.txt\").read()\n", "wordseq = words(flatland)\n", "\n", "P1 = UnigramTextModel(wordseq)\n", @@ -186,7 +186,7 @@ } ], "source": [ - "flatland = DataFile(\"EN-text/flatland.txt\").read()\n", + "flatland = open_data(\"EN-text/flatland.txt\").read()\n", "wordseq = words(flatland)\n", "P = UnigramTextModel(wordseq)\n", "text = \"itiseasytoreadwordswithoutspaces\"\n", @@ -358,7 +358,7 @@ } ], "source": [ - "flatland = DataFile(\"EN-text/flatland.txt\").read()\n", + "flatland = open_data(\"EN-text/flatland.txt\").read()\n", "decoder = ShiftDecoder(flatland)\n", "\n", "decoded_message = decoder.decode(ciphertext)\n", From 19d12de4443f827c581f4bb40473e4dec74bd9d5 Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Mon, 12 Jun 2017 20:40:06 +0300 Subject: [PATCH 8/9] Update search-4e.ipynb --- search-4e.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/search-4e.ipynb b/search-4e.ipynb index 100e0bcda..785596ef0 100644 --- a/search-4e.ipynb +++ b/search-4e.ipynb @@ -346,7 +346,7 @@ "outputs": [], "source": [ "from search import *\n", - "sgb_words = DataFile(\"EN-text/sgb-words.txt\")" + "sgb_words = open_data(\"EN-text/sgb-words.txt\")" ] }, { From 93e9e8eeb91d5939985dc21e5e7f47d4a5cb5189 Mon Sep 17 00:00:00 2001 From: Antonis Maronikolakis Date: Mon, 12 Jun 2017 20:44:25 +0300 Subject: [PATCH 9/9] Create CONTRIBUTING.md --- CONTRIBUTING.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 892b64d24..be78ab976 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -74,21 +74,21 @@ Running the Test-Suite ===================== The minimal requirement for running the testsuite is ``py.test``. You can -install it with:: +install it with: pip install pytest -Clone this repository:: +Clone this repository: git clone https://github.com/aimacode/aima-python.git -Fetch the aima-data submodule:: +Fetch the aima-data submodule: cd aima-python git submodule init git submodule update -Then you can run the testsuite with:: +Then you can run the testsuite from the `tests` directory with: py.test