Fixed $PRIOR support and bugfix in shrinkage results handling
[PsN.git] / bin / sse
blobd2d14035430061872935957116028178e4074bda
1 #!/usr/bin/perl
3 use FindBin qw($Bin);
4 use lib "$Bin/../lib";
6 # Don't edit the line below, it must look exactly like this.
7 # Everything above this line will be replaced #
9 use PsN;
10 use model;
11 use tool::sse;
12 use strict;
13 use debug;
14 use Getopt::Long;
15 use common_options;
17 my $cmd_line = $0 . " " . join( " ", @ARGV );
19 ## Configure the command line parsing
20 Getopt::Long::config("auto_abbrev");
22 my %options;
23 ## Declare the options
25 my %required_options = ( 'samples:i' => '100');
26 my %optional_options = ( 'alternative_models:s' => 'alt1.mod,alt2.mod,...',
27 'ref_ofv:i' => '500',
28 'parallel_simulations:i' => '1',
29 'estimate_simulation!' => '1' );
30 #"bins:i" => '',
31 #"selection_method:s" => '\'random\'|\'consecutive\'' );
33 my $res = GetOptions( \%options,
34 @common_options::get_opt_strings,
35 keys(%required_options),
36 keys(%optional_options) );
37 exit unless $res;
39 common_options::set_globals( \%options, 'sse' );
40 common_options::get_defaults( \%options, 'sse' );
41 common_options::sanity_checks( \%options, 'sse' );
43 my %help_text;
45 $help_text{Pre_help_message} = <<'EOF';
46 sse
48 Perl script for Stochastic Simulation and Estimation of NONMEM models.
50 Usage:
51 EOF
53 $help_text{Options} = <<'EOF';
54 Options:
56 The options are given here in their long form. Any option may be
57 abbreviated to any nonconflicting prefix. The -threads option
58 may be abbreviated to -t(or even -thr) but -debug may not be
59 abbreviated to -d because it conflicts with -debug_packages and
60 -debug_subroutines.
62 The following options are valid:
63 EOF
65 $help_text{-h} = <<'EOF';
66 -h | -?
68 With -h or -? sse will print a list of options and exit.
69 EOF
71 $help_text{-help} = <<'EOF';
72 -help
74 With -help sse will print this, longer, help message.
75 EOF
77 $help_text{-alternative_models} = <<'EOF';
78 -alternative_models=alt1.mod,alt2.mod,...
80 List of one or more alternative models to use for estimation
81 with simulated datasets. The filenames must be comma-separated,
82 no spaces.
83 EOF
85 $help_text{-samples} = <<'EOF';
86 -samples=N
88 The number of simulated datasets to generate.
89 EOF
91 $help_text{-estimate_simulation} = <<'EOF';
92 -estimate_simulation
94 By default, the simulation model is also used for estimation with
95 the simulated datasets. The resulting OFV values are used as reference
96 when evaluating the estimation results of alternative models. By setting
97 -no-estimate_simulation the estimation of the simulation model is turned
98 off, and the first alternative model is used as reference instead. See
99 also -ref_ofv.
102 $help_text{-ref_ofv} = <<'EOF';
103 -ref_ofv=500
105 Instead of using the OFV values from the estimation of a model as
106 reference when evaluating the other estimation results,
107 it is possible to set a fixed reference OFV value. If using ref_ofv,
108 it is not allowed to also estimate the simulation model.
110 $help_text{-parallel_simulations} = <<'EOF';
111 -parallel_simulations=1
113 parallel_simulations govern the number of simulations that will
114 be done in parallel. Normally simulations are quite fast and
115 need only be run one at a time. See the threads option for
116 controll over the number of estimations to do in parallel.
119 $help_text{Post_help_message} = <<'EOF';
120 Also see 'execute -help' for a description of common options.
123 common_options::online_help( 'sse', \%options, \%help_text, \%required_options, \%optional_options);
125 ## Check that we do have a model file
126 if ( scalar(@ARGV) < 1 ) {
127 print "A simulation model file must be specified. Use 'sse -h' for help.\n";
128 exit;
131 if( scalar(@ARGV) > 1 ){
132 print "SSE can only handle one modelfile, you listed: ",join(',',@ARGV),". Use 'sse -h' for help.\n";die;
133 exit;
136 unless ( defined $options{'samples'} ){
137 print "samples must be given\n" ;
138 exit;
141 unless ( defined $options{'clean'} ){
142 # Clean is by default much stricter in sse
143 $options{'clean'} = 3;
146 my $eval_string = common_options::model_parameters(\%options);
148 my $model = model -> new ( eval( $eval_string ),
149 filename => $ARGV[0],
150 ignore_missing_output_files => 1 );
153 my @alternatives=();
155 if ( defined $options{'alternative_models'} ){
156 #split string, assume comma separated
157 foreach my $altfile (split(/,/,$options{'alternative_models'})){
158 if (length($altfile)>0){
159 my $alternative_model = model ->
160 new ( eval( $eval_string ),filename => $altfile,ignore_missing_output_files => 1 );
161 push(@alternatives,$alternative_model);
164 if (scalar(@alternatives)<1){
165 die "Error: Option alternative_models used, but list of filenames could not be parsed.\n";
167 }else{
168 print "No alternative model given, will only estimate simulation model.\n" ;
172 my $sse = tool::sse ->
173 new ( eval( $common_options::parameters ),
174 estimate_simulation => $options{'estimate_simulation'},
175 ref_ofv => $options{'ref_ofv'},
176 parallel_simulations => $options{'parallel_simulations'},
177 models => [ $model ],
178 top_tool => 1,
179 alternative_models => \@alternatives,
180 samples => $options{'samples'} );
181 open(CMD, ">", $sse -> directory . "/command.txt");
182 print CMD $cmd_line, "\n";
183 close(CMD);
185 $sse -> run;
186 $sse -> prepare_results;
187 $sse -> print_results;