comparison cpack/dml/lib/dml_c3.pl @ 0:718306e29690 tip

commiting public release
author Daniel Wolff
date Tue, 09 Feb 2016 21:05:06 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:718306e29690
1 :- module(dml_c3,
2 [ csv_op_chart/3
3 , cla_op_chart/3
4 , cla_label_lang/3
5 , c3_bar/3, c3_bar/2
6 , c3_plot/3
7 , c3_steps/3
8 , c3_csteps/3
9 , c3_hist/5
10 ]).
11
12 :- use_module(library(computations)).
13 :- use_module(library(mlserver)).
14 :- use_rendering(c3).
15
16 csv_op_chart(Op,Result,Chart) :- op_chart(Op,Result,Chart), !.
17 csv_op_chart(Op,X,unrecognised(Op,X)).
18
19 op_chart(pitch_hist(_Weighting),Pairs,Ch) :-
20 unzip(Pairs,NoteNums,Counts),
21 maplist(computations:pitch_number_name,NoteNums,Pitches),
22 c3_bar(pitch-Pitches,counts-Counts,Ch1),
23 Ch=Ch1.put(axis/x/type,categorical).
24
25 op_chart(freq_hist(Map,_),Counts,Ch) :- c3_hist(bars,pitch,Map,Counts,Ch).
26 op_chart(freq_hist_r(Map,_),Counts,Ch) :- c3_hist(bars,pitch,Map,Counts,Ch).
27 op_chart(tempo,Pairs,Ch) :- unzip(Pairs,T,X), c3_plot(time-T,tempo-X,Ch).
28 op_chart(uniform_tempo(_),T-X,Ch) :- c3_plot(time-T,tempo-X,Ch).
29 op_chart(uniform_tempo_r(_),T-X,Ch) :- c3_plot(time-T,tempo-X,Ch).
30 op_chart(uniform_tempo(_,_),T-X,Ch) :- c3_plot(time-T,tempo-X,Ch).
31 op_chart(uniform_tempo_r(_,_),T-X,Ch) :- c3_plot(time-T,tempo-X,Ch).
32 op_chart(tempo_hist_r(_DT,Map),_-Counts,Ch) :- c3_hist(steps,tempo,Map,Counts,Ch).
33 op_chart(tempo_hist(_DT,Map),_-Counts,Ch) :- c3_hist(steps,tempo,Map,Counts,Ch).
34 op_chart(normalised_tempo(N),_T-X,Ch) :- tempo_curve(N,X,Ch).
35 op_chart(normalised_tempo_r(N),_T-X,Ch) :- tempo_curve(N,X,Ch).
36
37 cla_op_chart(Op,X,Chart) :- cla_chart(Op,X,Chart), !.
38 cla_op_chart(Op,X,unrecognised(Op,X)).
39
40 cla_chart(Op,X,Chart) :-
41 is_dict(X), _{result:R} :< X, !,
42 cla_chart(Op,R,Chart).
43
44 cla_chart(collection_pitch_histogram(_),X,Chart) :-
45 c3_bar(notenum-X.values,counts-X.counts,Chart).
46
47 cla_chart(collection_freq_histogram(Min,Max,Quant,_),X,Chart) :- % matlab
48 c3_hist(bars,pitch,binmap(Min,Max,(Max-Min)*Quant+1),X.counts,Chart).
49
50 cla_chart(collection_freq_histogram(_Lang,Min,Max,Quant,_),X,Chart) :-
51 c3_hist(bars,pitch,binmap(Min,Max,(Max-Min)*Quant+1),X.counts,Chart).
52
53 cla_chart(collection_tempo_histogram(_,Min,Max,N),X,Chart) :- % matlab
54 c3_hist(steps,tempo,expmap(Min,Max,N),X.counts,Chart).
55
56 cla_chart(collection_tempo_histogram(_Lang,_,Min,Max,N),X,Chart) :-
57 c3_hist(steps,tempo,expmap(Min,Max,N),X.counts,Chart).
58
59 cla_chart(collection_tempo_curve(N),X,Chart) :- % matlab
60 tempo_curve(N,X.means,Chart).
61
62 cla_chart(collection_tempo_curve(_Lang,N),X,Chart) :-
63 tempo_curve(N,X.means,Chart).
64
65 cla_chart(py_hist(tagged(tonic), key_tonic_hist:aggregate, []),X,Chart) :-
66 c3_bar(key-X.values,counts-X.counts,Chart1),
67 Chart=Chart1.put(axis/x/type,categorical).
68
69 cla_chart(py_hist(tagged(transcription), semitone_hist:aggregate, []),X,Chart) :-
70 c3_bar('pitch class'-X.values,counts-X.counts,Chart1),
71 Chart=Chart1.put(axis/x/type,categorical).
72
73 cla_chart(tuning_stats, X, Chart) :-
74 Hist=X.stats.hist,
75 c3_hist(steps,frequency,edgemap(Hist.edges),Hist.counts,Chart).
76
77 cla_chart(py_cla(tagged(transcription(1)), tuning_stats:per_file, []),X, Chart) :-
78 cla_chart(tuning_stats, X, Chart).
79
80
81 tempo_curve(N,X,Chart) :-
82 numlist(1,N,T),
83 c3_csteps(time-T,tempo-X,Chart).
84
85 c3_hist(bars,XLabel,Map,Counts,Chart) :-
86 array_list(centres(Map),Centres1),
87 maplist(fix(2),Centres1,Centres),
88 c3_bar(XLabel-Centres,counts-Counts,Chart).
89
90 c3_hist(steps,XLabel,Map,Counts,Chart) :-
91 array_list(edges(Map),Edges1),
92 maplist(fix(2),Edges1,Edges),
93 append(Counts,[0],C),
94 c3_steps(XLabel-Edges,counts-C,Chart).
95
96
97 fix(N,X,Y) :- Q is 10^N, Y is round(X*Q)/Q.
98
99 :- public c3:put//2
100 , c3:axis//2
101 , c3:bar//2
102 , c3:area//2
103 , c3:zoom//1
104 , c3:legend//1
105 , c3:subchart//1
106 , c3:put//2
107 , c3:scat//2
108 .
109
110 c3:put(Path,Val,D1,D1.put(Path,Val)).
111 c3:axis(Name,Label,D1,D2) :- axis_pos(Name,Pos), D2=D1.put(axis/Name/label,_{text:Label,position:Pos}).
112 c3:axes(Lab1,Lab2) --> c3:axis(x,Lab1), c3:axis(y,Lab2).
113 c3:legend(F) --> c3:put(legend/show,F).
114 c3:subchart(F) --> c3:put(subchart/show,F).
115 c3:zoom(F) --> c3:put(zoom/enabled,F).
116
117 c3:scat(XLabel,YLabel) --> c3:init(scatter,XLabel,YLabel).
118 c3:bar(XLabel,YLabel) --> c3:init(bar,XLabel,YLabel).
119 c3:area(XLabel,YLabel) --> c3:init(area,XLabel,YLabel).
120
121 c3:init(Type,XLabel,YLabel) -->
122 c3:axes(XLabel,YLabel),
123 c3:put(data,_{columns:[],type:Type}),
124 c3:put(axis/x/tick/fit,false).
125
126 axis_pos(x,'outer-center').
127 axis_pos(y,'outer-middle').
128
129 c3_plot(XL-XV,YL-YV, c3{data:_{x:XL,columns:[[XL|XV],[YL|YV]]}}.axes(XL,YL).legend(false)).
130 c3_steps(XL-XV,YL-YV, c3{ line:_{step:_{type:'step-after'}},
131 data:_{type:'area-step',x:XL, columns:[[XL|XV],[YL|YV]]}
132 }.axes(XL,YL).legend(false)).
133 c3_csteps(XL-XV,YL-YV, c3{data:_{type:step,x:XL,columns:[[XL|XV],[YL|YV]]}}.axes(XL,YL).legend(false)).
134 c3_bar(Label-Vals,c3{data:_{type:bar, columns:[[Label|Vals]]}}.axis(y,Label)).
135 c3_bar(XL-XV,YL-YV,c3{data:_{type:bar, x:XL, columns:[[XL|XV],[YL|YV]]}}.axes(XL,YL).legend(false)).
136
137
138 cla_label_lang(collection_pitch_histogram(_),pitch_histogram,pl).
139 cla_label_lang(collection_freq_histogram(_,_,_,_),freq_histogram,ml).
140 cla_label_lang(collection_freq_histogram(Lang,_,_,_,_),freq_histogram,Lang).
141 cla_label_lang(collection_tempo_histogram(_,_,_,_),tempo_histogram,ml). % matlab
142 cla_label_lang(collection_tempo_histogram(Lang,_,_,_,_),tempo_histogram,Lang).
143 cla_label_lang(collection_tempo_curve(_),tempo_curve,ml). % matlab
144 cla_label_lang(collection_tempo_curve(Lang,_),tempo_curve,Lang).
145 cla_label_lang(py_hist(tagged(tonic), key_tonic_hist:aggregate, []),tonic_histogram,py).
146 cla_label_lang(py_hist(tagged(transcription), semitone_hist:aggregate, _),pc_histogram,py).
147 cla_label_lang(tuning_stats, tuning_stats, py).
148 cla_label_lang(py_cla(tagged(transcription(1)), tuning_stats:per_file, _),tuning_stats, py).
149 cla_label_lang(py_cla(keys_chords,chord_seq_key_relative:aggregate,_),key_relative_chord_seq,py).
150 cla_label_lang(py_cla(similarity_bundle,similarity:per_file,_), similarity, py).
151
152