SlideShare a Scribd company logo
1 of 3
<?php
/**
* Description of Regression
* formule = y = ax + b
* @author peltenburg
*/
include_once("../PrognoseCreatorGemeenten/DBConnection.php");
include_once("../PrognoseCreatorGemeenten/aantalJongeren.php");
class Regression {
private $xAx_Points;
private $yAx_Points;
public function __construct($x, $y) {
$db_handle = DBConnect::getInstance();
$aantalJongeren = new aantalJongeren($db_handle);
$jaar = $aantalJongeren->showJaar();
$this->xAx_Points = $jaar;
$totaalAantalJongeren = $aantalJongeren->showAantalJongeren();
$this->yAx_Points = $totaalAantalJongeren;
}
public function NumberOfMeasurePoints($x) {
// calculate number points
$x = $this->xAx_Points;
if (isset($_POST['PrognoseJaar'])) {
$xIngevoerd = (double) $_POST['PrognoseJaar'];
array_push($x, $xIngevoerd);
$s = array_unique($x);
$n = count($s);
return $n;
} else {
$_POST['PrognoseJaar'] = 2012;
$xIngevoerd = (double) $_POST['PrognoseJaar'];
array_push($x, $xIngevoerd);
$s = array_unique($x);
$n = count($s);
return $n;
}
}
public function checkArrayLength($y) {
// ensure both arrays of points are the same size
$y = $this->yAx_Points;
array_push($y, (double) $this->calculateY());
$n = $this->NumberOfMeasurePoints($x);
if ($n != count($y)) {
trigger_error("linear_regression(): Number of elements in coordinate arrays do not match.",
E_USER_ERROR);
} else {
echo "arrays are of the same length";
}
}
public function y_Sum() {
$y = $this->yAx_Points;
$y_sum = array_sum($y);
return $y_sum;
}
public function x_sum() {
$x = $this->xAx_Points;
$x_sum = array_sum($x);
return $x_sum;
}
public function calculateA() {
/*
* a= (y2-y1)/(x2-x1)(waarde y op meetmoment 2 - waarde y op meetmoment 1)
*
* als de lijn over meerdere punten wordt berekend moet je gebruikmaken van
* a = SOM (x-x(gem))) * (y - y(gem)) / SOM (x - x (gem))
*/
$y = $this->yAx_Points;
$x = $this->xAx_Points;
$y2 = end($y);
$y1 = $y[0];
$x2 = end($x);
$x1 = $x[0];
$n = $this->NumberOfMeasurePoints($x) - 1;
$xGem = $this->x_sum() / $n;
$totaal_xGem = array();
for ($i = 0; $i < $n; $i++) {
$x_xGem = $x[$i] - $xGem;
$totaal_xGem[] = $x_xGem;
}
$x_x_gem_2 = array();
for ($i = 0; $i < count($totaal_xGem); $i++) {
$x_x_gem_2[] = $totaal_xGem[$i] * $totaal_xGem[$i];
}
$sum_x_x_gem_2 = array_sum($x_x_gem_2);
$n = $this->NumberOfMeasurePoints($x) - 1;
$yGem = $this->y_Sum() / $n;
$totaal_yGem = array();
for ($i = 0; $i < $n; $i++) {
$y_yGem = $y[$i] - $yGem;
$totaal_yGem[] = $y_yGem;
}
$x_xGemXy_yGem = array();
for ($i = 0; $i < $n; $i++) {
$x_xGemXy_yGem[] = $totaal_yGem[$i] * $totaal_xGem[$i];
}
$Sum_x_xGemXy_yGem = array_sum($x_xGemXy_yGem);
$a = $Sum_x_xGemXy_yGem / $sum_x_x_gem_2;
return $a;
}
public function calculateB() {
// calculate intercept
/*
* b = y(gem)-ax(gem)
*/
$x = $this->xAx_Points;
$x_sum = $this->x_sum();
$y_sum = $this->y_sum();
$n = $this->NumberOfMeasurePoints($this->xAx_Points) - 1;
$a = $this->calculateA();
$yMean = (double) $y_sum / $n;
$xMean = (double) $x_sum / $n;
$aTimesXmean = (double) (($a) * $xMean);
$bTotaal = $yMean - ($aTimesXmean);
return $bTotaal;
}
public function calculateY() {
/*
* y = ax+b
*/
$a = $this->calculateA();
$b = $this->calculateB();
$x = $this->xAx_Points;
$xIngevoerd = (double) $_POST['PrognoseJaar'];
array_push($x, $xIngevoerd);
$y = $a * end($x) + $b;
return $y;
}
}

