1 # {{{ include statements
3 start include statements
9 use ext
::Math
::MatrixReal
;
11 if ( $PsN::config
-> {'_'} -> {'use_database'} ) {
15 end include statements
17 # }}} include statements
23 foreach my $attribute ( 'logfile', 'raw_results_file' ) {
24 if ( not( ref($this -> {$attribute}) eq 'ARRAY' or
25 ref($this -> {$attribute}) eq 'HASH' ) ) {
26 my $tmp = $this -> {$attribute};
27 if ( not defined $tmp and $attribute eq 'logfile' ) {
30 $this -> {$attribute} = [];
31 for ( my $i = 1; $i <= scalar @
{$this -> {'models'}}; $i++ ) {
33 if ( $name =~ /\./ ) {
40 OSspecific
::absolute_path
( $this -> {'directory'}, $name );
41 push ( @
{$this -> {$attribute}}, $ldir.$name ) ;
45 if ( $PsN::config
-> {'_'} -> {'use_database'} ) {
46 my( $found_log, $found_cdd_id ) = $this -> read_cdd_log
;
48 $this -> register_cdd_in_database
unless ( $found_cdd_id );
50 $this -> log_object
unless ( $found_log and $found_cdd_id );
51 print "Found ",$this -> {'cdd_id'},"\n";
58 # {{{ register_cdd_in_database
60 start register_cdd_in_database
62 if ( $PsN::config
-> {'_'} -> {'use_database'} ) {
63 my $dbh = DBI
-> connect("DBI:mysql:host=".$PsN::config
-> {'_'} -> {'database_server'}.
64 ";databse=".$PsN::config
-> {'_'} -> {'project'},
65 $PsN::config
-> {'_'} -> {'user'},
66 $PsN::config
-> {'_'} -> {'password'},
69 # bins and case_column can be defined for more than one model. Skip
70 # registration of these for now.
71 # $sth = $dbh -> prepare("INSERT INTO ".$PsN::config -> {'_'} -> {'project'}.
72 # ".cdd ( tool_id, bins, case_column ) ".
73 # "VALUES (".$self -> {'tool_id'}.", '".$self -> {'bins'}.
74 # "', '".$self -> {'case_column'}."' )");
75 $sth = $dbh -> prepare
("INSERT INTO ".$PsN::config
-> {'_'} -> {'project'}.
77 "VALUES (".$self -> {'tool_id'}." )");
79 $self -> {'cdd_id'} = $sth->{'mysql_insertid'};
84 end register_cdd_in_database
86 # }}} register_cdd_in_database
88 # {{{ register_mfit_results
90 start register_mfit_results
92 if ( $PsN::config
-> {'_'} -> {'use_database'} ) {
93 my $dbh = DBI
-> connect("DBI:mysql:host=".$PsN::config
-> {'_'} -> {'database_server'}.
94 ";databse=".$PsN::config
-> {'_'} -> {'project'},
95 $PsN::config
-> {'_'} -> {'user'},
96 $PsN::config
-> {'_'} -> {'password'},
98 $dbh -> do( "LOCK TABLES ".$PsN::config
-> {'_'} -> {'project'}.
99 ".cdd_modelfit_results WRITE" );
100 my $sth = $dbh -> prepare
( "SELECT MAX(cdd_modelfit_results_id)".
101 " FROM ".$PsN::config
-> {'_'} -> {'project'}.
102 ".cdd_modelfit_results" );
103 $sth -> execute
or debug
-> die( message
=> $sth->errstr ) ;
104 my $select_arr = $sth -> fetchall_arrayref
;
105 $first_res_id = defined $select_arr -> [0][0] ?
($select_arr -> [0][0] + 1) : 0;
106 $last_res_id = $first_res_id + $#cook_score;
110 for( my $i = 0; $i <= $#cook_score; $i++ ) {
111 $insert_values = $insert_values."," if ( defined $insert_values );
112 $insert_values = $insert_values.
113 "('".$self -> {'cdd_id'}."', '".$self -> {'model_ids'}[$model_number-1].
114 "', '".$self -> {'prepared_model_ids'}[($model_number-1)*($#cook_score+1)+$i].
116 "','$cook_score[$i]', '$covariance_ratio[$i]', '$projections[$i][0]', '$projections[$i][01]', '$outside_n_sd[$i]' )";
118 $dbh -> do("INSERT INTO ".$PsN::config
-> {'_'} -> {'project'}.
119 ".cdd_modelfit_results ".
120 "( cdd_id, orig_model_id, model_id, ".
121 "bin, cook_score, covariance_ratio, ".
122 "pca_component_1, pca_component_2, outside_n_sd ) ".
123 "VALUES $insert_values");
124 $dbh -> do( "UNLOCK TABLES" );
128 end register_mfit_results
130 # }}} register_mfit_results
135 if( -e
$self -> {'directory'}.'object.txt' ) {
137 open( OLOG
, '<'.$self -> {'directory'}.'object.txt' );
140 for ( my $i = 1; $i < $#olog; $i++ ) {
141 $str = $str.$olog[$i];
144 my %tmp = eval( $str );
146 if( exists $tmp{'cdd_id'} ) {
147 $self -> {'cdd_id'} = $tmp{'cdd_id'};
156 # {{{ llp_pre_fork_setup
158 start llp_pre_fork_setup
160 $self -> modelfit_pre_fork_setup
;
162 end llp_pre_fork_setup
164 # }}} llp_pre_fork_setup
166 # {{{ modelfit_pre_fork_setup
168 start modelfit_pre_fork_setup
170 # These attributes can be given as a
171 # 1. A scalar : used for all models and problems
172 # 2. A 1-dim. array : specified per problem but same for all models
173 # 3. A 2-dim. array : specified per problem and model
174 my $bins = $self -> {'bins'};
175 # my $idxs = $self -> {'grouping_indexes'};
176 my $case_columns = $self -> {'case_columns'};
178 if ( defined $bins ) {
179 unless ( ref( \
$bins ) eq 'SCALAR' or
180 ( ref( $bins ) eq 'ARRAY' and scalar @
{$bins} > 0 ) ) {
181 debug
-> die( message
=> "Attribute bins is ",
182 "defined as a ",ref( $bins ),
183 "and is neither a scalar or a non-zero size array." );
184 } elsif ( ref( \
$bins ) eq 'SCALAR' ) {
186 foreach my $model ( @
{$self -> {'models'}} ) {
188 foreach my $problem ( @
{$model -> problems
} ) {
189 push( @pr_bins, $bins );
191 push( @mo_bins, \
@pr_bins );
193 $self -> {'bins'} = \
@mo_bins;
194 } elsif ( ref( $bins ) eq 'ARRAY' ) {
195 unless ( ref( \
$bins -> [0] ) eq 'SCALAR' or
196 ( ref( $bins -> [0] ) eq 'ARRAY' and scalar @
{$bins -> [0]} > 0 ) ) {
197 debug
-> die( message
=> "Attribute bins is ",
198 "defined as a ",ref( $bins -> [0] ),
199 "and is neither a scalar or a non-zero size array." );
200 } elsif ( ref(\
$bins -> [0]) eq 'SCALAR' ) {
202 foreach my $model ( @
{$self -> {'models'}} ) {
203 push( @mo_bins, $bins );
205 $self -> {'bins'} = \
@mo_bins;
210 foreach my $model ( @
{$self -> {'models'}} ) {
212 foreach my $data ( @
{$model -> datas
} ) {
213 push( @pr_bins, $data -> count_ind
);
215 push( @mo_bins, \
@pr_bins );
217 $self -> {'bins'} = \
@mo_bins;
220 if ( defined $case_columns ) {
221 if ( defined $case_columns ) {
222 unless ( ref( \
$case_columns ) eq 'SCALAR' or
223 ( ref( $case_columns ) eq 'ARRAY' and scalar @
{$case_columns} > 0 ) ) {
224 debug
-> die( message
=> "Attribute case_columns is ",
225 "defined as a ",ref( $case_columns ),
226 "and is neither a scalar or a non-zero size array." );
227 } elsif ( ref( \
$case_columns ) eq 'SCALAR' ) {
229 my @mo_case_columns = ();
230 foreach my $model ( @
{$self -> {'models'}} ) {
231 my @pr_case_columns = ();
232 for( my $i = 1; $i <= scalar @
{$model -> problems
}; $i++ ) {
233 if ( not $case_columns =~ /^\d/ ) {
235 my ( $junk, $column_position ) = $model ->
236 _get_option_val_pos
( name
=> $case_columns,
237 record_name
=> 'input',
238 problem_numbers
=> [$i] );
239 # We assume that there is no duplicate column names
240 push ( @pr_case_columns, $column_position->[0][0] );
243 push ( @pr_case_columns, $case_columns );
246 push( @mo_case_columns, \
@pr_case_columns );
248 $self -> {'case_columns'} = \
@mo_case_columns;
249 } elsif ( ref( $case_columns ) eq 'ARRAY' ) {
251 unless ( ref( \
$case_columns -> [0] ) eq 'SCALAR' or
252 ( ref( $case_columns -> [0] ) eq 'ARRAY' and
253 scalar @
{$case_columns -> [0]} > 0 ) ) {
254 debug
-> die( message
=> "Second dimension of attribute case_columns is ",
255 "defined as a ",ref( $case_columns -> [0]),
256 "and is neither a scalar or a non-zero size array." );
257 } elsif ( ref(\
$case_columns -> [0]) eq 'SCALAR' ) {
259 my @mo_case_columns = ();
260 foreach my $model ( @
{$self -> {'models'}} ) {
261 my @pr_case_columns = ();
262 for( my $i = 1; $i <= scalar @
{$model -> problems
}; $i++ ) {
263 if ( not $case_columns =~ /^\d/ ) {
265 my ( $junk, $column_position ) = $model ->
266 _get_option_val_pos
( name
=> $case_columns->[$i-1],
267 record_name
=> 'input',
268 problem_numbers
=> [$i] );
269 # We assume that there is no duplicate column names
270 push ( @pr_case_columns, $column_position->[0][0] );
273 push ( @pr_case_columns, $case_columns -> [$i-1] );
276 push( @mo_case_columns, \
@pr_case_columns );
278 $self -> {'case_columns'} = \
@mo_case_columns;
279 } elsif ( ref($case_columns -> [0]) eq 'ARRAY' ) {
281 my @mo_case_columns = ();
282 for( my $j = 0; $j < scalar @
{$self -> {'models'}}; $j++ ) {
283 my @pr_case_columns = ();
284 for( my $i = 1; $i <= scalar @
{$self -> {'models'} -> problems
}; $i++ ) {
285 if ( not $case_columns =~ /^\d/ ) {
287 my ( $junk, $column_position ) = $self -> {'models'} -> [$j] ->
288 _get_option_val_pos
( name
=> $case_columns->[$j]->[$i-1],
289 record_name
=> 'input',
290 problem_numbers
=> [$i] );
291 # We assume that there is no duplicate column names
292 push ( @pr_case_columns, $column_position->[0][0] );
295 push ( @pr_case_columns, $case_columns -> [$j]->[$i-1] );
298 push( @mo_case_columns, \
@pr_case_columns );
300 $self -> {'case_columns'} = \
@mo_case_columns;
304 debug
-> die( message
=> "case_columns is not specified for model $model_number" );
308 end modelfit_pre_fork_setup
310 # }}} modelfit_pre_fork_setup
316 my $subm_threads = ref( $self -> {'threads'} ) eq 'ARRAY' ?
317 $self -> {'threads'} -> [1]:$self -> {'threads'};
318 $self -> general_setup
( model_number
=> $model_number,
319 class => 'tool::modelfit',
320 subm_threads
=> $subm_threads );
330 if (ref( $self -> {'threads'} ) eq 'ARRAY') {
331 @subm_threads = @
{$self -> {'threads'}};
332 unshift(@subm_threads);
334 @subm_threads = ($self -> {'threads'});
336 $self -> general_setup
( model_number
=> $model_number,
337 class => 'tool::llp',
338 subm_threads
=> \
@subm_threads );
347 # Sub tool threads can be given as scalar or reference to an array?
348 my $subm_threads = $parm{'subm_threads'};
349 my $own_threads = ref( $self -> {'threads'} ) eq 'ARRAY' ?
350 $self -> {'threads'} -> [0]:$self -> {'threads'};
351 # case_column names are matched in the model, not the data!
353 my $model = $self -> {'models'} -> [$model_number-1];
354 my @bins = @
{$self -> {'bins'} -> [$model_number-1]};
356 # Check which models that hasn't been run and run them
357 # This will be performed each step but will only result in running
358 # models at the first step, if at all.
360 # If more than one process is used, there is a VERY high risk of interaction
361 # between the processes when creating directories for model fits. Therefore
362 # the {'directory'} attribute is given explicitly below.
365 unless ( $model -> is_run
) {
367 # ----------------------- Run original run ------------------------------
372 if ( defined $self -> {'subtool_arguments'} ) {
373 %subargs = %{$self -> {'subtool_arguments'}};
375 if( $self -> {'nonparametric_etas'} or
376 $self -> {'nonparametric_marginals'} ) {
377 $model -> add_nonparametric_code
;
380 my $orig_fit = tool
::modelfit
->
381 new
( reference_object
=> $self,
383 threads
=> $subm_threads,
384 directory
=> $self -> {'directory'}.'/orig_modelfit_dir'.$model_number,
386 parent_threads
=> $own_threads,
387 parent_tool_id
=> $self -> {'tool_id'},
389 raw_results
=> undef,
390 prepared_models
=> undef,
393 # $Data::Dumper::Maxdepth=1;
394 # die Dumper $orig_fit;
395 # ( models => [$model],
397 # run_on_lsf => $self -> {'run_on_lsf'},
398 # no_remote_execution => $self -> {'no_remote_execution'},
399 # no_remote_compile => $self -> {'no_remote_compile'},
400 # lsf_queue => $self -> {'lsf_queue'},
401 # lsf_options => $self -> {'lsf_options'},
402 # lsf_job_name => $self -> {'lsf_job_name'},
403 # lsf_project_name => $self -> {'lsf_project_name'},
405 # run_on_nordugrid => $self -> {'run_on_nordugrid'},
406 # cpu_time => $self -> {'cpu_time'},
408 # parent_tool_id => $self -> {'tool_id'},
411 # nm_version => $self -> {'nm_version'},
412 # picky => $self -> {'picky'},
413 # compress => $self -> {'compress'},
414 # threads => $subm_threads,
415 # retries => $self -> {'retries'},
416 # remove_temp_files => $self -> {'remove_temp_files'},
417 # base_directory => $self -> {'directory'},
418 # directory => $self -> {'directory'}.'/orig_modelfit_dir'.$model_number,
419 # parent_threads => $own_threads );
421 ui
-> print( category
=> 'cdd',
422 message
=> 'Executing base model.' );
431 # ------------------------ Print a log-header -----------------------------
435 open( LOG
, ">>".$self -> {'logfile'}[$model_number-1] );
436 my $ui_text = sprintf("%-5s",'RUN').','.sprintf("%20s",'FILENAME ').',';
437 print LOG
sprintf("%-5s",'RUN'),',',sprintf("%20s",'FILENAME '),',';
438 foreach my $param ( 'ofv', 'theta', 'omega', 'sigma' ) {
439 my $accessor = $param eq 'ofv' ?
$param : $param.'s';
440 my $orig_ests = $model -> outputs
-> [0] -> $accessor;
442 if( defined $orig_ests ){
443 for ( my $j = 0; $j < scalar @
{$orig_ests}; $j++ ) {
444 if ( $param eq 'ofv' ) {
445 my $label = uc($param)."_".($j+1);
446 $ui_text = $ui_text.sprintf("%12s",$label).',';
447 print LOG
sprintf("%12s",$label),',';
449 # Loop the parameter numbers (skip sub problem level)
450 if( defined $orig_ests -> [$j] and
451 defined $orig_ests -> [$j][0] ){
452 for ( my $num = 1; $num <= scalar @
{$orig_ests -> [$j][0]}; $num++ ) {
453 my $label = uc($param).$num."_".($j+1);
454 $ui_text = $ui_text.sprintf("%12s",$label).',';
455 print LOG
sprintf("%12s",$label),',';
467 # ------------------------ Log original run -------------------------------
471 open( LOG
, ">>".$self -> {'logfile'}[$model_number-1] );
472 $ui_text = sprintf("%5s",'0').','.sprintf("%20s",$model -> filename
).',';
473 print LOG
sprintf("%5s",'0'),',',sprintf("%20s",$model -> filename
),',';
474 foreach my $param ( 'ofv', 'theta', 'omega', 'sigma' ) {
475 my $accessor = $param eq 'ofv' ?
$param : $param.'s';
476 my $orig_ests = $model -> outputs
-> [0] -> $accessor;
478 if( defined $orig_ests ) {
479 for ( my $j = 0; $j < scalar @
{$orig_ests}; $j++ ) {
480 if ( $param eq 'ofv' ) {
481 $ui_text = $ui_text.sprintf("%12f",$orig_ests -> [$j][0]).',';
482 print LOG
sprintf("%12f",$orig_ests -> [$j][0]),',';
484 # Loop the parameter numbers (skip sub problem level)
485 if( defined $orig_ests -> [$j] and
486 defined $orig_ests -> [$j][0] ){
487 for ( my $num = 0; $num < scalar @
{$orig_ests -> [$j][0]}; $num++ ) {
488 $ui_text = $ui_text.sprintf("%12f",$orig_ests -> [$j][0][$num]).',';
489 print LOG
sprintf("%12f",$orig_ests -> [$j][0][$num]),',';
501 # --------------------- Initiate some variables ----------------------------
505 my $case_column = $self -> {'case_columns'} -> [$model_number-1] -> [0];
507 # Case-deletion Diagnostics will only work for models with one problem.
508 my $orig_data = $model -> datas
-> [0];
510 if ( not defined $orig_data ) {
511 debug
-> die( message
=> "No data file to resample from found in ".$model -> full_name
);
514 my @problems = @
{$model -> problems
};
517 my ( @skipped_ids, @skipped_keys, @skipped_values );
519 my %orig_factors = %{$orig_data -> factors
( column
=> $case_column )};
520 my $maxbins = scalar keys %orig_factors;
521 my $pr_bins = ( defined $bins[0] and $bins[0] <= $maxbins ) ?
524 my $done = ( -e
$self -> {'directory'}."/m$model_number/done" ) ?
1 : 0;
526 my ( @seed, $new_datas, $skip_ids, $skip_keys, $skip_values, $remainders );
532 # -------------- Create new case-deleted data sets ----------------------
536 # Keep the new sample data objects i memory and write them to disk later
537 # with a proper name.
539 ( $new_datas, $skip_ids, $skip_keys, $skip_values, $remainders )
540 = $orig_data -> case_deletion
( case_column
=> $case_column,
541 selection
=> $self -> {'selection_method'},
544 my $ndatas = scalar @
{$new_datas};
545 open( DB
, ">".$self -> {'directory'}."m$model_number/done.database.models" );
547 for ( my $j = 1; $j <= $ndatas; $j++ ) {
548 my @names = ( 'cdd_'.$j, 'rem_'.$j );
549 my @datasets = ( $new_datas -> [$j-1], $remainders -> [$j-1] );
550 foreach my $i ( 0, 1 ) {
551 my $dataset = $datasets[$i];
552 my ($data_dir, $data_file) = OSspecific
::absolute_path
( $self -> {'directory'}.'/m'.$model_number,
554 $dataset -> directory
( $data_dir );
555 $dataset -> filename
( $data_file );
557 my $newmodel = $model -> copy
( filename
=> $data_dir.$names[$i].'.mod',
560 $newmodel -> ignore_missing_files
(1);
561 $newmodel -> datafiles
( new_names
=> [$names[$i].'.dta'] );
562 $newmodel -> outputfile
( $data_dir.$names[$i].".lst" );
563 $newmodel -> datas
-> [0] = $dataset;
565 # set MAXEVAL=0. Again, CDD will only work for one $PROBLEM
566 $newmodel -> maxeval
( new_values
=> [[0]] );
569 if( $self -> {'nonparametric_etas'} or
570 $self -> {'nonparametric_marginals'} ) {
571 $newmodel -> add_nonparametric_code
;
575 push( @
{$new_models[$i]}, $newmodel );
576 $model_ids[$j*$i+$j-1] = $newmodel -> register_in_database
( force
=> 1 ) ;
577 print DB
$model_ids[$j*$i+$j-1],"\n";
578 $self -> {'prepared_model_ids'}[($model_number-1)*$ndatas*2+$j*$i+$j-1] =
579 $model_ids[$j*$i+$j-1];
583 # my $new_data = $new_datas -> [$j-1];
584 # my ($data_dir, $data_file) = OSspecific::absolute_path( $self -> {'directory'}.'/m'.$model_number,
585 # 'cdd_'.$j.'.dta' );
586 # $new_data -> directory( $data_dir );
587 # $new_data -> filename( $data_file );
588 # $new_data -> flush;
589 # my $newmodel = $model -> copy( filename => $data_dir."cdd_$j.mod",
592 # $newmodel -> ignore_missing_files(1);
593 # $newmodel -> datafiles( new_names => ["cdd_$j.dta"] );
594 # $newmodel -> outputfile( $data_dir."cdd_$j.lst" );
595 # $newmodel -> datas -> [0] = $new_data;
596 # $newmodel -> _write;
597 # push( @new_models, $newmodel );
598 # $model_ids[$j-1] = $newmodel -> register_in_database( force => 1 );
599 # print DB $model_ids[$j-1],"\n";
600 # $self -> {'prepared_model_ids'}[($model_number-1)*$ndatas+$j-1] =
604 if ( not -e
$self -> {'directory'}."m$model_number/done.database.tool_models" ) {
605 $self -> register_tm_relation
( model_ids
=> \
@model_ids,
606 prepared_models
=> 1 );
607 open( DB
, ">".$self -> {'directory'}."m$model_number/done.database.tool_models" );
611 # Create a checkpoint. Log the samples and individuals.
612 open( DONE
, ">".$self -> {'directory'}."/m$model_number/done" ) ;
613 print DONE
"Sampling from ",$orig_data -> filename
, " performed\n";
614 print DONE
"$pr_bins bins\n";
615 print DONE
"Skipped individuals:\n";
616 for( my $k = 0; $k < scalar @
{$skip_ids}; $k++ ) {
617 print DONE
join(',',@
{$skip_ids -> [$k]}),"\n";
619 print DONE
"Skipped keys:\n";
620 for( my $k = 0; $k < scalar @
{$skip_keys}; $k++ ) {
621 print DONE
join(',',@
{$skip_keys -> [$k]}),"\n";
623 print DONE
"Skipped values:\n";
624 for( my $k = 0; $k < scalar @
{$skip_values}; $k++ ) {
625 print DONE
join(',',@
{$skip_values -> [$k]}),"\n";
627 @seed = random_get_seed
;
628 print DONE
"seed: @seed\n";
631 open( SKIP
, ">".$self -> {'directory'}."skipped_individuals".$model_number.".csv" ) ;
632 for( my $k = 0; $k < scalar @
{$skip_ids}; $k++ ) {
633 print SKIP
join(',',@
{$skip_ids -> [$k]}),"\n";
636 open( SKIP
, ">".$self -> {'directory'}."skipped_keys".$model_number.".csv" ) ;
637 for( my $k = 0; $k < scalar @
{$skip_keys}; $k++ ) {
638 print SKIP
join(',',@
{$skip_keys -> [$k]}),"\n";
646 # --------- Recreate the datasets and models from a checkpoint ----------
650 ui
-> print( category
=> 'cdd',
651 message
=> "Recreating models from a previous run" );
652 open( DONE
, $self -> {'directory'}."/m$model_number/done" );
655 my ( $junk, $junk, $stored_filename, $junk ) = split(' ',$rows[0],4);
656 my ( $stored_bins, $junk ) = split(' ',$rows[1],2);
657 my ( @stored_ids, @stored_keys, @stored_values );
658 for ( my $k = 3; $k < 3+$stored_bins; $k++ ) {
660 my @bin_ids = split(',', $rows[$k] );
661 push( @stored_ids, \
@bin_ids );
663 for ( my $k = 4+$stored_bins; $k < 4+2*$stored_bins; $k++ ) {
665 my @bin_keys = split(',', $rows[$k] );
666 push( @stored_keys, \
@bin_keys );
668 for ( my $k = 5+2*$stored_bins; $k < 5+3*$stored_bins; $k++ ) {
670 my @bin_values = split(',', $rows[$k] );
671 push( @stored_values, \
@bin_values );
673 @seed = split(' ',$rows[5+3*$stored_bins]);
674 $skip_ids = \
@stored_ids;
675 $skip_keys = \
@stored_keys;
676 $skip_values = \
@stored_values;
677 shift( @seed ); # get rid of 'seed'-word
679 # Reinitiate the model objects
681 my $reg_relations = 0;
682 if ( -e
$self -> {'directory'}."m$model_number/done.database.models" ) {
683 open( DB
, $self -> {'directory'}."m$model_number/done.database.models" );
687 open( DB
, ">".$self -> {'directory'}."m$model_number/done.database.models" );
690 for ( my $j = 1; $j <= $stored_bins; $j++ ) {
691 my @names = ( 'cdd_'.$j, 'rem_'.$j );
692 foreach my $i ( 0, 1 ) {
693 my ($model_dir, $filename) = OSspecific
::absolute_path
( $self -> {'directory'}.'/m'.
696 my ($out_dir, $outfilename) = OSspecific
::absolute_path
( $self -> {'directory'}.'/m'.
699 my $new_mod = model
->
700 new
( directory
=> $model_dir,
701 filename
=> $filename,
702 outputfile
=> $outfilename,
703 extra_files
=> $model -> extra_files
,
705 ignore_missing_files
=> 1,
707 model_id
=> $model_ids[$j*$i+$j-1] );
708 push( @
{$new_models[$i]}, $new_mod );
710 if( not defined $model_ids[$j*$i+$j-1] ) {
711 $model_ids[$j*$i+$j-1] = $new_mod -> register_in_database
;
712 print DB
$model_ids[$j-1],"\n";
714 $self -> {'prepared_model_ids'}[($model_number-1)*
715 $stored_bins+$j*$i+$j-1] =
716 $model_ids[$j*$i+$j-1];
719 # my ($model_dir, $filename) = OSspecific::absolute_path( $self -> {'directory'}.'/m'.
721 # 'cdd_'.$j.'.mod' );
722 # my ($out_dir, $outfilename) = OSspecific::absolute_path( $self -> {'directory'}.'/m'.
724 # '/cdd_'.$j.'.lst' );
725 # my $new_mod = model ->
726 # new( directory => $model_dir,
727 # filename => $filename,
728 # outputfile => $outfilename,
729 # extra_files => $model -> extra_files,
731 # ignore_missing_files => 1,
733 # model_id => $model_ids[$j-1] );
734 # push( @new_models, $new_mod );
736 # if( not defined $model_ids[$j-1] ) {
737 # $model_ids[$j-1] = $new_mod -> register_in_database;
738 # print DB $model_ids[$j-1],"\n";
740 # $self -> {'prepared_model_ids'}[($model_number-1)*$stored_bins+$j-1] =
742 my $nl = $j == $stored_bins ?
"" : "\r";
743 ui
-> print( category
=> 'cdd',
744 message
=> ui
-> status_bar
( sofar
=> $j+1,
745 goal
=> $stored_bins+1 ).$nl,
750 if ( not -e
$self -> {'directory'}."m$model_number/done.database.tool_models" ) {
751 $self -> register_tm_relation
( model_ids
=> \
@model_ids,
752 prepared_models
=> 1 ) if ( $reg_relations );
753 open( DB
, ">".$self -> {'directory'}."m$model_number/done.database.tool_models" );
757 ui
-> print( category
=> 'cdd',
758 message
=> " ... done." );
759 random_set_seed
( @seed );
760 ui
-> print( category
=> 'cdd',
761 message
=> "Using $stored_bins previously sampled case-deletion sets ".
762 "from $stored_filename" )
763 unless $self -> {'parent_threads'} > 1;
768 push( @skipped_ids, $skip_ids );
769 push( @skipped_keys, $skip_keys );
770 push( @skipped_values, $skip_values );
772 # Use only the first half (the case-deleted) of the data sets.
773 $self -> {'prepared_models'}[$model_number-1]{'own'} = $new_models[0];
775 # The remainders are left until the analyze step
776 $self -> {'prediction_models'}[$model_number-1]{'own'} = $new_models[1];
778 # --------------------- Create the sub tools ------------------------------
783 $subdir =~ s/tool:://;
784 my @subtools = @
{$self -> {'subtools'}};
787 if ( defined $self -> {'subtool_arguments'} ) {
788 %subargs = %{$self -> {'subtool_arguments'}};
790 push( @
{$self -> {'tools'}},
792 new
( reference_object
=> $self,
793 models
=> $new_models[0],
794 threads
=> $subm_threads,
795 directory
=> $self -> {'directory'}.'/'.$subdir.'_dir'.$model_number,
796 _raw_results_callback
=> $self ->
797 _modelfit_raw_results_callback
( model_number
=> $model_number ),
798 subtools
=> \
@subtools,
799 parent_threads
=> $own_threads,
800 parent_tool_id
=> $self -> {'tool_id'},
802 raw_results
=> undef,
803 prepared_models
=> undef,
807 # ( models => $new_models[0],
808 # nm_version => $self -> {'nm_version'},
809 # run_on_lsf => $self -> {'run_on_lsf'},
810 # no_remote_execution => $self -> {'no_remote_execution'},
811 # no_remote_compile => $self -> {'no_remote_compile'},
812 # lsf_queue => $self -> {'lsf_queue'},
813 # lsf_options => $self -> {'lsf_options'},
814 # lsf_job_name => $self -> {'lsf_job_name'},
815 # lsf_project_name => $self -> {'lsf_project_name'},
817 # run_on_nordugrid => $self -> {'run_on_nordugrid'},
818 # cpu_time => $self -> {'cpu_time'},
820 # parent_tool_id => $self -> {'tool_id'},
822 # picky => $self -> {'picky'},
823 # compress => $self -> {'compress'},
824 # threads => $subm_threads,
825 # retries => $self -> {'retries'},
826 # remove_temp_files => $self -> {'remove_temp_files'},
827 # base_directory => $self -> {'directory'},
828 # directory => $self -> {'directory'}.'/'.$subdir.'_dir'.$model_number,
829 # _raw_results_callback => $self ->
830 # _modelfit_raw_results_callback( model_number => $model_number ),
831 # subtools => \@subtools,
832 # parent_threads => $own_threads,
837 open( SKIP
, ">".$self -> {'directory'}."skipped_values".$model_number.".csv" ) ;
838 for( my $k = 0; $k < scalar @
{$skip_values}; $k++ ) {
839 print SKIP
join(',',@
{$skip_values -> [$k]}),"\n";
854 # $proc_results{'skipped.section.identifiers'} = $self -> {'skipped.section.identifiers'};
855 # $proc_results{'skipped_ids'} = $self -> {'skipped_ids'};
856 # $proc_results{'skipped_keys'} = $self -> {'skipped_keys'};
857 # $proc_results{'skipped_values'} = $self -> {'skipped_values'};
859 push( @
{$self -> {'results'} -> {'own'}}, \
%proc_results );
865 # {{{ _modelfit_raw_results_callback
867 start _modelfit_raw_results_callback
870 # Use the cdd's raw_results file.
871 # The cdd and the bootstrap's callback methods are identical
872 # in the beginning, then the cdd callback adds cook.scores and
876 OSspecific
::absolute_path
( $self -> {'directory'},
877 $self -> {'raw_results_file'}[$model_number-1] );
878 my $orig_mod = $self -> {'models'}[$model_number-1];
879 my $xv = $self -> {'cross_validate'};
881 my $modelfit = shift;
883 my %max_hash = %{$mh_ref};
884 $modelfit -> raw_results_file
( $dir.$file );
885 if( $cross_validation_set ) {
886 $modelfit -> raw_results_append
( 1 ) if( not $self -> {'bca_mode'} ); # overwrite when doing a jackknife
887 my ( @new_header, %param_names );
888 foreach my $row ( @
{$modelfit -> {'raw_results'}} ) {
889 unshift( @
{$row}, 'cross_validation' );
891 $modelfit -> {'raw_results_header'} = undef; # May be a bit silly to do...
893 # my @orig_res = ( 0, 1, 1 ); # Model zero: original run. Problem 1 and subproblem 1
894 # foreach my $param ( @{$modelfit -> raw_results_header} ){
895 # next if( $param eq 'model' or $param eq 'problem' or $param eq 'subproblem' );
896 # my ( $accessor, $res );
897 # if ( $param eq 'theta' or $param eq 'omega' or $param eq 'sigma' or
898 # $param eq 'setheta' or $param eq 'seomega' or $param eq 'sesigma' or
899 # $param eq 'npomega' ) {
901 # $accessor = $param.'s';
902 # $res = $orig_mod -> {'outputs'} -> [0] -> $accessor;
904 # } elsif ( $param eq 'shrinkage_etas' ) {
906 # # Shrinkage does not work for subproblems right now.
907 # $res = $orig_mod -> eta_shrinkage;
909 # } elsif ( $param eq 'shrinkage_wres' ) {
911 # $res = $orig_mod -> wres_shrinkage;
915 # $res = $orig_mod -> {'outputs'} -> [0] -> $param;
921 # $res = defined $res ? $res -> [0][0] : undef;
922 # if( defined $res ) {
923 # if ( ref $res eq 'ARRAY' ) {
924 # push( @orig_res, @{$res} );
925 # push( @orig_res, (undef) x ($max_hash{$param}- scalar @{$res}) );
927 # push( @orig_res, $res );
930 # push( @orig_res, (undef) x $max_hash{$param} );
937 my ($raw_results_row,$row_structure) = $self -> create_raw_results_rows
( max_hash
=> $mh_ref,
938 model
=> $orig_mod );
940 unshift( @
{$modelfit -> {'raw_results'}}, @
{$raw_results_row} );
942 &{$self -> {'_raw_results_callback'}}( $self, $modelfit )
943 if ( defined $self -> {'_raw_results_callback'} );
945 my ( @new_header, %param_names );
946 my @params = ( 'theta', 'omega', 'sigma' );
947 foreach my $param ( @params ) {
948 my $labels = $orig_mod -> labels
( parameter_type
=> $param );
949 $param_names{$param} = $labels -> [0] if ( defined $labels );
952 foreach my $name ( @
{$modelfit -> {'raw_results_header'}} ) {
954 foreach my $param ( @params ) {
955 if ( $name eq $param ){
956 if( defined $param_names{$name} ) {
957 push( @new_header , @
{$param_names{$name}} );
959 for ( my $i = 1; $i <= $max_hash{ $name }; $i++ ) {
960 push ( @new_header, uc(substr($name,0,2)).$i );
965 } elsif ( $name eq 'se'.$param ) {
967 for ( my $i = 1; $i <= $max_hash{ $name }; $i++ ) {
968 push ( @new_names, uc(substr($param,0,2)).$i );
970 map ( $_ = 'se'.$_, @new_names );
972 push( @new_header, @new_names );
978 push( @new_header, $name );
982 $modelfit -> {'raw_results_header'} = \
@new_header;
984 if( $xv and not $self -> {'bca_mode'} ) {
985 foreach my $row ( @
{$modelfit -> {'raw_results'}} ) {
986 unshift( @
{$row}, 'cdd' );
988 unshift( @
{$modelfit -> {'raw_results_header'}}, 'method' );
994 end _modelfit_raw_results_callback
996 # }}} _modelfit_raw_results_callback
998 # {{{ modelfit_analyze
1000 start modelfit_analyze
1002 # Only valid for one problem and one sub problem.
1004 if ( $self -> {'cross_validate'} ) {
1006 # --- Evaluate the models on the remainder data sets ----
1011 $i < scalar @
{$self -> {'prediction_models'}[$model_number-1]{'own'}};
1013 $self -> {'prediction_models'}[$model_number-1]{'own'}[$i] ->
1014 update_inits
( from_model
=> $self ->
1015 {'prepared_models'}[$model_number-1]{'own'}[$i]);
1016 $self -> {'prediction_models'}[$model_number-1]{'own'}[$i] ->
1017 remove_records
( type
=> 'covariance' );
1018 $self -> {'prediction_models'}[$model_number-1]{'own'}[$i] -> _write
;
1021 OSspecific
::absolute_path
( $self -> {'directory'},
1022 $self -> {'raw_results_file'}[$model_number-1] );
1023 my $mod_eval = tool
::modelfit
->
1024 new
( reference_object
=> $self,
1026 {'prediction_models'}[$model_number-1]{'own'},
1027 base_directory
=> $self -> {'directory'},
1028 directory
=> $self -> {'directory'}.
1029 'evaluation_dir'.$model_number,
1030 _raw_results_callback
=> $self ->
1031 _modelfit_raw_results_callback
( model_number
=> $model_number,
1032 cross_validation_set
=> 1 ),
1033 parent_tool_id
=> $self -> {'tool_id'},
1035 raw_results
=> undef,
1036 prepared_models
=> undef,
1038 $Data::Dumper
::Maxdepth
= 2;
1039 # die Dumper $mod_eval;
1040 print "Running xv runs\n";
1047 # ---------------------- Cook-score -----------------------
1051 my ( @cook_score, @cov_ratio );
1052 if( $self -> models
-> [$model_number-1] ->
1053 outputs
-> [0] -> covariance_step_successful
-> [0][0]) {
1055 ui
-> print( category
=> 'cdd',
1056 message
=> "Calculating the cook-scores" );
1062 my $output_harvest = $self -> harvest_output
( accessors
=> ['thetas','raw_omegas','raw_sigmas'],
1063 search_output
=> 1 );
1065 foreach my $param ( 'thetas', 'raw_omegas', 'raw_sigmas' ) {
1066 my $orig_est = $self -> models
-> [$model_number-1] -> outputs
-> [0] -> $param;
1068 my $est = defined $output_harvest -> {$param} ?
1069 $output_harvest -> {$param} -> [$model_number-1]{'own'} : [];
1070 if( defined $est ) {
1071 for ( my $i = 0; $i < scalar @
{$est}; $i++ ) {
1072 my $n_par = defined $est->[$i][0][0] ?
1073 scalar @
{$est->[$i][0][0]} : 0;
1074 if( defined $est->[$i][0][0] ) {
1075 push( @
{$cdd_ests[$i]}, @
{$est->[$i][0][0]} );
1076 for ( my $j = 0; $j < $n_par; $j++ ) {
1077 push( @
{$changes[$i]}, $orig_est->[0][0][$j]-$est->[$i][0][0][$j]);
1080 push( @
{$cdd_ests[$i]}, (undef) x
$n_par );
1081 for ( my $j = 0; $j < $n_par; $j++ ) {
1082 push( @
{$changes[$i]}, (undef) x
$n_par);
1088 my $inv_cov_linear = $self -> models
-> [$model_number-1] ->
1089 outputs
-> [0] -> raw_invcovmatrix
-> [0][0];
1091 # Equation: sqrt((orig_est-est(i))'*inv_cov_matrix*(orig_est-est(i)))
1092 for ( my $i = 0; $i <= $#changes; $i++ ) {
1093 # Rightmost multiplication:
1097 foreach my $element ( @
{$inv_cov_linear} ) {
1098 $element = 0 if ( $element eq '.........' );
1101 $prod[$n-1] = $prod[$n-1] + $element * $changes[$i][$n-1];
1104 $prod[$n-1] = $prod[$n-1] + $element * $changes[$i][$m-1];
1106 $prod[$m-1] = $prod[$m-1] + $element * $changes[$i][$n-1];
1115 # Leftmost multiplication:
1116 for( my $j = 0; $j <= $#prod; $j++ ) {
1117 $cook_score[$i] = $cook_score[$i] + $changes[$i][$j] * $prod[$j];
1119 my $nl = $i == $#changes ?
"" : "\r";
1120 ui
-> print( category
=> 'cdd',
1121 message
=> ui
-> status_bar
( sofar
=> $i+1,
1122 goal
=> $#changes+1 ).$nl,
1126 # Calculate the square root
1127 for ( my $i = 0; $i <= $#cook_score; $i++ ) {
1128 if( $cook_score[$i] >= 0 ) {
1129 $cook_score[$i] = sqrt($cook_score[$i]);
1131 open( LOG
, ">>".$self -> {'logfile'}[$model_number-1] );
1132 print LOG
"Negative squared cook-score ",$cook_score[$i],
1133 "; can't take the square root.\n",
1134 "The cook-score for model $model_number and cdd bin $i was set to zero\n";
1135 # "The cook-score for model $model_number and cdd bin $i was set to undef\n";
1137 $cook_score[$i] = 0;
1138 # $cook_score[$i] = undef;
1143 $self -> {'cook_scores'} = \
@cook_score;
1145 ui
-> print( category
=> 'cdd',
1146 message
=> " ... done." );
1150 # ------------------- Covariance Ratio --------------------
1152 # {{{ Covariance Ratio
1154 # {{{ sub clear dots
1158 my @matrix = @
{$m_ref};
1159 # get rid of '........'
1161 foreach ( @matrix ) {
1162 push( @clear, $_ ) unless ( $_ eq '.........' );
1164 # print Dumper \@clear;
1170 # {{{ sub make square
1174 my @matrix = @
{$m_ref};
1175 # Make the matrix square:
1176 my $elements = scalar @matrix; # = M*(M+1)/2
1177 my $M = -0.5 + sqrt( 0.25 + 2 * $elements );
1179 for ( my $m = 1; $m <= $M; $m++ ) {
1180 for ( my $n = 1; $n <= $m; $n++ ) {
1181 push( @
{$square[$m-1]}, $matrix[($m-1)*$m/2 + $n - 1] );
1182 unless ( $m == $n ) {
1183 push( @
{$square[$n-1]}, $matrix[($m-1)*$m/2 + $n - 1] );
1192 ui
-> print( category
=> 'cdd',
1193 message
=> "Calculating the covariance-ratios" );
1195 # Equation: sqrt(det(cov_matrix(i))/det(cov_matrix(orig)))
1196 my $cov_linear = $self -> models
-> [$model_number-1] ->
1197 outputs
-> [0] -> raw_covmatrix
-> [0][0];
1199 if( defined $cov_linear ) {
1200 my $orig_cov = Math
::MatrixReal
->
1201 new_from_cols
( make_square
( clear_dots
( $cov_linear ) ) );
1202 $orig_det = $orig_cov -> det
();
1204 # AUTOLOAD: raw_covmatrix
1206 my $output_harvest = $self -> harvest_output
( accessors
=> ['raw_covmatrix'],
1207 search_output
=> 1 );
1209 my $est_cov = defined $output_harvest -> {'raw_covmatrix'} ?
$output_harvest -> {'raw_covmatrix'} -> [$model_number-1]{'own'} : [];
1211 my $mods = scalar @
{$est_cov};
1212 for ( my $i = 0; $i < scalar @
{$est_cov}; $i++ ) {
1213 if ( $orig_det != 0 and defined $est_cov->[$i][0][0] ) {
1214 my $cov = Math
::MatrixReal
->
1215 new_from_cols
( make_square
( clear_dots
( $est_cov->[$i][0][0] ) ) );
1216 my $ratio = $cov -> det
() / $orig_det;
1218 push( @cov_ratio, sqrt( $ratio ) );
1220 open( LOG
, ">>".$self -> {'logfile'}[$model_number-1] );
1221 print LOG
"Negative covariance ratio ",$ratio,
1222 "; can't take the square root.\n",
1223 "The covariance ratio for model $model_number and cdd bin $i was set to one (1)\n";
1224 # "The covariance ratio for model $model_number and cdd bin $i was set to undef\n";
1226 push( @cov_ratio, 1 );
1227 # push( @cov_ratio, undef );
1230 open( LOG
, ">>".$self -> {'logfile'}[$model_number-1] );
1231 print LOG
"The determinant of the cov-matrix of the original run was zero\n",
1232 "or the determinant of cdd bin $i was undefined\n",
1233 "The covariance ratio for model $model_number and cdd bin $i was set to one (1)\n";
1234 # "The covariance ratio for model $model_number and cdd bin $i was set to undef\n";
1236 push( @cov_ratio, 1 );
1237 # push( @cov_ratio, undef );
1240 my $nl = $i == $mods-1 ?
"" : "\r";
1241 ui
-> print( category
=> 'cdd',
1242 message
=> ui
-> status_bar
( sofar
=> $i+1,
1243 goal
=> $mods ).$nl,
1248 $self -> {'covariance_ratios'} = \
@cov_ratio;
1250 ui
-> print( category
=> 'cdd',
1251 message
=> " ... done." );
1253 # }}} Covariance Ratio
1255 # - Perform a PCA on the cook-score:covariance-ratio data --
1257 my ( $eig_ref, $eig_vec_ref, $proj_ref, $std_ref ) =
1258 $self -> pca
( data_matrix
=> [\
@cook_score,\
@cov_ratio] );
1259 my @projections = @
{$proj_ref};
1260 my @standard_deviation = @
{$std_ref};
1262 # ---- Mark the runs with CS-CR outside N standard deviations of the PCA ----
1267 for( my $i = 0; $i <= $#projections; $i++ ) {
1268 my $vector_length = 0;
1269 for( my $j = 0; $j <= 1; $j++ ) {
1270 $vector_length += $projections[$i][$j]**2;
1272 $vector_length = sqrt( $vector_length );
1274 for( my $j = 0; $j <= 1; $j++ ) {
1275 $n_sd += (($projections[$i][$j]/$vector_length)*$standard_deviation[$j])**2;
1277 $n_sd = ( $self -> {'outside_n_sd_check'} * sqrt( $n_sd ) );
1278 $outside_n_sd[$i] = $vector_length > $n_sd ?
1 : 0;
1281 $self -> {'outside_n_sd'} = \
@outside_n_sd;
1285 my %covariance_return_section;
1286 $covariance_return_section{'name'} = 'Diagnostics';
1287 $covariance_return_section{'labels'} = [[],['cook.scores','covariance.ratios','outside.n.sd']];
1290 for( my $i = 0; $i <= $#cov_ratio; $i ++ ){
1291 push( @res_array , [$cook_score[$i],$cov_ratio[$i],$outside_n_sd[$i]] );
1294 $covariance_return_section{'values'} = \
@res_array;
1296 push( @
{$self -> {'results'}[$model_number-1]{'own'}},\
%covariance_return_section );
1298 # --------------- Relative estimate change ----------------
1300 # {{{ Relative change of the parameter estimates
1302 my $output_harvest = $self -> harvest_output
( accessors
=> ['ofv', 'thetas', 'omegas', 'sigmas','sethetas', 'seomegas', 'sesigmas'],
1303 search_output
=> 1 );
1307 $return_section{'name'} = 'relative.changes';
1308 $return_section{'labels'} = [[],[]];
1312 for ( my $i = 0; $i < scalar @
{$output_harvest -> {'ofv'} -> [$model_number-1]{'own'}}; $i++ ) {
1314 foreach my $param ( 'ofv', 'thetas', 'omegas', 'sigmas',
1315 'sethetas', 'seomegas', 'sesigmas',) {
1317 my $orig_est = $self -> {'models'} -> [$model_number-1] -> outputs
-> [0] -> $param;
1318 my $est = defined $output_harvest -> {$param} ?
$output_harvest -> {$param} -> [$model_number-1]{'own'} : [];
1320 if ( $param eq 'ofv' ) {
1321 if ( defined $orig_est->[0][0] and $orig_est->[0][0] != 0 ) {
1322 push( @values, ($orig_est->[0][0]-$est->[$i][0][0])/$orig_est->[0][0] );
1324 push( @values, 'INF' );
1327 push( @
{$return_section{'labels'} -> [1]}, $param );
1331 if( defined $est->[$i][0][0] ){
1332 for ( my $j = 0; $j < scalar @
{$est->[$i][0][0]}; $j++ ) {
1333 if ( defined $orig_est->[0][0][$j] and $orig_est->[0][0][$j] != 0 ) {
1334 push( @values, ($orig_est->[0][0][$j]-$est->[$i][0][0][$j])/$orig_est->[0][0][$j]*100);
1336 push( @values, 'INF' );
1339 push( @
{$return_section{'labels'} -> [1]}, $param . '_' . $j );
1346 push( @rel_ests, \
@values );
1349 $return_section{'values'} = \
@rel_ests ;
1350 push( @
{$self -> {'results'}[$model_number-1]{'own'}},\
%return_section );
1352 # }}} Relative change of the parameter estimates
1354 $self -> update_raw_results
(model_number
=> $model_number);
1356 # ------------- Register the results in a Database ----------------
1358 if( not -e
$self -> {'directory'}."m$model_number/done.database.results" ) {
1359 open( DB
, ">".$self -> {'directory'}."m$model_number/done.database.results" );
1360 my ( $start_id, $last_id ) = $self ->
1361 register_mfit_results
( model_number
=> $model_number,
1362 cook_score
=> \
@cook_score,
1363 covariance_ratio
=> \
@cov_ratio,
1364 projections
=> $proj_ref,
1365 outside_n_sd
=> \
@outside_n_sd );
1366 print DB
"$start_id-$last_id\n";
1370 # experimental: to save memory
1371 $self -> {'prepared_models'}[$model_number-1]{'own'} = undef;
1373 end modelfit_analyze
1375 # }}} modelfit_analyze
1380 my $D = Math
::MatrixReal
->
1381 new_from_rows
( \
@data_matrix );
1382 my @n_dim = @
{$data_matrix[0]};
1383 my @d_dim = @data_matrix;
1384 my $n = scalar @n_dim;
1385 my $d = scalar @d_dim;
1386 map( $_=(1/$n), @n_dim );
1387 my $frac_vec_n = Math
::MatrixReal
->
1388 new_from_cols
( [\
@n_dim] );
1389 map( $_=1, @n_dim );
1390 map( $_=1, @d_dim );
1391 my $one_vec_n = Math
::MatrixReal
->
1392 new_from_cols
( [\
@n_dim] );
1393 my $one_vec_d = Math
::MatrixReal
->
1394 new_from_cols
( [\
@d_dim] );
1395 my $one_vec_d_n = $one_vec_d * ~$one_vec_n;
1396 my $M = $D*$frac_vec_n;
1397 my $M_matrix = $M * ~$one_vec_n;
1399 # Calculate the mean-subtracted data
1400 my $S = $D-$M_matrix;
1402 # compue the empirical covariance matrix
1405 # compute the eigenvalues and vectors
1406 my ($l, $V) = $C -> sym_diagonalize
();
1408 # Project the original data on the eigenvectors
1412 # l, V and projections are all MatrixReal objects.
1413 # We need to return the normal perl equivalents.
1414 @eigenvalues = @
{$l->[0]};
1415 @eigenvectors = @
{$V->[0]};
1416 @std = @
{$self -> std
( data_matrix
=> $P -> [0] )};
1417 # Make $P a n * d matrix
1419 @projections = @
{$P->[0]};
1427 my ( @sum, @pow_2_sum );
1428 if ( defined $data_matrix[0] ) {
1429 my $n = scalar @
{$data_matrix[0]};
1430 for( my $i = 0; $i <= $#data_matrix; $i++ ) {
1431 for( my $j = 0; $j < $n; $j++ ) {
1432 $sum[$i] = $sum[$i]+$data_matrix[$i][$j];
1433 $pow_2_sum[$i] += $data_matrix[$i][$j]*$data_matrix[$i][$j];
1435 $std[$i] = sqrt( ( $n*$pow_2_sum[$i] - $sum[$i]*$sum[$i] ) / ($n*$n) );
1442 # {{{ modelfit_post_fork_analyze
1444 start modelfit_post_fork_analyze
1446 # my @modelfit_results = @{ $self -> {'results'} -> {'subtools'} };
1447 my @modelfit_results = @
{ $self -> {'results'} };
1449 ui
-> print( category
=> 'cdd',
1450 message
=> "Soon done" );
1452 end modelfit_post_fork_analyze
1454 # }}} modelfit_post_fork_analyze
1456 # {{{ modelfit_results
1458 start modelfit_results
1460 my @orig_models = @
{$self -> {'models'}};
1461 my @orig_raw_results = ();
1462 foreach my $orig_model ( @orig_models ) {
1463 my $orig_output = $orig_model -> outputs
-> [0];
1464 push( @orig_raw_results, $orig_output -> $accessor );
1466 # my @models = @{$self -> {'prepared_models'}};
1467 my @outputs = @
{$self -> {'results'}};
1469 my @raw_results = ();
1471 foreach my $mod ( @outputs ) {
1473 foreach my $output ( @
{$mod -> {'subset_outputs'}} ) {
1474 push( @raw_inner, $output -> $accessor );
1476 push( @raw_results, \
@raw_inner );
1478 if ( $format eq 'relative' or $format eq 'relative_percent' ) {
1480 for ( my $i = 0; $i <= $#orig_raw_results; $i++ ) {
1481 print "Model\t$i\n";
1482 my @rel_subset = ();
1483 for ( my $i2 = 0; $i2 < scalar @
{$raw_results[$i]}; $i2++ ) {
1484 print "Subset Model\t$i2\n";
1486 for ( my $j = 0; $j < scalar @
{$orig_raw_results[$i]}; $j++ ) {
1487 print "Problem\t$j\n";
1488 if( ref( $orig_raw_results[$i][$j] ) eq 'ARRAY' ) {
1489 my @rel_subprob = ();
1490 for ( my $k = 0; $k < scalar @
{$orig_raw_results[$i][$j]}; $k++ ) {
1491 print "Subprob\t$k\n";
1492 if( ref( $orig_raw_results[$i][$j][$k] ) eq 'ARRAY' ) {
1493 my @rel_instance = ();
1494 for ( my $l = 0; $l < scalar @
{$orig_raw_results[$i][$j][$k]}; $l++ ) {
1495 print "Instance\t$l\n";
1496 my $orig = $orig_raw_results[$i][$j][$k][$l];
1497 my $res = $raw_results[$i][$i2][$j][$k][$l];
1498 if( defined $orig and ! $orig == 0 ) {
1499 print "ORIGINAL $orig\n";
1500 print "SUBSET $res\n";
1501 print "RELATIVE ",$res/$orig,"\n";
1502 if ( $format eq 'relative_percent' ) {
1503 push( @rel_instance, ($res/$orig-1)*100 );
1505 push( @rel_instance, $res/$orig );
1508 push( @rel_instance, 'NA' );
1510 push( @rel_subprob,\
@rel_instance );
1512 } elsif( ref( $orig_raw_results[$i][$j][$k] ) eq 'SCALAR' ) {
1513 print "One instance per problem\n";
1514 my $orig = $orig_raw_results[$i][$j][$k];
1515 my $res = $raw_results[$i][$i2][$j][$k];
1516 if( defined $orig and ! $orig == 0 ) {
1517 print "ORIGINAL $orig\n";
1518 print "SUBSET $res\n";
1519 print "RELATIVE ",$res/$orig,"\n";
1520 if ( $format eq 'relative_percent' ) {
1521 push( @rel_subprob, ($res/$orig-1)*100 );
1523 push( @rel_subprob, $res/$orig );
1526 push( @rel_subprob, 'NA' );
1529 print "WARNING: tool::cdd -> modelfit_results: neither\n\t".
1530 "array or scalar reference found at layer 4 in result data\n\t".
1531 "structure (found ",ref( $orig_raw_results[$i][$j][$k] ),")\n";
1534 push( @rel_prob, \
@rel_subprob );
1535 } elsif( ref( $orig_raw_results[$i][$j] ) eq 'SCALAR' ) {
1536 print "One instance per problem\n";
1537 my $orig = $orig_raw_results[$i][$j];
1538 my $res = $raw_results[$i][$i2][$j];
1539 if( defined $orig and ! $orig == 0 ) {
1540 print "ORIGINAL $orig\n";
1541 print "SUBSET $res\n";
1542 print "RELATIVE ",$res/$orig,"\n";
1543 if ( $format eq 'relative_percent' ) {
1544 push( @rel_prob, ($res/$orig-1)*100 );
1546 push( @rel_prob, $res/$orig );
1549 push( @rel_prob, 'NA' );
1552 print "WARNING: tool::cdd -> modelfit_results: neither\n\t".
1553 "array or scalar reference found at layer 3 in result data\n\t".
1554 "structure (found ",ref( $orig_raw_results[$i][$j] ),")\n";
1557 push( @rel_subset, \
@rel_prob );
1559 push( @results, \
@rel_subset );
1562 @results = @raw_results;
1565 end modelfit_results
1567 # }}} modelfit_results
1569 # {{{ relative_estimates
1571 start relative_estimates
1573 my $accessor = $parameter.'s';
1574 my @params = $self -> $accessor;
1576 # print "Parameter: $parameter\n";
1577 # sub process_inner_results {
1578 # my $res_ref = shift;
1581 # foreach my $res ( @{$res_ref} ) {
1582 # if ( ref ( $res ) eq 'ARRAY' ) {
1583 # process_inner_results( $res, $pad );
1585 # print "RELEST $pad\t$res\n";
1589 # process_inner_results( \@params, 0 );
1591 my @orig_params = $self -> $accessor( original_models
=> 1 );
1592 # [?][model][prob][subp][#]
1593 # print "ORIG TH1: ",$orig_params[0][0][0][0][0],"\n";
1594 for ( my $i = 0; $i < scalar @params; $i++ ) {
1597 for ( my $j = 0; $j < scalar @
{$params[$i]}; $j++ ) {
1598 # Loop over data sets
1600 for ( my $k = 1; $k < scalar @
{$params[$i]->[$j]}; $k++ ) {
1601 # Loop over problems (sort of, at least)
1603 for ( my $l = 0; $l < scalar @
{$params[$i]->[$j]->[$k]}; $l++ ) {
1604 # Loop over sub problems (sort of, at least)
1606 for ( my $m = 0; $m < scalar @
{$params[$i]->[$j]->[$k]->[$l]}; $m++ ) {
1607 # Loop over the params
1609 for ( my $n = 0; $n < scalar @
{$params[$i][$j][$k][$l][$m]}; $n++ ) {
1610 my $orig = $orig_params[$i][$j][$l][$m][$n];
1611 # my $orig = $params[$i][$j][0][$l][$m][$n];
1612 my $prep = $params[$i][$j][$k][$l][$m][$n];
1614 if ( $percentage ) {
1615 push( @par, ($prep/$orig*100)-100 );
1617 push( @par, $prep/$orig );
1620 push( @par, $PsN::out_miss_data
);
1623 push( @sub, \
@par );
1625 push( @prob, \
@sub );
1627 push( @prep, \
@prob );
1629 push( @mod, \
@prep );
1631 push( @relative_estimates, \
@mod );
1634 end relative_estimates
1636 # }}} relative_estimates
1638 # {{{ relative_confidence_limits
1640 start relative_confidence_limits
1642 my @params = @
{$self -> confidence_limits
( class => 'tool::llp',
1643 parameter
=> $parameter )};
1644 for ( my $i = 0; $i < scalar @params; $i++ ) {
1647 for ( my $j = 1; $j < scalar @
{$params[$i]}; $j++ ) {
1648 # Loop over data sets
1650 my @nums = sort {$a <=> $b} keys %{$params[$i][$j]};
1651 foreach my $num ( @nums ) {
1653 for ( my $n = 0; $n < scalar @
{$params[$i][$j]->{$num}}; $n++ ) {
1655 for ( my $o = 0; $o < scalar @
{$params[$i][$j]->{$num}->[$n]}; $o++ ) {
1656 # OBS: the [0] in the $j position points at the first element i.e
1657 # the results of the tool run on the original model
1658 my $orig = $params[$i][0]->{$num}->[$n][$o];
1659 my $prep = $params[$i][$j]->{$num}->[$n][$o];
1660 print "ORIG: $orig, PREP: $prep\n";
1662 if ( $percentage ) {
1663 push( @side_lim, ($prep/$orig*100)-100 );
1665 push( @side_lim, $prep/$orig );
1668 push( @side_lim, $PsN::out_miss_data
);
1671 push( @prob_lim, \
@side_lim );
1673 $num_lim{$num} = \
@prob_lim;
1675 push( @mod, \
%num_lim );
1677 push( @relative_limits, \
@mod );
1680 end relative_confidence_limits
1682 # }}} relative_confidence_limits
1684 # {{{ llp_print_results
1686 start llp_print_results
1688 # NOTE! Only valid for models with one problem and one sub problem!
1690 my %relative_values;
1691 $relative_values{'theta_cis'} = $self ->
1692 relative_confidence_limits
( parameter
=> 'theta',
1694 $relative_values{'omega_cis'} = $self ->
1695 relative_confidence_limits
( parameter
=> 'omega',
1697 $relative_values{'sigma_cis'} = $self ->
1698 relative_confidence_limits
( parameter
=> 'sigma',
1700 $relative_values{'thetas'} = $self ->
1701 relative_estimates
( parameter
=> 'theta',
1703 $relative_values{'omegas'} = $self ->
1704 relative_estimates
( parameter
=> 'omega',
1706 $relative_values{'sigmas'} = $self ->
1707 relative_estimates
( parameter
=> 'sigma',
1709 $relative_values{'sethetas'} = $self ->
1710 relative_estimates
( parameter
=> 'setheta',
1712 $relative_values{'seomegas'} = $self ->
1713 relative_estimates
( parameter
=> 'seomega',
1715 $relative_values{'sesigmas'} = $self ->
1716 relative_estimates
( parameter
=> 'sesigma',
1720 $prep_values{'theta_cis'} = $self -> confidence_limits
( class => 'tool::llp',
1721 parameter
=> 'theta' );;
1722 $prep_values{'omega_cis'} = $self -> confidence_limits
( class => 'tool::llp',
1723 parameter
=> 'omega' );;
1724 $prep_values{'sigma_cis'} = $self -> confidence_limits
( class => 'tool::llp',
1725 parameter
=> 'sigma' );;
1726 $prep_values{'thetas'} = $self -> thetas
;
1727 $prep_values{'omegas'} = $self -> omegas
;
1728 $prep_values{'sigmas'} = $self -> sigmas
;
1729 $prep_values{'sethetas'} = $self -> sethetas
;
1730 $prep_values{'seomegas'} = $self -> seomegas
;
1731 $prep_values{'sesigmas'} = $self -> sesigmas
;
1735 open( RES
, ">".$self -> {'results_file'} );
1736 print RES
"Case-Deletion Diagnostic with Log-Likelihood Profiling\n";
1738 for ( my $i = 0; $i < scalar @
{$relative_values{'theta_cis'}}; $i++ ) {
1739 print RES
"MODEL:;",$i+1,"\n";
1740 foreach my $param ( 'theta_cis', 'omega_cis', 'sigma_cis' ) {
1741 print RES
"\n",uc($param),":\n";
1742 # Loop over data sets
1744 my @nums = sort {$a <=> $b} keys %{$relative_values{$param}[$i][0]};
1746 foreach my $num ( @nums ) {
1747 printf RES
"$num;;;;";
1750 foreach my $num ( @nums ) {
1751 for ( my $o = 0; $o < scalar @
{$relative_values{$param}[$i][0]->{$num}[0]}; $o++ ) {
1752 my $side = $o == 0 ?
'lower' : 'upper';
1753 printf RES
";$side;rel diff (%)";
1758 foreach my $num ( @nums ) {
1759 for ( my $o = 0; $o < scalar @
{$relative_values{$param}[$i][0]->{$num}[0]}; $o++ ) {
1760 printf RES
";%7.5f",$prep_values{$param}[$i][0]->{$num}[0][$o];
1765 for ( my $j = 0; $j < scalar @
{$relative_values{$param}[$i]}; $j++ ) {
1766 printf RES
"%-7d",$j+1;
1767 my @nums = sort {$a <=> $b} keys %{$relative_values{$param}[$i][$j]};
1768 foreach my $num ( @nums ) {
1769 for ( my $n = 0; $n < scalar @
{$relative_values{$param}[$i][$j]->{$num}}; $n++ ) {
1770 for ( my $o = 0; $o < scalar @
{$relative_values{$param}[$i][$j]->{$num}[$n]}; $o++ ) {
1771 my $rel = $relative_values{$param}[$i][$j]->{$num}[$n][$o];
1772 my $prep = $prep_values{$param}[$i][$j+1]->{$num}[$n][$o];
1773 printf RES
";%7.5f",$prep;
1774 printf RES
";%3.0f",$rel;
1782 # Skipped id's, keys and values:
1786 # sub process_inner_results {
1787 # my $res_ref = shift;
1790 # foreach my $res ( @{$res_ref} ) {
1791 # if ( ref ( $res ) eq 'ARRAY' ) {
1792 # print "$pad ARRAY size ",scalar @{$res},"\n";
1793 # process_inner_results( $res, $pad );
1794 # } elsif ( ref ( $res ) eq 'HASH' ) {
1795 # print "$pad HASH keys ",keys %{$res},"\n";
1797 # print "$pad OTHER\n";
1801 # process_inner_results( $self -> {'results'}, 0 );
1804 foreach my $own ( @
{$self -> {'results'} -> {'own'}} ) {
1805 # print "REF1: ",ref($mod),"\n";
1806 # foreach my $prob ( @{$mod} ) {
1807 # print "REF2: ",ref($prob),"\n";
1808 # foreach my $subprob ( @{$prob} ) {
1809 # print "REF3: ",ref($subprob),"\n";
1810 # print "KEYS: ",keys %{$subprob},"\n";
1813 print RES
"MODEL $i\n";
1814 foreach my $param ( 'skipped_ids', 'skipped_keys', 'skipped_values' ) {
1815 print RES
uc($param),"\n";
1817 foreach my $prep ( @
{$own -> {$param}} ) {
1818 print RES
"Bin no;$j;";
1819 foreach my $val ( @
{$prep} ) {
1830 # for ( my $j = 0; $j < scalar @{$relative_values{'thetas_cis'}->[$i]}; $j++ ) {
1831 # print RES "MODEL:;",$j+1,"\n";
1832 # # Loop over problems (sort of, at least)
1833 # for ( my $l = 0; $l < scalar @{$relative_values{'thetas_cis'}->[$i]->[$j]->[0]}; $l++ ) {
1834 # # Loop over sub problems (sort of, at least)
1835 # for ( my $m = 0; $m < scalar @{$relative_values{'thetas_cis'}->[$i]->[$j]->[0]->[$l]}; $m++ ) {
1836 # # foreach my $param ( 'thetas', 'omegas', 'sigmas',
1837 # # 'sethetas', 'seomegas', 'sesigmas' ) {
1838 # foreach my $param ( 'theta_cis' ) {
1839 # print RES uc($param),":\n\n";
1840 # # Here one could add printing of parameter names, i.e. 'CL V...' or 'TH1 TH2...'
1841 # # Loop over data sets
1842 # for ( my $k = 0; $k < scalar @{$relative_values{$param}->[$i]->[$j]}; $k++ ) {
1843 # printf RES "%-7d",$k+1;
1844 # for ( my $n = 0; $n < scalar @{$relative_values{$param}[$i][$j][$k][$l][$m]}; $n++ ) {
1845 # for ( my $o = 0; $o < scalar @{$relative_values{$param}[$i][$j][$k][$l][$m][$n]}; $o++ ) {
1846 # my $rel = $relative_values{$param}->[$i][$j][$k][$l][$m][$n];
1847 # my $prep = $prep_values{$param}->[$j][$k][$l][$m][$n];
1848 # printf RES ";%7.5f",$prep;
1849 # printf RES ";%3.0f",$rel;
1865 end llp_print_results
1867 # }}} llp_print_results
1869 # {{{ general_print_results
1871 start general_print_results
1873 unless ( defined $self -> {'results'} ) {
1874 print "WARNING: cdd->general_print_results: no return values defined;\n"
1875 ."cannot print results\n";
1878 my %results = %{$self -> {'results'}};
1880 open( RES
, ">".$self -> {'results_file'} );
1881 print RES
"Case-Deletion Diagnostic\n";
1885 unless ( defined $results{'own'} ) {
1886 print "WARNING: cdd->general_print_results: no own return values defined;\n"
1887 ."cannot print results\n";
1892 my @own_results = @
{$results{'own'}};
1893 foreach my $result_unit ( @own_results ) {
1894 print RES
$result_unit -> {'name'},"\n";
1895 print RES
$result_unit -> {'comment'},"\n";
1896 my @values = defined $result_unit{'values'} ? @
{$result_unit{'values'}} : ();
1897 my @labels = defined $result_unit{'labels'} ? @
{$result_unit{'labels'}} : ();
1899 for ( my $i = 0; $i <= $#values; $i++ ) {
1901 for ( my $j = 0; $j <= $#values[$i]; $j++ ) {
1902 # Loop the sub problems
1903 for ( my $k = 0; $k <= $#values[$i][$j]; $k++ ) {
1904 # Loop the first result dimension
1905 for (my $l = 0; $l <= $#values[$i][$j][$k]; $l++ ) {
1906 # Loop the second result dimension
1907 for ( my $m = 0; $m <= $#values[$i][$j][$k][$l]; $m++ ) {
1908 # Loop the second result dimension
1909 for ( my $m = 0; $m <= $#values[$i][$j]$k][$l]; $m++ ) {
1910 foreach my $model_res ( @values ) {
1911 foreach my $prob_res ( @
{$model_unit} ) {
1912 foreach my $subprob_res ( @
{$prob_unit} ) {
1913 foreach my $subprob_res ( @
{$prob_unit} ) {
1917 end general_print_results
1919 # }}} general_print_results
1921 # {{{ modelfit_print_results
1923 start modelfit_print_results
1925 my @parameters = ( 'theta', 'omega', 'sigma',
1926 'setheta', 'seomega', 'sesigma' );
1927 my %relative_values;
1930 foreach my $parameter ( @parameters ) {
1931 my $accessor = $parameter.'s';
1932 $relative_values{$parameter} = $self ->
1933 relative_estimates
( parameter
=> $parameter,
1935 $prep_values{$parameter} = $self -> $accessor;
1936 $orig_values{$parameter} = $self -> $accessor( original_models
=> 1 );
1938 # sub process_results {
1939 # my $res_ref = shift;
1942 # foreach my $res ( @{$res_ref} ) {
1943 # if ( ref ( $res ) eq 'ARRAY' ) {
1944 # process_results( $res, $pad );
1946 # print "final $pad\t$res\n";
1950 # process_results( $relative_values{'thetas'}, 0 );
1954 print "Calling nthetas\n";
1955 $nparam{'thetas'} = $self -> nthetas
( original_models
=> 1 );
1956 print "Done that\n";
1957 open( RES
, ">".$self -> {'results_file'} );
1958 print RES
"Case-Deletion Diagnostic\n";
1959 # Date information to be added
1960 # print RES "Date:;;;;",$self -> {'date'},"\n";
1962 print RES
"Modelfiles:";
1963 foreach my $model ( @
{$self -> {'models'}} ) {
1964 print RES
";;;;",$model -> filename
,"\n";
1967 # Based on columns and number of datasets might better be shown if split by
1968 # model and problem:
1969 print RES
"Based on columns:";
1970 my $vars = $self -> {'case_columns'};
1971 if ( ref( $vars ) eq 'ARRAY' ) {
1972 foreach my $vars2 ( @
{$vars} ) {
1973 if ( ref( $vars2 ) eq 'ARRAY' ) {
1974 foreach my $vars3 ( @
{$vars2} ) {
1975 print RES
";;;;$vars3\n";
1978 print RES
";;;;$vars2\n";
1982 print RES
";;;;$vars\n";
1985 print RES
"Number of data sets:";
1986 my $bins = $self -> {'bins'};
1987 if ( ref( $bins ) eq 'ARRAY' ) {
1988 foreach my $bins2 ( @
{$bins} ) {
1989 if ( ref( $bins2 ) eq 'ARRAY' ) {
1990 foreach my $bins3 ( @
{$bins2} ) {
1991 print RES
";;;;$bins3\n";
1994 print RES
";;;;$bins2\n";
1998 print RES
";;;;$bins\n";
2001 print RES
"Selection:;;;;",$self-> {'selection_method'},"\n";
2002 if ( defined $self -> {'seed'} ) {
2003 print RES
"Seed number:;;;;",$self -> {'seed'},"\n";
2005 print RES
"No seed number specified\n";
2008 # TODO: $skip_keys etc from data->case_deletion must be transferred back to
2009 # the main process and appropriate attributes set.
2011 print RES
"\n\n\n\n";
2013 # process_results( $relative_values{'thetas'}->[0]->[0]->[0], 0 );
2015 for ( my $i = 0; $i < scalar @
{$relative_values{'theta'}}; $i++ ) {
2017 for ( my $j = 0; $j < scalar @
{$relative_values{'theta'}->[$i]}; $j++ ) {
2018 print RES
"MODEL:;",$j+1,"\n";
2019 # Loop over problems (sort of, at least)
2020 for ( my $l = 0; $l < scalar @
{$relative_values{'theta'}->[$i]->[$j]->[0]}; $l++ ) {
2021 # Loop over sub problems (sort of, at least)
2022 for ( my $m = 0; $m < scalar @
{$relative_values{'theta'}->[$i]->[$j]->[0]->[$l]}; $m++ ) {
2023 foreach my $param ( @parameters ) {
2024 print RES
uc($param),":\n\n";
2025 # Here one could add printing of parameter names, i.e. 'CL V...' or 'TH1 TH2...'
2026 # Loop over data sets
2028 for ( my $n = 1; $n <=scalar @
{$relative_values{$param}[$i][$j][0][$l][$m]}; $n++ ) {
2029 printf RES
"estimate;rel diff (%);";
2032 for ( my $n = 1; $n <= scalar @
{$relative_values{$param}[$i][$j][0][$l][$m]}; $n++ ) {
2037 for ( my $n = 0; $n < scalar @
{$relative_values{$param}[$i][$j][0][$l][$m]}; $n++ ) {
2038 printf RES
";%7.5f",$orig_values{$param}[$j][$l][$m][$n];
2042 for ( my $k = 0; $k < scalar @
{$relative_values{$param}->[$i]->[$j]}; $k++ ) {
2043 printf RES
"%-7d",$k+1;
2044 for ( my $n = 0; $n < scalar @
{$relative_values{$param}[$i][$j][$k][$l][$m]}; $n++ ) {
2045 my $rel = $relative_values{$param}->[$i][$j][$k][$l][$m][$n];
2046 my $prep = $prep_values{$param}->[$j][$k+1][$l][$m][$n];
2047 printf RES
";%7.5f",$prep;
2048 printf RES
";%3.0f",$rel;
2061 # sub process_inner_results {
2062 # my $res_ref = shift;
2065 # foreach my $res ( @{$res_ref} ) {
2066 # if ( ref ( $res ) eq 'ARRAY' ) {
2067 # print "$pad ARRAY size ",scalar @{$res},"\n";
2068 # process_inner_results( $res, $pad );
2069 # } elsif ( ref ( $res ) eq 'HASH' ) {
2070 # print "$pad HASH keys ",keys %{$res},"\n";
2072 # print "$pad OTHER\n";
2076 # process_inner_results( $self -> {'results'}, 0 );
2078 # Skipped id's, keys and values:
2081 foreach my $own ( @
{$self -> {'results'} -> {'own'}} ) {
2082 print RES
"MODEL $i\n";
2083 foreach my $param ( 'skipped_ids', 'skipped_keys', 'skipped_values' ) {
2084 print RES
uc($param),"\n";
2086 foreach my $prep ( @
{$own -> {$param}} ) {
2087 print RES
"Bin no;$j;";
2088 foreach my $val ( @
{$prep} ) {
2100 end modelfit_print_results
2102 # }}} modelfit_print_results
2104 # {{{ prepare_results
2106 start prepare_results
2108 if ( not defined $self -> {'raw_results'} ) {
2109 $self -> read_raw_results
();
2119 my ($outside_n_sd );
2120 for( my $i = 0; $i < scalar @
{$self -> {'raw_results_header'} -> [0]} ; $i++) {
2121 if( $self -> {'raw_results_header'} -> [0][$i] eq 'outside.n.sd' ){
2125 for( my $model_i; $model_i <= $#{$self -> {'raw_results'}}; $model_i++ ){
2126 for( my $problem_i; $problem_i <= $#{$self -> {'raw_results'} -> [$model_i]}; $problem_i++ ){
2127 my $test_val = $self -> {'raw_results'} -> [$model_i] -> [$problem_i] -> [$outside_n_sd];
2128 if( $test_val ne '' ){
2129 print "Outside ". $self -> {'outside_n_sd_check'};
2130 if( $test_val == 1 ){
2131 print " \t[ WARNING ]\n";
2133 print " \t[ OK ]\n";
2142 # {{{ update_raw_results
2143 start update_raw_results
2149 # foreach my $section( @{$self -> {'results'}[0] -> {'own'}} ){
2150 # if( $section -> {'name'} eq 'cook.scores' ){
2151 # $cook_scores = $section -> {'values'};
2153 # if( $section -> {'name'} eq 'cov.ratio' ){
2154 # $cov_ratios = $section -> {'values'};
2156 # if( $section -> {'name'} eq 'outside.n.sd' ){
2157 # $outside_n_sd = $section -> {'values'};
2162 OSspecific
::absolute_path
( $self -> {'directory'},
2163 $self -> {'raw_results_file'}[$model_number-1] );
2164 open( RRES
, $dir.$file );
2167 open( RRES
, '>',$dir.$file );
2170 print RRES
$rres[0] . ",cook.scores,cov.ratios,outside.n.sd\n";
2172 print RRES
$rres[1] . ",0,1,0\n";
2175 for( my $i = 2 ; $i <= $#rres; $i ++ ) {
2176 my $row_str = $rres[$i];
2178 $row_str .= sprintf( ",%.5f,%.5f,%1f\n" ,
2179 $self -> {'cook_scores'} -> [$i-2],
2180 $self -> {'covariance_ratios'} -> [$i-2],
2181 $self -> {'outside_n_sd'} -> [$i-2] );
2182 print RRES
$row_str;
2186 end update_raw_results
2188 # }}} update_raw_results
2190 # {{{ create_R_scripts
2191 start create_R_scripts
2193 unless( -e
$PsN::lib_dir
. '/R-scripts/cdd.R' ){
2194 'debug' -> die( message
=> 'CDD R-script are not installed, no matlab scripts will be generated.' );
2197 cp
( $PsN::lib_dir
. '/R-scripts/cdd.R', $self -> {'directory'} );
2199 end create_R_scripts