function testPlurality() { $m = new MammalClassifier(); $testData = '[{"buffalo":1,"antelope":1},{"buffalo":2},{"cat":2},{"buffalo":1},{"cat":2},{"antelope":2},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":2},{"giraffe":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":2,"antelope":1},{"buffalo":2,"antelope":1},{"antelope":2},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"nothing_here":0},{"buffalo":1,"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2}]'; $result = $m->onDataSet(json_decode($testData, true))->classify()->getResult(); $this->assertArrayHasKey('classification', $result); $this->assertArrayHasKey('antelope', $result['classification']); $this->assertArrayHasKey('buffalo', $result['classification']); $this->assertEquals(1, $result['classification']['antelope']); $this->assertEquals(1, $result['classification']['buffalo']); }
/** * @param $imageId integer Run the algorithm on a single image * @param boolean $store Store the result * @param MammalClassifier|null $classifier An instance of MammalClassifier * @param $classification * @param bool $scientistDataset Whether to store in the scientist dataset table * @return array|string The result */ public function runOnClassification($imageId, $store, $classifier, $classification, $scientistDataset = false) { if (!$classifier) { $classifier = new MammalClassifier(null, $scientistDataset); } try { if ($store) { return $classifier->onDataSet($classification)->classify()->store()->getResult(); } else { return $classifier->onDataSet($classification)->classify()->getResult(); } } catch (Exception $e) { return "No classifications."; } }
<?php require '../../src/core.php'; $classifier = new MammalClassifier(); $testJson = '[{"buffalo":1,"antelope":2},{"buffalo":2},{"cat":2},{"buffalo":1},{"cat":2},{"antelope":2},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":2},{"giraffe":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"buffalo":2,"antelope":1},{"buffalo":2,"antelope":1},{"antelope":2},{"buffalo":1,"antelope":1},{"buffalo":1,"antelope":1},{"nothing_here":0},{"buffalo":1,"antelope":1},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2},{"antelope":2}]'; if (isset($_POST['data'])) { echo '<pre>'; $classifications = json_decode($_POST['data'], true); echo "\nResult: \n"; print_r($classifier->onDataSet($classifications)->classify()->getResult()); echo '</pre>'; } else { $classifications = json_decode($testJson, true); echo "\nResult: \n"; print_r($classifier->onDataSet($classifications)->classify()->getResult()); }
<?php require 'core.php'; $classifier = new MammalClassifier(); // Usage: /* Create a MammalClassifier object -> call on() to specify the id of the image this will load up the image classifications from the database -> call classify to run the classification algorithm -> call store() to store result back in database -> call getResult() to get the result Order is (most of the time) important! */ $controller = new AlgorithmController(); $controller->runAlgorithm(); $id = 311; while ($id <= 311) { $res = $classifier->on($id)->classify()->store()->getResult(); $id++; print "id: " . $id . " =>"; print_r($res); print "\n"; }