@icgio/icg-utils 1.9.8 → 1.9.10
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.
- package/lib/observable.js +4 -3
- package/lib/utils.js +8 -1
- package/package.json +1 -1
package/lib/observable.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
class Observable {
|
|
2
2
|
constructor() {
|
|
3
3
|
this.listeners = []
|
|
4
|
+
this.last_notify_time = 0
|
|
4
5
|
}
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -25,10 +26,10 @@ class Observable {
|
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Notify all subscribers about an update
|
|
28
|
-
* @param {*} data - The data to pass to subscribers
|
|
29
29
|
*/
|
|
30
|
-
notify(
|
|
31
|
-
this.listeners.forEach((callback) => callback(
|
|
30
|
+
notify() {
|
|
31
|
+
this.listeners.forEach((callback) => callback())
|
|
32
|
+
this.last_notify_time = Date.now()
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
package/lib/utils.js
CHANGED
|
@@ -847,6 +847,13 @@ module.exports.random_normal_range = (mean, std_dev, a, b) => {
|
|
|
847
847
|
let v = Math.random()
|
|
848
848
|
let z = Math.sqrt(-2.0 * Math.log(u)) * Math.cos(2.0 * Math.PI * v) // Box-Muller Transform
|
|
849
849
|
let num = mean + z * std_dev
|
|
850
|
-
// Clip to range
|
|
851
850
|
return Math.max(min, Math.min(max, num))
|
|
852
851
|
}
|
|
852
|
+
|
|
853
|
+
// module.exports.random_beta_range = (alpha, beta, a, b) => {
|
|
854
|
+
// let u = Math.random()
|
|
855
|
+
// let v = Math.random()
|
|
856
|
+
// let value = Math.pow(u, 1 / alpha) / (Math.pow(u, 1 / alpha) + Math.pow(v, 1 / beta))
|
|
857
|
+
// return a + value * (b - a) // Scale result into [a, b] range
|
|
858
|
+
// }
|
|
859
|
+
// console.log(module.exports.random_beta_range(1, 100, 0.02, 0.03))
|