time-to-botec

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

README.md (2470B)


      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 # incrrange
     22 
     23 > Compute a [range][range] incrementally.
     24 
     25 <section class="intro">
     26 
     27 The [**range**][range] is defined as the difference between the maximum and minimum values.
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <section class="usage">
     34 
     35 ## Usage
     36 
     37 ```javascript
     38 var incrrange = require( '@stdlib/stats/incr/range' );
     39 ```
     40 
     41 #### incrrange()
     42 
     43 Returns an accumulator `function` which incrementally computes a [range][range].
     44 
     45 ```javascript
     46 var accumulator = incrrange();
     47 ```
     48 
     49 #### accumulator( \[x] )
     50 
     51 If provided an input value `x`, the accumulator function returns an updated [range][range]. If not provided an input value `x`, the accumulator function returns the current [range][range].
     52 
     53 ```javascript
     54 var accumulator = incrrange();
     55 
     56 var range = accumulator( -2.0 );
     57 // returns 0.0
     58 
     59 range = accumulator( 1.0 );
     60 // returns 3.0
     61 
     62 range = accumulator( 3.0 );
     63 // returns 5.0
     64 
     65 range = accumulator();
     66 // returns 5.0
     67 ```
     68 
     69 </section>
     70 
     71 <!-- /.usage -->
     72 
     73 <section class="notes">
     74 
     75 ## Notes
     76 
     77 -   Input values are **not** type checked. If provided `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.
     78 
     79 </section>
     80 
     81 <!-- /.notes -->
     82 
     83 <section class="examples">
     84 
     85 ## Examples
     86 
     87 <!-- eslint no-undef: "error" -->
     88 
     89 ```javascript
     90 var randu = require( '@stdlib/random/base/randu' );
     91 var incrrange = require( '@stdlib/stats/incr/range' );
     92 
     93 var accumulator;
     94 var v;
     95 var i;
     96 
     97 // Initialize an accumulator:
     98 accumulator = incrrange();
     99 
    100 // For each simulated datum, update the range...
    101 for ( i = 0; i < 100; i++ ) {
    102     v = randu() * 100.0;
    103     accumulator( v );
    104 }
    105 console.log( accumulator() );
    106 ```
    107 
    108 </section>
    109 
    110 <!-- /.examples -->
    111 
    112 <section class="links">
    113 
    114 [range]: https://en.wikipedia.org/wiki/Range_%28statistics%29
    115 
    116 </section>
    117 
    118 <!-- /.links -->