changeset 182:45120df952be

add head_map fn
author Henry S. Thompson <ht@inf.ed.ac.uk>
date Mon, 27 Nov 2023 22:14:53 +0000
parents 0058e523f649
children 0153b58ccff6
files lib/python/cc/ccstats.py
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/lib/python/cc/ccstats.py	Mon Nov 27 18:25:39 2023 +0000
+++ b/lib/python/cc/ccstats.py	Mon Nov 27 22:14:53 2023 +0000
@@ -210,6 +210,21 @@
         ds2 = delta2 / stdev
         print(n,p,q,'%6.4g'%delta1,'%4.2g'%ds1,'%6.4g'%delta2,'%4.2g'%ds2)
 
+def heat_map(basis_ym, basis_names, target_ym, target_names, nn, outf = sys.stdout):
+  nn=nn if isinstance(nn,list) else list(nn)
+  with (outf if outf is sys.stdout else open(outf,'w')) as outfile:
+    print("\tN",file=outfile)
+    print("Predict","\t".join(["{:d}"]*len(nn)).format(*nn),sep="\t",file=outfile)
+    for p in basis_names:
+      for q in target_names:
+        basis=SS[f'{basis_ym} {p}']
+        target=SS[f'{target_ym} {q}']
+        best = (stats.describe(target.all[np.array(basis.iranks_by_all[:n])]).mean
+                for n in nn)
+        print(f"{q} by {p}",
+              "\t".join(['{:6.4g}']*len(nn)).format(*best),
+              sep="\t",file=outfile)
+
 def predict(basis_ym, basis_name, target_ym, target_name, n):
   basis = SS['%s %s'%(basis_ym, basis_name)]
   target = SS['%s %s'%(target_ym, target_name)]