comparison yeti/silvet.yeti @ 14:a91de434feb8

More (sometimes baffled) annotations and a bit of work on the EM
author Chris Cannam
date Mon, 24 Mar 2014 16:31:20 +0000
parents e15bc63cb146
children f1f8c84339d0
comparison
equal deleted inserted replaced
13:e15bc63cb146 14:a91de434feb8
1 1
2 program silvet; 2 program silvet;
3 3
4 { prepareTimeFrequency } = load timefreq; 4 { prepareTimeFrequency } = load timefreq;
5 { loadTemplates, extractRanges } = load templates; 5 { loadTemplates, extractRanges } = load templates;
6 { initialiseEM } = load em; 6
7 em = load em;
7 8
8 mat = load may.matrix; 9 mat = load may.matrix;
9 vec = load may.vector; 10 vec = load may.vector;
11 plot = load may.plot;
10 12
11 templates = loadTemplates (); 13 templates = loadTemplates ();
12 14
13 ranges = extractRanges templates; 15 ranges = extractRanges templates;
14 16
15 eprintln "\nWe have \(length (keys templates)) instruments:"; 17 eprintln "\nWe have \(length (keys templates)) instruments:";
16 for (sort (keys templates)) do k: 18 for (sort (keys templates)) do k:
17 eprintln " * \(k) \(mat.size templates[k]) range \(ranges[k].lowestNote) -> \(ranges[k].highestNote)"; 19 eprintln " * \(k) \(mat.size templates[k]) range \(ranges[k].lowest) -> \(ranges[k].highest)";
18 done; 20 done;
19 eprintln ""; 21 eprintln "";
20 22
21 columns = prepareTimeFrequency "test.wav"; 23 columns = prepareTimeFrequency "test.wav";
22 24
23 height = if empty? columns then 0 else vec.length (head columns) fi; 25 height = if empty? columns then 0 else vec.length (head columns) fi;
24 26
25 chunkSize = { rows = height, columns = 100 }; 27 chunkSize = { rows = height, columns = 100 };
26 28
27 emdata = initialiseEM ranges 88 chunkSize; 29 emdata = em.initialise ranges templates 88 chunkSize;
28 30
29 eprintln "initialised EM data"; 31 eprintln "initialised EM data: overall pitch range \(emdata.lowest) -> \(emdata.highest)";
30 32
31 chunkify cols = 33 chunkify cols =
32 if empty? cols then [] 34 if empty? cols then []
33 else 35 else
34 (mat.resizedTo chunkSize 36 (mat.resizedTo chunkSize
38 40
39 chunks = chunkify columns; 41 chunks = chunkify columns;
40 42
41 eprintln "we have \(length chunks) chunks of size \(mat.size (head chunks))"; 43 eprintln "we have \(length chunks) chunks of size \(mat.size (head chunks))";
42 44
45 eprintln "attempting one expectation phase...";
43 46
47 error = em.performExpectation emdata (head chunks);
48
49 eprintln "done, result has dimension \(mat.size error)";
50
51 eprintln "attempting one maximisation phase...";
52
53 newP = em.performMaximisation emdata (head chunks) error;
54
55 eprintln "done";
56
57 \() (plot.plot [ Grid (head chunks) ]);
58 \() (plot.plot [ Grid error ]);
59
60 \() (plot.plot [ Grid newP ]);
61
62 ();
63
64