HanesWoolfTest.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace MathPHP\Tests\Statistics\Regression;
  3. use MathPHP\Statistics\Regression\HanesWoolf;
  4. class HanesWoolfTest extends \PHPUnit\Framework\TestCase
  5. {
  6. /**
  7. * @test getParameters
  8. * @dataProvider dataProviderForParameters
  9. * @param array $points
  10. * @param float $V
  11. * @param float $K
  12. */
  13. public function testGetParameters(array $points, float $V, float $K)
  14. {
  15. // Given
  16. $regression = new HanesWoolf($points);
  17. // When
  18. $parameters = $regression->getParameters();
  19. // Then
  20. $this->assertEqualsWithDelta($V, $parameters['V'], 0.0001);
  21. $this->assertEqualsWithDelta($K, $parameters['K'], 0.0001);
  22. }
  23. /**
  24. * @return array [points, V, K]
  25. */
  26. public function dataProviderForParameters(): array
  27. {
  28. return [
  29. [
  30. [[.038, .05], [.194, .127], [.425, .094], [.626, .2122], [1.253, .2729], [2.5, .2665], [3.740, .3317]],
  31. 0.361512337, 0.554178955,
  32. ],
  33. ];
  34. }
  35. /**
  36. * @test evaluate
  37. * @dataProvider dataProviderForEvaluate
  38. * @param array $points
  39. * @param $x
  40. * @param $expected_y
  41. */
  42. public function testEvaluate(array $points, float $x, float $expected_y)
  43. {
  44. // Given
  45. $regression = new HanesWoolf($points);
  46. // When
  47. $y = $regression->evaluate($x);
  48. // Then
  49. $this->assertEqualsWithDelta($expected_y, $y, 0.0001);
  50. }
  51. /**
  52. * @return array [points, x, expected y]
  53. */
  54. public function dataProviderForEvaluate(): array
  55. {
  56. return [
  57. [
  58. [[.038, .05], [.194, .127], [.425, .094], [.626, .2122], [1.253, .2729], [2.5, .2665], [3.740, .3317]],
  59. 5,
  60. 0.3254417
  61. ],
  62. ];
  63. }
  64. }