Download scripts/_tmp_oav_variance.py from mattbitzesty/pino-source-code: direct link, hf CLI and curl.
- Browser
- Download file 1.16 kB
-
https://huggingface.co/mattbitzesty/pino-source-code/resolve/e12dde84fe90540d000add61648844fbfd8ebdc7/scripts/_tmp_oav_variance.py
- Command line
-
hf download hf://mattbitzesty/pino-source-code@e12dde84fe90540d000add61648844fbfd8ebdc7/scripts/_tmp_oav_variance.py
-
curl -L -o _tmp_oav_variance.py https://huggingface.co/mattbitzesty/pino-source-code/resolve/e12dde84fe90540d000add61648844fbfd8ebdc7/scripts/_tmp_oav_variance.py
1.16 kB
| import json | |
| import numpy as np | |
| from pathlib import Path | |
| lines = Path('data/empirical_dataset_v1.jsonl').read_text().splitlines()[:1000] | |
| records = [json.loads(l) for l in lines] | |
| variances = [] | |
| for rec in records: | |
| traj = rec['trajectory'] | |
| t_steps = len(traj) | |
| s_ing = len(rec['formula']) | |
| oav = np.zeros((t_steps, s_ing)) | |
| for t, step in enumerate(traj): | |
| oav_step = step.get('OAV', {}) | |
| for s, comp in enumerate(rec['formula']): | |
| cas = comp.get('cas', '') | |
| if cas.startswith('NATURAL:'): | |
| cas = cas[len('NATURAL:'):] | |
| oav[t, s] = oav_step.get(cas, 0.0) | |
| # Mean CV of OAV per ingredient across time. | |
| mean_per_ing = oav.mean(axis=0) | |
| std_per_ing = oav.std(axis=0) | |
| cv = (std_per_ing / (mean_per_ing + 1e-8)).mean() | |
| variances.append(cv) | |
| print('mean CV', np.mean(variances)) | |
| print('median CV', np.median(variances)) | |
| print('max CV', np.max(variances)) | |
| # Check a single-ingredient record. | |
| for rec in records: | |
| if len(rec['formula']) == 1: | |
| print('single ing OAV', [step['OAV'][rec['formula'][0]['cas']] for step in rec['trajectory'][:5]]) | |
| break | |