@ohos-ports/stdlib-simulate 0.4.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/LICENSE +177 -0
  2. package/NOTICE +1 -0
  3. package/README.md +188 -0
  4. package/SECURITY.md +5 -0
  5. package/docs/types/index.d.ts +43 -0
  6. package/iter/README.md +142 -0
  7. package/iter/awgn/README.md +240 -0
  8. package/iter/awgn/docs/repl.txt +85 -0
  9. package/iter/awgn/docs/types/index.d.ts +155 -0
  10. package/iter/awgn/docs/types/test.ts +150 -0
  11. package/iter/awgn/lib/defaults.js +38 -0
  12. package/iter/awgn/lib/index.js +55 -0
  13. package/iter/awgn/lib/main.js +278 -0
  14. package/iter/awgn/package.json +68 -0
  15. package/iter/awln/README.md +238 -0
  16. package/iter/awln/docs/repl.txt +85 -0
  17. package/iter/awln/docs/types/index.d.ts +155 -0
  18. package/iter/awln/docs/types/test.ts +150 -0
  19. package/iter/awln/lib/defaults.js +38 -0
  20. package/iter/awln/lib/index.js +55 -0
  21. package/iter/awln/lib/main.js +299 -0
  22. package/iter/awln/package.json +72 -0
  23. package/iter/awun/README.md +238 -0
  24. package/iter/awun/docs/repl.txt +85 -0
  25. package/iter/awun/docs/types/index.d.ts +155 -0
  26. package/iter/awun/docs/types/test.ts +150 -0
  27. package/iter/awun/lib/defaults.js +38 -0
  28. package/iter/awun/lib/index.js +55 -0
  29. package/iter/awun/lib/main.js +305 -0
  30. package/iter/awun/package.json +68 -0
  31. package/iter/bartlett-hann-pulse/README.md +331 -0
  32. package/iter/bartlett-hann-pulse/docs/img/equation_bartlett_hann_pulse_waveform.svg +191 -0
  33. package/iter/bartlett-hann-pulse/docs/repl.txt +54 -0
  34. package/iter/bartlett-hann-pulse/docs/types/index.d.ts +105 -0
  35. package/iter/bartlett-hann-pulse/docs/types/test.ts +89 -0
  36. package/iter/bartlett-hann-pulse/lib/index.js +54 -0
  37. package/iter/bartlett-hann-pulse/lib/main.js +192 -0
  38. package/iter/bartlett-hann-pulse/lib/validate.js +97 -0
  39. package/iter/bartlett-hann-pulse/package.json +76 -0
  40. package/iter/bartlett-pulse/README.md +328 -0
  41. package/iter/bartlett-pulse/docs/img/equation_bartlett_pulse_waveform.svg +128 -0
  42. package/iter/bartlett-pulse/docs/repl.txt +54 -0
  43. package/iter/bartlett-pulse/docs/types/index.d.ts +105 -0
  44. package/iter/bartlett-pulse/docs/types/test.ts +89 -0
  45. package/iter/bartlett-pulse/lib/index.js +54 -0
  46. package/iter/bartlett-pulse/lib/main.js +169 -0
  47. package/iter/bartlett-pulse/lib/validate.js +97 -0
  48. package/iter/bartlett-pulse/package.json +72 -0
  49. package/iter/cosine-wave/README.md +292 -0
  50. package/iter/cosine-wave/docs/img/equation_cosine_waveform.svg +55 -0
  51. package/iter/cosine-wave/docs/repl.txt +51 -0
  52. package/iter/cosine-wave/docs/types/index.d.ts +96 -0
  53. package/iter/cosine-wave/docs/types/test.ts +78 -0
  54. package/iter/cosine-wave/lib/index.js +54 -0
  55. package/iter/cosine-wave/lib/main.js +156 -0
  56. package/iter/cosine-wave/lib/validate.js +90 -0
  57. package/iter/cosine-wave/package.json +70 -0
  58. package/iter/dirac-comb/README.md +278 -0
  59. package/iter/dirac-comb/docs/img/equation_dirac_comb.svg +44 -0
  60. package/iter/dirac-comb/docs/repl.txt +48 -0
  61. package/iter/dirac-comb/docs/types/index.d.ts +89 -0
  62. package/iter/dirac-comb/docs/types/test.ts +78 -0
  63. package/iter/dirac-comb/lib/index.js +54 -0
  64. package/iter/dirac-comb/lib/main.js +152 -0
  65. package/iter/dirac-comb/lib/validate.js +82 -0
  66. package/iter/dirac-comb/package.json +72 -0
  67. package/iter/docs/types/index.d.ts +678 -0
  68. package/iter/docs/types/test.ts +29 -0
  69. package/iter/flat-top-pulse/README.md +330 -0
  70. package/iter/flat-top-pulse/docs/img/equation_flat_top_pulse_waveform.svg +177 -0
  71. package/iter/flat-top-pulse/docs/repl.txt +54 -0
  72. package/iter/flat-top-pulse/docs/types/index.d.ts +105 -0
  73. package/iter/flat-top-pulse/docs/types/test.ts +89 -0
  74. package/iter/flat-top-pulse/lib/index.js +54 -0
  75. package/iter/flat-top-pulse/lib/main.js +193 -0
  76. package/iter/flat-top-pulse/lib/validate.js +97 -0
  77. package/iter/flat-top-pulse/package.json +71 -0
  78. package/iter/hann-pulse/README.md +328 -0
  79. package/iter/hann-pulse/docs/img/equation_hann_pulse_waveform.svg +129 -0
  80. package/iter/hann-pulse/docs/repl.txt +54 -0
  81. package/iter/hann-pulse/docs/types/index.d.ts +105 -0
  82. package/iter/hann-pulse/docs/types/test.ts +89 -0
  83. package/iter/hann-pulse/lib/index.js +54 -0
  84. package/iter/hann-pulse/lib/main.js +171 -0
  85. package/iter/hann-pulse/lib/validate.js +97 -0
  86. package/iter/hann-pulse/package.json +72 -0
  87. package/iter/lanczos-pulse/README.md +325 -0
  88. package/iter/lanczos-pulse/docs/img/equation_lanczos_pulse_waveform.svg +122 -0
  89. package/iter/lanczos-pulse/docs/repl.txt +54 -0
  90. package/iter/lanczos-pulse/docs/types/index.d.ts +105 -0
  91. package/iter/lanczos-pulse/docs/types/test.ts +89 -0
  92. package/iter/lanczos-pulse/lib/index.js +54 -0
  93. package/iter/lanczos-pulse/lib/main.js +169 -0
  94. package/iter/lanczos-pulse/lib/validate.js +97 -0
  95. package/iter/lanczos-pulse/package.json +70 -0
  96. package/iter/lib/index.js +186 -0
  97. package/iter/package.json +63 -0
  98. package/iter/periodic-sinc/README.md +301 -0
  99. package/iter/periodic-sinc/docs/img/equation_periodic_sinc.svg +146 -0
  100. package/iter/periodic-sinc/docs/img/equation_periodic_sinc_in_terms_of_period.svg +164 -0
  101. package/iter/periodic-sinc/docs/img/equation_periodic_sinc_in_terms_of_sinc_function.svg +65 -0
  102. package/iter/periodic-sinc/docs/img/equation_periodic_sinc_substitution_even.svg +34 -0
  103. package/iter/periodic-sinc/docs/img/equation_periodic_sinc_substitution_odd.svg +34 -0
  104. package/iter/periodic-sinc/docs/repl.txt +54 -0
  105. package/iter/periodic-sinc/docs/types/index.d.ts +98 -0
  106. package/iter/periodic-sinc/docs/types/test.ts +102 -0
  107. package/iter/periodic-sinc/lib/index.js +50 -0
  108. package/iter/periodic-sinc/lib/main.js +241 -0
  109. package/iter/periodic-sinc/lib/validate.js +90 -0
  110. package/iter/periodic-sinc/package.json +70 -0
  111. package/iter/pulse/README.md +322 -0
  112. package/iter/pulse/docs/img/equation_pulse_waveform.svg +115 -0
  113. package/iter/pulse/docs/repl.txt +58 -0
  114. package/iter/pulse/docs/types/index.d.ts +109 -0
  115. package/iter/pulse/docs/types/test.ts +100 -0
  116. package/iter/pulse/lib/index.js +54 -0
  117. package/iter/pulse/lib/main.js +165 -0
  118. package/iter/pulse/lib/validate.js +105 -0
  119. package/iter/pulse/package.json +69 -0
  120. package/iter/sawtooth-wave/README.md +289 -0
  121. package/iter/sawtooth-wave/docs/img/equation_sawtooth_waveform.svg +73 -0
  122. package/iter/sawtooth-wave/docs/repl.txt +51 -0
  123. package/iter/sawtooth-wave/docs/types/index.d.ts +96 -0
  124. package/iter/sawtooth-wave/docs/types/test.ts +78 -0
  125. package/iter/sawtooth-wave/lib/index.js +54 -0
  126. package/iter/sawtooth-wave/lib/main.js +161 -0
  127. package/iter/sawtooth-wave/lib/validate.js +90 -0
  128. package/iter/sawtooth-wave/package.json +67 -0
  129. package/iter/sine-wave/README.md +292 -0
  130. package/iter/sine-wave/docs/img/equation_sine_waveform.svg +55 -0
  131. package/iter/sine-wave/docs/repl.txt +51 -0
  132. package/iter/sine-wave/docs/types/index.d.ts +96 -0
  133. package/iter/sine-wave/docs/types/test.ts +78 -0
  134. package/iter/sine-wave/lib/index.js +54 -0
  135. package/iter/sine-wave/lib/main.js +156 -0
  136. package/iter/sine-wave/lib/validate.js +90 -0
  137. package/iter/sine-wave/package.json +70 -0
  138. package/iter/square-wave/README.md +291 -0
  139. package/iter/square-wave/docs/img/equation_square_waveform.svg +115 -0
  140. package/iter/square-wave/docs/repl.txt +55 -0
  141. package/iter/square-wave/docs/types/index.d.ts +105 -0
  142. package/iter/square-wave/docs/types/test.ts +89 -0
  143. package/iter/square-wave/lib/index.js +54 -0
  144. package/iter/square-wave/lib/main.js +156 -0
  145. package/iter/square-wave/lib/validate.js +99 -0
  146. package/iter/square-wave/package.json +67 -0
  147. package/iter/triangle-wave/README.md +289 -0
  148. package/iter/triangle-wave/docs/img/equation_triangle_waveform.svg +75 -0
  149. package/iter/triangle-wave/docs/repl.txt +51 -0
  150. package/iter/triangle-wave/docs/types/index.d.ts +96 -0
  151. package/iter/triangle-wave/docs/types/test.ts +78 -0
  152. package/iter/triangle-wave/lib/index.js +54 -0
  153. package/iter/triangle-wave/lib/main.js +160 -0
  154. package/iter/triangle-wave/lib/validate.js +90 -0
  155. package/iter/triangle-wave/package.json +66 -0
  156. package/lib/index.js +51 -0
  157. package/package.json +72 -0
