Fixed $PRIOR support and bugfix in shrinkage results handling
[PsN.git] / bin / execute
blobbe811b3ccc29bda2c46db5e2653c3df6404ae5d3
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, 'execute');
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 my $models_array;
58 my $eval_string = common_options::model_parameters(\%options);
60 foreach my $model_name ( @ARGV ){
61 my $outputfile = shift @outputfiles;
62 my $model;
63 unless( $fake ){
64 $model = model -> new ( eval( $eval_string ),
65 outputfile => $outputfile,
66 filename => $model_name,
67 ignore_missing_output_files => 1 );
69 if( $options{'nonparametric_etas'} or
70 $options{'nonparametric_marginals'} ) {
71 $model -> add_nonparametric_code;
74 if( $options{'shrinkage'} ) {
75 $model -> shrinkage_stats( enabled => 1 );
77 } else {
78 unless( -e $outputfile ){
79 print "The output file: $outputfile doesn't exist.\n";
80 exit;
82 $model = model -> new( eval( $eval_string ),
83 outputfile => $outputfile,
84 filename => 'dummy.mod',
85 ignore_missing_files => 1 );
88 push( @{$models_array}, $model );
91 my $modelfit;
92 if ( defined $options{'predict_data'} and defined $options{'predict_model'} ) {
93 if( scalar @{$models_array} > 1 ) {
94 debug -> die( message => "When using predict_data and predict_model, no "
95 ."more than one model at a time may be run with execute" );
97 my $outfile = $options{'predict_model'};
98 $outfile =~ s/\.mod//;
99 $outfile = $outfile.'.lst';
100 my $pred_mod = $models_array -> [0] -> copy( filename => $options{'predict_model'},
101 copy_data => 0,
102 copy_output => 0 );
103 $pred_mod -> datafiles( new_names => [$options{'predict_data'}] );
104 $pred_mod -> ignore_missing_files(1);
105 $pred_mod -> outputfile( $outfile );
106 $pred_mod -> maxeval( new_values => [[0]] );
107 $pred_mod -> remove_records( type => 'covariance' );
108 $pred_mod -> update_inits( from_model => $models_array -> [0] );
109 my @new_tables;
110 foreach my $file ( @{$pred_mod -> table_names -> [0]} ) {
111 push( @new_tables, $options{'predict_model'}.'.'.$file );
113 $pred_mod -> table_names( new_names => [\@new_tables] );
114 $modelfit = tool::modelfit ->
115 new ( eval( $common_options::parameters ),
116 models => [$pred_mod] );
117 } else {
118 $modelfit = tool::modelfit ->
119 new ( eval( $common_options::parameters ),
120 models => $models_array );
123 open(CMD, ">", $modelfit -> directory . "/command.txt");
124 print CMD $cmd_line, "\n";
125 close(CMD);
127 $modelfit -> run;
129 if( $options{'summarize'} ){
130 $modelfit -> summarize;