-
Notifications
You must be signed in to change notification settings - Fork 44
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.
$experiment = (new Scientist\Laboratory)
->experiment('experiment title')
->control($controlCallback)
->trial('trial name', $trialCallback);
$value = $experiment->run();
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.
$experiment = (new Scientist\Laboratory)
->experiment('experiment title')
->control($controlCallback)
->trial('first trial', $firstTrialCallback)
->trial('second trial', $secondTrialCallback)
->trial('third trial', $thirdTrialCallback)
->matcher(new Scientist\Matcher\StandardMatcher)
->chance(50);
$value = $experiment->run(3, 'apple', $panda, 42);
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.