This is a massive update that merges all changes from PsN_2_2_0_patches_serial. It...
[PsN.git] / bin / execute
blob6a37a274ffda8c6ebc177949ffaf25e13b85879c
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::online_help('execute', \%options, undef,{},{});
40 my @outputfiles;
41 my $fake;
42 if( $options{'outputfile'} ){
43 @outputfiles = split( /,/, $options{'outputfile'} );
46 if ( scalar( @ARGV ) < 1 ) {
47 unless( $options{'summarize'} and $options{'outputfile'} and not $options{'force'} ){
48 print "At least one model file must be specified. Use 'execute -h' for help.\n";
49 exit;
51 @ARGV = @outputfiles;
52 $fake = 1;
55 ui -> category( 'modelfit' );
57 random_set_seed_from_phrase( $options{'seed'} ) if ( defined $options{'seed'} );
59 debug -> level( $options{'debug'} );
60 debug -> package( $options{'debug_package'} );
61 debug -> subroutine( $options{'debug_subroutine'} );
62 debug -> warn_with_trace( $options{'warn_with_trace'} );
64 my $models_array;
66 my $eval_string = common_options::model_parameters(\%options);
68 foreach my $model_name ( @ARGV ){
69 my $outputfile = shift @outputfiles;
70 my $model;
71 unless( $fake ){
72 $model = model -> new ( eval( $eval_string ),
73 outputfile => $outputfile,
74 filename => $model_name,
75 ignore_missing_output_files => 1 );
77 if( $options{'nonparametric_etas'} or
78 $options{'nonparametric_marginals'} ) {
79 $model -> add_nonparametric_code;
82 if( $options{'shrinkage'} ) {
83 $model -> shrinkage_stats( enabled => 1 );
85 } else {
86 unless( -e $outputfile ){
87 print "The output file: $outputfile doesn't exist.\n";
88 exit;
90 $model = model -> new( eval( $eval_string ),
91 outputfile => $outputfile,
92 filename => 'dummy.mod',
93 ignore_missing_files => 1 );
96 push( @{$models_array}, $model );
99 my $modelfit;
100 if ( defined $options{'predict_data'} and defined $options{'predict_model'} ) {
101 if( scalar @{$models_array} > 1 ) {
102 debug -> die( message => "When using predict_data and predict_model, no "
103 ."more than one model at a time may be run with execute" );
105 my $outfile = $options{'predict_model'};
106 $outfile =~ s/\.mod//;
107 $outfile = $outfile.'.lst';
108 my $pred_mod = $models_array -> [0] -> copy( filename => $options{'predict_model'},
109 copy_data => 0,
110 copy_output => 0 );
111 $pred_mod -> datafiles( new_names => [$options{'predict_data'}] );
112 $pred_mod -> ignore_missing_files(1);
113 $pred_mod -> outputfile( $outfile );
114 $pred_mod -> maxeval( new_values => [[0]] );
115 $pred_mod -> remove_records( type => 'covariance' );
116 $pred_mod -> update_inits( from_model => $models_array -> [0] );
117 my @new_tables;
118 foreach my $file ( @{$pred_mod -> table_names -> [0]} ) {
119 push( @new_tables, $options{'predict_model'}.'.'.$file );
121 $pred_mod -> table_names( new_names => [\@new_tables] );
122 $modelfit = tool::modelfit ->
123 new ( eval( $common_options::parameters ),
124 models => [$pred_mod] );
125 } else {
126 $modelfit = tool::modelfit ->
127 new ( eval( $common_options::parameters ),
128 models => $models_array );
131 open(CMD, ">", $modelfit -> directory . "/command.txt");
132 print CMD $cmd_line, "\n";
133 close(CMD);
135 $modelfit -> run;
137 if( $options{'summarize'} ){
138 $modelfit -> summarize;