The importance of the math library for simple linear regression in PHP

Source: Internet
Author: User
Tags format contains functions variables php class
Brief introduction

Compared to other Open-source languages such as Perl and Python, the PHP community lacks a strong job to develop a math library.

One reason for this is that there are already a large number of sophisticated mathematical tools that may be preventing the community from developing its own PHP tools. For example, I have studied a powerful tool S System, which has an impressive set of statistical databases, designed to analyze datasets, and was awarded the ACM Award in 1998 for its language design. If S or its open source category R is just a exec_shellCall, so why bother using PHP to achieve the same statistical computing function? For more information on S System, its ACM awards, or R, see related resources.

Isn't this a waste of developer energy? If the motivation for developing a PHP math library is to save the developer's energy and use the best tools to do the job, then PHP's current topic is meaningful.

On the other hand, motivation for teaching may encourage the development of a PHP math library. For about 10% of the people, mathematics is an interesting subject to explore. For those who are also skilled at PHP, the development of the PHP Math library can enhance the math learning process, in other words, not just ReadingFor the section on T test, also ImplementA class that calculates the corresponding intermediate values and displays them in a standard format.

Through coaching and training, I want to prove that developing a PHP math library is not a difficult task, it may represent an interesting technology and learning problem. In this article, I'll provide an example of a PHP math library called SimpleLinearRegression, it demonstrates a common approach that can be used to develop a PHP math library. Let's start by discussing some common principles that guide me in developing this SimpleLinearRegressionClass.

   Guiding Principles

I have used six general principles to guide SimpleLinearRegressionThe development of the class.
    1. Each analysis model builds a class.
    2. Use reverse links to develop classes.
    3. Expected to have a large number of getter.
    4. Store intermediate results.
    5. Develop preferences for detailed APIs.
    6. Perfection is not a goal.


Let's look at these guidelines in more detail.
 
   Each analysis model builds a class

Each major analytical test or procedure should have a PHP class with the same name as the test or procedure name, which contains the input functions, functions and output functions that calculate the intermediate value and the total value (the median and total values are displayed on the screen in text or graphic format).

   use reverse link to develop class

In mathematical programming, the goal of coding is usually the analysis process (e.g.MultipleRegressionTimeSeriesOrChiSquaredThe standard output value that you want to generate. From a problem-solving perspective, this means that you can use reverse linking to develop a method of mathematical classes.

For example, the summary Output screen displays one or more summary statistics. These summary statistical results depend on the calculation of the intermediate statistic results, which may involve a deeper level of intermediate statistics, and so on. This development method based on the reverse link derives the next principle.

   expected to have a large number of getter

Most of the math class development work involves calculating intermediate values and summary values. In fact, this means that you should not be surprised if your class contains many getter methods for calculating intermediate and aggregate values.

   Store Intermediate Results

The intermediate results are stored in the result object so that you can use the intermediate result as input for subsequent computations. This principle is implemented in S language design. In the current environment, this principle is implemented by selecting the instance variable to represent the calculated intermediate value and the aggregated result.

   develop preferences for detailed APIs

When theSimpleLinearRegressionmember functions and instance variables in a class to make a naming scheme, I found that if I use a longer name (similar togetSumSquaredErrorSuch a name, and notgetYY2To describe the member functions and the instance variables, it is easier to understand what the functions are doing and what the variables represent.

I did not give up the abbreviated name altogether; however, when I use the abbreviated name, I have to try to provide a comment to fully explain the meaning of the name. My view is that highly abbreviated naming schemes are common in mathematical programming, but they make it more difficult to understand and prove whether a mathematical routine is more or less in step, without having to create such a difficulty.

   Perfection is not a goal

The goal of this coding exercise is not to be sure to develop a highly optimized and rigorous math engine for PHP. In the early stages, emphasis should be placed on learning to achieve significant analytical testing, as well as addressing the challenges in this area.

   instance Variables

When modeling a statistical test or procedure, you need to indicate which instance variables to declare.

The selection of an instance variable can be determined by stating the intermediate value and the total value generated by the analysis process. Each intermediate value and summary value can have a corresponding instance variable that takes the value of the variable as an object property.

I use this analysis to determine the list in Listing 1SimpleLinearRegressionWhat variables the class declares. Can be onMultipleRegressionANOVAOrTimeSeriesThe process performs a similar analysis.

[1] [2] [3] Next page



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.