{"_id":"56b536b4eed075230097d75e","user":"56b534d0168b5c1700c159a7","githubsync":"","__v":2,"category":{"_id":"56b534f35f1cf00d00cc475d","__v":10,"project":"56b534f15f1cf00d00cc4759","version":"56b534f25f1cf00d00cc475c","pages":["56b534f45f1cf00d00cc475f","56b5368185a6922300d1c538","56b5369a168b5c1700c159a9","56b536b4eed075230097d75e","56b536c32d7fc00d0037f496","56b5370a5997532100bc6c30","56b537147bccae0d00e9a1d0","56b537252d7fc00d0037f498","56b5372e5997532100bc6c32","56b5373d7719bb190014307a"],"sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-05T23:49:07.518Z","from_sync":false,"order":9999,"slug":"documentation","title":"Documentation"},"project":"56b534f15f1cf00d00cc4759","version":{"_id":"56b534f25f1cf00d00cc475c","project":"56b534f15f1cf00d00cc4759","__v":4,"createdAt":"2016-02-05T23:49:06.439Z","releaseDate":"2016-02-05T23:49:06.439Z","categories":["56b534f35f1cf00d00cc475d","56b55e5b5f1cf00d00cc477c","56b55e605f1cf00d00cc477d","56b5fac7e205510d001e4cfe"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-05T23:56:36.944Z","link_external":false,"link_url":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":2,"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.","excerpt":"A quick introduction to using Scientist.","slug":"basic-usage","type":"basic","title":"Basic Usage"}

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.