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