Comments (6)
Cool. I think I get it.
My one concern is that since it would be using an ordered numerical array, it is easy to mess up parameters and it isn't immediately clear what is going on. So I'd want LinearModel etc. to have parameter constants:
const X = 0; // x parameter index
const M = 1; // m parameter index
const B = 2; // b parameter index
Something like that, so then you can do:
function evaluateModel(...$params)
{
$x = $params[self::X];
$m = $params[self::M];
$b = $params[self::B];
return $m * $x + $b;
}
Basically, outside of a loop, if you are indexing into a numerical array, you probably want to do it with named meaningful constants to increase code clarity.
Thanks.
from math-php.
I agree with the naming. However, in the case linear or polynomial, the evaluate function is easily calculated using:
// $order = 1 for linear, 2 for y=m1 * x²+m2 * x +b, 3 for x^3, etc.
return Vandermonde($x, $order + 1)->multiply($betas)[0][0];
from math-php.
I have something in the works in my repository, but I'm seeing errors like the following:
- Math\Statistics\Regression\HanesWoolfTest::testGetParameters with data set #0 (array(array(0.037999999999999999, 0.050000000000000003), array(0.19400000000000001, 0.127), array(0.42499999999999999, 0.094), array(0.626, 0.2122), array(1.2529999999999999, 0.27289999999999998), array(2.5, 0.26650000000000001), array(3.7400000000000002, 0.33169999999999999)), 0.36151233700000002, 0.55417895500000003)
Error: Call to undefined method Math\Statistics\Regression\Regression::getModelParameters()
/home/travis/build/Beakerboy/math-php/src/Statistics/Regression/Regression.php:83
/home/travis/build/Beakerboy/math-php/tests/Statistics/Regression/HanesWoolfTest.php:13
Any ideas? Is there "one simple trick" to getting static methods to work in traits?
from math-php.
Static trait methods should work. Since you are inheriting from a parent Regression class, and that is making the call, but that doesn't have the trait, then that could be the cause of the method not being defined. I think if you include the use trait in the parent Regression class it will work, but then that kind of defeats the point of what you are trying to do.
The issue seems to be whether a parent method can use a child's trait, which might be no, but I'm not 100% sure.
from math-php.
Maybe using get_called_class() (or whatever that function is called) will work.
from math-php.
I've submitted a pull request. Lots has changed, but going forward I think this will make things more flexible and easier to extend.
from math-php.
Related Issues (20)
- What is the point of the complex polar form? HOT 7
- Division by zero in Probability\Distribution\Continuous\Continuous HOT 21
- Dealing with NANs HOT 3
- Integer Modulo n HOT 3
- Add vector, matrix and quaternion operations for 3d geometry HOT 1
- Could math-php support KPHP? HOT 1
- Truncated Mean Percentage HOT 5
- Incompatibility with Iterator and ArrayAccess interfaces HOT 1
- Quartiles calculation in Stats Descriptive HOT 1
- MiddlePayment For Loan HOT 2
- `number` is not a valid PHP type HOT 5
- Kernel Density Estimation: Improved Sheather-Jones algorithm HOT 4
- Bug for the t-test? HOT 5
- Add row/column algebra methods to Matrix for Vector HOT 3
- Document additional Matrix Row Operations and add their Columnar counterparts HOT 5
- Implicit Behavior of ImmutableSet
- Add Moore-Penrose Inverse HOT 12
- Psalm does not understand `number` pseudo-type HOT 3
- Add a factor method for Polynomials HOT 4
- Repeated measures ANOVA HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from math-php.