Code Monkey home page Code Monkey logo

Comments (6)

markrogoyski avatar markrogoyski commented on May 14, 2024

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.

Beakerboy avatar Beakerboy commented on May 14, 2024

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.

Beakerboy avatar Beakerboy commented on May 14, 2024

I have something in the works in my repository, but I'm seeing errors like the following:

  1. 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.

markrogoyski avatar markrogoyski commented on May 14, 2024

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.

Beakerboy avatar Beakerboy commented on May 14, 2024

Maybe using get_called_class() (or whatever that function is called) will work.

from math-php.

Beakerboy avatar Beakerboy commented on May 14, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.