More Related Content

What's hot

6 windows-phone8-introduction-m6-slides
6 windows-phone8-introduction-m6-slides6 windows-phone8-introduction-m6-slides
6 windows-phone8-introduction-m6-slidesMasterCode.vn
 
How to count money using PHP and not lose money
How to count money using PHP and not lose moneyHow to count money using PHP and not lose money
How to count money using PHP and not lose moneyPiotr Horzycki
 
Gta v savegame
Gta v savegameGta v savegame
Gta v savegamehozayfa999
 
Writing Sensible Code
Writing Sensible CodeWriting Sensible Code
Writing Sensible CodeAnis Ahmad
 
Crash Course to SQL in PHP
Crash Course to SQL in PHPCrash Course to SQL in PHP
Crash Course to SQL in PHPwebhostingguy
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Julien Vinber
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitmfrost503
 
Perl6 operators and metaoperators
Perl6   operators and metaoperatorsPerl6   operators and metaoperators
Perl6 operators and metaoperatorsSimon Proctor
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHPTaras Kalapun
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Mail.ru Group
 

What's hot (20)

TerminalでTwitter
TerminalでTwitterTerminalでTwitter
TerminalでTwitter
 
wget.pl
wget.plwget.pl
wget.pl
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
Presentation1
Presentation1Presentation1
Presentation1
 
6 windows-phone8-introduction-m6-slides
6 windows-phone8-introduction-m6-slides6 windows-phone8-introduction-m6-slides
6 windows-phone8-introduction-m6-slides
 
12. edit record
12. edit record12. edit record
12. edit record
 
11. delete record
11. delete record11. delete record
11. delete record
 
How to count money using PHP and not lose money
How to count money using PHP and not lose moneyHow to count money using PHP and not lose money
How to count money using PHP and not lose money
 
10. view one record
10. view one record10. view one record
10. view one record
 
Gta v savegame
Gta v savegameGta v savegame
Gta v savegame
 
Writing Sensible Code
Writing Sensible CodeWriting Sensible Code
Writing Sensible Code
 
Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
Crash Course to SQL in PHP
Crash Course to SQL in PHPCrash Course to SQL in PHP
Crash Course to SQL in PHP
 
Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?Et si on en finissait avec CRUD ?
Et si on en finissait avec CRUD ?
 
Mocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnitMocking Dependencies in PHPUnit
Mocking Dependencies in PHPUnit
 
Perl6 operators and metaoperators
Perl6   operators and metaoperatorsPerl6   operators and metaoperators
Perl6 operators and metaoperators
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Crazy things done on PHP
Crazy things done on PHPCrazy things done on PHP
Crazy things done on PHP
 
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
Security Meetup 22 октября. «Реверс-инжиниринг в Enterprise». Алексей Секрето...
 
Pop3ck sh
Pop3ck shPop3ck sh
Pop3ck sh
 

Viewers also liked

Laws of thermodynamics
Laws of thermodynamicsLaws of thermodynamics
Laws of thermodynamicsFaraz Ahmed
 
Rupsa_Article
Rupsa_ArticleRupsa_Article
Rupsa_ArticleRupsa Das
 
Brief Note-20-2016-cost effective CSR
Brief Note-20-2016-cost effective CSRBrief Note-20-2016-cost effective CSR
Brief Note-20-2016-cost effective CSRprimahendra
 
Assessing student learning: a rubric-based 'e-portfolio' approach to assessme...
Assessing student learning: a rubric-based 'e-portfolio' approach to assessme...Assessing student learning: a rubric-based 'e-portfolio' approach to assessme...
Assessing student learning: a rubric-based 'e-portfolio' approach to assessme...Alan Carbery
 