@@ -0,0 +1,55 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2019 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ /**
22
+ * Create an iterator which introduces additive white Gaussian noise (AWGN).
23
+ *
24
+ * @module @stdlib/simulate/iter/awgn
25
+ *
26
+ * @example
27
+ * var iterSineWave = require( '@stdlib/simulate/iter/sine-wave' );
28
+ * var iterawgn = require( '@stdlib/simulate/iter/awgn' );
29
+ *
30
+ * var sine = iterSineWave({
31
+ * 'iter': 100
32
+ * });
33
+ *
34
+ * var it = iterawgn( sine, 0.5 );
35
+ *
36
+ * var v = it.next().value;
37
+ * // returns <number>
38
+ *
39
+ * v = it.next().value;
40
+ * // returns <number>
41
+ *
42
+ * v = it.next().value;
43
+ * // returns <number>
44
+ *
45
+ * // ...
46
+ */
47
+
48
+ // MODULES //
49
+
50
+ var main = require( './main.js' );
51
+
52
+
53
+ // EXPORTS //
54
+
55
+ module.exports = main;
@@ -0,0 +1,278 @@
1
+ /**
2
+ * @license Apache-2.0
3
+ *
4
+ * Copyright (c) 2019 The Stdlib Authors.
5
+ *
6
+ * Licensed under the Apache License, Version 2.0 (the "License");
7
+ * you may not use this file except in compliance with the License.
8
+ * You may obtain a copy of the License at
9
+ *
10
+ * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ */
18
+
19
+ 'use strict';
20
+
21
+ // MODULES //
22
+
23
+ var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24
+ var setReadOnlyAccessor = require( '@stdlib/utils/define-nonenumerable-read-only-accessor' );
25
+ var setReadWriteAccessor = require( '@stdlib/utils/define-nonenumerable-read-write-accessor' );
26
+ var isIteratorLike = require( '@stdlib/assert/is-iterator-like' );
27
+ var isPositiveNumber = require( '@stdlib/assert/is-positive-number' ).isPrimitive;
28
+ var isPlainObject = require( '@stdlib/assert/is-plain-object' );
29
+ var isFunction = require( '@stdlib/assert/is-function' );
30
+ var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
31
+ var isUint32Array = require( '@stdlib/assert/is-uint32array' );
32
+ var hasOwnProp = require( '@stdlib/assert/has-own-property' );
33
+ var noop = require( '@stdlib/utils/noop' );
34
+ var constantFunction = require( '@stdlib/utils/constant-function' );
35
+ var iteratorSymbol = require( '@stdlib/symbol/iterator' );
36
+ var format = require( '@stdlib/string/format' );
37
+ var randn = require( '@stdlib/random/base/improved-ziggurat' ).factory;
38
+ var defaults = require( './defaults.js' );
39
+
40
+
41
+ // MAIN //
42
+
43
+ /**
44
+ * Returns an iterator which introduces additive white Gaussian noise with standard deviation `sigma`.
45
+ *
46
+ * @param {Iterator} iterator - input iterator
47
+ * @param {PositiveNumber} sigma - standard deviation of the noise
48
+ * @param {Options} [options] - function options
49
+ * @param {PRNG} [options.prng] - pseudorandom number generator which generates pseudorandom numbers drawn from a standard normal distribution
50
+ * @param {PRNGSeedMT19937} [options.seed] - pseudorandom number generator seed
51
+ * @param {PRNGStateMT19937} [options.state] - pseudorandom number generator state
52
+ * @param {boolean} [options.copy=true] - boolean indicating whether to copy a provided pseudorandom number generator state
53
+ * @throws {TypeError} first argument must be an iterator
54
+ * @throws {TypeError} second argument must be a positive number
55
+ * @throws {TypeError} third argument must be an object
56
+ * @throws {TypeError} must provide valid options
57
+ * @throws {Error} must provide a valid state
58
+ * @returns {Iterator} iterator
59
+ *
60
+ * @example
61
+ * var iterSineWave = require( '@stdlib/simulate/iter/sine-wave' );
62
+ *
63
+ * var sine = iterSineWave({
64
+ * 'iter': 100
65
+ * });
66
+ *
67
+ * var it = iterawgn( sine, 0.5 );
68
+ *
69
+ * var v = it.next().value;
70
+ * // returns <number>
71
+ *
72
+ * v = it.next().value;
73
+ * // returns <number>
74
+ *
75
+ * v = it.next().value;
76
+ * // returns <number>
77
+ *
78
+ * // ...
79
+ */
80
+ function iterawgn( iterator, sigma, options ) {
81
+ var rnorm;
82
+ var opts;
83
+ var iter;
84
+ var FLG;
85
+ if ( !isIteratorLike( iterator ) ) {
86
+ throw new TypeError( format( 'invalid argument. First argument must be an iterator. Value: `%s`.', iterator ) );
87
+ }
88
+ if ( !isPositiveNumber( sigma ) ) {
89
+ throw new TypeError( format( 'invalid argument. Second argument must be a positive number. Value: `%s`.', sigma ) );
90
+ }
91
+ opts = defaults();
92
+ if ( arguments.length > 2 ) {
93
+ if ( !isPlainObject( options ) ) {
94
+ throw new TypeError( format( 'invalid argument. Third argument must be an object. Value: `%s`.', options ) );
95
+ }
96
+ if ( hasOwnProp( options, 'copy' ) ) {
97
+ opts.copy = options.copy;
98
+ if ( !isBoolean( options.copy ) ) {
99
+ throw new TypeError( format( 'invalid option. `%s` option must be a boolean. Option: `%s`.', 'copy', options.copy ) );
100
+ }
101
+ }
102
+ if ( hasOwnProp( options, 'prng' ) ) {
103
+ if ( !isFunction( options.prng ) ) {
104
+ throw new TypeError( format( 'invalid option. `%s` option must be a pseudorandom number generator function. Option: `%s`.', 'prng', options.prng ) );
105
+ }
106
+ rnorm = options.prng;
107
+ }
108
+ // If provided a PRNG, ignore the `state` option, as we don't support getting or setting PRNG state.
109
+ else if ( hasOwnProp( options, 'state' ) ) {
110
+ opts.state = options.state;
111
+ if ( !isUint32Array( options.state ) ) {
112
+ throw new TypeError( format( 'invalid option. `%s` option must be a Uint32Array. Option: `%s`.', 'state', options.state ) );
113
+ }
114
+ }
115
+ // If provided a PRNG, ignore the `seed` option, as a `seed`, by itself, is insufficient to guarantee reproducibility. If provided a state, ignore the `seed` option, as a PRNG state should contain seed information.
116
+ else if ( hasOwnProp( options, 'seed' ) ) {
117
+ opts.seed = options.seed;
118
+ if ( options.seed === void 0 ) {
119
+ throw new TypeError( format( 'invalid option. `%s` option must be either a positive integer less than or equal to the maximum unsigned 32-bit integer or an array-like object containing integer values less than or equal to the maximum unsigned 32-bit integer. Option: `%s`.', 'seed', options.seed ) );
120
+ }
121
+ }
122
+ }
123
+ if ( rnorm === void 0 ) {
124
+ rnorm = randn( opts );
125
+ }
126
+ // Create an iterator protocol-compliant object:
127
+ iter = {};
128
+ setReadOnly( iter, 'next', next );
129
+ setReadOnly( iter, 'return', end );
130
+
131
+ // If an environment supports `Symbol.iterator` and the provided iterator is iterable, make the iterator iterable:
132
+ if ( iteratorSymbol && isFunction( iterator[ iteratorSymbol ] ) ) {
133
+ setReadOnly( iter, iteratorSymbol, factory );
134
+ }
135
+ // If we are provided an "external" PRNG, we don't support getting or setting PRNG state, as we'd need to check for compatible state value types, etc, entailing considerable complexity.
136
+ if ( options && options.prng ) {
137
+ setReadOnly( iter, 'seed', null );
138
+ setReadOnly( iter, 'seedLength', null );
139
+ setReadWriteAccessor( iter, 'state', constantFunction( null ), noop );
140
+ setReadOnly( iter, 'stateLength', null );
141
+ setReadOnly( iter, 'byteLength', null );
142
+ setReadOnly( iter, 'PRNG', null );
143
+ } else {
144
+ setReadOnlyAccessor( iter, 'seed', getSeed );
145
+ setReadOnlyAccessor( iter, 'seedLength', getSeedLength );
146
+ setReadWriteAccessor( iter, 'state', getState, setState );
147
+ setReadOnlyAccessor( iter, 'stateLength', getStateLength );
148
+ setReadOnlyAccessor( iter, 'byteLength', getStateSize );
149
+ setReadOnly( iter, 'PRNG', rnorm.PRNG );
150
+ }
151
+
152
+ return iter;
153
+
154
+ /**
155
+ * Returns the PRNG seed.
156
+ *
157
+ * @private
158
+ * @returns {PRNGSeedMT19937} seed
159
+ */
160
+ function getSeed() {
161
+ return rnorm.seed;
162
+ }
163
+
164
+ /**
165
+ * Returns the PRNG seed length.
166
+ *
167
+ * @private
168
+ * @returns {PositiveInteger} seed length
169
+ */
170
+ function getSeedLength() {
171
+ return rnorm.seedLength;
172
+ }
173
+
174
+ /**
175
+ * Returns the PRNG state length.
176
+ *
177
+ * @private
178
+ * @returns {PositiveInteger} state length
179
+ */
180
+ function getStateLength() {
181
+ return rnorm.stateLength;
182
+ }
183
+
184
+ /**
185
+ * Returns the PRNG state size (in bytes).
186
+ *
187
+ * @private
188
+ * @returns {PositiveInteger} state size (in bytes)
189
+ */
190
+ function getStateSize() {
191
+ return rnorm.byteLength;
192
+ }
193
+
194
+ /**
195
+ * Returns the current PRNG state.
196
+ *
197
+ * @private
198
+ * @returns {PRNGStateMT19937} current state
199
+ */
200
+ function getState() {
201
+ return rnorm.state;
202
+ }
203
+
204
+ /**
205
+ * Sets the PRNG state.
206
+ *
207
+ * @private
208
+ * @param {PRNGStateMT19937} s - generator state
209
+ * @throws {Error} must provide a valid state
210
+ */
211
+ function setState( s ) {
212
+ rnorm.state = s;
213
+ }
214
+
215
+ /**
216
+ * Returns an iterator protocol-compliant object containing the next iterated value.
217
+ *
218
+ * @private
219
+ * @returns {Object} iterator protocol-compliant object
220
+ */
221
+ function next() {
222
+ var v;
223
+ if ( FLG ) {
224
+ return {
225
+ 'done': true
226
+ };
227
+ }
228
+ v = iterator.next();
229
+ if ( v.done ) {
230
+ FLG = true;
231
+ return v;
232
+ }
233
+ if ( typeof v.value === 'number' ) {
234
+ v = v.value + ( sigma*rnorm() );
235
+ } else {
236
+ v = NaN;
237
+ }
238
+ return {
239
+ 'value': v,
240
+ 'done': false
241
+ };
242
+ }
243
+
244
+ /**
245
+ * Finishes an iterator.
246
+ *
247
+ * @private
248
+ * @param {*} [value] - value to return
249
+ * @returns {Object} iterator protocol-compliant object
250
+ */
251
+ function end( value ) {
252
+ FLG = true;
253
+ if ( arguments.length ) {
254
+ return {
255
+ 'value': value,
256
+ 'done': true
257
+ };
258
+ }
259
+ return {
260
+ 'done': true
261
+ };
262
+ }
263
+
264
+ /**
265
+ * Returns a new iterator.
266
+ *
267
+ * @private
268
+ * @returns {Iterator} iterator
269
+ */
270
+ function factory() {
271
+ return iterawgn( iterator[ iteratorSymbol ](), sigma, opts );
272
+ }
273
+ }
274
+
275
+
276
+ // EXPORTS //
277
+
278
+ module.exports = iterawgn;
@@ -0,0 +1,68 @@
1
+ {
2
+ "name": "@stdlib/simulate/iter/awgn",
3
+ "version": "0.0.0",
4
+ "description": "Create an iterator which introduces additive white Gaussian noise.",
5
+ "license": "Apache-2.0",
6
+ "author": {
7
+ "name": "The Stdlib Authors",
8
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9
+ },
10
+ "contributors": [
11
+ {
12
+ "name": "The Stdlib Authors",
13
+ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14
+ }
15
+ ],
16
+ "main": "./lib",
17
+ "directories": {
18
+ "benchmark": "./benchmark",
19
+ "doc": "./docs",
20
+ "example": "./examples",
21
+ "lib": "./lib",
22
+ "test": "./test"
23
+ },
24
+ "types": "./docs/types",
25
+ "scripts": {},
26
+ "homepage": "https://github.com/stdlib-js/stdlib",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git://github.com/stdlib-js/stdlib.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/stdlib-js/stdlib/issues"
33
+ },
34
+ "dependencies": {},
35
+ "devDependencies": {},
36
+ "engines": {
37
+ "node": ">=0.10.0",
38
+ "npm": ">2.7.0"
39
+ },
40
+ "os": [
41
+ "aix",
42
+ "darwin",
43
+ "freebsd",
44
+ "linux",
45
+ "macos",
46
+ "openbsd",
47
+ "sunos",
48
+ "win32",
49
+ "windows"
50
+ ],
51
+ "keywords": [
52
+ "stdlib",
53
+ "simulate",
54
+ "simulation",
55
+ "noise",
56
+ "additive",
57
+ "white",
58
+ "gaussian",
59
+ "normal",
60
+ "information theory",
61
+ "random",
62
+ "iterator",
63
+ "iterable",
64
+ "iterate",
65
+ "iteration",
66
+ "iter"
67
+ ]
68
+ }
@@ -0,0 +1,238 @@
1
+ <!--
2
+
3
+ @license Apache-2.0
4
+
5
+ Copyright (c) 2019 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
+ # iterawln
22
+
23
+ > Create an [iterator][mdn-iterator-protocol] which introduces additive white Laplacian noise (AWLN).
24
+
25
+ <section class="intro">
26
+
27
+ </section>
28
+
29
+ <!-- /.intro -->
30
+
31
+ <!-- Package usage documentation. -->
32
+
33
+ <section class="usage">
34
+
35
+ ## Usage
36
+
37
+ ```javascript
38
+ var iterawln = require( '@stdlib/simulate/iter/awln' );
39
+ ```
40
+
41
+ #### iterawln( iterator, sigma\[, options] )
42
+
43
+ Returns an [iterator][mdn-iterator-protocol] which introduces additive white Laplacian (a.k.a. biexponential or double-exponential) noise (AWLN) with standard deviation `sigma`.
44
+
45
+ ```javascript
46
+ var array2iterator = require( '@stdlib/array/to-iterator' );
47
+
48
+ var arr = array2iterator( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
49
+ var it = iterawln( arr, 0.2 );
50
+
51
+ var v = it.next().value;
52
+ // returns <number>
53
+
54
+ v = it.next().value;
55
+ // returns <number>
56
+
57
+ // ...
58
+ ```
59
+
60
+ The returned iterator protocol-compliant object has the following properties:
61
+
62
+ - **next**: function which returns an iterator protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the iterator is finished.
63
+ - **return**: function which closes an iterator and returns a single (optional) argument in an iterator protocol-compliant object.
64
+ - **PRNG**: underlying pseudorandom number generator (PRNG).
65
+ - **seed**: pseudorandom number generator seed. If provided a PRNG, the property value is `null`.
66
+ - **seedLength**: length of generator seed. If provided a PRNG, the property value is `null`.
67
+ - **state**: pseudorandom number generator state. If provided a PRNG, the property value is `null`.
68
+ - **stateLength**: length of generator state. If provided a PRNG, the property value is `null`.
69
+ - **byteLength**: size (in bytes) of generator state. If provided a PRNG, the property value is `null`.
70
+
71
+ The function accepts the following `options`:
72
+
73
+ - **prng**: pseudorandom number generator for generating uniformly distributed pseudorandom numbers on the interval `[0,1)`. If provided, the function **ignores** both the `state` and `seed` options. In order to seed the returned iterator, one must seed the provided `prng` (assuming the provided `prng` is seedable).
74
+ - **seed**: pseudorandom number generator seed.
75
+ - **state**: a [`Uint32Array`][@stdlib/array/uint32] containing pseudorandom number generator state. If provided, the function ignores the `seed` option.
76
+ - **copy**: `boolean` indicating whether to copy a provided pseudorandom number generator state. Setting this option to `false` allows sharing state between two or more pseudorandom number generators. Setting this option to `true` ensures that a returned iterator has exclusive control over its internal state. Default: `true`.
77
+
78
+ By default, an iterator uses the [MT19937][@stdlib/random/base/mt19937] algorithm to generate uniformly distributed pseudorandom numbers on the interval `[0,1)`. To use a different PRNG, set the `prng` option.
79
+
80
+ ```javascript
81
+ var array2iterator = require( '@stdlib/array/to-iterator' );
82
+ var minstd = require( '@stdlib/random/base/minstd-shuffle' );
83
+
84
+ var arr = array2iterator( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
85
+ var it = iterawln( arr, 0.2, {
86
+ 'prng': minstd.normalized
87
+ });
88
+
89
+ var v = it.next().value;
90
+ // returns <number>
91
+ ```
92
+
93
+ To seed an iterator, set the `seed` option.
94
+
95
+ ```javascript
96
+ var array2iterator = require( '@stdlib/array/to-iterator' );
97
+
98
+ var arr = array2iterator( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
99
+ var it1 = iterawln( arr, 0.2, {
100
+ 'seed': 12345
101
+ });
102
+
103
+ var v1 = it1.next().value;
104
+ // returns <number>
105
+
106
+ var it2 = iterawln( arr, 0.2, {
107
+ 'seed': 12345
108
+ });
109
+
110
+ var v2 = it2.next().value;
111
+ // returns <number>
112
+
113
+ var bool = ( v1 === v2 );
114
+ // returns true
115
+ ```
116
+
117
+ To return an iterator having a specific initial state, set the iterator `state` option.
118
+
119
+ ```javascript
120
+ var array2iterator = require( '@stdlib/array/to-iterator' );
121
+ var arr = array2iterator( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
122
+
123
+ var it1 = iterawln( arr, 0.2 );
124
+
125
+ // Progress the underlying generator state:
126
+ var i;
127
+ for ( i = 0; i < 3; i++ ) {
128
+ it1.next();
129
+ }
130
+
131
+ // Create a new iterator initialized to the current state of `it1`:
132
+ var it2 = iterawln( arr, 0.2, {
133
+ 'state': it1.state
134
+ });
135
+
136
+ // Test that the iterator values are the same:
137
+ var bool = ( it1.next().value === it2.next().value );
138
+ // returns true
139
+ ```
140
+
141
+ </section>
142
+
143
+ <!-- /.usage -->
144
+
145
+ <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
146
+
147
+ <section class="notes">
148
+
149
+ ## Notes
150
+
151
+ - If PRNG state is "shared" (meaning a state array was provided during iterator creation and **not** copied) and one sets the iterator state to a state array having a different length, the iterator does **not** update the existing shared state and, instead, points to the newly provided state array. In order to synchronize generated output according to the new shared state array, the state array for **each** relevant PRNG/iterator must be **explicitly** set.
152
+ - If PRNG state is "shared" and one sets the iterator state to a state array of the same length, the PRNG state is updated (along with the state of all other PRNGs/iterators sharing the state array).
153
+ - If an iterated value is non-numeric (including `NaN`), the returned [`iterator`][mdn-iterator-protocol] returns `NaN`. If non-numeric iterated values are possible, you are advised to provide an [`iterator`][mdn-iterator-protocol] which type checks and handles non-numeric values accordingly.
154
+
155
+ </section>
156
+
157
+ <!-- /.notes -->
158
+
159
+ <!-- Package usage examples. -->
160
+
161
+ <section class="examples">
162
+
163
+ ## Examples
164
+
165
+ <!-- eslint no-undef: "error" -->
166
+
167
+ ```javascript
168
+ var iterSineWave = require( '@stdlib/simulate/iter/sine-wave' );
169
+ var iterawln = require( '@stdlib/simulate/iter/awln' );
170
+
171
+ // Create an iterator for generating a sine wave:
172
+ var sine = iterSineWave({
173
+ 'iter': 100,
174
+ 'amplitude': 10.0
175
+ });
176
+
177
+ // Create an iterator for introducing additive white Laplacian noise:
178
+ var it = iterawln( sine, 3.0 );
179
+
180
+ // Perform manual iteration...
181
+ var v;
182
+ while ( true ) {
183
+ v = it.next();
184
+ if ( v.done ) {
185
+ break;
186
+ }
187
+ console.log( v.value );
188
+ }
189
+ ```
190
+
191
+ </section>
192
+
193
+ <!-- /.examples -->
194
+
195
+ <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
196
+
197
+ <section class="references">
198
+
199
+ </section>
200
+
201
+ <!-- /.references -->
202
+
203
+ <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
204
+
205
+ <section class="related">
206
+
207
+ * * *
208
+
209
+ ## See Also
210
+
211
+ - <span class="package-name">[`@stdlib/simulate/iter/awgn`][@stdlib/simulate/iter/awgn]</span><span class="delimiter">: </span><span class="description">create an iterator which introduces additive white Gaussian noise.</span>
212
+ - <span class="package-name">[`@stdlib/simulate/iter/awun`][@stdlib/simulate/iter/awun]</span><span class="delimiter">: </span><span class="description">create an iterator which introduces additive white uniform noise.</span>
213
+
214
+ </section>
215
+
216
+ <!-- /.related -->
217
+
218
+ <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
219
+
220
+ <section class="links">
221
+
222
+ [mdn-iterator-protocol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#The_iterator_protocol
223
+
224
+ [@stdlib/array/uint32]: https://www.npmjs.com/package/@stdlib/array-uint32
225
+
226
+ [@stdlib/random/base/mt19937]: https://www.npmjs.com/package/@stdlib/random-base-mt19937
227
+
228
+ <!-- <related-links> -->
229
+
230
+ [@stdlib/simulate/iter/awgn]: https://github.com/stdlib-js/simulate/tree/main/iter/awgn
231
+
232
+ [@stdlib/simulate/iter/awun]: https://github.com/stdlib-js/simulate/tree/main/iter/awun
233
+
234
+ <!-- </related-links> -->
235
+
236
+ </section>
237
+
238
+ <!-- /.links -->