@@ -351,106 +351,103 @@ function plot_timecourse(
351
351
end
352
352
end
353
353
354
- if isinstalled (" matplotlib" )
355
- function run_simulation (
356
- model:: Model ;
357
- viz_type:: String = " original" ,
358
- show_all:: Bool = false ,
359
- stdev:: Bool = false ,
360
- save_format:: String = " pdf" )
361
- if ! isdir (
354
+
355
+ function run_simulation (
356
+ model:: Model ;
357
+ viz_type:: String = " original" ,
358
+ show_all:: Bool = false ,
359
+ stdev:: Bool = false ,
360
+ save_format:: String = " pdf" )
361
+ if ! isdir (
362
+ joinpath (
363
+ model. path,
364
+ " figure"
365
+ )
366
+ )
367
+ mkdir (
362
368
joinpath (
363
369
model. path,
364
370
" figure"
365
371
)
366
372
)
367
- mkdir (
368
- joinpath (
369
- model. path,
370
- " figure"
371
- )
372
- )
373
- end
373
+ end
374
374
375
- if ! (viz_type in [" best" , " average" , " original" , " experiment" ])
376
- try
377
- parse (Int64, viz_type)
378
- catch
379
- error (
380
- " Avairable viz_type are: 'best','average','original','experiment','n(=1,2,...)'"
381
- )
382
- end
375
+ if ! (viz_type in [" best" , " average" , " original" , " experiment" ])
376
+ try
377
+ parse (Int64, viz_type)
378
+ catch
379
+ error (
380
+ " Avairable viz_type are: 'best','average','original','experiment','n(=1,2,...)'"
381
+ )
383
382
end
383
+ end
384
384
385
- n_file:: Vector{Int} = viz_type in [" original" , " experiment" ] ? [] : get_executable (model)
385
+ n_file:: Vector{Int} = viz_type in [" original" , " experiment" ] ? [] : get_executable (model)
386
386
387
- simulaitons_all:: Array{Float64,4} = fill (
388
- NaN ,
389
- (
390
- length (model. observables),
391
- length (n_file),
392
- length (model. sim. conditions),
393
- length (model. sim. t),
394
- )
387
+ simulaitons_all:: Array{Float64,4} = fill (
388
+ NaN ,
389
+ (
390
+ length (model. observables),
391
+ length (n_file),
392
+ length (model. sim. conditions),
393
+ length (model. sim. t),
395
394
)
396
- if viz_type != " experiment"
397
- if length (n_file) > 0
398
- if length (n_file) == 1 && viz_type == " average"
399
- error (" viz_type should be best, not $viz_type " )
400
- end
401
- for (j, nth_param_set) in enumerate (n_file)
402
- (model, is_successful) = validate! (model, nth_param_set)
403
- if is_successful
404
- for i in eachindex (model. observables)
405
- @inbounds simulaitons_all[i, j, :, :] = model. sim. simulations[i, :, :]
406
- end
407
- end
408
- end
409
- best_fitness_all:: Vector{Float64} = fill (Inf , length (n_file))
410
- for (i, nth_param_set) in enumerate (n_file)
411
- local filepath = joinpath (
412
- model. path,
413
- " fitparam" ,
414
- " $nth_param_set " ,
415
- " best_fitness" ,
416
- )
417
- if isfile (filepath * " .dat" )
418
- best_fitness_all[i] = readdlm (
419
- filepath * " .dat"
420
- )[1 , 1 ]
421
- elseif isfile (filepath * " .npy" )
422
- best_fitness_all[i] = numpy_load (
423
- filepath * " .npy"
424
- )[1 , 1 ]
395
+ )
396
+ if viz_type != " experiment"
397
+ if length (n_file) > 0
398
+ if length (n_file) == 1 && viz_type == " average"
399
+ error (" viz_type should be best, not $viz_type " )
400
+ end
401
+ for (j, nth_param_set) in enumerate (n_file)
402
+ (model, is_successful) = validate! (model, nth_param_set)
403
+ if is_successful
404
+ for i in eachindex (model. observables)
405
+ @inbounds simulaitons_all[i, j, :, :] = model. sim. simulations[i, :, :]
425
406
end
426
407
end
427
- best_param_set:: Int = n_file[argmin (best_fitness_all)]
428
- if viz_type == " best"
429
- model, _ = validate! (model, best_param_set)
430
- elseif viz_type != " average" && parse (Int64, viz_type) <= length (n_file)
431
- model, _ = validate! (model, parse (Int64, viz_type))
432
- elseif viz_type != " average" && parse (Int64, viz_type) > length (n_file)
433
- error (
434
- @sprintf (
435
- " n (%d) must be smaller than n_fitparam (%d)" ,
436
- parse (Int64, viz_type), length (n_file)
437
- )
438
- )
408
+ end
409
+ best_fitness_all:: Vector{Float64} = fill (Inf , length (n_file))
410
+ for (i, nth_param_set) in enumerate (n_file)
411
+ local filepath = joinpath (
412
+ model. path,
413
+ " fitparam" ,
414
+ " $nth_param_set " ,
415
+ " best_fitness" ,
416
+ )
417
+ if isfile (filepath * " .dat" )
418
+ best_fitness_all[i] = readdlm (
419
+ filepath * " .dat"
420
+ )[1 , 1 ]
421
+ elseif isfile (filepath * " .npy" )
422
+ best_fitness_all[i] = numpy_load (
423
+ filepath * " .npy"
424
+ )[1 , 1 ]
439
425
end
440
- else
441
- p:: Vector{Float64} = param_values ()
442
- u0:: Vector{Float64} = initial_values ()
443
- if model. sim. simulate! (p, u0) != = nothing
444
- error (
445
- " Simulation failed."
426
+ end
427
+ best_param_set:: Int = n_file[argmin (best_fitness_all)]
428
+ if viz_type == " best"
429
+ model, _ = validate! (model, best_param_set)
430
+ elseif viz_type != " average" && parse (Int64, viz_type) <= length (n_file)
431
+ model, _ = validate! (model, parse (Int64, viz_type))
432
+ elseif viz_type != " average" && parse (Int64, viz_type) > length (n_file)
433
+ error (
434
+ @sprintf (
435
+ " n (%d) must be smaller than n_fitparam (%d)" ,
436
+ parse (Int64, viz_type), length (n_file)
446
437
)
447
- end
438
+ )
439
+ end
440
+ else
441
+ p:: Vector{Float64} = param_values ()
442
+ u0:: Vector{Float64} = initial_values ()
443
+ if model. sim. simulate! (p, u0) != = nothing
444
+ error (
445
+ " Simulation failed."
446
+ )
448
447
end
449
448
end
450
- plot_timecourse (
451
- model, n_file, viz_type, show_all, stdev, simulaitons_all, save_format
452
- )
453
449
end
454
- else
455
- println (" run_simulation requires matplotlib." )
450
+ plot_timecourse (
451
+ model, n_file, viz_type, show_all, stdev, simulaitons_all, save_format
452
+ )
456
453
end
0 commit comments