Skip to content

Commit e92093e

Browse files
committed
fix: addressing first round comments
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: passed - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent c865177 commit e92093e

2 files changed

Lines changed: 53 additions & 37 deletions

File tree

lib/node_modules/@stdlib/stats/incr/wvariance/README.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,6 @@ console.log( accumulator() );
130130

131131
<section class="related">
132132

133-
* * *
134-
135-
## See Also
136-
137-
- <span class="package-name">[`@stdlib/stats/incr/ewvariance`][@stdlib/stats/incr/ewvariance]</span><span class="delimiter">: </span><span class="description">compute an exponentially weighted variance incrementally.</span>
138-
- <span class="package-name">[`@stdlib/stats/incr/variance`][@stdlib/stats/incr/variance]</span><span class="delimiter">: </span><span class="description">compute a variance incrementally.</span>
139-
- <span class="package-name">[`@stdlib/stats/incr/wmean`][@stdlib/stats/incr/wmean]</span><span class="delimiter">: </span><span class="description">compute a weighted arithmetic mean incrementally.</span>
140-
141133
</section>
142134

143135
<!-- /.related -->
@@ -150,12 +142,6 @@ console.log( accumulator() );
150142

151143
<!-- <related-links> -->
152144

153-
[@stdlib/stats/incr/ewvariance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/ewvariance
154-
155-
[@stdlib/stats/incr/variance]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/variance
156-
157-
[@stdlib/stats/incr/wmean]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/incr/wmean
158-
159145
<!-- </related-links> -->
160146

161147
</section>

lib/node_modules/@stdlib/stats/incr/wvariance/test/fixtures/python/runner.py

Lines changed: 53 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,70 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818

19-
2019
"""Generate fixture data for testing incremental weighted variance."""
2120

21+
import os
2222
import json
2323
import numpy as np
2424

25-
# reproducibility
26-
rng = np.random.default_rng(42)
25+
# Get the file path:
26+
FILE = os.path.realpath(__file__)
27+
28+
# Extract the directory in which this file resides:
29+
DIR = os.path.dirname(FILE)
30+
31+
32+
def gen(n, seed, name):
33+
"""Generate fixture data and write to file.
34+
35+
# Arguments
36+
37+
* `n`: number of samples
38+
* `seed`: random number generator seed
39+
* `name::str`: output filename
40+
41+
# Examples
42+
43+
``` python
44+
python> gen(50, 42, './data.json')
45+
```
46+
"""
47+
# Initialize random number generator for reproducibility:
48+
rng = np.random.default_rng(seed)
49+
50+
# Generate data:
51+
x = rng.normal(loc=0.0, scale=10.0, size=n)
52+
w = rng.uniform(0.1, 5.0, size=n)
53+
54+
# Store data to be written to file as a list of records:
55+
records = []
2756

28-
n = 50 # number of samples
57+
for k in range(1, n + 1):
58+
x_vals = x[:k]
59+
w_vals = w[:k]
2960

30-
# generate data
31-
x = rng.normal(loc=0.0, scale=10.0, size=n)
32-
w = rng.uniform(0.1, 5.0, size=n)
61+
weighted_mean = np.average(x_vals, weights=w_vals)
62+
var = np.average((x_vals - weighted_mean) ** 2, weights=w_vals)
3363

34-
records = []
64+
records.append({
65+
"step": k,
66+
"x": float(x[k - 1]),
67+
"w": float(w[k - 1]),
68+
"variance": float(var)
69+
})
3570

36-
for k in range(1, n + 1):
37-
xk = x[:k]
38-
wk = w[:k]
71+
# Based on the script directory, create an output filepath:
72+
filepath = os.path.join(DIR, name)
3973

40-
mu = np.average(xk, weights=wk)
74+
# Write the data to the output filepath as JSON:
75+
with open(filepath, "w", encoding="utf-8") as outfile:
76+
json.dump(records, outfile, indent=2)
4177

42-
var = np.average((xk - mu) ** 2, weights=wk)
4378

44-
records.append({
45-
"step": k,
46-
"x": float(x[k - 1]),
47-
"w": float(w[k - 1]),
48-
"variance": float(var)
49-
})
79+
def main():
80+
"""Generate fixture data."""
81+
gen(50, 42, "data.json")
5082

51-
# write to json
52-
with open("data.json", "w", encoding="utf-8") as f:
53-
json.dump(records, f, indent=2)
5483

55-
print("data.json written with", n, "records")
84+
if __name__ == "__main__":
85+
main()

0 commit comments

Comments
 (0)