time-to-botec

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

README.md (3132B)


      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 # isProbabilityArray
     22 
     23 > Test if a value is an array-like object containing only probabilities.
     24 
     25 <section class="intro">
     26 
     27 A **probability** is defined as a numeric value on the interval `[0,1]`.
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <section class="usage">
     34 
     35 ## Usage
     36 
     37 ```javascript
     38 var isProbabilityArray = require( '@stdlib/assert/is-probability-array' );
     39 ```
     40 
     41 #### isProbabilityArray( value )
     42 
     43 Tests if a `value` is an array-like object containing **only** probabilities.
     44 
     45 <!-- eslint-disable no-new-wrappers -->
     46 
     47 ```javascript
     48 var Number = require( '@stdlib/number/ctor' );
     49 var Uint8Array = require( '@stdlib/array/uint8' );
     50 
     51 var bool = isProbabilityArray( [ 0.6, 0.5, 0.25 ] );
     52 // returns true
     53 
     54 bool = isProbabilityArray( [ 0.6, 0.5, new Number( 0.25 ) ] );
     55 // returns true
     56 
     57 bool = isProbabilityArray( new Uint8Array( [ 0, 1 ] ) );
     58 // returns true
     59 
     60 bool = isProbabilityArray( [ 3.14, 0.0 ] );
     61 // returns false
     62 ```
     63 
     64 #### isProbabilityArray.primitives( value )
     65 
     66 Tests if a `value` is an array-like object `array` containing **only** primitive probabilities.
     67 
     68 <!-- eslint-disable no-new-wrappers -->
     69 
     70 ```javascript
     71 var Number = require( '@stdlib/number/ctor' );
     72 
     73 var bool = isProbabilityArray.primitives( [ 1.0, 0.0, 0.8 ] );
     74 // returns true
     75 
     76 bool = isProbabilityArray.primitives( [ 0.9, new Number(1.0) ] );
     77 // returns false
     78 ```
     79 
     80 #### isProbabilityArray.objects( value )
     81 
     82 Tests if a `value` is an array-like object `array` containing **only** `Number` objects whose values are probabilities.
     83 
     84 <!-- eslint-disable no-new-wrappers -->
     85 
     86 ```javascript
     87 var Number = require( '@stdlib/number/ctor' );
     88 
     89 var bool = isProbabilityArray.objects( [ new Number(1.0), new Number(1.0) ] );
     90 // returns true
     91 
     92 bool = isProbabilityArray.objects( [ 1.0, 0.0, 0.6 ] );
     93 // returns false
     94 ```
     95 
     96 </section>
     97 
     98 <!-- /.usage -->
     99 
    100 <section class="examples">
    101 
    102 ## Examples
    103 
    104 <!-- eslint no-undef: "error" -->
    105 
    106 ```javascript
    107 var Uint8Array = require( '@stdlib/array/uint8' );
    108 var isProbabilityArray = require( '@stdlib/assert/is-probability-array' );
    109 
    110 var arr = [ 0.0, 1.0, 0.5 ];
    111 var bool = isProbabilityArray( arr );
    112 // returns true
    113 
    114 arr = [ 0.5, 0.25, 0.25 ];
    115 bool = isProbabilityArray( arr );
    116 // returns true
    117 
    118 arr = new Uint8Array( [ 0, 0, 1, 0, 1 ] );
    119 bool = isProbabilityArray( arr );
    120 // returns true
    121 
    122 arr = [ 3.14, -1.0 ];
    123 bool = isProbabilityArray( arr );
    124 // returns false
    125 
    126 bool = isProbabilityArray( [] );
    127 // returns false
    128 
    129 bool = isProbabilityArray( null );
    130 // returns false
    131 ```
    132 
    133 </section>
    134 
    135 <!-- /.examples -->
    136 
    137 <section class="links">
    138 
    139 </section>
    140 
    141 <!-- /.links -->