The algorithm of the five-bit

Source: Internet
Author: User

Using the five-bit algorithm to calculate the distribution of data

First, we set up a five-bit algorithm point K value, respectively, using 16%,37%,63%,84% probability

According to the function percentile of Excel, and the K value, we calculate four point value respectively, the result is as shown

Although Excel has its own functions, Java does not, you must write your own program to implement

Creating the Method.java Class

 Packagecom.test;ImportJava.text.DecimalFormat;Importjava.util.ArrayList;Importjava.util.Collections;ImportJava.util.Comparator;Importjava.util.List; Public classMethod {/*** Five-point algorithm *@authorAdministrator **/     Public Static DoubleCaculatequinte (Double[] data,int k) {        DoublePoint = 0.00; Try{List<Double> list =method.createlist (data); Point= Method.getvalue (list, K); } Catch(Exception e) {e.printstacktrace (); }        returnPoint ; }        /*** Calculate Point value *@paramlist *@paramp *@return     */     Public Static DoubleGetValue (list<double> List,intp) {        //List Size        intn =list.size (); DoubleDoubledata = ((Double) (n-1) *p)/100; //Integer Part        inti = (n-1) *p/100; DecimalFormat DecimalFormat=NewDecimalFormat ("####### #0.000000000"); //number of decimal parts        Doublej = double.parsedouble (Decimalformat.format (Doubledata-i)); //I element value double A = List.get (i);        The I+1 element value of double b = list.get (i+1); returnDouble.parsedouble (Decimalformat.format (((1-j) *a) + (j*b))); }        /*** Inverted Sort *@paramDD *@return     */@SuppressWarnings ("Unchecked")     Public StaticList<double> CreateList (Double... dd) {List<Double> list =NewArraylist<double>();  for(Double db:dd) {list.add (db); } @SuppressWarnings ("Rawtypes") Comparator Comparator=NewComparator () {@Override Public intCompare (Object O1, Object O2) {DoubleD1 = (Double) O1; DoubleD2 = (Double) O2; if(D1 >D2) {                    return1; }Else if(D1 = =D2) {                    return0; }Else{                    return-1;        }            }        };        Collections.sort (List,comparator); returnlist; }}

Red Place to explain: I looked at other netizens on the percentile principle of the description, they say A and B, respectively take i+1 and i+2 value, but I according to them, calculated the result is not right (http://www.360doc.com/content/15/ 0718/17/26365336_485725251.shtml)

Write a test class Test.java

 Packagecom.test; Public classTest { Public Static voidMain (string[] args) {Double[] dd = {            4.5077089,            2.8531679,            2.5365171,            2.5248491,            2.2526313,            1.2222833,            0.8638264,            0.7489835,            0.7429955,            0.6211575,            0.5247851,            0.4948757,            0.4946506,            0.4172792,            0.3435438,            0.1663883,            -0.014807,            -0.06503,            -0.334462,            -0.430975,            -0.478554,            -2.720794,            -3.328721,            -5.205578        }; int[] k = {16,37,63,84}; SYSTEM.OUT.PRINTLN (Method.caculatequinte (DD, k[0])); SYSTEM.OUT.PRINTLN (Method.caculatequinte (DD, k[1])); SYSTEM.OUT.PRINTLN (Method.caculatequinte (DD, k[2])); SYSTEM.OUT.PRINTLN (Method.caculatequinte (DD, k[3])); }}

Look at the results, as shown in

Exactly the same result as the Excel self-function calculation

The algorithm of the five-bit

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.