LineweaverBurkTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace MathPHP\Tests\Statistics\Regression;
  3. use MathPHP\Statistics\Regression\LineweaverBurk;
  4. class LineweaverBurkTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /**
  7. * @test getEquation - Equation matches pattern y = V * X / (K + x)
  8. * @dataProvider dataProviderForEquation
  9. * @param array $points
  10. */
  11. public function testGetEquation(array $points)
  12. {
  13. // Given
  14. $regression = new LineweaverBurk($points);
  15. // Then
  16. $this->assertRegExp('/^y = \d+[.]\d+x\/\(\d+[.]\d+\+x\)$/', $regression->getEquation());
  17. }
  18. /**
  19. * @return array [points]
  20. */
  21. public function dataProviderForEquation(): array
  22. {
  23. return [
  24. [
  25. [ [.038, .05], [.194, .127], [.425, .094], [.626, .2122], [1.253, .2729], [2.5, .2665], [3.740, .3317] ]
  26. ]
  27. ];
  28. }
  29. /**
  30. * @test getParameters
  31. * @dataProvider dataProviderForParameters
  32. * @param array $points
  33. * @param float $V
  34. * @param float $K
  35. */
  36. public function testGetParameters(array $points, float $V, float $K)
  37. {
  38. // Given
  39. $regression = new LineweaverBurk($points);
  40. // When
  41. $parameters = $regression->getParameters();
  42. // Then
  43. $this->assertEqualsWithDelta($V, $parameters['V'], 0.0001);
  44. $this->assertEqualsWithDelta($K, $parameters['K'], 0.0001);
  45. }
  46. /**
  47. * @return array [points, V, K]
  48. */
  49. public function dataProviderForParameters(): array
  50. {
  51. return [
  52. [
  53. [ [.038, .05], [.194, .127], [.425, .094], [.626, .2122], [1.253, .2729], [2.5, .2665], [3.740, .3317] ],
  54. 0.222903511, 0.13447224,
  55. ],
  56. ];
  57. }
  58. /**
  59. * @test evaluate
  60. * @dataProvider dataProviderForEvaluate
  61. * @param array $points
  62. * @param float $x
  63. * @param float $y
  64. */
  65. public function testEvaluate(array $points, float $x, float $y)
  66. {
  67. // Given
  68. $regression = new LineweaverBurk($points);
  69. // Then
  70. $this->assertEqualsWithDelta($y, $regression->evaluate($x), 0.0001);
  71. }
  72. /**
  73. * @return array [points, x, y]
  74. */
  75. public function dataProviderForEvaluate(): array
  76. {
  77. return [
  78. [
  79. [ [.038, .05], [.194, .127], [.425, .094], [.626, .2122], [1.253, .2729], [2.5, .2665], [3.740, .3317] ],
  80. 0.038, 0.049111286,
  81. ],
  82. ];
  83. }
  84. }