Skip to content

Instantly share code, notes, and snippets.

@y-tag
Created March 23, 2013 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save y-tag/5229582 to your computer and use it in GitHub Desktop.
Save y-tag/5229582 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/perl
use strict;
use warnings;
use 5.008;
use Data::Dumper;
main();
sub main {
my $server_path = "/home/vagrant/git/jubatus/build/src/server/jubaclassifier";
my $conf_dir = "/home/vagrant/eval/conf";
my $client_path = "/home/vagrant/eval/bin/eval_svmdata2";
my @data_result_array = (
["/home/vagrant/eval/data/news20.scale", "/home/vagrant/eval/data/news20.t.scale", "/home/vagrant/eval/cv/news20", "/home/vagrant/eval/result/news20"],
["/home/vagrant/eval/data/usps", "/home/vagrant/eval/data/usps.t", "/home/vagrant/eval/cv/usps", "/home/vagrant/eval/result/usps"],
["/home/vagrant/eval/data/letter.scale", "/home/vagrant/eval/data/letter.scale.t", "/home/vagrant/eval/cv/letter", "/home/vagrant/eval/result/letter"],
["/home/vagrant/eval/data/ijcnn1", "/home/vagrant/eval/data/ijcnn1.t", "/home/vagrant/eval/cv/ijcnn1", "/home/vagrant/eval/result/ijcnn1"],
["/home/vagrant/eval/data/w7a", "/home/vagrant/eval/data/w7a.t", "/home/vagrant/eval/cv/w7a", "/home/vagrant/eval/result/w7a"],
);
foreach my $d_r (@data_result_array) {
my $train_f = $d_r->[0];
my $test_f = $d_r->[1];
my $cv_dir = $d_r->[2];
my $result_dir = $d_r->[3];
system("mkdir -p $result_dir") unless -d $result_dir;
my @conf_array = ();
push @conf_array, "perceptron.json";
push @conf_array, "pa.json";
push @conf_array, choose_best_conf($conf_dir, $cv_dir, "pa1");
push @conf_array, choose_best_conf($conf_dir, $cv_dir, "pa2");
push @conf_array, choose_best_conf($conf_dir, $cv_dir, "cw");
push @conf_array, choose_best_conf($conf_dir, $cv_dir, "arow");
push @conf_array, choose_best_conf($conf_dir, $cv_dir, "nherd");
push @conf_array, choose_best_conf($conf_dir, $cv_dir, "scw1");
push @conf_array, choose_best_conf($conf_dir, $cv_dir, "scw2");
print Dumper(\@conf_array);
foreach my $conf (@conf_array) {
my $pid = fork();
if ($pid < 0) {
die "fork fail!";
} elsif ($pid == 0) {
exec("$server_path -f $conf_dir/$conf");
} else {
sleep(2);
my $result_num = 0;
system("rm -f $result_dir/result_$conf");
my $cmd = "$client_path $train_f $test_f > $result_dir/result_$conf";
print "$cmd\n";
system($cmd);
kill(15, $pid);
}
}
}
}
sub choose_best_conf {
my ($conf_dir, $cv_dir, $name) = @_;
my $cmd = "perl choose_best_conf.pl $cv_dir/result_$name*.json";
my $best_result = `$cmd`;
my $best_conf = "";
if ($best_result =~ /(\d+)\.json/) {
$best_conf = $name . "_" . $1 . ".json";
}
$best_conf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment