changeset 28:cd9fd74931bb

Reuse some calculations, plot some plots
author Chris Cannam
date Mon, 31 Mar 2014 17:21:51 +0100
parents 9ec18d453889
children 6a80e0cb2c94
files yeti/em.yeti yeti/silvet.yeti yeti/silvet_onecolumn.yeti
diffstat 3 files changed, 21 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/yeti/em.yeti	Mon Mar 31 17:06:24 2014 +0100
+++ b/yeti/em.yeti	Mon Mar 31 17:21:51 2014 +0100
@@ -83,18 +83,23 @@
     columns = mat.width chunk;
     e = mat.constMatrix epsilon { rows = 1, columns };
 
+    noteInstrumentProducts = [:];
+
     pitches = mat.concatVertical
        (map do note:
             if note < data.lowest or note > data.highest then e else
                 fold do acc inst:
                     { w, p, s } = distributionsFor data inst note;
-                    fold do acc bin:
-                         mat.sum
-                            [acc, 
-                             mat.scaled (mat.at w bin 0) 
-                                (mat.entryWiseProduct
-                                    [p, s, mat.newRowVector (mat.getRow bin chunk)])]
-                    done acc [0..mat.height chunk - 1]
+                    prod =
+                        fold do acc bin:
+                            mat.sum
+                               [acc, 
+                                mat.scaled (mat.at w bin 0) 
+                                   (mat.entryWiseProduct
+                                       [p, s, mat.newRowVector (mat.getRow bin chunk)])]
+                        done e [0..mat.height chunk - 1];
+                    noteInstrumentProducts[{inst,note}] := prod;
+                    mat.sum [acc, prod];
                 done e [0..data.nInstruments-1]
             fi;
         done [0..data.nNotes - 1]);
@@ -105,14 +110,7 @@
            (mat.concatVertical
                (map do note:
                     if not inRange data.ranges inst note then e else
-                        { w, p, s } = distributionsFor data inst note;
-                        fold do acc bin:
-                            mat.sum
-                               [acc,
-                                mat.scaled (mat.at w bin 0)
-                                   (mat.entryWiseProduct
-                                       [p, s, mat.newRowVector (mat.getRow bin chunk)])]
-                        done e [0..mat.height chunk - 1]
+                        noteInstrumentProducts[{inst,note}]
                     fi
                 done [0..data.nNotes - 1]))
         done [0..data.nInstruments-1]);
--- a/yeti/silvet.yeti	Mon Mar 31 17:06:24 2014 +0100
+++ b/yeti/silvet.yeti	Mon Mar 31 17:21:51 2014 +0100
@@ -5,7 +5,6 @@
 { loadTemplates, extractRanges } = load templates;
 
 em = load em;
-em1 = load em_onecolumn;
 
 mat = load may.matrix;
 vec = load may.vector;
@@ -44,7 +43,9 @@
 eprintln "we have \(length chunks) chunks of size \(mat.size (head chunks))";
 
 oneIteration emdata chunk n =
-   ({ estimate, q } = em.performExpectation emdata chunk;
+   (eprintln "E";
+    { estimate, q } = em.performExpectation emdata chunk;
+    eprintln "M";
     newdata = em.performMaximisation emdata chunk q;
     if (n % 6 == 0) then
         \() (plot.plot [ Grid chunk ]);
@@ -60,7 +61,10 @@
     d := oneIteration d (head chunks) i;
 done;    
 
-eprintln "done";
+eprintln "done, plotting pitch activation matrix";
+
+\() (plot.plot [Grid d.pitches]);
+\() (plot.plot [Contour d.pitches]);
 
 
 ();
--- a/yeti/silvet_onecolumn.yeti	Mon Mar 31 17:06:24 2014 +0100
+++ b/yeti/silvet_onecolumn.yeti	Mon Mar 31 17:21:51 2014 +0100
@@ -26,7 +26,7 @@
 
 em1data = em1.initialise ranges templates 88;
 
-col = head (drop 50 columns); // (drop ((length columns) / 2) columns);
+col = head (drop 50 columns);
 
 \() (plot.plot [ Caption "Source frequency distribution", Vector col ]);