GitHub時代に逆行
#! perl # cv.pl 評価データ 予測データ use strict; use warnings; # コマンドラインからファイルリストを取得 my @files = @ARGV; # 各要素を定義 my ($tp, $fp, $tn, $fn); $tp = $fp = $tn = $fn = 0; open(FILE, "<$files[0]") or die("file open error : $files[0]"); open(FILE2, "<$files[1]") or die("file open error : $files[1]"); while(my $a = readline(FILE)) { my $p = readline(FILE2); # 評価データから答えを取得 my ($a_class, @temp) = split(/\s+/, $a); # positive if(int($p) == 1) { # true-positive if(int($a_class) == 1) { $tp++; } # false-positive else { $fp++; } } # negative else { # false-negative if(int($a_class) == 1) { $fn++; } # true-negative else { $tn++; } } } close(FILE); close(FILE2); # Precision, Recall, F-measure の計算 my $p_precision = $tp / ($tp + $fp); my $p_recall = $tp / ($tp + $fn); my $p_fmeasure = 2 * $p_precision * $p_recall / ($p_precision + $p_recall); my $n_precision = $tn / ($tn + $fn); my $n_recall = $tn / ($tn + $fp); my $n_fmeasure = 2 * $n_precision * $n_recall / ($n_precision + $n_recall); # stdout 出力 printf "Accuracy = \t%.3f (%d / %d)\n\n", ($tp + $tn) / ($tp + $fp + $tn + $fn), ($tp + $tn), ($tp + $fp + $tn + $fn); printf "class +1:\n"; printf " Precision = \t%.3f (%d / %d)\n", $p_precision, $tp, ($tp + $fp); printf " Recall = \t%.3f (%d / %d)\n", $p_recall, $tp, ($tp + $fn); printf " F-measure = \t%.3f\n\n", $p_fmeasure; printf "class -1:\n"; printf " Precision = \t%.3f (%d / %d)\n", $n_precision, $tn, ($tn + $fn); printf " Recall = \t%.3f (%d / %d)\n", $n_recall, $tn, ($tn + $fp); printf " F-measure = \t%.3f\n\n", $n_fmeasure; # ここ汚い printf "Confusion Matrix\n"; printf "\tPredicted Class\n"; printf "\tp (+1)\t\tn (-1)\n"; printf "p (+1)\t%.3f (%d/%d)\t%.3f (%d/%d)\n", $tp / ($tp + $fn), $tp, ($tp + $fn), $fn / ($tp + $fn), $fn, ($tp + $fn); printf "n (-1)\t%.3f (%d/%d)\t%.3f (%d/%d)\n", $fp / ($fp + $tn), $fp, ($fp + $tn), $tn / ($fp + $tn), $tn, ($fp + $tn); printf "Labelled\nClass\n"; exit;
#! perl # 音声を重ねがけ保存 (16bit only) # mixman.pl inputfile mixsoundfile outputfile # inputfile : かける元のWAVファイル # mixsoundfile : 重ね合わせるWAVファイル # outputfile : 書き出されるWAVファイル use strict; use warnings; my ($input, $sound, $output) = @ARGV; open(IN, "<$input") or die("file open error : $input"); binmode IN; # binary mode open(DATA, "<$sound") or die("file open error : $input"); binmode DATA; $ binary mode my @effect; # 重ね合わせるWAVのRAWデータ配列 my $temp; # riffタグスキップ seek(DATA, 44, 0); while(read(DATA, $temp, 2)) { # 2byte (short) read my $data = unpack("s", $temp); # binary -> short に変換 push(@effect, $data); } open(SAVE, ">$output") or die("file write error"); binmode SAVE; # 元のファイルに加算していく my $in_cnt = 0; # 繰り返すのでリングバッファ用のカウンタ my $eff_cnt = $#effect; # riffタグをコピー for(my $i=0; $i<44; $i++) { read(IN, $temp, 1); print SAVE $temp; } while(read(IN, $temp, 2)) { # 2byte read my $data = unpack("s", $temp); # short -> binary print SAVE pack("s", ($data + $effect[$in_cnt % $eff_cnt])); $in_cnt++; } close(SAVE); close(DATA); close(IN);