{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","results":{"codes":[]},"settings":"","params":[]},"next":{"description":"","pages":[]},"title":"Basic Usage","type":"basic","slug":"basic-usage","excerpt":"A quick introduction to using Scientist.","body":"The key to mastering Scientist, is learning how to define Experiments. In the introduction section, we created a basic experiment, but there's a lot more available to use. Let's take a look at a very simple experiment.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$experiment = (new Scientist\\\\Laboratory)\\n  ->experiment('experiment title')\\n\\t->control($controlCallback)\\n  ->trial('trial name', $trialCallback);\\n\\n$value = $experiment->run();\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nThat's great. We're defining an experiment with a control, and a single trial. Nothing too complicated there.\n\nNow let's take a look at a more complex example. Here we'll see more of the methods that we can use to define our experiments.\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n$experiment = (new Scientist\\\\Laboratory)\\n  ->experiment('experiment title')\\n\\t->control($controlCallback)\\n  ->trial('first trial',  $firstTrialCallback)\\n  ->trial('second trial', $secondTrialCallback)\\n  ->trial('third trial',  $thirdTrialCallback)\\n  ->matcher(new Scientist\\\\Matcher\\\\StandardMatcher)\\n  ->chance(50);\\n\\n$value = $experiment->run(3, 'apple', $panda, 42);\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\nIn the above example, we are using every available experiment method.\n\nOnce again, we'll get the result of the `$controlCallback` callable instance when we run the `run()` method. All of our callbacks will execute, but only the control callback's resulting value will be used.\n\nIn the next section, we'll examine each of the methods above in more detail.","updates":[],"order":2,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"56b536b4eed075230097d75e","createdAt":"2016-02-05T23:56:36.944Z","user":"56b534d0168b5c1700c159a7","githubsync":"","__v":2,"category":{"sync":{"isSync":false,"url":""},"pages":["56b534f45f1cf00d00cc475f","56b5368185a6922300d1c538","56b5369a168b5c1700c159a9","56b536b4eed075230097d75e","56b536c32d7fc00d0037f496","56b5370a5997532100bc6c30","56b537147bccae0d00e9a1d0","56b537252d7fc00d0037f498","56b5372e5997532100bc6c32","56b5373d7719bb190014307a"],"title":"Documentation","slug":"documentation","order":9999,"from_sync":false,"reference":false,"_id":"56b534f35f1cf00d00cc475d","createdAt":"2016-02-05T23:49:07.518Z","__v":10,"project":"56b534f15f1cf00d00cc4759","version":"56b534f25f1cf00d00cc475c"},"project":"56b534f15f1cf00d00cc4759","version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["56b534f35f1cf00d00cc475d","56b55e5b5f1cf00d00cc477c","56b55e605f1cf00d00cc477d","56b5fac7e205510d001e4cfe"],"_id":"56b534f25f1cf00d00cc475c","project":"56b534f15f1cf00d00cc4759","releaseDate":"2016-02-05T23:49:06.439Z","__v":4,"createdAt":"2016-02-05T23:49:06.439Z"}}

Basic Usage

A quick introduction to using Scientist.

The key to mastering Scientist, is learning how to define Experiments. In the introduction section, we created a basic experiment, but there's a lot more available to use. Let's take a look at a very simple experiment. [block:code] { "codes": [ { "code": "<?php\n\n$experiment = (new Scientist\\Laboratory)\n ->experiment('experiment title')\n\t->control($controlCallback)\n ->trial('trial name', $trialCallback);\n\n$value = $experiment->run();", "language": "php" } ] } [/block] That's great. We're defining an experiment with a control, and a single trial. Nothing too complicated there. Now let's take a look at a more complex example. Here we'll see more of the methods that we can use to define our experiments. [block:code] { "codes": [ { "code": "<?php\n\n$experiment = (new Scientist\\Laboratory)\n ->experiment('experiment title')\n\t->control($controlCallback)\n ->trial('first trial', $firstTrialCallback)\n ->trial('second trial', $secondTrialCallback)\n ->trial('third trial', $thirdTrialCallback)\n ->matcher(new Scientist\\Matcher\\StandardMatcher)\n ->chance(50);\n\n$value = $experiment->run(3, 'apple', $panda, 42);", "language": "php" } ] } [/block] In the above example, we are using every available experiment method. Once again, we'll get the result of the `$controlCallback` callable instance when we run the `run()` method. All of our callbacks will execute, but only the control callback's resulting value will be used. In the next section, we'll examine each of the methods above in more detail.