comparison yeti/silvet.yeti @ 27:9ec18d453889

Split single-column and matrix versions
author Chris Cannam
date Mon, 31 Mar 2014 17:06:24 +0100
parents fbc4011c7693
children cd9fd74931bb
comparison
equal deleted inserted replaced
26:fbc4011c7693 27:9ec18d453889
61 done; 61 done;
62 62
63 eprintln "done"; 63 eprintln "done";
64 64
65 65
66 /*
67 em1data = em1.initialise ranges templates 88;
68
69 col = head (drop 50 columns); // (drop ((length columns) / 2) columns);
70
71 \() (plot.plot [ Caption "Source frequency distribution", Vector col ]);
72
73 \() (plot.plot [ Caption "Source distribution beforehand", Grid em1data.sources]);
74
75 normalise v =
76 (s = vec.sum v;
77 if s > 0 then vec.divideBy s v
78 else v
79 fi);
80
81 oneIteration em1data col n =
82 ({ estimate, q } = em1.performExpectation em1data col;
83 newdata = em1.performMaximisation em1data col q;
84 if (n % 6 == 0) then
85 \() (plot.plot [ Caption "Pitch distribution before and after M-step update for iteration \(n)", Vector (em1data.pitches), Vector (newdata.pitches) ]);
86 \() (plot.plot [ Caption "Source distribution after M-step update for iteration \(n)", Grid newdata.sources ]);
87 \() (plot.plot [ Caption "Q function for E-step iteration \(n)", Vector q ]);
88 \() (plot.plot [ Caption "Estimate from E-step iteration \(n) against original source distribution, and difference between them", Vector estimate, Vector (normalise col), Vector (vec.subtract estimate (normalise col)) ]);
89 fi;
90 newdata);
91
92 iterations = 12;
93
94 var d = em1data;
95
96 for [1..iterations] do i:
97 d := oneIteration d col i;
98 done;
99
100 var sounding = [];
101
102 println "pitch distribution: \(vec.list d.pitches)";
103
104 for [d.lowest .. d.highest] do p:
105 if (vec.at d.pitches p) > 0.05 then
106 sounding := sounding ++ [p];
107 fi;
108 done;
109
110 println "Sounding: \(sounding)";
111
112 toNote p = (array ["A","A#","B","C","C#","D","D#","E","F","F#","G","G#"])[p % 12];
113
114 println "Notes: \(map toNote sounding)";
115
116 var instruments = [];
117 for sounding do p:
118 var best = 0;
119 var bestp = 0;
120 for [0..d.instCount-1] do i:
121 if mat.at d.sources p i > bestp then
122 bestp := mat.at d.sources p i;
123 best := i;
124 fi;
125 done;
126 if bestp > 0 then
127 instruments := instruments ++ [best];
128 else
129 instruments := instruments ++ [-1];
130 fi;
131 done;
132
133 println "Instruments: \(map do i: (d.instruments[i]) done instruments)";
134
135 if not (empty? sounding) then
136 p = head sounding;
137 i = head instruments;
138 w = mat.getColumn p d.templates[i];
139 \() (plot.plot [ Vector w, Vector (normalise col), Caption "Template for instrument \(d.instruments[i]), pitch \(p), against normalised source distribution" ]);
140 fi;
141 */
142
143 (); 66 ();
144 67
145 68