changeset 13:e15bc63cb146

Ranges, EM initialisation
author Chris Cannam
date Fri, 21 Mar 2014 18:12:38 +0000
parents 0f6db1895e1c
children a91de434feb8
files notes/cplcaMT-annotated.m yeti/em.yeti yeti/silvet.yeti yeti/templates.yeti
diffstat 4 files changed, 64 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/notes/cplcaMT-annotated.m	Fri Mar 21 17:14:44 2014 +0000
+++ b/notes/cplcaMT-annotated.m	Fri Mar 21 18:12:38 2014 +0000
@@ -223,7 +223,7 @@
     %disp(['Iteration: ' num2str(it)]);
     
     % E-step
-    xa = eps; %% tiny non-zero initialiser
+    xa = eps; %% tiny non-zero initialiser as we'll be dividing by this later
     for k = 16:73  %% overall note range found in instrument set
         fh{k} = fftn( h{k}, wc); %% this and the subsequent ifftn are for the pitch-shift convolution step I think
         for r=1:R  %% instruments
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/yeti/em.yeti	Fri Mar 21 18:12:38 2014 +0000
@@ -0,0 +1,31 @@
+
+module em;
+
+mm = load may.mathmisc;
+vec = load may.vector;
+mat = load may.matrix;
+
+initialiseEM ranges notes size =
+    {
+        pitches = // z in the original
+            array (map do note:
+                map \(mm.random ()) [0..size.columns-1]
+            done [0..notes-1]),
+        sources =
+            mapIntoHash id // u in the original
+                do instrument:
+                    array (map do note:
+                        if note >= ranges[instrument].lowestNote and
+                           note <= ranges[instrument].highestNote
+                        then vec.ones size.columns
+                        else vec.zeros size.columns
+                        fi
+                    done [0..notes-1])
+                done (keys ranges);
+    };
+
+{
+    initialiseEM
+}
+
+
--- a/yeti/silvet.yeti	Fri Mar 21 17:14:44 2014 +0000
+++ b/yeti/silvet.yeti	Fri Mar 21 18:12:38 2014 +0000
@@ -2,31 +2,42 @@
 program silvet;
 
 { prepareTimeFrequency } = load timefreq;
-{ loadTemplates } = load templates;
+{ loadTemplates, extractRanges } = load templates;
+{ initialiseEM } = load em;
 
 mat = load may.matrix;
 vec = load may.vector;
 
 templates = loadTemplates ();
 
-eprintln "we have \(length (keys templates)) instruments:";
-for (sort (keys templates)) eprintln;
+ranges = extractRanges templates;
+
+eprintln "\nWe have \(length (keys templates)) instruments:";
+for (sort (keys templates)) do k:
+    eprintln " * \(k) \(mat.size templates[k]) range \(ranges[k].lowestNote) -> \(ranges[k].highestNote)";
+done;
 eprintln "";
 
 columns = prepareTimeFrequency "test.wav";
 
-chunkSize = 100;
 height = if empty? columns then 0 else vec.length (head columns) fi;
 
+chunkSize = { rows = height, columns = 100 };
+
+emdata = initialiseEM ranges 88 chunkSize;
+
+eprintln "initialised EM data";
+
 chunkify cols = 
     if empty? cols then []
     else
-       (mat.resizedTo { rows = chunkSize, columns = height }
-           (mat.fromColumns (take chunkSize cols)))
-        :. \(chunkify (drop chunkSize cols));
+       (mat.resizedTo chunkSize
+           (mat.fromColumns (take chunkSize.columns cols)))
+        :. \(chunkify (drop chunkSize.columns cols));
     fi;
 
 chunks = chunkify columns;
 
 eprintln "we have \(length chunks) chunks of size \(mat.size (head chunks))";
 
+
--- a/yeti/templates.yeti	Fri Mar 21 17:14:44 2014 +0000
+++ b/yeti/templates.yeti	Fri Mar 21 18:12:38 2014 +0000
@@ -2,6 +2,7 @@
 module templates;
 
 vec = load may.vector;
+mat = load may.matrix;
 
 // Load instrument templates
 
@@ -22,14 +23,24 @@
     do instrument:
         readFile "../data/\(instrument).csv" "UTF-8"
             do istr:
-                array
+                mat.fromColumns
                    (map do line:
                         vec.fromList (map number (strSplit "," line))
-                   done (istr.lines ()));
+                    done (istr.lines ()));
             done;
     done instruments;
 
+//!!! these ranges are hardcoded in the original (and are a bit more restrictive)
+extractRanges templates = mapIntoHash id
+    do instrument:
+        levels = map vec.sum (mat.asColumns (templates[instrument]));
+        first = length levels - length (find (>0) levels);
+        last = length (find (>0) (reverse levels)) - 1;
+        { lowestNote = first, highestNote = last }
+    done (keys templates);
+
 {
-    loadTemplates
+    loadTemplates,
+    extractRanges
 }