sorted raw results since they now can arrive out of order
[PsN.git] / bin / execute
blob0f1e7700cbee430d34709364bdcb9050c0c89edb
1 #!/usr/local/bin/perl
3 # Only for Development
4 use FindBin qw($Bin);
5 use lib "$Bin/../lib";
7 # Don't edit the line below, it must look exactly like this.
8 # Everything above this line will be replaced #
10 # Perl includes #
11 use strict;
12 use Getopt::Long;
13 # External modules #
14 use Math::Random;
15 # PsN includes #
16 use PsN;
17 use tool::modelfit;
18 use model;
19 use debug;
20 use common_options;
21 use ui;
23 my $cmd_line = $0 . " " . join( " ", @ARGV );
25 my %options;
27 my %optional_options = ( "predict_data:s" => undef,
28 "predict_model:s" => undef );
30 my $res = GetOptions( \%options,
31 @common_options::get_opt_strings,
32 keys(%optional_options) );
34 exit unless $res;
36 common_options::set_globals( \%options );
37 common_options::get_defaults( \%options, 'execute' );
38 common_options::sanity_checks( \%options, 'execute' );
39 common_options::online_help('execute', \%options, undef,{},{});
41 my @outputfiles;
42 my $fake;
43 if( $options{'outputfile'} ){
44 @outputfiles = split( /,/, $options{'outputfile'} );
47 if ( scalar( @ARGV ) < 1 ) {
48 unless( $options{'summarize'} and $options{'outputfile'} and not $options{'force'} ){
49 print "At least one model file must be specified. Use 'execute -h' for help.\n";
50 exit;
52 @ARGV = @outputfiles;
53 $fake = 1;
56 ui -> category( 'modelfit' );
58 random_set_seed_from_phrase( $options{'seed'} ) if ( defined $options{'seed'} );
60 debug -> level( $options{'debug'} );
61 debug -> package( $options{'debug_package'} );
62 debug -> subroutine( $options{'debug_subroutine'} );
63 debug -> warn_with_trace( $options{'warn_with_trace'} );
65 my $models_array;
67 my $eval_string = common_options::model_parameters(\%options);
69 foreach my $model_name ( @ARGV ){
70 my $outputfile = shift @outputfiles;
71 my $model;
72 unless( $fake ){
73 $model = model -> new ( eval( $eval_string ),
74 outputfile => $outputfile,
75 filename => $model_name,
76 ignore_missing_output_files => 1 );
78 if( $options{'nonparametric_etas'} or
79 $options{'nonparametric_marginals'} ) {
80 $model -> add_nonparametric_code;
83 if( $options{'shrinkage'} ) {
84 $model -> shrinkage_stats( enabled => 1 );
86 } else {
87 unless( -e $outputfile ){
88 print "The output file: $outputfile doesn't exist.\n";
89 exit;
91 $model = model -> new( eval( $eval_string ),
92 outputfile => $outputfile,
93 filename => 'dummy.mod',
94 ignore_missing_files => 1 );
97 push( @{$models_array}, $model );
100 my $modelfit;
101 if ( defined $options{'predict_data'} and defined $options{'predict_model'} ) {
102 if( scalar @{$models_array} > 1 ) {
103 debug -> die( message => "When using predict_data and predict_model, no "
104 ."more than one model at a time may be run with execute" );
106 my $outfile = $options{'predict_model'};
107 $outfile =~ s/\.mod//;
108 $outfile = $outfile.'.lst';
109 my $pred_mod = $models_array -> [0] -> copy( filename => $options{'predict_model'},
110 copy_data => 0,
111 copy_output => 0 );
112 $pred_mod -> datafiles( new_names => [$options{'predict_data'}] );
113 $pred_mod -> ignore_missing_files(1);
114 $pred_mod -> outputfile( $outfile );
115 $pred_mod -> maxeval( new_values => [[0]] );
116 $pred_mod -> remove_records( type => 'covariance' );
117 $pred_mod -> update_inits( from_model => $models_array -> [0] );
118 my @new_tables;
119 foreach my $file ( @{$pred_mod -> table_names -> [0]} ) {
120 push( @new_tables, $options{'predict_model'}.'.'.$file );
122 $pred_mod -> table_names( new_names => [\@new_tables] );
123 $modelfit = tool::modelfit ->
124 new ( eval( $common_options::parameters ),
125 models => [$pred_mod] );
126 } else {
127 $modelfit = tool::modelfit ->
128 new ( eval( $common_options::parameters ),
129 models => $models_array );
132 open(CMD, ">", $modelfit -> directory . "/command.txt");
133 print CMD $cmd_line, "\n";
134 close(CMD);
136 $modelfit -> run;
138 if( $options{'summarize'} ){
139 $modelfit -> summarize;