time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (3971B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # incrpcorrdist
     22 
     23 > Compute a [sample Pearson product-moment correlation distance][pearson-correlation] incrementally.
     24 
     25 <section class="intro">
     26 
     27 The [sample Pearson product-moment correlation distance][pearson-correlation] is defined as
     28 
     29 <!-- <equation class="equation" label="eq:pearson_distance" align="center" raw="d_{x,y} = 1 - r_{x,y} = 1 - \frac{\operatorname{cov_n(x,y)}}{\sigma_x \sigma_y}" alt="Equation for the Pearson product-moment correlation distance."> -->
     30 
     31 <div class="equation" align="center" data-raw-text="d_{x,y} = 1 - r_{x,y} = 1 - \frac{\operatorname{cov_n(x,y)}}{\sigma_x \sigma_y}" data-equation="eq:pearson_distance">
     32     <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@7e0a95722efd9c771b129597380c63dc6715508b/lib/node_modules/@stdlib/stats/incr/pcorrdist/docs/img/equation_pearson_distance.svg" alt="Equation for the Pearson product-moment correlation distance.">
     33     <br>
     34 </div>
     35 
     36 <!-- </equation> -->
     37 
     38 where `r` is the [sample Pearson product-moment correlation coefficient][pearson-correlation], `cov(x,y)` is the sample covariance, and `σ` corresponds to the sample standard deviation. As `r` resides on the interval `[-1,1]`, `d` resides on the interval `[0,2]`.
     39 
     40 </section>
     41 
     42 <!-- /.intro -->
     43 
     44 <section class="usage">
     45 
     46 ## Usage
     47 
     48 ```javascript
     49 var incrpcorrdist = require( '@stdlib/stats/incr/pcorrdist' );
     50 ```
     51 
     52 #### incrpcorrdist( \[mx, my] )
     53 
     54 Returns an accumulator `function` which incrementally computes a [sample Pearson product-moment correlation distance][pearson-correlation].
     55 
     56 ```javascript
     57 var accumulator = incrpcorrdist();
     58 ```
     59 
     60 If the means are already known, provide `mx` and `my` arguments.
     61 
     62 ```javascript
     63 var accumulator = incrpcorrdist( 3.0, -5.5 );
     64 ```
     65 
     66 #### accumulator( \[x, y] )
     67 
     68 If provided input value `x` and `y`, the accumulator function returns an updated [sample correlation coefficient][pearson-correlation]. If not provided input values `x` and `y`, the accumulator function returns the current [sample correlation coefficient][pearson-correlation].
     69 
     70 ```javascript
     71 var accumulator = incrpcorrdist();
     72 
     73 var d = accumulator( 2.0, 1.0 );
     74 // returns 1.0
     75 
     76 d = accumulator( 1.0, -5.0 );
     77 // returns 0.0
     78 
     79 d = accumulator( 3.0, 3.14 );
     80 // returns ~0.035
     81 
     82 d = accumulator();
     83 // returns ~0.035
     84 ```
     85 
     86 </section>
     87 
     88 <!-- /.usage -->
     89 
     90 <section class="notes">
     91 
     92 ## Notes
     93 
     94 -   Input values are **not** type checked. If provided `NaN` or a value which, when used in computations, results in `NaN`, the accumulated value is `NaN` for **all** future invocations. If non-numeric inputs are possible, you are advised to type check and handle accordingly **before** passing the value to the accumulator function.
     95 
     96 </section>
     97 
     98 <!-- /.notes -->
     99 
    100 <section class="examples">
    101 
    102 ## Examples
    103 
    104 <!-- eslint no-undef: "error" -->
    105 
    106 ```javascript
    107 var randu = require( '@stdlib/random/base/randu' );
    108 var incrpcorrdist = require( '@stdlib/stats/incr/pcorrdist' );
    109 
    110 var accumulator;
    111 var x;
    112 var y;
    113 var i;
    114 
    115 // Initialize an accumulator:
    116 accumulator = incrpcorrdist();
    117 
    118 // For each simulated datum, update the sample correlation distance...
    119 for ( i = 0; i < 100; i++ ) {
    120     x = randu() * 100.0;
    121     y = randu() * 100.0;
    122     accumulator( x, y );
    123 }
    124 console.log( accumulator() );
    125 ```
    126 
    127 </section>
    128 
    129 <!-- /.examples -->
    130 
    131 <section class="links">
    132 
    133 [pearson-correlation]: https://en.wikipedia.org/wiki/Pearson_correlation_coefficient
    134 
    135 </section>
    136 
    137 <!-- /.links -->