Viewers also liked (9)

Laws of thermodynamics
Laws of thermodynamicsLaws of thermodynamics
Laws of thermodynamics
 
Rupsa_Article
Rupsa_ArticleRupsa_Article
Rupsa_Article
 
Brief Note-20-2016-cost effective CSR
Brief Note-20-2016-cost effective CSRBrief Note-20-2016-cost effective CSR
Brief Note-20-2016-cost effective CSR
 
.Body parts.
.Body parts..Body parts.
.Body parts.
 
Contenido 2. el sector primario
Contenido 2. el sector primarioContenido 2. el sector primario
Contenido 2. el sector primario
 
IVMS-Gen Path-Inflammation
IVMS-Gen Path-InflammationIVMS-Gen Path-Inflammation
IVMS-Gen Path-Inflammation
 
Assessing student learning: a rubric-based 'e-portfolio' approach to assessme...
Assessing student learning: a rubric-based 'e-portfolio' approach to assessme...Assessing student learning: a rubric-based 'e-portfolio' approach to assessme...
Assessing student learning: a rubric-based 'e-portfolio' approach to assessme...
 
Расчет рамы в лира
Расчет рамы в лираРасчет рамы в лира
Расчет рамы в лира
 
Los mercados. la competencia
Los mercados. la competenciaLos mercados. la competencia
Los mercados. la competencia
 

Similar to linieaire regressie

Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in actionJace Ju
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolveXSolve
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of TransductionDavid Stockton
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Lucas Witold Adamus
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPWildan Maulana
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design PatternsHugo Hamon
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome TownRoss Tuck
 
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...Mateusz Zalewski
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6garux
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにYuya Takeyama
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsRoss Tuck
 
Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm OldRoss Tuck
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console componentHugo Hamon
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
 
Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"Fwdays
 

Similar to linieaire regressie (20)

Advanced php testing in action
Advanced php testing in actionAdvanced php testing in action
Advanced php testing in action
 
PHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolvePHPCon 2016: PHP7 by Witek Adamus / XSolve
PHPCon 2016: PHP7 by Witek Adamus / XSolve
 
The Art of Transduction
The Art of TransductionThe Art of Transduction
The Art of Transduction
 
Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?Why async and functional programming in PHP7 suck and how to get overr it?
Why async and functional programming in PHP7 suck and how to get overr it?
 
Object Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOPObject Oriented Programming with PHP 5 - More OOP
Object Oriented Programming with PHP 5 - More OOP
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Database Design Patterns
Database Design PatternsDatabase Design Patterns
Database Design Patterns
 
Command Bus To Awesome Town
Command Bus To Awesome TownCommand Bus To Awesome Town
Command Bus To Awesome Town
 
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
[PHPCon 2023] “Kto to pisał?!... a, to ja.”, czyli sposoby żeby znienawidzić ...
 
Introdução ao Perl 6
Introdução ao Perl 6Introdução ao Perl 6
Introdução ao Perl 6
 
PHP 5.4
PHP 5.4PHP 5.4
PHP 5.4
 
Functional php
Functional phpFunctional php
Functional php
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
PHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くためにPHPUnit でよりよくテストを書くために
PHPUnit でよりよくテストを書くために
 
Models and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and HobgoblinsModels and Service Layers, Hemoglobin and Hobgoblins
Models and Service Layers, Hemoglobin and Hobgoblins
 
Things I Believe Now That I'm Old
Things I Believe Now That I'm OldThings I Believe Now That I'm Old
Things I Believe Now That I'm Old
 
Symfony2 - extending the console component
Symfony2 - extending the console componentSymfony2 - extending the console component
Symfony2 - extending the console component
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"Pim Elshoff "Technically DDD"
Pim Elshoff "Technically DDD"
 
PHPSpec BDD for PHP
PHPSpec BDD for PHPPHPSpec BDD for PHP
PHPSpec BDD for PHP
 

