changeset 24:0e8ee830b5ee

Normalise source distributions row-wise (per note)
author Chris Cannam
date Mon, 31 Mar 2014 12:46:24 +0100
parents 990b8b8b7e25
children 80f02ff5d37a
files yeti/em_onecolumn.yeti yeti/silvet.yeti
diffstat 2 files changed, 34 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/yeti/em_onecolumn.yeti	Fri Mar 28 15:38:07 2014 +0000
+++ b/yeti/em_onecolumn.yeti	Mon Mar 31 12:46:24 2014 +0100
@@ -22,14 +22,14 @@
         pitches = // z in the original. 1 per note
             normalise (vec.randoms notes),
         sources = // u in the original. 1 per note-instrument
-            //!!! should this be normalised across instruments? i.e. row-wise
-            mat.fromColumns
-               (map do instrument:
-                    vec.fromList
-                       (map do note:
-                            if inRange ranges instrument note then 1 else 0 fi
-                        done [0..notes-1])
-                done instruments),
+            mat.fromRows
+               (map do note:
+                   normalise
+                      (vec.fromList
+                          (map do instrument:
+                               if inRange ranges instrument note then 1 else 0 fi
+                           done instruments))
+                done [0..notes-1]),
         instruments = array instruments,
         instCount = length instruments,
         noteCount = notes,
@@ -88,27 +88,33 @@
         done [0..data.noteCount-1]);
     pitches = vec.divideBy (vec.sum pitches) pitches;
 
-    sources = mat.fromColumns
-       (map do inst: vec.fromList
-           (map do note:
+    sources = mat.fromRows
+       (map do note: vec.fromList
+           (map do inst:
                 if not inRange data.ranges inst note then epsilon else
                     { w, p, s } = distributionsFor data inst note;
                     fold do acc bin:
                         acc + s * p * (vec.at w bin) * (vec.at q bin);
                     done epsilon [0..vec.length column - 1]
                 fi;
-            done [0..data.noteCount-1])
-        done [0..data.instCount-1]);
+            done [0..data.instCount-1])
+        done [0..data.noteCount-1]);
    
     sourceDenoms = fold do acc inst:
         vec.add [acc, (mat.getColumn inst sources)]
     done (vec.zeros data.noteCount) [0..data.instCount-1];
-    
-    sources = mat.fromColumns
+
+    //!!! shouldn't this normalisation be the other way? (rows, not columns)    
+/*    sources = mat.fromColumns
        (map do inst: 
             vec.divide (mat.getColumn inst sources) sourceDenoms;
         done [0..data.instCount-1]);
- 
+*/
+    sources = mat.fromRows
+       (map do note: 
+            vec.divide (mat.getRow note sources) sourceDenoms;
+        done [0..data.noteCount-1]);
+
     data with { 
         pitches,
         sources,
--- a/yeti/silvet.yeti	Fri Mar 28 15:38:07 2014 +0000
+++ b/yeti/silvet.yeti	Mon Mar 31 12:46:24 2014 +0100
@@ -123,6 +123,18 @@
 
 println "Instruments: \(map do i: (d.instruments[i]) done instruments)";
 
+normalise v =
+   (s = vec.sum v;
+    if s > 0 then vec.divideBy s v 
+    else v
+    fi);
+
+if not (empty? sounding) then
+   p = head sounding;
+   i = head instruments;
+   w = mat.getColumn p d.templates[i];
+   \() (plot.plot [ Vector w, Vector (normalise col), Caption "Template for instrument \(d.instruments[i]), pitch \(p), against normalised source distribution" ]);
+fi;
 
 ();