linieaire regressie

  • 1. <?php /** * Description of Regression * formule = y = ax + b * @author peltenburg */ include_once("../PrognoseCreatorGemeenten/DBConnection.php"); include_once("../PrognoseCreatorGemeenten/aantalJongeren.php"); class Regression { private $xAx_Points; private $yAx_Points; public function __construct($x, $y) { $db_handle = DBConnect::getInstance(); $aantalJongeren = new aantalJongeren($db_handle); $jaar = $aantalJongeren->showJaar(); $this->xAx_Points = $jaar; $totaalAantalJongeren = $aantalJongeren->showAantalJongeren(); $this->yAx_Points = $totaalAantalJongeren; } public function NumberOfMeasurePoints($x) { // calculate number points $x = $this->xAx_Points; if (isset($_POST['PrognoseJaar'])) { $xIngevoerd = (double) $_POST['PrognoseJaar']; array_push($x, $xIngevoerd); $s = array_unique($x); $n = count($s); return $n; } else { $_POST['PrognoseJaar'] = 2012; $xIngevoerd = (double) $_POST['PrognoseJaar']; array_push($x, $xIngevoerd); $s = array_unique($x); $n = count($s); return $n; } } public function checkArrayLength($y) { // ensure both arrays of points are the same size $y = $this->yAx_Points; array_push($y, (double) $this->calculateY()); $n = $this->NumberOfMeasurePoints($x); if ($n != count($y)) { trigger_error("linear_regression(): Number of elements in coordinate arrays do not match.", E_USER_ERROR); } else {
  • 2. echo "arrays are of the same length"; } } public function y_Sum() { $y = $this->yAx_Points; $y_sum = array_sum($y); return $y_sum; } public function x_sum() { $x = $this->xAx_Points; $x_sum = array_sum($x); return $x_sum; } public function calculateA() { /* * a= (y2-y1)/(x2-x1)(waarde y op meetmoment 2 - waarde y op meetmoment 1) * * als de lijn over meerdere punten wordt berekend moet je gebruikmaken van * a = SOM (x-x(gem))) * (y - y(gem)) / SOM (x - x (gem)) */ $y = $this->yAx_Points; $x = $this->xAx_Points; $y2 = end($y); $y1 = $y[0]; $x2 = end($x); $x1 = $x[0]; $n = $this->NumberOfMeasurePoints($x) - 1; $xGem = $this->x_sum() / $n; $totaal_xGem = array(); for ($i = 0; $i < $n; $i++) { $x_xGem = $x[$i] - $xGem; $totaal_xGem[] = $x_xGem; } $x_x_gem_2 = array(); for ($i = 0; $i < count($totaal_xGem); $i++) { $x_x_gem_2[] = $totaal_xGem[$i] * $totaal_xGem[$i]; } $sum_x_x_gem_2 = array_sum($x_x_gem_2); $n = $this->NumberOfMeasurePoints($x) - 1; $yGem = $this->y_Sum() / $n; $totaal_yGem = array(); for ($i = 0; $i < $n; $i++) { $y_yGem = $y[$i] - $yGem; $totaal_yGem[] = $y_yGem; }
  • 3. $x_xGemXy_yGem = array(); for ($i = 0; $i < $n; $i++) { $x_xGemXy_yGem[] = $totaal_yGem[$i] * $totaal_xGem[$i]; } $Sum_x_xGemXy_yGem = array_sum($x_xGemXy_yGem); $a = $Sum_x_xGemXy_yGem / $sum_x_x_gem_2; return $a; } public function calculateB() { // calculate intercept /* * b = y(gem)-ax(gem) */ $x = $this->xAx_Points; $x_sum = $this->x_sum(); $y_sum = $this->y_sum(); $n = $this->NumberOfMeasurePoints($this->xAx_Points) - 1; $a = $this->calculateA(); $yMean = (double) $y_sum / $n; $xMean = (double) $x_sum / $n; $aTimesXmean = (double) (($a) * $xMean); $bTotaal = $yMean - ($aTimesXmean); return $bTotaal; } public function calculateY() { /* * y = ax+b */ $a = $this->calculateA(); $b = $this->calculateB(); $x = $this->xAx_Points; $xIngevoerd = (double) $_POST['PrognoseJaar']; array_push($x, $xIngevoerd); $y = $a * end($x) + $b; return $y; } }