diff -Nru octave-stk-2.4.2/ChangeLog octave-stk-2.5.0/ChangeLog --- octave-stk-2.4.2/ChangeLog 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/ChangeLog 2017-09-13 07:51:00.000000000 +0000 @@ -1,3 +1,865 @@ +2017-09-12 Julien Bect + + CODING_GUIDELINES: Add (and apply) CG#12 guideline + + * admin/CODING_GUIDELINES: Document in CG#12 why it is better to + use "hold off" instead of "cla" when calling stk_plot1d in a loop. + * examples/02_design_of_experiments/stk_example_doe03.m: Apply CG#12. + * examples/02_design_of_experiments/stk_example_doe05.m: Apply CG#12. + + CODING_GUIDELINES: Add CG#11 guideline + + * admin/CODING_GUIDELINES: Document in CG#11 why horzcat and + vertcat must be called explicitely. + +2017-09-11 Julien Bect + + Workaround for get (0, 'Format') compatibility issue + + * misc/text/stk_disp_getformat.m: New function to get 'Format' and + 'FormatSpacing' properties in a Matlab/Octave comaptible way. + * misc/text/stk_disp_isloose.m: Rewrite using the new function. + * admin/octpkg/INDEX: Add new function to the INDEX. + * arrays/@stk_dataframe/disp.m: Use the new function. + * arrays/@stk_dataframe/stk_sprintf.m: Idem. + * arrays/@stk_factorialdesign/stk_factorialdesign.m: Itou. + +2017-09-10 Julien Bect + + Raise Octave version requirement to 3.6 + + * README.md: Indicate that STK is tested to work on "GNU Octave + 3.6.2 or newer", which corresponds to the version currently + available in Debian old-old-stable, a.k.a. Wheezy. + * admin/CODING_GUIDELINES: Update coding guidelines. + * admin/build_tools/build_octpkg.m: Set octave depencency version + to 3.6.0 in the DESCRIPTION file. + * arrays/@stk_dataframe/stk_sprintf.m: Remove hacks. + * arrays/@stk_dataframe/subsasgn.m: Remove hacks. + * arrays/@stk_factorialdesign/subsasgn.m: Remove hacks. + * arrays/generic/stk_sprintf.m: Remove hacks. + * misc/error/stk_error.m: Remove hacks. + * misc/mole/quantile/quantile.m: Remove hacks. + * stk_init.m: Remove hacks. + * utils/stk_plot1d.m: Remove hacks. + * arrays/@stk_dataframe/isequal.m: Remove overloaded isequal + function, no longer needed. + * arrays/@stk_factorialdesign/isequal.m: Idem. + * core/@stk_kreq_qr/isequal.m: Idem. + * core/@stk_model_gpposterior/isequal.m: Idem. + * lm/@stk_lm_affine/isequal.m: Idem. + * lm/@stk_lm_constant/isequal.m: Idem. + * lm/@stk_lm_cubic/isequal.m: Idem. + * lm/@stk_lm_matrix/isequal.m: Idem. + * lm/@stk_lm_null/isequal.m: Idem. + * lm/@stk_lm_quadratic/isequal.m: Idem. + * misc/optim/@stk_optim_baseclass/isequal.m: Idem. + * misc/optim/@stk_optim_fmincon/isequal.m: Idem. + * misc/optim/@stk_optim_fminsearch/isequal.m: Idem. + * misc/optim/@stk_optim_octavesqp/isequal.m: Idem. + * misc/parallel/@stk_parallel_engine_none/isequal.m: Idem. + * misc/parallel/@stk_parallel_engine_parfor/isequal.m: Idem. + * admin/octpkg/INDEX: Update INDEX. + * admin/octpkg/patches/remove-buildmex.patch: Update patch. + * admin/octpkg/patches/remove-testprivatemex.patch: Update patch. + * admin/octpkg/patches/stk-init-rmpath-cleanup.patch: Update patch. + +2017-09-07 Julien Bect + + stk_plot_shadedci.m: Use area instead of fill for old Octave/Matlab + + * misc/plot/stk_plot_shadedci.m: Use area instead of fill for old + versions of Octave and Matlab. + +2017-09-05 Julien Bect + + stk_runtests.m: In Octave, check that __run_test_suite__ exists + + * misc/test/stk_runtests.m: In Octave, check that + __run_test_suite__ exists before actually trying to call it. + +2017-09-04 Julien Bect + + stk_sampcrit_ei_eval.m: Remove deprecated calling forms + + * sampling/stk_sampcrit_ei_eval.m: Remove deprecated calling forms. + + Make halfpintl public, with an stk_ prefix + + * sampling/private/halfpintl.m: Remove from private directory. + * sampling/stk_halfpintl.m: Renamed from halfpintl.m. + * admin/octpkg/INDEX: Expose stk_halfpintl in the INDEX. + * sampling/stk_sampcrit_akg_eval.m: Update. + * admin/octpkg/patches/comment-out-unit-tests-in-private-functions.patch: Remove. + * admin/octpkg/patches/series: Update. + + Use Octave's native test function on Octave + + * misc/test/stk_test.m: Use Octave's native test function on Octave. + * misc/test/stk_runtests.m: Similarly, use Octave's native + __run_test_suite__ function when running on Octave. + * admin/octpkg/patches/use-native-test-function.patch: Remove patch. + * admin/octpkg/patches/series: Remove patch. + * admin/octpkg/INDEX: Add stk_test to the INDEX. + +2017-09-01 Julien Bect + + Multiply/divide an stk_dataframe object by a scalar + + * arrays/@stk_dataframe/mtimes.m: Implement a special case for the + multiplication of an stk_dataframe object by a numerical scalar. + * arrays/@stk_dataframe/mldivide.m: Idem for left division. + * arrays/@stk_dataframe/mrdivide.m: Idem for right division. + + Overload left/right matrix division for stk_dataframe objects + + * arrays/@stk_dataframe/mldivide.m: New function. + * arrays/@stk_dataframe/mrdivide.m: New function. + * admin/octpkg/INDEX: Add new functions to the INDEX. + + stk_benchmark_predict.m: The boxplot function might be unavailable + + * misc/benchmarks/stk_benchmark_predict.m: Wrap call to boxplot in + try-catch block, since the boxplot function might be unavailable. + + @stk_sampcrit_ei/set.m: Remove unnecessary assert + + * sampling/@stk_sampcrit_ei/set.m: Remove unnecessary assert, + since only scalar output models are supported in STK at this time. + + Remove support for old-style .a structures + + * arrays/@stk_dataframe/private/get_column_number.c: Remove + support for old-style .a structures. + * misc/dist/stk_gpquadform.m: Idem. + * arrays/@struct/double.m: Removed. + * arrays/@struct/stk_boundingbox.m: Removed. + * arrays/@struct/stk_length.m: Removed. + * admin/octpkg/INDEX: Update. + * arrays/@stk_dataframe/subsref.m: Remove unit tests. + * core/@stk_model_gpposterior/stk_predict.m: Idem. + * core/stk_predict.m: Idem. + * arrays/generic/stk_feval.m: Idem. + * covfcs/stk_expcov_aniso.m: Idem. + * covfcs/stk_gausscov_aniso.m: Idem. + * covfcs/stk_materncov32_aniso.m: Idem. + * covfcs/stk_sphcov_aniso.m: Idem. + * NEWS.md: Advertise. + +2017-08-31 Julien Bect + + stk_generate_samplepaths.m: Remove xtest for ticket #14 + + * utils/stk_generate_samplepaths.m: Remove xtest for ticket #14 + since the problem as been solved, as expected, by the previous + commit. + + Exact predictions at obs points for noiseless models (ticket #49) + + * core/@stk_model_gpposterior/stk_predict.m: Ensure exact + prediction at observation points for noiseless models. + * core/stk_predict.m: Change xtest to test. + * sampling/@stk_sampcrit_eqi/feval.m: Fix EQI computation at the + points where the variance is zero. + + Insert HTML version of AUTHORS.md in the documentation + + * admin/build_tools/generate_htmldoc.m: Insert HTML version of + AUTHORS.md in the documentation. + + INDEX: Add @stk_factorialdesign/ismember + + * admin/octpkg/INDEX: INDEX: Add @stk_factorialdesign/ismember. + + Convert AUTHORS to markdown. + + * AUTHORS: Renamed to AUTHORS.md + * AUTHORS.md: Renamed from AUTHORS, and converted to md syntax. + * admin/find_nonstandard_characters.sh: Scan AUTHORS.md as well. + * admin/build_tools/build_octpkg.m: Update. + * README.md: Update. + * admin/RELEASE.md: Update. + + NEWS.md: Write Matérn with an accent on the "e" + + * NEWS.md: Write Matérn with an accent on the "e", since we are + already using UTF-8 in this file anyway (for the umlaut on the "u" + of Müller). + +2017-08-30 Julien Bect + + Overload ismember for stk_factorialdesign objects (ticket #29) + + * arrays/@stk_factorialdesign/ismember.m: New function + +2017-08-29 Julien Bect + + stk_sampcrit_ehvi_eval.m: Avoid OOM errors (ticket #48) + + * sampling/stk_sampcrit_ehvi_eval.m: Process batches of rectangles + to avoid OOM errors. + + Adapt html doc generation to changes in generate_html (fix) + + * admin/build_tools/get_allpurpose_html_options.m: Fix earlier + commit (a12753859a6a) with the same name. + + generate_htmldoc.m: Use HTML version of NEWS.md (ticket #61) + + * admin/build_tools/generate_htmldoc.m: Insert HTML version of + NEWS.md, produced by markdown, inside NEWS.html. + + NEWS.md: Fix markdown formatting + + * NEWS.md: Fix markdown formatting + +2017-08-28 Julien Bect + + Convert NEWS to markdown formatting (ticket #60) + + * NEWS.md: Convert NEWS to markdown formatting and rename to NEWS.md. + * NEWS: Removed. + * admin/build_tools/build_octpkg.m: Rename NEWS to NEWS.md. + +2017-08-26 Julien Bect + + @stk_dataframe/ismember.m: Do not assume 'rows' (ticket #50) + + * arrays/@stk_dataframe/ismember.m: Do not assume 'rows', in order + to have a behaviour that is consistent with that of the base + function on numerical matrices. + + Remove isoctave function + + * misc/mole/isoctave/isoctave.m: Deleted. + * stk_init.m: Use exist directly. Remove a few lines related to + the isoctave function. + * misc/mole/graphics_toolkit/graphics_toolkit.m: Use exist + directly. + * misc/optim/@stk_optim_octavesqp/stk_optim_octavesqp.m: Use exist + directly. + * misc/options/stk_options_set.m: Use exist directly. + * misc/parallel/stk_parallel_start.m: Use exist directly. + * misc/test/stk_test.m: Use exist directly. + * admin/octpkg/patches/remove-buildmex.patch: Refresh patch. + * admin/octpkg/patches/remove-testprivatemex.patch: Refresh patch. + * admin/octpkg/patches/stk-init-rmpath-cleanup.patch: Refresh patch. + * admin/octpkg/patches/use-native-test-function.patch: Refresh patch. + + CG#10: Disable TeX interpreter for variable names + + * admin/CODING_GUIDELINES: Introduce new coding guideline, CG#10, + recommending to disable the TeX interpreter for variable names. + * arrays/@stk_dataframe/plot.m: Follow CG#10. + * arrays/@stk_dataframe/plotmatrix.m: Follow CG#10. + * arrays/@stk_factorialdesign/private/plot_surfmeshcontour.m: Follow CG#10. + * arrays/@stk_hrect/axis.m: Follow CG#10. + +2017-08-25 Julien Bect + + Adapt html doc generation to changes in generate_html + + * admin/build_tools/get_allpurpose_html_options.m: Adapt html doc + generation to changes in generate_html. + +2017-07-25 Julien Bect + + @stk_dataframe/bsxfun.m: Fix colnames/rownames selection + + * arrays/@stk_dataframe/bsxfun.m: Fix colnames/rownames selection. + +2017-07-24 Julien Bect + + @stk_model_gpposterior/stk_predict_leaveoneout.m: Ensure var >= 0 + + * core/@stk_model_gpposterior/stk_predict_leaveoneout.m: Make sure + that variances will always be non-negative. + + Benchmark virtual LOO-CV speedup + + * misc/benchmarks/stk_benchmark_loocv.m: New benchmark script to + evaluate to speedup brought by the implementation of virtual LOO + cross validation. + + Move some LOO-CV unit tests + + * core/stk_predict_leaveoneout.m: Move unit tests for correctness + of virtual LOO-CV formulas to + @stk_model_gpposterior/stk_predict_leaveoneout.m. + * core/@stk_model_gpposterior/stk_predict_leaveoneout.m: Here. + + Keep a copy of the original "direct" implementation of LOO-CV. + + * core/@stk_model_gpposterior/stk_predict_leaveoneout_direct.m: + Internal function, which is simply a copy of our original, + "direct" implementation of LOO-CV. Can be used to check + correctness of virtual LOO formulas, and for benchmarking. + * admin/octpkg/INDEX: Hide internal function from the index. + +2017-07-23 Rémi Stroh + + stk_predict_leaveoneout.m: Use virtual Leave-One-Out formula (ticket #35) + + * core\@stk_model_gpposterior\stk_predict_leaveoneout.m: Replace + the naive expression of the cross-validation, by the virtual + leave-one-out formula. + * core\stk_predict_leaveoneout.m: Add a test to check virtual + LOO formula. + +2017-07-12 Julien Bect + + stk_benchmark_predict.m: New function to benchmark stk_predict + + * misc/benchmarks/stk_benchmark_predict.m: New function to + benchmark stk_predict. + + stk_benchmark_.m: New function to help benchmark computation times + + * misc/benchmarks/stk_benchmark_.m: New function to help benchmark + computation times. + +2017-07-10 Julien Bect + + stk_example_misc04.m: Work-around for Octave bug #49267. + + * examples/03_miscellaneous/stk_example_misc04.m: Work-around for + Octave bug #49267. + + New octpkg patch to comment out unit tests in private functions + + * admin/octpkg/patches/comment-out-unit-tests-in-private-functions.patch: + New octpkg patch to comment out unit tests in private functions. + * admin/octpkg/patches/series: Add new test to the series. + +2017-07-09 Julien Bect + + stk_predict_leaveoneout.m: Update help text + + * core/stk_predict_leaveoneout.m: Update help text. + + Set release date based on hg date in the build process + + * Makefile: Pass hg date to build_* functions. + * admin/build_tools/build_allpurpose.m: Use hg date. + * admin/build_tools/build_octpkg.m: Use hg date. + * admin/build_tools/copy_citation.m: Use hg date. + * admin/build_tools/copy_readme.m: Use hg date. + +2017-07-05 Julien Bect + + stk_sampcrit_akg_eval.m: Fix unit tests + + * sampling/stk_sampcrit_akg_eval.m: Fix unit tests. + + stk_dominatedhv_mex.c: Avoid "uninitialized variable" warnings + + * misc/pareto/private/stk_dominatedhv_mex.c: Avoid "uninitialized + variable" compiler warnings. + + CG#09: Use erfcinv when norminv fails (ticket #78) + + * admin/CODING_GUIDELINES: Introduce new coding guideline, CG#09, + recommending to use erfcinv directly when norminv fails. + * sampling/@stk_sampcrit_eqi/set.m: Implement CG#09. + +2017-07-04 Rémi Stroh + + @stk_sampcrit_eqi\set.m: Change "norminv" by "erfcinv" (ticket #78) + + * sampling\@stk_sampcrit_eqi\set.m: Replace the use of "norminv" + function, available only with the statistical toolbox, by an + expression using "erfcinv", a special basis function. + + utils\stk_plot1d.m: Correct a bug + + * utils\@stk_plot1d.m: Correct a bug, in the case where xt is empty. + + utils/@stk_plot1d: sort data before plotting + + * utils/@stk_plot1d: sort xt as increasing order before plotting. + The output vectors zt, zp and zsim are similarly modified before + their drawings. + + arrays/@stk_dataframe: Overload 3 additional unitary test functions + + * arrays/@stk_dataframe/isnan.m: New overloaded test function + * arrays/@stk_dataframe/isinf.m: Idem. + * arrays/@stk_dataframe/isfinite.m: Idem. + +2017-07-03 Julien Bect + + stk_param_estim.m: Do not use model.param as a starting point + + * param/estim/stk_param_estim.m: Do not use model.param as a + starting point; if param0 is not provided, call stk_param_init. + Modify documentation accordingly; it wasn't up-to-date anyway. + +2017-07-02 Julien Bect + + @stk_model_gpposterior/stk_predict.m: Skip main loop when nt == 0 + + * core/@stk_model_gpposterior/stk_predict.m: Skip main loop when + nt == 0. + + stk_predict_leaveoneout.m: nargout == 0 => create plots + + * core/@stk_model_gpposterior/stk_predict_leaveoneout.m: Calling + stk_predict_leaveoneout with no output arguments now automatically + create two cross-validation diagnostics in two subplots: + prediction VS observations, left panel, and normalized + + residuals, right panel. + * core/stk_predict_leaveoneout.m: Do not change nargout when + calling overloaded method. + * examples/01_kriging_basics/stk_example_kb10.m: Advertise the new + syntax at the end of the script. + + @stk_dataframe/stk_dataframe.m: Accept char colnames/rownames + + * arrays/@stk_dataframe/stk_dataframe.m: Tolerate char arguments + instead of cells for column and row names in the special case + where the expected number of elements is one. + +2017-07-01 Julien Bect + + stk_plot_probdom2d.m: New function + + * utils/stk_plot_probdom2d.m: New function to represent the + uncertainty about a 2D Pareto front. This function is currently + considered experimental and should not be expected to produce a + reliable representation of the uncertainty for difficult or + high-dimensional optimization problems. + * examples/03_miscellaneous/stk_example_misc04.m: Update the + example to use the new function. + * admin/octpkg/INDEX: Add the new function to the INDEX. + + @stk_model_gpposterior/stk_generate_samplepaths.m: Overload base + + * core/@stk_model_gpposterior/stk_generate_samplepaths.m: New + function, overload base STK function. + + Remove all occurences of response_name + + * core/stk_model.m: Do not mention response_name as an optional + field, since it isn't used anywhere in STK now. + * examples/03_miscellaneous/stk_example_misc04.m: No more + response_name. + + Return a plain numerical array from stk_generate_samplepaths + + * utils/stk_generate_samplepaths.m: Return a plain double + precision numerical array; no more data frames here. + * arrays/@stk_dataframe/stk_generate_samplepaths.m: Removed. + * examples/03_miscellaneous/stk_example_misc04.m: Updated. + * admin/octpkg/INDEX: Update the INDEX. + + @stk_model_gpposterior/stk_model_gpposterior.m: Check xi + + * core/@stk_model_gpposterior/stk_model_gpposterior.m: Check the + number of columns of input argument xi. + + Move important plotting functions to 'utils' directory + + * misc/plot/stk_plot1d.m: Moved to 'utils' directory. + * misc/plot/stk_plot_histnormres.m: Idem. + * misc/plot/stk_plot_predvsobs.m: Idem. + * utils/stk_plot1d.m: Moved from 'misc/plot' directory. + * utils/stk_plot_histnormres.m: Idem. + * utils/stk_plot_predvsobs.m: Idem. + +2017-06-29 Julien Bect + + Add a new test case named 'truss3' + + * examples/test_functions/stk_testcase_truss3.m: New function. + * examples/test_functions/stk_testfun_truss3_bb.m: New function. + * examples/test_functions/stk_testfun_truss3_vol.m: New function. + * admin/octpkg/INDEX: Add new functions to the INDEX. + + stk_plot_predvsobs.m: Lowercase labels + + * misc/plot/stk_plot_predvsobs.m: Lowercase labels. + +2017-06-28 Julien Bect + + Change mnemonic 'IncorrectArgument' to 'InvalidArgument' + + * arrays/@stk_dataframe/cat.m: Change mnemonic 'IncorrectArgument' + to 'InvalidArgument', since both of them were used interchangeably. + * arrays/@stk_dataframe/find.m: Idem. + * arrays/@stk_factorialdesign/private/plot_surfmeshcontour.m: Idem. + * misc/dist/stk_gpquadform.m: Idem. + * misc/pareto/stk_dominatedhv.m: Idem. + * param/estim/stk_param_estim.m: Idem. + * param/estim/stk_param_init.m: Idem. + * sampling/stk_sampling_olhs.m: Idem. + * sampling/stk_sampling_sobol.m: Idem. + + @stk_dataframe/bsxfun.m: Remove annoying warnings + + * arrays/@stk_dataframe/bsxfun.m: Take the column names (or row + names) from the first argument in case of disagreement, as in R. + Remove the annoying warnings. + +2017-06-27 Julien Bect + + @stk_dataframe/set.m: Backout revision 29c5b2515988 + + * arrays/@stk_dataframe/set.m: *Do not* reject colnames and + rownames values with an insufficient number of elements. + + @stk_dataframe/subsasgn.m: Add (currently failing) unit tests + + * arrays/@stk_dataframe/subsasgn.m: Add (currently failing) unit + tests for the insertion of row/column names on data frames that + have none. + + @stk_model_gpposterior/stk_model_gpposterior.m: Check 'prior_model' arg + + * core/@stk_model_gpposterior/stk_model_gpposterior.m: Check that + input argument 'prior_model' is a structure. + + Logical-valued operators now return logical values on df as well + + * arrays/@stk_dataframe/and.m: Return logical result. + * arrays/@stk_dataframe/eq.m: Idem. + * arrays/@stk_dataframe/ge.m: Idem. + * arrays/@stk_dataframe/gt.m: Idem. + * arrays/@stk_dataframe/le.m: Idem. + * arrays/@stk_dataframe/lt.m: Idem. + * arrays/@stk_dataframe/ne.m: Idem. + * arrays/@stk_dataframe/or.m: Idem. + * arrays/@stk_dataframe/xor.m: Idem. + * arrays/@stk_dataframe/not.m: New function. + * admin/octpkg/INDEX: Add new function to the INDEX. + +2017-06-26 Rémi Stroh + + stk_distrib_normal_crps.m: Make unit test deterministic (ticket #77) + + * misc\distrib\stk_distrib_normal_crps.m: Replace the random + selection of data with fixed data. + + stk_distrib_normal_crps.m: Change the final test (ticket #77) + + * misc\distrib\stk_distrib_normal_crps.m: Modify the last test + to support compatibility with older versions of Matlab and + Octave. + +2017-06-26 Julien Bect + + @stk_dataframe/set.m: Check colnames and rownames values more strictly + + * arrays/@stk_dataframe/set.m: Reject colnames and rownames values + with an insufficient number of elements. + + @stk_dataframe/subsref.m: Fix empty indexing + + * arrays/@stk_dataframe/subsref.m: Fix empty indexing. + + @stk_dataframe/stk_dataframe.m: Fix typo + + * arrays/@stk_dataframe/stk_dataframe.m: Fix typo. + +2017-06-25 Julien Bect + + @stk_dataframe/fieldnames.m: Add row names to the list + + * arrays/@stk_dataframe/fieldnames.m: Add row names. Also, do not + include empty row or column names in the list. + +2017-06-24 Julien Bect + + stk_sampling_sobol.m: Fix help text + + * sampling/stk_sampling_sobol.m: Fix help text. + + build_octpkg.m: Add 'License:' in DESCRIPTION + + * admin/build_tools/build_octpkg.m: Add 'License:' in DESCRIPTION. + * admin/build_tools/generate_htmldoc.m: Remove 'Read License" subst. + + @stk_dataframe/stk_sprintf.m: Improve formatting for empty data frames + + * arrays/@stk_dataframe/stk_sprintf.m: Improve formatting for + empty data frames. In particular, display column names or row + names if appropriate. + * arrays/@stk_dataframe/disp.m: Source formatting. + * arrays/generic/stk_sprintf.m: Fix help text. Source formatting. + +2017-06-23 Julien Bect + + stk_dataframe.m: Guess the size when the first input is empty + + * arrays/@stk_dataframe/stk_dataframe.m: Deduce the number of + columns and rows from the length of colnames and rownames, + respectively, when the first input argument is empty. Note that + this patch changes the object generated by the default constructor. + +2017-06-20 Julien Bect + + stk_dominatedhv.m: Accept @stk_dataframe inputs + + * misc/pareto/stk_dominatedhv.m: Tolerate any kind of input + argument that can be converted to a double precision matrix, in + particular @stk_dataframe objects. + +2017-06-16 Julien Bect + + Don't use ~ to ignore output arguments (see CG#07) + + * admin/CODING_GUIDELINES: Improve CG#07 + * sampling/stk_sampcrit_akg_eval.m: Apply CG#07 + * sampling/stk_sampling_nesteddesign.m: Apply CG#07 + * sampling/stk_sampling_nestedlhs.m: Apply CG#07 + + @stk_sampcrit_eqi/disp.m: Fix display bug + + * sampling/@stk_sampcrit_eqi/disp.m: Fix display bug for the case + where point_batch_size is a function handle. + + stk_sampcrit_eqi.m: Increase unit test tolerance (ticket #76) + + * sampling/@stk_sampcrit_eqi/stk_sampcrit_eqi.m: Increase the + numerical tolerance in two unit tests. + + stk_sampcrit_eqi.m: Fix one unit test (ticket #76) + + * sampling/@stk_sampcrit_eqi/stk_sampcrit_eqi.m: Fix one unit + test; in Octave, str2func fails on phony function names. + +2017-06-15 Julien Bect + + stk_sampcrit_akg_eval.m: Improve numerical robustness + + * sampling/stk_sampcrit_akg_eval.m: Mitigate the effect of small + inaccurate covariance values on the computation of the slopes. + + halfpintl.m: Fix a bug affecting slope equality cases + + * sampling/private/halfpintl.m: Fix a bug affecting slope equality + cases. + + stk_plot_shadedci.m: Use area when fill fails (ticket #75) + + * misc/plot/stk_plot_shadedci.m: fill does not accept a axis + handle argument in Matlab prior to R2016a. Use area as we were + doing before when fill fails. + +2017-06-12 Julien Bect + + stk_plot_shadedci.m: Use fill instead of area + + * misc/plot/stk_plot_shadedci.m: Recent changes in Matlab R2017a + have altered the behaviour of area. Using fill is cleaner. + + stk_plot_shadedci.m: Use three shaded areas + + * misc/plot/stk_plot_shadedci.m: Use three shaded areas to + visualize three levels of pointwise confidence intervals at once. + +2017-06-07 Julien Bect + + Optimize for speed + + * core/@stk_kreq_qr/get.m: Use a simple switch. + * core/@stk_model_gpposterior/stk_predict.m: Call get directly. + * sampling/@stk_sampcrit_akg/feval.m: Call get directly. + +2017-06-06 Julien Bect + + @stk_model_gpposterior/stk_predict.m: Improve error messages + + * core/@stk_model_gpposterior/stk_predict.m: Improve the error + messages corresponding to the case where xt has an incorrect size. + +2017-06-05 Julien Bect + + @stk_dataframe/plotmatrix.m: Overload base function + + * arrays/@stk_dataframe/plotmatrix.m: New function, overload base + function to enrich plotmatrix graphics with variable names when + possible. + * admin/octpkg/INDEX: Add the new function to the index. + + Optimize for speed + + * arrays/@stk_dataframe/set_data.m: New function, fast setter. + * admin/octpkg/INDEX: Add the new function to the index. + * arrays/@stk_dataframe/set.m: Use set_data. + * arrays/@stk_factorialdesign/set.m: Use set_data. + * arrays/@stk_hrect/stk_rescale.m: Optimize for speed. + * arrays/@stk_hrect/subsasgn.m: Optimize for speed. + * sampling/stk_sampling_randunif.m: Optimize for speed. + * sampling/stk_sampling_regulargrid.m: Optimize for speed. + +2017-06-03 Julien Bect + + Optimize a few functions for speed + + * arrays/@stk_dataframe/stk_dataframe.m: Optimize + * arrays/@stk_factorialdesign/stk_factorialdesign.m: Optimize + * arrays/@stk_hrect/stk_rescale.m: Optimize + * sampling/stk_sampling_randunif.m: Optimize + * sampling/stk_sampling_regulargrid.m: Optimize + * admin/octpkg/patches/matlab-graphics-axis-Axes.patch: Update + + Upcast objects from derived classes to stk_dataframe + + * arrays/@stk_factorialdesign/stk_dataframe.m: New function. + * arrays/@stk_hrect/stk_dataframe.m: New function. + * admin/octpkg/INDEX: Add new functions to the index. + +2017-05-29 Julien Bect + + @stk_dataframe/find.m: Overload base function + + * arrays/@stk_dataframe/find.m: Overload base function to support + calling find with an stk_dataframe as first input argument. + * admin/octpkg/INDEX: Add new function to the index. + + stk_dataframe.m: Improve error messages + + * arrays/@stk_dataframe/stk_dataframe.m: Improve error message + when either colnames or rownames has an incorrect number of + elements. + + stk_sampcrit_akg_eval.m: Set zr_min to +Inf when zr_mean is empty + + * sampling/stk_sampcrit_akg_eval.m: Set zr_min to +Inf when + zr_mean is empty. + + stk_hrect.m: Preserve colmumns names for stk_dataframe inputs + + * arrays/@stk_hrect/stk_hrect.m: Preserve colmumns names when the + input is an stk_dataframe object. + +2017-05-28 Julien Bect + + stk_factorialdesign.m: Accept stk_dataframe levels + + * arrays/@stk_factorialdesign/stk_factorialdesign.m: Accept + one-variable stk_dataframe factors and preserve column names in + this case. + * arrays/@stk_factorialdesign/stk_boundingbox.m: Do not assume + that the cell array of levels is row-shaped. + * admin/octpkg/patches/matlab-graphics-axis-Axes.patch: Update + patch. + + stk_predict: Remove old inaccessible display_waitbar stuff + + * core/@stk_model_gpposterior/stk_predict.m: Remove old and + inaccessible display_waitbar stuff. + +2017-05-27 Julien Bect + + Implement the AKG criterion + + * sampling/stk_sampcrit_akg_eval.m: New function, this is were the + actual computation of the AKG criterion happens. + * sampling/private/halfpintl.m: New private function that computes + the intersection of lower half-planes (equivalently, the lower + envelope of a set of lines) needed in the AKG. + * sampling/@stk_sampcrit_akg/stk_sampcrit_akg.m: New function. + * sampling/@stk_sampcrit_akg/feval.m: New function, does some + non-trivial preliminary work before calling stk_sampcrit_akg_eval. + * sampling/@stk_sampcrit_akg/disp.m: New function, copied from + other sampcrit classes with minor adaptations. + * sampling/@stk_sampcrit_akg/get.m: New function, this is the same + trivial getter as in other sampcrit classes. + * sampling/@stk_sampcrit_akg/set.m: New function, contains some + pre-computations that depend on the reference grid only. + * examples/02_design_of_experiments/stk_example_doe05.m: Use AKG + as a default, and propose EQI as an option. + * admin/octpkg/INDEX: Update index with new functions. + + @stk_model_gpposterior/stk_make_kreq: new (internal) method + + * core/@stk_model_gpposterior/stk_make_kreq.m: New method. + * core/@stk_model_gpposterior/stk_predict.m: Use the new method. + * admin/octpkg/INDEX: Update index with new function. + + @stk_sampcrit_eqi: point_batch_size can also be a function + + * sampling/@stk_sampcrit_eqi/stk_sampcrit_eqi.m: Add unit tests. + * sampling/@stk_sampcrit_eqi/set.m: Accept functions and char for + the value of point_batch_size. + * sampling/@stk_sampcrit_eqi/feval.m: Compute point_batch_size. + + Fix a spelling error (instanciated -> instantiated) + + * sampling/@stk_sampcrit_ei/stk_sampcrit_ei.m: Fix spelling error. + * sampling/@stk_sampcrit_eqi/stk_sampcrit_eqi.m: Idem. + +2017-05-25 Julien Bect + + Massive overhaul of sampling criterion classes + + * sampling/@stk_sampcrit_modelbased: Class removed + * sampling/@stk_sampcrit_modelbased/feval.m: Removed + * sampling/@stk_sampcrit_modelbased/get_input_data.m: Removed + * sampling/@stk_sampcrit_modelbased/get_model.m: Removed + * sampling/@stk_sampcrit_modelbased/get_output_data.m: Removed + * sampling/@stk_sampcrit_modelbased/set_model.m: Removed + * sampling/@stk_sampcrit_modelbased/stk_model_update.m: Removed + * sampling/@stk_sampcrit_modelbased/stk_sampcrit_modelbased.m: Removed + * sampling/@stk_sampcrit_singleobjoptim: Class removed + * sampling/@stk_sampcrit_singleobjoptim/get_bminimize.m: Removed + * sampling/@stk_sampcrit_singleobjoptim/get_goal.m: Removed + * sampling/@stk_sampcrit_singleobjoptim/set_goal.m: Removed + * sampling/@stk_sampcrit_singleobjoptim/stk_sampcrit_singleobjoptim.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim: Class removed + * sampling/@stk_sampcrit_thresholdbasedoptim/disp.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/get.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/get_threshold_mode.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/get_threshold_quantile_order.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/get_threshold_value.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/set.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/set_goal.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/set_model.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/set_threshold_mode.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/set_threshold_quantile_order.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/set_threshold_value.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/stk_model_update.m: Removed + * sampling/@stk_sampcrit_thresholdbasedoptim/stk_sampcrit_thresholdbasedoptim.m: Removed + * sampling/@stk_sampcrit_base: Class renamed to @stk_function + * sampling/@stk_sampcrit_base/stk_sampcrit_base.m: Moved to @stk_function, renamed, modified + * sampling/@stk_sampcrit_base/disp.m: : Moved to @stk_function and modified + * sampling/@stk_sampcrit_base/display.m: Idem. + * sampling/@stk_sampcrit_base/horzcat.m: Idem. + * sampling/@stk_sampcrit_base/subsasgn.m: Idem. + * sampling/@stk_sampcrit_base/subsref.m: Idem. + * sampling/@stk_sampcrit_base/vertcat.m: Idem. + * sampling/@stk_function: Replaces @stk_sampcrit_base + * sampling/@stk_function/stk_function.m: Moved from @stk_sampcrit_base, renamed, modified + * sampling/@stk_function/disp.m: Moved from @stk_sampcrit_base and modified + * sampling/@stk_function/display.m: Idem. + * sampling/@stk_function/horzcat.m: Idem. + * sampling/@stk_function/subsasgn.m: Idem. + * sampling/@stk_function/subsref.m: Idem. + * sampling/@stk_function/vertcat.m: Idem. + * sampling/@stk_function/feval.m: New method (error only) + * sampling/@stk_function/get.m: New method (error only) + * core/@struct/get_input_data.m: New method to support prior models defined as structures + * core/@struct/get_output_data.m: Idem. + * core/@struct/get_prior_model.m: Idem. + * core/@struct/private/assert_struct_is_model.m: Private function used by the last three + * sampling/@stk_sampcrit_ei: Complete class rewrite + * sampling/@stk_sampcrit_ei/stk_sampcrit_ei.m: Entirely rewritten + * sampling/@stk_sampcrit_ei/msfeval.m: Moved to feval.m + * sampling/@stk_sampcrit_ei/feval.m: Moved from msfeval.m and modified + * sampling/@stk_sampcrit_ei/disp.m: Moved from thresholdbasedoptim and modified + * sampling/@stk_sampcrit_ei/get.m: New method (trivial getter) + * sampling/@stk_sampcrit_ei/set.m: New method (non-trivial setter) + * sampling/@stk_sampcrit_eqi: Complete class rewrite + * sampling/@stk_sampcrit_eqi/stk_sampcrit_eqi.m: Entirely rewritten + * sampling/@stk_sampcrit_eqi/msfeval.m: Moved to feval.m + * sampling/@stk_sampcrit_eqi/feval.m: Moved from msfeval.m and modified + * sampling/@stk_sampcrit_eqi/disp.m: Moved from thresholdbasedoptim and modified + * sampling/@stk_sampcrit_eqi/get.m: New method (trivial getter) + * sampling/@stk_sampcrit_eqi/set.m: New method (non-trivial setter) + * examples/02_design_of_experiments/stk_example_doe05.m: Rewrite almost entirely + * admin/octpkg/INDEX: Update index + 2017-05-16 Julien Bect Fix object display problem (ticket #73) @@ -6,6 +868,9 @@ compact/loose display status in a Matlab/Octave compatible-way. * core/@stk_model_gpposterior/disp.m: Use the new function. * core/@stk_model_gpposterior/display.m: Idem. + * sampling/@stk_sampcrit_base/disp.m: Idem. + * sampling/@stk_sampcrit_base/display.m: Idem. + * sampling/@stk_sampcrit_thresholdbasedoptim/disp.m: Idem. * admin/octpkg/INDEX: Add the new function to the index. 2017-05-13 Julien Bect @@ -23,6 +888,14 @@ * misc/distrib/stk_distrib_normal_ei.m: Recommend to use stk_sampcrit_ei_eval instead. +2017-05-12 Rémi Stroh + + Format help texts. + + * sampling/stk_sampling_nesteddesign.m: Formatting help text to + follow the STK style. + * sampling/stk_sampling_nestedlhs.m: Idem. + 2017-05-11 Julien Bect Remove dominated solutions in MOO sampling criteria @@ -85,6 +958,31 @@ minimization strategy while a comment in the source code indicated maximization. +2017-05-05 Julien Bect + + stk_distrib_normal_crps.m: Remove example from help text + + * misc/distrib/stk_distrib_normal_crps.m: Remove example from help + text. The functions in misc/distrib are meant to be independent of + the rest of the toolbox, we should avoid using functions from + other parts of STK inside them. + +2017-05-03 Rémi Stroh + + stk_distrib_normal_crps.m: New function to compute the Gaussian CRPS + + * misc/distrib/stk_distrib_normal_crps.m: New function to compute + the Continuous Ranked Probability Score in the case of a Gaussian + predictive density. + +2017-04-27 Rémi Stroh + + New functions to create nested designs. + + * sampling/stk_sampling_nesteddesign.m: New function to create nested + designs. + * sampling/stk_sampling_nestedlhs.m: New function to create nested LHS. + 2017-04-27 Julien Bect vertcat.m: Preserve column names when some are missing (ticket #66) @@ -112,6 +1010,41 @@ * utils/stk_generate_samplepaths.m: No need to set lognoisevariance to -inf in the noiseless case. + Bring examples up to date with changes in stk_model_gpposterior + + * examples/02_design_of_experiments/stk_example_doe03.m: Do not + modify directly the 'lognoisevariance' field of the prior. + * examples/02_design_of_experiments/stk_example_doe05.m: Do not + modify directly the 'param' field of the prior. + + stk_sampcrit_thresholdbasedoptim.m: Fix input argument processing + + * sampling/@stk_sampcrit_thresholdbasedoptim/stk_sampcrit_thresholdbasedoptim.m: + Fix input argument processing. + + Reorganize parameter-related functions + + * param/classes: New directory, that will contain parameter + classes in the future. There are no parameter classes currently, + but this is the place where they will be. + * paramestim/private/stk_get_optimizable_parameters.m: Moved to param/classes. + * paramestim/private/stk_set_optimizable_parameters.m: Idem. + * param/classes/stk_get_optimizable_parameters.m: Moved from paramestim/private. + * param/classes/stk_set_optimizable_parameters.m: Idem. + * paramestim/stk_param_estim.m: Moved to param/estim. + * paramestim/stk_param_getdefaultbounds.m: Idem. + * paramestim/stk_param_gls.m: Idem. + * paramestim/stk_param_init.m: Idem. + * paramestim/stk_param_init_lnv.m: Idem. + * paramestim/stk_param_relik.m: Idem. + * param/estim/stk_param_estim.m: Moved from paramestim/. + * param/estim/stk_param_getdefaultbounds.m: Idem. + * param/estim/stk_param_gls.m: Idem. + * param/estim/stk_param_init.m: Idem. + * param/estim/stk_param_init_lnv.m: Idem. + * param/estim/stk_param_relik.m: Idem. + * stk_init.m: Update the path + 2017-04-18 Julien Bect Rewrite two private functions with try-catch blocks instead of tests @@ -732,7 +1665,7 @@ 2016-07-21 Rémi Stroh - arrays/@stk_dataframe: Overload 25 additional unary base functions (sin, exp...) + arrays/@stk_dataframe: Overload 25 additional unitary base functions (sin, exp...) * arrays/@stk_dataframe/acos.m: New overloaded base function * arrays/@stk_dataframe/acosd.m: Idem. @@ -815,9 +1748,9 @@ New function to get/set optimizable parameters. * paramestim/private/stk_get_optimizable_parameters.m: New - function get the value of optizable parameters. + function get the value of optimizable parameters. * paramestim/private/stk_set_optimizable_parameters.m: New - function set the value of optizable parameters. + function set the value of optimizable parameters. * paramestim/stk_param_estim.m: Use the new functions wherever it is appropriate. * paramestim/stk_param_relik.m: Idem. @@ -5349,7 +6282,7 @@ 2012-09-08 Julien Bect - Adding default bounds for Matern 3/2 covariances. + Adding default bounds for Matérn 3/2 covariances. * paramestim/stk_param_estim.m: modified @@ -5790,7 +6723,7 @@ * stk_init.m: Turned output pagination off and disabled verbose help messages in Octave. - New covariance function (Matern 3/2). + New covariance function (Matérn 3/2). * utils/specfun/stk_sf_matern32.m: New function. * covfcs/stk_materncov32_aniso.m: New function. @@ -5812,12 +6745,12 @@ 2012-02-05 Julien Bect - New covariance function (Matern 5/2). + New covariance function (Matérn 5/2). * utils/specfun/stk_sf_matern52.m: New function. * covfcs/stk_materncov52_aniso.m: New function. * covfcs/stk_materncov52_iso.m: New function. - * core/stk_param_estim.m: Added Matern 5/2 to get_default_bounds(). + * core/stk_param_estim.m: Added Matérn 5/2 to get_default_bounds(). * examples/example06.m: New script. * examples/run_all_examples.m: Increased NB_EXAMPLES. diff -Nru octave-stk-2.4.2/CITATION octave-stk-2.5.0/CITATION --- octave-stk-2.4.2/CITATION 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/CITATION 2017-09-13 07:51:00.000000000 +0000 @@ -3,7 +3,7 @@ To cite this release of STK in publications use: Julien Bect, Emmanuel Vazquez and others (2017). - STK: a Small (Matlab/Octave) Toolbox for Kriging. Release 2.4. + STK: a Small (Matlab/Octave) Toolbox for Kriging. Release 2.5. URL http://kriging.sourceforge.net A BibTeX entry for LaTeX users is: @@ -11,8 +11,8 @@ @misc{, author = {Bect, Julien and Vazquez, Emmanuel and others}, title = {{STK}: a {S}mall ({M}atlab/{O}ctave) {T}oolbox - for {K}riging. {R}elease 2.4}, - year = {2014}, + for {K}riging. {R}elease 2.5}, + year = {2017}, url = {http://kriging.sourceforge.net} } diff -Nru octave-stk-2.4.2/debian/changelog octave-stk-2.5.0/debian/changelog --- octave-stk-2.4.2/debian/changelog 2018-02-10 09:39:09.000000000 +0000 +++ octave-stk-2.5.0/debian/changelog 2018-02-26 08:08:11.000000000 +0000 @@ -1,3 +1,17 @@ +octave-stk (2.5.0-1) unstable; urgency=medium + + [ Mike Miller ] + * d/control, d/copyright: Use secure URL for upstream source. + + [ Julien Bect ] + * New upstream version 2.5.0 + * d/copyright: Update copyright info + * d/patches: Remove patch 0001, no longer needed + * d/patches/0002: update patch + * d/patches/0003: update patch + + -- Julien Bect Mon, 26 Feb 2018 09:08:11 +0100 + octave-stk (2.4.2-5) unstable; urgency=medium * Use dh-octave for building the package diff -Nru octave-stk-2.4.2/debian/control octave-stk-2.5.0/debian/control --- octave-stk-2.4.2/debian/control 2018-01-26 13:51:11.000000000 +0000 +++ octave-stk-2.5.0/debian/control 2018-02-26 08:08:11.000000000 +0000 @@ -5,7 +5,7 @@ Uploaders: Julien Bect , Build-Depends: debhelper (>= 11), dh-octave Standards-Version: 4.1.3 -Homepage: http://octave.sourceforge.net/stk/ +Homepage: https://octave.sourceforge.io/stk/ Vcs-Git: https://salsa.debian.org/pkg-octave-team/octave-stk.git Vcs-Browser: https://salsa.debian.org/pkg-octave-team/octave-stk Testsuite: autopkgtest-pkg-octave diff -Nru octave-stk-2.4.2/debian/copyright octave-stk-2.5.0/debian/copyright --- octave-stk-2.4.2/debian/copyright 2017-12-28 09:40:02.000000000 +0000 +++ octave-stk-2.5.0/debian/copyright 2018-02-26 08:08:11.000000000 +0000 @@ -1,7 +1,7 @@ Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: stk package for Octave Upstream-Contact: The Octave Community -Source: http://octave.sourceforge.net/stk/index.html +Source: https://octave.sourceforge.io/stk/ Files: * Copyright: 2015-2017, CentraleSupelec @@ -15,10 +15,11 @@ 2013, Derek Bingham, Simon Fraser University 2012, Rik Wehbring 1995-2012, Kurt Hornik - 2015-2016, LNE + 2015-2017, LNE 2005-2015, John W. Eaton 2013-2015, Arun Giridhar 2016, IRT SystemX + 2016, EDF R&D 2007, Massachusetts Institute of Technology 2010, Lyndon While, Lucas Bradstreet License: GPL-3+ diff -Nru octave-stk-2.4.2/debian/patches/0001-Remove-stk_config_testprivatemex.patch octave-stk-2.5.0/debian/patches/0001-Remove-stk_config_testprivatemex.patch --- octave-stk-2.4.2/debian/patches/0001-Remove-stk_config_testprivatemex.patch 2017-12-28 09:40:02.000000000 +0000 +++ octave-stk-2.5.0/debian/patches/0001-Remove-stk_config_testprivatemex.patch 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ -Description: Remove stk_config_testprivatemex -Author: Julien Bect -Forwarded: https://sourceforge.net/p/kriging/tickets/31/ -Last-Update: 2015-11-01 ---- -This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ ---- a/inst/stk_init.m -+++ b/inst/stk_init.m -@@ -228,26 +228,6 @@ - fullfile(root, 'examples', 'datasets' ) ... - fullfile(root, 'examples', 'test_functions' ) }]; - --% Fix a problem with private folders in Octave 3.2.x --% (add private folders to the path to make STK work...) --if (exist ('OCTAVE_VERSION', 'builtin') == 5) -- v = version; -- if strcmp (v(1:4), '3.2.') -- test_path = [path {... -- fullfile(root, 'arrays', '@stk_dataframe') ... -- fullfile(root, 'arrays', '@stk_factorialdesign') ... -- fullfile(root, 'core', '@stk_kreq_qr')}]; -- private_path = {}; -- for i = 1:(length (test_path)) -- p = fullfile (test_path{i}, 'private'); -- if exist (p, 'dir') -- private_path = [private_path {p}]; -- end -- end -- path = [path private_path]; -- end --end -- - end % function - - diff -Nru octave-stk-2.4.2/debian/patches/0002-Remove-the-MOLE.patch octave-stk-2.5.0/debian/patches/0002-Remove-the-MOLE.patch --- octave-stk-2.4.2/debian/patches/0002-Remove-the-MOLE.patch 2017-12-28 09:40:02.000000000 +0000 +++ octave-stk-2.5.0/debian/patches/0002-Remove-the-MOLE.patch 2018-02-26 08:08:11.000000000 +0000 @@ -151,17 +151,6 @@ -%!error linsolve ({1},2) -%!error linsolve (1,{2}) -%!error linsolve (1,2,3) ---- a/inst/misc/parallel/stk_parallel_start.m -+++ b/inst/misc/parallel/stk_parallel_start.m -@@ -33,7 +33,7 @@ - if strcmp (class (eng), 'stk_parallel_engine_none') %#ok - - % use Mathworks' PCT if available -- if (~ isoctave) && (exist ('matlabpool','file')) -+ if (0) && (exist ('matlabpool','file')) - eng = stk_parallel_engine_parfor (); - stk_parallel_engine_set (eng); - end --- a/inst/stk_init.m +++ b/inst/stk_init.m @@ -52,10 +52,7 @@ @@ -171,28 +160,11 @@ - - case 'prune_mole' - stk_init__config_mole (root, false, true); % prune, but do not add to path -- -+ + case 'clear_persistents' % Note: this implies munlock stk_init__clear_persistents (); -@@ -127,7 +124,6 @@ - function stk_init__munlock () - - filenames = { ... -- 'isoctave', ... - 'stk_optim_fmincon', ... - 'stk_options_set', ... - 'stk_parallel_engine_set'}; -@@ -147,7 +143,6 @@ - stk_init__munlock (); - - filenames = { ... -- 'isoctave', ... - 'stk_disp_progress', ... - 'stk_gausscov_iso', ... - 'stk_gausscov_aniso', ... -@@ -183,9 +178,6 @@ +@@ -181,9 +178,6 @@ % Add STK folders to the path addpath (path{:}); @@ -202,10 +174,11 @@ end % function -@@ -292,91 +284,3 @@ +@@ -269,89 +263,3 @@ + s = strrep (s, '.', '\.'); end % function - +- - -function stk_init__config_mole (root, do_addpath, prune_unused) - @@ -218,9 +191,6 @@ - -opts = {root, mole_dir, do_addpath, prune_unused}; - --% isoctave --install_mole_function ('isoctave', opts{:}); -- -% Provide missing octave functions for Matlab users -% TODO: extract functions that are REALLY needed in separate directories -% and get rid of the others ! @@ -277,7 +247,7 @@ - if exist (function_dir, 'dir') && exist (function_mfile, 'file') - - % fprintf ('[MOLE] Providing function %s\n', function_name); -- if do_addpath, +- if do_addpath - addpath (function_dir); - end - @@ -294,17 +264,6 @@ -end - -end % function ---- a/inst/misc/optim/@stk_optim_octavesqp/stk_optim_octavesqp.m -+++ b/inst/misc/optim/@stk_optim_octavesqp/stk_optim_octavesqp.m -@@ -69,7 +69,7 @@ - - % Provide default QP solver if needed - if isempty (options.qp_solver) -- if isoctave -+ if (1) % isoctave - % Octave's core qp function - options.qp_solver = 'qp'; - else --- a/inst/misc/mole/isrow/isrow.m +++ /dev/null @@ -1,34 +0,0 @@ @@ -344,7 +303,7 @@ -end % function --- a/inst/misc/mole/quantile/quantile.m +++ /dev/null -@@ -1,464 +0,0 @@ +@@ -1,463 +0,0 @@ -% QUANTILE ... - -% Copyright Notice @@ -693,8 +652,7 @@ -%!error quantile () -%!error quantile (1, 2, 3, 4, 5) -%!error quantile (['A'; 'B'], 10) --% %!error quantile (1:10, [true, false]) --% % this test fails in Octave 3.2.x +-%!error quantile (1:10, [true, false]) -%!error quantile (1:10, ones (2,2)) -%!error quantile (1, 1, 1.5) -%!error quantile (1, 1, 0) @@ -809,51 +767,6 @@ -end - -end % function ---- a/inst/misc/mole/isoctave/isoctave.m -+++ /dev/null -@@ -1,42 +0,0 @@ --% ISOCTAVE returns true if Octave is used as an interpreter, false otherwise -- --% Copyright Notice --% --% Copyright (C) 2011-2013 SUPELEC --% --% Author: Julien Bect --% --% Note: was called 'stk_is_octave_in_use' in STK <= 2.0.1 -- --% Copying Permission Statement --% --% This file is part of --% --% STK: a Small (Matlab/Octave) Toolbox for Kriging --% (http://sourceforge.net/projects/kriging) --% --% STK is free software: you can redistribute it and/or modify it under --% the terms of the GNU General Public License as published by the Free --% Software Foundation, either version 3 of the License, or (at your --% option) any later version. --% --% STK is distributed in the hope that it will be useful, but WITHOUT --% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --% License for more details. --% --% You should have received a copy of the GNU General Public License --% along with STK. If not, see . -- --function octave_in_use = isoctave -- --persistent b; -- --if isempty (b), -- b = (exist ('OCTAVE_VERSION', 'builtin') == 5); -- mlock; --end -- --octave_in_use = b; -- --end % function --- a/inst/misc/mole/graphics_toolkit/graphics_toolkit.m +++ /dev/null @@ -1,69 +0,0 @@ @@ -865,7 +778,7 @@ -% CALL: NAME = graphics_toolkit () -% -% returns: --% +-% -% * the result of get (0, 'defaultfigure__backend__') if you're running an old version -% of Octave that does not have graphics_toolkit, -% @@ -901,8 +814,8 @@ - -function name = graphics_toolkit () - --if isoctave, -- +-if exist ('OCTAVE_VERSION', 'builtin') == 5 % Octave +- - try - % This should work on older versions of Octave, e.g., 3.2.4 - % (there was no notion of a 'toolkit' at the time, but if gnuplot @@ -911,32 +824,21 @@ - catch - error ('Unable to determine which toolkit is being used.'); - end -- --else % Matlab -- +- +-else % Matlab +- - try - assert (usejava ('jvm')); - name = 'matlab-jvm'; - catch - name = 'matlab-nojvm'; - end -- +- -end - -end % function - -%#ok<*CTCH> ---- a/inst/misc/options/stk_options_set.m -+++ b/inst/misc/options/stk_options_set.m -@@ -123,7 +123,7 @@ - opts.stk_axes.properties = {'FontSize', 8}; - - % Select optimizer for stk_param_estim --if isoctave -+if (1) % isoctave - % In Octave we use sqp (which is always available) in both cases - opts.stk_param_estim.minimize_box = stk_optim_octavesqp (); - opts.stk_param_estim.minimize_unc = stk_optim_octavesqp (); --- a/post_install.m +++ /dev/null @@ -1,42 +0,0 @@ diff -Nru octave-stk-2.4.2/debian/patches/0003-Mark-expected-failure.patch octave-stk-2.5.0/debian/patches/0003-Mark-expected-failure.patch --- octave-stk-2.4.2/debian/patches/0003-Mark-expected-failure.patch 2017-12-28 09:40:02.000000000 +0000 +++ octave-stk-2.5.0/debian/patches/0003-Mark-expected-failure.patch 2018-02-26 08:08:11.000000000 +0000 @@ -6,8 +6,8 @@ Last-Update: 2017-10-13 --- This patch header follows DEP-3: http://dep.debian.net/deps/dep3/ ---- a/inst/paramestim/stk_param_init.m -+++ b/inst/paramestim/stk_param_init.m +--- a/inst/param/estim/stk_param_init.m ++++ b/inst/param/estim/stk_param_init.m @@ -364,7 +364,9 @@ %! xt = stk_sampling_regulargrid (NT, DIM, BOX); % Generate a regular grid %! zt = stk_feval (f, xt); % Values of f on the grid diff -Nru octave-stk-2.4.2/debian/patches/series octave-stk-2.5.0/debian/patches/series --- octave-stk-2.4.2/debian/patches/series 2017-12-28 09:40:02.000000000 +0000 +++ octave-stk-2.5.0/debian/patches/series 2018-02-26 08:08:11.000000000 +0000 @@ -1,3 +1,2 @@ -0001-Remove-stk_config_testprivatemex.patch 0002-Remove-the-MOLE.patch 0003-Mark-expected-failure.patch diff -Nru octave-stk-2.4.2/DESCRIPTION octave-stk-2.5.0/DESCRIPTION --- octave-stk-2.4.2/DESCRIPTION 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/DESCRIPTION 2017-09-13 07:51:00.000000000 +0000 @@ -1,12 +1,12 @@ Name: STK # -Version: 2.4.2 +Version: 2.5.0 # -Date: 16-May-2017 +Date: 2017-09-13 # Title: STK: A Small Toolbox for Kriging # -Author: See AUTHORS file +Author: See AUTHORS.md file # Maintainer: Julien BECT and Emmanuel VAZQUEZ @@ -21,8 +21,10 @@ STK can be useful for other applications areas (such as Geostatistics, Machine Learning, Non-parametric Regression, etc.). # +License: GPLv3+ +# Url: https://sourceforge.net/projects/kriging/ # -Depends: octave (>= 3.2.4) +Depends: octave (>= 3.6.0) # Autoload: no diff -Nru octave-stk-2.4.2/doc/AUTHORS octave-stk-2.5.0/doc/AUTHORS --- octave-stk-2.4.2/doc/AUTHORS 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/doc/AUTHORS 1970-01-01 00:00:00.000000000 +0000 @@ -1,31 +0,0 @@ -STK is mainly developped and maintained by (alphabetical order): - - BECT Julien - VAZQUEZ Emmanuel - -The following people have helped develop the toolbox in various ways -(from providing ideas and bug reports to actually contributing code): - - ALEKSOVSKA Ivana - ASSOULINE Tom - AUTRET Florent - BENASSI Romain - DABOUSSI Elias - DRAUG Carnë - DUHAMEL Stephano - DUTRIEUX Héloïse - FELIOT Paul - FRASNEDO Sophie - JAN Benoit - KETTANI Othmane - KRAUTH Alexandra - LI Ling - PIERA-MARTINEZ Miguel - RAHALI Elham - RAVISANKAR Ashwin - RESSEGUIER Valentin - STROH Rémi - VILLEMONTEIX Julien - -Individual copyright notices are provided at the beginning of each -file in the toolbox. diff -Nru octave-stk-2.4.2/doc/AUTHORS.md octave-stk-2.5.0/doc/AUTHORS.md --- octave-stk-2.4.2/doc/AUTHORS.md 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/doc/AUTHORS.md 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,31 @@ +STK is mainly developped and maintained by (alphabetical order): + + * BECT Julien + * VAZQUEZ Emmanuel + +The following people have helped develop the toolbox in various ways +(from providing ideas and bug reports to actually contributing code): + + * ALEKSOVSKA Ivana + * ASSOULINE Tom + * AUTRET Florent + * BENASSI Romain + * DABOUSSI Elias + * DRAUG Carnë + * DUHAMEL Stephano + * DUTRIEUX Héloïse + * FELIOT Paul + * FRASNEDO Sophie + * JAN Benoit + * KETTANI Othmane + * KRAUTH Alexandra + * LI Ling + * PIERA-MARTINEZ Miguel + * RAHALI Elham + * RAVISANKAR Ashwin + * RESSEGUIER Valentin + * STROH Rémi + * VILLEMONTEIX Julien + +Individual copyright notices are provided at the beginning of each +file in the toolbox. diff -Nru octave-stk-2.4.2/doc/README.md octave-stk-2.5.0/doc/README.md --- octave-stk-2.4.2/doc/README.md 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/doc/README.md 2017-09-13 07:51:00.000000000 +0000 @@ -22,9 +22,9 @@ ## General information - Version: 2.4.2 + Version: 2.5.0 (2017-09-13) - Authors: See AUTHORS file + Authors: See AUTHORS.md file Maintainers: Julien Bect and Emmanuel Vazquez @@ -113,7 +113,7 @@ ### Requirements and recommendations for use with GNU Octave - The STK is tested to work with GNU Octave 3.2.4 or newer. + The STK is tested to work with GNU Octave 3.6.2 or newer. ### Requirements and recommendations for use with Matlab @@ -164,7 +164,6 @@ DOI: 10.1007/s11222-011-9241-4. - ## Ways to get help, report bugs, ask for new features... Use the "help" mailing-list: diff -Nru octave-stk-2.4.2/INDEX octave-stk-2.5.0/INDEX --- octave-stk-2.4.2/INDEX 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/INDEX 2017-09-13 07:51:00.000000000 +0000 @@ -1,5 +1,5 @@ stk >> STK, a Small Toolbox for Kriging - + ## Copyright Notice ## ## Copyright (C) 2015-2017 CentraleSupelec @@ -58,7 +58,7 @@ stk_make_matcov stk_predict stk_predict_leaveoneout - stk_pmisclass + stk_pmisclass stk_conditioning stk_generate_samplepaths stk_isnoisy @@ -73,6 +73,8 @@ stk_param_init stk_param_init_lnv stk_param_relik +#stk_get_optimizable_parameters +#stk_set_optimizable_parameters Posterior model objects @stk_model_gpposterior/stk_model_gpposterior @@ -82,17 +84,25 @@ @stk_model_gpposterior/get_input_data @stk_model_gpposterior/get_output_data @stk_model_gpposterior/get_prior_model -#@stk_model_gpposterior/stk_isnoisy [overload STK] -#@stk_model_gpposterior/disp [overload base] -#@stk_model_gpposterior/display [overload base] -#@stk_model_gpposterior/fieldnames [overload base] -#@stk_model_gpposterior/get [overload base] -#@stk_model_gpposterior/isequal [overload base] -#@stk_model_gpposterior/set [overload base] -#@stk_model_gpposterior/subsasgn [overload base] -#@stk_model_gpposterior/subsref [overload base] -#@stk_model_gpposterior/horzcat [overload base] -#@stk_model_gpposterior/vertcat [overload base] +#@stk_model_gpposterior/stk_isnoisy [overload STK] +#@stk_model_gpposterior/stk_generate_samplepaths [overload STK] +#@stk_model_gpposterior/stk_make_kreq [internal] +#@stk_model_gpposterior/stk_predict_leaveoneout_direct [internal] +#@stk_model_gpposterior/disp [overload base] +#@stk_model_gpposterior/display [overload base] +#@stk_model_gpposterior/fieldnames [overload base] +#@stk_model_gpposterior/get [overload base] +#@stk_model_gpposterior/isequal [overload base] +#@stk_model_gpposterior/set [overload base] +#@stk_model_gpposterior/subsasgn [overload base] +#@stk_model_gpposterior/subsref [overload base] +#@stk_model_gpposterior/horzcat [overload base] +#@stk_model_gpposterior/vertcat [overload base] + +## Prior models are currently represented by structures +#@struct/get_input_data [internal] +#@struct/get_output_data [internal] +#@struct/get_prior_model [internal] ## The stk_kre_qr class -> not ready to be exposed #@stk_kreq_qr/disp [overload base] @@ -118,7 +128,7 @@ stk_materncov_aniso stk_materncov_iso stk_sphcov_aniso - stk_sphcov_iso + stk_sphcov_iso stk_noisecov stk_discretecov @@ -162,6 +172,8 @@ stk_sampling_halton_rr2 stk_sampling_sobol stk_sampling_maximinlhs + stk_sampling_nesteddesign + stk_sampling_nestedlhs stk_sampling_olhs stk_sampling_randomlhs stk_sampling_randunif @@ -178,13 +190,44 @@ stk_mindist stk_phipcrit -Design of experiments (sequential): criterions - stk_sampcrit_ei_eval +Design of experiments (sequential): criteria + stk_sampcrit_ei_eval stk_sampcrit_ehvi_eval stk_sampcrit_emmi_eval + stk_sampcrit_akg_eval stk_distrib_normal_ei stk_distrib_student_ei +## Design of experiments (sequential): criterion objects + +#@stk_function/stk_function [experimental] +#@stk_function/disp [overload base] +#@stk_function/display [overload base] +#@stk_function/get [overload base] +#@stk_function/horzcat [overload base] +#@stk_function/subsasgn [overload base] +#@stk_function/subsref [overload base] +#@stk_function/vertcat [overload base] +#@stk_function/feval [overload base] + +#@stk_sampcrit_ei/stk_sampcrit_ei [experimental] +#@stk_sampcrit_ei/disp [overload base] +#@stk_sampcrit_ei/feval [overload base] +#@stk_sampcrit_ei/get [overload base] +#@stk_sampcrit_ei/set [overload base] + +#@stk_sampcrit_eqi/stk_sampcrit_eqi [experimental] +#@stk_sampcrit_eqi/disp [overload base] +#@stk_sampcrit_eqi/feval [overload base] +#@stk_sampcrit_eqi/get [overload base] +#@stk_sampcrit_eqi/set [overload base] + +#@stk_sampcrit_akg/stk_sampcrit_akg [experimental] +#@stk_sampcrit_akg/disp [overload base] +#@stk_sampcrit_akg/feval [overload base] +#@stk_sampcrit_akg/get [overload base] +#@stk_sampcrit_akg/set [overload base] + Examples: kriging basics stk_example_kb01 stk_example_kb01n @@ -204,6 +247,7 @@ stk_example_doe02 stk_example_doe03 stk_example_doe04 + stk_example_doe05 Examples: miscellaneous stk_example_misc01 @@ -217,6 +261,9 @@ stk_testfun_braninhoo stk_testfun_goldsteinprice stk_testfun_twobumps + stk_testcase_truss3 + stk_testfun_truss3_bb + stk_testfun_truss3_vol ## Cf. misc/distrib/README #stk_distrib_normal_cdf [internal] @@ -241,25 +288,22 @@ stk_isdominated stk_paretofind +Miscellaneous: Validation of models + stk_distrib_normal_crps + #stk_commonsize [internal] #stk_sprintf [internal] #stk_sprintf_colnames [internal] #stk_sprintf_rownames [internal] #stk_sprintf_sizetype [internal] -## Those are for legacy support of .a data structures -## (will be completely removed in the 3.x series) -#@struct/double [overload base + deprecated] -#@struct/stk_boundingbox [overload STK + deprecated] -#@struct/stk_length [overload STK + deprecated] - #@stk_dataframe/stk_boundingbox [overload STK] #@stk_dataframe/stk_conditioning [overload STK] -#@stk_dataframe/stk_generate_samplepaths [overload STK] #@stk_dataframe/stk_length [overload STK] #@stk_dataframe/stk_normalize [overload STK] #@stk_dataframe/stk_rescale [overload STK] #@stk_dataframe/apply [internal] +#@stk_dataframe/set_data [internal] #@stk_dataframe/stk_sprintf [internal] #@stk_dataframe/stk_sprintf_colnames [internal] #@stk_dataframe/stk_sprintf_rownames [internal] @@ -290,13 +334,17 @@ #@stk_dataframe/exp [overload base] #@stk_dataframe/expm1 [overload base] #@stk_dataframe/fieldnames [overload base] +#@stk_dataframe/find [overload base] #@stk_dataframe/ge [overload base] #@stk_dataframe/get [overload base] #@stk_dataframe/gt [overload base] #@stk_dataframe/horzcat [overload base] #@stk_dataframe/isempty [overload base] #@stk_dataframe/isequal [overload base] +#@stk_dataframe/isfinite [overload base] +#@stk_dataframe/isinf [overload base] #@stk_dataframe/ismember [overload base] +#@stk_dataframe/isnan [overload base] #@stk_dataframe/ldivide [overload base] #@stk_dataframe/le [overload base] #@stk_dataframe/length [overload base] @@ -306,22 +354,26 @@ #@stk_dataframe/log2 [overload base] #@stk_dataframe/logical [overload base] #@stk_dataframe/lt [overload base] -#@stk_dataframe/ne [overload base] -#@stk_dataframe/or [overload base] -#@stk_dataframe/plot [overload base] -#@stk_dataframe/subsasgn [overload base] -#@stk_dataframe/subsref [overload base] #@stk_dataframe/max [overload base] #@stk_dataframe/mean [overload base] #@stk_dataframe/median [overload base] #@stk_dataframe/min [overload base] #@stk_dataframe/minus [overload base] #@stk_dataframe/mode [overload base] +#@stk_dataframe/mrdivide [overload base] +#@stk_dataframe/mldivide [overload base] #@stk_dataframe/mtimes [overload base] +#@stk_dataframe/ne [overload base] +#@stk_dataframe/not [overload base] +#@stk_dataframe/or [overload base] #@stk_dataframe/openvar [overload base] +#@stk_dataframe/plot [overload base] +#@stk_dataframe/plotmatrix [overload base] #@stk_dataframe/plus [overload base] #@stk_dataframe/power [overload base] #@stk_dataframe/prod [overload base] +#@stk_dataframe/subsasgn [overload base] +#@stk_dataframe/subsref [overload base] #@stk_dataframe/rdivide [overload base] #@stk_dataframe/realpow [overload base] #@stk_dataframe/reshape [overload base] @@ -352,6 +404,7 @@ #@stk_factorialdesign/fieldnames [overload base] #@stk_factorialdesign/get [overload base] #@stk_factorialdesign/isequal [overload base] +#@stk_factorialdesign/ismember [overload base] #@stk_factorialdesign/mesh [overload base] #@stk_factorialdesign/meshc [overload base] #@stk_factorialdesign/meshz [overload base] @@ -363,6 +416,7 @@ #@stk_factorialdesign/stk_boundingbox [overload STK] #@stk_factorialdesign/stk_normalize [overload STK] #@stk_factorialdesign/stk_rescale [overload STK] +#@stk_factorialdesign/stk_dataframe [overload STK] #@stk_factorialdesign/stk_sprintf [internal] #@stk_factorialdesign/stk_sprintf_levels [internal] @@ -378,6 +432,7 @@ #@stk_hrect/stk_boundingbox [overload STK] #@stk_hrect/stk_normalize [overload STK] #@stk_hrect/stk_rescale [overload STK] +#@stk_hrect/stk_dataframe [overload STK] ## Optimizers stk_minimize_boxconstrained @@ -403,6 +458,7 @@ Miscellaneous: options, plots... stk_dist + stk_halfpintl stk_init stk_options_get stk_options_set @@ -410,6 +466,8 @@ #stk_plot_shadedci [internal] stk_plot_histnormres stk_plot_predvsobs + stk_plot_probdom2d + stk_test stk_runtests stk_version @@ -436,6 +494,7 @@ #stk_disp_examplewelcome [internal] #stk_disp_progress [internal] #stk_disp_isloose [internal] +#stk_disp_getformat [internal] #stk_sprintf_colvect [internal] #stk_sprintf_colvect_fixedpoint [internal] #stk_sprintf_colvect_scientific [internal] diff -Nru octave-stk-2.4.2/inst/arrays/generic/stk_feval.m octave-stk-2.5.0/inst/arrays/generic/stk_feval.m --- octave-stk-2.4.2/inst/arrays/generic/stk_feval.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/generic/stk_feval.m 2017-09-13 07:51:00.000000000 +0000 @@ -373,9 +373,3 @@ %! G = @(t)(0.365 * t^2 + (cos ((t - 1)*(t - 2) + 0.579033))); %! z = stk_feval ({@sin, @cos, G, F, 'tan'}, t, [], [], false); %! assert (isequal (z.colnames, {'sin' 'cos' 'F3' 'F4_1' 'F4_2' 'tan'})); - -%!test % backward compatibility with old-style STK structures -%! n = 15; -%! x = struct ('a', (linspace (0, pi, n))'); -%! y = stk_feval (@sin, x); -%! assert (isequal (size (y), [n 1])); diff -Nru octave-stk-2.4.2/inst/arrays/generic/stk_sprintf.m octave-stk-2.5.0/inst/arrays/generic/stk_sprintf.m --- octave-stk-2.4.2/inst/arrays/generic/stk_sprintf.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/generic/stk_sprintf.m 2017-09-13 07:51:00.000000000 +0000 @@ -1,7 +1,8 @@ -% STK_SPRINTF_DATA prints the content of an array into a string +% STK_SPRINTF prints the content of an array into a string % Copyright Notice % +% Copyright (C) 2017 CentraleSupelec % Copyright (C) 2013, 2014 SUPELEC % % Authors: Julien Bect @@ -51,19 +52,14 @@ else if (nargin < 2) || isempty (data_col_width) - try - switch get (0, 'Format') - case 'short' - data_col_width = 6; - case 'long' - data_col_width = 16; - otherwise - % FIXME: handle other formatting modes... - data_col_width = 10; - end - catch - % Property 'Format' doesn't exist in Octave 3.2.x - data_col_width = 6; + switch stk_disp_getformat () + case 'short' + data_col_width = 6; + case 'long' + data_col_width = 16; + otherwise + % FIXME: handle other formatting modes... + data_col_width = 10; end end @@ -71,10 +67,10 @@ s = repmat ('', n, 1); %#ok<*AGROW> - for j = 1:d, + for j = 1:d xx = stk_sprintf_colvect (x(:, j), data_col_width); s = [s xx]; % formatted data - if j < d, + if j < d % column separator s = [s repmat(' ', n, nb_spaces_colsep)]; end diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/and.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/and.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/and.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/and.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,9 +2,9 @@ % Copyright Notice % -% Copyright (C) 2013 SUPELEC +% Copyright (C) 2017 CentraleSupelec % -% Author: Julien Bect +% Author: Julien Bect % Copying Permission Statement % @@ -26,13 +26,8 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function y = and(x1, x2) +function y = and (x1, x2) -y = bsxfun(@and, x1, x2); +y = (logical (x1) & logical (x2)); end % function - -%!test stk_test_dfbinaryop(@and, floor(3*rand(7, 2)), floor(3*rand(7, 2))); -%!test stk_test_dfbinaryop(@and, floor(3*rand(7, 2)), 1.0); -%!error stk_test_dfbinaryop(@and, floor(3*rand(7, 2)), floor(3*rand(7, 3))); - diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/bsxfun.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/bsxfun.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/bsxfun.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/bsxfun.m 2017-09-13 07:51:00.000000000 +0000 @@ -51,7 +51,7 @@ %---- Choose column and row names --------------------------------------- -if isa (x1, 'stk_dataframe'), +if isa (x1, 'stk_dataframe') c1 = x1.colnames; r1 = x1.rownames; else @@ -59,7 +59,7 @@ r1 = {}; end -if isa (x2, 'stk_dataframe'), +if isa (x2, 'stk_dataframe') c2 = x2.colnames; r2 = x2.rownames; else @@ -67,30 +67,24 @@ r2 = {}; end -if isempty (c1) - colnames = c2; -elseif isempty (c2) +[nr, nc] = size (ydata); + +if length (c1) == nc + % Keep the columns names from the first dataframe (as in R) colnames = c1; +elseif length (c2) == nc + colnames = c2; else - if (~ isequal (size (c1), size (c2))) || (any (~ strcmp (c1, c2))) - warning ('STK:bsxfun:IncompatibleColumnNames', ... - 'Incompatible column names.'); colnames = {}; - else - colnames = c1; - end + colnames = {}; end -if isempty (r1) - rownames = r2; -elseif isempty (r2) +if length (r1) == nr + % Keep the columns names from the first dataframe (as in R) rownames = r1; +elseif length (r2) == nr + rownames = r2; else - if (~ isequal (size (r1), size (r2))) || (any (~ strcmp (r1, r2))) - warning ('STK:bsxfun:IncompatibleRowNames', ... - 'Incompatible row names.'); rownames = {}; - else - rownames = r1; - end + rownames = {}; end %--- Create output ------------------------------------------------------ @@ -100,18 +94,6 @@ end % function -% DESIGN NOTES -% -% Starting from STK 2.2.0, the result of bsxfun is ALWAYS an -% stk_dataframe object, and has column names iff -% * either one of the two arguments doesn't have columns names -% * or the columns names of both arguments agree. -% -% With this design choice, we ensure that if the underlying operation F -% is commutative on double-precision arrays, then it stays commutative -% on stk_dataframe objects. - - %!shared x1, x2, data1, data2 %! x1 = rand (3, 2); data1 = stk_dataframe (x1); %! x2 = rand (3, 2); data2 = stk_dataframe (x2); @@ -128,3 +110,17 @@ %! z = bsxfun (@plus, data1, data2); %! assert (isa (z, 'stk_dataframe') && isequal (double (z), x1 + x2)) +%--- check the behaviour wrt column / row names -------------------------------- + +%!shared x, y +%! x = stk_dataframe (randn (2), {'x1', 'x2'}, {'a'; 'b'}); +%! y = stk_dataframe (randn (2), {'y1', 'y2'}, {'c'; 'd'}); + +%!test z = x + y; +%! assert (isequal (z.colnames, x.colnames)); +%! assert (isequal (z.rownames, x.rownames)); + +%!test z = y + x; +%! assert (isequal (z.colnames, y.colnames)); +%! assert (isequal (z.rownames, y.rownames)); + diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/cat.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/cat.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/cat.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/cat.m 2017-09-13 07:51:00.000000000 +0000 @@ -37,7 +37,7 @@ if dim ~= 2 errmsg = 'Dataframes can only be concatenated along dimension 1 or 2.'; - stk_error(errmsg, 'IncorrectArgument'); + stk_error(errmsg, 'InvalidArgument'); else % concatenate along dimension 2, i.e., horizontally z = horzcat(varargin{:}); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/disp.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/disp.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/disp.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/disp.m 2017-09-13 07:51:00.000000000 +0000 @@ -7,10 +7,11 @@ % Copyright Notice % +% Copyright (C) 2017 CentraleSupelec % Copyright (C) 2013, 2014 SUPELEC % -% Authors: Julien Bect -% Emmanuel Vazquez +% Authors: Julien Bect +% Emmanuel Vazquez % Copying Permission Statement % @@ -34,7 +35,7 @@ function disp (x, verbosity, prefix, data_col_width) -if (nargin < 2) || (isempty (verbosity)), +if (nargin < 2) || (isempty (verbosity)) verbosity = stk_options_get ('stk_dataframe', 'disp_format'); end @@ -42,7 +43,7 @@ prefix = ' '; end -if (nargin < 4) || (isempty (data_col_width)), +if (nargin < 4) || (isempty (data_col_width)) data_col_width = []; end @@ -53,17 +54,12 @@ %!shared x, fmt -%! try % doesn't work on old Octave versions, nevermind -%! fmt = get (0, 'Format'); -%! catch -%! fmt = nan; -%! end +%! fmt = stk_disp_getformat (); %! x = stk_dataframe (rand (3, 2)); -%!test format rat; disp (x); -%!test format long; disp (x); -%!test format short; disp (x); -%! if ~isnan (fmt), set (0, 'Format', fmt); end +%!test format rat; disp (x); +%!test format long; disp (x); +%!test format short; disp (x); format (fmt); %!test disp (stk_dataframe (zeros (0, 1))) %!test disp (stk_dataframe (zeros (0, 2))) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/eq.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/eq.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/eq.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/eq.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,9 +2,9 @@ % Copyright Notice % -% Copyright (C) 2013 SUPELEC +% Copyright (C) 2017 CentraleSupelec % -% Author: Julien Bect +% Author: Julien Bect % Copying Permission Statement % @@ -26,12 +26,8 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function y = eq(x1, x2) +function y = eq (x1, x2) -y = bsxfun(@eq, x1, x2); +y = (double (x1) == double (x2)); end % function - -%!test stk_test_dfbinaryop(@eq, floor(3*rand(7, 2)), floor(3*rand(7, 2))); -%!test stk_test_dfbinaryop(@eq, floor(3*rand(7, 2)), 1.0); -%!error stk_test_dfbinaryop(@eq, floor(3*rand(7, 2)), floor(3*rand(7, 3))); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/fieldnames.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/fieldnames.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/fieldnames.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/fieldnames.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,6 +2,7 @@ % Copyright Notice % +% Copyright (C) 2017 CentraleSupelec % Copyright (C) 2013 SUPELEC % % Author: Julien Bect @@ -28,12 +29,28 @@ function fn = fieldnames (x) -fn = [x.colnames reserved_field_names()]; +% Non-empty column names +cn = x.colnames; +cn = cn(~ cellfun (@isempty, cn)); + +% Non-empty row names +rn = x.rownames; +rn = rn(~ cellfun (@isempty, rn))'; + +fn = [cn rn reserved_field_names()]; end % function + %!test %! x = stk_dataframe (rand (3, 2), {'u' 'v'}); %! s1 = sort (fieldnames (x)); %! s2 = {'colnames' 'data' 'info' 'rownames' 'u' 'v'}; %! assert (all (strcmp (s1, s2))); + +%!test +%! x = stk_dataframe (rand (3, 2)); +%! x.rownames(2:3) = {'aa', 'bb'}; +%! x.colnames{2} = 'toto'; +%! assert (isequal (fieldnames (x), ... +%! {'toto' 'aa' 'bb' 'data' 'info' 'rownames' 'colnames'})); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/find.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/find.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/find.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/find.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,45 @@ +% @STK_DATAFRAME/FIND [overload base function] +% +% See also: find + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function varargout = find (x, varargin) + +if isa (x, 'stk_dataframe') + + varargout = cell (1, max (nargout, 1)); + [varargout{:}] = find (logical (x), varargin{:}); + +else + + stk_error (['@stk_dataframe/find only supports stk_dataframe objects ' ... + 'for the first input argument.'], 'InvalidArgument'); + +end + +end % function diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/ge.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/ge.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/ge.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/ge.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,9 +2,9 @@ % Copyright Notice % -% Copyright (C) 2013 SUPELEC +% Copyright (C) 2017 CentraleSupelec % -% Author: Julien Bect +% Author: Julien Bect % Copying Permission Statement % @@ -26,13 +26,8 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function y = ge(x1, x2) +function y = ge (x1, x2) -y = bsxfun(@ge, x1, x2); +y = (double (x1) >= double (x2)); end % function - -%!test stk_test_dfbinaryop(@ge, floor(3*rand(7, 2)), floor(3*rand(7, 2))); -%!test stk_test_dfbinaryop(@ge, floor(3*rand(7, 2)), 1.0); -%!error stk_test_dfbinaryop(@ge, floor(3*rand(7, 2)), floor(3*rand(7, 3))); - diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/gt.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/gt.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/gt.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/gt.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,9 +2,9 @@ % Copyright Notice % -% Copyright (C) 2013 SUPELEC +% Copyright (C) 2017 CentraleSupelec % -% Author: Julien Bect +% Author: Julien Bect % Copying Permission Statement % @@ -26,13 +26,8 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function y = gt(x1, x2) +function y = gt (x1, x2) -y = bsxfun(@gt, x1, x2); +y = (double (x1) > double (x2)); end % function - -%!test stk_test_dfbinaryop(@gt, floor(3*rand(7, 2)), floor(3*rand(7, 2))); -%!test stk_test_dfbinaryop(@gt, floor(3*rand(7, 2)), 1.0); -%!error stk_test_dfbinaryop(@gt, floor(3*rand(7, 2)), floor(3*rand(7, 3))); - diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/isfinite.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/isfinite.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/isfinite.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/isfinite.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,38 @@ +% ISFINITE [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Remi Stroh + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function ydata = isfinite (x) + +ydata = isfinite (x.data); + +end % function + + +%!test +%! u = [pi, NaN, Inf, -Inf]; x = stk_dataframe (u); v = isfinite (x); +%! assert (islogical (v) && isequal (v, isfinite (u))) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/isinf.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/isinf.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/isinf.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/isinf.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,38 @@ +% ISINF [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Remi Stroh + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function ydata = isinf (x) + +ydata = isinf (x.data); + +end % function + + +%!test +%! u = [pi, NaN, Inf, -Inf]; x = stk_dataframe (u); v = isinf (x); +%! assert (islogical (v) && isequal (v, isinf (u))) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/ismember.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/ismember.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/ismember.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/ismember.m 2017-09-13 07:51:00.000000000 +0000 @@ -31,21 +31,17 @@ if ~ all (cellfun (@ischar, varargin)) stk_error ('Invalid flag (should be a string).', 'InvalidArgument'); -else - % At least of of the arguments (A or B) is an stk_dataframe, - % therefore ismember should work on rows - flags = unique ([{'rows'} varargin{:}]); end varargout = cell (1, max (nargout, 1)); if isa (A, 'stk_dataframe') - [varargout{:}] = ismember (A.data, B, flags{:}); + [varargout{:}] = ismember (A.data, B, varargin{:}); -else % isa (B, 'stk_dataframe') +else % B is an stk_dataframe object - [varargout{:}] = ismember (A, B.data, flags{:}); + [varargout{:}] = ismember (A, B.data, varargin{:}); end @@ -60,15 +56,15 @@ %! u2 = - ones (1, 4); %! x2 = stk_dataframe (u2); -%!assert (ismember (u1, x)) -%!assert (ismember (x1, u)) -%!assert (ismember (x1, x)) - -%!assert (~ ismember (u2, x)) -%!assert (~ ismember (x2, u)) -%!assert (~ ismember (x2, x)) +%!assert (ismember (u1, x, 'rows')) +%!assert (ismember (x1, u, 'rows')) +%!assert (ismember (x1, x, 'rows')) + +%!assert (~ ismember (u2, x, 'rows')) +%!assert (~ ismember (x2, u, 'rows')) +%!assert (~ ismember (x2, x, 'rows')) %!test -%! [b, idx] = ismember ([x2; x1; x1], x); +%! [b, idx] = ismember ([x2; x1; x1], x, 'rows'); %! assert (isequal (b, [false; true; true])); %! assert (isequal (idx, [0; 1; 1])) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/isnan.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/isnan.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/isnan.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/isnan.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,38 @@ +% ISNAN [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Remi Stroh + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function ydata = isnan (x) + +ydata = isnan (x.data); + +end % function + + +%!test +%! u = [pi, NaN, Inf, -Inf]; x = stk_dataframe (u); v = isnan (x); +%! assert (islogical (v) && isequal (v, isnan (u))) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/le.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/le.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/le.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/le.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,9 +2,9 @@ % Copyright Notice % -% Copyright (C) 2013 SUPELEC +% Copyright (C) 2017 CentraleSupelec % -% Author: Julien Bect +% Author: Julien Bect % Copying Permission Statement % @@ -26,12 +26,8 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function y = le(x1, x2) +function y = le (x1, x2) -y = bsxfun(@le, x1, x2); +y = (double (x1) <= double (x2)); end % function - -%!test stk_test_dfbinaryop(@le, floor(3*rand(7, 2)), floor(3*rand(7, 2))); -%!test stk_test_dfbinaryop(@le, floor(3*rand(7, 2)), 1.0); -%!error stk_test_dfbinaryop(@le, floor(3*rand(7, 2)), floor(3*rand(7, 3))); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/lt.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/lt.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/lt.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/lt.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,9 +2,9 @@ % Copyright Notice % -% Copyright (C) 2013 SUPELEC +% Copyright (C) 2017 CentraleSupelec % -% Author: Julien Bect +% Author: Julien Bect % Copying Permission Statement % @@ -26,12 +26,8 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function y = lt(x1, x2) +function y = lt (x1, x2) -y = bsxfun(@lt, x1, x2); +y = (double (x1) < double (x2)); end % function - -%!test stk_test_dfbinaryop(@lt, floor(3*rand(7, 2)), floor(3*rand(7, 2))); -%!test stk_test_dfbinaryop(@lt, floor(3*rand(7, 2)), 1.0); -%!error stk_test_dfbinaryop(@lt, floor(3*rand(7, 2)), floor(3*rand(7, 3))); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/mldivide.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/mldivide.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/mldivide.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/mldivide.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,88 @@ +% MLDIVIDE [overload base function] + +% Copyright Notice +% +% Copyright (C) 2015, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function y = mldivide (x1, x2) + +if isa (x1, 'stk_dataframe') + + x1_data = x1.data; + rownames = x1.colnames; + + if isa (x2, 'stk_dataframe') % both are stk_dataframe objects + + x2_data = x2.data; + colnames = x2.colnames; + + else % x1 is an stk_dataframe object, but not x2 + + x2_data = x2; + colnames = {}; + + end + +else % x2 is an stk_dataframe object, but x1 is not + + x1_data = x1; + + x2_data = x2.data; + colnames = x2.colnames; + + if isscalar (x1) % special case + rownames = x2.rownames; + else + rownames = {}; + end + +end + +y = stk_dataframe (x1_data \ x2_data, colnames, rownames); + +end % function + + +%!test +%! x1_data = [57 7; 2 0]; +%! x1 = stk_dataframe (x1_data, {'x' 'y'}, {'a'; 'b'}); +%! x2_data = [8 7; 2 0]; +%! x2 = stk_dataframe (x2_data, {'w' 'z'}, {'a'; 'b'}); +%! y = x2 \ x1; +%! assert (stk_isequal_tolabs (y, ... +%! stk_dataframe ([1 0; 7 1], {'x'; 'y'}, {'w'; 'z'}))); + + +% Special case: division by a scalar + +%!shared x_data, x, y_data, y +%! x_data = [3 3; 6 3; 9 12]; +%! y_data = [1 1; 2 1; 3 4]; +%! x = stk_dataframe (x_data, {'x' 'y'}, {'a'; 'b'; 'c'}); + +%!test y = 3 \ x; +%!assert (isequal (y, stk_dataframe (y_data, {'x' 'y'}, {'a'; 'b'; 'c'}))); + +%!error y = x \ 3; diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/mrdivide.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/mrdivide.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/mrdivide.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/mrdivide.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,88 @@ +% MRDIVIDE [overload base function] + +% Copyright Notice +% +% Copyright (C) 2015, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function y = mrdivide (x1, x2) + +if isa (x1, 'stk_dataframe') + + x1_data = x1.data; + rownames = x1.rownames; + + if isa (x2, 'stk_dataframe') % both are stk_dataframe objects + + x2_data = x2.data; + colnames = x2.rownames; + + else + + x2_data = x2; + + if isscalar (x2) % special case + colnames = x1.colnames; + else + colnames = {}; + end + + end + +else % x2 is an stk_dataframe object, but x1 is not + + x1_data = x1; + rownames = {}; + + x2_data = x2.data; + colnames = x2.rownames; + +end + +y = stk_dataframe (x1_data / x2_data, colnames, rownames); + +end % function + + +%!test +%! x1_data = [8 7; 58 49]; +%! x1 = stk_dataframe (x1_data, {'x' 'y'}, {'a'; 'b'}); +%! x2_data = [8 7; 2 0]; +%! x2 = stk_dataframe (x2_data, {'x' 'y'}, {'u'; 'v'}); +%! y = x1 / x2; +%! assert (stk_isequal_tolabs (y, ... +%! stk_dataframe ([1 0; 7 1], {'u'; 'v'}, {'a'; 'b'}))); + + +% Special case: division by a scalar + +%!shared x_data, x, y_data, y +%! x_data = [3 3; 6 3; 9 12]; +%! y_data = [1 1; 2 1; 3 4]; +%! x = stk_dataframe (x_data, {'x' 'y'}, {'a'; 'b'; 'c'}); + +%!test y = x / 3; +%!assert (isequal (y, stk_dataframe ([1 1; 2 1; 3 4], {'x' 'y'}, {'a'; 'b'; 'c'}))); + +%!error y = 3 / x; diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/mtimes.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/mtimes.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/mtimes.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/mtimes.m 2017-09-13 07:51:00.000000000 +0000 @@ -29,19 +29,40 @@ function y = mtimes (x1, x2) if isa (x1, 'stk_dataframe') + x1_data = x1.data; rownames = x1.rownames; -else + + if isa (x2, 'stk_dataframe') % both are stk_dataframe objects + + x2_data = x2.data; + colnames = x2.colnames; + + else % x1 is an stk_dataframe object, but not x2 + + x2_data = x2; + + if isscalar (x2) % special case + colnames = x1.colnames; + else + colnames = {}; + end + + end + +else % x2 is an stk_dataframe object, but x1 is not + x1_data = x1; - rownames = {}; -end - -if isa (x2, 'stk_dataframe') + x2_data = x2.data; colnames = x2.colnames; -else - x2_data = x2; - colnames = {}; + + if isscalar (x1) % special case + rownames = x2.rownames; + else + rownames = {}; + end + end y = stk_dataframe (x1_data * x2_data, colnames, rownames); @@ -63,3 +84,15 @@ %!assert (isequal (z.data, w)); %!assert (isequal (z.rownames, x.rownames)); %!assert (isequal (z.colnames, y.colnames)); + + +% Special case: multiplication by a scalar + +%!shared x, y +%! x = stk_dataframe (rand (3, 2), {'x' 'y'}, {'a'; 'b'; 'c'}); + +%!test y = 3 * x; +%!assert (isequal (y, stk_dataframe (3 * x.data, {'x' 'y'}, {'a'; 'b'; 'c'}))); + +%!test y = x * 3; +%!assert (isequal (y, stk_dataframe (3 * x.data, {'x' 'y'}, {'a'; 'b'; 'c'}))); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/ne.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/ne.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/ne.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/ne.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,9 +2,9 @@ % Copyright Notice % -% Copyright (C) 2013 SUPELEC +% Copyright (C) 2017 CentraleSupelec % -% Author: Julien Bect +% Author: Julien Bect % Copying Permission Statement % @@ -26,12 +26,8 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function y = ne(x1, x2) +function y = ne (x1, x2) -y = bsxfun(@ne, x1, x2); +y = (double (x1) ~= double (x2)); end % function - -%!test stk_test_dfbinaryop(@ne, floor(3*rand(7, 2)), floor(3*rand(7, 2))); -%!test stk_test_dfbinaryop(@ne, floor(3*rand(7, 2)), 1.0); -%!error stk_test_dfbinaryop(@ne, floor(3*rand(7, 2)), floor(3*rand(7, 3))); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/not.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/not.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/not.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/not.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,33 @@ +% NOT [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function y = not (x) + +y = ~ logical (x); + +end % function diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/or.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/or.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/or.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/or.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,9 +2,9 @@ % Copyright Notice % -% Copyright (C) 2013 SUPELEC +% Copyright (C) 2017 CentraleSupelec % -% Author: Julien Bect +% Author: Julien Bect % Copying Permission Statement % @@ -26,12 +26,8 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function y = or(x1, x2) +function y = or (x1, x2) -y = bsxfun(@or, x1, x2); +y = (logical (x1) | logical (x2)); end % function - -%!test stk_test_dfbinaryop(@or, floor(3*rand(7, 2)), floor(3*rand(7, 2))); -%!test stk_test_dfbinaryop(@or, floor(3*rand(7, 2)), 1.0); -%!error stk_test_dfbinaryop(@or, floor(3*rand(7, 2)), floor(3*rand(7, 3))); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/plot.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/plot.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/plot.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/plot.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,7 +2,7 @@ % Copyright Notice % -% Copyright (C) 2015, 2016 CentraleSupelec +% Copyright (C) 2015-2017 CentraleSupelec % Copyright (C) 2013, 2014 SUPELEC % % Author: Julien Bect @@ -55,14 +55,14 @@ %--- Handle stk_dataframe inputs ------------------------------------------ -if isa (x, 'stk_dataframe'), +if isa (x, 'stk_dataframe') xlab = x.colnames; x = double (x); else xlab = {}; end -if isa (z, 'stk_dataframe'), +if isa (z, 'stk_dataframe') zlab = z.colnames; z = double (z); else @@ -100,17 +100,17 @@ h = plot (h_axes, x, z, S, varargin{:}); end -if ~ isempty (xlab), +if ~ isempty (xlab) if size (x, 2) == 1 - stk_xlabel (xlab{1}); + stk_xlabel (xlab{1}, 'interpreter', 'none'); % CG#10 end % Note: in the case where x has several columns (and z also) we could % create more elaborate legends, e.g., "Zj versus Xj". Another time. end if ~ isempty (zlab) - if size (z, 2) == 1, - stk_ylabel (zlab{1}); + if size (z, 2) == 1 + stk_ylabel (zlab{1}, 'interpreter', 'none'); % CG#10 else legend (zlab{:}); end @@ -151,7 +151,7 @@ % Extract axis handle (if it is present) [h_axes, varargin, n_argin] = stk_plot_getaxesarg (varargin{:}); -if n_argin == 0, +if n_argin == 0 stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); end @@ -244,11 +244,11 @@ function keyval_pairs = parse_keyval_ (key, val, varargin) -if nargin == 0, +if nargin == 0 keyval_pairs = {}; -elseif nargin == 1, +elseif nargin == 1 errmsg = 'Syntax error. Incomplete key-value pair'; stk_error (errmsg, 'NotEnoughInputArgs'); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/plotmatrix.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/plotmatrix.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/plotmatrix.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/plotmatrix.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,125 @@ +% @STK_DATAFRAME/PLOTMATRIX [overload base function] +% +% See also: plotmatrix + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function varargout = plotmatrix (varargin) + +% Parse the list of input arguments +[h_axes, x, y, linespec] = parse_args_ (varargin{:}); + +% Read x argument +if isa (x, 'stk_dataframe') + x_data = double (x); + x_colnames = x.colnames; +else + x_data = x; + x_colnames = {}; +end +nx = size (x_data, 2); + +varargout = cell (1, max (nargout, 2)); +if isempty (y) + + y_colnames = x_colnames; + ny = nx; + + [varargout{:}] = plotmatrix (h_axes, x_data, linespec{:}); + +else + + % Read y argument + if isa (y, 'stk_dataframe') + y_data = double (y); + y_colnames = y.colnames; + else + y_data = double (y); + y_colnames = {}; + end + ny = size (y_data, 2); + + [varargout{:}] = plotmatrix (h_axes, x_data, y_data, linespec{:}); + +end + +hh = varargout{2}; +varargout = varargout(1:nargout); + +if ~ isempty (x_colnames) + for i = 1:nx + stk_xlabel (hh(ny, i), x_colnames{i}, 'interpreter', 'none'); % CG#10 + end +end + +if ~ isempty (y_colnames) + for j = 1:ny + stk_ylabel (hh(j, 1), y_colnames{j}, 'interpreter', 'none'); % CG#10 + end +end + + +end % function + + +function [h_axes, x, y, linespec] = parse_args_ (varargin) + +% Extract axis handle (if it is present) +[h_axes, varargin, n_argin] = stk_plot_getaxesarg (varargin{:}); + +switch n_argin + + case 0 + stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); + + case 1 + x = varargin{1}; + y = []; + linespec = {}; + + case 2 + if ischar (varargin{2}) + x = varargin{1}; + y = []; + linespec = varargin(2); + else + x = varargin{1}; + y = varargin{2}; + linespec = {}; + end + + case 3 + x = varargin{1}; + y = varargin{2}; + linespec = varargin(3); + + otherwise + stk_error ('Too many input arguments.', 'TooManyInputArgs'); + +end % switch + +end % function diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/set_data.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/set_data.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/set_data.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/set_data.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,58 @@ +% @STK_DATAFRAME/SET_DATA [STK internal] + +% Copyright Notice +% +% Copyright (C) 2015, 2017 CentraleSupelec +% Copyright (C) 2013 SUPELEC +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function x = set_data (x, data) + +[n1, d1] = size (x.data); +[n2, d2] = size (data); +x.data = data; + +if (n1 ~= n2) && ~ isempty (x.rownames) + if n2 > n1 + % silently add rows without a name + x.rownames = [x.rownames; repmat({''}, n2 - n1, 1)]; + else + % delete superfluous row names and emit a warning + x.rownames = x.rownames(1:n2); + warning ('Some row names have been deleted.'); + end +end + +if (d1 ~= d2) && ~ isempty (x.colnames) + if d2 > d1 + % silently add columns without a name + x.colnames = [x.colnames; repmat({''}, 1, d2 - d1)]; + else + % delete superfluous column names and emit a warning + x.colnames = x.colnames(1:d2); + warning ('Some column names have been deleted.'); + end +end + +end % function diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/set.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/set.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/set.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/set.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,7 +2,7 @@ % Copyright Notice % -% Copyright (C) 2015 CentraleSupelec +% Copyright (C) 2015, 2017 CentraleSupelec % Copyright (C) 2013 SUPELEC % % Author: Julien Bect @@ -96,31 +96,7 @@ case - 1 % set entire array - [n1, d1] = size (x.data); - [n2, d2] = size (value); - x.data = value; - - if (n1 ~= n2) && ~ isempty (x.rownames) - if n2 > n1, - % silently add rows without a name - x.rownames = [x.rownames; repmat({''}, n2 - n1, 1)]; - else - % delete superfluous row names and emit a warning - x.rownames = x.rownames(1:n2); - warning ('Some row names have been deleted.'); - end - end - - if (d1 ~= d2) && ~ isempty (x.colnames) - if d2 > d1, - % silently add columns without a name - x.colnames = [x.colnames; repmat({''}, 1, d2 - d1)]; - else - % delete superfluous column names and emit a warning - x.colnames = x.colnames(1:d2); - warning ('Some column names have been deleted.'); - end - end + x = set_data (x, value); otherwise if isequal (size(value), [size(x.data, 1) 1]) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/stk_dataframe.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/stk_dataframe.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/stk_dataframe.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/stk_dataframe.m 2017-09-13 07:51:00.000000000 +0000 @@ -59,7 +59,7 @@ function x = stk_dataframe (x, colnames, rownames) -if nargin > 3, +if nargin > 3 stk_error ('Too many input arguments.', 'TooManyInputArgs'); @@ -69,66 +69,54 @@ colnames = {}; rownames = {}; -elseif strcmp (class (x), 'stk_dataframe') %#ok +elseif isa (x, 'stk_dataframe') - if nargin > 1, - - if iscell (colnames) - x = set (x, 'colnames', colnames); - elseif ~ isempty (colnames) - stk_error (['colnames should be either a cell array ' ... - 'of strings or [].'], 'InvalidArgument'); - % Note: [] means "keep x.colnames" - % while {} means "no column names" - end + if strcmp (class (x), 'stk_dataframe') %#ok - if nargin > 2 - if iscell (rownames) - x = set (x, 'rownames', rownames); - elseif ~ isempty (rownames) - stk_error (['rownames should be either a cell array ' ... + if nargin > 1 + + if iscell (colnames) + x = set (x, 'colnames', colnames); + elseif ~ isempty (colnames) + stk_error (['colnames should be either a cell array ' ... 'of strings or [].'], 'InvalidArgument'); - % Note: [] means "keep x.rownames" - % while {} means "no rownames names" + % Note: [] means "keep x.colnames" + % while {} means "no column names" + end + + if nargin > 2 + if iscell (rownames) + x = set (x, 'rownames', rownames); + elseif ~ isempty (rownames) + stk_error (['rownames should be either a cell array ' ... + 'of strings or [].'], 'InvalidArgument'); + % Note: [] means "keep x.rownames" + % while {} means "no row names" + end end end - end - - return % We already have an stk_dataframe object - -elseif isa (x, 'stk_dataframe') - - x_data = x.data; - - if nargin == 1, - colnames = x.colnames; - rownames = x.rownames; + return % We already have an stk_dataframe object - else % nargin > 1, + else % x belongs to a derived class - if (isempty (colnames)) && (~ iscell (colnames)) - colnames = x.colnames; - elseif ~ iscell (colnames) - stk_error (['colnames should be either a cell array ' ... - 'of strings or [].'], 'InvalidArgument'); - % Note: [] means "keep x.colnames" - % while {} means "no column names" - end + x_data = x.data; - if nargin == 2, + if nargin == 1 + colnames = x.colnames; rownames = x.rownames; - else % nargin > 2, + else % nargin > 1, - if (isempty (rownames)) && (~ iscell (rownames)) + % colnames = [] means "keep x.colnames" + if isempty (colnames) && ~ iscell (colnames) + colnames = x.colnames; + end + + % rownames missing or [] means "keep x.rownames" + if (nargin == 2) || (isempty (rownames) && ~ iscell (rownames)) rownames = x.rownames; - elseif ~ iscell (rownames) - stk_error (['rownames should be either a cell array ' ... - 'of strings or [].'], 'InvalidArgument'); - % Note: [] means "keep x.rownames" - % while {} means "no rownames names" end end end @@ -137,41 +125,77 @@ x_data = double (x); - if nargin < 3, + if nargin < 3 rownames = {}; - if nargin < 2, + if nargin < 2 colnames = {}; end end end -[n, d] = size (x_data); - -% Check colnames argument: must be a 1 x d cell array of strings -if ~ iscell (colnames) +if isempty (x_data) + + % Process colnames argument if isempty (colnames) + d = 0; colnames = {}; + elseif iscell (colnames) + d = numel (colnames); + colnames = reshape (colnames, 1, d); else - stk_error ('colnames should be a cell array.', 'TypeMismatch'); + stk_error ('colnames should be a cell array', 'TypeMismatch'); end -elseif (~ isempty (colnames)) && (~ isequal (size (colnames), [1 d])) - colnames = reshape (colnames, 1, d); -end - -% Check rownames argument: must be a n x 1 cell array of strings -if ~ iscell (rownames) + + % Process rownames argument if isempty (rownames) + n = 0; rownames = {}; + elseif iscell (rownames) + n = numel (rownames); + rownames = reshape (rownames, n, 1); else - stk_error ('rownames should be a cell array.', 'TypeMismatch'); + stk_error ('rownames should be a cell array', 'TypeMismatch'); end -elseif (~ isempty (rownames)) && (~ isequal (size (rownames), [n 1])) - rownames = reshape (rownames, n, 1); + + x_data = zeros (n, d); + +else + + [n, d] = size (x_data); + + % Process colnames argument + if isempty (colnames) + colnames = {}; + elseif iscell (colnames) && numel (colnames) == d + colnames = reshape (colnames, 1, d); + elseif ischar (colnames) && d == 1 + colnames = {colnames}; + else + stk_error (['colnames should be a cell array with d elements, ' ... + 'where d is the number of columns of the dataframe'], 'IncorrectSize'); + end + + % Process rownames argument + if isempty (rownames) + rownames = {}; + elseif iscell (rownames) && numel (rownames) == n + rownames = reshape (rownames, n, 1); + elseif ischar (rownames) && n == 1 + rownames = {rownames}; + else + stk_error (['rownames should be a cell array with n elements, ' ... + 'where n is the number of rows of the dataframe'], 'IncorrectSize'); + end + end -x = struct ('data', x_data, ... - 'colnames', {colnames}, 'rownames', {rownames}, 'info', ''); +x = struct (); + +x.data = x_data; +x.colnames = colnames; +x.rownames = rownames; +x.info = ''; x = class (x, 'stk_dataframe'); @@ -184,7 +208,7 @@ %!test % default constructor %! x = stk_dataframe (); -%! assert (isa (x, 'stk_dataframe') && isequal (size (x), [0 1])) +%! assert (isa (x, 'stk_dataframe') && isequal (size (x), [0 0])) %!test %! y = stk_dataframe (rand (3, 2)); @@ -276,3 +300,25 @@ %!error %! x = stk_factorialdesign ({1:3, 1:2}); %! y = stk_dataframe (x, {}, pi); + +%!test +%! x = stk_dataframe ([], {'a', 'b'}); +%! assert (isequal (size (x), [0 2])) +%! assert (isequal (x.colnames, {'a' 'b'})); +%! assert (isequal (x.rownames, {})); + +%!test +%! x = stk_dataframe ([], {'a', 'b'}, {'toto'}); +%! assert (isequal (size (x), [1 2])) +%! assert (isequal (x.colnames, {'a' 'b'})); +%! assert (isequal (x.rownames, {'toto'})); + +% Check that we tolerate char arguments for colnames/rownames + +%!test +%! x = stk_dataframe (randn (10, 1), 'NOx'); +%! assert (isequal (x.colnames, {'NOx'})); + +%!test +%! x = stk_dataframe (randn (1, 2), {}, 'aaa'); +%! assert (isequal (x.rownames, {'aaa'})); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/stk_generate_samplepaths.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/stk_generate_samplepaths.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/stk_generate_samplepaths.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/stk_generate_samplepaths.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,144 +0,0 @@ -% STK_GENERATE_SAMPLEPATHS [overload STK function] - -% Copyright Notice -% -% Copyright (C) 2015 CentraleSupelec -% Copyright (C) 2011-2014 SUPELEC -% -% Authors: Julien Bect -% Emmanuel Vazquez - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function zsim = stk_generate_samplepaths (model, varargin) - -if isa (model, 'stk_dataframe') - stk_error (['The first input argument (model) should not be an ' ... - 'stk_dataframe object'], TypeMismatch'); -end - -switch nargin, - - case {0, 1}, - stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); - - case 2, - % CALL: ZSIM = stk_generate_samplepaths (MODEL, XT) - xt = varargin{1}; - nb_paths = 1; - conditional = false; - - zsim = stk_generate_samplepaths (model, double (xt)); - - case 3, - % CALL: ZSIM = stk_generate_samplepaths (MODEL, XT, NB_PATHS) - xt = varargin{1}; - nb_paths = varargin{2}; - conditional = false; - - if isa (nb_paths, 'stk_dataframe') - nb_paths = double (nb_paths); - assert (isscalar (nb_paths)); - end - - zsim = stk_generate_samplepaths (model, double (xt), nb_paths); - - case 4, - % CALL: ZSIM = stk_generate_samplepaths (MODEL, XI, ZI, XT) - xi = varargin{1}; - zi = varargin{2}; - xt = varargin{3}; - nb_paths = 1; - conditional = true; - - zsim = stk_generate_samplepaths (model, double (xi), ... - double (zi), double (xt)); - - case 5, - % CALL: ZSIM = stk_generate_samplepaths (MODEL, XI, ZI, XT, NB_PATHS) - xi = varargin{1}; - zi = varargin{2}; - xt = varargin{3}; - nb_paths = varargin{4}; - conditional = true; - - if isa (nb_paths, 'stk_dataframe') - nb_paths = double (nb_paths); - assert (isscalar (nb_paths)); - end - - zsim = stk_generate_samplepaths (model, double (xi), ... - double (zi), double (xt), nb_paths); - - otherwise - stk_error ('Too many input arguments.', 'TooManyInputArgs'); - -end - -%--- stk_dataframe output ----------------------------------------------------- - -if isa (zsim, 'stk_dataframe') - % This case happens when model.response_name exists and contains a - % non-empty string. - - if conditional && (isa (zi, 'stk_dataframe')) ... - && (~ isempty (zi.colnames)) ... - && (~ strcmp (model.response_name, zi.colnames)) - % colnames are different: don't use any - zsim.colnames = {}; - end - - try - zsim.rownames = xt.rownames; - catch - zsim.rownames = {}; - end - -else % model.response name does not exist or is empty - - try - rownames = xt.rownames; - catch - rownames = {}; - end - - try - response_name = zi.colnames{1}; - assert (numel (zi.colnames) == 1); - assert ((~ isempty (response_name)) && (ischar (response_name))); - if nb_paths == 1, - colnames = {response_name}; - else - colnames = arrayfun ( ... - @(i)(sprintf ('%s_%d', response_name, i)), ... - 1:nb_paths, 'UniformOutput', false); - end - catch - colnames = {}; - end - - zsim = stk_dataframe (zsim, colnames, rownames); - -end - -end % function - -%#ok<*CTCH> diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/stk_sprintf.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/stk_sprintf.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/stk_sprintf.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/stk_sprintf.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,7 +2,7 @@ % Copyright Notice % -% Copyright (C) 2015 CentraleSupelec +% Copyright (C) 2015, 2017 CentraleSupelec % Copyright (C) 2013, 2014 SUPELEC % % Authors: Julien Bect @@ -30,28 +30,63 @@ function s = stk_sprintf (x, verbosity, data_col_width) -if (nargin < 2) || (isempty (verbosity)), +if (nargin < 2) || (isempty (verbosity)) verbosity = stk_options_get ('stk_dataframe', 'disp_format'); end + if ~ ismember (verbosity, {'basic', 'verbose'}) errmsg = 'verbosity should be ''basic'' or ''verbose''.'; stk_error (errmsg, 'InvalidArgument'); end -if (nargin < 3) || (isempty (data_col_width)), +if (nargin < 3) || (isempty (data_col_width)) data_col_width = []; end -s = sprintf_table_ (x.data, x.colnames, x.rownames, data_col_width); - -if strcmp (verbosity, 'verbose'), +if isempty (x) spstr = stk_options_get ('stk_dataframe', 'disp_spstr'); - s = char (... - '.colnames =', horzcat (spstr, stk_sprintf_colnames (x)), ... - '.rownames =', horzcat (spstr, stk_sprintf_rownames (x)), ... - '.data =', horzcat (repmat (spstr, size (s, 1), 1), s)); + if strcmp (verbosity, 'verbose') + + s = char (... + '.colnames =', horzcat (spstr, stk_sprintf_colnames (x)), ... + '.rownames =', horzcat (spstr, stk_sprintf_rownames (x)), ... + '.data =', horzcat (spstr, '<', stk_sprintf_sizetype (x.data), '>')); + + else + + [n, d] = size (x); + + s = sprintf ('Empty data frame with %d rows and %d columns', n, d); + + if d > 0 && ~ isempty (x.colnames) + s = char (s, ... + sprintf (' with .colnames = %s', stk_sprintf_colnames (x))); + elseif n > 0 && ~ isempty (x.rownames) + s = char (s, ... + sprintf (' with .rownames = %s', stk_sprintf_rownames (x))); + end + end + +else % x is not empty + + s = sprintf_table_ (x.data, x.colnames, x.rownames, data_col_width); + + if strcmp (verbosity, 'verbose') + + spstr = stk_options_get ('stk_dataframe', 'disp_spstr'); + + s = char (... + '.colnames =', horzcat (spstr, stk_sprintf_colnames (x)), ... + '.rownames =', horzcat (spstr, stk_sprintf_rownames (x)), ... + '.data =', horzcat (repmat (spstr, size (s, 1), 1), s)); + + elseif isempty (s) + + disp toto + + end end @@ -72,19 +107,14 @@ else if (nargin < 2) || isempty (data_col_width) - try - switch get (0, 'Format') - case 'short' - data_col_width = 8; - case 'long' - data_col_width = 16; - otherwise - % FIXME: handle other formatting modes... - data_col_width = 8; - end - catch - % Property 'Format' doesn't exist in Octave 3.2.x - data_col_width = 8; + switch stk_disp_getformat () + case 'short' + data_col_width = 8; + case 'long' + data_col_width = 16; + otherwise + % FIXME: handle other formatting modes... + data_col_width = 8; end end @@ -114,13 +144,13 @@ s = [s repmat(' :', nb_rows, 1) ... repmat(' ', nb_rows, nb_spaces_colsep)]; - for j = 1:d, + for j = 1:d xx = stk_sprintf_colvect (x(:, j), data_col_width); Lxx = size (xx, 2); vn = colnames{j}; - if isempty (vn), + if isempty (vn) vn = repmat('-', 1, Lxx); end @@ -128,7 +158,7 @@ s = [s [sprintf('% *s', L, vn); % variable name repmat(' ', n, L - Lxx) xx]]; % formatted data - if j < d, + if j < d % column separator s = [s repmat(' ', nb_rows, nb_spaces_colsep)]; end @@ -141,17 +171,12 @@ %!shared x, fmt -%! try % doesn't work on old Octave versions, nevermind -%! fmt = get (0, 'Format'); -%! catch -%! fmt = nan; -%! end +%! fmt = stk_disp_getformat (); %! x = stk_dataframe (rand (3, 2)); -%!test format rat; disp (x); -%!test format long; disp (x); -%!test format short; disp (x); -%! if ~isnan (fmt), set (0, 'Format', fmt); end +%!test format rat; disp (x); +%!test format long; disp (x); +%!test format short; disp (x); format (fmt); %!test disp (stk_dataframe (zeros (0, 1))) %!test disp (stk_dataframe (zeros (0, 2))) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/subsasgn.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/subsasgn.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/subsasgn.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/subsasgn.m 2017-09-13 07:51:00.000000000 +0000 @@ -42,17 +42,6 @@ return end -if all (builtin ('size', x) == 0) - % This happens in Octave 3.2.x when doing B(idx) = D if B does not exist and - % D is an stk_dataframe. In this case, x is a corrupted stk_dataframe object - % with underlying structure of size 0x0... - % The following hack should be sufficient to let repmat (x, ...) work - % when x is a scalar stk_dataframe (but row and column names will be lost): - x_data = subsasgn ([], idx, val.data); - x = stk_dataframe (x_data); - return -end - switch idx(1).type case '()' @@ -73,7 +62,7 @@ val_data = double (val); - if L == 2, % matrix-style indexing + if L == 2 % matrix-style indexing % Process row indices I = idx(1).subs{1}; @@ -101,7 +90,7 @@ x.data = subsasgn (x.data, idx, val_data); - if L == 1, % linear indexing + if L == 1 % linear indexing % Linear indexing is not allowed to change the shape of a % dataframe (this happens, with numeric arrays, when @@ -169,13 +158,13 @@ else % Assignment rhs is empty: deletion - if L == 1, % Linear indexing + if L == 1 % Linear indexing - if d == 1, % Column array => remove rows + if d == 1 % Column array => remove rows I = idx(1).subs{1}; J = 1; remove_rows = true; - elseif n == 1, % Row array => remove columns + elseif n == 1 % Row array => remove columns I = 1; J = idx(1).subs{1}; remove_rows = false; @@ -217,7 +206,7 @@ case '.' - if strcmp (idx(1).subs, 'data') && length (idx) > 1, + if strcmp (idx(1).subs, 'data') && length (idx) > 1 if strcmp (idx(2).type, '()') x = subsasgn (x, idx(2:end), val); @@ -239,47 +228,48 @@ end % function + %!shared x, s, t, data -%! x = stk_dataframe(rand(3, 2)); +%! x = stk_dataframe (rand (3, 2)); %! s = {'a'; 'b'; 'c'}; %! t = {'xx' 'yy'}; %!test %! x.rownames = s; -%! assert (isequal(get(x, 'rownames'), s)) +%! assert (isequal (get (x, 'rownames'), s)) %!test %! x.colnames = t; -%! assert (isequal(get(x, 'rownames'), s)) -%! assert (isequal(get(x, 'colnames'), t)) +%! assert (isequal (get (x, 'rownames'), s)) +%! assert (isequal (get (x, 'colnames'), t)) %!test %! x.rownames{2} = 'dudule'; -%! assert (isequal(get(x, 'rownames'), {'a'; 'dudule'; 'c'})) -%! assert (isequal(get(x, 'colnames'), t)) +%! assert (isequal (get (x, 'rownames'), {'a'; 'dudule'; 'c'})) +%! assert (isequal (get (x, 'colnames'), t)) %!test %! x.colnames{1} = 'martha'; -%! assert (isequal(get(x, 'rownames'), {'a'; 'dudule'; 'c'})) -%! assert (isequal(get(x, 'colnames'), {'martha' 'yy'})) +%! assert (isequal (get (x, 'rownames'), {'a'; 'dudule'; 'c'})) +%! assert (isequal (get (x, 'colnames'), {'martha' 'yy'})) % %!error x.colnames{1} = 'yy' % %!error x.colnames = {'xx' 'xx'} %!test -%! data = stk_dataframe(zeros(3, 2), {'x1' 'x2'}); -%! u = rand(3, 1); data.x2 = u; -%! assert (isequal(double(data), [zeros(3, 1) u])) +%! data = stk_dataframe (zeros(3, 2), {'x1' 'x2'}); +%! u = rand(3, 1); data.x2 = u; +%! assert (isequal (double (data), [zeros(3, 1) u])) %!test -%! data = stk_dataframe(zeros(3, 2), {'x1' 'x2'}); +%! data = stk_dataframe (zeros (3, 2), {'x1' 'x2'}); %! data.x2(3) = 27; -%! assert (isequal(double(data), [0 0; 0 0; 0 27])) +%! assert (isequal (double (data), [0 0; 0 0; 0 27])) -%!error data.toto = rand(3, 1); +%!error data.toto = rand (3, 1); %!shared x -%! x = stk_dataframe(reshape(1:12, 4, 3), {'u' 'v' 'w'}); +%! x = stk_dataframe (reshape (1:12, 4, 3), {'u' 'v' 'w'}); %!test %! x(:, 2) = []; @@ -404,7 +394,7 @@ %! assert (isequal (z(1, :), x(1, :))); %! assert (isequal (z(3, :), y)); -%--- change several values at once with linear indxing ------------------------- +%--- change several values at once with linear indexing ------------------------ %!shared x %! x = stk_dataframe (zeros (2), {'u' 'v'}); @@ -421,3 +411,14 @@ %!error % too many elements %! x(1:5) = 3; + +%--- add just one row/column name ---------------------------------------------- + +%!shared x +%! x = stk_dataframe (randn (3, 3)); + +%!test x.colnames{2} = 'y'; +%!assert (isequal (x.colnames, {'' 'y' ''})); + +%!test x.rownames{2} = 'b'; +%!assert (isequal (x.rownames, {''; 'b'; ''})); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/subsref.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/subsref.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/subsref.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/subsref.m 2017-09-13 07:51:00.000000000 +0000 @@ -35,11 +35,11 @@ L = length (idx(1).subs); - if L == 1, % linear indexing + if L == 1 % linear indexing t = subsref (x.data, idx); - elseif L == 2, % matrix-style indexing + elseif L == 2 % matrix-style indexing % Process row indices I = idx(1).subs{1}; @@ -57,16 +57,36 @@ J = process_cell_indices (J, x.colnames, 'Column'); end - t = stk_dataframe (x.data(I, J)); + if isempty (I) + if isempty (J) + t_data = []; + else + t_data = zeros (0, size (x.data, 2)); + t_data = t_data(:, J); + end + else + if isempty (J) + t_data = zeros (size (x.data, 1), 0); + t_data = t_data(I, :); + else + t_data = x.data(I, J); + end + end - if ~ isempty (x.colnames) - t.colnames = x.colnames(1, J); + if isempty (x.colnames) + cn = {}; + else + cn = x.colnames(1, J); end - if ~ isempty (x.rownames) - t.rownames = x.rownames(I, 1); + if isempty (x.rownames) + rn = {}; + else + rn = x.rownames(I, 1); end + t = stk_dataframe (t_data, cn, rn); + else stk_error ('Illegal indexing.', 'IllegalIndexing'); end @@ -82,7 +102,7 @@ end -if (length (idx)) > 1, +if (length (idx)) > 1 t = subsref (t, idx(2:end)); end @@ -118,14 +138,6 @@ %!error t = data(1, 1, 1); % too many indices %!error t = data{1}; % curly braces not allowed -%!test % legacy feature: data.a returns the 'mean' column if it exists -%! data = set(data, 'colnames', {'mean', 'x2'}); -%! assert(isequal(data.a, u(:, 1))); - -%!test % legacy feature: data.a returns the whole dataframe otherwise -%! data = set(data, 'colnames', {'x1', 'x2'}); -%! assert(isequal(data.a, u)); - %!test % select rows and columns %! x = stk_dataframe (reshape (1:15, 5, 3), {'u' 'v' 'w'}); %! assert (isequal (x([3 5], 2), stk_dataframe ([8; 10], {'v'}))); @@ -140,3 +152,19 @@ %!assert (isequal (double (data(2)), u(2))) %!assert (isequal (double (data(3, 1)), u(3))) %!error t = data(1, 1, 1); % too many indices + +%--- empty indexing ------------------------------------------------------------ + +%!test +%! x = stk_dataframe (randn (2, 2), {'u' 'v'}); +%! y = x ([], :); +%! assert (isa (y, 'stk_dataframe')); +%! assert (isequal (size (y), [0 2])); +%! assert (isequal (y.colnames, {'u' 'v'})); + +%!test +%! x = stk_dataframe (randn (2, 2), [], {'a' 'b'}); +%! y = x (:, []); +%! assert (isa (y, 'stk_dataframe')); +%! assert (isequal (size (y), [2 0])); +%! assert (isequal (y.rownames, {'a'; 'b'})); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/vertcat.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/vertcat.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/vertcat.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/vertcat.m 2017-09-13 07:51:00.000000000 +0000 @@ -196,12 +196,12 @@ %!shared x, y %! x = stk_dataframe (rand (2, 3), {'a', 'b', 'c'}); %! y = stk_dataframe (rand (3, 2), {'a', 'b'}); -%! y = [y rand(3, 1)]; +%! y = horzcat (y, rand(3, 1)); % last column name is missing %!test -%! z = [x; y]; +%! z = vertcat (x, y); %! assert (isequal (z.colnames, {'a' 'b' 'c'})) %!test -%! z = [y; x]; +%! z = vertcat (y, x); %! assert (isequal (z.colnames, {'a' 'b' 'c'})) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_dataframe/xor.m octave-stk-2.5.0/inst/arrays/@stk_dataframe/xor.m --- octave-stk-2.4.2/inst/arrays/@stk_dataframe/xor.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_dataframe/xor.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,9 +2,9 @@ % Copyright Notice % -% Copyright (C) 2013 SUPELEC +% Copyright (C) 2017 CentraleSupelec % -% Author: Julien Bect +% Author: Julien Bect % Copying Permission Statement % @@ -26,17 +26,8 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function y = xor(x1, x2) +function y = xor (x1, x2) -y = bsxfun(@xor, x1, x2); +y = xor (logical (x1), logical (x2)); end % function - -%!shared x, y, z -%! x = floor (3 * rand (7, 2)); -%! y = floor (3 * rand (7, 2)); -%! z = floor (3 * rand (7, 3)); - -%!test stk_test_dfbinaryop ('xor', x, y); -%!test stk_test_dfbinaryop ('xor', x, 1.0); -%!error stk_test_dfbinaryop ('xor', x, z); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/ismember.m octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/ismember.m --- octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/ismember.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/ismember.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,108 @@ +% ISMEMBER [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function varargout = ismember (A, B, varargin) + +if ~ all (cellfun (@ischar, varargin)) + stk_error ('Invalid flag (should be a string).', 'InvalidArgument'); +end + +if isa (A, 'stk_factorialdesign') + + varargout = cell (1, max (nargout, 1)); + [varargout{:}] = ismember (double (A), B, varargin{:}); + +else % B is an stk_factorialdesign object + + has_rows = false; + has_legacy = false; + + for k = 1:(numel (varargin)) + switch varargin{k} + case 'rows' + has_rows = true; + case 'legacy' + has_legacy = true; + otherwise + errmsg = sprintf ('Unknown flag: %s', varargin{k}); + stk_error (errmsg, 'InvalidArgument'); + end + end + + if has_rows && ~ has_legacy && (nargout < 2) % This case can be optimized + + lia = ismember_fd (A, B); + varargout = {lia}; + + else % otherwise, use the base ismember function + + varargout = cell (1, max (nargout, 1)); + [varargout{:}] = ismember (A, double (B), varargin{:}); + + end + +end + +end % function + + +function [lia, locb] = ismember_fd (A, B) + +[n, dim] = size (A); +if dim ~= length (B.levels) + stk_error (['A and B should have the same number ' ... + 'of columns'], 'InvalidArgument'); +end + +b = false (n, dim); +for j = 1:dim + b(:, j) = ismember (A(:, j), B.levels{j}); +end + +lia = all (b, 2); + +end % function + + +%!shared A, B, BB, b +%! +%! i_max = 10; n = 100; d = 5; +%! +%! A = randi (i_max, n, d); +%! +%! levels = repmat ({1:i_max}, 1, d); +%! levels{4} = 1:2:i_max; +%! B = stk_factorialdesign (levels); +%! +%! BB = double (B); + +%!test b = ismember (A, B); +%!assert (isequal (b, ismember (A, BB))); + +%!test b = ismember (A, B, 'rows'); +%!assert (isequal (b, ismember (A, BB, 'rows'))); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/private/plot_surfmeshcontour.m octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/private/plot_surfmeshcontour.m --- octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/private/plot_surfmeshcontour.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/private/plot_surfmeshcontour.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,7 +2,7 @@ % Copyright Notice % -% Copyright (C) 2016 CentraleSupelec +% Copyright (C) 2016, 2017 CentraleSupelec % Copyright (C) 2013 Valentin Resseguier % Copyright (C) 2012-2014 SUPELEC % @@ -50,15 +50,15 @@ % Create labels if x provides column names c = get (x.stk_dataframe, 'colnames'); -if ~ isempty (c), - stk_xlabel (h_axes, c{1}); +if ~ isempty (c) + stk_xlabel (h_axes, c{1}, 'interpreter', 'none'); % CG#10 end -if length (c) > 1, - stk_ylabel (h_axes, c{2}); +if length (c) > 1 + stk_ylabel (h_axes, c{2}, 'interpreter', 'none'); % CG#10 end % Use interpolated shading for surf and pcolor plots -if ismember (func2str (plotfun), {'surf', 'pcolor'}), +if ismember (func2str (plotfun), {'surf', 'pcolor'}) shading (h_axes, 'interp'); end @@ -85,7 +85,7 @@ % Extract axis handle (if it is present) [h_axes, varargin, n_argin] = stk_plot_getaxesarg (varargin{:}); -if n_argin < 2, +if n_argin < 2 stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); end @@ -94,16 +94,16 @@ opts = varargin(3:end); % Then, x must be an stk_factorialdesign object -if ~ isa (x, 'stk_factorialdesign'), +if ~ isa (x, 'stk_factorialdesign') stk_error (['The first input argument should be a handle to existing' ... 'axes or and stk_factorialdesign object.'], 'TypeMismatch'); end dim = size (x, 2); -if dim ~= 2, +if dim ~= 2 errmsg = 'Only works for two-dimensional factor spaces.'; - stk_error (errmsg, 'IncorrectArgument'); + stk_error (errmsg, 'InvalidArgument'); end end % function @@ -121,8 +121,8 @@ % in particular when options are provided. Let's try that first. if strcmp (func2str (plotfun), 'contour') - [C_ignored, h_plot] = contour ... - (h_axes, x, y, z, varargin{:}); %#ok + [ignd, h_plot] = contour ... + (h_axes, x, y, z, varargin{:}); %#ok CG#07 else h_plot = plotfun (h_axes, x, y, z, varargin{:}); end @@ -149,7 +149,7 @@ try if strcmp (func2str (plotfun), 'contour') - [C_ignored, h_plot] = contour (x, y, z, numarg{:}); %#ok + [ignd, h_plot] = contour (x, y, z, numarg{:}); %#ok CG#07 else h_plot = plotfun (x, y, z, numarg{:}); end diff -Nru octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/set.m octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/set.m --- octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/set.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/set.m 2017-09-13 07:51:00.000000000 +0000 @@ -37,7 +37,7 @@ % x = stk_factorialdesign (value); % to preserve the value of the other fields (info, colnames, ...). tmp = stk_factorialdesign (value); - x = set (df, 'data', tmp.data); + x = set_data (df, tmp.data); case 'stk_dataframe', errmsg = 'Field .stk_dataframe is read-only.'; diff -Nru octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/stk_boundingbox.m octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/stk_boundingbox.m --- octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/stk_boundingbox.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/stk_boundingbox.m 2017-09-13 07:51:00.000000000 +0000 @@ -28,13 +28,17 @@ function box = stk_boundingbox (x) -if nargin > 1, +if nargin > 1 stk_error ('Too many input arguments.', 'TooManyInputArgs'); end xmin = cellfun (@min, x.levels); xmax = cellfun (@max, x.levels); +dim = numel (xmin); +xmin = reshape (xmin, 1, dim); +xmax = reshape (xmax, 1, dim); + box = stk_hrect ([xmin; xmax]); box.colnames = x.stk_dataframe.colnames; diff -Nru octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/stk_dataframe.m octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/stk_dataframe.m --- octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/stk_dataframe.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/stk_dataframe.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,90 @@ +% @STK_FACTORIALDESIGN/STK_DATAFRAME [overload STK function] +% +% See also: stk_dataframe + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function x = stk_dataframe (x, colnames, rownames) + +x = x.stk_dataframe; + +if nargin > 1 + + % Note: [] means "keep x.colnames" while {} means "no column names" + if iscell (colnames) + x = set (x, 'colnames', colnames); + elseif ~ isempty (colnames) + stk_error (['colnames should be either a cell array ' ... + 'of strings or [].'], 'InvalidArgument'); + end + + if nargin > 2 + + % Note: [] means "keep x.rownames" while {} means "no row names" + if iscell (rownames) + x = set (x, 'rownames', rownames); + elseif ~ isempty (rownames) + stk_error (['rownames should be either a cell array ' ... + 'of strings or [].'], 'InvalidArgument'); + end + end + +end + +end % function + +%!shared x, cn, rn, y, cn2, rn2 +%! cn = {'x' 'y'}; +%! rn = {'a'; 'b'; 'c'; 'd'}; +%! x = stk_factorialdesign ({1:2, 1:2}, cn, rn); +%! cn2 = {'xx' 'yy'}; +%! rn2 = {'aa'; 'bb'; 'cc'; 'dd'}; + +%!test y = stk_dataframe (x); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, cn)) +%!assert (isequal (y.rownames, rn)) + +%!test y = stk_dataframe (x, cn2); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, cn2)) +%!assert (isequal (y.rownames, rn)) + +%!test y = stk_dataframe (x, cn2, rn2); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, cn2)) +%!assert (isequal (y.rownames, rn2)) + +%!test y = stk_dataframe (x, [], rn2); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, cn)) +%!assert (isequal (y.rownames, rn2)) + +%!test y = stk_dataframe (x, {}, rn2); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, {})) +%!assert (isequal (y.rownames, rn2)) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/stk_factorialdesign.m octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/stk_factorialdesign.m --- octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/stk_factorialdesign.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/stk_factorialdesign.m 2017-09-13 07:51:00.000000000 +0000 @@ -27,60 +27,90 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function x = stk_factorialdesign(levels, varargin) +function x = stk_factorialdesign (levels, varargin) -if nargin == 0 % default constructor +if nargin == 0 % default constructor levels = {[]}; end -% number of factors -d = length(levels); - -if ~iscell(levels) || (numel(levels) ~= d) +if ~ iscell (levels) - errmsg = 'Expecting a "flat" cell array as first argument.'; - stk_error(errmsg, 'TypeMismatch'); + stk_error ('Expecting a cell array as first argument', 'TypeMismatch'); else - if ~all(cellfun(@isnumeric, levels)) - - errmsg = 'Only numeric factors are currently supported.'; - stk_error(errmsg, 'TypeMismatch'); + % Guess the number of factors from the length of the cell array + dim = length (levels); + + % Extract raw factor data and column names (when they are available) + raw_levels = cell (1, dim); + raw_levels_anyempty = false; + colnames = cell (1, dim); + colnames_allempty = true; + for i = 1:dim + li = levels{i}; + + if isa (li, 'stk_dataframe') + assert (size (li, 2) == 1); + cn = get (li, 'colnames'); + if isempty (cn) + colnames{i} = ''; + else + colnames(i) = cn; + end + raw_levels{i} = double (li); + elseif isnumeric (li) + colnames{i} = ''; + raw_levels{i} = double (li(:)); + levels{i} = raw_levels{i}; + else + errmsg = 'Only numeric factors are currently supported.'; + stk_error (errmsg, 'TypeMismatch'); + end - else % ok, numeric levels, we know how to handle that + if isempty (raw_levels{i}) + raw_levels_anyempty = true; + end - if (d == 0) || any(cellfun(@isempty, levels)) - - xdata = zeros(0, d); - - elseif d == 1 - - xdata = levels{1}(:); - - else - - % coordinate arrays - coord = cell(1, d); - [coord{:}] = ndgrid(levels{:}); - - % design matrix - xdata = zeros(numel(coord{1}), d); - for j = 1:d, - xdata(:, j) = coord{j}(:); - end - + if ~ isempty (colnames{i}) + colnames_allempty = false; end + end + + if (dim == 0) || raw_levels_anyempty - % base dataframe - df = stk_dataframe (xdata, varargin{:}); - df = set (df, 'info', 'Created by stk_factorialdesign'); - - % "factorial design" object - x = struct ('levels', {levels}); - x = class (x, 'stk_factorialdesign', df); + xdata = zeros (0, dim); - end % if + elseif dim == 1 + + xdata = raw_levels{1}; + + else + + % coordinate arrays + coord = cell (1, dim); + [coord{:}] = ndgrid (raw_levels{:}); + + % design matrix + xdata = zeros (numel (coord{1}), dim); + for j = 1:dim + xdata(:, j) = coord{j}(:); + end + + end + + % base dataframe + df = stk_dataframe (xdata, varargin{:}); + df = set (df, 'info', 'Created by stk_factorialdesign'); + + % column names ? + if isempty (get (df, 'colnames')) && ~ colnames_allempty + df = set (df, 'colnames', colnames); + end + + % "factorial design" object + x = struct (); x.levels = levels; + x = class (x, 'stk_factorialdesign', df); end % if @@ -98,7 +128,6 @@ % tests some incorrect values for 'levels' %!error stk_factorialdesign ('bouh'); -%!error stk_factorialdesign (repmat ({[0 1]}, 2, 2)); % categorical variable not supported yet %!error stk_factorialdesign ({{'a' 'b'}}); @@ -106,17 +135,12 @@ %--- disp & display ----------------------------------------------------------- %!shared x, fmt -%! try % doesn't work on old Octave versions, nevermind -%! fmt = get (0, 'Format'); -%! catch -%! fmt = nan; -%! end +%! fmt = stk_disp_getformat (); %! x = stk_sampling_regulargrid (3^2, 2); %!test format rat; disp (x); %!test format long; disp (x); -%!test format short; disp (x); -%! if ~ isnan (fmt), set (0, 'Format', fmt); end +%!test format short; disp (x); format (fmt); %!test disp (stk_sampling_regulargrid (0^1, 1)); %!test disp (stk_sampling_regulargrid (0^2, 2)); diff -Nru octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/subsasgn.m octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/subsasgn.m --- octave-stk-2.4.2/inst/arrays/@stk_factorialdesign/subsasgn.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_factorialdesign/subsasgn.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,6 +2,7 @@ % Copyright Notice % +% Copyright (C) 2017 CentraleSupelec % Copyright (C) 2014 SUPELEC % % Author: Julien Bect @@ -35,13 +36,6 @@ return end -if all (builtin ('size', x) == 0) - % This happens in Octave 3.2.x when doing B(idx) = D if B does not - % exist and D is an stk_factorialdesign object. In this case, x is an - % UNITIALIZED 0x0 stk_factorialdesign object. We have to initialize it. - x = stk_factorialdesign (); -end - switch idx(1).type case '()' diff -Nru octave-stk-2.4.2/inst/arrays/@stk_hrect/axis.m octave-stk-2.5.0/inst/arrays/@stk_hrect/axis.m --- octave-stk-2.4.2/inst/arrays/@stk_hrect/axis.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_hrect/axis.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,7 +2,7 @@ % Copyright Notice % -% Copyright (C) 2016 CentraleSupelec +% Copyright (C) 2016, 2017 CentraleSupelec % Copyright (C) 2014 SUPELEC % % Author: Julien Bect @@ -34,7 +34,7 @@ varargout = cell (1, nargout); labels = {}; -for i = 1:nargin, +for i = 1:nargin a = varargin{i}; if isa (a, 'stk_hrect') df = a.stk_dataframe; @@ -60,10 +60,10 @@ % Add labels if available if (~ isempty (labels)) - stk_xlabel (h_axes, labels{1}); - stk_ylabel (h_axes, labels{2}); + stk_xlabel (h_axes, labels{1}, 'interpreter', 'none'); % CG#10 + stk_ylabel (h_axes, labels{2}, 'interpreter', 'none'); % CG#10 if (length (labels) > 2) - stk_zlabel (h_axes, labels{3}); + stk_zlabel (h_axes, labels{3}, 'interpreter', 'none'); % CG#10 end end diff -Nru octave-stk-2.4.2/inst/arrays/@stk_hrect/stk_dataframe.m octave-stk-2.5.0/inst/arrays/@stk_hrect/stk_dataframe.m --- octave-stk-2.4.2/inst/arrays/@stk_hrect/stk_dataframe.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_hrect/stk_dataframe.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,91 @@ +% @STK_HRECT/STK_DATAFRAME [overload STK function] +% +% See also: stk_dataframe + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function x = stk_dataframe (x, colnames, rownames) + +x = x.stk_dataframe; + +if nargin > 1 + + % Note: [] means "keep x.colnames" while {} means "no column names" + if iscell (colnames) + x = set (x, 'colnames', colnames); + elseif ~ isempty (colnames) + stk_error (['colnames should be either a cell array ' ... + 'of strings or [].'], 'InvalidArgument'); + end + + if nargin > 2 + + % Note: [] means "keep x.rownames" while {} means "no row names" + if iscell (rownames) + x = set (x, 'rownames', rownames); + elseif ~ isempty (rownames) + stk_error (['rownames should be either a cell array ' ... + 'of strings or [].'], 'InvalidArgument'); + end + end + +end + +end % function + + +%!shared x, cn, rn, y, cn2, rn2 +%! cn = {'x' 'y'}; +%! rn = {'lower_bounds'; 'upper_bounds'}; +%! x = stk_hrect ([0 0; 1 1], cn); +%! cn2 = {'xx' 'yy'}; +%! rn2 = {'aa'; 'bb'}; + +%!test y = stk_dataframe (x); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, cn)) +%!assert (isequal (y.rownames, rn)) + +%!test y = stk_dataframe (x, cn2); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, cn2)) +%!assert (isequal (y.rownames, rn)) + +%!test y = stk_dataframe (x, cn2, rn2); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, cn2)) +%!assert (isequal (y.rownames, rn2)) + +%!test y = stk_dataframe (x, [], rn2); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, cn)) +%!assert (isequal (y.rownames, rn2)) + +%!test y = stk_dataframe (x, {}, rn2); +%!assert (strcmp (class (y), 'stk_dataframe')) +%!assert (isequal (y.colnames, {})) +%!assert (isequal (y.rownames, rn2)) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_hrect/stk_hrect.m octave-stk-2.5.0/inst/arrays/@stk_hrect/stk_hrect.m --- octave-stk-2.4.2/inst/arrays/@stk_hrect/stk_hrect.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_hrect/stk_hrect.m 2017-09-13 07:51:00.000000000 +0000 @@ -50,7 +50,7 @@ function s = stk_hrect (arg1, colnames) -if nargin > 2, +if nargin > 2 stk_error ('Too many input arguments.', 'TooManyInputArgs'); @@ -72,11 +72,22 @@ if (prod (size (arg1)) == 1) % arg1 is the dimension of the input space % => create a default hyper-rectangle [0; 1]^d, with d = arg1 + d = arg1; box_data = repmat ([0; 1], 1, d); + box_colnames = {}; + else + + if isa (arg1, 'stk_dataframe') + box_colnames = get (arg1, 'colnames'); + else + box_colnames = {}; + end + box_data = double (arg1); d = size (box_data, 2); + if (~ isequal (size (box_data), [2 d])) stk_error ('Invalid size: should be 2 x dim.', 'IncorrectSize'); end @@ -86,7 +97,8 @@ stk_error ('Invalid bounds', 'InvalidBounds'); end - df = stk_dataframe (box_data, {}, {'lower_bounds', 'upper_bounds'}); + df = stk_dataframe (box_data, ... + box_colnames, {'lower_bounds', 'upper_bounds'}); s = class (struct (), 'stk_hrect', df); end @@ -98,5 +110,13 @@ end % function +%#ok<*PSIZE> + %!test stk_test_class ('stk_hrect') + +%!shared dom +%!test dom = stk_hrect ([-1; 1], {'x'}); +%!assert (isequal (dom.colnames, {'x'})) +%!assert (isequal (dom.rownames, {'lower_bounds'; 'upper_bounds'})) +%!assert (isequal (dom.data, [-1; 1])) diff -Nru octave-stk-2.4.2/inst/arrays/@stk_hrect/stk_rescale.m octave-stk-2.5.0/inst/arrays/@stk_hrect/stk_rescale.m --- octave-stk-2.4.2/inst/arrays/@stk_hrect/stk_rescale.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_hrect/stk_rescale.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,6 +2,7 @@ % Copyright Notice % +% Copyright (C) 2017 CentraleSupelec % Copyright (C) 2012-2014 SUPELEC % % Author: Julien Bect @@ -28,7 +29,7 @@ function [x, a, b] = stk_rescale (x, box1, box2) -if nargin > 3, +if nargin > 3 stk_error ('Too many input arguments.', 'TooManyInputArgs'); end @@ -36,53 +37,70 @@ x_data = double (x); d = size (x_data, 2); -% Ensure that box1 is an stk_hrect object -if ~ isa (box1, 'stk_hrect') - if isempty (box1) - box1 = stk_hrect (d); % Default: [0; 1] ^ DIM - else - box1 = stk_hrect (box1); +box1_data = double (box1); + +if isempty (box1_data) + + % Speed up the case where box1 is empty + b1 = 1; + a1 = 0; + +else + + % Ensure that box1 is an stk_hrect object, or can be converted to one + % (note: this checks that lower bounds are smaller than upper bounds) + if ~ isa (box1, 'stk_hrect') + box1 = stk_hrect (box1); %#ok + end + + % Check the number of columns + if size (box1_data, 2) ~= d + errmsg = sprintf ('box1 should have size [2 d], with d=%d.', d); + stk_error (errmsg, 'IncorrectSize'); end + + % Scale to [0; 1] (xx --> zz) + xmin = box1_data(1, :); + xmax = box1_data(2, :); + b1 = 1 ./ (xmax - xmin); + a1 = - xmin .* b1; + end -% Extract lower/upper bounds for box1 -box1_data = double (box1.stk_dataframe); -if ~ isequal (size (box1_data), [2 d]) - errmsg = sprintf ('box1 should have size [2 d], with d=%d.', d); - stk_error (errmsg, 'IncorrectSize'); -end +box2_data = double (box2); -% Ensure that box2 is an stk_hrect object -if ~ isa (box2, 'stk_hrect') - if isempty (box2) - box2 = stk_hrect (d); % [0; 1] ^ d - else - box2 = stk_hrect (box2); +if isempty (box2_data) + + % Speed up the case where box2 is empty + b2 = 1; + a2 = 0; + +else + + % Ensure that box2 is an stk_hrect object, or can be converted to one + % (note: this checks that lower bounds are smaller than upper bounds) + if ~ isa (box2, 'stk_hrect') + box2 = stk_hrect (box2); %#ok end + + % Check the number of columns + if size (box2_data, 2) ~= d + errmsg = sprintf ('box2 should have size [2 d], with d=%d.', d); + stk_error (errmsg, 'IncorrectSize'); + end + + % scale to box2 (zz --> yy) + ymin = box2_data(1, :); + ymax = box2_data(2, :); + b2 = ymax - ymin; + a2 = ymin; + end -% Extract lower/upper bounds for box2 -box2_data = double (box2.stk_dataframe); -if ~ isequal (size (box2_data), [2 d]) - errmsg = sprintf ('box2 should have size [2 d], with d=%d.', d); - stk_error (errmsg, 'IncorrectSize'); -end - -% Scale to [0; 1] (xx --> zz) -xmin = box1_data(1, :); -xmax = box1_data(2, :); -b1 = 1 ./ (xmax - xmin); -a1 = - xmin .* b1; - -% scale to box2 (zz --> yy) -ymin = box2_data(1, :); -ymax = box2_data(2, :); -b2 = ymax - ymin; -a2 = ymin; - b = b2 .* b1; a = a2 + a1 .* b2; -x(:) = bsxfun (@plus, a, x_data * diag (b)); + +x(:) = bsxfun (@plus, a, bsxfun (@times, x_data, b)); end % function diff -Nru octave-stk-2.4.2/inst/arrays/@stk_hrect/subsasgn.m octave-stk-2.5.0/inst/arrays/@stk_hrect/subsasgn.m --- octave-stk-2.4.2/inst/arrays/@stk_hrect/subsasgn.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@stk_hrect/subsasgn.m 2017-09-13 07:51:00.000000000 +0000 @@ -33,7 +33,7 @@ x.stk_dataframe = subsasgn (x.stk_dataframe, idx, value); - data = get (x.stk_dataframe, 'data'); + data = double (x); if any (data(1, :) > data(2, :)) stk_error ('Lower bounds cannot be larger than upperbounds', ... 'IllegalAssigment'); diff -Nru octave-stk-2.4.2/inst/arrays/@struct/double.m octave-stk-2.5.0/inst/arrays/@struct/double.m --- octave-stk-2.4.2/inst/arrays/@struct/double.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@struct/double.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,35 +0,0 @@ -% DOUBLE [overload base function, deprecated] -% -% DEPRECATION WARNING: The use of .a structures is deprecated. - -% Copyright Notice -% -% Copyright (C) 2013, 2016 SUPELEC -% -% Author: Julien Bect - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function xdata = double (x) - -xdata = x.a; - -end % function diff -Nru octave-stk-2.4.2/inst/arrays/@struct/stk_boundingbox.m octave-stk-2.5.0/inst/arrays/@struct/stk_boundingbox.m --- octave-stk-2.4.2/inst/arrays/@struct/stk_boundingbox.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@struct/stk_boundingbox.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,57 +0,0 @@ -% STK_BOUNDINGBOX [overload STK function, deprecated] -% -% DEPRECATION WARNING: The use of .a structures is deprecated. - -% Copyright Notice -% -% Copyright (C) 2015, 2016 CentraleSupelec -% -% Author: Julien Bect - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function box = stk_boundingbox (x) - -if nargin > 1, - stk_error ('Too many input arguments.', 'TooManyInputArgs'); -end - -if ~ isfield (x, 'a') - % The "modern STK" answer is: - stk_error (['stk_boundingbox (x) is not defined for structure ' ... - 'arguments.'], 'TypeMismatch'); -else - % But for backward compatibility we still support: - box = stk_boundingbox (x.a); -end - -end % function - - -%!shared x, y, cn -%! cn = {'a', 'b', 'c'}; -%! x = struct ('a', [0 3 2; 1 4 1; 7 0 2]); - -%!error y = stk_boundingbox (); -%!test y = stk_boundingbox (x); -%!error y = stk_boundingbox (x, 1); - -%!assert (isequal (y.data, [0 0 1; 7 4 2])); diff -Nru octave-stk-2.4.2/inst/arrays/@struct/stk_length.m octave-stk-2.5.0/inst/arrays/@struct/stk_length.m --- octave-stk-2.4.2/inst/arrays/@struct/stk_length.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/arrays/@struct/stk_length.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,40 +0,0 @@ -% STK_LENGTH [overload STK function, deprecated] -% -% DEPRECATION WARNING: The use of .a structures is deprecated. - -% Copyright Notice -% -% Copyright (C) 2015, 2016 CentraleSupelec -% -% Author: Julien Bect - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function l = stk_length (x) - -l = size (x.a, 1); - -end % function - - -%!test -%! x = struct ('a', [5; 2]); -%! assert (isequal (stk_length (x), 2)); diff -Nru octave-stk-2.4.2/inst/core/@stk_kreq_qr/get.m octave-stk-2.5.0/inst/core/@stk_kreq_qr/get.m --- octave-stk-2.4.2/inst/core/@stk_kreq_qr/get.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@stk_kreq_qr/get.m 2017-09-13 07:51:00.000000000 +0000 @@ -6,7 +6,7 @@ % Copyright Notice % -% Copyright (C) 2015 CentraleSupelec +% Copyright (C) 2015, 2017 CentraleSupelec % Copyright (C) 2013, 2014 SUPELEC % % Author: Julien Bect @@ -34,84 +34,76 @@ function value = get (kreq, propname) -try +switch propname - % if it's a field in the underlying structure, don't waste time - value = kreq.(propname); - -catch - - switch propname + case {'n', 'r', 'P_scaling', 'LS_Q', 'LS_R', 'RS', 'lambda_mu'} + value = kreq.(propname); - case 'lambda' - value = kreq.lambda_mu(1:kreq.n, :); - - case 'mu' - value = kreq.lambda_mu((kreq.n + 1):end, :); - - case 'delta_var' - value = dot (kreq.lambda_mu, kreq.RS, 1)'; - - case 'log_abs_det_kriging_matrix' - % LS_Q has +/- 1 determinant, so we only need to care about LS_R - value = sum (log (abs (diag (kreq.LS_R)))); - - case 'log_det_covariance_matrix_a' - n = kreq.n; - Q11 = kreq.LS_Q(1:n, 1:n); - R11 = kreq.LS_R(1:n, 1:n); - value = log (det (Q11 * R11)); % K = Q11 * R11 - % note: this method seems much less accurate than the others, - % we strongly recommend to avoid using it - - case 'log_det_covariance_matrix_b' - n = kreq.n; - Q11 = kreq.LS_Q(1:n, 1:n); - R11 = kreq.LS_R(1:n, 1:n); - Kchol = stk_cholcov (Q11 * R11); % K = Q11 * R11 - value = 2 * sum (log (diag (Kchol))); - - case 'log_det_covariance_matrix_c' - % note: very efficient (but not the best) and quite simple to understand - n = kreq.n; - Q11 = kreq.LS_Q(1:n, 1:n); - diag_R = diag (kreq.LS_R); - logdet1 = log (abs (det (Q11))); - logdet2 = sum (log (abs (diag_R(1:n)))); - value = logdet1 + logdet2; - - case {'log_det_covariance_matrix', 'log_det_covariance_matrix_d'} - % note: this is the fastest of all five solutions for large matrices - % (for small matrices, the difference is negligible)... but also - % the trickiest ! - n = kreq.n; - QL = kreq.LS_Q((n + 1):end, :); % lowerpart of LS_Q - diag_R = diag (kreq.LS_R); - logdet1 = sum (log (abs (diag_R))); - T = kreq.LS_R \ (QL'); - logdet2 = log (abs (det (T((n + 1):end, :)))); - value = logdet1 + logdet2; - - case 'log_det_covariance_matrix_e' - % note: the most time consuming of all five solutions (blame qrdelete), - % we strongly recommend to avoid using it - n = kreq.n; - r = kreq.r; - Q = kreq.LS_Q; - R = kreq.LS_R; - for i = 0:(r - 1), - [Q, R] = qrdelete (Q, R, n + r - i, 'row'); - [Q, R] = qrdelete (Q, R, n + r - i, 'col'); - end - value = sum (log (abs (diag (R)))); - - otherwise - error ('There is no property called ''%s''.', propname); - - end % switch - -end % try_catch + case 'lambda' + value = kreq.lambda_mu(1:kreq.n, :); + + case 'mu' + value = kreq.lambda_mu((kreq.n + 1):end, :); + + case 'delta_var' + value = dot (kreq.lambda_mu, kreq.RS, 1)'; + + case 'log_abs_det_kriging_matrix' + % LS_Q has +/- 1 determinant, so we only need to care about LS_R + value = sum (log (abs (diag (kreq.LS_R)))); + + case 'log_det_covariance_matrix_a' + n = kreq.n; + Q11 = kreq.LS_Q(1:n, 1:n); + R11 = kreq.LS_R(1:n, 1:n); + value = log (det (Q11 * R11)); % K = Q11 * R11 + % note: this method seems much less accurate than the others, + % we strongly recommend to avoid using it + + case 'log_det_covariance_matrix_b' + n = kreq.n; + Q11 = kreq.LS_Q(1:n, 1:n); + R11 = kreq.LS_R(1:n, 1:n); + Kchol = stk_cholcov (Q11 * R11); % K = Q11 * R11 + value = 2 * sum (log (diag (Kchol))); + + case 'log_det_covariance_matrix_c' + % note: very efficient (but not the best) and quite simple to understand + n = kreq.n; + Q11 = kreq.LS_Q(1:n, 1:n); + diag_R = diag (kreq.LS_R); + logdet1 = log (abs (det (Q11))); + logdet2 = sum (log (abs (diag_R(1:n)))); + value = logdet1 + logdet2; + + case {'log_det_covariance_matrix', 'log_det_covariance_matrix_d'} + % note: this is the fastest of all five solutions for large matrices + % (for small matrices, the difference is negligible)... but also + % the trickiest ! + n = kreq.n; + QL = kreq.LS_Q((n + 1):end, :); % lowerpart of LS_Q + diag_R = diag (kreq.LS_R); + logdet1 = sum (log (abs (diag_R))); + T = kreq.LS_R \ (QL'); + logdet2 = log (abs (det (T((n + 1):end, :)))); + value = logdet1 + logdet2; + + case 'log_det_covariance_matrix_e' + % note: the most time consuming of all five solutions (blame qrdelete), + % we strongly recommend to avoid using it + n = kreq.n; + r = kreq.r; + Q = kreq.LS_Q; + R = kreq.LS_R; + for i = 0:(r - 1) + [Q, R] = qrdelete (Q, R, n + r - i, 'row'); + [Q, R] = qrdelete (Q, R, n + r - i, 'col'); + end + value = sum (log (abs (diag (R)))); + + otherwise + error ('There is no property called ''%s''.', propname); + +end % switch end % function - -%#ok<*CTCH> diff -Nru octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_generate_samplepaths.m octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_generate_samplepaths.m --- octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_generate_samplepaths.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_generate_samplepaths.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,83 @@ +% STK_GENERATE_SAMPLEPATHS [overload STK function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function zsim = stk_generate_samplepaths (model, varargin) + +switch nargin + + case {0, 1} + stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); + + case 2 + % CALL: ZSIM = stk_generate_samplepaths (MODEL, XT) + xt = varargin{1}; + nb_paths = 1; + conditional = false; + + case 3 + % CALL: ZSIM = stk_generate_samplepaths (MODEL, XT, NB_PATHS) + xt = varargin{1}; + nb_paths = varargin{2}; + conditional = false; + + case 4 + % CALL: ZSIM = stk_generate_samplepaths (MODEL, XI, ZI, XT) + xi = varargin{1}; + zi = varargin{2}; + xt = varargin{3}; + nb_paths = 1; + conditional = true; + + case 5 + % CALL: ZSIM = stk_generate_samplepaths (MODEL, XI, ZI, XT, NB_PATHS) + xi = varargin{1}; + zi = varargin{2}; + xt = varargin{3}; + nb_paths = varargin{4}; + conditional = true; + + otherwise + stk_error ('Too many input arguments.', 'TooManyInputArgs'); + +end + +if ~ isa (model, 'stk_model_gpposterior') + stk_error ('Syntax error.', 'SyntaxError'); +end + +if conditional + model = stk_model_update (model, xi, zi); +end + +xi = get_input_data (model); +zi = get_output_data (model); +model = get_prior_model (model); + +zsim = stk_generate_samplepaths (model, xi, zi, xt, nb_paths); + +end % function diff -Nru octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_make_kreq.m octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_make_kreq.m --- octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_make_kreq.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_make_kreq.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,38 @@ +% STK_MAKE_KREQ [STK internal] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function kreq = stk_make_kreq (M_post, x) + +% Create prior cross-covariance matrix (and design matrix at x) +[Kti, Pt] = stk_make_matcov (M_post.prior_model, x, M_post.input_data); + +% Create full kriging equation object +kreq = stk_set_righthandside (M_post.kreq, Kti, Pt); + +end % function + diff -Nru octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_model_gpposterior.m octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_model_gpposterior.m --- octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_model_gpposterior.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_model_gpposterior.m 2017-09-13 07:51:00.000000000 +0000 @@ -44,6 +44,12 @@ 'same number of rows as x_obs.'], 'IncorrectSize'); end + % Currently, prior models are represented exclusively as structures + if ~ isstruct (prior_model) + stk_error (['Input argument ''prior_model'' must be a ' ... + 'prior model structure.'], 'InvalidArgument'); + end + % Make sure that lognoisevariance is -inf for noiseless models if ~ stk_isnoisy (prior_model) prior_model.lognoisevariance = -inf; @@ -53,6 +59,10 @@ % accept model structures with missing 'dim' field if (~ isfield (prior_model, 'dim')) || (isempty (prior_model.dim)) prior_model.dim = size (xi, 2); + elseif ~ isempty (xi) && (prior_model.dim ~= size (xi, 2)) + stk_error (sprintf (['The number of columns of xi (which is %d) ' ... + 'is different from the value of prior_model.dim (which is ' ... + '%d).'], size (xi, 2), prior_model.dim), 'InvalidArgument'); end % Check prior_model.lognoisevariance diff -Nru octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_predict_leaveoneout_direct.m octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_predict_leaveoneout_direct.m --- octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_predict_leaveoneout_direct.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_predict_leaveoneout_direct.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,90 @@ +% STK_PREDICT_LEAVEONEOUT_DIRECT [STK internal] + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% +% Author: Julien Bect +% Stefano Duhamel + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [LOO_pred, LOO_res] = stk_predict_leaveoneout_direct (M_post) + +% Heteroscedatic noise ? +heteroscedastic = ~ isscalar (M_post.prior_model.lognoisevariance); + +n = size (M_post.input_data, 1); +zp_mean = zeros (n, 1); +zp_var = zeros (n, 1); + +prior_model = M_post.prior_model; + +for i = 1:n + + xx = M_post.input_data; xx(i, :) = []; xt = M_post.input_data(i, :); + zz = M_post.output_data; zz(i, :) = []; + + % In the heteroscedastic case, the vector of log-variances for the + % noise is stored in prior_model.lognoisevariance. This vector must be + % modified too, when performing cross-validation. + if heteroscedastic + prior_model = M_post.prior_model; + prior_model.lognoisevariance(i) = []; + end + + zp = stk_predict (prior_model, xx, zz, xt); + + zp_mean(i) = zp.mean; + zp_var(i) = zp.var; + +end + +% Prepare outputs +LOO_pred = stk_dataframe ([zp_mean zp_var], {'mean', 'var'}); + +% Compute residuals ? +if nargout ~= 1 + + % Compute "raw" residuals + raw_res = M_post.output_data - zp_mean; + + % Compute normalized residual + noisevariance = exp (M_post.prior_model.lognoisevariance); + norm_res = raw_res ./ (sqrt (noisevariance + zp_var)); + + % Pack results into a dataframe + LOO_res = stk_dataframe ([raw_res norm_res], ... + {'residuals', 'norm_res'}); +end + +% Create LOO cross-validation plots? +if nargout == 0 + + % Plot predictions VS observations (left planel)... + stk_subplot (1, 2, 1); stk_plot_predvsobs (M_post.output_data, LOO_pred); + + % ...and normalized residuals (right panel) + stk_subplot (1, 2, 2); stk_plot_histnormres (LOO_res.norm_res); + +end + +end % function diff -Nru octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_predict_leaveoneout.m octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_predict_leaveoneout.m --- octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_predict_leaveoneout.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_predict_leaveoneout.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,10 +2,11 @@ % Copyright Notice % -% Copyright (C) 2016 CentraleSupelec +% Copyright (C) 2017 CentraleSupelec +% Copyright (C) 2017 LNE % -% Author: Julien Bect -% Stefano Duhamel +% Authors: Remi Stroh +% Julien Bect % Copying Permission Statement % @@ -29,55 +30,97 @@ function [LOO_pred, LOO_res] = stk_predict_leaveoneout (M_post) -if nargin > 1, +if nargin > 1 stk_error ('Too many input arguments.', 'TooManyInputArgs'); end -% Heteroscedatic noise ? -heteroscedastic = ~ isscalar (M_post.prior_model.lognoisevariance); - -n = size (M_post.input_data, 1); -zp_mean = zeros (n, 1); -zp_var = zeros (n, 1); - prior_model = M_post.prior_model; -for i = 1:n % FIXME: use "virtual cross-validation" formulae - - xx = M_post.input_data; xx(i, :) = []; xt = M_post.input_data(i, :); - zz = M_post.output_data; zz(i, :) = []; - - % In the heteroscedastic case, the vector of log-variances for the - % noise is stored in prior_model.lognoisevariance. This vector must be - % modified too, when performing cross-validation. - if heteroscedastic - prior_model = M_post.prior_model; - prior_model.lognoisevariance(i) = []; - end - - zp = stk_predict (prior_model, xx, zz, xt); - - zp_mean(i) = zp.mean; - zp_var(i) = zp.var; - +% Compute the covariance matrix, and the trend matrix +% (this covariance matrix K takes the noise into account) +[K, P] = stk_make_matcov (prior_model, M_post.input_data); +simple_kriging = (size (P, 2) == 0); + +% If simple kriging, just compute the inverse covariance matrix +if simple_kriging + R = inv (K); +else + % Use a more complex formula ("virtual cross-validation") + P_K = P' / K; + R = K \ (eye (size (K)) - P * ((P_K * P) \ P_K)); + % I = inv (K); + % R = I - I * P * (inv (P' * I * P)) * P' * I; end +dR = diag (R); % The diagonal of the LOO matrix + +% Mean +zi = M_post.output_data; +raw_res = R * zi ./ dR; % Compute "raw" residuals +zp_mean = zi - raw_res; % LOO prediction + +% Variance +noisevariance = exp (M_post.prior_model.lognoisevariance); +zp_var = max (0, 1 ./ dR - noisevariance); -% Prepare outputs -LOO_pred = stk_dataframe ([zp_mean zp_var], {'mean', 'var'}); +LOO_pred = stk_dataframe (horzcat (zp_mean, zp_var), {'mean', 'var'}); % Compute residuals ? -if nargout > 1 - - % Compute "raw" residuals - raw_res = M_post.output_data - zp_mean; +if nargout ~= 1 % Compute normalized residual - noisevariance = exp (M_post.prior_model.lognoisevariance); - norm_res = raw_res ./ (sqrt (noisevariance + zp_var)); + % norm_res = (zi - zp_mean) ./ (sqrt (noisevariance + zp_var)); + norm_res = (sqrt (dR)) .* raw_res; % Pack results into a dataframe - LOO_res = stk_dataframe ([raw_res norm_res], ... + LOO_res = stk_dataframe (horzcat (raw_res, norm_res), ... {'residuals', 'norm_res'}); end +% Create LOO cross-validation plots? +if nargout == 0 + + % Plot predictions VS observations (left planel)... + stk_subplot (1, 2, 1); stk_plot_predvsobs (M_post.output_data, LOO_pred); + + % ...and normalized residuals (right panel) + stk_subplot (1, 2, 2); stk_plot_histnormres (LOO_res.norm_res); + +end + end % function + + +%!test % Check virtual Leave-One-Out formula +%! +%! n = 20; d = 1; +%! x_obs = stk_sampling_regulargrid (n, d, [0; 2*pi]); +%! z_obs = stk_feval (@sin, x_obs); +%! +%! lm_list = {stk_lm_null, stk_lm_constant, stk_lm_affine}; +%! +%! for j = 0:2 +%! for k = 1:(length (lm_list)) +%! +%! model = stk_model ('stk_materncov32_iso', d); +%! model.lm = lm_list{k}; +%! model.param = log ([1; 5]); +%! +%! switch j % test various scenarios for lognoisevariance +%! case 0 +%! model.lognoisevariance = -inf; +%! case 1 +%! model.lognoisevariance = 0; +%! case 2 +%! model.lognoisevariance = (1 + rand (n, 1)) * 1e-3; +%! end +%! +%! M_post = stk_model_gpposterior (model, x_obs, z_obs); +%! +%! [loo_pred, loo_res] = stk_predict_leaveoneout (M_post); +%! [direct_pred, direct_res] = stk_predict_leaveoneout_direct (M_post); +%! +%! assert (stk_isequal_tolrel (loo_pred, direct_pred)); +%! assert (stk_isequal_tolrel (loo_res, direct_res)); +%! +%! end +%! end diff -Nru octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_predict.m octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_predict.m --- octave-stk-2.4.2/inst/core/@stk_model_gpposterior/stk_predict.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@stk_model_gpposterior/stk_predict.m 2017-09-13 07:51:00.000000000 +0000 @@ -30,12 +30,11 @@ function [zp, lambda, mu, K] = stk_predict (M_post, xt) -if nargin > 2, +if nargin > 2 stk_error ('Too many input arguments.', 'TooManyInputArgs'); end % TODO: these should become options -display_waitbar = false; block_size = []; M_prior = M_post.prior_model; @@ -51,8 +50,13 @@ xt = (1:nt)'; else nt = size (xt, 1); - if ~ isequal (size (xt), [nt, M_prior.dim]), - stk_error ('The size of xt is incorrect.', 'IncorrectSize'); + if length (size (xt)) > 2 + stk_error (['The input argument xt should not have more than two ' ... + 'dimensions'], 'IncorrectSize'); + elseif ~ isequal (size (xt), [nt M_prior.dim]) + stk_error (sprintf (['The number of columns of xt (which is %d) ' ... + 'does not agree with the dimension of the model (which is ' ... + '%d).'], size (xt, 2), M_prior.dim), 'IncorrectSize'); end end @@ -62,7 +66,7 @@ compute_prediction = ~ isempty (M_post.output_data); % compute the kriging prediction, or just the variances ? -if compute_prediction, +if compute_prediction zp_a = zeros (nt, 1); else zp_a = nan (nt, 1); @@ -77,18 +81,22 @@ block_size = ceil (MAX_RS_SIZE / (n_obs * SIZE_OF_DOUBLE)); end -% blocks of size approx. block_size -nb_blocks = max (1, ceil (nt / block_size)); - -block_size = ceil (nt / nb_blocks); +if nt == 0 + % skip main loop + nb_blocks = 0; +else + % blocks of size approx. block_size + nb_blocks = max (1, ceil (nt / block_size)); + block_size = ceil (nt / nb_blocks); +end % The full lambda_mu matrix is only needed when nargout > 1 -if nargout > 1, - lambda_mu = zeros (n_obs + M_post.kreq.r, nt); +if nargout > 1 + lambda_mu = zeros (n_obs + get (M_post.kreq, 'r'), nt); end % The full RS matrix is only needed when nargout > 3 -if nargout > 3, +if nargout > 3 RS = zeros (size (lambda_mu)); end @@ -105,50 +113,68 @@ % solve the kriging equation for the current block xt_ = xt(idx, :); - [Kti, Pt] = stk_make_matcov (M_prior, xt_, M_post.input_data); - kreq = stk_set_righthandside (M_post.kreq, Kti, Pt); + kreq = stk_make_kreq (M_post, xt_); % compute the kriging mean - if compute_prediction, - zp_a(idx) = kreq.lambda' * (double (M_post.output_data)); + if compute_prediction + zp_a(idx) = (get (kreq, 'lambda'))' * (double (M_post.output_data)); end % The full lambda_mu matrix is only needed when nargout > 1 if nargout > 1 - lambda_mu(:, idx) = kreq.lambda_mu; + lambda_mu(:, idx) = get (kreq, 'lambda_mu'); end % The full RS matrix is only needed when nargout > 3 - if nargout > 3, - RS(:, idx) = kreq.RS; + if nargout > 3 + RS(:, idx) = get (kreq, 'RS'); end % compute kriging variances (this does NOT include the noise variance) - zp_v(idx) = stk_make_matcov (M_prior, xt_, xt_, true) - kreq.delta_var; + zp_v(idx) = stk_make_matcov (M_prior, xt_, xt_, true) ... + - get (kreq, 'delta_var'); % note: the following modification computes prediction variances for noisy % variance, i.e., including the noise variance also - % zp_v(idx) = stk_make_matcov (M_prior, xt_, [], true) ... - % - dot (kreq.lambda_mu, kreq.RS); + % zp_v(idx) = stk_make_matcov (M_prior, xt_, [], true) ... + % - get (kreq, 'delta_var'); b = (zp_v < 0); - if any (b), + if any (b) zp_v(b) = 0.0; warning('STK:stk_predict:NegativeVariancesSetToZero', sprintf ( ... ['Correcting numerical inaccuracies in kriging variance.\n' ... '(%d negative variances have been set to zero)'], sum (b))); end - if display_waitbar, - waitbar (idx_end/nt, hwb, sprintf ( ... - 'In stk\\_predict(): %d/%d predictions completed',idx_end,nt)); - end end -if display_waitbar, - close (hwb); +%--- Ensure exact prediction at observation points for noiseless models -------- + +if ~ stk_isnoisy (M_prior) + + % FIXME: Fix the kreq object instead ? + + xi = double (M_post.input_data); + zi = double (M_post.output_data); + + [b, loc] = ismember (xt, xi, 'rows'); + if sum (b) > 0 + + if compute_prediction + zp_a(b) = zi(loc(b)); + end + + zp_v(b) = 0.0; + + if nargout > 1 + lambda_mu(:, b) = 0.0; + lambda_mu(sub2ind (size (lambda_mu), loc(b), find (b))) = 1.0; + end + end end + %--- Prepare outputs ----------------------------------------------------------- zp = stk_dataframe ([zp_a zp_v], {'mean' 'var'}); @@ -161,7 +187,7 @@ mu = lambda_mu((n_obs+1):end, :); end -if nargout > 3, +if nargout > 3 K0 = stk_make_matcov (M_prior, xt, xt); deltaK = lambda_mu' * RS; K = K0 - 0.5 * (deltaK + deltaK'); @@ -221,14 +247,6 @@ %! assert (isequal (size (lambda), [n m])); %! assert (all (isnan (y_prd_nan.mean))); -%!test % use old-style .a structures (legacy) -%! x_obs_a = struct ('a', double (x_obs)); -%! z_obs_a = struct ('a', double (z_obs)); -%! x_prd_a = struct ('a', double (x_prd)); -%! M_post1 = stk_model_gpposterior (M_prior, x_obs_a, z_obs_a); -%! y_prd1 = stk_predict (M_post, x_prd_a); -%! assert (stk_isequal_tolrel (y_prd, y_prd1)); - %!test % discrete model (prediction indices provided) %! M_prior1 = stk_model ('stk_discretecov', M_prior, x0); %! M_post1 = stk_model_gpposterior (M_prior1, idx_obs, z_obs); diff -Nru octave-stk-2.4.2/inst/core/stk_model.m octave-stk-2.5.0/inst/core/stk_model.m --- octave-stk-2.4.2/inst/core/stk_model.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/stk_model.m 2017-09-13 07:51:00.000000000 +0000 @@ -21,7 +21,7 @@ % which has mandatory fields and optional fields. % % MANDATORY FIELDS: covariance_type, param, lm, lognoisevariance -% OPTIONAL FIELD: param_prior, noise_prior, response_name +% OPTIONAL FIELD: param_prior, noise_prior % % See also stk_materncov_iso, stk_materncov_aniso, ... diff -Nru octave-stk-2.4.2/inst/core/stk_predict_leaveoneout.m octave-stk-2.5.0/inst/core/stk_predict_leaveoneout.m --- octave-stk-2.4.2/inst/core/stk_predict_leaveoneout.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/stk_predict_leaveoneout.m 2017-09-13 07:51:00.000000000 +0000 @@ -1,37 +1,42 @@ % STK_PREDICT_LEAVEONEOUT computes LOO predictions and residuals % -% CALL: LOO_PRED = stk_predict_leaveoneout (M_prior, xi, zi) +% CALL: LOO_PRED = stk_predict_leaveoneout (M_PRIOR, XI, ZI) % -% computes LOO predictions for (xi, zi) using the prior model M_prior. The -% result is a dataframe with n rows and two columns, where n is the number of -% rows of xi and zi. The first column is named 'mean' and contains LOO -% prediction means. The second column is named 'var' and contains LOO +% computes LOO predictions for (XI, ZI) using the prior model M_PRIOR. The +% result is a dataframe with n rows and two columns, where n is the common +% number of rows of XI and ZI. The first column is named 'mean' and contains +% LOO prediction means. The second column is named 'var' and contains LOO % prediction variances. % -% CALL: [LOO_PRED, LOO_RES] = stk_predict_leaveoneout (M_prior, xi, zi) +% CALL: [LOO_PRED, LOO_RES] = stk_predict_leaveoneout (M_PRIOR, XI, ZI) % % also returns LOO residuals. The result LOO_RES is a dataframe with n rows % and two columns. The first column is named 'residuals' and contains raw % (i.e., unnormalized) residuals. The second column is named 'norm_res' and % contains normalized residuals. % -% CALL: [LOO_PRED, LOO_RES] = stk_predict_leaveoneout (M_post) +% CALL: [LOO_PRED, LOO_RES] = stk_predict_leaveoneout (M_POST) % -% does the same as above using a posterior model object directly. +% does the same as above using a posterior model object M_POST directly. +% +% CALL: stk_predict_leaveoneout (...) +% +% automatically produces LOO cross-validations plots in the current figure, +% using stk_plot_predvsobs (left panel) and stk_plot_histnormres (right +% panel). % % REMARK % % This function actually computes pseudo-LOO prediction and residuals, % where the same parameter vector is used for all data points. % -% See also stk_example_kb10 +% See also stk_example_kb10, stk_plot_predvsobs, stk_plot_histnormres % Copyright Notice % -% Copyright (C) 2016 CentraleSupelec +% Copyright (C) 2016, 2017 CentraleSupelec % -% Author: Julien Bect -% Stefano Duhamel +% Author: Julien Bect % Copying Permission Statement % @@ -55,14 +60,23 @@ function varargout = stk_predict_leaveoneout (M_prior, xi, zi) -if nargin > 3, +if nargin > 3 stk_error ('Too many input arguments.', 'TooManyInputArgs'); end M_post = stk_model_gpposterior (M_prior, xi, zi); -varargout = cell (1, max (1, nargout)); -[varargout{:}] = stk_predict_leaveoneout (M_post); +if nargout == 0 + + % Call stk_predict_leaveoneout with nargout == 0 to create the plots + stk_predict_leaveoneout (M_post); + +else + + varargout = cell (1, nargout); + [varargout{:}] = stk_predict_leaveoneout (M_post); + +end end % function diff -Nru octave-stk-2.4.2/inst/core/stk_predict.m octave-stk-2.5.0/inst/core/stk_predict.m --- octave-stk-2.4.2/inst/core/stk_predict.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/stk_predict.m 2017-09-13 07:51:00.000000000 +0000 @@ -127,13 +127,14 @@ %! assert (isequal (size (mu), [1 m])); % ordinary kriging %! assert (isequal (size (K), [m m])); -%!test % use old-style .a structures (legacy) -%! y_prd2 = stk_predict(model, struct('a', double(x_obs)), ... -%! struct('a', double(z_obs)), struct('a', double(x_prd))); -%! assert(stk_isequal_tolrel(double(y_prd1), double(y_prd2))); - %!test % predict on large set of locations -%! x_obs = stk_sampling_regulargrid (20, 1, [0; pi]); -%! z_obs = stk_feval (@sin, x_obs); %! x_prd = stk_sampling_regulargrid (1e5, 1, [0; pi]); %! y_prd = stk_predict (model, x_obs, z_obs, x_prd); + +%!test % predict on an observation point +%! % https://sourceforge.net/p/kriging/tickets/49/ +%! [zp, lambda] = stk_predict (model, x_obs, z_obs, x_obs(4)); +%! assert (isequal (z_obs(4), zp.mean)) +%! assert (isequal (zp.var, 0)) +%! lambda_ref = zeros (n, 1); lambda_ref(4) = 1; +%! assert (isequal (lambda, lambda_ref)) diff -Nru octave-stk-2.4.2/inst/core/@struct/get_input_data.m octave-stk-2.5.0/inst/core/@struct/get_input_data.m --- octave-stk-2.4.2/inst/core/@struct/get_input_data.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@struct/get_input_data.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,43 @@ +% GET_INTPUT_DATA returns the input data of the model + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function input_data = get_input_data (model) + +assert_struct_is_model (model); + +if isfield (model, 'dim') + + input_data = zeros (0, model.dim); + +else + + input_data = []; + +end + +end % function diff -Nru octave-stk-2.4.2/inst/core/@struct/get_output_data.m octave-stk-2.5.0/inst/core/@struct/get_output_data.m --- octave-stk-2.4.2/inst/core/@struct/get_output_data.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@struct/get_output_data.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,35 @@ +% GET_OUTPUT_DATA returns the output data of the model + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function output_data = get_output_data (model) + +assert_struct_is_model (model); + +output_data = zeros (0, 1); + +end % function diff -Nru octave-stk-2.4.2/inst/core/@struct/get_prior_model.m octave-stk-2.5.0/inst/core/@struct/get_prior_model.m --- octave-stk-2.4.2/inst/core/@struct/get_prior_model.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@struct/get_prior_model.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,35 @@ +% GET_PRIOR_MODEL returns the prior_model structure + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function prior_model = get_prior_model (model) + +assert_struct_is_model (model); + +prior_model = model; + +end % function diff -Nru octave-stk-2.4.2/inst/core/@struct/private/assert_struct_is_model.m octave-stk-2.5.0/inst/core/@struct/private/assert_struct_is_model.m --- octave-stk-2.4.2/inst/core/@struct/private/assert_struct_is_model.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/core/@struct/private/assert_struct_is_model.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,39 @@ +% ASSERT_STRUCT_IS_MODEL [STK internal] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function assert_struct_is_model (model) + +% Just a quick check +if ~ isfield (model, 'param') + + stk_error (['The input argument does not look like a valid STK model' ... + 'structure.'], 'Invalid Argument'); + +end + +end % function diff -Nru octave-stk-2.4.2/inst/covfcs/stk_expcov_aniso.m octave-stk-2.5.0/inst/covfcs/stk_expcov_aniso.m --- octave-stk-2.4.2/inst/covfcs/stk_expcov_aniso.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/covfcs/stk_expcov_aniso.m 2017-09-13 07:51:00.000000000 +0000 @@ -152,13 +152,10 @@ %!assert (isequal (K1, K2)); %!assert (isequal (K1, K3)); -%!test % various types of input arguments +%!test % df versus ordinary array %! u = double (x); v = double (y); %! K1 = stk_expcov_aniso (param, u, v, -1); -%! K2 = stk_expcov_aniso (param, struct ('a', u), struct ('a', v), -1); -%! K3 = stk_expcov_aniso (param, stk_dataframe (u), stk_dataframe (v), -1); -%! assert (isequal (K1, K2)); -%! assert (isequal (K1, K3)); +%! K2 = stk_expcov_aniso (param, stk_dataframe (u), stk_dataframe (v), -1); %!error stk_expcov_aniso (param, x, y, -2); %!test stk_expcov_aniso (param, x, y, -1); diff -Nru octave-stk-2.4.2/inst/covfcs/stk_gausscov_aniso.m octave-stk-2.5.0/inst/covfcs/stk_gausscov_aniso.m --- octave-stk-2.4.2/inst/covfcs/stk_gausscov_aniso.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/covfcs/stk_gausscov_aniso.m 2017-09-13 07:51:00.000000000 +0000 @@ -152,13 +152,10 @@ %!assert (isequal (K1, K2)); %!assert (isequal (K1, K3)); -%!test % various types of input arguments +%!test % df versus ordinary array %! u = double (x); v = double (y); %! K1 = stk_gausscov_aniso (param, u, v, -1); -%! K2 = stk_gausscov_aniso (param, struct ('a', u), struct ('a', v), -1); -%! K3 = stk_gausscov_aniso (param, stk_dataframe (u), stk_dataframe (v), -1); -%! assert (isequal (K1, K2)); -%! assert (isequal (K1, K3)); +%! K2 = stk_gausscov_aniso (param, stk_dataframe (u), stk_dataframe (v), -1); %!error stk_gausscov_aniso (param, x, y, -2); %!test stk_gausscov_aniso (param, x, y, -1); diff -Nru octave-stk-2.4.2/inst/covfcs/stk_materncov32_aniso.m octave-stk-2.5.0/inst/covfcs/stk_materncov32_aniso.m --- octave-stk-2.4.2/inst/covfcs/stk_materncov32_aniso.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/covfcs/stk_materncov32_aniso.m 2017-09-13 07:51:00.000000000 +0000 @@ -153,13 +153,11 @@ %!assert (isequal (K1, K2)); %!assert (isequal (K1, K3)); -%!test % various types of input arguments +%!test % df versus ordinary array %! u = double (x); v = double (y); %! K1 = stk_materncov32_aniso (param, u, v, -1); -%! K2 = stk_materncov32_aniso (param, struct ('a', u), struct ('a', v), -1); -%! K3 = stk_materncov32_aniso (param, stk_dataframe (u), stk_dataframe (v), -1); +%! K2 = stk_materncov32_aniso (param, stk_dataframe (u), stk_dataframe (v), -1); %! assert (isequal (K1, K2)); -%! assert (isequal (K1, K3)); %!error stk_materncov32_aniso (param, x, y, -2); %!test stk_materncov32_aniso (param, x, y, -1); diff -Nru octave-stk-2.4.2/inst/covfcs/stk_sphcov_aniso.m octave-stk-2.5.0/inst/covfcs/stk_sphcov_aniso.m --- octave-stk-2.4.2/inst/covfcs/stk_sphcov_aniso.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/covfcs/stk_sphcov_aniso.m 2017-09-13 07:51:00.000000000 +0000 @@ -152,13 +152,11 @@ %!assert (isequal (K1, K2)); %!assert (isequal (K1, K3)); -%!test % various types of input arguments +%!test % df versus ordinary array %! u = double (x); v = double (y); %! K1 = stk_sphcov_aniso (param, u, v, -1); -%! K2 = stk_sphcov_aniso (param, struct ('a', u), struct ('a', v), -1); -%! K3 = stk_sphcov_aniso (param, stk_dataframe (u), stk_dataframe (v), -1); +%! K2 = stk_sphcov_aniso (param, stk_dataframe (u), stk_dataframe (v), -1); %! assert (isequal (K1, K2)); -%! assert (isequal (K1, K3)); %!error stk_sphcov_aniso (param, x, y, -2); %!test stk_sphcov_aniso (param, x, y, -1); diff -Nru octave-stk-2.4.2/inst/examples/01_kriging_basics/stk_example_kb10.m octave-stk-2.5.0/inst/examples/01_kriging_basics/stk_example_kb10.m --- octave-stk-2.4.2/inst/examples/01_kriging_basics/stk_example_kb10.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/examples/01_kriging_basics/stk_example_kb10.m 2017-09-13 07:51:00.000000000 +0000 @@ -54,7 +54,17 @@ M_prior = stk_model (@stk_materncov52_aniso, d); % prior M_prior.param = stk_param_estim (M_prior, x, y); % ReML parameter estimation +% Compye LOO predictions and residuals [y_LOO, res_LOO] = stk_predict_leaveoneout (M_prior, x, y); +% Plot predictions VS observations (left planel) +% and normalized residuals (right panel) stk_figure ('stk_example_kb10 (a)'); stk_plot_predvsobs (y, y_LOO); stk_figure ('stk_example_kb10 (b)'); stk_plot_histnormres (res_LOO.norm_res); + +% Note that the three previous lines can be summarized, +% if you only need the two diagnostic plots, as: +% +% stk_predict_leaveoneout (M_prior, x, y); +% +% (calling stk_predict_leaveoneout with no output arguments creates the plots). diff -Nru octave-stk-2.4.2/inst/examples/02_design_of_experiments/stk_example_doe03.m octave-stk-2.5.0/inst/examples/02_design_of_experiments/stk_example_doe03.m --- octave-stk-2.4.2/inst/examples/02_design_of_experiments/stk_example_doe03.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/examples/02_design_of_experiments/stk_example_doe03.m 2017-09-13 07:51:00.000000000 +0000 @@ -147,7 +147,7 @@ [EI_max, i_max] = max (EI_val); % Figure: upper panel - stk_subplot (2, 1, 1); cla; + stk_subplot (2, 1, 1); hold off; % CG#12 stk_plot1d (data.x, data.z, xg, zg, z_pred); xlim (BOX); hold on; plot (xg(i_max), zg(i_max), 'ro', 'MarkerFaceColor', 'y'); diff -Nru octave-stk-2.4.2/inst/examples/02_design_of_experiments/stk_example_doe05.m octave-stk-2.5.0/inst/examples/02_design_of_experiments/stk_example_doe05.m --- octave-stk-2.4.2/inst/examples/02_design_of_experiments/stk_example_doe05.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/examples/02_design_of_experiments/stk_example_doe05.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,186 @@ +% STK_EXAMPLE_DOE05 A simple illustration of 1D Bayesian optimization +% +% Our goal here is to minimize the one-dimensional function +% +% x |--> x * sin (x) +% +% over the interval [0; 4 * pi], using noisy evaluations. +% +% Evaluations points are chosen sequentially using either AKG criterion +% (default) or the EQI criterion (set SAMPCRIT_NAME to 'EQI'); + +% Copyright Notice +% +% Copyright (C) 2015-2017 CentraleSupelec +% Copyright (C) 2016 EDF R&D +% Copyright (C) 2013, 2014 SUPELEC +% +% Authors: Julien Bect +% Tom Assouline, Florent Autret & Stefano Duhamel (for EDF R&D) + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +stk_disp_examplewelcome; +stk_figure ('stk_example_eqi_test'); + + +%% Problem definition +% Here we define a one-dimensional optimization problem. +% The goal is to find the minimum of f on the domain BOX. + +% 1D test function +f = @(x)(x .* sin (x)); % Define a 1D test function +DIM = 1; % Dimension of the factor space +BOX = stk_hrect ([0; 12], {'x'}); % Factor space (hyper-rectangle object) + +% Variance of the observation noise +NOISE_VARIANCE = 2 ^ 2; + +% Space discretization +GRID_SIZE = 200; % Number of points in the grid +xg = stk_sampling_regulargrid (GRID_SIZE, DIM, BOX); + +% Give names explicit names to the points of the grid +xg.rownames = arrayfun ... + (@(i)(sprintf ('xg(%03d)', i)), 1:GRID_SIZE, 'UniformOutput', false)'; + +% Values of the function on the grid +zg = stk_feval (f, xg); +zg.colnames = {'z'}; + + +%% Parameters affecting the sequential design algorithm + +N0 = 5; % Size of the initial (regularly spaced) design +BUDGET = 100; % Total evaluation budget +REESTIM_PERIOD = 10; % How often should we re-estimate the cov parameters ? +SAMPCRIT_NAME = 'AKG'; % Choose a particular sampling criterion + +% Note: the two criteria proposed here compute an "expected improvement" of +% some kind. As such, they return positive values, and must be maximized. + +switch SAMPCRIT_NAME + case 'EQI' + QUANTILE_ORDER = 0.5; + POINT_BATCH_SIZE = @(x, n) BUDGET - n; + sampcrit = stk_sampcrit_eqi ([], QUANTILE_ORDER, POINT_BATCH_SIZE); + case 'AKG' + sampcrit = stk_sampcrit_akg (); +end + + +%% Initial design of experiments + +% Construction of the initial design +x0 = stk_sampling_regulargrid (N0, DIM, BOX); + +% Give names explicit names to the points in the initial design +x0.rownames = arrayfun ... + (@(i)(sprintf ('init%03d', i)), 1:N0, 'UniformOutput', false)'; + +% Simulate noisy observations of the initial design +z0 = stk_feval (f, x0); z0.colnames = {'z'}; +z0 = z0 + sqrt (NOISE_VARIANCE) * randn (size (z0)); + + +%% Specification of the model (Gaussian process prior) + +model0 = stk_model ('stk_materncov52_iso'); + +% Assume that the variance of the observation noise is known +model0.lognoisevariance = log (NOISE_VARIANCE); + +% Add a prior on covariance parameters (log (sigma^2), log (1/rho)) +model0.prior.mean = log ([1.0; 1/4.0]); +model0.prior.invcov = diag (1 ./ [+inf log(2)^2]); + + +%% Sequential design of experiments +% Here, evaluations points are chosen sequentially using the sampling criterion, +% starting from the initial design defined above. + +% Plot only once in a while +PLOT_PERIOD = 5; + +% Start from the initial design +x = x0; +z = z0; + +for iter = 1:(BUDGET - N0) + + if mod (iter, REESTIM_PERIOD) == 1 + % Create posterior model object from scratch + % (covariance function parameters estimated by marginal MAP) + model = stk_model_gpposterior (model0, x, z); + else + % Update posterior model object + % (covariance function parameters not re-estimated) + model = stk_model_update (model, x_new, z_new); + end + + % Instanciate sampling criterion object with model + sampcrit.model = model; + + % Compute the EQI criterion on the grid + [crit_val, z_pred] = sampcrit (xg); + + if mod (iter, PLOT_PERIOD) == 1 + % Figure: upper panel + stk_subplot (2, 1, 1); hold off; % CG#12 + stk_plot1d ([],[], xg, zg, z_pred); + hold on; plot (x, z, 'k.'); + % Figure: lower panel + stk_subplot (2, 1, 2); cla; + plot (xg, crit_val); xlim (BOX); ylabel (SAMPCRIT_NAME); + end + + if all (crit_val == 0), break, end + + % Pick the point where the EQI is maximum as our next evaluation point + [crit_max, i_max] = max (crit_val); + x_new = xg(i_max, :); + + % Simulate a new observation at the selected location + z_new = zg(i_max, :) + sqrt (NOISE_VARIANCE) * randn; + + % Indicate new point on the lower panel + if mod (iter, PLOT_PERIOD) == 1 + hold on; plot (x_new, crit_max, 'ro', 'MarkerFaceColor', 'y'); + end + + % Add the new evaluation to the DoE + x = vertcat (x, x_new); + z = vertcat (z, z_new); + + drawnow; % pause + +end + +% Display the final DoE +data = stk_dataframe ([x z], {'x', 'z'}); disp (data); + +% Total number of evaluations ? +fprintf ('\nNumber of evaluations: %d + %d = %d.\n\n', N0, BUDGET - N0, BUDGET); + + +%#ok<*AGROW> + +%!test stk_example_doe05; close all; diff -Nru octave-stk-2.4.2/inst/examples/03_miscellaneous/stk_example_misc04.m octave-stk-2.5.0/inst/examples/03_miscellaneous/stk_example_misc04.m --- octave-stk-2.4.2/inst/examples/03_miscellaneous/stk_example_misc04.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/examples/03_miscellaneous/stk_example_misc04.m 2017-09-13 07:51:00.000000000 +0000 @@ -4,22 +4,32 @@ % % We consider a bi-objective optimization problem, where the objective % functions are modeled as a pair of independent stationary Gaussian -% processes with a Matern 5/2 isotropic covariance function. +% processes with a Matern 5/2 anisotropic covariance function. % -% Figure (a): we draw (unconditional) samplepaths of the Pareto front -% using (unconditional) samplepaths of the pair of objective functions. +% Figure (a): represent unconditional realizations of the Pareto front and +% and estimate of the probability of being non-dominated at each point +% of the objective space. % -% Figure (b): we represent a Monte-Carlo estimate of the probability of -% domination, computed on a grid. +% Figure (b): represent conditional realizations of the Pareto front and +% and estimate of the posteriorior probability of being non-dominated +% at each point of the objective space. +% +% EXPERIMENTAL FUNCTION WARNING +% +% This script uses the stk_plot_probdom2d function, which is currently +% considered an experimental function. Read the help for more information. % % REFERENCE % % [1] Michael Binois, David Ginsbourger and Olivier Roustant, Quantifying % uncertainty on Pareto fronts with Gaussian Process conditional simu- -% lations, Preprint hal-00904811, 2013. +% lations, European J. of Operational Research, 2043(2):386-394, 2015. +% +% See also: stk_plot_probdom2d % Copyright Notice % +% Copyright (C) 2017 CentraleSupelec % Copyright (C) 2014 SUPELEC % % Author: Julien Bect @@ -47,96 +57,46 @@ stk_disp_examplewelcome; -%% MODEL +%% Objective functions + +DIM = 2; +BOX = [[0; 5] [0; 3]]; -DIM = 3; -BOX = repmat ([0; 1], 1, DIM); +f1 = @(x) 4 * x(:,1) .^ 2 + 4 * x(:,2) .^ 2; +f2 = @(x) (x(:,1) - 5) .^ 2 + (x(:,2) - 5) .^ 2; -model1 = stk_model ('stk_materncov52_iso', DIM); -model1.param = log ([1.0 1/0.5]); -model1.response_name = 'y1'; -model2 = stk_model ('stk_materncov52_iso', DIM); -model2.param = log ([1.0 1/2.0]); -model2.response_name = 'y2'; +%% Data -NB_SIMULATION_POINTS = 500; -x_sim = stk_sampling_randunif (NB_SIMULATION_POINTS, DIM, BOX); +n_obs = 10; +x_obs = stk_sampling_maximinlhs (n_obs, [], BOX); -%% SIMULATE AND PLOT REALIZATIONS OF THE PARETO FRONT +z_obs = zeros (n_obs, 2); +z_obs(:, 1) = f1 (x_obs.data); % Remark: f1 (x_obs) should be OK... +z_obs(:, 2) = f2 (x_obs.data); % ... but see Octave bug #49267 -NB_SAMPLEPATHS = 20; -% Simulate samplepaths -y1_sim = stk_generate_samplepaths (model1, x_sim, NB_SAMPLEPATHS); -y2_sim = stk_generate_samplepaths (model2, x_sim, NB_SAMPLEPATHS); +%% Stationary GP models -% Empirical lower/upper bounds for each response -y1_min = min (y1_sim(:)); y1_max = max (y1_sim(:)); -y2_min = min (y2_sim(:)); y2_max = max (y2_sim(:)); +model1 = stk_model ('stk_materncov52_aniso', DIM); +model1.param = stk_param_estim (model1, x_obs, z_obs(:, 1)); -% Axis for a nice plot -y1_axis = [y1_min - 0.05 * (y1_max - y1_min), y1_max]; -y2_axis = [y2_min - 0.05 * (y2_max - y2_min), y2_max]; +model2 = stk_model ('stk_materncov52_aniso', DIM); +model2.param = stk_param_estim (model2, x_obs, z_obs(:, 1)); -% Figure + colormap stk_figure ('stk_example_misc04 (a)'); -cm = jet (NB_SAMPLEPATHS); -for i = 1:NB_SAMPLEPATHS, - - y_sim = [y1_sim(:, i) y2_sim(:, i)]; - y_nd = y_sim(stk_paretofind (y_sim), :); - - % Add two extremities to the Pareto front - y_nd_0 = stk_dataframe ([y_nd(1, 1) y2_max], y_nd.colnames); - y_nd_1 = stk_dataframe ([y1_max y_nd(end, 2)], y_nd.colnames); - y_nd = [y_nd_0; y_nd; y_nd_1]; %#ok - - stairs (y_nd.data(:, 1), y_nd.data(:, 2), 'Color', cm(i, :)); - stk_labels (model1.response_name, model2.response_name); - axis ([y1_axis y2_axis]); hold on; - -end - -stk_title ('Simulated Pareto fronts'); - - -%% SIMULATE DOMINATED REGION - -NB_SAMPLEPATHS = 100; - -% Simulate samplepaths -y1_sim = stk_generate_samplepaths (model1, x_sim, NB_SAMPLEPATHS); -y2_sim = stk_generate_samplepaths (model2, x_sim, NB_SAMPLEPATHS); - -% Empirical lower/upper bounds for each response -y1_min = min (y1_sim(:)); y1_max = max (y1_sim(:)); -y2_min = min (y2_sim(:)); y2_max = max (y2_sim(:)); - -% Axes for a nice plot -y1_axis = [y1_min - 0.05 * (y1_max - y1_min), y1_max]; -y2_axis = [y2_min - 0.05 * (y2_max - y2_min), y2_max]; - -% Test points -n_test = 100 ^ 2; -y_test = stk_sampling_regulargrid (n_test, 2, [y1_axis' y2_axis']); -y_test.colnames = {model1.response_name, model2.response_name}; - -isdom = zeros (size (y_test, 1), 1); -for i = 1:NB_SAMPLEPATHS, - y_sim = [y1_sim(:, i) y2_sim(:, i)]; - isdom = isdom + stk_isdominated (y_test, y_sim); -end -isdom = isdom / NB_SAMPLEPATHS; +stk_plot_probdom2d (model1, model2, BOX); + + +%% Conditionned GP models -% Figure (b) stk_figure ('stk_example_misc04 (b)'); -colormap (hot); pcolor (y_test, isdom); -colorbar ('YTick', [0 .25 .5 .75 1], ... - 'YTickLabel', {'0%', '25%', '50%', '75%', '100%'}); -stk_title ('Probability of domination'); + +stk_plot_probdom2d ( ... + stk_model_gpposterior (model1, x_obs, z_obs(:, 1)), ... + stk_model_gpposterior (model2, x_obs, z_obs(:, 2)), BOX); %!test stk_example_misc04; close all; diff -Nru octave-stk-2.4.2/inst/examples/test_functions/stk_testcase_truss3.m octave-stk-2.5.0/inst/examples/test_functions/stk_testcase_truss3.m --- octave-stk-2.4.2/inst/examples/test_functions/stk_testcase_truss3.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/examples/test_functions/stk_testcase_truss3.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,242 @@ +% STK_TESTCASE_TRUSS3 provides information about the 'truss3' test case +% +% CALL: TC = stk_testcase_truss3 () +% +% returns a structure TC that describes the 'truss3' test case, borrowed +% from [1, chapter 9]. This structure contains two fields: +% +% * .constants: all the numerical constants for this problem, +% +% * .search_domain: an stk_hrect object that specifies the search domain +% of the optimization problem. +% +% TEST CASE OVERVIEW +% +% The system considered in this test case is the following 3-bar truss: +% +% <--------- D -----------> +% <--- w ---> +% ------A==========B==============C------ +% \_ | __/ ^ +% \_ | (2) __/ | +% \_ | __/ L +% (1) \_ | __/ (3) | +% \_P_/ v +% +% Nodes A, B and C are fixed (pin joints). Node D is submitted to both an +% horizontal load F1 (e.g., wind) and a vertical load F2 (suspended load). +% +% The design variables are the cross-sections a1, a2 and a3 of the three +% bars, and the horizontal position w of the vertical bar. The quantities +% of interest are the total volume of the structure, the mechanical +% (tensile) stress in the bars, and the displacement of P. Various +% formulations of optimization problems can be considered, depending on +% which quantities are selected as contraints and objectives, and whether +% or not uncertainties are taken into account (robust formulations). +% +% NUMERICAL CONSTANTS +% +% The numerical values borrowed from [1] have been converted to SI +% units. The fields of TC.constants are: +% +% * .D: truss width [m], +% * .L: length of the vertical bar [m], +% * .E: Young's modulus [Pa], +% +% * .a_min: minimal cross-section [m^2], +% * .a_max: maximal cross-section [m^2], +% * .w_min: minimal value of the position of the vertical bar [m], +% * .w_max: maximal value of the position of the vertical bar [m], +% +% * .F1_mean: mean (nominal) value of the horizontal load [N], +% * .F1_std: standard deviation of the horizontal load [N], +% * .F2_mean: mean (nominal) value of the vertical load [N] +% * .F2_std: standard deviation of the vertical load [N]. +% +% The standard deviations .F1_std and .F2_std are used in the formulation +% of robust optimization problems related to this test case [see 1, chap 11]. +% +% NUMERICAL FUNCTIONS +% +% Two numerical functions are provided to compute the quantities of interest +% of this test case: +% +% * stk_testfun_truss3_vol: computes the total volume of the structure, +% +% * stk_testfun_truss3_bb: computes the tensile stress in the bars and the +% displacement of P. +% +% Both functions have the same syntax: +% +% V = stk_testfun_truss3_vol (X, CONST) +% +% Z = stk_testfun_truss3_bb (X, CONST) +% +% where CONST is a structure containing the necessary numerical constants. +% To use the constants from [1], pass TC.constants as second input argument. +% +% Both function accept as first input argument an N x D matrix (or data +% frame) where D is either 4 or 6: +% +% * columns 1--3: cross-section a1, a2 and a3, +% +% * column 4: position w of the horizontal bar, +% +% * column 5-6 (optional): horizontal and vertical loads F1, F2. +% +% The second function is named 'bb' for 'black box', as it plays the role of +% a (supposedly expensive to evaluate) black box computer model for this +% test case. The output Z has five columns, corresponding to: +% +% * columns 1--2: horizontal and vertical displacement y1, y2 of P, +% +% * columns 3--5: tensile stress sigma_j in bars j = 1, 2 and 3. +% +% EXAMPLE +% +% tc = stk_testcase_truss3 (); n = 5; +% +% % Draw 5 points uniformly in the 4D input domain ("design space") +% xd = stk_sampling_randunif (n, [], tc.search_domain) +% +% % Compute the volumes +% v = stk_testfun_truss3_vol (xd, tc.constants) +% +% % Compute displacements and stresses for nominal loads +% z = stk_testfun_truss3_bb (xd, tc.constants) +% +% % Draw loads from normal distributions +% F = stk_dataframe (zeros (n, 2), {'F1' 'F2'}); +% F(:, 1) = tc.constants.F1_mean + tc.constants.F1_std * randn (n, 1); +% F(:, 2) = tc.constants.F2_mean + tc.constants.F2_std * randn (n, 1); +% +% % Compute displacements and stresses for the random loads +% x = [xd F] +% z = stk_testfun_truss3_bb (x, tc.constants) +% +% REFERENCE +% +% [1] Indraneel Das, Nonlinear Multicriteria Optimization and Robust +% Optimality. PhD thesis, Rice University, 1997. +% +% [2] Juhani Koski, Defectiveness of weighting method in multicriterion +% optimization of structures. Int. J. for Numerical Methods in +% Biomedical Engineering, 1(6):333-337, 1985. +% +% See also: stk_testfun_truss3_vol, stk_testfun_truss3_bb + +% Copyright Notice +% +% This file: stk_testcase_truss3.m was written in 2017 +% by Julien Bect . +% +% To the extent possible under law, the author(s) have dedicated all +% copyright and related and neighboring rights to this file to the pub- +% lic domain worldwide. This file is distributed without any warranty. +% +% This work is published from France. +% +% You should have received a copy of the CC0 Public Domain Dedication +% along with this file. If not, see +% . + +% Copying Permission Statement (STK toolbox as a whole) +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function tc = stk_testcase_truss3 () + +tc = struct (); + +%--- Numerical constants ------------------------------------------------------- + +% Conversion from feet to meters +m_per_foot = 0.3048; +m_per_inch = m_per_foot / 12; + +% Conversion from lbf (pound-force) to newtons (N) +N_per_lbf = 4.4482216152605; +N_per_kip = 1000 * N_per_lbf; + +% Conversion from psi (pound-force per square inch) to Pa (pascals) +Pa_per_psi = N_per_lbf / (m_per_inch ^ 2); +Ps_per_ksi = 1000 * Pa_per_psi; + +% Constants in Das (97) (differs from the test case used by Koski (1985)) + +% Truss width +constants.D = 120 * m_per_foot; % [m] 120 feet ~ 36.6 m + +% Length of the vertical bar +constants.L = 60 * m_per_foot; % [m] 60 feet ~ 18.3 m + +% Young's modulus (steel) +constants.E = 29e3 * Ps_per_ksi; % [Pa] 29e3 ksi ~ 200 GPa + +% Minimal and maximal cross-sections +constants.a_min = 0.8 * m_per_inch ^ 2; % [m^2] 0.8 in^2 ~ 5.2 cm^2 +constants.a_max = 3.0 * m_per_inch ^ 2; % [m^2] 0.8 in^2 ~ 19.4 cm^2 + +% Bounds the position of the vertical bar +constants.w_min = constants.D / 4; % [m] +constants.w_max = 3 * constants.w_min; % [m] + +% Normal distribution on the loads +constants.F1_mean = 100 * N_per_kip; +constants.F1_std = 15 * N_per_kip; +constants.F2_mean = 1000 * N_per_kip; +constants.F2_std = 25 * N_per_kip; + +%--- Search domain (bounds on design variables) -------------------------------- + +a_dom = stk_hrect ( ... % Bounds on cross-sections + repmat ([constants.a_min; constants.a_max], 1, 3), {'a1', 'a2', 'a3'}); + +w_dom = stk_hrect ( ... % Bounds on w + [constants.w_min; constants.w_max], {'w'}); + +search_domain = [a_dom w_dom]; + +%--- Store everything inside a structure --------------------------------------- + +tc.constants = constants; +tc.search_domain = search_domain; + +end % function + + +%!shared tc, xd, n +%! tc = stk_testcase_truss3 (); n = 5; +%! xd = stk_sampling_randunif (n, [], tc.search_domain); + +%!test +%! v = stk_testfun_truss3_vol (xd, tc.constants); +%! z = stk_testfun_truss3_bb (xd, tc.constants); +%! assert (isequal (size (v), [n 1])); +%! assert (isequal (size (z), [n 5])); + +%!test +%! F = stk_dataframe (zeros (n, 2), {'F1' 'F2'}); +%! F(:, 1) = tc.constants.F1_mean + tc.constants.F1_std * randn (n, 1); +%! F(:, 2) = tc.constants.F2_mean + tc.constants.F2_std * randn (n, 1); +%! x = [xd F]; +%! v = stk_testfun_truss3_vol (x, tc.constants); +%! z = stk_testfun_truss3_bb (x, tc.constants); +%! assert (isequal (size (v), [n 1])); +%! assert (isequal (size (z), [n 5])); diff -Nru octave-stk-2.4.2/inst/examples/test_functions/stk_testfun_truss3_bb.m octave-stk-2.5.0/inst/examples/test_functions/stk_testfun_truss3_bb.m --- octave-stk-2.4.2/inst/examples/test_functions/stk_testfun_truss3_bb.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/examples/test_functions/stk_testfun_truss3_bb.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,129 @@ +% STK_TESTFUN_TRUSS3_BB computes displacements and stresses for 'truss3' +% +% CALL: Z = stk_testfun_truss3_bb (X, CONST) +% +% See also: stk_testcase_truss3, stk_testfun_truss3_vol + +% Copyright Notice +% +% This file: stk_testfun_truss3_bb.m was written in 2017 +% by Julien Bect . +% +% To the extent possible under law, the author(s) have dedicated all +% copyright and related and neighboring rights to this file to the pub- +% lic domain worldwide. This file is distributed without any warranty. +% +% This work is published from France. +% +% You should have received a copy of the CC0 Public Domain Dedication +% along with this file. If not, see +% . + +% Copying Permission Statement (STK toolbox as a whole) +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function z = stk_testfun_truss3_bb (x, const) + +% Convert input to double-precision input data +% (and get rid of extra structure such as table or stk_dataframe objects) +x_ = double (x); + +% Check input size +[n, dim] = size (x_); +switch dim + + case 4 + % Use nominal loads + F = zeros (n, 2); + F(:, 1) = const.F1_mean; + F(:, 2) = const.F2_mean; + x_ = [x_ F]; + + case 6 + % Loads have been provided as well + + otherwise + error ('Incorrect number of variables.'); + +end + +% Extract variables +a = x_(:, 1:3); % Cross-sections of the bars [m^2] +w = x_(:, 4); % Horizontal position of bar #2 [m] +F = x_(:, 5:6); % Horizontal and vertical loads [N] + +% Extract constants +D = const.D; % Total width of the structure [m] +L = const.L; % Length of the vertical bar [m] +E = const.E; % Young's modulus [Pa] + +% Check w values +D_w = D - w; +if any (w < 0) || any (D_w < 0) + error ('w should be between 0 and D.') +end + +% Lengths +LL = repmat (L, [n 3]); +LL(:, 1) = sqrt (L ^ 2 + w .^ 2); +LL(:, 3) = sqrt (L ^ 2 + D_w .^ 2); + +% Sines and cosines +sin_theta = L ./ LL(:, 1); +cos_theta = w ./ LL(:, 1); +sin_alpha = L ./ LL(:, 3); +cos_alpha = D_w ./ LL(:, 3); + +% Linear relation between tensile forces and elongations, +% assuming linear elasticity (Hooke's law) +C = E * a ./ LL; + +% Compute displacement of node P and stresses +y = zeros (n, 2); % Displacement of node P +s = zeros (n, 3); % Tensile stress in the bars +for i = 1:n + + % Rectangular matrix A for Equ. 9.1 in Das (1997) p.65, gives the + % equilibrium relation between tensile forces and loads (small displacements) + A = [cos_theta(i) sin_theta(i); 0 1; -cos_alpha(i) sin_alpha(i)]; + + % Stiffness matrix + K = A' * (diag (C(i, :))) * A; + + % Compute the displacement of node P + y(i, :) = F(i, :) / K; + + % Bar elongations + delta = y(i, :) * A'; + + % Tensile stresses (Hooke's law) + s(i, :) = E * delta ./ LL(i, :); + +end + +% Output: return displacement of node P and tensile stresses (five outputs) +z = [y s]; + +% df-in/df-out +if isa (x, 'stk_dataframe') + z = stk_dataframe (z, {'y1' 'y2' 'sigma1' 'sigma2' 'sigma3'}, x.rownames); +end + +end % function diff -Nru octave-stk-2.4.2/inst/examples/test_functions/stk_testfun_truss3_vol.m octave-stk-2.5.0/inst/examples/test_functions/stk_testfun_truss3_vol.m --- octave-stk-2.4.2/inst/examples/test_functions/stk_testfun_truss3_vol.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/examples/test_functions/stk_testfun_truss3_vol.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,71 @@ +% STK_TESTFUN_TRUSS3_VOL computes the volume of the 'truss3' structure +% +% CALL: V = stk_testfun_truss3_vol (X, CONST) +% +% See also: stk_testcase_truss3, stk_testfun_truss3_bb + + +% Copyright Notice +% +% This file: stk_testfun_truss3_vol.m was written in 2017 +% by Julien Bect . +% +% To the extent possible under law, the author(s) have dedicated all +% copyright and related and neighboring rights to this file to the pub- +% lic domain worldwide. This file is distributed without any warranty. +% +% This work is published from France. +% +% You should have received a copy of the CC0 Public Domain Dedication +% along with this file. If not, see +% . + +% Copying Permission Statement (STK toolbox as a whole) +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function V = stk_testfun_truss3_vol (x, const) + +% Convert input to double-precision input data +% (and get rid of extra structure such as table or stk_dataframe objects) +x_ = double (x); + +% Extract design variables +a1 = x_(:, 1); +a2 = x_(:, 2); +a3 = x_(:, 3); +w = x_(:, 4); + +% Extract constants +L = const.L; +D = const.D; + +% Length of bar 1 and bar 3 +L1 = sqrt (L ^ 2 + w .^ 2); +L3 = sqrt (L ^ 2 + (D - w) .^ 2); + +% Total volume +V = a1 .* L1 + a2 * L + a3 .* L3; + +% df-in/df-out +if isa (x, 'stk_dataframe') + V = stk_dataframe (V, {'V'}, x.rownames); +end + +end % function diff -Nru octave-stk-2.4.2/inst/misc/benchmarks/stk_benchmark_loocv.m octave-stk-2.5.0/inst/misc/benchmarks/stk_benchmark_loocv.m --- octave-stk-2.4.2/inst/misc/benchmarks/stk_benchmark_loocv.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/benchmarks/stk_benchmark_loocv.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,85 @@ +% STK_BENCHMARK_LOOCV Benchmark stk_predict_leaveoneout +% +% Compare run time of virtual LOO-CV implementation with respect to +% the old, "direct" implementation. +% +% Note: correctness of implementation is already taken care of in the +% unit tests. We only care about computation speed here. + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function t_out = stk_benchmark_loocv () + +nrep = 100; + +n = [10 20 40 80 160 320]; +m = numel (n); + +t_virtual = zeros (nrep, m); +t_direct = zeros (nrep, m); + +for i = 1:m + + fprintf ('i = %d/%d...\n', i, m); + + % Prepare test + d = 1; + x_obs = stk_sampling_regulargrid (n(i), d, [0; 2*pi]); + z_obs = stk_feval (@sin, x_obs); + model = stk_model ('stk_materncov32_iso', d); + model.param = log ([1; 5]); + model.lognoisevariance = (1 + rand (n(i), 1)) * 1e-3; + M_post = stk_model_gpposterior (model, x_obs, z_obs); + + testfun = @() stk_predict_leaveoneout (M_post); + t_virtual(:, i) = stk_benchmark_ (testfun, 2, nrep); + + testfun = @() stk_predict_leaveoneout_direct (M_post); + t_direct(:, i) = stk_benchmark_ (testfun, 2, nrep); +end + +% Express results in ms +t_virtual = t_virtual * 1000; +t_direct = t_direct * 1000; + +t = stk_dataframe (zeros (m, 4), {'virtual', '[mad]', 'direct', '[mad]'}); +for i = 1:m + t.rownames{i} = sprintf ('n = % 3d', n(i)); + t(i, 1) = median (t_virtual(:, i)); + t(i, 2) = median (abs (t_virtual(:, i) - t.virtual(i))); + t(i, 3) = median (t_direct(:, i)); + t(i, 4) = median (abs (t_direct(:, i) - t.direct(i))); +end + +if nargout == 0 + loocv_benchmark_results = t; + display (loocv_benchmark_results); +else + t_out = t; +end + +end % function diff -Nru octave-stk-2.4.2/inst/misc/benchmarks/stk_benchmark_.m octave-stk-2.5.0/inst/misc/benchmarks/stk_benchmark_.m --- octave-stk-2.4.2/inst/misc/benchmarks/stk_benchmark_.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/benchmarks/stk_benchmark_.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,63 @@ +% STK_BENCHMARK_ Benchmark stk_predict + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function t = stk_benchmark_ (testfun, nargout, nrep) + +varargout = cell (1, nargout); + +% First, warm up + choose number of repetitions +nrep_internal = 1; +ok = false; +while ~ ok + + tic; + for ii = 1:nrep_internal + [varargout{:}] = testfun (); %#ok<*NASGU> + end + t_ = toc (); + + if t_ > 1e-2 + ok = true; + else + nrep_internal = nrep_internal * 2; + end +end + +% Do the actual measurements +t = zeros (1, nrep); +for i = 1:nrep + + tic; + for ii = 1:nrep_internal + [varargout{:}] = testfun (); %#ok<*NASGU> + end + t(i) = toc / nrep_internal; + +end + +end % function diff -Nru octave-stk-2.4.2/inst/misc/benchmarks/stk_benchmark_predict.m octave-stk-2.5.0/inst/misc/benchmarks/stk_benchmark_predict.m --- octave-stk-2.4.2/inst/misc/benchmarks/stk_benchmark_predict.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/benchmarks/stk_benchmark_predict.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,92 @@ +% STK_BENCHMARK_PREDICT Benchmark stk_predict + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function t_out = stk_benchmark_predict () + +nrep = 100; + +n_obs_list = [1 10 100]; +n_prd_list = [1 10 100 1000]; + +[n_obs, n_prd] = ndgrid (n_obs_list, n_prd_list); +m = numel (n_obs); + +t = zeros (nrep, m); + +M_prior = test_A_init (); + +for i = 1:m + fprintf ('i = %d/%d...\n', i, m); + testfun = @() test_A (M_prior, n_obs(i), n_prd(i)); + t(:, i) = stk_benchmark_ (testfun, 1, nrep); +end + +% Express results in ms +t = t * 1000; + +t_out = stk_dataframe (zeros (m, 2), {'median', 'mad'}); +for i = 1:m + t_out.rownames{i} = sprintf ('% 4d /% 4d', n_obs(i), n_prd(i)); + t_out.median(i) = median (t(:, i)); + t_out.mad(i) = median (abs (t(:, i) - t_out.median(i))); +end + +% Boxplots (if available) +h_fig = stk_figure ('stk_benchmark_predict'); +try + boxplot (log10 (t * 1000)); + set(gca (), 'xticklabel', t_out.rownames); + stk_labels ('n_{obs} / n_{pred}', 'log10 (t) [ms]'); +catch + close (h_fig); +end + +end % function + + +function M_prior = test_A_init () + +% M_prior = stk_model ('stk_materncov32_iso'); +% M_prior.param = [0; 0]; + +% This works even in very releases of STK +M_prior = stk_model (); +M_prior.covariance_type = 'stk_materncov32_iso'; +M_prior.param = [0; 0]; + +end % function + + +function z_prd = test_A (M_prior, n_obs, n_prd) + +x_obs = (linspace (0, 1, n_obs))'; +z_obs = sin (x_obs); +x_prd = rand (n_prd, 1); +z_prd = stk_predict (M_prior, x_obs, z_obs, x_prd); + +end diff -Nru octave-stk-2.4.2/inst/misc/dist/stk_gpquadform.m octave-stk-2.5.0/inst/misc/dist/stk_gpquadform.m --- octave-stk-2.4.2/inst/misc/dist/stk_gpquadform.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/dist/stk_gpquadform.m 2017-09-13 07:51:00.000000000 +0000 @@ -3,7 +3,7 @@ % CALL: Q = stk_gpquadform (X, Y, RX, RY) % % computes a matrix Q, whose entries Q(i,j) are given by a Gibbs- -% Paciorek quadratic form +% Paciorek quadratic form % % Q(i,j) = \sum_{k = 1}^d (X(i,k) - Y(j,k))^2 / R(i,j,k)^2, % @@ -18,6 +18,7 @@ % Copyright Notice % +% Copyright (C) 2017 CentraleSupelec % Copyright (C) 2013, 2014 SUPELEC % % Author: Julien Bect @@ -44,22 +45,12 @@ function Q = stk_gpquadform (x, y, rx, ry, pairwise) -if nargin > 5, - stk_error ('Too many input arguments.', 'TooManyInputArgs'); -end - -% read argument #1 -if isstruct (x), - x = x.a; -end - -% read argument #2 -if isstruct (y), - y = y.a; +if nargin > 5 + stk_error ('Too many input arguments.', 'TooManyInputArgs'); end % read argument #4 -if nargin < 4, +if nargin < 4 if isempty (y) ry = rx; else @@ -69,13 +60,13 @@ else if (isempty (y)) && (~ isempty (ry)) && (~ isequal (rx, ry)) errmsg = 'ry should be empty or equal to rx'; - stk_error (errmsg, 'IncorrectArgument'); + stk_error (errmsg, 'InvalidArgument'); end end - + % read argument #5 -if nargin < 5, +if nargin < 5 pairwise = false; else if ~ islogical (pairwise) @@ -120,14 +111,6 @@ %!error Q = stk_gpquadform(x, rx, z, ry) %% -% Check that ".a" structures are accepted - -%!test -%! Dxy1 = stk_gpquadform(x, y, rx, ry); -%! Dxy2 = stk_gpquadform(struct('a', x), struct('a', y), rx, ry); -%! assert(stk_isequal_tolabs(Dxy1, Dxy2)); - -%% % Tests with r = 1/sqrt(2) %!shared x, y, z, rx, ry, rz diff -Nru octave-stk-2.4.2/inst/misc/distrib/stk_distrib_normal_crps.m octave-stk-2.5.0/inst/misc/distrib/stk_distrib_normal_crps.m --- octave-stk-2.4.2/inst/misc/distrib/stk_distrib_normal_crps.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/distrib/stk_distrib_normal_crps.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,145 @@ +% STK_DISTRIB_NORMAL_CRPS computes the CRPS for Gaussian predictive distributions +% +% CALL: CRPS = stk_distrib_normal_crps (Z, MU, SIGMA) +% +% computes the Continuous Ranked Probability Score (CRPS) of Z with respect +% to a Gaussian predictive distribution with mean MU and standard deviation +% SIGMA. +% +% The CRPS is defined as the integral of the Brier score for the event +% {Z <= z}, when z ranges from -inf to +inf: +% +% CRPS = int_{-inf}^{+inf} [Phi((z - MU)/SIGMA) - u(z - Z)]^2 dz, +% +% where Phi is the normal cdf and u the Heaviside step function. The CRPS +% is equal to zero if, and only if, the predictive distribution is a Dirac +% distribution (SIGMA = 0) and the observed value is equal to the predicted +% value (Z = MU). +% +% REFERENCE +% +% [1] Tilmann Gneiting and Adrian E. Raftery, "Strictly proper scoring +% rules, prediction, and estimation", Journal of the American +% Statistical Association, 102(477):359-378, 2007. +% +% See also: stk_distrib_normal_cdf, stk_predict_leaveoneout + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec & LNE +% +% Authors: Remi Stroh +% Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function crps = stk_distrib_normal_crps(z, mu, sigma) + +if nargin > 4 + stk_error('Too many inputs arguments.', 'TooManyInputArgs'); +end + + +%% Center and reduce the data + +if nargin > 1 && ~ isempty (mu) + delta = bsxfun (@minus, z, mu); % compute z - m +else + % Default: mu = 0; + delta = z; +end + +if nargin > 2 && ~ isempty (sigma) + sigma(sigma < 0) = nan; +else + % Default: sigma = 1 + sigma = 1; +end + +% Check size +[delta, sigma] = stk_commonsize (delta, sigma); + + +%% Formula for CRPS + +crps = nan (size (delta)); + +b0 = ~ (isnan (delta) | isnan (sigma)); +b1 = (sigma > 0); + +% Compute the CRPS where sigma > 0 +b = b0 & b1; +if any (b) + u = delta(b) ./ sigma(b); % (z - m)/s + crps(b) = sigma(b) .* (2 * stk_distrib_normal_pdf (u)... + + u .* (2 * stk_distrib_normal_cdf (u) - 1)) - sigma(b) / (sqrt (pi)); +end + +% Compute the CRPS where sigma == 0: CRPS = abs(z - mu) +b = b0 & (~ b1); +crps(b) = abs (delta(b)); + +% Correct numerical inaccuracies +crps(crps < 0) = 0; + +end + + +% Check particular values + +%!assert (stk_isequal_tolabs (stk_distrib_normal_crps (0.0, 0.0, 0.0), 0.0)) +%!assert (stk_isequal_tolabs (stk_distrib_normal_crps (0.0, 0.0, 1.0), (sqrt(2) - 1)/sqrt(pi))) + +% Compute Continuous Ranked Probability Score (CRPS) + +%!shared n, x_obs, mu, sigma, crps, crps_exp +%! x_obs = [ 1.78; -2.29; -1.62; -5.89; 2.88; 0.65; 2.74; -3.42]; % observations +%! mu = [-0.31; -0.59; 1.48; -1.57; -0.05; -0.27; 1.05; 1.27]; % predictions +%! sigma = [ 2.76; 6.80; 1.63; 1.19; 4.98; 9.60; 5.85; 2.24]; % standard dev +%! n = size(x_obs, 1); +%! crps = stk_distrib_normal_crps (x_obs, mu, sigma); + +%!assert (isequal (size (crps), [n, 1])) +%!assert (all (crps >= 0)) +%!assert (stk_isequal_tolabs (crps, stk_distrib_normal_crps(mu, x_obs, sigma))) + +%!assert (stk_isequal_tolabs (stk_distrib_normal_crps (x_obs, mu, 0), abs (x_obs - mu))) + +% % Numerical integration to get the reference results used below +% crps_ref = nan (n, 1); +% for k = 1:n +% x1 = linspace (mu(k) - 6*sigma(k), x_obs(k), 2e6); +% x2 = linspace (x_obs(k), mu(k) + 6*sigma(k), 2e6); +% F1 = stk_distrib_normal_cdf (x1, mu(k), sigma(k)) .^ 2; +% F2 = stk_distrib_normal_cdf (mu(k), x2, sigma(k)) .^ 2; +% crps_ref(k) = trapz ([x1 x2], [F1 F2]); +% end + +%! crps_ref = [ ... +%! 1.247856605928301 ... +%! 1.757798727719891 ... +%! 2.216236225997414 ... +%! 3.648696666764968 ... +%! 1.832355265287495 ... +%! 2.278618297947438 ... +%! 1.560544734359158 ... +%! 3.455697443411153 ]; +%! assert (stk_isequal_tolabs (crps, crps_ref, 1e-10)); diff -Nru octave-stk-2.4.2/inst/misc/error/stk_error.m octave-stk-2.5.0/inst/misc/error/stk_error.m --- octave-stk-2.4.2/inst/misc/error/stk_error.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/error/stk_error.m 2017-09-13 07:51:00.000000000 +0000 @@ -37,7 +37,7 @@ try stack = dbstack ('-completenames'); % In Octave, -completenames is at best ignored (in recent versions) - % or generates an error (in, e.g., Octave 3.2.4). + % or generates an error (in, e.g., Octave 3.6.2). catch stack = dbstack (); end diff -Nru octave-stk-2.4.2/inst/misc/mole/graphics_toolkit/graphics_toolkit.m octave-stk-2.5.0/inst/misc/mole/graphics_toolkit/graphics_toolkit.m --- octave-stk-2.4.2/inst/misc/mole/graphics_toolkit/graphics_toolkit.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/mole/graphics_toolkit/graphics_toolkit.m 2017-09-13 07:51:00.000000000 +0000 @@ -6,7 +6,7 @@ % CALL: NAME = graphics_toolkit () % % returns: -% +% % * the result of get (0, 'defaultfigure__backend__') if you're running an old version % of Octave that does not have graphics_toolkit, % @@ -42,8 +42,8 @@ function name = graphics_toolkit () -if isoctave, - +if exist ('OCTAVE_VERSION', 'builtin') == 5 % Octave + try % This should work on older versions of Octave, e.g., 3.2.4 % (there was no notion of a 'toolkit' at the time, but if gnuplot @@ -52,16 +52,16 @@ catch error ('Unable to determine which toolkit is being used.'); end - -else % Matlab - + +else % Matlab + try assert (usejava ('jvm')); name = 'matlab-jvm'; catch name = 'matlab-nojvm'; end - + end end % function diff -Nru octave-stk-2.4.2/inst/misc/mole/isoctave/isoctave.m octave-stk-2.5.0/inst/misc/mole/isoctave/isoctave.m --- octave-stk-2.4.2/inst/misc/mole/isoctave/isoctave.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/mole/isoctave/isoctave.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,42 +0,0 @@ -% ISOCTAVE returns true if Octave is used as an interpreter, false otherwise - -% Copyright Notice -% -% Copyright (C) 2011-2013 SUPELEC -% -% Author: Julien Bect -% -% Note: was called 'stk_is_octave_in_use' in STK <= 2.0.1 - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function octave_in_use = isoctave - -persistent b; - -if isempty (b), - b = (exist ('OCTAVE_VERSION', 'builtin') == 5); - mlock; -end - -octave_in_use = b; - -end % function diff -Nru octave-stk-2.4.2/inst/misc/mole/quantile/quantile.m octave-stk-2.5.0/inst/misc/mole/quantile/quantile.m --- octave-stk-2.4.2/inst/misc/mole/quantile/quantile.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/mole/quantile/quantile.m 2017-09-13 07:51:00.000000000 +0000 @@ -346,8 +346,7 @@ %!error quantile () %!error quantile (1, 2, 3, 4, 5) %!error quantile (['A'; 'B'], 10) -% %!error quantile (1:10, [true, false]) -% % this test fails in Octave 3.2.x +%!error quantile (1:10, [true, false]) %!error quantile (1:10, ones (2,2)) %!error quantile (1, 1, 1.5) %!error quantile (1, 1, 0) diff -Nru octave-stk-2.4.2/inst/misc/optim/@stk_optim_octavesqp/private/sqp_quadprog.m octave-stk-2.5.0/inst/misc/optim/@stk_optim_octavesqp/private/sqp_quadprog.m --- octave-stk-2.4.2/inst/misc/optim/@stk_optim_octavesqp/private/sqp_quadprog.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/optim/@stk_optim_octavesqp/private/sqp_quadprog.m 2017-09-13 07:51:00.000000000 +0000 @@ -452,8 +452,8 @@ try % Call quadprog to solve the QP subproblem quadprog_options = optimset ('Display', 'off'); - [p, obj_qp, quadprog_exitflag, quadprog_output, lambda] = quadprog ... - (B, c, -C, -d, F, g, [], [], x, quadprog_options); %#ok + [p, ignd1, quadprog_exitflag, ignd2, lambda] = quadprog ... + (B, c, -C, -d, F, g, [], [], x, quadprog_options); %#ok CG#07 catch warning (ws); rethrow (lasterror ()); diff -Nru octave-stk-2.4.2/inst/misc/optim/@stk_optim_octavesqp/stk_minimize_boxconstrained.m octave-stk-2.5.0/inst/misc/optim/@stk_optim_octavesqp/stk_minimize_boxconstrained.m --- octave-stk-2.4.2/inst/misc/optim/@stk_optim_octavesqp/stk_minimize_boxconstrained.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/optim/@stk_optim_octavesqp/stk_minimize_boxconstrained.m 2017-09-13 07:51:00.000000000 +0000 @@ -61,6 +61,6 @@ % Note: with this implementation, f_val is computed twice % (once when f is called by sqp, and once again when nabla_f is called) -[f_val, df] = f (u); %#ok +[ignd, df] = f (u); %#ok CG#07 end % function diff -Nru octave-stk-2.4.2/inst/misc/optim/@stk_optim_octavesqp/stk_optim_octavesqp.m octave-stk-2.5.0/inst/misc/optim/@stk_optim_octavesqp/stk_optim_octavesqp.m --- octave-stk-2.4.2/inst/misc/optim/@stk_optim_octavesqp/stk_optim_octavesqp.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/optim/@stk_optim_octavesqp/stk_optim_octavesqp.m 2017-09-13 07:51:00.000000000 +0000 @@ -69,7 +69,7 @@ % Provide default QP solver if needed if isempty (options.qp_solver) - if isoctave + if exist ('OCTAVE_VERSION', 'builtin') == 5 % Octave % Octave's core qp function options.qp_solver = 'qp'; else diff -Nru octave-stk-2.4.2/inst/misc/options/stk_options_set.m octave-stk-2.5.0/inst/misc/options/stk_options_set.m --- octave-stk-2.4.2/inst/misc/options/stk_options_set.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/options/stk_options_set.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,7 +2,7 @@ % Copyright Notice % -% Copyright (C) 2015, 2016 CentraleSupelec +% Copyright (C) 2015-2017 CentraleSupelec % Copyright (C) 2014 SUPELEC & A. Ravisankar % Copyright (C) 2013 SUPELEC % @@ -40,16 +40,16 @@ switch nargin - case 0, % nothing to do, just return the output + case 0 % nothing to do, just return the output - case 1, % reset + case 1 % reset if (ischar (varargin{1})) && strcmp (varargin{1}, 'default') options = init_options (); else stk_error ('Syntax error', 'SyntaxError'); end - case 2, + case 2 switch varargin{1} case 'stk_sf_matern' @@ -63,7 +63,7 @@ options.(varargin{1}) = varargin{2}; end - case 3, + case 3 switch varargin{1} case 'stk_param_estim' @@ -123,7 +123,7 @@ opts.stk_axes.properties = {'FontSize', 8}; % Select optimizer for stk_param_estim -if isoctave +if exist ('OCTAVE_VERSION', 'builtin') == 5 % In Octave we use sqp (which is always available) in both cases opts.stk_param_estim.minimize_box = stk_optim_octavesqp (); opts.stk_param_estim.minimize_unc = stk_optim_octavesqp (); diff -Nru octave-stk-2.4.2/inst/misc/parallel/stk_parallel_start.m octave-stk-2.5.0/inst/misc/parallel/stk_parallel_start.m --- octave-stk-2.4.2/inst/misc/parallel/stk_parallel_start.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/parallel/stk_parallel_start.m 2017-09-13 07:51:00.000000000 +0000 @@ -2,6 +2,7 @@ % Copyright Notice % +% Copyright (C) 2017 CentraleSupelec % Copyright (C) 2013, 2014 SUPELEC % % Author: Julien Bect @@ -33,7 +34,8 @@ if strcmp (class (eng), 'stk_parallel_engine_none') %#ok % use Mathworks' PCT if available - if (~ isoctave) && (exist ('matlabpool','file')) + if (exist ('OCTAVE_VERSION', 'builtin') ~= 5) ... % no Octave + && (exist ('matlabpool', 'file')) eng = stk_parallel_engine_parfor (); stk_parallel_engine_set (eng); end diff -Nru octave-stk-2.4.2/inst/misc/pareto/stk_dominatedhv.m octave-stk-2.5.0/inst/misc/pareto/stk_dominatedhv.m --- octave-stk-2.4.2/inst/misc/pareto/stk_dominatedhv.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/pareto/stk_dominatedhv.m 2017-09-13 07:51:00.000000000 +0000 @@ -95,9 +95,12 @@ if iscell (y), y = cellfun (@(z) wfg_preprocessing (z, y_ref), y, 'UniformOutput', false); else % y is a matrix - if (~ isnumeric (y)) || (ndims (y) ~= 2) %#ok see CODING_GUDELINES - stk_error (['y should be a numeric matrix or ' ... - 'a cell array'], 'IncorrectArgument'); + try + y = double (y); + assert (ndims (y) == 2); %#ok see CODING_GUDELINES + catch + stk_error (['y should either be a cell array or be (convertible ' ... + 'to) a numeric matrix'], 'InvalidArgument'); end y = wfg_preprocessing (y, y_ref); end @@ -145,7 +148,7 @@ % Check the size of y if (p > p_ref) stk_error (['The number of columns the data matrix should not be ' ... - 'larger than the number of columns of y_ref'], 'IncorrectArgument'); + 'larger than the number of columns of y_ref'], 'InvalidArgument'); end % WFG convention: maximization problem @@ -197,6 +200,11 @@ %! assert (stk_isequal_tolrel (hv, hv0, 1e-10)); %!test +%! yy = stk_dataframe (- y); % Check that @stk_dataframe inputs are accepted +%! hv = stk_dominatedhv (yy); +%! assert (stk_isequal_tolrel (hv, hv0, 1e-10)); + +%!test %! hv = stk_dominatedhv (-y, [], 0); %! assert (stk_isequal_tolrel (hv, hv0, 1e-10)); diff -Nru octave-stk-2.4.2/inst/misc/plot/stk_plot1d.m octave-stk-2.5.0/inst/misc/plot/stk_plot1d.m --- octave-stk-2.4.2/inst/misc/plot/stk_plot1d.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/plot/stk_plot1d.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,156 +0,0 @@ -% STK_PLOT1D is a convenient plot function for 1D kriging predictions -% -% CALL: stk_plot1d (XI, ZI, XT, ZT, ZP) -% -% plots the evaluation points (XI, ZI), the "true function" with values -% ZT on the grid XT, and a representation of the prediction ZP on the -% same grid XT: the kriging prediction (posterior mean) surrounded by a -% shaded area corresponding to 95% pointwise confidence intervals. -% -% It is possible to omit plotting either the observations (XI, ZI) or -% the true function ZT by providing empty matrices. -% -% CALL: stk_plot1d (XI, ZI, XT, ZT, ZP, ZSIM) -% -% also plots a set ZSIM of samplepaths. -% -% CALL: stk_plot1d (H_AXES, ...) -% -% plots into existing axes with axis handle H_AXES. - -% Copyright Notice -% -% Copyright (C) 2015-2016 CentraleSupelec -% Copyright (C) 2011-2014 SUPELEC -% -% Authors: Julien Bect -% Emmanuel Vazquez - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function h_plot = stk_plot1d (varargin) - -% Extract axis handle (if it is present) -[h_axes, varargin] = stk_plot_getaxesarg (varargin{:}); - -h_plot = stk_plot1d_ (h_axes, varargin{:}); - -end % function - - -function h = stk_plot1d_ (h_axes, xi, zi, xt, zt, zp, zsim) - -has_zt_arg = (nargin > 4) && (~ isempty (zt)); -has_zp_arg = (nargin > 5) && (~ isempty (zp)); -has_zsim_arg = (nargin > 6) && (~ isempty (zsim)); - -% Shaded area representing pointwise confidence intervals -if has_zp_arg - h_ci = stk_plot_shadedci (h_axes, xt, zp); - hold on; -else - h_ci = []; -end - -% Plot sample paths -if has_zsim_arg - if isa (zsim, 'stk_dataframe') - % Prevents automatic creation of a legend by @stk_dataframe/plot - zsim.colnames = {}; - end - h_sim = plot (h_axes, xt, zsim, ... - '-', 'LineWidth', 1, 'Color', [0.39, 0.47, 0.64]); - hold on; -else - h_sim = []; -end - -% Ground truth -if has_zt_arg - h_truth = plot (h_axes, xt, zt, ... - '--', 'LineWidth', 3, 'Color', [0.39, 0.47, 0.64]); - hold on; -else - h_truth = []; -end - -% Kriging predictor (posterior mean) -if has_zp_arg - h_pred = plot (h_axes, xt, zp.mean, ... - 'LineWidth', 3, 'Color', [0.95 0.25 0.3]); - hold on; -else - h_pred = []; -end - -% Evaluations -if ~ isempty (zi) - h_obs = plot (h_axes, xi, zi, ... - 'ko', 'MarkerSize', 6, 'MarkerFaceColor', 'k'); -else - h_obs = []; -end - -hold off; set (gca, 'box', 'off'); - -% Prepare for the legend -h_list = []; -s_list = {}; -if ~ isempty (h_truth) - h_list = [h_list; h_truth]; - s_list = [s_list; {'True function'}]; -end -if ~ isempty (h_obs) - h_list = [h_list; h_obs]; - s_list = [s_list; {'Observations'}]; -end -if ~ isempty (h_pred) - h_list = [h_list; h_pred]; - s_list = [s_list; {'Posterior mean'}]; -end -if ~ isempty (h_ci) - h_list = [h_list; h_ci]; - s_list = [s_list; {'95% credible interval'}]; -end -if ~ isempty (h_sim) - h_list = [h_list; h_sim(1)]; - s_list = [s_list; {'Samplepaths'}]; -end - -% Create the legend -try - h_legend = legend (h_list, s_list{:}); - set (h_legend, 'Color', 0.98 * [1 1 1]); - legend (h_axes, 'hide'); -catch - % The above call to legend is expected to fail in octave 3.2.x since the - % syntax with a list of handles was not implemented back then. - warning ('Failed to create the legend object.'); -end - -% Make it possible to recover all the handles easily, if needed -h.truth = h_truth; -h.obs = h_obs; -h.pred = h_pred; -h.ci = h_ci; -h.sim = h_sim; - -end % function diff -Nru octave-stk-2.4.2/inst/misc/plot/stk_plot_histnormres.m octave-stk-2.5.0/inst/misc/plot/stk_plot_histnormres.m --- octave-stk-2.4.2/inst/misc/plot/stk_plot_histnormres.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/plot/stk_plot_histnormres.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,82 +0,0 @@ -% STK_PLOT_HISTNORMRES plots an histogram for normalized residuals -% -% CALL: H = stk_plot_histnormres (NORM_RES, ...) -% -% CALL: H = stk_plot_histnormres (H_AXES, NORM_RES, ...) -% -% See also stk_predict_leaveoneout, stk_example_kb10 - -% Copyright Notice -% -% Copyright (C) 2016, 2017 CentraleSupelec -% -% Author: Julien Bect - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function h = stk_plot_histnormres (varargin) - -[h_axes, varargin, n_argin] = stk_plot_getaxesarg (varargin{:}); - -if n_argin >= 1 - norm_res = double (varargin{1}); - opts = varargin(2:end); -else - stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); -end - -% Ignore infinite normalized residuals, with a warning -b = isinf (norm_res); -if any (b) - warning (sprintf ('Ignoring %d infinite normalized resiudals.', sum (b))); - norm_res = norm_res(~ b); -end - -% Choose the number of bins using the Freedman-Diaconis rule -n = length (norm_res); -q = quantile (norm_res, [0 0.25 0.75 1]); -binsize = 2 * (q(3) -q(2)) * (n ^ (- 1/3)); -nbins = ceil ((q(4) - q(1)) / binsize); - -% Compute and plot histogram pdf -[count, rr] = hist (norm_res, nbins); -pdf = count / (n * (rr(2) - rr(1))); -h.hist = bar (rr, pdf, 'hist'); hold on; - -% Center view -M = max (3, max (abs (xlim ()))); xlim ([-M, M]); - -% Plot reference N(0, 1) pdf -rr = linspace (-M, M, 100); -pdf_ref = 1 / (sqrt (2 * pi)) * (exp (- 0.5 * (rr .^ 2))); -h.ref_pdf = plot (rr, pdf_ref, 'r--'); - -% Apply options -if ~ isempty (opts) - set (h.hist, opts{:}); -end - -% Create labels -h_labels = stk_labels (h_axes, 'normalized residuals', 'probability density'); -h.xlabel = h_labels(1); -h.ylabel = h_labels(2); - -end % function diff -Nru octave-stk-2.4.2/inst/misc/plot/stk_plot_predvsobs.m octave-stk-2.5.0/inst/misc/plot/stk_plot_predvsobs.m --- octave-stk-2.4.2/inst/misc/plot/stk_plot_predvsobs.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/plot/stk_plot_predvsobs.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,70 +0,0 @@ -% STK_PLOT_PREDVSOBS plots predictions against observations -% -% CALL: H = stk_plot_predvsobs (Z_OBS, Z_PRED, ...) -% -% CALL: H = stk_plot_predvsobs (H_AXES, Z_OBS, Z_PRED, ...) -% -% See also stk_predict_leaveoneout, stk_example_kb10 - -% Copyright Notice -% -% Copyright (C) 2016 CentraleSupelec -% -% Author: Julien Bect - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function h = stk_plot_predvsobs (varargin) - -[h_axes, varargin, n_argin] = stk_plot_getaxesarg (varargin{:}); - -if n_argin >= 2 - y = varargin{1}; - y_pred = varargin{2}; - opts = varargin(3:end); -else - stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); -end - -% Extract numerical predictions -try - y_pred = y_pred.mean; -catch - y_pred = double (y_pred); -end - -% Plot prediction versus truth -h.data = plot (h_axes, y, y_pred, 'kd'); hold on; - -% Plot "reference" line y_LOO = y -h.refline = plot (h_axes, xlim, xlim, 'r--'); - -% Apply options -if ~ isempty (opts) - set (h.data, opts{:}); -end - -% Create labels -h_labels = stk_labels (h_axes, 'Observations', 'Predictions'); -h.xlabel = h_labels(1); -h.ylabel = h_labels(2); - -end % function diff -Nru octave-stk-2.4.2/inst/misc/plot/stk_plot_shadedci.m octave-stk-2.5.0/inst/misc/plot/stk_plot_shadedci.m --- octave-stk-2.4.2/inst/misc/plot/stk_plot_shadedci.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/plot/stk_plot_shadedci.m 2017-09-13 07:51:00.000000000 +0000 @@ -5,7 +5,7 @@ % Copyright Notice % -% Copyright (C) 2015, 2016 CentraleSupelec +% Copyright (C) 2015-2017 CentraleSupelec % Copyright (C) 2012, 2013 SUPELEC % % Authors: Julien Bect @@ -37,18 +37,54 @@ x = double (x); -delta = 1.96 * sqrt (abs (z.var)); -h_plot = area (h_axes, x, [z.mean - delta, 2 * delta]); - -% Remove the first area object (between 0 and z.mean - delta) -delete (h_plot(1)); h_plot = h_plot(2); +% Avoid a dependency on the stat toolbox in Matlab: +% norminv (1 - 0.05/2) = 1.9600 +% norminv (1 - 0.01/2) = 2.5758 +% norminv (1 - 0.001/2) = 3.2905 +delta0 = [3.2905 2.5758 1.9600]; +gray_level = [0.95 0.88 0.80]; + +% Use fill or area ? +persistent use_fill +if isempty (use_fill) + v = regexp (version (), '^[0-9]*\.', 'match'); + + if exist ('OCTAVE_VERSION', 'builtin') + % In Octave 3.x, prefer area. There are several problems with fill + use_fill = (str2double (v{1}) >= 4); + else + % Problem: fill does not support the h_axes argument in Matlab < R2016a + use_fill = (str2double (v{1}) >= 9); % 9.0 is R2016a + end +end -c = [0.8 0.8 0.8]; % Light gray -set (h_plot, 'FaceColor', c, 'LineStyle', '-', 'LineWidth', 1, 'EdgeColor', c); -if ~ isempty (opts) - set (h_plot, opts{:}); +for k = 1:3 + + delta = delta0(k) * sqrt (abs (z.var)); + patch_color = gray_level(k) * [1 1 1]; + + if use_fill + xx = [x; flipud(x)]; + zz = [z.mean - delta; flipud(z.mean + delta)]; + h_plot = fill (h_axes, xx, zz, patch_color, 'EdgeColor', patch_color); + else + h_plot = area (h_axes, x, [z.mean - delta, 2 * delta]); + % Remove the first area object (between 0 and z.mean - delta) + delete (h_plot(1)); h_plot = h_plot(2); + set (h_plot, 'FaceColor', patch_color, 'LineStyle', '-', ... + 'LineWidth', 1, 'EdgeColor', patch_color); + end + hold on; + + % The options in 'opts', if any, are applied to all patch objects + if ~ isempty (opts) + set (h_plot, opts{:}); + end + end +hold off; + % Raise current axis to the top layer, to prevent it % from being hidden by the grayed area set (gca, 'Layer', 'top'); @@ -61,7 +97,7 @@ % Extract axis handle (if it is present) [h_axes, varargin, n_argin] = stk_plot_getaxesarg (varargin{:}); -if n_argin < 2, +if n_argin < 2 stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); end diff -Nru octave-stk-2.4.2/inst/misc/test/stk_runtests.m octave-stk-2.5.0/inst/misc/test/stk_runtests.m --- octave-stk-2.4.2/inst/misc/test/stk_runtests.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/test/stk_runtests.m 2017-09-13 07:51:00.000000000 +0000 @@ -1,10 +1,19 @@ % STK_RUNTESTS runs all tests in a given directory (or in STK's searchpath). +% +% FIXME: missing doc % Copyright Notice % -% Copyright (C) 2015 CentraleSupelec +% Copyright (C) 2015, 2017 CentraleSupelec +% Copyright (C) 2012-2014 SUPELEC % % Author: Julien Bect +% +% This file has been adapted from runtests.m in Octave 3.6.2 (which is +% distributed under the GNU General Public Licence version 3 (GPLv3)). +% The original copyright notice was as follows: +% +% Copyright (C) 2010-2012 John W. Eaton % Copying Permission Statement % @@ -26,14 +35,266 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function stk_runtests (directory) +%% Original Octave doc, to be adapted +% -*- texinfo -*- +% @deftypefn {Function File} {} runtests () +% @deftypefnx {Function File} {} runtests (@var{directory}) +% Execute built-in tests for all function files in the specified directory. +% If no directory is specified, operate on all directories in Octave's +% search path for functions. +% @seealso{rundemos, path} +% @end deftypefn + +function stk_runtests (varargin) + +if (exist ('OCTAVE_VERSION', 'builtin') == 5) ... + && (exist ('__run_test_suite__', 'file') == 2) + + % Use the original __run_test_suite__ function, shipped with Octave + if nargin == 0 + % Scan all STK directories if no input argument is provided + directory = fileparts (fileparts (fileparts (mfilename ('fullpath')))); + else + directory = varargin{1}; + end + + % NOTE: feval prevents Matlab from complaining about the underscores + feval ('__run_test_suite__', {directory}, {}); + +else % Matlab + + % Use the replacement that is provided with STK + stk_runtests_ (varargin{:}); + +end % if + +end % function + + +function stk_runtests_ (directory) if nargin == 0 % scan all STK directories if no input argument is provided - directory = fileparts (fileparts (fileparts (mfilename ('fullpath')))); + dirs = stk_init ('genpath'); +else + % otherwise, directory is expected to be a valid directory name + if ~ exist (directory, 'dir') + error ('Directory not found.'); + end + here = pwd (); + cd (directory); + dirs = {pwd()}; % get absolute path + cd (here); +end + +% number of directories to be explored +nb_topdirs = numel(dirs); + +% run tests all available tests in each directory +n_total = 0; n_pass = 0; n_files = 0; n_notest = 0; n_dirs = 0; err = {}; +for i = 1:nb_topdirs + [np, nt, nn, nf, nd, err] = run_all_tests (dirs{i}, dirs{i}, err); + n_total = n_total + nt; + n_pass = n_pass + np; + n_files = n_files + nf; + n_notest = n_notest + nn; + n_dirs = n_dirs + nd; +end + +if n_dirs > 1, + fprintf ('*** Summary for all %d directories:\n', n_dirs); + fprintf ('*** --> passed %d/%d tests\n', n_pass, n_total); + fprintf ('*** --> %d/%d files had no tests\n\n', n_notest, n_files); +end + +if ~ isempty (err) + fprintf ('!!! Summary of failed tests:\n'); + for i = 1:(size (err, 1)) + fprintf ('!!! %s [%d/%d]\n', err{i,1}, err{i,2} - err{i,3}, err{i,2}); + end +end + +end % function + + +%%%%%%%%%%%%%%%%% +% run_all_tests % +%%%%%%%%%%%%%%%%% + +function [n_pass, n_total, n_notest, n_files, n_dirs, err] ... + = run_all_tests (testdir, basedir, err) + +% list directory content +dirinfo = dir(testdir); +flist = {dirinfo.name}; + +here = pwd (); cd (basedir); + +fprintf ('Processing files in %s:\n\n', testdir); +fflush (stdout); + +% init counters +n_total = 0; +n_pass = 0; +n_files = 0; +n_notest = 0; +n_dirs = 1; + +% list of subdirectories to be processed +subdirs_class = {}; +subdirs_private = {}; + +for i = 1:numel (flist) + f = flist{i}; + ff = fullfile(testdir, f); + if (length (f) > 2) && strcmp (f((end-1):end), '.m') + n_files = n_files + 1; + print_test_file_name (f); + if has_tests (ff) + % Silence all warnings & prepare for warning detection. + s = warning_off (); + try + % Do the actual tests. + [p, n] = stk_test (ff, 'quiet', stdout); + % Note: the presence of the third argument (fid=stdout) forces + % stk_test in batch mode, which means that it doesn't stop at + % the first failed test. + print_pass_fail (n, p); + n_total = n_total + n; + n_pass = n_pass + p; + % Record function name if at least one test failed + if p < n, + err = [err; {ff, n, p}]; + end + % deal with warnings + if ~ isempty (lastwarn ()), + fprintf (' (warnings)'); + end + warning (s); + catch + % Restore warning state after error + warning (s); + rethrow (lasterror ()); + end + else + n_notest = n_notest + 1; + fprintf (' NO TESTS'); + end + fprintf ('\n'); + fflush (stdout); + elseif dirinfo(i).isdir && (f(1) == '@') + subdirs_class{end+1} = ff; + elseif dirinfo(i).isdir && strcmp(f, 'private') + subdirs_private{end+1} = ff; + end +end +fprintf (' --> passed %d/%d tests\n', n_pass, n_total); +fprintf (' --> %d/%d files had no tests\n', n_notest, n_files); +fprintf ('\n'); + +for i = 1:(length (subdirs_class)) + + [p, n, nnt, nf, nd, err] = run_all_tests ... + (subdirs_class{i}, pwd(), err); + + n_total = n_total + n; + n_pass = n_pass + p; + n_files = n_files + nf; + n_notest = n_notest + nnt; + n_dirs = n_dirs + nd; +end + +for i = 1:(length (subdirs_private)) + + [p, n, nnt, nf, nd, err] = run_all_tests ... + (subdirs_private{i}, subdirs_private{i}, err); + + n_total = n_total + n; + n_pass = n_pass + p; + n_files = n_files + nf; + n_notest = n_notest + nnt; + n_dirs = n_dirs + nd; +end + +cd (here); + +end % function + + +%%%%%%%%%%%%% +% has_tests % +%%%%%%%%%%%%% + +function retval = has_tests (f) + +fid = fopen (f); +if (fid >= 0) + str = fread (fid, '*char')'; + fclose (fid); + retval = ~ isempty (regexp ... + (str, '^%!(test|assert|error|warning)', 'lineanchors')); +else + error ('runtests: fopen failed: %s', f); +end + +end % function + + +%%%%%%%%%%%%%%%%%%% +% print_pass_fail % +%%%%%%%%%%%%%%%%%%% + +function print_pass_fail (n, p) + +if (n > 0) + fprintf (' PASS %2d/%-2d', p, n); + nfail = n - p; + if (nfail > 0) + fprintf (' FAIL %d', nfail); + end +end + +end % function + + +%%%%%%%%%%%%%%%%%%%%%%%% +% print_test_file_name % +%%%%%%%%%%%%%%%%%%%%%%%% + +function print_test_file_name (nm) + +filler = repmat ('.', 1, 50 - length(nm)); +fprintf (' %s %s', nm, filler); + +end % function + + +%%%%%%%%%%%%%%% +% warning_off % +%%%%%%%%%%%%%%% + +function s = warning_off () + +s = warning ('off', 'all'); + +% Check whether warnings can be still be recovered by lastwarn +% (this is not the case in Octave 3.8.2, for example; +% see https://savannah.gnu.org/bugs/?41028) + +lastwarn (''); +warning ('ah:ah', 'toto'); +[msg, id] = lastwarn (); + +if ~ (strcmp (id, 'ah:ah') && strcmp (msg, 'toto')) + warning ('on', 'all'); + for i = 1:(length (s)) + if ~ isempty (regexp (s(i).identifier, '^Octave:', 'once')) + warning (s(i).state, s(i).identifier); + end + end end -__run_test_suite__ ({directory}, {}); +lastwarn (''); end % function diff -Nru octave-stk-2.4.2/inst/misc/test/stk_test.m octave-stk-2.5.0/inst/misc/test/stk_test.m --- octave-stk-2.4.2/inst/misc/test/stk_test.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/test/stk_test.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,708 @@ +% STK_TEST performs tests for a given M-file. +% +% FIXME: missing doc + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% Copyright (C) 2012, 2013 SUPELEC +% +% Authors: Julien Bect +% Emmanuel Vazquez +% +% This file has been adapted from test.m in Octave 3.6.2, distributed +% under the GNU General Public Licence version 3 (GPLv3). The original +% copyright notice was as follows: +% +% Copyright (C) 2005-2012 Paul Kienzle + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +%% +% Octave doc, to be adapted... +% +% -*- texinfo -*- +% @deftypefn {Command} {} test @var{name} +% @deftypefnx {Command} {} test @var{name} quiet|normal|verbose +% @deftypefnx {Function File} {} test ('@var{name}', 'quiet|normal|verbose', @var{fid}) +% @deftypefnx {Function File} {} test ([], 'explain', @var{fid}) +% @deftypefnx {Function File} {@var{success} =} test (@dots{}) +% @deftypefnx {Function File} {[@var{n}, @var{max}] =} test (@dots{}) +% @deftypefnx {Function File} {[@var{code}, @var{idx}] =} test ('@var{name}', 'grabdemo') +% +% Perform tests from the first file in the loadpath matching @var{name}. +% @code{test} can be called as a command or as a function. Called with +% a single argument @var{name}, the tests are run interactively and stop +% after the first error is encountered. +% +% With a second argument the tests which are performed and the amount of +% output is selected. +% +% @table @asis +% @item 'quiet' +% Don't report all the tests as they happen, just the errors. +% +% @item 'normal' +% Report all tests as they happen, but don't do tests which require +% user interaction. +% +% @item 'verbose' +% Do tests which require user interaction. +% @end table +% +% The argument @var{fid} can be used to allow batch processing. Errors +% can be written to the already open file defined by @var{fid}, and +% hopefully when Octave crashes this file will tell you what was happening +% when it did. You can use @code{stdout} if you want to see the results as +% they happen. You can also give a file name rather than an @var{fid}, in +% which case the contents of the file will be replaced with the log from +% the current test. +% +% Called with a single output argument @var{success}, @code{test} returns +% true if all of the tests were successful. Called with two output arguments +% @var{n} and @var{max}, the number of successful tests and the total number +% of tests in the file @var{name} are returned. +% +% If the second argument is 'explain', then @var{name} is ignored and an +% explanation of the line markers used is written to the file @var{fid}. +% @seealso{assert, error, example} +% @end deftypefn + +function varargout = stk_test (varargin) + +varargout = cell (1, nargout); + +if exist ('OCTAVE_VERSION', 'builtin') == 5 + + % Use the original test function shipped with Octave + [varargout{:}] = test (varargin{:}); + +else % Matlab + + % Use the one that is provided with STK + [varargout{:}] = stk_test_ (varargin{:}); + +end % if + +end % function + + +function [x__ret1, x__ret2, x__ret3] = stk_test_ (x__name, x__flag, x__fid) + +SIGNAL_FAIL = '!!!!! '; % prefix: test had an unexpected result +SIGNAL_EMPTY = '????? '; % prefix: no tests in file +SIGNAL_BLOCK = '***** '; % prefix: code for the test +SIGNAL_FILE = '>>>>> '; % prefix: new test file + +nb_expected_failures = 0; % counter for expected failures ('xtest' blocks) + +% default value for input arg #2: 'quiet' +if nargin < 2 || isempty(x__flag), x__flag = 'quiet'; end + +% default value for input arg #3: [] (interactive mode, output --> stdout) +if nargin < 3, x__fid = []; end + +if (nargin < 1) || (nargin > 3), + error('Incorrect number of input arguments.'); +end + +% first argument must be a non-empty string +if isempty(x__name) || ~ischar(x__name), + error('The first argument of stk_test() must be a non-empty string'); +end + +% second argument must be a non-empty string +if ~isempty(x__flag) && ~ischar(x__flag), + error('The first argument of stk_test() must be either empty or a string'); +end + +x__batch = (~ isempty (x__fid)); + +% Decide if error messages should be collected. +x__close_fid = 0; +if (x__batch) + if (ischar (x__fid)) + x__fid = fopen (x__fid, 'wt'); + if (x__fid < 0) + error ('test: could not open log file'); + end + x__close_fid = 1; + end + %fprintf (x__fid, '%sprocessing %s\n', SIGNAL_FILE, x__name); + %fflush (x__fid); +else + x__fid = stdout; +end + +switch x__flag, + case 'normal', + x__verbose = x__batch; + case 'quiet', + x__verbose = 0; + case 'verbose', + x__verbose = 1; + otherwise, + error('test: unknown flag ''%s''', x__flag); +end + +% Locate the file to test. +x__file = file_in_loadpath (x__name, 'all'); +if (isempty (x__file)) + x__file = file_in_loadpath ([x__name, '.m'], 'all'); +end +if (isempty (x__file)) + x__file = file_in_loadpath ([x__name, '.cc'], 'all'); +end + +if (iscell (x__file)) + % If repeats, return first in path. + if (isempty (x__file)) + x__file = ''; + else + x__file = x__file{1}; + end +end +if (isempty (x__file)) + if (exist (x__name) == 3) + fprintf (x__fid, '%s%s source code with tests for dynamically linked function not found\n', SIGNAL_EMPTY, x__name); + else + fprintf (x__fid, '%s%s does not exist in path\n', SIGNAL_EMPTY, x__name); + end + fflush (x__fid); + if (nargout > 0) + x__ret1 = 0; x__ret2 = 0; + end + if (x__close_fid) + fclose(x__fid); + end + return; +end + +% Grab the test code from the file. +x__body = x__extract_test_code (x__file); + +if (isempty (x__body)) + fprintf (x__fid, '%s%s has no tests available\n', SIGNAL_EMPTY, x__file); + fflush (x__fid); + if (nargout > 0) + x__ret1 = 0; x__ret2 = 0; + end + if (x__close_fid) + fclose(x__fid); + end + return; +else + % Add a dummy comment block to the end for ease of indexing. + if (x__body (length(x__body)) == sprintf('\n')) + x__body = sprintf ('\n%s%%', x__body); + else + x__body = sprintf ('\n%s\n%%', x__body); + end +end + +% Chop it up into blocks for evaluation. +x__lineidx = find (x__body == sprintf('\n')); +x__blockidx = x__lineidx(find (~ isspace (x__body(x__lineidx+1))))+1; + +% Ready to start tests ... if in batch mode, tell us what is happening. +if (x__verbose) + disp ([SIGNAL_FILE, x__file]); +end + +% Assume all tests will pass. +x__all_success = 1; + +% Process each block separately, initially with no shared variables. +x__tests = 0; x__successes = 0; +x__shared_names = {}; +x__shared_vals = {}; +for x__i = 1:length(x__blockidx)-1 + + % Extract the block. + x__block = x__body(x__blockidx(x__i):x__blockidx(x__i+1)-2); + + % Let the user/logfile know what is happening. + if (x__verbose) + fprintf (x__fid, '%s%s\n', SIGNAL_BLOCK, x__block); + fflush (x__fid); + end + + % Split x__block into x__type and x__code. + x__idx = find (~ isletter (x__block)); + if (isempty (x__idx)) + x__type = x__block; + x__code = ''; + else + x__type = x__block(1:x__idx(1)-1); + x__code = x__block(x__idx(1):length(x__block)); + end + + % Assume the block will succeed. + x__success = 1; + x__msg = []; + + %%% SHARED + + if (strcmp (x__type, 'shared')) + x__istest = 0; + + % Separate initialization code from variables. + x__idx = find (x__code == sprintf('\n')); + if (isempty (x__idx)) + x__vars = x__code; + x__code = ''; + else + x__vars = x__code (1:x__idx(1)-1); + x__code = x__code (x__idx(1):length(x__code)); + end + + % Strip comments off the variables. + x__idx = find(x__vars == '%'); + if (~ isempty (x__idx)) + x__vars = x__vars(1:x__idx(1)-1); + end + + % Assign default values to variables. + try + x__vars = deblank (x__vars); + if (~ isempty (x__vars)) + x__shared_names = {}; + while ~isempty(x__vars), + [x__shared_names{end+1}, x__vars] = strtok(x__vars, ', '); + end + x__shared_vals = repmat({[]}, 1, length(x__shared_names)); + else + x__shared_names = {}; + x__shared_vals = {}; + end + catch + % Couldn't declare, so don't initialize. + x__code = ''; + x__success = 0; + x__msg = sprintf ('%sshared variable initialization failed\n', ... + SIGNAL_FAIL); + end + + % Initialization code will be evaluated below. + + elseif (strcmp (x__type, 'end')) + % end simply declares the end of a previous function block. + % There is no processing to be done here, just skip to next block. + x__istest = 0; + x__code = ''; + + %%% ASSERT + + elseif strcmp(x__type, 'assert') + x__istest = 1; + % Put the keyword back on the code. + x__code = x__block; + % The code will be evaluated below as a test block. + + %%% ERROR/WARNING + + elseif (strcmp (x__type, 'error') || strcmp(x__type, 'warning')) + x__istest = 1; + x__warning = strcmp (x__type, 'warning'); + [x__pattern, x__id, x__code] = getpattern (x__code); + if (x__id) + x__patstr = ['id=',x__id]; + else + x__patstr = ['<',x__pattern,'>']; + end + + % FIXME: in the Octave version, syntax errors are counted as + % failure, even for an 'error' block. This won't be the case here. + + if (x__success) + x__success = 0; + %x__warnstate = warning ('query', 'quiet'); + %warning ('on', 'quiet'); + try + % This code is supposed to fail, so we don't save the output + % into x__shared_vals. + eval_test_code(x__code, x__shared_names, x__shared_vals{:}); + if (~ x__warning) + x__msg = sprintf ('%sexpected %s but got no error\n', ... + SIGNAL_FAIL, x__patstr); + else + if (~ isempty (x__id)) + [ignore_arg, x__err] = lastwarn; + x__mismatch =~strcmp (x__err, x__id); + else + x__err = trimerr (lastwarn, 'warning'); + x__mismatch = isempty (regexp (x__err, x__pattern, 'once')); + end + %warning (x__warnstate.state, 'quiet'); + if (isempty (x__err)) + x__msg = sprintf ('%sexpected %s but got no warning\n', ... + SIGNAL_FAIL, x__patstr); + elseif (x__mismatch) + x__msg = sprintf ('%sexpected %s but got %s\n', ... + SIGNAL_FAIL, x__patstr, x__err); + else + x__success = 1; + end + end + + catch + if (~ isempty (x__id)) + [ignore_arg, x__err] = lasterr(); + x__mismatch =~strcmp (x__err, x__id); + else + x__err = trimerr (lasterr(), 'error'); + x__mismatch = isempty (regexp (x__err, x__pattern, 'once')); + end + %warning (x__warnstate.state, 'quiet'); + if (x__warning) + x__msg = sprintf ('%sexpected warning %s but got error %s\n', ... + SIGNAL_FAIL, x__patstr, x__err); + elseif (x__mismatch) + x__msg = sprintf ('%sexpected %s but got %s\n', ... + SIGNAL_FAIL, x__patstr, x__err); + else + x__success = 1; + end + end + clear x__testx__; + end + % Code already processed. + x__code = ''; + + %%% TEST + + elseif (strcmp (x__type, 'test') || strcmp (x__type, 'xtest')) + x__istest = 1; + % Code will be evaluated below. + + %%% Comment block. + + elseif ((x__block(1) == '%') || (x__block(1) == '#')) + x__istest = 0; + x__code = ''; % skip the code + + %%% Unknown block. + + else + x__istest = 1; + x__success = 0; + x__msg = sprintf ('%sunknown test type!\n', SIGNAL_FAIL); + x__code = ''; % skip the code + end + + % evaluate code for test, shared, and assert. + if (~ isempty(x__code)) + try + % FIXME: need to check for embedded test functions, which cause + % segfaults, until issues with subfunctions in functions are resolved. + embed_func = regexp (x__code, '^\s*function ', 'once', 'lineanchors'); + if (isempty (embed_func)) + [x__shared_vals{:}] = eval_test_code(x__code, ... + x__shared_names, x__shared_vals{:}); + else + error (['Functions embedded in %!test blocks are not allowed.\n', ... + 'Use the %!function/%!end syntax instead to define shared functions for testing.\n']); + end + catch + if (strcmp (x__type, 'xtest')) + x__msg = sprintf ('%sknown failure\n%s', SIGNAL_FAIL, lasterr ()); + nb_expected_failures = nb_expected_failures + 1; + else + x__msg = sprintf ('%stest failed\n%s', SIGNAL_FAIL, lasterr ()); + x__success = 0; + end + if (isempty (lasterr ())) + error ('empty error text, probably Ctrl-C --- aborting'); + end + end + clear x__testx__; + end + + % All done. Remember if we were successful and print any messages. + if (~ isempty (x__msg)) + % Make sure the user knows what caused the error. + if (~ x__verbose) + fprintf (x__fid, '%s%s\n', SIGNAL_BLOCK, x__block); + fflush (x__fid); + end + fprintf(x__fid, '%s', x__msg); + fprintf(x__fid, '%s', sprintf('\n')); + fflush (x__fid); + % FIXME: Dump the shared variables to x__fid... Octave uses fdisp() + % to do that, but Matlab doesn't have this function + end + if (x__success == 0) + x__all_success = 0; + % Stop after one error if not in batch mode. + if (~ x__batch) + if (nargout > 0) + x__ret1 = 0; x__ret2 = 0; + end + if (x__close_fid) + fclose(x__fid); + end + return; + end + end + x__tests = x__tests + x__istest; + x__successes = x__successes + x__success * x__istest; +end + +if nargout == 0 + if x__tests || (nb_expected_failures > 0) + if (nb_expected_failures) + fprintf ('PASSES %d out of %d tests (%d expected failures)\n', ... + x__successes, x__tests, nb_expected_failures); + else + fprintf ('PASSES %d out of %d tests\n', x__successes, x__tests); + end + else + fprintf ('%s%s has no tests available\n', SIGNAL_EMPTY, x__file); + end +elseif (nargout == 1) + x__ret1 = x__all_success; +else + x__ret1 = x__successes; + x__ret2 = x__tests; + x__ret3 = nb_expected_failures; +end + +end % function + + +%%%%%%%%%%%%%%%%%% +% eval_test_code % +%%%%%%%%%%%%%%%%%% +% +% Evaluate a block of code in a 'controlled' environment. +% +function varargout = eval_test_code(x__code, x__list_shared, varargin) + +% Check input arguments +if length(x__list_shared) ~= length(varargin), + error('Incorrect argument sizes.'); +end + +% Protect variable names x__list_shared, x__i +for i = 1:length(x__list_shared), + if strcmp(x__list_shared{i}, 'x__list_shared'), + error('x__list_shared cannot be used as a shared variable'); + elseif strcmp(x__list_shared{i}, 'x__i'), + error('x__i cannot be used as a shared variable'); + end +end + +% Prepare shared variables +for x__i = 1:length(x__list_shared) + eval(sprintf('%s = varargin{%d};', x__list_shared{x__i}, x__i)); +end + +% Run the code +if exist ('OCTAVE_VERSION', 'builtin') == 5 % Octave + + % Run without output capture (evalc is not implemented yet in Octave) + eval (x__code); + +else % Matlab + + % Run with output capture + % (TODO: compare the output with a reference, if provided) + gobble_output = evalc (x__code); %#ok + +end + +% Save shared variables +varargout = cell(1, length(x__list_shared)); +for x__i = 1:length(x__list_shared), + if ~exist(x__list_shared{x__i}, 'var'), + varargout{x__i} = []; + else + varargout{x__i} = eval(x__list_shared{x__i}); + end +end + +end % function + + +%%%%%%%%%%%%%% +% getpattern % +%%%%%%%%%%%%%% +% +% Strip from ' code'. +% Also handles 'id=ID code' +% +function [pattern, id, rest] = getpattern (str) + +pattern = '.'; +id = []; +rest = str; +str = trimleft (str); +if (~ isempty (str) && str(1) == '<') + close = index (str, '>'); + if (close) + pattern = str(2:close-1); + rest = str(close+1:end); + end +elseif (strncmp (str, 'id=', 3)) + [id, rest] = strtok (str(4:end)); +end + +end % function + + +%%%%%%%%%%% +% trimerr % +%%%%%%%%%%% +% +% Strip '.*prefix:' from '.*prefix: msg\n' and strip trailing blanks. +% +function msg = trimerr (msg, prefix) + +idx = index (msg, [prefix, ':']); +if (idx > 0) + msg(1:idx+length(prefix)) = []; +end +msg = trimleft (deblank (msg)); + +end % function + + +%%%%%%%%%%%% +% trimleft % +%%%%%%%%%%%% +% +% Strip leading blanks from string. +% +function str = trimleft (str) + +idx = find (isspace (str)); +leading = find (idx == 1:length(idx)); +if (~ isempty (leading)) + str = str(leading(end)+1:end); +end + +end % function + + +%%%%%%%%%%%%%%%%%%%%%%%% +% x__extract_test_code % +%%%%%%%%%%%%%%%%%%%%%%%% +% +function body = x__extract_test_code (nm) + +fid = fopen (nm, 'rt'); +if fid == -1, + error(sprintf('File %s cannot be opened.', nm)); +end + +body = ''; +if (fid >= 0) + while (~ feof (fid)) + ln = fgetl (fid); + if (length (ln) >= 2 && strcmp (ln(1:2), '%!')) + body = [body, sprintf('\n')]; + if (length(ln) > 2) + body = [body, ln(3:end)]; + end + end + end + fclose (fid); +end + +end % function + + +%% Tests of 'assert' blocks + +%!assert(isempty([])) % support for test assert shorthand +%!assert((1 + 1) == 2) + +%% Tests of shared variables + +% Default: variables are not shared between blocks. +%!test a=1; +%!test assert(~exist('a')); + +% 'shared' blocks allow to declare a variable shared by several blocks +%!shared a % create a shared variable +%!test a = 3; % assign to a shared variable +%!test assert(a == 3); % variable should equal 3 in this second 'test' block + +% Each 'shared' blocks deletes previously declared shared variables +%!shared b, c % replace shared variables {'a'} --> {'b', 'c'} +%!test assert(~exist('a')); % a no longer exists +%!test assert(isempty(b)); % variables start off empty + +%!shared a % recreate a shared variable that had been deleted +%!test assert (isempty(a)); % it is empty, even though it was equal to 3 before + +%!shared a, b, c % creates three shared variables +%! a = 1; b = 2; c = 3; % give values to all variables, in the same block +%!assert(isequal([a, b, c], [1, 2, 3])); % test all of them together +%!test c=6; % update a value +%!test % show that the update sticks between blocks +%! assert(isequal([a, b, c], [1, 2, 6])); +%!shared % clear all shared variables +%!assert(~exist('a')) % show that they are cleared + +%% Tests for 'error' and 'warning' blocks + +%!error test % not enough input arguments +%!error test(1, 2, 3, 4) % too many input args +%!error garbage % usage on nonexistent function should be + +% When used without a pattern <>, 'error' block succeed on any error +%!error stt_test('test', 'bogus'); % undefined function error +%!error stk_test('test', 'bogus'); % error raised by stk_test itself + +% !test lastwarn(); % clear last warning just in case +% !warning % we expect a warning msg including "worry about" +% ! warning('Don''t worry about this warning'); + +%% Tests the behaviour of stk_test() itself + +% The number of input arguments should be between one and three +%!error stk_test(); +%!error stk_test('disp', 'verbose', [], 'extra arg !!!'); + +% The first argument of stk_test() must be a non-empty string +%!error stk_test([]) +%!error stk_test(0.0) + +% The second argument of stk_test() must be a either empty, or one of the +%%! following strings: normal, quiet, verbose +%!error stk_test('stk_mindist', 0.0) +%!error stk_test('stk_mindist', 'dudule') + +%% Failure tests +% All the following should fail. These tests should be disabled unless you +% are developing stk_test() since users don't like to be presented with +% expected failures. Use % ! to disable. + +% !xtest error('This test is known to fail') % expected failure +% !test error('---------Failure tests. Use test(''test'',''verbose'',1)'); +% !test assert(1 == 2); +% !bogus % unknown block type +% !error toeplitz([1,2,3]); % correct usage +% !shared garbage in % variables must be comma separated +% !test }{ % syntax errors fail properly +% !error 'succeeds.'; % error test fails if code succeeds +% !error error('message') % error pattern must match diff -Nru octave-stk-2.4.2/inst/misc/text/stk_disp_getformat.m octave-stk-2.5.0/inst/misc/text/stk_disp_getformat.m --- octave-stk-2.4.2/inst/misc/text/stk_disp_getformat.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/text/stk_disp_getformat.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,120 @@ +% STK_DISP_GETFORMAT [STK internal] +% +% CALL: [FMT, SPC] = stk_disp_getformat () +% +% NOTE +% +% This function solves a Matlab/Octave compatibility issue. See: +% +% * https://savannah.gnu.org/bugs/?51035 +% * https://savannah.gnu.org/bugs/?49951 +% * https://savannah.gnu.org/bugs/?46034 +% * https://sourceforge.net/p/kriging/tickets/73 + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Authors: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [fmt, spc] = stk_disp_getformat () + +persistent method +if isempty (method) + method = choose_method (); +end + +switch method + + case 1 % Matlab and some versions of Octave (e.g., 4.0.3) + + % Note: 'Format' and 'FormatSpacing' have been removed from the public + % list of root properties since Matlab R2014b, but are still recommended + % as the proper way to obtain this information in R2017a's manual. + + fmt = get (0, 'Format'); + spc = get (0, 'FormatSpacing'); + + case 2 % Octave 4.2 for sure (when was it introduced ?) + + % In Octave 4.2.0 the 'Format' and 'FormatSpacing' root property have + % been removed, but __formattring__ and __compactformat__ are still + % available. + + fmt = feval ('__formatstring__'); + spc = feval ('__compactformat__'); + + case 3 % Octave > 4.2 + + % After Octave 4.2.0, __formattring__ and __compactformat__ have been + % removed too, and a new syntax is available. + + [fmt, spc] = format (); + + otherwise + + % If nothing works, I really don't know which version of Octave or + % Matlab you are using, but defaulting to 'short' + 'loose' in this case + % seems better than a warning or an error. + + fmt = 'short'; + spc = 'loose'; + +end % switch + +end % function + + +function method = choose_method () + +try + + spc = get (0, 'FormatSpacing'); + assert (ismember (spc, {'compact', 'loose'})); + method = 1; + +catch + + if exist ('__compactformat__', 'builtin') == 5 + + method = 2; + + else + + try + + [fmt, spc] = format (); %#ok CG#07 + assert (ismember (spc, {'compact', 'loose'})); + method = 3; + + catch + + method = 4; + + end % try + + end % if + +end % try + +end % function diff -Nru octave-stk-2.4.2/inst/misc/text/stk_disp_isloose.m octave-stk-2.5.0/inst/misc/text/stk_disp_isloose.m --- octave-stk-2.4.2/inst/misc/text/stk_disp_isloose.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/misc/text/stk_disp_isloose.m 2017-09-13 07:51:00.000000000 +0000 @@ -8,7 +8,9 @@ % % This function solves a Matlab/Octave compatibility issue. See: % -% * https://savannah.gnu.org/bugs/index.php?51035 +% * https://savannah.gnu.org/bugs/?51035 +% * https://savannah.gnu.org/bugs/?49951 +% * https://savannah.gnu.org/bugs/?46034 % * https://sourceforge.net/p/kriging/tickets/73 % Copyright Notice @@ -39,30 +41,8 @@ function b = stk_disp_isloose () -try - - % This works in Matlab (even though 'FormatSpacing' as been removed from - % the public list of root properties since R2014b) and in Octave <= 4.0.3 - fmt = get (0, 'FormatSpacing'); - -catch - - try - - % In Octave 4.2.0 the 'FormatSpacing' root property has been removed - % but a different syntax has been introduced: - [ign, fmt] = format (); %#ok - - catch - - % If nothing works, I really don't know which version of Octave or - % Matlab you are using, but defaulting to 'loose' in this case seems - % better than a warning or an error. - fmt = 'loose'; - - end -end +[fmt, spc] = stk_disp_getformat (); %#ok CG#07 -b = strcmp (fmt, 'loose'); +b = strcmp (spc, 'loose'); end % function diff -Nru octave-stk-2.4.2/inst/param/classes/stk_get_optimizable_parameters.m octave-stk-2.5.0/inst/param/classes/stk_get_optimizable_parameters.m --- octave-stk-2.4.2/inst/param/classes/stk_get_optimizable_parameters.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/param/classes/stk_get_optimizable_parameters.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,76 @@ +% STK_GET_OPTIMIZABLE_PARAMETERS [STK internal] +% +% CALL: VALUE = stk_get_optimizable_parameters (PARAM) +% +% returns the value of the 'optimizable_parameters' property of PARAM. +% +% NOTE: +% +% Numerical arrays are considered as a special kind of parameter object, for +% which the 'optimizable_parameters' property is taken to be PARAM(:). +% +% INTERNAL FUNCTION WARNING: +% +% This function is currently considered as internal. STK users that wish to +% experiment with parameter classes can already overload it, but should be +% aware that API-breaking changes are likely to happen in future releases. +% +% See also: stk_set_optimizable_parameters + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function value = stk_get_optimizable_parameters (param) + +% This function will catch all calls to stk_get_optimizable_parameters for which +% param is not an object of a "parameter class" (more precisely, a class that +% implements stk_get_optimizable_parameters) + +if ~ isnumeric (param) + + try + + % Extract parameter values + param = param(:); + + % Note: if param is an object, the previous line is actually a call to + % subsref in disguise. This way of supporting parameter objects has + % been introduced in STK 2.0.0 as an "experimental" feature. It is now + % deprecated. + + catch + + stk_error (['stk_get_optimizable_parameters is not implemented for ' ... + 'objects of class ', class(param), '.'], 'TypeMismatch'); + + end + +end % if + +% Make sure that the result is a column vector +value = param(:); + +end % function diff -Nru octave-stk-2.4.2/inst/param/classes/stk_set_optimizable_parameters.m octave-stk-2.5.0/inst/param/classes/stk_set_optimizable_parameters.m --- octave-stk-2.4.2/inst/param/classes/stk_set_optimizable_parameters.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/param/classes/stk_set_optimizable_parameters.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,70 @@ +% STK_SET_OPTIMIZABLE_PARAMETERS [STK internal] +% +% CALL: PARAM = stk_set_optimizable_parameters (PARAM, VALUE) +% +% sets to VALUE the 'optimizable_parameters' property of PARAM. The argument +% VALUE is expected to be a numerical vector of the appropriate length. +% +% NOTE: +% +% Numerical arrays are considered as a special kind of parameter object, for +% which the 'optimizable_parameters' property is taken to be PARAM(:). +% +% INTERNAL FUNCTION WARNING: +% +% This function is currently considered as internal. STK users that wish to +% experiment with parameter classes can already overload it, but should be +% aware that API-breaking changes are likely to happen in future releases. +% +% See also: stk_get_optimizable_parameters + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function param = stk_set_optimizable_parameters (param, value) + +% This function will catch all calls to stk_set_optimizable_parameters for which +% neither param nor value is an object of a "parameter class" (more precisely, +% a class that implements stk_set_optimizable_parameters) + +try + + % If param is numeric, the following syntax preserves its size and type + param(:) = value; + + % Note: if param is an object, the previous line is actually a call to + % subsasgn in disguise. This way of supporting parameter objects has been + % introduced in STK 2.0.0 as an "experimental" feature. It is now + % deprecated. + +catch + + stk_error (['stk_set_optimizable_parameters is not implemented for ' ... + 'objects of class ', class(param), '.'], 'TypeMismatch'); + +end % if + +end % function diff -Nru octave-stk-2.4.2/inst/param/estim/stk_param_estim.m octave-stk-2.5.0/inst/param/estim/stk_param_estim.m --- octave-stk-2.4.2/inst/param/estim/stk_param_estim.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/param/estim/stk_param_estim.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,320 @@ +% STK_PARAM_ESTIM estimates the parameters of a covariance function +% +% CALL: PARAM = stk_param_estim (MODEL, XI, YI, PARAM0) +% CALL: [PARAM, LNV] = stk_param_estim (MODEL, XI, YI, PARAM0) +% +% estimates the parameters PARAM of the covariance function in MODEL +% from the data (XI, YI) using the restricted maximum likelihood (ReML) +% method. The value PARAM0 is used as a starting point for local +% optimization. +% +% The observations are assumed to be noisy if MODEL.lognoisevariance is +% not -inf. In this case, the variance of the noise is estimated if +% MODEL.lognoisevariance is nan, and assumed known otherwise. The +% estimated log-variance is returned as the second output argument LNV +% (equal to MODEL.lognoisevariance when it is assumed to be known). +% +% CALL: PARAM = stk_param_estim (MODEL, XI, YI) +% CALL: [PARAM, LNV] = stk_param_estim (MODEL, XI, YI) +% +% does the same thing but uses stk_param_init to provide a starting value +% automatically. +% +% CALL: [PARAM, LNV] = stk_param_estim (MODEL, XI, YI, PARAM0, LNV0) +% +% additionally provides an initial guess LNV0 for the logarithm of the +% noise variance. In this case the observations are automatically assumed +% to be noisy, and the value of MODEL.lognoisevariance is ignored. +% +% CALL: PARAM = stk_param_estim (MODEL, XI, YI, PARAM0, [], CRIT) +% CALL: [PARAM, LNV] = stk_param_estim (MODEL, XI, YI, PARAM0, LNV0, CRIT) +% +% uses the estimation criterion CRIT instead of the default ReML criterion. +% +% EXAMPLES: see, e.g., stk_example_kb02, stk_example_kb03, stk_example_kb04, +% stk_example_kb06, stk_example_misc02 + +% Copyright Notice +% +% Copyright (C) 2015-2017 CentraleSupelec +% Copyright (C) 2014 SUPELEC & A. Ravisankar +% Copyright (C) 2011-2013 SUPELEC +% +% Authors: Julien Bect +% Emmanuel Vazquez +% Ashwin Ravisankar +% Remi Stroh + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [param_opt, lnv_opt, info] = stk_param_estim ... + (model, xi, zi, param0, lnv0, criterion) + +if nargin > 6, + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +% Empty is the same as not provided +if nargin < 6, criterion = []; end +if nargin < 5, lnv0 = []; end +if nargin < 4, param0 = []; end + +% size checking: xi, zi +zi_data = double (zi); +if ~ isequal (size (zi_data), [stk_length(xi) 1]), + errmsg = 'zi should be a column, with the same number of rows as xi.'; + stk_error (errmsg, 'IncorrectSize'); +end + +% Warn about special case: constant response +if (std (zi_data) == 0) + warning ('STK:stk_param_estim:ConstantResponse', ['Constant-response ' ... + 'data: the output of stk_param_estim is likely to be unreliable.']); +end + +% Make sure that lognoisevariance is -inf for noiseless models +if ~ stk_isnoisy (model) + model.lognoisevariance = -inf; +end + +% Should we estimate the variance of the noise, too ? +if ~ isempty (lnv0) + % lnv0 present => noise variance *must* be estimated + do_estim_lnv = true; + if isnan (lnv0) || isinf (lnv0) + stk_error (['Incorrect value for input argumen lnv0. The starting ' ... + 'point for the estimation of lnv must be neither infinite nor ' ... + 'NaN.'], 'InvalidArgument'); + end +else + % Otherwise, noise variance estimation happens when lnv has NaNs + lnv0 = model.lognoisevariance; + do_estim_lnv = any (isnan (lnv0)); +end + +if do_estim_lnv && (~ isscalar (lnv0)) + stk_error (['Estimating the variance of the noise is not possible ' ... + 'in the hetereoscedastic case yet. Sorry.'], 'InvalidArgument'); +end + +% Default criterion: restricted likelihood (ReML method) +if isempty (criterion) + criterion = @stk_param_relik; +end + +% param0: provide a value (if not provided as input argument) +[param0, lnv0] = provide_param0_value (model, xi, zi, param0, lnv0); + +% lnv0: try stk_param_init_lnv if we still have no acceptable value +if do_estim_lnv && (isnan (lnv0)) + model.param = param0; + lnv0 = stk_param_init_lnv (model, xi, zi); +end + +% TODO: allow user-defined bounds +[lb, ub] = stk_param_getdefaultbounds (model.covariance_type, param0, xi, zi); + +% Get vector of numerical parameters +u0 = stk_get_optimizable_parameters (param0); + +if do_estim_lnv + [lblnv, ublnv] = get_default_bounds_lnv (model, lnv0, xi, zi); + lb = [lb ; lblnv]; + ub = [ub ; ublnv]; + u0 = [u0; lnv0]; +end + +switch do_estim_lnv + case false, + f = @(u)(f_ (model, u, xi, zi, criterion)); + case true, + f = @(u)(f_with_noise_ (model, u, xi, zi, criterion)); +end + +bounds_available = (~ isempty (lb)) && (~ isempty (ub)); + +if bounds_available + A = stk_options_get ('stk_param_estim', 'minimize_box'); + [u_opt, crit_opt] = stk_minimize_boxconstrained (A, f, u0, lb, ub); +else + A = stk_options_get ('stk_param_estim', 'minimize_unc'); + [u_opt, crit_opt] = stk_minimize_unconstrained (A, f, u0); +end + +if do_estim_lnv + lnv_opt = u_opt(end); + u_opt(end) = []; +else + lnv_opt = model.lognoisevariance; +end + +% Create parameter object +param_opt = stk_set_optimizable_parameters (model.param, u_opt); + +% Create 'info' structure, if requested +if nargout > 2, + info.criterion = criterion; + info.crit_opt = crit_opt; + info.lower_bounds = lb; + info.upper_bounds = ub; +end + +end % function + +%#ok<*CTCH,*LERR,*SPWRN,*WNTAG> + + +%--- The objective function --------------------------------------------------- + +function [l, dl] = f_ (model, u, xi, zi, criterion) + +model.param = stk_set_optimizable_parameters (model.param, u); + +if nargout == 1, + l = criterion (model, xi, zi); +else + [l, dl] = criterion (model, xi, zi); +end + +end % function + + +function [l, dl] = f_with_noise_ (model, u, xi, zi, criterion) + +model.param = stk_set_optimizable_parameters (model.param, u(1:end-1)); +model.lognoisevariance = u(end); + +if nargout == 1, + l = criterion (model, xi, zi); +else + [l, dl, dln] = criterion (model, xi, zi); + dl = [dl; dln]; +end + +end % function + + +function [lblnv,ublnv] = get_default_bounds_lnv ... % -------------------------- + (model, lnv0, xi, zi) %#ok + +TOLVAR = 0.5; + +% Bounds for the variance parameter +empirical_variance = var(zi); +lblnv = log (eps); +ublnv = log (empirical_variance) + TOLVAR; + +% Make sure that lnv0 falls within the bounds +if ~ isempty (lnv0) + lblnv = min (lblnv, lnv0 - TOLVAR); + ublnv = max (ublnv, lnv0 + TOLVAR); +end + +end % function + + +function [param0, lnv0] = provide_param0_value ... % --------------------------- + (model, xi, zi, param0, lnv0) + +% param0: try to use input argument first +if ~ isempty (param0) + + % Cast param0 into an object of the appropriate type + param0 = stk_set_optimizable_parameters (model.param, param0); + + % Test if param0 contains nans + if any (isnan (stk_get_optimizable_parameters (param0))) + warning ('param0 has nans, calling stk_param_init instead'); + param0 = []; + end +end + +% param0: try stk_param_init if we still have no acceptable value +if isempty (param0) + model.lognoisevariance = lnv0; + [param0, lnv0] = stk_param_init (model, xi, zi); +end + +end % function + + +%!shared f, xi, zi, NI, param0, param1, model +%! +%! f = @(x)(- (0.8 * x + sin (5 * x + 1) + 0.1 * sin (10 * x)) ); +%! DIM = 1; NI = 20; box = [-1.0; 1.0]; +%! xi = stk_sampling_regulargrid (NI, DIM, box); +%! +%! SIGMA2 = 1.0; % variance parameter +%! NU = 4.0; % regularity parameter +%! RHO1 = 0.4; % scale (range) parameter +%! param0 = log ([SIGMA2; NU; 1/RHO1]); +%! +%! model = stk_model ('stk_materncov_iso'); + +%!test % noiseless +%! zi = stk_feval (f, xi); +%! param1 = stk_param_estim (model, xi, zi, param0); +%! assert (isequal (size (param1), size (param0))) + +% We cannot assume a DETERMINISTIC optimization algorithm +% (for some reason, Octave's sqp is not exactly deterministic) + +%!test % same thing, with empty lnv0 (ok) +%! param2 = stk_param_estim (model, xi, zi, param0, []); +%! assert (stk_isequal_tolrel (param2, param1, 1e-2)) + +%!error % same thing, with lnv0 == NaN (not ok as a starting point) +%! param2 = stk_param_estim (model, xi, zi, param0, nan); + +%!error % same thing, with lnv0 == -inf (not ok as a starting point) +%! param2 = stk_param_estim (model, xi, zi, param0, -inf); + +%!test % same thing, with explicit value for 'criterion' +%! param2 = stk_param_estim (model, xi, zi, param0, [], @stk_param_relik); +%! assert (stk_isequal_tolrel (param1, param2, 1e-2)) + +%!test % noiseless +%! zi = stk_feval (f, xi); +%! param1 = stk_param_estim (model, xi, zi, param0); +%! param2 = stk_param_estim (model, xi, zi, param0, [], @stk_param_relik); +%! % We cannot assume a DETERMINISTIC optimization algorithm +%! % (for some reason, Octave's sqp is not exactly deterministic) +%! assert (stk_isequal_tolrel (param1, param2, 1e-2)) + +%!test % noisy +%! NOISE_STD_TRUE = 0.1; +%! NOISE_STD_INIT = 1e-5; +%! zi = zi + NOISE_STD_TRUE * randn(NI, 1); +%! model.lognoisevariance = 2 * log(NOISE_STD_INIT); +%! [param, lnv] = stk_param_estim ... +%! (model, xi, zi, param0, model.lognoisevariance); + +% Incorrect number of input arguments +%!error param = stk_param_estim () +%!error param = stk_param_estim (model); +%!error param = stk_param_estim (model, xi); +%!error param = stk_param_estim (model, xi, zi, param0, log(eps), @stk_param_relik, pi); + +%!test % Constant response +%! model = stk_model ('stk_materncov52_iso'); +%! n = 10; x = stk_sampling_regulargrid (n, 1, [0; 1]); z = ones (size (x)); +%! param = stk_param_estim (model, x, z, model.param); +%! assert ((all (isfinite (param))) && (length (param) == 2)); diff -Nru octave-stk-2.4.2/inst/param/estim/stk_param_getdefaultbounds.m octave-stk-2.5.0/inst/param/estim/stk_param_getdefaultbounds.m --- octave-stk-2.4.2/inst/param/estim/stk_param_getdefaultbounds.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/param/estim/stk_param_getdefaultbounds.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,143 @@ +% STK_PARAM_GETDEFAULTBOUNDS provides lower/upper bounds for covariance parameters +% +% CALL: [LB, UB] = stk_param_getdefaultbounds (COVARIANCE_TYPE, PARAM0, XI, ZI) +% +% returns lower bounds LB and upper bounds UB for the optimization of the +% parameters of a parameterized covariance function COVARIANCE_TYPE, given +% the starting point PARAM0 of the optimization and the data (XI, ZI). +% +% NOTE: user-defined covariance functions +% +% For user-defined covariance functions, lower/upper bounds can be provided +% using one of the following two approaches: +% +% a) if the covariance uses a dedicated class C for parameter values, +% the prefered approach is to imlement stk_param_getdefaultbounds for +% this class; +% +% b) otherwise, for a covariance function named mycov, simply provide a +% function named mycov_defaultbounds. + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% Copyright (C) 2015 CentraleSupelec & LNE +% Copyright (C) 2011-2014 SUPELEC +% +% Authors: Julien Bect +% Emmanuel Vazquez +% Remi Stroh + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [lb, ub] = stk_param_getdefaultbounds (covariance_type, param0, xi, zi) + +if isobject (param0) + + % param0 is an object from a class that does not implement + % stk_param_getdefaultbounds (otherwise we wouldn't have ended up here). + % We assume that this is a choice of the designer of the parameter class, + % and therefore return [] without a warning. + + lb = []; + ub = []; + +elseif ~ isfloat (param0) + + stk_error ('Incorrect type for param0.', 'TypeMismatch'); + +else + + % constants + opts = stk_options_get ('stk_param_getdefaultbounds'); + TOLVAR = opts.tolvar; + TOLSCALE = opts.tolscale; + + % bounds for the variance parameter + log_empirical_variance = log (var (double (zi))); + if log_empirical_variance == - Inf + logvar_lb = param0(1) - TOLVAR; + logvar_ub = param0(1) + TOLVAR; + else + logvar_lb = min (log_empirical_variance, param0(1)) - TOLVAR; + logvar_ub = max (log_empirical_variance, param0(1)) + TOLVAR; + end + + dim = size (xi, 2); + + if ~ ischar (covariance_type) + % Assume that model.covariance_type is a handle + covariance_type = func2str (covariance_type); + end + + switch covariance_type, + + case {'stk_materncov_aniso', 'stk_materncov_iso'} + + nu_lb = min (log (0.5), param0(2)); + nu_ub = max (log (min (50, 10 * dim)), param0(2)); + + range_mid = param0(3:end); + range_lb = range_mid(:) - TOLSCALE; + range_ub = range_mid(:) + TOLSCALE; + + lb = [logvar_lb; nu_lb; range_lb]; + ub = [logvar_ub; nu_ub; range_ub]; + + case { 'stk_materncov32_aniso', 'stk_materncov32_iso', ... + 'stk_materncov52_aniso', 'stk_materncov52_iso', ... + 'stk_expcov_aniso', 'stk_expcov_iso', ... + 'stk_gausscov_aniso', 'stk_gausscov_iso', ... + 'stk_sphcov_aniso', 'stk_sphcov_iso'} + + range_mid = param0(2:end); + range_lb = range_mid(:) - TOLSCALE; + range_ub = range_mid(:) + TOLSCALE; + + lb = [logvar_lb; range_lb]; + ub = [logvar_ub; range_ub]; + + otherwise + try + % Undocumented feature: make it possible to define a + % XXXX_getdefaultbounds function that provides parameter + % bounds during estimation for a user-defined covariance + % function called XXXX (in the case, where this covariance + % has parameters type double). + fname = [covariance_type '_getdefaultbounds']; + [lb, ub] = feval (fname, param0, xi, zi); + catch + err = lasterror (); + msg = strrep (err.message, sprintf ('\n'), sprintf ('\n|| ')); + warning(['Unable to initialize covariance parameters ' ... + 'automatically for covariance functions of type ''%s''.'... + '\n\nEmpty bounds are returned.\n\nThe original error ' ... + 'message was:\n|| %s\n'], covariance_type, msg); + lb = []; + ub = []; + end + + end % switch + +end % if + +end % function + diff -Nru octave-stk-2.4.2/inst/param/estim/stk_param_gls.m octave-stk-2.5.0/inst/param/estim/stk_param_gls.m --- octave-stk-2.4.2/inst/param/estim/stk_param_gls.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/param/estim/stk_param_gls.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,105 @@ +% STK_PARAM_GLS computes a generalised least squares estimate +% +% CALL: BETA = stk_param_gls (MODEL, XI, ZI) +% +% computes the generalised least squares estimate BETA of the vector of +% coefficients for the linear part of MODEL, where XI and ZI stand for +% the evaluation points and observed responses, respectively. +% +% CALL: [BETA, SIGMA2] = stk_param_gls (MODEL, XI, ZI) +% +% also returns the associated unbiased estimate SIGMA2 of sigma^2, assu- +% ming that the actual covariance matrix of the Gaussian process part of +% the model is sigma^2 K, with K the covariance matrix built from MODEL. +% +% SIGMA2 is actually the "best" unbiased estimate of sigma^2 : +% +% 1 +% SIGMA2 = ----- * || ZI - P BETA ||^2_{K^{-1}} +% n - r +% +% where n is the number of observations, r the length of BETA, P the +% design matrix for the linear part of the model, and || . ||_{K^{-1}} +% the norm associated to the positive definite matrix K^{-1}. It is the +% best estimate with respect to the quadratic risk, among all unbiased +% estimates which are quadratic in the residuals. + +% Copyright Notice +% +% Copyright (C) 2015, 2016 CentraleSupelec +% Copyright (C) 2014 SUPELEC & A. Ravisankar +% Copyright (C) 2011-2013 SUPELEC +% +% Authors: Julien Bect +% Emmanuel Vazquez +% Ashwin Ravisankar + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [beta, sigma2, L] = stk_param_gls (model, xi, zi) + +n = size (xi, 1); + +% Build the covariance matrix and the design matrix +[K, P] = stk_make_matcov (model, xi); + +% Cast zi into a double-precision array +zi = double (zi); + +% Compute the Generalized Least Squares (GLS) estimate +L = stk_cholcov (K, 'lower'); +W = L \ P; +u = L \ zi; +beta = (W' * W) \ (W' * u); + +if nargin > 1, + % Assuming that the actual covariance matrice is sigma^2 K, compute the + % "best" unbiased estimate of sigma2 (best wrt the quadratic risk, among + % all unbiased estimates which are quadratic in the residuals) + r = length (beta); + sigma2 = 1 / (n - r) * sum ((u - W * beta) .^ 2); +end + +end % end function stk_param_gls + + +%!shared xi, zi, model, beta, sigma2 +%! xi = (1:10)'; zi = sin (xi); +%! model = stk_model ('stk_materncov52_iso'); +%! model.param = [0.0 0.0]; + +%!test +%! model.lm = stk_lm_constant (); +%! [beta, sigma2] = stk_param_gls (model, xi, zi); +%!assert (stk_isequal_tolabs (beta, 0.1346064, 1e-6)) +%!assert (stk_isequal_tolabs (sigma2, 0.4295288, 1e-6)) + +%!test +%! model.lm = stk_lm_affine (); +%! [beta, sigma2] = stk_param_gls (model, xi, zi); +%!assert (stk_isequal_tolabs (beta, [0.4728342; -0.0614960], 1e-6)) +%!assert (stk_isequal_tolabs (sigma2, 0.4559431, 1e-6)) + +%!test +%! model.lm = stk_lm_null (); +%! [beta, sigma2] = stk_param_gls (model, xi, zi); +%!assert (isequal (beta, zeros (0, 1))) +%!assert (stk_isequal_tolabs (sigma2, 0.3977993, 1e-6)) diff -Nru octave-stk-2.4.2/inst/param/estim/stk_param_init_lnv.m octave-stk-2.5.0/inst/param/estim/stk_param_init_lnv.m --- octave-stk-2.4.2/inst/param/estim/stk_param_init_lnv.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/param/estim/stk_param_init_lnv.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,107 @@ +% STK_PARAM_INIT_LNV provides a rough estimate of the variance of the noise +% +% CALL: LNV = stk_param_init_lnv (MODEL, XI, YI) +% +% returns a rough estimate of the log of the noise variance computed using +% the given MODEL and data (XI, YI), using the restricted maximum likelihood +% (ReML) method. It selects the maximizer of the ReML criterion out of a +% list of possible values. +% +% NOTE: assumption on the model +% +% The model is assumed to be a stationary Gaussian process, with +% model.param(1) corresponding to the log of the Gaussian process variance. +% This assumption is currently fulfilled by all the models shipped with STK. +% +% See also: stk_param_estim, stk_param_init + +% Copyright Notice +% +% Copyright (C) 2014 SUPELEC +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function lnv = stk_param_init_lnv (model, xi, zi) + +if nargin > 3, + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +% size checking: xi, zi +if ~ isequal (size (zi), [size(xi, 1) 1]), + errmsg = 'zi should be a column, with the same number of rows as xi.'; + stk_error (errmsg, 'IncorrectSize'); +end + +% Warn about special case: constant response +if (std (double (zi)) == 0) + warning ('STK:stk_param_estim_lnv:ConstantResponse', ['Constant- ' ... + 'response data: the output of stk_param_estim_lnv is likely ' ... + 'to be unreliable.']); +end + +% Make sure that lognoisevariance is -inf for noiseless models +if ~ stk_isnoisy (model) + model.lognoisevariance = -inf; +end + +% We will work with the ratio eta = sigma2_noise / sigma2 +log_eta_min = -15; % exp(-15) = 3e-7 approx -> very small noise +log_eta_max = +15; % exp(+15) = 3e+7 approx -> very large noise +log_eta_list = linspace (log_eta_min, log_eta_max, 5); + +% Initialize parameter search +log_eta_best = nan; +aLL_best = +inf; + +% Try all values from log_eta_list +for log_eta = log_eta_list + model.lognoisevariance = model.param(1) + log_eta; + aLL = stk_param_relik (model, xi, zi); + if (~ isnan (aLL)) && (aLL < aLL_best) + log_eta_best = log_eta; + aLL_best = aLL; + end +end + +if isinf (aLL_best) + errmsg = 'Couldn''t find reasonable parameter values... ?!?'; + stk_error (errmsg, 'AlgorithmFailure'); +end + +lnv = model.param(1) + log_eta_best; + +end % function + + +%!test +%! f = @(x)(- (0.8 * x + sin (5 * x + 1) + 0.1 * sin (10 * x))); +%! ni = 20; +%! xi = (linspace (-1, 1, ni))' + 0.2 * (randn (ni, 1)); +%! zi = stk_feval (f, xi); +%! +%! model = stk_model ('stk_materncov_iso'); +%! model.param = log ([1; 5/2; 1/0.4]); +%! lnv = stk_param_init_lnv (model, xi, zi); +%! +%! assert ((isscalar (lnv)) && (lnv > -30) && (lnv < 30)); diff -Nru octave-stk-2.4.2/inst/param/estim/stk_param_init.m octave-stk-2.5.0/inst/param/estim/stk_param_init.m --- octave-stk-2.4.2/inst/param/estim/stk_param_init.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/param/estim/stk_param_init.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,468 @@ +% STK_PARAM_INIT provides a starting point for stk_param_estim +% +% CALL: PARAM = stk_param_init (MODEL, XI, YI) +% +% provides a quick and dirty estimate of the parameters of MODEL based on the +% data (XI, YI), that can be used as a starting point for stk_param_estim. It +% selects the maximizer of the ReML criterion out of a list of possible values +% given data (XI, YI). This syntax is appropriate for noiseless observations +% and for noisy observations with known noise variance (i.e., when the +% 'lognoisevariance' field in MODEL is either -Inf or has a finite value). +% +% CALL: [PARAM, LNV] = stk_param_init (MODEL, XI, YI) +% +% also returns a value for the 'lognoisevariance' field. In the case of +% noiseless observations or noisy observations with known noise variance, this +% is simply the value that was provided by the user in MODEL.lognoisevariance. +% In the case where MODEL.lognoisevariance is NaN (noisy observation with +% unknown noise variance), LNV is estimated by stk_param_init together with +% PARAM. +% +% CALL: [PARAM, LNV] = stk_param_init (MODEL, XI, YI, BOX) +% +% takes into account the (hyper-rectangular) domain on which the model is +% going to be used. It is used in the heuristics that determines the list of +% parameter values mentioned above. BOX should be a 2 x DIM matrix with BOX(1, +% j) and BOX(2, j) being the lower- and upper-bound of the interval on the +% j^th coordinate, with DIM being the dimension of XI, DIM = size(XI,2). If +% provided, If missing or empty, the BOX argument defaults to [min(XI); +% max(XI)]. +% +% CALL: [PARAM, LNV] = stk_param_init (MODEL, XI, YI, BOX, DO_ESTIM_LNV) +% +% with DO_ESTIM_LNV = TRUE forces the estimation of the variance of the noise, +% regardless of the value of MODEL.lognoisevariance. If FALSE, it prevents +% estimation of the variance of the noise, which is only possible if the +% 'lognoisevariance' field in MODEL is either -Inf or has a finite value. +% +% See also stk_example_kb02, stk_example_kb03, stk_example_misc03 + +% Copyright Notice +% +% Copyright (C) 2015, 2016 CentraleSupelec +% Copyright (C) 2012-2014 SUPELEC +% +% Authors: Julien Bect +% Paul Feliot + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [param, lnv] = stk_param_init (model, varargin) + +cov_list = { ... + 'stk_expcov_iso', ... + 'stk_expcov_aniso', ... + 'stk_gausscov_iso', ... + 'stk_gausscov_aniso', ... + 'stk_materncov_iso', ... + 'stk_materncov_aniso', ... + 'stk_materncov32_iso', ... + 'stk_materncov32_aniso', ... + 'stk_materncov52_iso', ... + 'stk_materncov52_aniso', ... + 'stk_sphcov_iso', ... + 'stk_sphcov_aniso'}; + +if ~ ischar (model.covariance_type) + % Assume that model.covariance_type is a handle + model.covariance_type = func2str (model.covariance_type); +end + +if ismember (model.covariance_type, cov_list) + + % An initialization for this covariance type is provided in STK + [param, lnv] = stk_param_init_ (model, varargin{:}); + +else + try + % Undocumented feature: make it possible to define a XXXX_param_init + % function that provides initial estimates for a user-defined + % covariance function called XXXX. + fname = [model.covariance_type '_param_init']; + [param, lnv] = feval (fname, model, varargin{:}); + catch + err = lasterror (); + msg = strrep (err.message, sprintf ('\n'), sprintf ('\n|| ')); + msg = sprintf (['Unable to initialize covariance parameters ' ... + 'automatically for covariance functions of type ''%s''.\n\nThe ' ... + 'original error message was:\n|| %s\n'], model.covariance_type, msg); + stk_error (msg, 'UnableToInitialize'); + end % try_catch +end % if + +end % function + +%#ok<*CTCH,*LERR> + + +function [param, lnv] = stk_param_init_ (model, xi, zi, box, do_estim_lnv) + +if nargin > 5, + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +if ~ isequal (size (zi), [size(xi, 1) 1]), + errmsg = 'zi should be a column, with the same number of rows as xi.'; + stk_error (errmsg, 'IncorrectSize'); +end + +%--- first, default values for arguments 'box' and 'noisy' --------------------- + +if nargin < 4, + box = []; +end + +if ~ isa (box, 'stk_hrect') + if isempty (box), + box = stk_boundingbox (xi); % Default: bounding box + else + box = stk_hrect (box); + end +end + + +%--- backward compatiblity ----------------------------------------------------- + +% Make sure that lognoisevariance is -inf for noiseless models +if ~ stk_isnoisy (model) + model.lognoisevariance = -inf; +end + +% Ensure backward compatiblity with respect to model.order / model.lm +model = stk_model_fixlm (model); + + +%--- lognoisevariance ? -------------------------------------------------------- + +lnv = model.lognoisevariance; + +% Noise variance estimation is not supported in the heteroscedastic case +if (~ isscalar (lnv)) && (any (isnan (lnv))) + stk_error (['model.lognoisevariance is non-scalar and contains nans. ' ... + 'Noise variance estimation is not supported in the heteroscedastic ' ... + 'case '], 'InvalidArgument'); +end + +% Estimation of noise variance ? +% * if do_estim_lnv is provided, use it to decide +% * if not, estimation occurs when lnv is nan +if nargin < 5 + if isscalar (lnv) + % In the homoscedastic case, estimate noise variance iff lnv is nan + do_estim_lnv = isnan (lnv); + else + % Noise variance estimation is not supported in the heteroscedastic + % case (see above). Heteroscedastic case with known noise variance: + do_estim_lnv = false; + end +else % do_estim_lnv has been provided + if isscalar (lnv) + if do_estim_lnv + lnv = nan; + elseif isnan (lnv) + stk_error (sprintf ... + (['do_estim_lnv is false, but model.lognoisevariance ' ... + 'is nan. If you don''t want the noise variance to be ' ... + 'estimated, you must provide a value for it!']), ... + 'MissingParameterValue'); + end + else + % Noise variance estimation is not supported in the heteroscedastic + % case (see above). + if do_estim_lnv + stk_error (['Noise variance estimation is not supported in the ' ... + 'heteroscedastic case '], 'InvalidArgument'); + end + end +end + +if (do_estim_lnv) && (nargout < 2) + warning (['stk_param_init will be computing an estimation of the ' ... + 'variance of the noise, perhaps should you call the function ' ... + 'with two output arguments?']); +end + + +%--- then, each type of covariance is dealt with specifically ------------------ + +switch model.covariance_type + + case {'stk_expcov_iso', 'stk_materncov32_iso', 'stk_materncov52_iso', ... + 'stk_gausscov_iso', 'stk_sphcov_iso'} + [param, lnv] = paraminit_ (model.covariance_type, ... + xi, zi, box, model.lm, lnv); + + case {'stk_expcov_aniso', 'stk_materncov32_aniso', ... + 'stk_materncov52_aniso', 'stk_gausscov_aniso', 'stk_sphcov_aniso'} + xi = stk_normalize (xi, box); + c = [model.covariance_type(1:end-5) 'iso']; + [param, lnv] = paraminit_ (c, xi, zi, [], model.lm, lnv); + param = [param(1); param(2) - log(diff(box, [], 1))']; + + case 'stk_materncov_iso' + nu = 5/2 * size (xi, 2); + covname_iso = @(param, x, y, diff, pairwise) stk_materncov_iso ... + ([param(1) log(nu) param(2)], x, y, diff, pairwise); + [param, lnv] = paraminit_ (covname_iso, xi, zi, box, model.lm, lnv); + param = [param(1); log(nu); param(2)]; + + case 'stk_materncov_aniso' + nu = 5/2 * size (xi, 2); + covname_iso = @(param, x, y, diff, pairwise) stk_materncov_iso ... + ([param(1) log(nu) param(2)], x, y, diff, pairwise); + xi = stk_normalize (xi, box); + [param, lnv] = paraminit_ (covname_iso, xi, zi, [], model.lm, lnv); + param = [param(1); log(nu); param(2) - log(diff(box, [], 1))']; + + otherwise + errmsg = 'Unsupported covariance type.'; + stk_error (errmsg, 'InvalidArgument'); +end + +end % function + + +function [param, lnv] = paraminit_ (covname_iso, xi, zi, box, lm, lnv) + +% Check for special case: constant response +if (std (double (zi)) == 0) + warning ('STK:stk_param_init:ConstantResponse', ... + 'Parameter estimation is impossible with constant-response data.'); + param = [0 0]; if any (isnan (lnv)), lnv = 0; end + return % Return some default values +end + +d = size (xi, 2); + +model = stk_model (covname_iso); +model.lm = lm; +model.lognoisevariance = lnv; + +% list of possible values for the ratio eta = sigma2_noise / sigma2 +if (isscalar (lnv) && (lnv ~= -inf)) + % Homoscedastic noisy case, with known or unknown noise variance + eta_list = 10 .^ (-6:3:0); +else + % Noiseless case or heteroscedastic noisy case (known noise variance) + eta_list = 0; +end + +% list of possible values for the range parameter +if isempty (box) + % assume box = repmat([0; 1], 1, d) + box_diameter = sqrt (d); +else + box_diameter = sqrt (sum (diff (box) .^ 2)); +end +rho_max = 2 * box_diameter; +rho_min = box_diameter / 50; +rho_list = logspace (log10 (rho_min), log10 (rho_max), 5); + +% Initialize parameter search +eta_best = NaN; +rho_best = NaN; +sigma2_best = NaN; +aLL_best = +Inf; + +% Homoscedastic case ? +homoscedastic = (isscalar (lnv)); + +% Try all possible combinations of rho and eta from the lists +for eta = eta_list + for rho = rho_list + + % First use sigma2 = 1.0 + model.param = [0.0, -log(rho)]; + + % The same code works for the noiseless case and for the case where lnv + % must be estimated (in the first case, eta = 0 and thus lnv is -inf) + if (eta == 0) || (homoscedastic && (isnan (lnv))) + model.lognoisevariance = log (eta); + [ignd, sigma2] = stk_param_gls (model, xi, zi); %#ok CG#07 + if ~ (sigma2 > 0), continue; end + log_sigma2 = log (sigma2); + model.lognoisevariance = log (eta * sigma2); + else % Known variances (homo- and hetero-scedastic cases) + model.param = [0.0, -log(rho)]; + log_sigma2 = (mean (lnv)) - (log (eta)); + sigma2 = exp (log_sigma2); + end + + % Now, compute the antilog-likelihood + model.param(1) = log_sigma2; + aLL = stk_param_relik (model, xi, zi); + if ~isnan(aLL) && (aLL < aLL_best) + eta_best = eta; + rho_best = rho; + aLL_best = aLL; + sigma2_best = sigma2; + end + end +end + +if isinf (aLL_best) + errmsg = 'Couldn''t find reasonable parameter values... ?!?'; + stk_error (errmsg, 'AlgorithmFailure'); +end + +param = log ([sigma2_best; 1/rho_best]); + +if (isscalar (lnv)) && (isnan (lnv)) + % Homoscedatic case with unknown variance... Here is our estimate: + lnv = log (eta_best * sigma2_best); +end + +end % function + + +%!test +%! xi = (1:10)'; zi = sin (xi); +%! model = stk_model ('stk_materncov52_iso'); +%! model.param = stk_param_init (model, xi, zi, [1; 10], false); +%! xt = (1:9)' + 0.5; zt = sin (xt); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (sum ((zt - zp.mean) .^ 2) < 1e-3); + +%!test % check equivariance of parameter estimates +%! f = @(x) sin (x); +%! xi = stk_sampling_regulargrid (10, 1); zi = stk_feval (f, xi); +%! shift = 1000; scale = 0.01; +%! model = stk_model ('stk_materncov32_iso'); +%! p1 = stk_param_init (model, xi, zi); +%! p2 = stk_param_init (model, xi, shift + scale .* zi); +%! assert (stk_isequal_tolabs (p2(1), p1(1) + log (scale^2), 1e-10)) +%! assert (stk_isequal_tolabs (p2(2), p1(2), eps)) + +%!shared xi, zi, BOX, xt, zt +%! +%! f = @(x)(- (0.8 * x + sin (5 * x + 1) + 0.1 * sin (10 * x))); +%! DIM = 1; % Dimension of the factor space +%! BOX = [-1.0; 1.0]; % Factor space +%! +%! xi = stk_sampling_regulargrid (20, DIM, BOX); % Evaluation points +%! zi = stk_feval (f, xi); % Evaluation results +%! +%! NT = 400; % Number of points in the grid +%! xt = stk_sampling_regulargrid (NT, DIM, BOX); % Generate a regular grid +%! zt = stk_feval (f, xt); % Values of f on the grid + +%!test +%! model = stk_model ('stk_materncov_iso'); +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); +%! model.param = stk_param_estim (model, xi, zi, param0); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!test +%! model = stk_model ('stk_materncov_aniso'); +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); +%! model.param = stk_param_estim (model, xi, zi, param0); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!test +%! model = stk_model ('stk_materncov32_iso'); +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); +%! model.param = stk_param_estim (model, xi, zi, param0); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!test +%! model = stk_model ('stk_materncov32_aniso'); +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); +%! model.param = stk_param_estim (model, xi, zi, param0); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!test +%! model = stk_model ('stk_materncov52_iso'); +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); +%! model.param = stk_param_estim (model, xi, zi, param0); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!test +%! model = stk_model ('stk_materncov52_aniso'); +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); +%! model.param = stk_param_estim (model, xi, zi, param0); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!test +%! model = stk_model ('stk_gausscov_iso'); +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); +%! model.param = stk_param_estim (model, xi, zi, param0); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!test +%! model = stk_model ('stk_gausscov_aniso'); +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); +%! model.param = stk_param_estim (model, xi, zi, param0); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!test % Homoscedastic case / do_estim_lnv = true +%! model = stk_model ('stk_materncov32_iso'); +%! [model.param, model.lognoisevariance] = ... +%! stk_param_init (model, xi, zi, BOX, true); +%! [model.param, model.lognoisevariance] = ... +%! stk_param_estim (model, xi, zi); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (model.lognoisevariance > -inf); +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!error % Homoscedastic case / do_estim_lnv = false / model.lnv = nan +%! model = stk_model ('stk_materncov32_iso'); +%! model.lognoisevariance = nan; % not compatible with do_estim_lnv == false +%! [model.param, model.lognoisevariance] = ... +%! stk_param_init (model, xi, zi, BOX, false); + +%!error % Heteroscedastic case / do_estim_lnv = true +%! model = stk_model ('stk_materncov32_iso'); +%! lnv = log ((100 + rand (size (zi))) / 1e6); +%! model.lognoisevariance = lnv; % here we say that lnv is known +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX, true); + +%!test % Heteroscedastic case / known noise variance +%! model = stk_model ('stk_materncov32_iso'); +%! lnv = log ((100 + rand (size (zi))) / 1e6); +%! model.lognoisevariance = lnv; % here we say that lnv is known +%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); +%! model.param = stk_param_estim (model, xi, zi, param0); +%! zp = stk_predict (model, xi, zi, xt); +%! assert (isequal (model.lognoisevariance, lnv)); % should be untouched +%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) + +%!shared model, x, z +%! model = stk_model ('stk_materncov52_iso'); +%! n = 10; x = stk_sampling_regulargrid (n, 1, [0; 1]); z = ones (size (x)); + +%!test % Constant response, noiseless model +%! [param, lnv] = stk_param_init (model, x, z); +%! assert ((all (isfinite (param))) && (length (param) == 2)); +%! assert (isequal (lnv, -inf)); + +%!test % Constant response, noisy model +%! model.lognoisevariance = nan; +%! [param, lnv] = stk_param_init (model, x, z); +%! assert ((all (isfinite (param))) && (length (param) == 2)); +%! assert (isscalar (lnv) && isfinite (lnv)); diff -Nru octave-stk-2.4.2/inst/param/estim/stk_param_relik.m octave-stk-2.5.0/inst/param/estim/stk_param_relik.m --- octave-stk-2.4.2/inst/param/estim/stk_param_relik.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/param/estim/stk_param_relik.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,231 @@ +% STK_PARAM_RELIK computes the restricted likelihood of a model given data +% +% CALL: [ARL, dARL_dtheta, dARL_dLNV] = stk_param_relik (MODEL, XI, YI) +% +% computes the opposite of the restricted likelihood (denoted by ARL for +% Anti-Restricted Likelihood) of MODEL given the data (XI, YI). The function +% also returns the gradient dARL_dtheta of ARL with respect to the parameters +% of the covariance function and the derivative dARL_dLNV of ARL with respect +% to the logarithm of the noise variance. +% +% EXAMPLE: see paramestim/stk_param_estim.m + +% Copyright Notice +% +% Copyright (C) 2015, 2016 CentraleSupelec +% Copyright (C) 2011-2014 SUPELEC +% +% Authors: Julien Bect +% Emmanuel Vazquez + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [rl, drl_param, drl_lnv] = stk_param_relik (model, xi, yi) + +if nargin > 3, + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +% Get numerical parameter vector from parameter object +paramvec = stk_get_optimizable_parameters (model.param); + +PARAMPRIOR = isfield (model, 'prior'); +NOISEPRIOR = isfield (model, 'noiseprior'); + +% Make sure that lognoisevariance is -inf for noiseless models +if ~ stk_isnoisy (model) + model.lognoisevariance = -inf; +end + +n = size (xi, 1); + + +%% Compute the (opposite of) the restricted log-likelihood + +[K, P] = stk_make_matcov (model, xi); +q = size (P, 2); +simple_kriging = (q == 0); + +if simple_kriging + + G = K; % No need to filter anything out + +else + + % Construct a "filtering matrix" A = W' + [Q, R_ignored] = qr (P); %#ok %the second argument *must* be here + W = Q(:, (q+1):n); + + % Compute G = W' * K * W (covariance matrix of filtered observations) + M = (stk_cholcov (K)) * W; + G = (M') * M; + + % Check if G is (at least close to) symmetric + Delta = G - G'; s = sqrt (diag (G)); + if any (abs (Delta) > eps * (s * s')) + warning ('STK:stk_param_relik:NumericalAccuracyProblem', ... + 'The computation of G = W'' * K * W is inaccurate.'); + G = 0.5 * (G + G'); % Make it at least symmetric + end +end + +% Cholesky factorization: G = C' * C, with upper-triangular C +C = stk_cholcov (G); + +% Compute log (det (G)) using the Cholesky factor +ldetWKW = 2 * sum (log (diag (C))); + +% Compute (W' yi)' * G^(-1) * (W' yi) as u' * u, with u = C' \ (W' * yi) +if simple_kriging + u = linsolve (C, double (yi), struct ('UT', true, 'TRANSA', true)); +else + u = linsolve (C, W' * double (yi), struct ('UT', true, 'TRANSA', true)); +end +attache = sum (u .^ 2); + +rl = 0.5 * ((n - q) * log(2 * pi) + ldetWKW + attache); + + +%% Add priors + +if PARAMPRIOR + delta_p = paramvec - model.prior.mean; + rl = rl + 0.5 * delta_p' * model.prior.invcov * delta_p; +end + +if NOISEPRIOR + delta_lnv = model.lognoisevariance - model.noiseprior.mean; + rl = rl + 0.5 * (delta_lnv ^ 2) / model.noiseprior.var; +end + + +%% Compute gradient + +if nargout >= 2 + + nbparam = length (paramvec); + drl_param = zeros (nbparam, 1); + + if simple_kriging + H = inv (G); + else + F = linsolve (C, W', struct ('UT', true, 'TRANSA', true)); + H = F' * F; % = W * G^(-1) * W' + end + + z = H * double (yi); + + for diff = 1:nbparam, + V = feval (model.covariance_type, model.param, xi, xi, diff); + drl_param(diff) = 1/2 * (sum (sum (H .* V)) - z' * V * z); + end + + if PARAMPRIOR + drl_param = drl_param + model.prior.invcov * delta_p; + end + + if nargout >= 3, + if model.lognoisevariance == -inf + drl_lnv = nan; + else + diff = 1; + V = stk_noisecov (n, model.lognoisevariance, diff); + drl_lnv = 1/2 * (sum (sum (H .* V)) - z' * V * z); + if NOISEPRIOR + drl_lnv = drl_lnv + delta_lnv / model.noiseprior.var; + end + end + end + +end + +end % function + + + +%!shared f, xi, zi, NI, model, J, dJ1, dJ2 +%! +%! f = @(x)(- (0.8 * x(:, 1) + sin (5 * x(:, 2) + 1) ... +%! + 0.1 * sin (10 * x(:, 3)))); +%! DIM = 3; NI = 20; box = repmat ([-1.0; 1.0], 1, DIM); +%! xi = stk_sampling_halton_rr2 (NI, DIM, box); +%! zi = stk_feval (f, xi); +%! +%! SIGMA2 = 1.0; % variance parameter +%! NU = 4.0; % regularity parameter +%! RHO1 = 0.4; % scale (range) parameter +%! +%! model = stk_model('stk_materncov_aniso'); +%! model.param = log([SIGMA2; NU; 1/RHO1 * ones(DIM, 1)]); + +%!error [J, dJ1, dJ2] = stk_param_relik (); +%!error [J, dJ1, dJ2] = stk_param_relik (model); +%!error [J, dJ1, dJ2] = stk_param_relik (model, xi); +%!test [J, dJ1, dJ2] = stk_param_relik (model, xi, zi); +%!error [J, dJ1, dJ2] = stk_param_relik (model, xi, zi, pi); + +%!test +%! TOL_REL = 0.01; +%! assert (stk_isequal_tolrel (J, 21.6, TOL_REL)); +%! assert (stk_isequal_tolrel (dJ1, [4.387 -0.1803 0.7917 0.1392 2.580]', TOL_REL)); +%! assert (isnan (dJ2)); + +%!shared xi, zi, model, TOL_REL +%! xi = [-1 -.6 -.2 .2 .6 1]'; +%! zi = [-0.11 1.30 0.23 -1.14 0.36 -0.37]'; +%! model = stk_model ('stk_materncov_iso'); +%! model.param = log ([1.0 4.0 2.5]); +%! model.lognoisevariance = log (0.01); +%! TOL_REL = 0.01; + +%!test % Another simple 1D check +%! [ARL, dARL_dtheta, dARL_dLNV] = stk_param_relik (model, xi, zi); +%! assert (stk_isequal_tolrel (ARL, 6.327, TOL_REL)); +%! assert (stk_isequal_tolrel (dARL_dtheta, [0.268 0.0149 -0.636]', TOL_REL)); +%! assert (stk_isequal_tolrel (dARL_dLNV, -1.581e-04, TOL_REL)); + +%!test % Same 1D test with simple kriging +%! model.lm = stk_lm_null; +%! [ARL, dARL_dtheta, dARL_dLNV] = stk_param_relik (model, xi, zi); +%! assert (stk_isequal_tolrel (ARL, 7.475, TOL_REL)); +%! assert (stk_isequal_tolrel (dARL_dtheta, [0.765 0.0238 -1.019]', TOL_REL)); +%! assert (stk_isequal_tolrel (dARL_dLNV, 3.0517e-03, TOL_REL)); + +%!test % Check the gradient on a 2D test case +%! +%! f = @stk_testfun_braninhoo; +%! DIM = 2; +%! BOX = [[-5; 10], [0; 15]]; +%! NI = 20; +%! TOL_REL = 1e-2; +%! DELTA = 1e-6; +%! +%! model = stk_model ('stk_materncov52_iso', DIM); +%! xi = stk_sampling_halton_rr2 (NI, DIM, BOX); +%! zi = stk_feval (f, xi); +%! +%! model.param = [1 1]; +%! [r1 dr] = stk_param_relik (model, xi, zi); +%! +%! model.param = model.param + DELTA * [0 1]; +%! r2 = stk_param_relik (model, xi, zi); +%! +%! assert (stk_isequal_tolrel (dr(2), (r2 - r1) / DELTA, TOL_REL)); diff -Nru octave-stk-2.4.2/inst/paramestim/private/stk_get_optimizable_parameters.m octave-stk-2.5.0/inst/paramestim/private/stk_get_optimizable_parameters.m --- octave-stk-2.4.2/inst/paramestim/private/stk_get_optimizable_parameters.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/paramestim/private/stk_get_optimizable_parameters.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,77 +0,0 @@ -% STK_GET_OPTIMIZABLE_PARAMETERS [STK internal] -% -% CALL: VALUE = stk_get_optimizable_parameters (PARAM) -% -% returns the value of the 'optimizable_parameters' property of PARAM. -% -% NOTE: -% -% Numerical arrays are considered as a special kind of parameter object, for -% which the 'optimizable_parameters' property is taken to be PARAM(:). -% -% INTERNAL FUNCTION WARNING: -% -% This function is currently considered as internal, which is why it is -% located in a private directory. STK users that which to experiment with -% parameter classes can already overload it, but should be aware that -% API-breaking changes are likely to happen in future releases of STK. -% -% See also: stk_set_optimizable_parameters - -% Copyright Notice -% -% Copyright (C) 2016, 2017 CentraleSupelec -% -% Author: Julien Bect - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function value = stk_get_optimizable_parameters (param) - -% This function will catch all calls to stk_get_optimizable_parameters for which -% param is not an object of a "parameter class" (more precisely, a class that -% implements stk_get_optimizable_parameters) - -if ~ isnumeric (param) - - try - - % Extract parameter values - param = param(:); - - % Note: if param is an object, the previous line is actually a call to - % subsref in disguise. This way of supporting parameter objects has - % been introduced in STK 2.0.0 as an "experimental" feature. It is now - % deprecated. - - catch - - stk_error (['stk_get_optimizable_parameters is not implemented for ' ... - 'objects of class ', class(param), '.'], 'TypeMismatch'); - - end - -end % if - -% Make sure that the result is a column vector -value = param(:); - -end % function diff -Nru octave-stk-2.4.2/inst/paramestim/private/stk_set_optimizable_parameters.m octave-stk-2.5.0/inst/paramestim/private/stk_set_optimizable_parameters.m --- octave-stk-2.4.2/inst/paramestim/private/stk_set_optimizable_parameters.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/paramestim/private/stk_set_optimizable_parameters.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,71 +0,0 @@ -% STK_SET_OPTIMIZABLE_PARAMETERS [STK internal] -% -% CALL: PARAM = stk_set_optimizable_parameters (PARAM, VALUE) -% -% sets to VALUE the 'optimizable_parameters' property of PARAM. The argument -% VALUE is expected to be a numerical vector of the appropriate length. -% -% NOTE: -% -% Numerical arrays are considered as a special kind of parameter object, for -% which the 'optimizable_parameters' property is taken to be PARAM(:). -% -% INTERNAL FUNCTION WARNING: -% -% This function is currently considered as internal, which is why it is -% located in a private directory. STK users that which to experiment with -% parameter classes can already overload it, but should be aware that -% API-breaking changes are likely to happen in future releases of STK. -% -% See also: stk_get_optimizable_parameters - -% Copyright Notice -% -% Copyright (C) 2016, 2017 CentraleSupelec -% -% Author: Julien Bect - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function param = stk_set_optimizable_parameters (param, value) - -% This function will catch all calls to stk_set_optimizable_parameters for which -% neither param nor value is an object of a "parameter class" (more precisely, -% a class that implements stk_set_optimizable_parameters) - -try - - % If param is numeric, the following syntax preserves its size and type - param(:) = value; - - % Note: if param is an object, the previous line is actually a call to - % subsasgn in disguise. This way of supporting parameter objects has been - % introduced in STK 2.0.0 as an "experimental" feature. It is now - % deprecated. - -catch - - stk_error (['stk_set_optimizable_parameters is not implemented for ' ... - 'objects of class ', class(param), '.'], 'TypeMismatch'); - -end % if - -end % function diff -Nru octave-stk-2.4.2/inst/paramestim/stk_param_estim.m octave-stk-2.5.0/inst/paramestim/stk_param_estim.m --- octave-stk-2.4.2/inst/paramestim/stk_param_estim.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/paramestim/stk_param_estim.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,318 +0,0 @@ -% STK_PARAM_ESTIM estimates the parameters of a covariance function -% -% CALL: PARAM = stk_param_estim (MODEL, XI, YI, PARAM0) -% CALL: [PARAM, LNV] = stk_param_estim (MODEL, XI, YI, PARAM0) -% -% estimates the parameters PARAM of the covariance function in MODEL -% from the data (XI, YI) using the restricted maximum likelihood (ReML) -% method. A starting point PARAM0 must be provided. -% -% The observations are assumed to be noisy if MODEL.lognoisevariance is -% not -inf. In this case, the variance of the noise is estimated if -% MODEL.lognoisevariance is nan, and assumed known otherwise. The -% estimated log-variance is returned as the second output argument LNV -% (equal to MODEL.lognoisevariance when it is assumed to be known). -% -% CALL: [PARAM, LNV] = stk_param_estim (MODEL, XI, YI, PARAM0, LNV0) -% -% additionally provides an initial guess LNV0 for the logarithm of the -% noise variance. In this case the observations are automatically assumed -% to be noisy, and the value of MODEL.lognoisevariance is ignored. -% -% CALL: PARAM = stk_param_estim (MODEL, XI, YI, PARAM0, [], CRIT) -% CALL: [PARAM, LNV] = stk_param_estim (MODEL, XI, YI, PARAM0, LNV0, CRIT) -% -% uses the estimation criterion CRIT instead of the default ReML criterion. -% -% EXAMPLES: see, e.g., stk_example_kb02, stk_example_kb03, stk_example_kb04, -% stk_example_kb06, stk_example_misc02 - -% Copyright Notice -% -% Copyright (C) 2015-2017 CentraleSupelec -% Copyright (C) 2014 SUPELEC & A. Ravisankar -% Copyright (C) 2011-2013 SUPELEC -% -% Authors: Julien Bect -% Emmanuel Vazquez -% Ashwin Ravisankar -% Remi Stroh - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function [param_opt, lnv_opt, info] = stk_param_estim ... - (model, xi, zi, param0, lnv0, criterion) - -if nargin > 6, - stk_error ('Too many input arguments.', 'TooManyInputArgs'); -end - -% Empty is the same as not provided -if nargin < 6, criterion = []; end -if nargin < 5, lnv0 = []; end -if nargin < 4, param0 = []; end - -% size checking: xi, zi -zi_data = double (zi); -if ~ isequal (size (zi_data), [stk_length(xi) 1]), - errmsg = 'zi should be a column, with the same number of rows as xi.'; - stk_error (errmsg, 'IncorrectSize'); -end - -% Warn about special case: constant response -if (std (zi_data) == 0) - warning ('STK:stk_param_estim:ConstantResponse', ['Constant-response ' ... - 'data: the output of stk_param_estim is likely to be unreliable.']); -end - -% Make sure that lognoisevariance is -inf for noiseless models -if ~ stk_isnoisy (model) - model.lognoisevariance = -inf; -end - -% Should we estimate the variance of the noise, too ? -if ~ isempty (lnv0) - % lnv0 present => noise variance *must* be estimated - do_estim_lnv = true; - if isnan (lnv0) || isinf (lnv0) - stk_error (['Incorrect value for input argumen lnv0. The starting ' ... - 'point for the estimation of lnv must be neither infinite nor ' ... - 'NaN.'], 'IncorrectArgument'); - end -else - % Otherwise, noise variance estimation happens when lnv has NaNs - lnv0 = model.lognoisevariance; - do_estim_lnv = any (isnan (lnv0)); -end - -if do_estim_lnv && (~ isscalar (lnv0)) - stk_error (['Estimating the variance of the noise is not possible ' ... - 'in the hetereoscedastic case yet. Sorry.'], 'IncorrectArgument'); -end - -% Default criterion: restricted likelihood (ReML method) -if isempty (criterion) - criterion = @stk_param_relik; -end - -% param0: provide a value (if not provided as input argument) -[param0, lnv0] = provide_param0_value (model, xi, zi, param0, lnv0); - -% lnv0: try stk_param_init_lnv if we still have no acceptable value -if do_estim_lnv && (isnan (lnv0)) - model.param = param0; - lnv0 = stk_param_init_lnv (model, xi, zi); -end - -% TODO: allow user-defined bounds -[lb, ub] = stk_param_getdefaultbounds (model.covariance_type, param0, xi, zi); - -% Get vector of numerical parameters -u0 = stk_get_optimizable_parameters (param0); - -if do_estim_lnv - [lblnv, ublnv] = get_default_bounds_lnv (model, lnv0, xi, zi); - lb = [lb ; lblnv]; - ub = [ub ; ublnv]; - u0 = [u0; lnv0]; -end - -switch do_estim_lnv - case false, - f = @(u)(f_ (model, u, xi, zi, criterion)); - case true, - f = @(u)(f_with_noise_ (model, u, xi, zi, criterion)); -end - -bounds_available = (~ isempty (lb)) && (~ isempty (ub)); - -if bounds_available - A = stk_options_get ('stk_param_estim', 'minimize_box'); - [u_opt, crit_opt] = stk_minimize_boxconstrained (A, f, u0, lb, ub); -else - A = stk_options_get ('stk_param_estim', 'minimize_unc'); - [u_opt, crit_opt] = stk_minimize_unconstrained (A, f, u0); -end - -if do_estim_lnv - lnv_opt = u_opt(end); - u_opt(end) = []; -else - lnv_opt = model.lognoisevariance; -end - -% Create parameter object -param_opt = stk_set_optimizable_parameters (model.param, u_opt); - -% Create 'info' structure, if requested -if nargout > 2, - info.criterion = criterion; - info.crit_opt = crit_opt; - info.lower_bounds = lb; - info.upper_bounds = ub; -end - -end % function - -%#ok<*CTCH,*LERR,*SPWRN,*WNTAG> - - -%--- The objective function --------------------------------------------------- - -function [l, dl] = f_ (model, u, xi, zi, criterion) - -model.param = stk_set_optimizable_parameters (model.param, u); - -if nargout == 1, - l = criterion (model, xi, zi); -else - [l, dl] = criterion (model, xi, zi); -end - -end % function - - -function [l, dl] = f_with_noise_ (model, u, xi, zi, criterion) - -model.param = stk_set_optimizable_parameters (model.param, u(1:end-1)); -model.lognoisevariance = u(end); - -if nargout == 1, - l = criterion (model, xi, zi); -else - [l, dl, dln] = criterion (model, xi, zi); - dl = [dl; dln]; -end - -end % function - - -function [lblnv,ublnv] = get_default_bounds_lnv ... % -------------------------- - (model, lnv0, xi, zi) %#ok - -TOLVAR = 0.5; - -% Bounds for the variance parameter -empirical_variance = var(zi); -lblnv = log (eps); -ublnv = log (empirical_variance) + TOLVAR; - -% Make sure that lnv0 falls within the bounds -if ~ isempty (lnv0) - lblnv = min (lblnv, lnv0 - TOLVAR); - ublnv = max (ublnv, lnv0 + TOLVAR); -end - -end % function - - -function [param0, lnv0] = provide_param0_value ... % --------------------------- - (model, xi, zi, param0, lnv0) - -% param0: try to use input argument first -if ~ isempty (param0) - - % Cast param0 into an object of the appropriate type - param0 = stk_set_optimizable_parameters (model.param, param0); - - % Test if param0 contains nans - if any (isnan (stk_get_optimizable_parameters (param0))) - warning ('param0 has nans, using model.param instead'); - param0 = []; - end -end - -% param0: try to use model.param if we still have no acceptable value -if isempty (param0) && ~ any (isnan (stk_get_optimizable_parameters (model.param))) - param0 = model.param; -end - -% param0: try stk_param_init if we still have no acceptable value -if isempty (param0) - model.lognoisevariance = lnv0; - [param0, lnv0] = stk_param_init (model, xi, zi); -end - -end % function - - -%!shared f, xi, zi, NI, param0, param1, model -%! -%! f = @(x)(- (0.8 * x + sin (5 * x + 1) + 0.1 * sin (10 * x)) ); -%! DIM = 1; NI = 20; box = [-1.0; 1.0]; -%! xi = stk_sampling_regulargrid (NI, DIM, box); -%! -%! SIGMA2 = 1.0; % variance parameter -%! NU = 4.0; % regularity parameter -%! RHO1 = 0.4; % scale (range) parameter -%! param0 = log ([SIGMA2; NU; 1/RHO1]); -%! -%! model = stk_model ('stk_materncov_iso'); - -%!test % noiseless -%! zi = stk_feval (f, xi); -%! param1 = stk_param_estim (model, xi, zi, param0); -%! assert (isequal (size (param1), size (param0))) - -% We cannot assume a DETERMINISTIC optimization algorithm -% (for some reason, Octave's sqp is not exactly deterministic) - -%!test % same thing, with empty lnv0 (ok) -%! param2 = stk_param_estim (model, xi, zi, param0, []); -%! assert (stk_isequal_tolrel (param2, param1, 1e-2)) - -%!error % same thing, with lnv0 == NaN (not ok as a starting point) -%! param2 = stk_param_estim (model, xi, zi, param0, nan); - -%!error % same thing, with lnv0 == -inf (not ok as a starting point) -%! param2 = stk_param_estim (model, xi, zi, param0, -inf); - -%!test % same thing, with explicit value for 'criterion' -%! param2 = stk_param_estim (model, xi, zi, param0, [], @stk_param_relik); -%! assert (stk_isequal_tolrel (param1, param2, 1e-2)) - -%!test % noiseless -%! zi = stk_feval (f, xi); -%! param1 = stk_param_estim (model, xi, zi, param0); -%! param2 = stk_param_estim (model, xi, zi, param0, [], @stk_param_relik); -%! % We cannot assume a DETERMINISTIC optimization algorithm -%! % (for some reason, Octave's sqp is not exactly deterministic) -%! assert (stk_isequal_tolrel (param1, param2, 1e-2)) - -%!test % noisy -%! NOISE_STD_TRUE = 0.1; -%! NOISE_STD_INIT = 1e-5; -%! zi = zi + NOISE_STD_TRUE * randn(NI, 1); -%! model.lognoisevariance = 2 * log(NOISE_STD_INIT); -%! [param, lnv] = stk_param_estim ... -%! (model, xi, zi, param0, model.lognoisevariance); - -% Incorrect number of input arguments -%!error param = stk_param_estim () -%!error param = stk_param_estim (model); -%!error param = stk_param_estim (model, xi); -%!error param = stk_param_estim (model, xi, zi, param0, log(eps), @stk_param_relik, pi); - -%!test % Constant response -%! model = stk_model ('stk_materncov52_iso'); -%! n = 10; x = stk_sampling_regulargrid (n, 1, [0; 1]); z = ones (size (x)); -%! param = stk_param_estim (model, x, z, model.param); -%! assert ((all (isfinite (param))) && (length (param) == 2)); diff -Nru octave-stk-2.4.2/inst/paramestim/stk_param_getdefaultbounds.m octave-stk-2.5.0/inst/paramestim/stk_param_getdefaultbounds.m --- octave-stk-2.4.2/inst/paramestim/stk_param_getdefaultbounds.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/paramestim/stk_param_getdefaultbounds.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,143 +0,0 @@ -% STK_PARAM_GETDEFAULTBOUNDS provides lower/upper bounds for covariance parameters -% -% CALL: [LB, UB] = stk_param_getdefaultbounds (COVARIANCE_TYPE, PARAM0, XI, ZI) -% -% returns lower bounds LB and upper bounds UB for the optimization of the -% parameters of a parameterized covariance function COVARIANCE_TYPE, given -% the starting point PARAM0 of the optimization and the data (XI, ZI). -% -% NOTE: user-defined covariance functions -% -% For user-defined covariance functions, lower/upper bounds can be provided -% using one of the following two approaches: -% -% a) if the covariance uses a dedicated class C for parameter values, -% the prefered approach is to imlement stk_param_getdefaultbounds for -% this class; -% -% b) otherwise, for a covariance function named mycov, simply provide a -% function named mycov_defaultbounds. - -% Copyright Notice -% -% Copyright (C) 2017 CentraleSupelec -% Copyright (C) 2015 CentraleSupelec & LNE -% Copyright (C) 2011-2014 SUPELEC -% -% Authors: Julien Bect -% Emmanuel Vazquez -% Remi Stroh - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function [lb, ub] = stk_param_getdefaultbounds (covariance_type, param0, xi, zi) - -if isobject (param0) - - % param0 is an object from a class that does not implement - % stk_param_getdefaultbounds (otherwise we wouldn't have ended up here). - % We assume that this is a choice of the designer of the parameter class, - % and therefore return [] without a warning. - - lb = []; - ub = []; - -elseif ~ isfloat (param0) - - stk_error ('Incorrect type for param0.', 'TypeMismatch'); - -else - - % constants - opts = stk_options_get ('stk_param_getdefaultbounds'); - TOLVAR = opts.tolvar; - TOLSCALE = opts.tolscale; - - % bounds for the variance parameter - log_empirical_variance = log (var (double (zi))); - if log_empirical_variance == - Inf - logvar_lb = param0(1) - TOLVAR; - logvar_ub = param0(1) + TOLVAR; - else - logvar_lb = min (log_empirical_variance, param0(1)) - TOLVAR; - logvar_ub = max (log_empirical_variance, param0(1)) + TOLVAR; - end - - dim = size (xi, 2); - - if ~ ischar (covariance_type) - % Assume that model.covariance_type is a handle - covariance_type = func2str (covariance_type); - end - - switch covariance_type, - - case {'stk_materncov_aniso', 'stk_materncov_iso'} - - nu_lb = min (log (0.5), param0(2)); - nu_ub = max (log (min (50, 10 * dim)), param0(2)); - - range_mid = param0(3:end); - range_lb = range_mid(:) - TOLSCALE; - range_ub = range_mid(:) + TOLSCALE; - - lb = [logvar_lb; nu_lb; range_lb]; - ub = [logvar_ub; nu_ub; range_ub]; - - case { 'stk_materncov32_aniso', 'stk_materncov32_iso', ... - 'stk_materncov52_aniso', 'stk_materncov52_iso', ... - 'stk_expcov_aniso', 'stk_expcov_iso', ... - 'stk_gausscov_aniso', 'stk_gausscov_iso', ... - 'stk_sphcov_aniso', 'stk_sphcov_iso'} - - range_mid = param0(2:end); - range_lb = range_mid(:) - TOLSCALE; - range_ub = range_mid(:) + TOLSCALE; - - lb = [logvar_lb; range_lb]; - ub = [logvar_ub; range_ub]; - - otherwise - try - % Undocumented feature: make it possible to define a - % XXXX_getdefaultbounds function that provides parameter - % bounds during estimation for a user-defined covariance - % function called XXXX (in the case, where this covariance - % has parameters type double). - fname = [covariance_type '_getdefaultbounds']; - [lb, ub] = feval (fname, param0, xi, zi); - catch - err = lasterror (); - msg = strrep (err.message, sprintf ('\n'), sprintf ('\n|| ')); - warning(['Unable to initialize covariance parameters ' ... - 'automatically for covariance functions of type ''%s''.'... - '\n\nEmpty bounds are returned.\n\nThe original error ' ... - 'message was:\n|| %s\n'], covariance_type, msg); - lb = []; - ub = []; - end - - end % switch - -end % if - -end % function - diff -Nru octave-stk-2.4.2/inst/paramestim/stk_param_gls.m octave-stk-2.5.0/inst/paramestim/stk_param_gls.m --- octave-stk-2.4.2/inst/paramestim/stk_param_gls.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/paramestim/stk_param_gls.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,105 +0,0 @@ -% STK_PARAM_GLS computes a generalised least squares estimate -% -% CALL: BETA = stk_param_gls (MODEL, XI, ZI) -% -% computes the generalised least squares estimate BETA of the vector of -% coefficients for the linear part of MODEL, where XI and ZI stand for -% the evaluation points and observed responses, respectively. -% -% CALL: [BETA, SIGMA2] = stk_param_gls (MODEL, XI, ZI) -% -% also returns the associated unbiased estimate SIGMA2 of sigma^2, assu- -% ming that the actual covariance matrix of the Gaussian process part of -% the model is sigma^2 K, with K the covariance matrix built from MODEL. -% -% SIGMA2 is actually the "best" unbiased estimate of sigma^2 : -% -% 1 -% SIGMA2 = ----- * || ZI - P BETA ||^2_{K^{-1}} -% n - r -% -% where n is the number of observations, r the length of BETA, P the -% design matrix for the linear part of the model, and || . ||_{K^{-1}} -% the norm associated to the positive definite matrix K^{-1}. It is the -% best estimate with respect to the quadratic risk, among all unbiased -% estimates which are quadratic in the residuals. - -% Copyright Notice -% -% Copyright (C) 2015, 2016 CentraleSupelec -% Copyright (C) 2014 SUPELEC & A. Ravisankar -% Copyright (C) 2011-2013 SUPELEC -% -% Authors: Julien Bect -% Emmanuel Vazquez -% Ashwin Ravisankar - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function [beta, sigma2, L] = stk_param_gls (model, xi, zi) - -n = size (xi, 1); - -% Build the covariance matrix and the design matrix -[K, P] = stk_make_matcov (model, xi); - -% Cast zi into a double-precision array -zi = double (zi); - -% Compute the Generalized Least Squares (GLS) estimate -L = stk_cholcov (K, 'lower'); -W = L \ P; -u = L \ zi; -beta = (W' * W) \ (W' * u); - -if nargin > 1, - % Assuming that the actual covariance matrice is sigma^2 K, compute the - % "best" unbiased estimate of sigma2 (best wrt the quadratic risk, among - % all unbiased estimates which are quadratic in the residuals) - r = length (beta); - sigma2 = 1 / (n - r) * sum ((u - W * beta) .^ 2); -end - -end % end function stk_param_gls - - -%!shared xi, zi, model, beta, sigma2 -%! xi = (1:10)'; zi = sin (xi); -%! model = stk_model ('stk_materncov52_iso'); -%! model.param = [0.0 0.0]; - -%!test -%! model.lm = stk_lm_constant (); -%! [beta, sigma2] = stk_param_gls (model, xi, zi); -%!assert (stk_isequal_tolabs (beta, 0.1346064, 1e-6)) -%!assert (stk_isequal_tolabs (sigma2, 0.4295288, 1e-6)) - -%!test -%! model.lm = stk_lm_affine (); -%! [beta, sigma2] = stk_param_gls (model, xi, zi); -%!assert (stk_isequal_tolabs (beta, [0.4728342; -0.0614960], 1e-6)) -%!assert (stk_isequal_tolabs (sigma2, 0.4559431, 1e-6)) - -%!test -%! model.lm = stk_lm_null (); -%! [beta, sigma2] = stk_param_gls (model, xi, zi); -%!assert (isequal (beta, zeros (0, 1))) -%!assert (stk_isequal_tolabs (sigma2, 0.3977993, 1e-6)) diff -Nru octave-stk-2.4.2/inst/paramestim/stk_param_init_lnv.m octave-stk-2.5.0/inst/paramestim/stk_param_init_lnv.m --- octave-stk-2.4.2/inst/paramestim/stk_param_init_lnv.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/paramestim/stk_param_init_lnv.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,107 +0,0 @@ -% STK_PARAM_INIT_LNV provides a rough estimate of the variance of the noise -% -% CALL: LNV = stk_param_init_lnv (MODEL, XI, YI) -% -% returns a rough estimate of the log of the noise variance computed using -% the given MODEL and data (XI, YI), using the restricted maximum likelihood -% (ReML) method. It selects the maximizer of the ReML criterion out of a -% list of possible values. -% -% NOTE: assumption on the model -% -% The model is assumed to be a stationary Gaussian process, with -% model.param(1) corresponding to the log of the Gaussian process variance. -% This assumption is currently fulfilled by all the models shipped with STK. -% -% See also: stk_param_estim, stk_param_init - -% Copyright Notice -% -% Copyright (C) 2014 SUPELEC -% -% Author: Julien Bect - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function lnv = stk_param_init_lnv (model, xi, zi) - -if nargin > 3, - stk_error ('Too many input arguments.', 'TooManyInputArgs'); -end - -% size checking: xi, zi -if ~ isequal (size (zi), [size(xi, 1) 1]), - errmsg = 'zi should be a column, with the same number of rows as xi.'; - stk_error (errmsg, 'IncorrectSize'); -end - -% Warn about special case: constant response -if (std (double (zi)) == 0) - warning ('STK:stk_param_estim_lnv:ConstantResponse', ['Constant- ' ... - 'response data: the output of stk_param_estim_lnv is likely ' ... - 'to be unreliable.']); -end - -% Make sure that lognoisevariance is -inf for noiseless models -if ~ stk_isnoisy (model) - model.lognoisevariance = -inf; -end - -% We will work with the ratio eta = sigma2_noise / sigma2 -log_eta_min = -15; % exp(-15) = 3e-7 approx -> very small noise -log_eta_max = +15; % exp(+15) = 3e+7 approx -> very large noise -log_eta_list = linspace (log_eta_min, log_eta_max, 5); - -% Initialize parameter search -log_eta_best = nan; -aLL_best = +inf; - -% Try all values from log_eta_list -for log_eta = log_eta_list - model.lognoisevariance = model.param(1) + log_eta; - aLL = stk_param_relik (model, xi, zi); - if (~ isnan (aLL)) && (aLL < aLL_best) - log_eta_best = log_eta; - aLL_best = aLL; - end -end - -if isinf (aLL_best) - errmsg = 'Couldn''t find reasonable parameter values... ?!?'; - stk_error (errmsg, 'AlgorithmFailure'); -end - -lnv = model.param(1) + log_eta_best; - -end % function - - -%!test -%! f = @(x)(- (0.8 * x + sin (5 * x + 1) + 0.1 * sin (10 * x))); -%! ni = 20; -%! xi = (linspace (-1, 1, ni))' + 0.2 * (randn (ni, 1)); -%! zi = stk_feval (f, xi); -%! -%! model = stk_model ('stk_materncov_iso'); -%! model.param = log ([1; 5/2; 1/0.4]); -%! lnv = stk_param_init_lnv (model, xi, zi); -%! -%! assert ((isscalar (lnv)) && (lnv > -30) && (lnv < 30)); diff -Nru octave-stk-2.4.2/inst/paramestim/stk_param_init.m octave-stk-2.5.0/inst/paramestim/stk_param_init.m --- octave-stk-2.4.2/inst/paramestim/stk_param_init.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/paramestim/stk_param_init.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,468 +0,0 @@ -% STK_PARAM_INIT provides a starting point for stk_param_estim -% -% CALL: PARAM = stk_param_init (MODEL, XI, YI) -% -% provides a quick and dirty estimate of the parameters of MODEL based on the -% data (XI, YI), that can be used as a starting point for stk_param_estim. It -% selects the maximizer of the ReML criterion out of a list of possible values -% given data (XI, YI). This syntax is appropriate for noiseless observations -% and for noisy observations with known noise variance (i.e., when the -% 'lognoisevariance' field in MODEL is either -Inf or has a finite value). -% -% CALL: [PARAM, LNV] = stk_param_init (MODEL, XI, YI) -% -% also returns a value for the 'lognoisevariance' field. In the case of -% noiseless observations or noisy observations with known noise variance, this -% is simply the value that was provided by the user in MODEL.lognoisevariance. -% In the case where MODEL.lognoisevariance is NaN (noisy observation with -% unknown noise variance), LNV is estimated by stk_param_init together with -% PARAM. -% -% CALL: [PARAM, LNV] = stk_param_init (MODEL, XI, YI, BOX) -% -% takes into account the (hyper-rectangular) domain on which the model is -% going to be used. It is used in the heuristics that determines the list of -% parameter values mentioned above. BOX should be a 2 x DIM matrix with BOX(1, -% j) and BOX(2, j) being the lower- and upper-bound of the interval on the -% j^th coordinate, with DIM being the dimension of XI, DIM = size(XI,2). If -% provided, If missing or empty, the BOX argument defaults to [min(XI); -% max(XI)]. -% -% CALL: [PARAM, LNV] = stk_param_init (MODEL, XI, YI, BOX, DO_ESTIM_LNV) -% -% with DO_ESTIM_LNV = TRUE forces the estimation of the variance of the noise, -% regardless of the value of MODEL.lognoisevariance. If FALSE, it prevents -% estimation of the variance of the noise, which is only possible if the -% 'lognoisevariance' field in MODEL is either -Inf or has a finite value. -% -% See also stk_example_kb02, stk_example_kb03, stk_example_misc03 - -% Copyright Notice -% -% Copyright (C) 2015, 2016 CentraleSupelec -% Copyright (C) 2012-2014 SUPELEC -% -% Authors: Julien Bect -% Paul Feliot - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function [param, lnv] = stk_param_init (model, varargin) - -cov_list = { ... - 'stk_expcov_iso', ... - 'stk_expcov_aniso', ... - 'stk_gausscov_iso', ... - 'stk_gausscov_aniso', ... - 'stk_materncov_iso', ... - 'stk_materncov_aniso', ... - 'stk_materncov32_iso', ... - 'stk_materncov32_aniso', ... - 'stk_materncov52_iso', ... - 'stk_materncov52_aniso', ... - 'stk_sphcov_iso', ... - 'stk_sphcov_aniso'}; - -if ~ ischar (model.covariance_type) - % Assume that model.covariance_type is a handle - model.covariance_type = func2str (model.covariance_type); -end - -if ismember (model.covariance_type, cov_list) - - % An initialization for this covariance type is provided in STK - [param, lnv] = stk_param_init_ (model, varargin{:}); - -else - try - % Undocumented feature: make it possible to define a XXXX_param_init - % function that provides initial estimates for a user-defined - % covariance function called XXXX. - fname = [model.covariance_type '_param_init']; - [param, lnv] = feval (fname, model, varargin{:}); - catch - err = lasterror (); - msg = strrep (err.message, sprintf ('\n'), sprintf ('\n|| ')); - msg = sprintf (['Unable to initialize covariance parameters ' ... - 'automatically for covariance functions of type ''%s''.\n\nThe ' ... - 'original error message was:\n|| %s\n'], model.covariance_type, msg); - stk_error (msg, 'UnableToInitialize'); - end % try_catch -end % if - -end % function - -%#ok<*CTCH,*LERR> - - -function [param, lnv] = stk_param_init_ (model, xi, zi, box, do_estim_lnv) - -if nargin > 5, - stk_error ('Too many input arguments.', 'TooManyInputArgs'); -end - -if ~ isequal (size (zi), [size(xi, 1) 1]), - errmsg = 'zi should be a column, with the same number of rows as xi.'; - stk_error (errmsg, 'IncorrectSize'); -end - -%--- first, default values for arguments 'box' and 'noisy' --------------------- - -if nargin < 4, - box = []; -end - -if ~ isa (box, 'stk_hrect') - if isempty (box), - box = stk_boundingbox (xi); % Default: bounding box - else - box = stk_hrect (box); - end -end - - -%--- backward compatiblity ----------------------------------------------------- - -% Make sure that lognoisevariance is -inf for noiseless models -if ~ stk_isnoisy (model) - model.lognoisevariance = -inf; -end - -% Ensure backward compatiblity with respect to model.order / model.lm -model = stk_model_fixlm (model); - - -%--- lognoisevariance ? -------------------------------------------------------- - -lnv = model.lognoisevariance; - -% Noise variance estimation is not supported in the heteroscedastic case -if (~ isscalar (lnv)) && (any (isnan (lnv))) - stk_error (['model.lognoisevariance is non-scalar and contains nans. ' ... - 'Noise variance estimation is not supported in the heteroscedastic ' ... - 'case '], 'InvalidArgument'); -end - -% Estimation of noise variance ? -% * if do_estim_lnv is provided, use it to decide -% * if not, estimation occurs when lnv is nan -if nargin < 5 - if isscalar (lnv) - % In the homoscedastic case, estimate noise variance iff lnv is nan - do_estim_lnv = isnan (lnv); - else - % Noise variance estimation is not supported in the heteroscedastic - % case (see above). Heteroscedastic case with known noise variance: - do_estim_lnv = false; - end -else % do_estim_lnv has been provided - if isscalar (lnv) - if do_estim_lnv - lnv = nan; - elseif isnan (lnv) - stk_error (sprintf ... - (['do_estim_lnv is false, but model.lognoisevariance ' ... - 'is nan. If you don''t want the noise variance to be ' ... - 'estimated, you must provide a value for it!']), ... - 'MissingParameterValue'); - end - else - % Noise variance estimation is not supported in the heteroscedastic - % case (see above). - if do_estim_lnv - stk_error (['Noise variance estimation is not supported in the ' ... - 'heteroscedastic case '], 'InvalidArgument'); - end - end -end - -if (do_estim_lnv) && (nargout < 2) - warning (['stk_param_init will be computing an estimation of the ' ... - 'variance of the noise, perhaps should you call the function ' ... - 'with two output arguments?']); -end - - -%--- then, each type of covariance is dealt with specifically ------------------ - -switch model.covariance_type - - case {'stk_expcov_iso', 'stk_materncov32_iso', 'stk_materncov52_iso', ... - 'stk_gausscov_iso', 'stk_sphcov_iso'} - [param, lnv] = paraminit_ (model.covariance_type, ... - xi, zi, box, model.lm, lnv); - - case {'stk_expcov_aniso', 'stk_materncov32_aniso', ... - 'stk_materncov52_aniso', 'stk_gausscov_aniso', 'stk_sphcov_aniso'} - xi = stk_normalize (xi, box); - c = [model.covariance_type(1:end-5) 'iso']; - [param, lnv] = paraminit_ (c, xi, zi, [], model.lm, lnv); - param = [param(1); param(2) - log(diff(box, [], 1))']; - - case 'stk_materncov_iso' - nu = 5/2 * size (xi, 2); - covname_iso = @(param, x, y, diff, pairwise) stk_materncov_iso ... - ([param(1) log(nu) param(2)], x, y, diff, pairwise); - [param, lnv] = paraminit_ (covname_iso, xi, zi, box, model.lm, lnv); - param = [param(1); log(nu); param(2)]; - - case 'stk_materncov_aniso' - nu = 5/2 * size (xi, 2); - covname_iso = @(param, x, y, diff, pairwise) stk_materncov_iso ... - ([param(1) log(nu) param(2)], x, y, diff, pairwise); - xi = stk_normalize (xi, box); - [param, lnv] = paraminit_ (covname_iso, xi, zi, [], model.lm, lnv); - param = [param(1); log(nu); param(2) - log(diff(box, [], 1))']; - - otherwise - errmsg = 'Unsupported covariance type.'; - stk_error (errmsg, 'IncorrectArgument'); -end - -end % function - - -function [param, lnv] = paraminit_ (covname_iso, xi, zi, box, lm, lnv) - -% Check for special case: constant response -if (std (double (zi)) == 0) - warning ('STK:stk_param_init:ConstantResponse', ... - 'Parameter estimation is impossible with constant-response data.'); - param = [0 0]; if any (isnan (lnv)), lnv = 0; end - return % Return some default values -end - -d = size (xi, 2); - -model = stk_model (covname_iso); -model.lm = lm; -model.lognoisevariance = lnv; - -% list of possible values for the ratio eta = sigma2_noise / sigma2 -if (isscalar (lnv) && (lnv ~= -inf)) - % Homoscedastic noisy case, with known or unknown noise variance - eta_list = 10 .^ (-6:3:0); -else - % Noiseless case or heteroscedastic noisy case (known noise variance) - eta_list = 0; -end - -% list of possible values for the range parameter -if isempty (box) - % assume box = repmat([0; 1], 1, d) - box_diameter = sqrt (d); -else - box_diameter = sqrt (sum (diff (box) .^ 2)); -end -rho_max = 2 * box_diameter; -rho_min = box_diameter / 50; -rho_list = logspace (log10 (rho_min), log10 (rho_max), 5); - -% Initialize parameter search -eta_best = NaN; -rho_best = NaN; -sigma2_best = NaN; -aLL_best = +Inf; - -% Homoscedastic case ? -homoscedastic = (isscalar (lnv)); - -% Try all possible combinations of rho and eta from the lists -for eta = eta_list - for rho = rho_list - - % First use sigma2 = 1.0 - model.param = [0.0, -log(rho)]; - - % The same code works for the noiseless case and for the case where lnv - % must be estimated (in the first case, eta = 0 and thus lnv is -inf) - if (eta == 0) || (homoscedastic && (isnan (lnv))) - model.lognoisevariance = log (eta); - [beta_ignored, sigma2] = stk_param_gls (model, xi, zi); %#ok - if ~ (sigma2 > 0), continue; end - log_sigma2 = log (sigma2); - model.lognoisevariance = log (eta * sigma2); - else % Known variances (homo- and hetero-scedastic cases) - model.param = [0.0, -log(rho)]; - log_sigma2 = (mean (lnv)) - (log (eta)); - sigma2 = exp (log_sigma2); - end - - % Now, compute the antilog-likelihood - model.param(1) = log_sigma2; - aLL = stk_param_relik (model, xi, zi); - if ~isnan(aLL) && (aLL < aLL_best) - eta_best = eta; - rho_best = rho; - aLL_best = aLL; - sigma2_best = sigma2; - end - end -end - -if isinf (aLL_best) - errmsg = 'Couldn''t find reasonable parameter values... ?!?'; - stk_error (errmsg, 'AlgorithmFailure'); -end - -param = log ([sigma2_best; 1/rho_best]); - -if (isscalar (lnv)) && (isnan (lnv)) - % Homoscedatic case with unknown variance... Here is our estimate: - lnv = log (eta_best * sigma2_best); -end - -end % function - - -%!test -%! xi = (1:10)'; zi = sin (xi); -%! model = stk_model ('stk_materncov52_iso'); -%! model.param = stk_param_init (model, xi, zi, [1; 10], false); -%! xt = (1:9)' + 0.5; zt = sin (xt); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (sum ((zt - zp.mean) .^ 2) < 1e-3); - -%!test % check equivariance of parameter estimates -%! f = @(x) sin (x); -%! xi = stk_sampling_regulargrid (10, 1); zi = stk_feval (f, xi); -%! shift = 1000; scale = 0.01; -%! model = stk_model ('stk_materncov32_iso'); -%! p1 = stk_param_init (model, xi, zi); -%! p2 = stk_param_init (model, xi, shift + scale .* zi); -%! assert (stk_isequal_tolabs (p2(1), p1(1) + log (scale^2), 1e-10)) -%! assert (stk_isequal_tolabs (p2(2), p1(2), eps)) - -%!shared xi, zi, BOX, xt, zt -%! -%! f = @(x)(- (0.8 * x + sin (5 * x + 1) + 0.1 * sin (10 * x))); -%! DIM = 1; % Dimension of the factor space -%! BOX = [-1.0; 1.0]; % Factor space -%! -%! xi = stk_sampling_regulargrid (20, DIM, BOX); % Evaluation points -%! zi = stk_feval (f, xi); % Evaluation results -%! -%! NT = 400; % Number of points in the grid -%! xt = stk_sampling_regulargrid (NT, DIM, BOX); % Generate a regular grid -%! zt = stk_feval (f, xt); % Values of f on the grid - -%!test -%! model = stk_model ('stk_materncov_iso'); -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); -%! model.param = stk_param_estim (model, xi, zi, param0); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!test -%! model = stk_model ('stk_materncov_aniso'); -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); -%! model.param = stk_param_estim (model, xi, zi, param0); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!test -%! model = stk_model ('stk_materncov32_iso'); -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); -%! model.param = stk_param_estim (model, xi, zi, param0); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!test -%! model = stk_model ('stk_materncov32_aniso'); -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); -%! model.param = stk_param_estim (model, xi, zi, param0); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!test -%! model = stk_model ('stk_materncov52_iso'); -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); -%! model.param = stk_param_estim (model, xi, zi, param0); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!test -%! model = stk_model ('stk_materncov52_aniso'); -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); -%! model.param = stk_param_estim (model, xi, zi, param0); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!test -%! model = stk_model ('stk_gausscov_iso'); -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); -%! model.param = stk_param_estim (model, xi, zi, param0); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!test -%! model = stk_model ('stk_gausscov_aniso'); -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); -%! model.param = stk_param_estim (model, xi, zi, param0); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!test % Homoscedastic case / do_estim_lnv = true -%! model = stk_model ('stk_materncov32_iso'); -%! [model.param, model.lognoisevariance] = ... -%! stk_param_init (model, xi, zi, BOX, true); -%! [model.param, model.lognoisevariance] = ... -%! stk_param_estim (model, xi, zi); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (model.lognoisevariance > -inf); -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!error % Homoscedastic case / do_estim_lnv = false / model.lnv = nan -%! model = stk_model ('stk_materncov32_iso'); -%! model.lognoisevariance = nan; % not compatible with do_estim_lnv == false -%! [model.param, model.lognoisevariance] = ... -%! stk_param_init (model, xi, zi, BOX, false); - -%!error % Heteroscedastic case / do_estim_lnv = true -%! model = stk_model ('stk_materncov32_iso'); -%! lnv = log ((100 + rand (size (zi))) / 1e6); -%! model.lognoisevariance = lnv; % here we say that lnv is known -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX, true); - -%!test % Heteroscedastic case / known noise variance -%! model = stk_model ('stk_materncov32_iso'); -%! lnv = log ((100 + rand (size (zi))) / 1e6); -%! model.lognoisevariance = lnv; % here we say that lnv is known -%! [param0, model.lognoisevariance] = stk_param_init (model, xi, zi, BOX); -%! model.param = stk_param_estim (model, xi, zi, param0); -%! zp = stk_predict (model, xi, zi, xt); -%! assert (isequal (model.lognoisevariance, lnv)); % should be untouched -%! assert (max ((zp.mean - zt) .^ 2) < 1e-3) - -%!shared model, x, z -%! model = stk_model ('stk_materncov52_iso'); -%! n = 10; x = stk_sampling_regulargrid (n, 1, [0; 1]); z = ones (size (x)); - -%!test % Constant response, noiseless model -%! [param, lnv] = stk_param_init (model, x, z); -%! assert ((all (isfinite (param))) && (length (param) == 2)); -%! assert (isequal (lnv, -inf)); - -%!test % Constant response, noisy model -%! model.lognoisevariance = nan; -%! [param, lnv] = stk_param_init (model, x, z); -%! assert ((all (isfinite (param))) && (length (param) == 2)); -%! assert (isscalar (lnv) && isfinite (lnv)); diff -Nru octave-stk-2.4.2/inst/paramestim/stk_param_relik.m octave-stk-2.5.0/inst/paramestim/stk_param_relik.m --- octave-stk-2.4.2/inst/paramestim/stk_param_relik.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/paramestim/stk_param_relik.m 1970-01-01 00:00:00.000000000 +0000 @@ -1,231 +0,0 @@ -% STK_PARAM_RELIK computes the restricted likelihood of a model given data -% -% CALL: [ARL, dARL_dtheta, dARL_dLNV] = stk_param_relik (MODEL, XI, YI) -% -% computes the opposite of the restricted likelihood (denoted by ARL for -% Anti-Restricted Likelihood) of MODEL given the data (XI, YI). The function -% also returns the gradient dARL_dtheta of ARL with respect to the parameters -% of the covariance function and the derivative dARL_dLNV of ARL with respect -% to the logarithm of the noise variance. -% -% EXAMPLE: see paramestim/stk_param_estim.m - -% Copyright Notice -% -% Copyright (C) 2015, 2016 CentraleSupelec -% Copyright (C) 2011-2014 SUPELEC -% -% Authors: Julien Bect -% Emmanuel Vazquez - -% Copying Permission Statement -% -% This file is part of -% -% STK: a Small (Matlab/Octave) Toolbox for Kriging -% (http://sourceforge.net/projects/kriging) -% -% STK is free software: you can redistribute it and/or modify it under -% the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your -% option) any later version. -% -% STK is distributed in the hope that it will be useful, but WITHOUT -% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -% License for more details. -% -% You should have received a copy of the GNU General Public License -% along with STK. If not, see . - -function [rl, drl_param, drl_lnv] = stk_param_relik (model, xi, yi) - -if nargin > 3, - stk_error ('Too many input arguments.', 'TooManyInputArgs'); -end - -% Get numerical parameter vector from parameter object -paramvec = stk_get_optimizable_parameters (model.param); - -PARAMPRIOR = isfield (model, 'prior'); -NOISEPRIOR = isfield (model, 'noiseprior'); - -% Make sure that lognoisevariance is -inf for noiseless models -if ~ stk_isnoisy (model) - model.lognoisevariance = -inf; -end - -n = size (xi, 1); - - -%% Compute the (opposite of) the restricted log-likelihood - -[K, P] = stk_make_matcov (model, xi); -q = size (P, 2); -simple_kriging = (q == 0); - -if simple_kriging - - G = K; % No need to filter anything out - -else - - % Construct a "filtering matrix" A = W' - [Q, R_ignored] = qr (P); %#ok %the second argument *must* be here - W = Q(:, (q+1):n); - - % Compute G = W' * K * W (covariance matrix of filtered observations) - M = (stk_cholcov (K)) * W; - G = (M') * M; - - % Check if G is (at least close to) symmetric - Delta = G - G'; s = sqrt (diag (G)); - if any (abs (Delta) > eps * (s * s')) - warning ('STK:stk_param_relik:NumericalAccuracyProblem', ... - 'The computation of G = W'' * K * W is inaccurate.'); - G = 0.5 * (G + G'); % Make it at least symmetric - end -end - -% Cholesky factorization: G = C' * C, with upper-triangular C -C = stk_cholcov (G); - -% Compute log (det (G)) using the Cholesky factor -ldetWKW = 2 * sum (log (diag (C))); - -% Compute (W' yi)' * G^(-1) * (W' yi) as u' * u, with u = C' \ (W' * yi) -if simple_kriging - u = linsolve (C, double (yi), struct ('UT', true, 'TRANSA', true)); -else - u = linsolve (C, W' * double (yi), struct ('UT', true, 'TRANSA', true)); -end -attache = sum (u .^ 2); - -rl = 0.5 * ((n - q) * log(2 * pi) + ldetWKW + attache); - - -%% Add priors - -if PARAMPRIOR - delta_p = paramvec - model.prior.mean; - rl = rl + 0.5 * delta_p' * model.prior.invcov * delta_p; -end - -if NOISEPRIOR - delta_lnv = model.lognoisevariance - model.noiseprior.mean; - rl = rl + 0.5 * (delta_lnv ^ 2) / model.noiseprior.var; -end - - -%% Compute gradient - -if nargout >= 2 - - nbparam = length (paramvec); - drl_param = zeros (nbparam, 1); - - if simple_kriging - H = inv (G); - else - F = linsolve (C, W', struct ('UT', true, 'TRANSA', true)); - H = F' * F; % = W * G^(-1) * W' - end - - z = H * double (yi); - - for diff = 1:nbparam, - V = feval (model.covariance_type, model.param, xi, xi, diff); - drl_param(diff) = 1/2 * (sum (sum (H .* V)) - z' * V * z); - end - - if PARAMPRIOR - drl_param = drl_param + model.prior.invcov * delta_p; - end - - if nargout >= 3, - if model.lognoisevariance == -inf - drl_lnv = nan; - else - diff = 1; - V = stk_noisecov (n, model.lognoisevariance, diff); - drl_lnv = 1/2 * (sum (sum (H .* V)) - z' * V * z); - if NOISEPRIOR - drl_lnv = drl_lnv + delta_lnv / model.noiseprior.var; - end - end - end - -end - -end % function - - - -%!shared f, xi, zi, NI, model, J, dJ1, dJ2 -%! -%! f = @(x)(- (0.8 * x(:, 1) + sin (5 * x(:, 2) + 1) ... -%! + 0.1 * sin (10 * x(:, 3)))); -%! DIM = 3; NI = 20; box = repmat ([-1.0; 1.0], 1, DIM); -%! xi = stk_sampling_halton_rr2 (NI, DIM, box); -%! zi = stk_feval (f, xi); -%! -%! SIGMA2 = 1.0; % variance parameter -%! NU = 4.0; % regularity parameter -%! RHO1 = 0.4; % scale (range) parameter -%! -%! model = stk_model('stk_materncov_aniso'); -%! model.param = log([SIGMA2; NU; 1/RHO1 * ones(DIM, 1)]); - -%!error [J, dJ1, dJ2] = stk_param_relik (); -%!error [J, dJ1, dJ2] = stk_param_relik (model); -%!error [J, dJ1, dJ2] = stk_param_relik (model, xi); -%!test [J, dJ1, dJ2] = stk_param_relik (model, xi, zi); -%!error [J, dJ1, dJ2] = stk_param_relik (model, xi, zi, pi); - -%!test -%! TOL_REL = 0.01; -%! assert (stk_isequal_tolrel (J, 21.6, TOL_REL)); -%! assert (stk_isequal_tolrel (dJ1, [4.387 -0.1803 0.7917 0.1392 2.580]', TOL_REL)); -%! assert (isnan (dJ2)); - -%!shared xi, zi, model, TOL_REL -%! xi = [-1 -.6 -.2 .2 .6 1]'; -%! zi = [-0.11 1.30 0.23 -1.14 0.36 -0.37]'; -%! model = stk_model ('stk_materncov_iso'); -%! model.param = log ([1.0 4.0 2.5]); -%! model.lognoisevariance = log (0.01); -%! TOL_REL = 0.01; - -%!test % Another simple 1D check -%! [ARL, dARL_dtheta, dARL_dLNV] = stk_param_relik (model, xi, zi); -%! assert (stk_isequal_tolrel (ARL, 6.327, TOL_REL)); -%! assert (stk_isequal_tolrel (dARL_dtheta, [0.268 0.0149 -0.636]', TOL_REL)); -%! assert (stk_isequal_tolrel (dARL_dLNV, -1.581e-04, TOL_REL)); - -%!test % Same 1D test with simple kriging -%! model.lm = stk_lm_null; -%! [ARL, dARL_dtheta, dARL_dLNV] = stk_param_relik (model, xi, zi); -%! assert (stk_isequal_tolrel (ARL, 7.475, TOL_REL)); -%! assert (stk_isequal_tolrel (dARL_dtheta, [0.765 0.0238 -1.019]', TOL_REL)); -%! assert (stk_isequal_tolrel (dARL_dLNV, 3.0517e-03, TOL_REL)); - -%!test % Check the gradient on a 2D test case -%! -%! f = @stk_testfun_braninhoo; -%! DIM = 2; -%! BOX = [[-5; 10], [0; 15]]; -%! NI = 20; -%! TOL_REL = 1e-2; -%! DELTA = 1e-6; -%! -%! model = stk_model ('stk_materncov52_iso', DIM); -%! xi = stk_sampling_halton_rr2 (NI, DIM, BOX); -%! zi = stk_feval (f, xi); -%! -%! model.param = [1 1]; -%! [r1 dr] = stk_param_relik (model, xi, zi); -%! -%! model.param = model.param + DELTA * [0 1]; -%! r2 = stk_param_relik (model, xi, zi); -%! -%! assert (stk_isequal_tolrel (dr(2), (r2 - r1) / DELTA, TOL_REL)); diff -Nru octave-stk-2.4.2/inst/sampling/@stk_function/display.m octave-stk-2.5.0/inst/sampling/@stk_function/display.m --- octave-stk-2.4.2/inst/sampling/@stk_function/display.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_function/display.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,48 @@ +% @STK_FUNCTION/DISPLAY [overload base function] +% +% See also: display + +% Copyright Notice +% +% Copyright (C) 2016 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function display (F) %#ok<*DISPLAY> + +loose_spacing = stk_disp_isloose (); + +name = inputname (1); +if isempty (name) + name = 'ans'; +end + +if loose_spacing + fprintf ('\n'); +end + +fprintf ('%s = ', name); + +disp (F); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_function/disp.m octave-stk-2.5.0/inst/sampling/@stk_function/disp.m --- octave-stk-2.4.2/inst/sampling/@stk_function/disp.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_function/disp.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,63 @@ +% @STK_FUNCTION/DISP [overload base function] +% +% See also: disp + +% Copyright Notice +% +% Copyright (C) 2016 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function disp (F) + +loose_spacing = stk_disp_isloose (); + +fprintf ('<%s>\n', stk_sprintf_sizetype (F)); + +if loose_spacing + fprintf ('\n'); +end + +if ~ strcmp (class (F), 'stk_function') %#ok + + fprintf ('*** WARNING: %s has no proper disp () method.\n', class (F)); + + if loose_spacing + fprintf ('***\n'); + end + + fprintf ('*** Dumping the raw content of the underlying structure...\n'); + + if loose_spacing + fprintf ('***\n\n'); + end + + disp (struct (F)); + + if loose_spacing + fprintf ('\n'); + end + +end % if + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_function/feval.m octave-stk-2.5.0/inst/sampling/@stk_function/feval.m --- octave-stk-2.4.2/inst/sampling/@stk_function/feval.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_function/feval.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,36 @@ +% @STK_FUNCTION/FEVAL [overload base function] +% +% See also: feval + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function F_val = feval (F, x, varargin) %#ok + +stk_error (sprintf ('Method feval is missing from class %s.', ... + class (F)), 'Missing Method'); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_function/get.m octave-stk-2.5.0/inst/sampling/@stk_function/get.m --- octave-stk-2.4.2/inst/sampling/@stk_function/get.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_function/get.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,33 @@ +% @STK_SAMPCRIT_EI/GET [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function value = get (crit, propname) + +value = crit.(propname); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_function/horzcat.m octave-stk-2.5.0/inst/sampling/@stk_function/horzcat.m --- octave-stk-2.4.2/inst/sampling/@stk_function/horzcat.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_function/horzcat.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,36 @@ +% @STK_FUNCTION/HORZCAT [overload base function] +% +% See also: horzcat + +% Copyright Notice +% +% Copyright (C) 2016 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function varargout = horzcat (varargin) + +stk_error (['Arrays of sampling criterion objects are not supported. ', ... + 'Use cell arrays instead.'], 'IllegalOperation'); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_function/stk_function.m octave-stk-2.5.0/inst/sampling/@stk_function/stk_function.m --- octave-stk-2.4.2/inst/sampling/@stk_function/stk_function.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_function/stk_function.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,75 @@ +% STK_FUNCTION [experimental] +% +% EXPERIMENTAL CLASS WARNING: This class is currently considered experimental. +% STK users that wish to experiment with it are welcome to do so, but should +% be aware that API-breaking changes are likely to happen in future releases. +% We invite them to direct any questions, remarks or comments about this +% experimental class to the STK mailing list. +% +% CALL: F = stk_function () +% +% creates a "pure" function object. Pure function objects are useless by +% themselves, and typically constructed as parent objects for derived +% function object classes (e.g., sampling criterion objects). +% +% See also: stk_sampcrit_ei, stk_sampcrit_eqi + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function F = stk_function () + +if nargin > 0 + + % Catch syntax errors (Octave only) + stk_error ('Too many input arguments.', 'TooManyInputArgs'); + +end % if + +F = class (struct (), 'stk_function'); + +end % function + + +%!shared F + +%!test F = stk_function () % ending ";" omitted on purpose, to test disp + +%!error F = stk_function (1.234) % too many input arguments + +%!error [F F]; % arrays of sampling criterion objects are not supported +%!error [F; F]; % idem + +%!error get (F, 'toto'); % field does not exist +%!error y = feval (F, 1.0); % not implemented for "pure" function objects + +%!error dummy = F{2}; % illegal indexing +%!error dummy = F(1.0); % feval not implemented +%!error dummy = F.toto; % field does not exist + +%!error F{2} = 1.234; % illegal indexing +%!error F(5) = 1.234; % illegal indexing +%!error F.toto = 1.234; % field does not exist diff -Nru octave-stk-2.4.2/inst/sampling/@stk_function/subsasgn.m octave-stk-2.5.0/inst/sampling/@stk_function/subsasgn.m --- octave-stk-2.4.2/inst/sampling/@stk_function/subsasgn.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_function/subsasgn.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,50 @@ +% @STK_FUNCTION/SUBSASGN [overload base function] +% +% See also: subsasgn + +% Copyright Notice +% +% Copyright (C) 2016 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function F = subsasgn (F, idx, value) + +switch idx(1).type + + case '.' + + if length (idx) > 1 + value = subsasgn (get (F, idx(1).subs), idx(2:end), value); + end + + F = set (F, idx(1).subs, value); + + case {'{}', '()'} + + errmsg = 'Illegal assignment'; + stk_error (errmsg, 'IllegalAssignment'); + +end + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_function/subsref.m octave-stk-2.5.0/inst/sampling/@stk_function/subsref.m --- octave-stk-2.4.2/inst/sampling/@stk_function/subsref.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_function/subsref.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,53 @@ +% @STK_FUNCTION/SUBSREF [overload base function] +% +% See also: subsref + +% Copyright Notice +% +% Copyright (C) 2016 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [value, argout2] = subsref (F, idx) + +switch idx(1).type + + case '()' + [value, argout2] = feval (F, idx(1).subs{:}); + + case '{}' + + errmsg = 'Indexing with curly braces is not allowed.'; + stk_error (errmsg, 'IllegalIndexing'); + + case '.' + + value = get (F, idx(1).subs); + +end + +if (length (idx)) > 1 + value = subsref (value, idx(2:end)); +end + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_function/vertcat.m octave-stk-2.5.0/inst/sampling/@stk_function/vertcat.m --- octave-stk-2.4.2/inst/sampling/@stk_function/vertcat.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_function/vertcat.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,36 @@ +% @STK_FUNCTION/VERTCAT [overload base function] +% +% See also: vertcat + +% Copyright Notice +% +% Copyright (C) 2016 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function varargout = vertcat (varargin) + +stk_error (['Arrays of sampling criterion objects are not supported. ', ... + 'Use cell arrays instead.'], 'IllegalOperation'); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/stk_halfpintl.m octave-stk-2.5.0/inst/sampling/stk_halfpintl.m --- octave-stk-2.4.2/inst/sampling/stk_halfpintl.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_halfpintl.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,194 @@ +% STK_HALFPINTL computes an intersection of lower half-planes +% +% CALL: [A, B, Z] = stk_halfpintl (A, B) +% +% computes the intersection of the lower half-planes defined by the vector +% of slopes A and the vector of intercepts B. The output vectors A and B +% contain the slopes and intercept of the lines that actually contribute to +% the boundary of the intersection, sorted in such a way that the k^th +% element corresponds to the k^th piece of the piecewise affine boundary. +% The output Z contains the intersection points (shorter by one element). +% +% ALGORITHM +% +% The algorithm implemented in this function is described in [1, 2]. +% +% REFERENCE +% +% [1] P. I. Frazier, W. B. Powell, and S. Dayanik. The Knowledge-Gradient +% Policy for Correlated Normal Beliefs. INFORMS Journal on Computing +% 21(4):599-613, 2009. +% +% [2] W. Scott, P. I. Frazier and W. B. Powell. The correlated knowledge +% gradient for simulation optimization of continuous parameters using +% Gaussian process regression. SIAM J. Optim, 21(3):996-1026, 2011. + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [a, b, z] = stk_halfpintl (a, b) + +% a: slopes +% b: intercepts + +m = length (a); +assert (isequal (size (a), [m 1])); +assert (isequal (size (b), [m 1])); + +if m == 1 + z = []; + return +end + + +% 1) Sort by decreasing slopes (and increasing intercept in case of equality) + +tmp = [a b]; +tmp = sortrows (tmp, [-1 2]); +a_in = tmp(:, 1); +b_in = tmp(:, 2); + + +% 2) Prepare output lists + +a_out = nan (m, 1); % *at most* m lines in the output list +b_out = nan (m, 1); +z_out = nan (m - 1, 1); % the maximal number of intersections in m - 1, then + +a_out(1) = a_in(1); +b_out(1) = b_in(1); + +k_in = 2; % index of the next input element to be analyzed +k_out = 1; % index of the last element stored in the output list + + +% 3) Process input list + +while k_in <= m + + if a_in(k_in) == a_out(k_out) % equality of slopes + + k_in = k_in + 1; + + else % inequality: a_in(k_in) < a_out(k_out) + + % Compute intersection + z = (b_in(k_in) - b_out(k_out)) / (a_out(k_out) - a_in(k_in)); + + if (k_out == 1) || (z > z_out(k_out-1)) + % Insert the new element at the end of the output list + z_out(k_out) = z; + k_out = k_out + 1; + a_out(k_out) = a_in(k_in); + b_out(k_out) = b_in(k_in); + k_in = k_in + 1; + else + % Remove the last element of the output list + k_out = k_out - 1; + end + + end % if + +end % while + +a = a_out(1:k_out); +b = b_out(1:k_out); +z = z_out(1:(k_out - 1)); + +end % function + + +%!test % case #1 +%! a = 1; +%! b = 1; +%! [a_out, b_out, z_out] = stk_halfpintl (a, b); +%! assert (a_out == 1) +%! assert (b_out == 1) +%! assert (isempty (z_out)) + +%!test % case #2: two lines, slopes not equal, already sorted +%! a = [1; -1]; +%! b = [0; 2]; +%! [a_out, b_out, z_out] = stk_halfpintl (a, b); +%! assert (isequal (a_out, [1; -1])) +%! assert (isequal (b_out, [0; 2])) +%! assert (z_out == 1) + +%!test % case #3: same as #2, but not sorted +%! a = [-1; 1]; +%! b = [ 2; 0]; +%! [a_out, b_out, z_out] = stk_halfpintl (a, b); +%! assert (isequal (a_out, [1; -1])) +%! assert (isequal (b_out, [0; 2])) +%! assert (z_out == 1) + +%!test % case #4: two lines, equal slopes, already sorted +%! a = [0; 0]; +%! b = [1; 2]; +%! [a_out, b_out, z_out] = stk_halfpintl (a, b); +%! assert (a_out == 0) +%! assert (b_out == 1) +%! assert (isempty (z_out)) + +%!test % case #5: same as #4, but not sorted +%! a = [0; 0]; +%! b = [2; 1]; +%! [a_out, b_out, z_out] = stk_halfpintl (a, b); +%! assert (a_out == 0) +%! assert (b_out == 1) +%! assert (isempty (z_out)) + +%!test % case #6: add a dominated line to #2 (the result does not change) +%! a = [1; -1; 0]; +%! b = [0; 2; 1]; +%! [a_out, b_out, z_out] = stk_halfpintl (a, b); +%! assert (isequal (a_out, [1; -1])) +%! assert (isequal (b_out, [0; 2])) +%! assert (z_out == 1) + +%!test % case #7: permutation of #6 +%! a = [1; 0; -1]; +%! b = [0; 1; 2]; +%! [a_out, b_out, z_out] = stk_halfpintl (a, b); +%! assert (isequal (a_out, [1; -1])) +%! assert (isequal (b_out, [0; 2])) +%! assert (z_out == 1) + +%!test % case #8: another permutation of #6 +%! a = [0; 1; -1]; +%! b = [1; 0; 2]; +%! [a_out, b_out, z_out] = stk_halfpintl (a, b); +%! assert (isequal (a_out, [1; -1])) +%! assert (isequal (b_out, [0; 2])) +%! assert (z_out == 1) + +%!test % case #9: same as #8, with some duplicated lines added +%! a = [0; 1; 0; -1; 0; -1; 1]; +%! b = [1; 0; 1; 2; 1; 2; 0]; +%! [a_out, b_out, z_out] = stk_halfpintl (a, b); +%! assert (isequal (a_out, [1; -1])) +%! assert (isequal (b_out, [0; 2])) +%! assert (z_out == 1) diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/disp.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/disp.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/disp.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/disp.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,64 @@ +% @STK_SAMPCRIT_AKG/DISP [overload base function] +% +% See also: disp + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function disp (crit) + +loose_spacing = stk_disp_isloose (); + +fprintf ('<%s>\n', stk_sprintf_sizetype (crit)); + +if loose_spacing + fprintf ('|\n'); +end + +if isempty (crit.model) + % Uninstantiated sampling criterion + model_str = '-- (not instantiated)'; +else + % Instantiated sampling criterion + model_str = sprintf ('<%s>', stk_sprintf_sizetype (crit.model)); +end + +if isempty (crit.reference_grid) + % Uninstantiated sampling criterion + xr_str = '-- (use current evaluation points)'; +else + % Instantiated sampling criterion + xr_str = sprintf ('<%s>', stk_sprintf_sizetype (crit.reference_grid)); +end + +fprintf ('| model: %s\n', model_str); +fprintf ('| reference_grid: %s\n', xr_str); + +if loose_spacing + fprintf ('|\n\n'); +end + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/feval.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/feval.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/feval.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/feval.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,57 @@ +% @STK_SAMPCRIT_AKG/FEVAL [overload base function] +% +% See also: feval + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [AKG, zp] = feval (crit, x, varargin) + +% Implementation note: stk_predict currently does not offer the possibility to +% get the right-hand side of the kriging equation, which is needed here. So, +% instead of calling stk_predict, we manipulate here the kriging equation object +% directly... + +kreq = stk_make_kreq (crit.model, x); + +prior_model = get_prior_model (crit.model); + +zc_mean = (get (kreq, 'lambda'))' * (double (get_output_data (crit.model))); +zc_var = stk_make_matcov (prior_model, x, x, true) - get (kreq, 'delta_var'); +zc_std = sqrt (max (0, zc_var)); +zcr_cov0 = stk_make_matcov (prior_model, x, crit.xr); +zcr_cov = zcr_cov0 - (get (kreq, 'RS'))' * crit.zr_lambdamu; + +AKG = stk_sampcrit_akg_eval ... + (zc_mean, zc_std, crit.zr_mean, crit.zr_std, zcr_cov); + +if nargout > 1 + zp = stk_dataframe ([zc_mean zc_var], {'mean' 'var'}); +end + +% FIXME: Loop over blocks, as in stk_predict ? + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/get.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/get.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/get.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/get.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,33 @@ +% @STK_SAMPCRIT_AKG/GET [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function value = get (crit, propname) + +value = crit.(propname); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/set.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/set.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/set.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/set.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,89 @@ +% @STK_SAMPCRIT_AKG/SET [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function crit = set (crit, propname, value) + +switch propname + + case 'model' + crit.model = value; + crit = compute_zr_data (crit); + + case 'reference_grid' + crit.reference_grid = double (value); + if ~ isempty (crit.model) + crit = compute_zr_data (crit); + end + + otherwise + + errmsg = sprintf ('There is no property named %s', propname); + stk_error (errmsg, 'InvalidArgument'); + +end % switch + +end % function + + +function crit = compute_zr_data (crit) + +if isempty (crit.model) + + crit.xr = []; + crit.zr_mean = []; + crit.zr_std = []; + crit.zr_lambdamu = []; + +else + + if isempty (crit.reference_grid) + crit.xr = get_input_data (crit.model); + else + crit.xr = crit.reference_grid; + end + + if isstruct (crit.model) + % Prior model described by a structure (currently considered as improper + % prior, since we have no way of distinguishing between proper and + % improper priors...) + crit.zr_mean = []; + crit.zr_std = []; + crit.zr_lambdamu = []; + else + [zp, lambda, mu] = stk_predict (crit.model, crit.xr); + crit.zr_mean = zp.mean; + crit.zr_std = sqrt (zp.var); + crit.zr_lambdamu = [lambda; mu]; + end + + % WARNING: the "mu" component of this lambdamu vector might be affected by a + % scaling introduced by the kreq object. Do not use directly. + +end + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/stk_sampcrit_akg.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/stk_sampcrit_akg.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_akg/stk_sampcrit_akg.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_akg/stk_sampcrit_akg.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,192 @@ +% STK_SAMPCRIT_AKG [experimental] +% +% EXPERIMENTAL CLASS WARNING: This class is currently considered experimental. +% STK users that wish to experiment with it are welcome to do so, but should +% be aware that API-breaking changes are likely to happen in future releases. +% We invite them to direct any questions, remarks or comments about this +% experimental class to the STK mailing list. +% +% CALL: CRIT = stk_sampcrit_akg (MODEL) +% +% creates an AKG criterion object CRIT associated to MODEL. The input +% argument MODEL can be empty, in which case CRIT is an uninstantiated +% criterion object (to be instantiated later by setting the 'model' +% property of CRIT). The reference grid is taken to be the current set of +% evaluation points as in [1]. +% +% CALL: CRIT = stk_sampcrit_akg (MODEL, XR) +% +% uses XR as reference grid. +% +% FOR MORE INFORMATION +% +% Refer to the documentation of stk_sampcrit_akg_eval for more information. +% +% REFERENCES +% +% [1] W. Scott, P. I. Frazier and W. B. Powell. The correlated knowledge +% gradient for simulation optimization of continuous parameters using +% Gaussian process regression. SIAM J. Optim, 21(3):996-1026, 2011. +% +% See also: stk_sampcrit_akg_eval + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function crit = stk_sampcrit_akg (model, xr) + +if nargin > 2 + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +% Public properties +crit.model = []; % read/write +crit.reference_grid = []; % read/write + +% Private (hidden, read-only) properties +crit.xr = []; +crit.zr_mean = []; +crit.zr_std = []; +crit.zr_lambdamu = []; + +% Create default object +crit = class (crit, 'stk_sampcrit_akg', stk_function ()); + +% Set user-defined value of reference_grid +if (nargin >= 2) && (~ isempty (xr)) + crit = set (crit, 'reference_grid', xr); +end + +% Instantiate the sampling criterion with a model +if (nargin >= 1) && (~ isempty (model)) + crit = set (crit, 'model', model); +end + +end % function + + +%% +% construct with nargin == 0 + +%!shared F, M, AKG +%! M = stk_model_gpposterior (stk_model, [1 2 3]', [1.234 3 2]'); + +%!test F = stk_sampcrit_akg () % ending ";" omitted on purpose, to test disp + +%!assert (isempty (F.model)) +%!assert (isempty (get (F, 'model'))) +%!assert (isempty (F.reference_grid)) +%!assert (isempty (get (F, 'reference_grid'))) +%!error F.toto +%!error get (F, 'toto') + +%!error F.toto = 1.234; % field does not exist +%!error F = set (F, 'toto', 1.234); % field does not exist + +%!error AKG = feval (F, 1.0); + +%!test F = stk_sampcrit_akg (); F.model = M; +%! assert (isequal (F.model, M)); +%!test F = stk_sampcrit_akg (); F = set (F, 'model', M); +%! assert (isequal (F.model, M)); +%! assert (isequal (size (F.zr_mean), [3 1])) % n x 1 +%! assert (isequal (size (F.zr_std), [3 1])) % n x 1 +%! assert (isequal (size (F.zr_lambdamu), [4 3])) % (n+1) x n (constant mean) +%!test F.model = []; % remove model +%! assert (isempty (F.model)); +%! assert (isempty (F.zr_mean)) +%! assert (isempty (F.zr_std)) +%! assert (isempty (F.zr_lambdamu)) + +% set reference grid when model is empty +%!test xr = [1 1.5 2 2.5 3]'; +%! F.reference_grid = xr % ending ";" omitted on purpose, to test disp +%! assert (isequal (F.reference_grid, xr)) +%! assert (isempty (F.zr_mean)) +%! assert (isempty (F.zr_std)) +%! assert (isempty (F.zr_lambdamu)) +%!test F.reference_grid = []; +%! assert (isempty (F.reference_grid)) + +% set reference grid when model is not empty +%!test F = stk_sampcrit_akg (); F.model = M; +%! assert (isequal (F.model, M)); +%! xr = [1 1.5 2 2.5 3]'; +%! F.reference_grid = xr % ending ";" omitted on purpose, to test disp +%! assert (isequal (F.reference_grid, xr)) +%! assert (isequal (size (F.zr_mean), [5 1])) % nr x 1 +%! assert (isequal (size (F.zr_std), [5 1])) % nr x 1 +%! assert (isequal (size (F.zr_lambdamu), [4 5])) % (n+1) x nr (constant mean) +%!test F.reference_grid = []; +%! assert (isempty (F.reference_grid)) + +%% +% construct with nargin == 1; M is a proper (posterior) model + +%!test F = stk_sampcrit_akg (M) % ending ";" omitted on purpose, to test disp + +%!assert (isequal (F.model, M)) + +%!test AKG = feval (F, [1.0; 1.1; 1.2]); +%!assert (isequal (size (AKG), [3 1])) +%!assert (all (AKG >= 0)) + +%!test [AKG2, zp] = feval (F, [1.0; 1.1; 1.2]); +%! assert (isequal (AKG2, AKG)); +%! assert (isa (zp, 'stk_dataframe') && isequal (size (zp), [3 2])) + +%% +% construct with nargin == 1; M is an improper (prior) model + +%!shared F, xr +%! xr = [1 1.5 2 2.5 3]'; +%!test F = stk_sampcrit_akg (stk_model ()); +%!assert (isempty (F.reference_grid)) + +%!test F.reference_grid = xr; +%!assert (isequal (F.reference_grid, xr)) +%!assert (isempty (F.zr_mean)) +%!assert (isempty (F.zr_std)) +%!assert (isempty (F.zr_lambdamu)) + +%!error AKG = feval (F, 1.0); + + +%% +% construct with nargin == 2; M is a proper (posterior) model + +%!shared F, M, xr +%! xr = [1 1.5 2 2.5 3]'; +%! M = stk_model_gpposterior (stk_model, [1 2 3]', [1.234 3 2]'); + +%!test F = stk_sampcrit_akg (M, xr); +%!assert (isequal (F.model, M)) +%!assert (isequal (F.reference_grid, xr)) +%!assert (isequal (size (F.zr_mean), [5 1])) % nr x 1 +%!assert (isequal (size (F.zr_std), [5 1])) % nr x 1 +%!assert (isequal (size (F.zr_lambdamu), [4 5])) % (n+1) x nr (constant mean) + +%!error F = stk_sampcrit_akg (M, xr, 1.234); % too many input arguments diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampcrit_akg_eval.m octave-stk-2.5.0/inst/sampling/stk_sampcrit_akg_eval.m --- octave-stk-2.4.2/inst/sampling/stk_sampcrit_akg_eval.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampcrit_akg_eval.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,233 @@ +% STK_SAMPCRIT_AKG_EVAL computes the Approximate KG criterion +% +% CALL: AKG = stk_sampcrit_akg_eval (ZC_MEAN, ZC_STD, ZR_MEAN, ZR_STD, ZCR_COV) +% +% computes the value AKG of the Approximate KG criterion for a set of +% candidates points, with respect to a certain reference grid. The +% predictive distributions of the objective function (to be minimized) at +% the candidates and reference points is assumed to be jointly Gaussian, +% with mean ZC_MEAN and standard deviation ZC_STD for the candidate points, +% mean ZR_MEAN and satandard deviation ZR_STD on the reference points, and +% covariance matrix ZCR_COV between the candidate and reference points. +% The input argument must have the following sizes: +% +% * ZC_MEAN M x 1, +% * ZC_STD M x 1, +% * ZR_MEAN L x 1, +% * ZR_STD L x 1, +% * ZCR_COV M x L, +% +% where M is the number of candidate points and L the number of reference +% points. The output has size M x 1. +% +% NOTE ABOUT THE "KNOWLEDGE GRADIENT" CRITERION +% +% The "Knowlegde Gradient" (KG) criterion is the one-step look-ahead (a.k.a +% myopic) sampling criterion associated to the problem of estimating the +% minimizer of the objective function under the L^1 loss (equivalently, +% under the linear loss/utility). +% +% This sampling strategy was proposed for the first time in the work of +% Mockus and co-authors in the 70's (see [1] and refs therein), for the case +% of noiseless evaluations, but only applied to particular Brownian-like +% processes for which the minimum of the posterior mean coincides with the +% best evaluations so far (in which case the KG criterion coincides with the +% EI criterion introduced later by Jones et al [2]). +% +% It was later discussed for the case of a finite space with independent +% Gaussian priors first by Gupta and Miescke [3] and then by Frazier et al +% [4] who named it "knowledge gradient". It was extended to the case of +% correlated priors by Frazier et al [5]. +% +% NOTE ABOUT THE REFERENCE SET +% +% For the case of continuous input spaces, there is no exact expression of +% the KG criterion. The approximate KG criterion proposed in this function +% is an approximation of the KG criterion where the continuous 'min' in the +% expression of the criterion at the i^th candidate point are replaced by +% discrete mins over some reference grid *augmented* with the i^th candidate +% point. +% +% This type of approximation has been proposed by Scott et al [6] under the +% name "knowledge gradient for continuous parameters" (KGCP). In [6], the +% reference grid is composed of the current set of evaluation points. The +% implementation proposed in STK leaves this choice to the user. +% +% Note that, with the reference grid proposed in [6], the complexity of one +% evaluation of the AKG (KGCP) criterion increases as O(N log N), where N +% denotes the number of evaluation points. +% +% NOTE ABOUT THE NOISELESS CASE +% +% Simplified formulas are available for the noiseless case (see [7]) but not +% currenly implemented in STK. +% +% REFERENCES +% +% [1] J. Mockus, V. Tiesis and A. Zilinskas. The application of Bayesian +% methods for seeking the extremum. In L.C.W. Dixon and G.P. Szego, eds, +% Towards Global Optimization, 2:117-129, North Holland NY, 1978. +% +% [2] D. R. Jones, M. Schonlau and William J. Welch. Efficient global +% optimization of expensive black-box functions. Journal of Global +% Optimization, 13(4):455-492, 1998. +% +% [3] S. Gupta and K. Miescke, Bayesian look ahead one-stage sampling +% allocations for selection of the best population, J. Statist. Plann. +% Inference, 54:229-244, 1996. +% +% [4] P. I. Frazier, W. B. Powell, S. Dayanik, A knowledge gradient policy +% for sequential information collection, SIAM J. Control Optim., +% 47(5):2410-2439, 2008. +% +% [5] P. I. Frazier, W. B. Powell, and S. Dayanik. The Knowledge-Gradient +% Policy for Correlated Normal Beliefs. INFORMS Journal on Computing +% 21(4):599-613, 2009. +% +% [6] W. Scott, P. I. Frazier and W. B. Powell. The correlated knowledge +% gradient for simulation optimization of continuous parameters using +% Gaussian process regression. SIAM J. Optim, 21(3):996-1026, 2011. +% +% [7] J. van der Herten, I. Couckuyt, D. Deschrijver, T. Dhaene, Fast +% Calculation of the Knowledge Gradient for Optimization of Deterministic +% Engineering Simulations, arXiv preprint arXiv:1608.04550 +% +% See also: STK_SAMPCRIT_EI_EVAL + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function AKG = stk_sampcrit_akg_eval (zc_mean, zc_std, zr_mean, zr_std, zcr_cov) + +% zc_mean: M x 1 where M is the number of (C)andidate points +% zc_std: M x 1 +% zr_mean: L x 1 where L is the number of (R)eference points +% zr_std: L x 1 +% zcr_cov M x L covariance between (C)andidate points and (R)eference points + +% note: Scott et al.'s "KGCP" corresponds to refs points X_1, ..., X_n + +if nargin > 5 + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +M = size (zc_mean, 1); +if ~ isequal (size (zc_mean), [M 1]) + stk_error (['zc_mean should have size M x 1, where M is the number of ' ... + 'candidate points.'], 'IncorrectSize'); +end +if ~ isequal (size (zc_std), [M 1]) + stk_error (['zc_std should have size M x 1, where M is the number of ' ... + 'candidate points.'], 'IncorrectSize'); +end + +L = size (zr_mean, 1); +if ~ isequal (size (zr_mean), [L 1]) + stk_error (['zr_mean should have size L x 1, where L is the number of ' ... + 'reference points.'], 'IncorrectSize'); +end +if ~ isequal (size (zr_std), [L 1]) + stk_error (['zr_std should have size L x 1, where L is the number of ' ... + 'reference points.'], 'IncorrectSize'); +end + +if ~ isequal (size (zcr_cov), [M L]) + stk_error (['zcr_cov should have size L x 1, where M is the number of ' ... + 'candidate points and L the number of reference points.'], ... + 'IncorrectSize'); +end + +AKG = zeros (M, 1); + +% Minimum over the reference grid +if isempty (zr_mean) + zr_min = +inf; +else + zr_min = min (zr_mean); +end + +for i = 1:M + + if zc_std(i) == 0, continue; end + + % Mitigate the effect of small inaccurate covariance values + a0 = zcr_cov(i,:)' / zc_std(i); + a0 = max (-zr_std, min (zr_std, a0)); + + a = [a0; zc_std(i)]; % slopes + b = [zr_mean; zc_mean(i)]; % intercepts + + % Intersection of lower half-planes + % (algorithm similar to the one in Scott et al, 2011, Table 4.1, + % except that cases of equal slopes are dealt with inside the loop) + [a, b, z] = stk_halfpintl (a, b); + + % Compute normal cdfs and pdfs + F = [0; stk_distrib_normal_cdf(z); 1]; + p = [0; stk_distrib_normal_pdf(z); 0]; + + % Compute the expected min (Equation 4.11 in Scott et al, 2011) + expected_min = sum (b .* diff (F)) - sum (a .* diff (p)); + + % Finally, compute the value of the AKG criterion + AKG(i) = max (0, min (zr_min, zc_mean(i)) - expected_min); + +end % for + +end % function + + +%!shared zc_mean, zc_std, zr_mean, zr_std, zcr_cov, AKG, nc +%! xi = [0; 0.2; 0.7; 0.9]; +%! zi = [1; 0.9; 0.6; 0.1] - 10; +%! ni = 4; +%! +%! M_prior = stk_model('stk_materncov32_iso'); +%! M_prior.param = log ([1.0; 2.1]); +%! M_prior.lognoisevariance = 0.678; +%! +%! nc = 20; +%! xc = stk_sampling_regulargrid (nc, 1, [0; 1]); +%! [zp, ignd1, ignd2, K] = stk_predict (M_prior, xi, zi, [xi; xc]); % See CG#07 +%! +%! ir = 1:ni; ic = ni + (1:nc); +%! +%! zc_mean = zp.mean(ic); +%! zc_std = sqrt (zp.var(ic)); +%! +%! % reference grid: current evaluation points ("KGCP") +%! zr_mean = zp.mean(ir); +%! zr_std = sqrt (zp.var(ir)); +%! +%! zcr_cov = K(ic, ir); + +%!test AKG = stk_sampcrit_akg_eval (zc_mean, zc_std, zr_mean, zr_std, zcr_cov); +%!assert (isequal (size (AKG), [nc 1])) +%!assert (all (AKG >= 0)) + +% not enough or too many input args +%!error AKG = stk_sampcrit_akg_eval (zc_mean, zc_std, zr_mean, zr_std); +%!error AKG = stk_sampcrit_akg_eval (zc_mean, zc_std, zr_mean, zr_std, zcr_cov, 1.234); diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampcrit_ehvi_eval.m octave-stk-2.5.0/inst/sampling/stk_sampcrit_ehvi_eval.m --- octave-stk-2.4.2/inst/sampling/stk_sampcrit_ehvi_eval.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampcrit_ehvi_eval.m 2017-09-13 07:51:00.000000000 +0000 @@ -62,7 +62,7 @@ function EHVI = stk_sampcrit_ehvi_eval (zp_mean, zp_std, zi, zr) -if nargin > 4, +if nargin > 4 stk_error ('Too many input arguments.', 'TooManyInputArgs'); end @@ -79,12 +79,28 @@ % Shift rectangle number to third dimension Rs = shiftdim (S.sign, -2); Ra = shiftdim (S.xmin', -1); - Rb = shiftdim (S.xmax', -1); + Rb = shiftdim (S.xmax', -1); - EIa = stk_distrib_normal_ei (Ra, zp_mean, zp_std, 1); % m x p x R - EIb = stk_distrib_normal_ei (Rb, zp_mean, zp_std, 1); % m x p x R + % Number of rectangles + R = size (Ra, 3); - EHVI = EHVI - sum (bsxfun (@times, Rs, prod (EIb - EIa, 2)), 3); + % Deal with BLOCK_SIZE rectangles at a time to avoid OOM + BLOCK_SIZE = ceil (1e7 / (numel (EIr))); + nb_blocks = ceil (R / BLOCK_SIZE); + r2 = 0; + for b = 1:nb_blocks + + r1 = r2 + 1; + r2 = min (r1 + BLOCK_SIZE - 1, R); + + % Both EIa and EIb will have size m x p x BLOCK_SIZE + EIa = stk_distrib_normal_ei (Ra(:, :, r1:r2), zp_mean, zp_std, 1); + EIb = stk_distrib_normal_ei (Rb(:, :, r1:r2), zp_mean, zp_std, 1); + + EHVI = EHVI - sum (bsxfun (@times, ... + Rs(:, :, r1:r2), prod (EIb - EIa, 2)), 3); + + end % if end % if diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/disp.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/disp.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/disp.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/disp.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,56 @@ +% @STK_SAMPCRIT_EI/DISP [overload base function] +% +% See also: disp + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function disp (crit) + +loose_spacing = stk_disp_isloose (); + +fprintf ('<%s>\n', stk_sprintf_sizetype (crit)); + +if loose_spacing + fprintf ('|\n'); +end + +if isempty (crit.model) + % Uninstantiated sampling criterion + model_str = '-- (not instantiated)'; +else + % Instantiated sampling criterion + model_str = sprintf ('<%s>', stk_sprintf_sizetype (crit.model)); +end + +fprintf ('| model: %s\n', model_str); +fprintf ('| current_minimum: %s\n', num2str (crit.current_minimum)); + +if loose_spacing + fprintf ('|\n\n'); +end + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/feval.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/feval.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/feval.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/feval.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,37 @@ +% @STK_SAMPCRIT_EI/FEVAL [overload base function] +% +% See also: feval + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [EI, zp] = feval (crit, x, varargin) + +zp = stk_predict (crit.model, x); + +EI = stk_sampcrit_ei_eval (zp.mean, sqrt (zp.var), crit.current_minimum); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/get.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/get.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/get.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/get.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,33 @@ +% @STK_SAMPCRIT_EI/GET [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function value = get (crit, propname) + +value = crit.(propname); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/set.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/set.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/set.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/set.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,69 @@ +% @STK_SAMPCRIT_EI/SET [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function crit = set (crit, propname, value) + +switch propname + + case 'model' % Modifiable property + + if isempty (value) + + crit.model = []; + crit.current_minimum = +inf; + + else + + % Set 'model' property + crit.model = value; + + % Compute current minimum + zi = get_output_data (crit.model); + if isempty (zi) + crit.current_minimum = +inf; + else + n = size (zi, 1); + crit.current_minimum = min (zi); + end + + end % if + + case 'current_min' % Read-only property + + stk_error (sprintf (['Property ''current_min'' is read-only.\n\n' ... + 'WHY: The value of ''current_min'' is computed automatically ' ... + 'from the input data of the model.']), 'ReadOnlyProperty'); + + otherwise + + errmsg = sprintf ('There is no property named %s', propname); + stk_error (errmsg, 'InvalidArgument'); + +end % switch + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/stk_sampcrit_ei.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/stk_sampcrit_ei.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_ei/stk_sampcrit_ei.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_ei/stk_sampcrit_ei.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,115 @@ +% STK_SAMPCRIT_EI [experimental] +% +% EXPERIMENTAL CLASS WARNING: This class is currently considered experimental. +% STK users that wish to experiment with it are welcome to do so, but should +% be aware that API-breaking changes are likely to happen in future releases. +% We invite them to direct any questions, remarks or comments about this +% experimental class to the STK mailing list. +% +% CALL: CRIT = stk_sampcrit_ei (MODEL) +% +% creates an EI criterion object CRIT associated to MODEL. The input +% argument MODEL can be empty, in which case CRIT is an uninstantiated +% criterion object (to be instantiated later by setting the 'model' +% property of CRIT). +% +% See also: stk_sampcrit_eqi + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function crit = stk_sampcrit_ei (model) + +if nargin > 1 + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +% Public properties +crit.model = []; % read/write +crit.current_minimum = inf; % read only + +% Create default object +crit = class (crit, 'stk_sampcrit_ei', stk_function ()); + +% Instantiate the sampling criterion with a model +if (nargin >= 1) && (~ isempty (model)) + crit = set (crit, 'model', model); +end + +end % function + + +%!error F = stk_sampcrit_ei ([], 1.234); % too many input arguments + +%% +% construct with nargin == 0 + +%!shared F, M, EI +%! M = stk_model_gpposterior (stk_model, [1 2 3]', [1.234 3 2]'); + +%!test F = stk_sampcrit_ei () % ending ";" omitted on purpose, to test disp + +%!assert (isempty (F.model)) +%!assert (isempty (get (F, 'model'))) +%!assert (F.current_minimum == +inf) +%!assert (get (F, 'current_minimum') == +inf) +%!error F.toto +%!error get (F, 'toto') + +%!error F.current_min = 1.234; % read-only +%!error F = set (F, 'current_min', 1.234); % read-only +%!error F.toto = 1.234; % field does not exist +%!error F = set (F, 'toto', 1.234); % field does not exist + +%!error EI = feval (F, 1.0); + +%!test F = stk_sampcrit_ei (); F.model = M; +%! assert (~ isempty (F.model)); +%!test F = stk_sampcrit_ei (); F = set (F, 'model', M); +%! assert (~ isempty (F.model)); +%!test F.model = []; % remove model +%! assert (isempty (F.model)); +%! assert (F.current_minimum == +inf); + +%% +% construct with nargin == 1; M is a proper (posterior) model + +%!test F = stk_sampcrit_ei (M) % ending ";" omitted on purpose, to test disp + +%!assert (isequal (F.model, M)) +%!assert (F.current_minimum == 1.234); + +%!test EI = feval (F, [1.0; 1.1; 1.2]); +%!assert (isequal (size (EI), [3 1])) +%!assert (all (EI >= 0)) + +%% +% construct with nargin == 1; M is an improper (prior) model + +%!shared F +%!test F = stk_sampcrit_ei (stk_model ()); +%!assert (F.current_minimum == +inf); +%!error feval (F, 1.0); diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampcrit_ei_eval.m octave-stk-2.5.0/inst/sampling/stk_sampcrit_ei_eval.m --- octave-stk-2.4.2/inst/sampling/stk_sampcrit_ei_eval.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampcrit_ei_eval.m 2017-09-13 07:51:00.000000000 +0000 @@ -66,130 +66,14 @@ % You should have received a copy of the GNU General Public License % along with STK. If not, see . -function EI = stk_sampcrit_ei_eval (arg1, arg2, arg3) +function EI = stk_sampcrit_ei_eval (zp_mean, zp_std, zi) -if isa (arg2, 'stk_model_gpposterior') - % - % WARNING: DEPRECATED USE ! - % - % We keep this syntax in 2.4.x to avoid breaking things in a bugfix release - % but it will be removed in future releases - % - warn_about_deprecated_use ('EI = stk_sampcrit_ei_eval (xt, M_post, goal)'); - - if nargin > 3 - stk_error ('Too many input arguments.', 'TooManyInputArgs'); - end - - xt = arg1; - M_post = arg2; - - if nargin < 3 - goal = 'minimize'; - else - goal = arg3; - end - - zi = M_post.output_data; assert (size (zi, 2) == 1); - zp = stk_predict (M_post, xt); - - zp_mean = zp.mean; - zp_std = sqrt (zp.var); - -elseif (isa (arg2, 'stk_dataframe')) ... - && (isequal (arg2.colnames, {'mean', 'var'})) - % - % WARNING: DEPRECATED USE ! - % - % We keep this syntax in 2.4.x to avoid breaking things in a bugfix release - % but it will be removed in future releases. - % - warn_about_deprecated_use ('EI = stk_sampcrit_ei_eval (xt, zp, goal)'); - - if nargin > 3 - stk_error ('Too many input arguments.', 'TooManyInputArgs'); - end - - % Remark: With this syntax, xt is ignored. Beurk. - zp = arg2; - - if nargin < 3 - goal = 'minimize'; - else - goal = arg3; - end - - zp_mean = zp.mean; - zp_std = sqrt (zp.var); - - % TODO: warning !!! - - % WARNING: The threshold used here is *not* the usual one (maximum of the - % posterior mean instead of maximum of the observations). - zi = zp_mean; - -else - - % The syntax - % - % EI = stk_sampcrit_ei_eval (zp_mean, zp_std, zi) - % - % is the one that will be kept for future releases. - - if nargin > 4 - stk_error ('Too many input arguments.', 'TooManyInputArgs'); - end - - zp_mean = arg1; - zp_std = arg2; - zi = arg3; - - goal = 'minimize'; - -end - -% Minimize or maximize? -switch goal - case 'minimize' - minimize = true; - threshold = min (zi); - case 'maximize' - minimize = false; - threshold = max (zi); - otherwise - stk_error (['Incorrect value for argument ''goal'': should be ' ... - 'either ''minimize'' or ''maximize''.'], 'InvalidArgument'); +if nargin > 4 + stk_error ('Too many input arguments.', 'TooManyInputArgs'); end % Evaluate the sampling criterion -EI = stk_distrib_normal_ei (threshold, zp_mean, zp_std, minimize); - -end % function - - -function warn_about_deprecated_use (s) - -warning ('STK:stk_hrect:stk_sampcrit_ei_eval:DeprecatedUse', sprintf ([ ... - 'The syntax\n' ... - '\n' ... - ' %s\n' ... - '\n' ... - 'was introduced by mistake in STK 2.4.0 (without documentation,\n' ... - 'but apparently some people read the source code...).\n' ... - '\n' ... - '*** It will not be supported in future releases. ***\n' ... - '\n' ... - 'Please use the syntax\n' ... - '\n' ... - ' EI = stk_sampcrit_ei_eval (zp_mean, zp_std, zi)\n' ... - '\n' ... - 'instead. Sorry for the inconvenience. Use\n' ... - '\n' ... - ' warning (''off'', ' ... - '''STK:stk_hrect:stk_sampcrit_ei_eval:DeprecatedUse'')\n' ... - '\n' ... - 'if you don''t want to see this warning again. ' ... - 'Read the doc for more information.\n'], s)); %#ok +EI = stk_distrib_normal_ei (min (zi), zp_mean, zp_std, true); end % function @@ -214,18 +98,3 @@ %! EI1 = stk_sampcrit_ei_eval (zp.mean, sqrt (zp.var), min (zi)); %!assert (isequal (EI1, EIref)) - -%!test % Deprecated syntax #1 (STK 2.4.0 only, never documented) -%! M_post = stk_model_gpposterior (M_prior, xi, zi); -%! EI2 = stk_sampcrit_ei_eval (xt, M_post); -%! EI2b = stk_sampcrit_ei_eval (xt, M_post, 'minimize'); -%! assert (isequal (EI2, EI2b)); % 'minimize' is the default - -%!assert (isequal (EI2, EIref)) - -%!test % Deprecated syntax #2 (STK 2.4.0 only, never documented) -%! EI3 = stk_sampcrit_ei_eval ([], zp); -%! EI3b = stk_sampcrit_ei_eval ([], zp, 'minimize'); -%! assert (isequal (EI3, EI3b)); % 'minimize' is the default - -%!assert (~ isequal (EI3, EIref)); % we *know* that result will be different !!! diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/disp.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/disp.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/disp.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/disp.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,64 @@ +% @STK_SAMPCRIT_EQI/DISP [overload base function] +% +% See also: disp + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function disp (crit) + +loose_spacing = stk_disp_isloose (); + +fprintf ('<%s>\n', stk_sprintf_sizetype (crit)); + +if loose_spacing + fprintf ('|\n'); +end + +if isempty (crit.model) + % Uninstantiated sampling criterion + model_str = '-- (not instantiated)'; +else + % Instantiated sampling criterion + model_str = sprintf ('<%s>', stk_sprintf_sizetype (crit.model)); +end + +if isa (crit.point_batch_size, 'function_handle') + pbs_str = func2str (crit.point_batch_size); +else + pbs_str = num2str (crit.point_batch_size); +end + +fprintf ('| model: %s\n', model_str); +fprintf ('| quantile_order: %s\n', num2str (crit.quantile_order)); +fprintf ('| point_batch_size: %s\n', pbs_str); +fprintf ('| current_minimum: %s\n', num2str (crit.current_minimum)); + +if loose_spacing + fprintf ('|\n\n'); +end + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/feval.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/feval.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/feval.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/feval.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,70 @@ +% @STK_SAMPCRIT_EQI/FEVAL [overload base function] +% +% See also: feval + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% Copyright (C) EDF R&D +% +% Authors: Tom Assouline, Florent Autret & Stefano Duhamel (for EDF R&D) +% Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function [EQI, zp] = feval (crit, x, tau2) + +zp = stk_predict (crit.model, x); + +zp_mean = zp.mean; +zp_std = sqrt (zp.var); + +if nargin < 3 + % If tau2 is missing, compute tau2 assuming that a batch of size + % crit.point_batch_size will be made at the selected evaluation point. + % Otherwise, use the value of tau2 provided as an input argument. Note + % that the value of crit.point_batch_size is ignored in this second case. + if stk_isnoisy (crit.model) + + if isa (crit.point_batch_size, 'function_handle') + n = stk_length (get (crit.model, 'input_data')); + pbs = feval (crit.point_batch_size, x, n); + else + pbs = crit.point_batch_size; + end + + prior_model = get (crit.model, 'prior_model'); + tau2 = (exp (prior_model.lognoisevariance)) / pbs; + + else + tau2 = 0; + end +end + +tmp = (zp_std .^ 2) ./ (tau2 + zp_std .^ 2); +tmp(zp_std == 0) = 0.0; +quantile_moy = zp_mean + crit.quantile_value * (sqrt (tau2 .* tmp)); +quantile_var = (zp_std .^ 2) .* tmp; + +EQI = stk_sampcrit_ei_eval ( ... + quantile_moy, sqrt (quantile_var), crit.current_minimum); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/get.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/get.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/get.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/get.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,33 @@ +% @STK_SAMPCRIT_EI/GET [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function value = get (crit, propname) + +value = crit.(propname); + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/set.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/set.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/set.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/set.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,127 @@ +% @STK_SAMPCRIT_EQI/SET [overload base function] + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function crit = set (crit, propname, value) + +switch propname + + case 'model' + + if isempty (value) + + crit.model = []; + crit.current_minimum = +inf; + + else + + crit.model = value; + crit.current_minimum = compute_current_minimum (crit); + + end + + case 'quantile_order' + + order = double (value); + + if (~ isscalar (order)) || (order < 0) || (order > 1) + stk_error (['The value of property ''quantile_order'' ' ... + 'must be a scalar between 0 and 1.'], 'InvalidArgument'); + else + crit.quantile_order = order; + try + crit.quantile_value = norminv (order); + catch + crit.quantile_value = - sqrt (2) * erfcinv (2 * order); % CG#09 + end + end + + if ~ isempty (crit.model) + crit.current_minimum = compute_current_minimum (crit); + end + + case 'point_batch_size' + + if ischar (value) + + crit.point_batch_size = str2func (value); + + elseif isa (value, 'function_handle') + + crit.point_batch_size = value; + + else % Last possibility: a fixed numeric value + + point_batch_size = double (value); + + if (~ isscalar (point_batch_size)) || (point_batch_size <= 0) ... + || (point_batch_size ~= floor (point_batch_size)) + stk_error ('Incorrect ''point_batch_size'' value', ... + 'InvalidArgument'); + else + crit.point_batch_size = point_batch_size; + end + + end + + case 'current_minimum' % Visible but read-only property + + stk_error (sprintf (['Property ''current_minimum'' is read-only.' ... + '\n\nWHY: The value of ''current_minimum'' is computed ' ... + 'automatically from the input data of the model.']), ... + 'ReadOnlyProperty'); + + case 'quantile_value' % Hidden, read-only property + + stk_error (sprintf (['Property ''quantile_value'' is read-only.' ... + '\n\nWHY: The value of ''quantile_value'' is computed ' ... + 'automatically from the value of ''quantile_order''.']), ... + 'ReadOnlyProperty'); + + otherwise + + errmsg = sprintf ('There is no property named %s', propname); + stk_error (errmsg, 'InvalidArgument'); + +end % switch + +end % function + + +function m = compute_current_minimum (crit) + +xi = get_input_data (crit.model); + +if isempty (xi) + m = +inf; +else + zp = stk_predict (crit.model, xi); + q = zp.mean + crit.quantile_value * (sqrt (zp.var)); + m = min (q); +end + +end % function diff -Nru octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/stk_sampcrit_eqi.m octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/stk_sampcrit_eqi.m --- octave-stk-2.4.2/inst/sampling/@stk_sampcrit_eqi/stk_sampcrit_eqi.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/@stk_sampcrit_eqi/stk_sampcrit_eqi.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,209 @@ +% STK_SAMPCRIT_EQI [experimental] +% +% EXPERIMENTAL CLASS WARNING: This class is currently considered experimental. +% STK users that wish to experiment with it are welcome to do so, but should +% be aware that API-breaking changes are likely to happen in future releases. +% We invite them to direct any questions, remarks or comments about this +% experimental class to the STK mailing list. +% +% CALL: CRIT = stk_sampcrit_eqi (MODEL) +% +% creates an EQI criterion object CRIT associated to MODEL, where the +% quantile of interest is the median of the output. The input argument +% MODEL can be empty, in which case CRIT is an uninstantiated criterion +% object (which can be instantiated later by setting the 'model' property +% of CRIT). +% +% CALL: CRIT = stk_sampcrit_eqi (MODEL, P) +% +% uses quantile order P instead of the default 0.5. +% +% See also: stk_sampcrit_ei + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function crit = stk_sampcrit_eqi (model, quantile_order, point_batch_size) + +if nargin > 3 + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +% Public properties +crit.model = []; +crit.quantile_order = 0.5; +crit.point_batch_size = 1; +crit.current_minimum = inf; + +% Private (hidden, read-only) properties +crit.quantile_value = 0.0; + +crit = class (crit, 'stk_sampcrit_eqi', stk_function ()); + +% Set user-defined value of quantile_order +if (nargin >= 2) && (~ isempty (quantile_order)) + crit = set (crit, 'quantile_order', quantile_order); +end + +% Set user-defined value of point_batch_size +if (nargin >= 3) && (~ isempty (point_batch_size)) + crit = set (crit, 'point_batch_size', point_batch_size); +end + +% Instantiate the sampling criterion with a model (it is important to do this +% one last, to avoid re-computing current_minimum several times) +if (nargin >= 1) && (~ isempty (model)) + crit = set (crit, 'model', model); +end + +end % function + + +%!error F = stk_sampcrit_eqi ([], 0.5, 10, 1.234); % too many input arguments + +%% +% construct with nargin == 0 + +%!shared F, M, EQI +%! M = stk_model_gpposterior (stk_model, [1 2 3]', [1.234 3 2]'); + +%!test F = stk_sampcrit_eqi () % ending ";" omitted on purpose, to test disp + +%!assert (isempty (F.model)) +%!assert (isempty (get (F, 'model'))) +%!assert (F.quantile_order == 0.5) +%!assert (get (F, 'quantile_order') == 0.5) +%!assert (F.current_minimum == +inf) +%!assert (get (F, 'current_minimum') == +inf) +%!error F.toto +%!error get (F, 'toto') + +%!error F.current_min = 1.234; % read-only +%!error F = set (F, 'current_min', 1.234); % read-only +%!error F.toto = 1.234; % field does not exist +%!error F = set (F, 'toto', 1.234); % field does not exist +%!test F.quantile_order = 0.9; assert (F.quantile_order == 0.9) +%!test F = set (F, 'quantile_order', 0.8); assert (F.quantile_order == 0.8) +%!error F.quantile_order = 1.1; +%!error F.quantile_order = -0.1; +%!error F.quantile_order = [1 2]; +%!error F.current_minimum = 3.333; % read-only +%!error F.quantile_value = 2.222; % read-only + +%!error EQI = feval (F, 1.0); + +%!test F = stk_sampcrit_eqi (); F.model = M; +%! assert (~ isempty (F.model)); +%!test F = stk_sampcrit_eqi (); F = set (F, 'model', M); +%! assert (~ isempty (F.model)); +%!test F.model = []; % remove model +%! assert (isempty (F.model)); +%! assert (F.current_minimum == +inf); + +%% +% construct with nargin == 1; M is a proper (posterior) model + +%!test F = stk_sampcrit_eqi (M) % ending ";" omitted on purpose, to test disp + +%!assert (isequal (F.model, M)) +%!assert (stk_isequal_tolrel (F.current_minimum, 1.234, 10 * eps)); + +%!test EQI = feval (F, [1.0; 1.1; 1.2]); +%!assert (isequal (size (EQI), [3 1])) +%!assert (all (EQI >= 0)) + +%!test F.quantile_order = 0.9; assert (F.quantile_order == 0.9) + +%% +% same as the one before, but with a noisy model + +%!shared F, M, EQI +%! prior_model = stk_model (); +%! prior_model.lognoisevariance = 0.678; +%! M = stk_model_gpposterior (prior_model, [1 2 3]', [1.234 3 2]'); + +%!test F = stk_sampcrit_eqi (M); + +%!assert (isequal (F.model, M)) +%!assert (stk_isequal_tolrel (F.current_minimum, 2.077997, 1e-5)); + +%!test EQI = feval (F, [1.0; 1.1; 1.2]); +%!assert (isequal (size (EQI), [3 1])) +%!assert (all (EQI >= 0)) + +%!test F.quantile_order = 0.9; assert (F.quantile_order == 0.9) + +%% +% construct with nargin == 1; M is an improper (prior) model + +%!shared F +%!test F = stk_sampcrit_eqi (stk_model ()); +%!assert (F.current_minimum == +inf); +%!error feval (F, 1.0); + +%% +% construct with nargin == 2 + +%!shared F, M +%! M = stk_model_gpposterior (stk_model (), [1 2 3]', [1.234 3 2]'); + +%!error F = stk_sampcrit_eqi (M, [], 0); +%!error F = stk_sampcrit_eqi (M, [], 1.5); +%!error F = stk_sampcrit_eqi (M, [], nan); +%!error F = stk_sampcrit_eqi (M, [], [10 20]); +%!test F = stk_sampcrit_eqi (M, [], 10); + +%!assert (isequal (F.quantile_order, 0.5)); +%!assert (isequal (F.point_batch_size, 10)); + +%!error F = stk_sampcrit_eqi (M, 0.8, 0); +%!error F = stk_sampcrit_eqi (M, 0.8, 1.5); +%!error F = stk_sampcrit_eqi (M, 0.8, nan); +%!error F = stk_sampcrit_eqi (M, 0.8, [10 20]); +%!test F = stk_sampcrit_eqi (M, 0.8, 5); + +%!assert (isequal (F.quantile_order, 0.8)); +%!assert (isequal (F.point_batch_size, 5)); + +%% +% test various forms for point_batch_size + +%!shared F, M, EQI +%! prior_model = stk_model (); +%! prior_model.lognoisevariance = 0.678; +%! M = stk_model_gpposterior (prior_model, [1 2 3]', [1.234 3 2]'); +%! F = stk_sampcrit_eqi (M); + +%!test F.point_batch_size = 10; % numeric +%!assert (isequal (F.point_batch_size, 10)) +%!test EQI = feval (F, [1.0; 1.1; 1.2]); + +%!test F.point_batch_size = @(x, n) 100 - n; % function handle +%!assert (isa (F.point_batch_size, 'function_handle')) +%!test EQI = feval (F, [1.0; 1.1; 1.2]); + +%!test F.point_batch_size = 'sin'; % char +%!assert (isa (F.point_batch_size, 'function_handle')) diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampling_maximinlhs.m octave-stk-2.5.0/inst/sampling/stk_sampling_maximinlhs.m --- octave-stk-2.4.2/inst/sampling/stk_sampling_maximinlhs.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampling_maximinlhs.m 2017-09-13 07:51:00.000000000 +0000 @@ -115,7 +115,7 @@ x = zeros (n, d); for i = 1:d % for each dimension, draw a random permutation - [sx, x(:,i)] = sort (rand (n,1)); %#ok + [ignd, x(:,i)] = sort (rand (n,1)); %#ok CG#07 end x = (x - rand (size (x))) / n; diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampling_nesteddesign.m octave-stk-2.5.0/inst/sampling/stk_sampling_nesteddesign.m --- octave-stk-2.4.2/inst/sampling/stk_sampling_nesteddesign.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampling_nesteddesign.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,229 @@ +% STK_SAMPLING_NESTEDDESIGN generates a nested design +% +% CALL: X = stk_sampling_nesteddesign (N, DIM) +% +% generates a nested design with length(N) levels, with N(k) points at +% the k-th level. X has sum(N) rows and (DIM + 1) columns, the last +% column begin the levels. +% A design is nested when all points at the (k+1)-th level are also at +% the k-th level. +% +% CALL: X = stk_sampling_nesteddesign (N, DIM, BOX) +% +% does the same thing in the DIM-dimensional hyperrectangle specified by the +% argument BOX, which is a 2 x DIM matrix where BOX(1, j) and BOX(2, j) are +% the lower- and upper-bound of the interval on the j^th coordinate. +% Default value for BOX: [0; 1]^DIM. +% If BOX is provided, DIM = size(BOX, 2). +% Warning: size(X, 2) == (DIM + 1) +% +% CALL: X = stk_sampling_nesteddesign (N, DIM, BOX, NITER) +% +% allows to change the number of independent random LHS that are used, +% when generating a maximin LHS. +% Default value for NITER: 1000. +% +% CALL: X = stk_sampling_nesteddesign (N, DIM, BOX, NITER, LEVELS) +% +% does the same thing, but the levels are indexed by the vector LEVELS. +% The length of LEVELS must be greater or equal than the length of N. +% Default value for levels: 1:length(N). +% +% EXAMPLE +% +% n = [30, 14, 5, 2]; dim = 2; +% bnd = stk_hrect([-5, 1; 7, 2]); +% levels = [100; 50; 33; 25; 20;]; +% x = stk_sampling_nesteddesign(n, dim, bnd, [], levels); +% +% REFERENCE +% +% [1] Loic Le Gratiet, "Multi-fidelity Gaussian process regression for +% computer experiments", PhD thesis, Universite Paris-Diderot - +% Paris VII, 2013. +% +% See also: stk_sampling_nestedlhs, stk_sampling_maximinlhs + +% Copyright Notice +% +% Copyright (C) 2017 LNE +% Copyright (C) 2017 CentraleSupelec +% +% Authors: Remi Stroh + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function nested_design = stk_sampling_nesteddesign(n, dim, box, niter, levels) + + +if nargin > 5, + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +if nargin < 1, + stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); +end + +%% Read the input arguments + +% number of points +n = n(:); +if any(n <= 0) + stk_error('Number of points at each level must be strictly positive.',... + 'InvalidArgument'); +end +nLev = length(n); + +% Read argument dim +if (nargin > 2) && (~ isempty (box)) + dim = size (box, 2); +elseif (nargin < 2) || (isempty (dim)) + dim = 1; % Default dimension +end + +% Read argument box +if (nargin < 3) || isempty (box) + box = stk_hrect (dim); +else + % Check that box is a box + if ~ isa (box, 'stk_hrect') + box = stk_hrect (box); + end +end + +% niter, number of interation +if (nargin < 4) || isempty(niter) + niter = 1000; +end + +% Read argument levels +level_name = 'Level'; % Column name of the column level +if (nargin < 5) || isempty (levels) + levels = (1:nLev)'; +else + % Find the colnames of the levels + if isa(levels, 'stk_dataframe') + % If isa data frame with a non-empty colname, return the first + % non-empty colnames + empty_colnames = ~cellfun(@isempty, levels.colnames); + if any(empty_colnames) + level_name = levels.colnames{find(empty_colnames, 1)}; + end + end + + % Assert vector + levels = double(levels(:)); + % Assert unique values of levels + if ~isequal(unique(levels), sort(levels)) + stk_error('Levels are not unique.', 'InvalidArgument') + end + + % Check number of proposed levels + if length(levels) < nLev + stk_error('You do not have enough levels, or the array ''n'' is too long.',... + 'InvalidArgument'); + end + levels = levels(1:nLev); +end + +%% Nested design +best_design = NaN(n(1), dim); + +row_highLevels = @(M, k, numb)(numb(M) - ( (numb(k) - 1):-1:0)); +row_currentLevel = @(M, k, numb)(numb(M) - ( (numb(k) - 1):-1:numb(k + 1)) ); + +% k_lev = nLev +best_design(row_highLevels(1, nLev, n), :) = ... + double( stk_sampling_maximinlhs(n(nLev), dim, box, niter) ); + +for k_lev = (nLev - 1):-1:1 + % 1: Generate a LHS design + X_new_k = stk_sampling_maximinlhs(n(k_lev), dim, box, niter); + + % 2: Compute minimal distance between any proposed points, and points + % already in the design + X_prev = best_design(row_highLevels(1, k_lev + 1, n), :); + dist_new_prev = min( stk_dist(X_new_k, X_prev), [], 2); + + % 3: Keep the farthest + [ignd, ind_dist] = sort(dist_new_prev, 'descend'); %#ok CG#07 + ind_select = ind_dist( 1:((n(k_lev) - n(k_lev + 1)) ), 1); + + best_design(row_currentLevel(1, k_lev, n), :) = double( X_new_k(ind_select, :) ); +end + +%% Create a nested design +nested_design = NaN(sum(n), dim + 1); +% The total number of points in the nested design +nCumNb = [0; cumsum(n)]; + +% Add points + the corresponding level +for knL = 1:nLev + nested_design((nCumNb(knL) + 1):(nCumNb(knL + 1)), :) = [ + best_design(row_highLevels(1, knL, n), :), repmat(levels(knL), n(knL), 1)]; +end + +% Add columns names +colnames = cell(1, dim + 1); +if ~isempty(box.colnames) + colnames(1, 1:dim) = box.colnames; +end +colnames{1, dim + 1} = level_name; + +% Return a nested design +nested_design = stk_dataframe(nested_design, colnames); +end + +% Check error for incorrect number of input arguments +%!shared x, n, dim, box, niter, levels +%! n = [23; 14; 5; 2]; dim = 2; box = [0, 0; 4, 4]; niter = 10; +%! levels = [10.1; 15.2; -9.3; 2.4; 17.5]; + +%!error x = stk_sampling_nesteddesign (); +%!test x = stk_sampling_nesteddesign (n); +%!test x = stk_sampling_nesteddesign (n, dim); +%!test x = stk_sampling_nesteddesign (n, dim, box); +%!test x = stk_sampling_nesteddesign (n, dim, box, niter); +%!test x = stk_sampling_nesteddesign (n, dim, box, niter, levels); +%!error x = stk_sampling_nesteddesign (n, dim, box, niter, levels, pi); + +% Check type of ouputs => assert is Nested Design +%!assert ( isequal(size(x), [sum(n), dim + 1]) ); +%!assert ( isa(x, 'stk_dataframe') ); +%! cn = [0; cumsum(n)]; +%! for lev = 1:length(n), +%! y = x( (cn(lev) + 1):(cn(lev + 1)), 1:dim ); +%! assert (isequal (size (y), [n(lev) dim])); +%! if lev > 1 +%! assert ( isequal(z((end - n(lev) + 1):end, :), y) ); +%! end +%! if lev == length(n) +%! assert (stk_is_lhs (y, n(lev), dim, box)); +%! end +%! z = y; +%! end + +% Check column names +%!assert (isequal (x.colnames{dim + 1}, 'Level')); +%! levels = stk_dataframe(levels, {'t'}); +%! box = stk_hrect(box, {'x1', 'x2', 'x3', 'x4'}); +%!test x = stk_sampling_nesteddesign (n, [], box, [], levels); +%!assert (isequal(x.colnames, {'x1', 'x2', 'x3', 'x4', 't'}) ); \ No newline at end of file diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampling_nestedlhs.m octave-stk-2.5.0/inst/sampling/stk_sampling_nestedlhs.m --- octave-stk-2.4.2/inst/sampling/stk_sampling_nestedlhs.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampling_nestedlhs.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,282 @@ +% STK_SAMPLING_NESTEDLHS builds a Nested Latin Hypercube Sampling (NLHS) +% +% CALL: X = stk_sampling_nestedlhs (N, DIM) +% +% builds a NLHS, with length(N) levels, N(k) points at the k-th level, +% and a dimension DIM. X has sum(N) rows and (DIM + 1) columns, the last +% column begin the levels. +% A design is nested when all points observed at the (k+1)-th level are +% also observed at the k-th level. +% A nested design is a Latin Hypercube Sampling (LHS), if every +% sub-design corresponding to a specified level is a LHS. +% Remark: N(k) must divide N(k + 1). +% +% CALL: X = stk_sampling_nestedlhs (N, DIM, BOX) +% +% does the same thing in the DIM-dimensional hyperrectangle specified by the +% argument BOX, which is a 2 x DIM matrix where BOX(1, j) and BOX(2, j) are +% the lower- and upper-bound of the interval on the j^th coordinate. +% Default value for BOX: [0; 1]^DIM. +% If BOX is provided, DIM = size(BOX, 2). +% Warning: size(X, 2) == (DIM + 1) +% +% CALL: X = stk_sampling_nestedlhs (N, DIM, BOX, NITER) +% +% allows to change the number of independent random LHS that are used at +% each level to complete the design. +% Default value for NITER: 1000. +% Put NITER to 1 to generate a random NLHS. +% +% CALL: X = stk_sampling_nestedlhs (N, DIM, BOX, NITER, LEVELS) +% +% does the same thing, but the levels are indexed by the vector LEVELS. +% The length of LEVELS must be greater or equal than the length of N. +% Default value for LEVELS: 1:length(N). +% +% EXAMPLE +% +% n = [48, 12, 6, 2]; dim = 2; +% bnd = stk_hrect([-5, 1; 7, 2]); +% levels = [100; 50; 33; 25; 20;]; +% x = stk_sampling_nestedlhs(n, dim, bnd, [], levels); +% +% REFERENCE +% +% [1] Peter Z. G. Qian, "Nested latin hypercube designs", Biometrika, +% 96(4):957-970, 2009. +% +% See also: stk_sampling_nesteddesign, stk_sampling_randomlhs + +% Copyright Notice +% +% Copyright (C) 2017 LNE +% Copyright (C) 2017 CentraleSupelec +% +% Authors: Remi Stroh + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function nested_LHS = stk_sampling_nestedlhs(n, dim, box, niter, levels) + +if nargin > 5, + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +if nargin < 1, + stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); +end + +%% Read input arguments +% number of points +n = n(:); % assert vector +if any(n <= 0) + stk_error('Number of points at each level must be strictly positive.',... + 'InvalidArgument'); +end +nLev = length(n); + +% Read argument dim +if (nargin > 2) && (~ isempty (box)) + dim = size (box, 2); +elseif (nargin < 2) || (isempty (dim)) + dim = 1; % Default dimension +end + +% Read argument box +if (nargin < 3) || isempty (box) + box = stk_hrect (dim); +else + % Check that box is a box + if ~ isa (box, 'stk_hrect') + box = stk_hrect (box); + end +end + +% niter, number of interation +if (nargin < 4) || isempty(niter) + niter = 1000; +end + +% Read argument levels +level_name = 'Level'; % Column name of the column level +if (nargin < 5) || isempty (levels) + levels = (1:nLev)'; +else + % Find the colnames of the levels + if isa(levels, 'stk_dataframe') + % If isa data frame with a non-empty colname, return the first + % non-empty colnames + empty_colnames = ~cellfun(@isempty, levels.colnames); + if any(empty_colnames) + level_name = levels.colnames{find(empty_colnames, 1)}; + end + end + + % Assert vector + levels = double(levels(:)); + % Assert unique values of levels + if ~isequal(unique(levels), sort(levels)) + stk_error('Levels are not unique.', 'InvalidArgument') + end + + % Check number of proposed levels + if length(levels) < nLev + stk_error('You do not have enough levels, or the array ''n'' is too long.',... + 'InvalidArgument'); + end + levels = levels(1:nLev); +end + +%% Quotient between each level +quotient = floor(n(1:(nLev - 1))./n(2:nLev)); +remainder = n(1:(nLev - 1)) - quotient.*n(2:nLev); +if any( remainder ~= 0 ) + %assert n(2)|n(1); n(3)|n(2); n(4)|n(3); etc, ... + stk_error(['This method supposes that the number of points',... + ' at level t + 1 divides the number of points at level t.'],... + 'InvalidArgument'); +end + +%% Build the nested design +% Nested Latin hypercube designs +% BY PETER Z. G. QIAN, 2009 + +best_LHS = NaN(n(1), dim); +X_prev = NaN(0, dim); % at the beginning there is not any point +n = [n; 0]; % no point are asked at the level nLev + 1 +quotient = [1; quotient]; % no multiplication at the first level + +% Two functions to find points of a level +row_highLevels = @(M, k, numb)(numb(M) - ( (numb(k) - 1):-1:0)); +row_currentLevel = @(M, k, numb)(numb(M) - ( (numb(k) - 1):-1:numb(k + 1)) ); + +for k_lev = nLev:-1:1; %begin by the end + + list_nb = (1:n(k_lev))'; % list of all values we must get after this loop + n_new_k = n(k_lev) - n(k_lev + 1); % number of new value to add + + list_nb_new_k = NaN(n_new_k, dim); + for id = 1:dim + list_nb_new_k(:, id) = list_nb(~ismember(list_nb, X_prev(:, id)), 1); + % Find every element in the complete list of number, which are not + % chosen in the previous level + end + + best_score = -Inf; + for k_try = 1:niter + + X_new_kl = NaN(n_new_k, dim); %the matrix to add + + [ignd, random_index] = sort(rand(n_new_k, dim), 1); %#ok CG#07 + for i = 1:dim + X_new_kl(:, i) = list_nb_new_k(random_index(:, i), i); + end + + LHS_cand_kl = NaN(n(k_lev), dim); + LHS_cand_kl(row_highLevels(k_lev, k_lev + 1, n), :) = X_prev; + LHS_cand_kl(row_currentLevel(k_lev, k_lev, n) , :) = X_new_kl; + % add new results (only observed at this level, and not any higher) + % to previous results (corresponding to point observed at higher levels, + % and so, at this level too) + + % Random moves + LHS_cand_kl = LHS_cand_kl - rand(n(k_lev), dim); + % Extend on a larger space for next loop + LHS_cand_kl = ceil(quotient(k_lev)*LHS_cand_kl); + + if n(k_lev) > 1 && niter > 1 + score = stk_mindist(LHS_cand_kl); + else % particular case where n(kl) == 1 (no distance) + score = 0; + end + if score > best_score + % Save the best design in the lhs. + best_score = score; + best_LHS = LHS_cand_kl; + end + end % end k_try + % For the next loop, get the points of the previous levels + X_prev = best_LHS; +end +% Remove the 0 from the end +n = n(1:nLev); + +% Random move + scaling in [0; 1] +best_LHS = (best_LHS - rand(n(1), dim))/n(1); +% Rescale in box +best_LHS = stk_rescale(best_LHS, [], box); + +%% Create a nested design +nested_LHS = NaN(sum(n), dim + 1); +% The total number of points in the LHS design +nCumNb = [0; cumsum(n)]; + +% Add points + the corresponding level +for knL = 1:nLev + nested_LHS((nCumNb(knL) + 1):(nCumNb(knL + 1)), :) = [ + best_LHS(row_highLevels(1, knL, n), :), repmat(levels(knL), n(knL), 1)]; +end + +% Add columns names +colnames = cell(1, dim + 1); +if ~isempty(box.colnames) + colnames(1, 1:dim) = box.colnames; +end +colnames{1, dim + 1} = level_name; + +% Return a nested LHS +nested_LHS = stk_dataframe(nested_LHS, colnames); + +end + +% Check error for incorrect number of input arguments +%!shared x, n, dim, box, niter, levels +%! n = [48; 12; 4; 2]; dim = 2; box = [0, 0; 4, 4]; niter = 10; +%! levels = [10.1; 15.2; -9.3; 2.4; 17.5]; + +%!error x = stk_sampling_nestedlhs (); +%!test x = stk_sampling_nestedlhs (n); +%!test x = stk_sampling_nestedlhs (n, dim); +%!test x = stk_sampling_nestedlhs (n, dim, box); +%!test x = stk_sampling_nestedlhs (n, dim, box, niter); +%!test x = stk_sampling_nestedlhs (n, dim, box, niter, levels); +%!error x = stk_sampling_nestedlhs (n, dim, box, niter, levels, pi); + +% Check type of ouputs => assert is Nested LHS +%!assert ( isequal(size(x), [sum(n), dim + 1]) ); +%!assert ( isa(x, 'stk_dataframe') ); +%! cn = [0; cumsum(n)]; +%! for lev = 1:length(n), +%! y = x( (cn(lev) + 1):(cn(lev + 1)), 1:dim ); +%! assert (isequal (size (y), [n(lev) dim])); +%! assert (stk_is_lhs (y, n(lev), dim, box)); +%! if lev > 1 +%! assert ( isequal(z((end - n(lev) + 1):end, :), y) ); +%! end +%! z = y; +%! end + +% Check column names +%!assert (isequal (x.colnames{dim + 1}, 'Level')); +%! levels = stk_dataframe(levels, {'t'}); +%! box = stk_hrect(box, {'x1', 'x2', 'x3', 'x4'}); +%!test x = stk_sampling_nestedlhs (n, [], box, [], levels); +%!assert (isequal(x.colnames, {'x1', 'x2', 'x3', 'x4', 't'}) ); \ No newline at end of file diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampling_olhs.m octave-stk-2.5.0/inst/sampling/stk_sampling_olhs.m --- octave-stk-2.4.2/inst/sampling/stk_sampling_olhs.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampling_olhs.m 2017-09-13 07:51:00.000000000 +0000 @@ -89,7 +89,7 @@ n_ = 2^(r + 1) + 1; if (r <= 0) || (abs(n - n_) > eps), errmsg = 'n must be an integer of the form 2^(r+1) + 1 with r > 0'; - stk_error(errmsg, 'IncorrectArgument'); + stk_error(errmsg, 'InvalidArgument'); end n = n_; @@ -99,7 +99,7 @@ if (nargin > 1) && ~isempty(d), if d ~= 2 * r, errmsg = 'Incorrect value of d, please read the documentation...'; - stk_error(errmsg, 'IncorrectArgument'); + stk_error(errmsg, 'InvalidArgument'); end else d = 2 * r; @@ -110,7 +110,7 @@ if (nargin > 1) && ~isempty(d), if d ~= r + 1 + nchoosek(r, 2), errmsg = 'Incorrect value of d, please read the documentation...'; - stk_error(errmsg, 'IncorrectArgument'); + stk_error(errmsg, 'InvalidArgument'); end else d = r + 1 + nchoosek(r, 2); @@ -134,7 +134,7 @@ permut = permut(:); if ~isequal(sort(permut), (1:q)'), errmsg = sprintf('permut should be a permutation of 1:%d.', q); - stk_error(errmsg, 'IncorrectArgument'); + stk_error(errmsg, 'InvalidArgument'); end end diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampling_randunif.m octave-stk-2.5.0/inst/sampling/stk_sampling_randunif.m --- octave-stk-2.4.2/inst/sampling/stk_sampling_randunif.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampling_randunif.m 2017-09-13 07:51:00.000000000 +0000 @@ -59,19 +59,28 @@ % Read argument box if (nargin < 3) || isempty (box) - box = stk_hrect (dim); % build a default box + box = []; % default box: [0; 1] ^ dim else box = stk_hrect (box); % convert input argument to a proper box end -if n == 0, % empty sample - xdata = zeros (0, dim); -else % at least one input point - xdata = stk_rescale (rand(n, dim), [], box); +if isempty (box) + if n == 0 + x = stk_dataframe (zeros (0, dim)); % Empty sample + else + x = stk_dataframe (rand (n, dim)); + end +else + if n == 0 + x = stk_dataframe (box, [], {}); % Keep column names + x = set_data (x, zeros (0, dim)); % Empty sample + else + % FIXME: stk_rescale should return a df when box is a df ? + x = stk_dataframe (box, [], {}); + x = set_data (x, stk_rescale (rand (n, dim), [], box)); + end end -x = stk_dataframe (xdata, box.colnames); - end % function diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampling_regulargrid.m octave-stk-2.5.0/inst/sampling/stk_sampling_regulargrid.m --- octave-stk-2.4.2/inst/sampling/stk_sampling_regulargrid.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampling_regulargrid.m 2017-09-13 07:51:00.000000000 +0000 @@ -58,9 +58,15 @@ % Read argument 'box' if (nargin < 3) || isempty (box) - box = stk_hrect (dim); % build a default box + xmin = zeros (1, dim); + xmax = ones (1, dim); + box_colnames = {}; else box = stk_hrect (box); % convert input argument to a proper box + box_data = double (box); + box_colnames = get (box, 'colnames'); + xmin = box_data(1, :); + xmax = box_data(2, :); end if length (n) == 1 @@ -78,13 +84,11 @@ % levels levels = cell (1, dim); -xmin = box.data(1, :); -xmax = box.data(2, :); for j = 1:dim, levels{j} = linspace (xmin(j), xmax(j), n(j)); end -x = stk_factorialdesign (levels, box.colnames); +x = stk_factorialdesign (levels, box_colnames); end % function diff -Nru octave-stk-2.4.2/inst/sampling/stk_sampling_sobol.m octave-stk-2.5.0/inst/sampling/stk_sampling_sobol.m --- octave-stk-2.4.2/inst/sampling/stk_sampling_sobol.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/sampling/stk_sampling_sobol.m 2017-09-13 07:51:00.000000000 +0000 @@ -1,17 +1,24 @@ % STK_SAMPLING_SOBOL generates points from a Sobol sequence % % CALL: X = stk_sampling_sobol (N, D) -% CALL: X = stk_sampling_sobol (N, D, FALSE) % % computes the first N terms of a D-dimensional Sobol sequence (with % N < 2^32 and D <= 1111). The sequence is generated using the algorithm % of Bratley and Fox [1], as modified by Joe and Kuo [3]. % -% CALL: X = stk_sampling_sobol (N, D, TRUE) -% -% skips an initial segment of the sequence. More precisely, according to -% the recommendation of [2] and [3], a number of points equal to the largest -% power of 2 smaller than n is skipped. +% CALL: X = stk_sampling_sobol (N, DIM, BOX) +% +% does the same thing in the DIM-dimensional hyperrectangle specified by the +% argument BOX, which is a 2 x DIM matrix where BOX(1, j) and BOX(2, j) are +% the lower- and upper-bound of the interval on the j^th coordinate. +% +% CALL: X = stk_sampling_sobol (N, D, BOX, DO_SKIP) +% +% skips an initial segment of the Sobol sequence if DO_SKIP is true. More +% precisely, according to the recommendation of [2] and [3], a number of +% points equal to the largest power of 2 smaller than n is skipped. If +% DO_SKIP is false, the beginning of the sequence is returns, as in the +% previous cases (in other words, DO_SKIP = false is the default). % % NOTE: Implementation % @@ -84,7 +91,7 @@ % Check that either dim or box is provided if (isempty (dim)) && (isempty (box)) stk_error (['The dimension argument can be omitted if, and only if, a ' ... - 'valid box argument is provided instead.'], 'IncorrectArgument'); + 'valid box argument is provided instead.'], 'InvalidArgument'); end % Process box argument @@ -97,7 +104,7 @@ dim = size (box, 2); elseif dim ~= size (box, 2) stk_error (['The dimension argument must be compatible with' ... - 'the box argument when both are provided.'], 'IncorrectArgument'); + 'the box argument when both are provided.'], 'InvalidArgument'); end end diff -Nru octave-stk-2.4.2/inst/stk_init.m octave-stk-2.5.0/inst/stk_init.m --- octave-stk-2.4.2/inst/stk_init.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/stk_init.m 2017-09-13 07:51:00.000000000 +0000 @@ -1,6 +1,6 @@ % STK_INIT initializes the STK % -% CALL: stk_init() +% CALL: stk_init () % % STK_INIT sets paths and environment variables @@ -126,15 +126,14 @@ function stk_init__munlock () -filenames = { ... - 'isoctave', ... - 'stk_optim_fmincon', ... - 'stk_options_set', ... - 'stk_parallel_engine_set'}; +filenames = { ... + 'stk_optim_fmincon', ... + 'stk_options_set', ... + 'stk_parallel_engine_set' }; for i = 1:(length (filenames)) name = filenames{i}; - if mislocked (name), + if mislocked (name) munlock (name); end end @@ -146,20 +145,19 @@ stk_init__munlock (); -filenames = { ... - 'isoctave', ... - 'stk_disp_progress', ... - 'stk_gausscov_iso', ... - 'stk_gausscov_aniso', ... - 'stk_materncov_aniso', ... - 'stk_materncov_iso', ... - 'stk_materncov32_aniso', ... - 'stk_materncov32_iso', ... - 'stk_materncov52_aniso', ... - 'stk_materncov52_iso', ... - 'stk_optim_fmincon', ... - 'stk_options_set', ... - 'stk_parallel_engine_set'}; +filenames = { ... + 'stk_disp_progress', ... + 'stk_gausscov_iso', ... + 'stk_gausscov_aniso', ... + 'stk_materncov_aniso', ... + 'stk_materncov_iso', ... + 'stk_materncov32_aniso', ... + 'stk_materncov32_iso', ... + 'stk_materncov52_aniso', ... + 'stk_materncov52_iso', ... + 'stk_optim_fmincon', ... + 'stk_options_set', ... + 'stk_parallel_engine_set' }; for i = 1:(length (filenames)) clear (filenames{i}); @@ -173,7 +171,7 @@ path = stk_init__genpath (root); % Check for missing directories -for i = 1:length (path), +for i = 1:length (path) if ~ exist (path{i}, 'dir') error (sprintf (['Directory %s does not exist.\n' ... 'Is there a problem in stk_init__genpath ?'], path{i})); @@ -194,20 +192,21 @@ path = {}; % main function folders -path = [path {... +path = [path { ... fullfile(root, 'arrays' ) ... fullfile(root, 'arrays', 'generic' ) ... fullfile(root, 'core' ) ... fullfile(root, 'covfcs' ) ... fullfile(root, 'covfcs', 'rbf' ) ... fullfile(root, 'lm' ) ... - fullfile(root, 'paramestim' ) ... + fullfile(root, 'param', 'classes' ) ... + fullfile(root, 'param', 'estim' ) ... fullfile(root, 'sampling' ) ... fullfile(root, 'utils' ) }]; % 'misc' folder and its subfolders misc = fullfile (root, 'misc'); -path = [path {... +path = [path { ... fullfile(misc, 'design' ) ... fullfile(misc, 'dist' ) ... fullfile(misc, 'distrib' ) ... @@ -221,33 +220,13 @@ fullfile(misc, 'text' ) }]; % folders that contain examples -path = [path {... +path = [path { ... fullfile(root, 'examples', '01_kriging_basics' ) ... fullfile(root, 'examples', '02_design_of_experiments') ... fullfile(root, 'examples', '03_miscellaneous' ) ... fullfile(root, 'examples', 'datasets' ) ... fullfile(root, 'examples', 'test_functions' ) }]; -% Fix a problem with private folders in Octave 3.2.x -% (add private folders to the path to make STK work...) -if (exist ('OCTAVE_VERSION', 'builtin') == 5) - v = version; - if strcmp (v(1:4), '3.2.') - test_path = [path {... - fullfile(root, 'arrays', '@stk_dataframe') ... - fullfile(root, 'arrays', '@stk_factorialdesign') ... - fullfile(root, 'core', '@stk_kreq_qr')}]; - private_path = {}; - for i = 1:(length (test_path)) - p = fullfile (test_path{i}, 'private'); - if exist (p, 'dir') - private_path = [private_path {p}]; - end - end - path = [path private_path]; - end -end - end % function @@ -285,27 +264,6 @@ function s = escape_regexp (s) -% For backward compatibility with Octave 3.2.x, we cannot use regexprep here: -% -% s = regexprep (s, '([\+\.\\])', '\\$1'); -% -% Indeed, compare the results with Octave 3.8.x -% -% >> regexprep ('2.2.0', '(\.)', '\$1') -% ans = 2$12$10 -% -% >> regexprep ('2.2.0', '(\.)', '\\$1') -% ans = 2\.2\.0 -% -% and those with Octave 3.2.4 -% -% >> regexprep ('2.2.0', '(\.)', '\$1') -% ans = 2\.2\.0 -% -% >> regexprep ('2.2.0', '(\.)', '\\$1') -% ans = 2\\.2\\.0 -% - s = strrep (s, '\', '\\'); s = strrep (s, '+', '\+'); s = strrep (s, '.', '\.'); @@ -324,9 +282,6 @@ opts = {root, mole_dir, do_addpath, prune_unused}; -% isoctave -install_mole_function ('isoctave', opts{:}); - % Provide missing octave functions for Matlab users % TODO: extract functions that are REALLY needed in separate directories % and get rid of the others ! @@ -383,7 +338,7 @@ if exist (function_dir, 'dir') && exist (function_mfile, 'file') % fprintf ('[MOLE] Providing function %s\n', function_name); - if do_addpath, + if do_addpath addpath (function_dir); end diff -Nru octave-stk-2.4.2/inst/stk_version.m octave-stk-2.5.0/inst/stk_version.m --- octave-stk-2.4.2/inst/stk_version.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/stk_version.m 2017-09-13 07:51:00.000000000 +0000 @@ -29,6 +29,6 @@ function v = stk_version () -v = '2.4.2'; +v = '2.5.0'; end % function diff -Nru octave-stk-2.4.2/inst/utils/stk_generate_samplepaths.m octave-stk-2.5.0/inst/utils/stk_generate_samplepaths.m --- octave-stk-2.4.2/inst/utils/stk_generate_samplepaths.m 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/inst/utils/stk_generate_samplepaths.m 2017-09-13 07:51:00.000000000 +0000 @@ -38,15 +38,11 @@ % % NOTE: Output type % -% The output argument ZSIM will be an stk_dataframe if at least one of the -% following conditions is met: +% The output argument ZSIM is a plain (double precision) numerical array, +% even if XT is a data frame. Row names can be added afterwards as follows: % -% a) the MODEL structure has a non-empty char field named 'response_name'; -% -% b) one of the input arguments XT, XI or ZI is an stk_dataframe object. -% -% If both MODEL.response_name and ZI.colnames exist and are non-empty, they -% must be equal (if they are not, ZSIM.colnames is empty). +% ZSIM = stk_generate_samplepaths (MODEL, XT); +% ZSIM = stk_dataframe (ZSIM, {}, XT.rownames); % % EXAMPLES: see stk_example_kb05, stk_example_kb07 % @@ -54,7 +50,7 @@ % Copyright Notice % -% Copyright (C) 2015, 2016 CentraleSupelec +% Copyright (C) 2015-2017 CentraleSupelec % Copyright (C) 2011-2014 SUPELEC % % Authors: Julien Bect @@ -85,24 +81,24 @@ % Note: we know that none of the input argument is an stk_dataframe object % (otherwise we would have ended up in @stk_dataframe/stk_generate_samplepaths) -switch nargin, +switch nargin - case {0, 1}, + case {0, 1} stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); - case 2, + case 2 % CALL: ZSIM = stk_generate_samplepaths (MODEL, XT) xt = varargin{1}; nb_paths = 1; conditional = false; - case 3, + case 3 % CALL: ZSIM = stk_generate_samplepaths (MODEL, XT, NB_PATHS) xt = varargin{1}; nb_paths = varargin{2}; conditional = false; - case 4, + case 4 % CALL: ZSIM = stk_generate_samplepaths (MODEL, XI, ZI, XT) xi = varargin{1}; zi = varargin{2}; @@ -110,7 +106,7 @@ nb_paths = 1; conditional = true; - case 5, + case 5 % CALL: ZSIM = stk_generate_samplepaths (MODEL, XI, ZI, XT, NB_PATHS) xi = varargin{1}; zi = varargin{2}; @@ -123,18 +119,40 @@ end -% Prepare extended dataset for conditioning, if required -% (TODO: avoid duplicating observations points if xi is a subset of xt) -if conditional, + +%--- Process input arguments --------------------------------------------------- + +% Extract row names from xt +xt = double (xt); + +% Check nb_paths argument +nb_paths = double (nb_paths); +if ~ isscalar (nb_paths) || ~ (nb_paths > 0) + stk_error ('nb_paths must be a positive scalar', 'Invalid argument'); +end + + +%--- Extend xt with the observation points, if needed -------------------------- + +if conditional + + % Keep only numerical data for xi, zi + xi = double (xi); + zi = double (zi); + + % Conditioning by kriging => we must simulate on the observation points too xt = [xi; xt]; xi_ind = 1:(size (xi, 1)); + end +% FIXME: Avoid duplicating observations points if xi is a subset of xt + %--- Generate unconditional sample paths -------------------------------------- % Pick unique simulation points -[xt_unique, i_ignore, j] = unique (xt, 'rows'); %#ok +[xt_unique, ignd, j] = unique (xt, 'rows'); %#ok CG#07 % Did we actually find duplicates in xt ? duplicates_detected = (size (xt_unique, 1) < size (xt, 1)); @@ -142,7 +160,7 @@ % Compute the covariance matrix % (even if there no duplicates, it is not guaranteed % that xt_unique and xt are equal) -if duplicates_detected, +if duplicates_detected K = stk_make_matcov (model, xt_unique, xt_unique); else K = stk_make_matcov (model, xt, xt); @@ -161,9 +179,9 @@ %--- Generate conditional sample paths ---------------------------------------- if conditional - + % Carry out the kriging prediction at points xt - [zp_ignore, lambda] = stk_predict (model, xi, zi, xt); %#ok + [ignd, lambda] = stk_predict (model, xi, zi, xt); %#ok CG#07 if ~ stk_isnoisy (model) @@ -194,25 +212,6 @@ end - -%--- stk_dataframe output ? -------------------------------------------------- - -try %#ok - - response_name = model.response_name; - assert ((~ isempty (response_name)) && (ischar (response_name))); - - if nb_paths == 1, - zsim_colnames = {response_name}; - else - zsim_colnames = arrayfun ( ... - @(i)(sprintf ('%s_%d', response_name, i)), ... - 1:nb_paths, 'UniformOutput', false); - end - - zsim = stk_dataframe (zsim, zsim_colnames); -end - end % function @@ -243,3 +242,8 @@ %! zsim = stk_generate_samplepaths (model, [xt; xt], nb_paths); %! assert (isequal (size (zsim), [2 * n, nb_paths])); %! assert (isequal (zsim(1:n, :), zsim((n + 1):end, :))); + +%!test % simulation points equal to observation points (noiseless model) +%! % https://sourceforge.net/p/kriging/tickets/14/ +%! zsim = stk_generate_samplepaths (model, xt, zeros (n, 1), xt); +%! assert (isequal (zsim, zeros (n, 1))); diff -Nru octave-stk-2.4.2/inst/utils/stk_plot1d.m octave-stk-2.5.0/inst/utils/stk_plot1d.m --- octave-stk-2.4.2/inst/utils/stk_plot1d.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/utils/stk_plot1d.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,174 @@ +% STK_PLOT1D is a convenient plot function for 1D kriging predictions +% +% CALL: stk_plot1d (XI, ZI, XT, ZT, ZP) +% +% plots the evaluation points (XI, ZI), the "true function" with values +% ZT on the grid XT, and a representation of the prediction ZP on the +% same grid XT: the kriging prediction (posterior mean) surrounded by a +% shaded area corresponding to 95% pointwise confidence intervals. +% +% It is possible to omit plotting either the observations (XI, ZI) or +% the true function ZT by providing empty matrices. +% +% CALL: stk_plot1d (XI, ZI, XT, ZT, ZP, ZSIM) +% +% also plots a set ZSIM of samplepaths. +% +% CALL: stk_plot1d (H_AXES, ...) +% +% plots into existing axes with axis handle H_AXES. +% +% CALL: H_PLOT = stk_plot1d (...) +% +% returns the handles of the drawing in a structure. + +% Copyright Notice +% +% Copyright (C) 2015-2017 CentraleSupelec +% Copyright (C) 2011-2014 SUPELEC +% +% Authors: Julien Bect +% Emmanuel Vazquez +% Remi Stroh + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function h_plot = stk_plot1d (varargin) + +% Extract axis handle (if it is present) +[h_axes, varargin] = stk_plot_getaxesarg (varargin{:}); + +if nargout < 1 + stk_plot1d_ (h_axes, varargin{:}); + % Do not display the handles if they are not asked (graphical option) +else + h_plot = stk_plot1d_ (h_axes, varargin{:}); +end + +end % function + + +function h = stk_plot1d_ (h_axes, xi, zi, xt, zt, zp, zsim) + +has_zt_arg = (nargin > 4) && (~ isempty (zt)); +has_zp_arg = (nargin > 5) && (~ isempty (zp)); +has_zsim_arg = (nargin > 6) && (~ isempty (zsim)); + +if (nargin > 3) && (~ isempty (xt)) + [xt, idx_sort] = sort (xt); +end + +% Shaded area representing pointwise confidence intervals +if has_zp_arg + % Sort zp + zp = zp(idx_sort, :); + + h_ci = stk_plot_shadedci (h_axes, xt, zp); + hold on; +else + h_ci = []; +end + +% Plot sample paths +if has_zsim_arg + % Sort zsim + zsim = zsim(idx_sort, :); + + if isa (zsim, 'stk_dataframe') + % Prevents automatic creation of a legend by @stk_dataframe/plot + zsim.colnames = {}; + end + h_sim = plot (h_axes, xt, zsim, ... + '-', 'LineWidth', 1, 'Color', [0.39, 0.47, 0.64]); + hold on; +else + h_sim = []; +end + +% Ground truth +if has_zt_arg + % Sort zt + zt = zt(idx_sort, :); + + h_truth = plot (h_axes, xt, zt, ... + '--', 'LineWidth', 3, 'Color', [0.39, 0.47, 0.64]); + hold on; +else + h_truth = []; +end + +% Kriging predictor (posterior mean) +if has_zp_arg + % zp has already been sorted + h_pred = plot (h_axes, xt, zp.mean, ... + 'LineWidth', 3, 'Color', [0.95 0.25 0.3]); + hold on; +else + h_pred = []; +end + +% Evaluations +if ~ isempty (zi) + h_obs = plot (h_axes, xi, zi, ... + 'ko', 'MarkerSize', 6, 'MarkerFaceColor', 'k'); +else + h_obs = []; +end + +hold off; set (gca, 'box', 'off'); + +% Prepare for the legend +h_list = []; +s_list = {}; +if ~ isempty (h_truth) + h_list = [h_list; h_truth]; + s_list = [s_list; {'True function'}]; +end +if ~ isempty (h_obs) + h_list = [h_list; h_obs]; + s_list = [s_list; {'Observations'}]; +end +if ~ isempty (h_pred) + h_list = [h_list; h_pred]; + s_list = [s_list; {'Posterior mean'}]; +end +if ~ isempty (h_ci) + h_list = [h_list; h_ci]; + s_list = [s_list; {'95% credible interval'}]; +end +if ~ isempty (h_sim) + h_list = [h_list; h_sim(1)]; + s_list = [s_list; {'Samplepaths'}]; +end + +% Create the legend +h_legend = legend (h_list, s_list{:}); +set (h_legend, 'Color', 0.98 * [1 1 1]); +legend (h_axes, 'hide'); + +% Make it possible to recover all the handles easily, if needed +h.truth = h_truth; +h.obs = h_obs; +h.pred = h_pred; +h.ci = h_ci; +h.sim = h_sim; + +end % function diff -Nru octave-stk-2.4.2/inst/utils/stk_plot_histnormres.m octave-stk-2.5.0/inst/utils/stk_plot_histnormres.m --- octave-stk-2.4.2/inst/utils/stk_plot_histnormres.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/utils/stk_plot_histnormres.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,82 @@ +% STK_PLOT_HISTNORMRES plots an histogram for normalized residuals +% +% CALL: H = stk_plot_histnormres (NORM_RES, ...) +% +% CALL: H = stk_plot_histnormres (H_AXES, NORM_RES, ...) +% +% See also stk_predict_leaveoneout, stk_example_kb10 + +% Copyright Notice +% +% Copyright (C) 2016, 2017 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function h = stk_plot_histnormres (varargin) + +[h_axes, varargin, n_argin] = stk_plot_getaxesarg (varargin{:}); + +if n_argin >= 1 + norm_res = double (varargin{1}); + opts = varargin(2:end); +else + stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); +end + +% Ignore infinite normalized residuals, with a warning +b = isinf (norm_res); +if any (b) + warning (sprintf ('Ignoring %d infinite normalized resiudals.', sum (b))); + norm_res = norm_res(~ b); +end + +% Choose the number of bins using the Freedman-Diaconis rule +n = length (norm_res); +q = quantile (norm_res, [0 0.25 0.75 1]); +binsize = 2 * (q(3) -q(2)) * (n ^ (- 1/3)); +nbins = ceil ((q(4) - q(1)) / binsize); + +% Compute and plot histogram pdf +[count, rr] = hist (norm_res, nbins); +pdf = count / (n * (rr(2) - rr(1))); +h.hist = bar (rr, pdf, 'hist'); hold on; + +% Center view +M = max (3, max (abs (xlim ()))); xlim ([-M, M]); + +% Plot reference N(0, 1) pdf +rr = linspace (-M, M, 100); +pdf_ref = 1 / (sqrt (2 * pi)) * (exp (- 0.5 * (rr .^ 2))); +h.ref_pdf = plot (rr, pdf_ref, 'r--'); + +% Apply options +if ~ isempty (opts) + set (h.hist, opts{:}); +end + +% Create labels +h_labels = stk_labels (h_axes, 'normalized residuals', 'probability density'); +h.xlabel = h_labels(1); +h.ylabel = h_labels(2); + +end % function diff -Nru octave-stk-2.4.2/inst/utils/stk_plot_predvsobs.m octave-stk-2.5.0/inst/utils/stk_plot_predvsobs.m --- octave-stk-2.4.2/inst/utils/stk_plot_predvsobs.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/utils/stk_plot_predvsobs.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,70 @@ +% STK_PLOT_PREDVSOBS plots predictions against observations +% +% CALL: H = stk_plot_predvsobs (Z_OBS, Z_PRED, ...) +% +% CALL: H = stk_plot_predvsobs (H_AXES, Z_OBS, Z_PRED, ...) +% +% See also stk_predict_leaveoneout, stk_example_kb10 + +% Copyright Notice +% +% Copyright (C) 2016 CentraleSupelec +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function h = stk_plot_predvsobs (varargin) + +[h_axes, varargin, n_argin] = stk_plot_getaxesarg (varargin{:}); + +if n_argin >= 2 + y = varargin{1}; + y_pred = varargin{2}; + opts = varargin(3:end); +else + stk_error ('Not enough input arguments.', 'NotEnoughInputArgs'); +end + +% Extract numerical predictions +try + y_pred = y_pred.mean; +catch + y_pred = double (y_pred); +end + +% Plot prediction versus truth +h.data = plot (h_axes, y, y_pred, 'kd'); hold on; + +% Plot "reference" line y_LOO = y +h.refline = plot (h_axes, xlim, xlim, 'r--'); + +% Apply options +if ~ isempty (opts) + set (h.data, opts{:}); +end + +% Create labels +h_labels = stk_labels (h_axes, 'observations', 'predictions'); +h.xlabel = h_labels(1); +h.ylabel = h_labels(2); + +end % function diff -Nru octave-stk-2.4.2/inst/utils/stk_plot_probdom2d.m octave-stk-2.5.0/inst/utils/stk_plot_probdom2d.m --- octave-stk-2.4.2/inst/utils/stk_plot_probdom2d.m 1970-01-01 00:00:00.000000000 +0000 +++ octave-stk-2.5.0/inst/utils/stk_plot_probdom2d.m 2017-09-13 07:51:00.000000000 +0000 @@ -0,0 +1,170 @@ +% STK_PLOT_PROBDOM2D represents the uncertainty about a 2D Pareto +% +% CALL: stk_plot_probdom2d (MODEL1, MODEL2, BOX) +% +% represents the uncertainty about the 2D Pareto front associated with the +% minimization of models MODEL1 and MODEL2 over the domain BOX. +% +% Use prior model structures (see stk_model) to represent prior uncertainty. +% +% Use @stk_model_gpposterior objects to represent posterior uncertainty. +% +% EXPERIMENTAL FUNCTION WARNING +% +% This function is currently considered experimental. Because of the very +% basic method used to choose the simulation points (uniform IID sampling), +% the plots produced by this function are very unreliable representations +% on the residual uncertainty on the Pareto front (except perhaps on low- +% dimensional problems of moderate difficulty). +% +% STK users that wish to experiment with it are welcome to do so, but should +% be aware of this limitation. We invite them to direct any questions, +% remarks or comments about this experimental class to the STK mailing list. +% +% REFERENCE +% +% [1] Michael Binois, David Ginsbourger and Olivier Roustant, Quantifying +% uncertainty on Pareto fronts with Gaussian Process conditional simu- +% lations, European J. of Operational Research, 2043(2):386-394, 2015. +% +% See also: stk_example_misc04, stk_model, stk_gpposterior + +% Copyright Notice +% +% Copyright (C) 2017 CentraleSupelec +% Copyright (C) 2014 SUPELEC +% +% Author: Julien Bect + +% Copying Permission Statement +% +% This file is part of +% +% STK: a Small (Matlab/Octave) Toolbox for Kriging +% (http://sourceforge.net/projects/kriging) +% +% STK is free software: you can redistribute it and/or modify it under +% the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your +% option) any later version. +% +% STK is distributed in the hope that it will be useful, but WITHOUT +% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +% License for more details. +% +% You should have received a copy of the GNU General Public License +% along with STK. If not, see . + +function stk_plot_probdom2d (model1, model2, box) + +if nargin > 3 + stk_error ('Too many input arguments.', 'TooManyInputArgs'); +end + +% FIXME: Provide a convenient way of changing these parameters + +% Number of additional random points in input space +NB_SIMULATION_POINTS = 1000; + +% Number of sample paths drawn to estimate the probabilities +NB_SAMPLEPATHS = 100; + +% Number of individual sample paths to be plotted +% (must be smaller than NB_SAMPLEPATHS) +NB_SAMPLEPATHS_PLOT = 20; + +% Number of test points in the objective space +NB_TEST_POINTS = 100 ^ 2; + + +%% Observation points (points where both objectives hae been evaluated) + +x1 = double (get_input_data (model1)); +x2 = double (get_input_data (model2)); + +x_obs = intersect (x1, x2, 'rows'); + + +%% Simulation points + +x_sim = stk_sampling_randunif (NB_SIMULATION_POINTS, [], box); +x_sim = vertcat (x_sim, x_obs); + +% FIXME: Optimize the location of simulation points... (IID uniform is perhaps +% approximately OK for vague prior models, but *not* for posterior models +% obtained at the end of a long optimization procedure...) + + +%% Generate a "large" number of sample paths + +% Simulate samplepaths +y1_sim = double (stk_generate_samplepaths (model1, x_sim, NB_SAMPLEPATHS)); +y2_sim = double (stk_generate_samplepaths (model2, x_sim, NB_SAMPLEPATHS)); + +% Empirical lower/upper bounds for each response +y1_min = min (y1_sim(:)); y1_max = max (y1_sim(:)); +y2_min = min (y2_sim(:)); y2_max = max (y2_sim(:)); + +% Axis for a nice plot +y1_axis = [y1_min - 0.05 * (y1_max - y1_min), y1_max]; +y2_axis = [y2_min - 0.05 * (y2_max - y2_min), y2_max]; + + +%% Plot a few individual sample paths of the Pareto front + +stk_subplot (1, 2, 1); cm = jet (NB_SAMPLEPATHS_PLOT); + +for i = 1:NB_SAMPLEPATHS_PLOT + + % Extract Pareto front + y_sim = [y1_sim(:, i) y2_sim(:, i)]; + y_nd = y_sim(stk_paretofind (y_sim), :); + + % Add two extremities to the Pareto front + y_nd = [[y_nd(1, 1) y2_max]; y_nd; [y1_max y_nd(end, 2)]]; + + stairs (y_nd(:, 1), y_nd(:, 2), 'Color', cm(i, :)); + + stk_labels ('first objective', 'second objective'); + % FIXME: Add meaningful labels in a 'robust' way... currently, prior model + % structures do not necessarily have a 'response_name' field, and + % for posterior model object the 'response_name' field is not + % directly accessible... + + if i == 1 + axis ([y1_axis y2_axis]); hold on; + end +end + +stk_title ('simulated Pareto fronts'); + + +%% Probability of being dominated + +% Test points (a grid over the relevant subset of the objective space) +y_test = stk_sampling_regulargrid (NB_TEST_POINTS, 2, [y1_axis' y2_axis']); + +% Compute empirical probabilities +isdom = zeros (size (y_test, 1), 1); +for i = 1:NB_SAMPLEPATHS + y_sim = [y1_sim(:, i) y2_sim(:, i)]; + isdom = isdom + stk_isdominated (y_test, y_sim); +end +isdom = isdom / NB_SAMPLEPATHS; + +% Figure +stk_subplot (1, 2, 2); +colormap (hot); pcolor (y_test, isdom); +colorbar ('YTick', [0 .25 .5 .75 1], ... + 'YTickLabel', {'0%', '25%', '50%', '75%', '100%'}); +stk_labels ('first objective', 'second objective'); % FIXME: See above +stk_title ('Proba. of being dominated'); + +% FIXME: Change the aspect ratio of the figure, if it is possible to do it in +% a portable way. Figures with 1 x 2 subplots are not pretty... + +end % function + + +%#ok<*AGROW> diff -Nru octave-stk-2.4.2/NEWS octave-stk-2.5.0/NEWS --- octave-stk-2.4.2/NEWS 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/NEWS 2017-09-13 07:51:00.000000000 +0000 @@ -1,912 +1,1054 @@ -Changes in version 2.4.2 -======================== +# Changes in version 2.5.0 -* Bug fixes +## Required Octave version - o Fix display problem of stk_model_gpposterior objects in Octave 4.2 - (ticket #73). +* Required Octave version number has been raised to 3.6.0. +## Sequential design of experiments -Changes in version 2.4.1 -======================== +* `stk_sampcrit_akg_eval`: New function. Computes the Approximate + Knowledge Gradient (AKG) sampling criterion. -* Bug fixes +* `stk_example_doe05`: Example script that demonstrates the use of the AKG + and EQI sampling criteria for noisy optimization. - o stk_pmisclass.m: Handle properly the case where K22 is negative or null. +* New (experimental) classes to represent sampling criterion objects: + `stk_sampcrit_ei`, `stk_sampcrit_akg`, `stk_sampcrit_eqi`. - o stk_get_optimizable_parameters.m, stk_get_optimizable_parameters.m: Fix - syntax errors. +* `stk_sampcrit_ei_eval`: Remove deprecated calling forms. - o stk_param_estim.m: Issue a better error message when LNV0 (the starting - point for the estimation of the lognoisevariance parameter) is either - NaN of infinite (ticket #72). +## Design of experiments -* Sampling criteria +* `stk_factorialdesign`: Accept one-variable `stk_dataframe` objects as + factors and preserve column names in this case. - o stk_sampcrit_ei_eval.m: The function now has a new syntax. The other - syntaxes, introduced (accidentally) in STK 2.4.0, will remain - supported in 2.4.x, but are deprecated and will be removed in a - future release. +* `stk_sampling_nesteddesign`: New function to create nested designs. - o Unlike the older stk_distrib_normal_ei function, - stk_sampcrit_ei_eval is written for a *minimization* problem, - following the usual convention in optimization software. +* `stk_sampling_nestedlhs`: New function to create nested LHS (NLHS). - o From now on, it is recommended to use stk_sampcrit_ei_eval instead of - stk_distrib_normal_ei. +* `stk_sampling_sobol`: Fix help text. - o stk_sampcrit_emmi_eval.m: Now accepts for the input argument ZI a set of - observations that contains dominated solutions (rows). Dominated rows - and duplicates are removed automatically, as in stk_sampcrit_ehvi_eval. +## Validation of models -* Documentation +* `stk_distrib_normal_crps`: New function to compare observations and + predictive (Gaussian) density. - o stk_pmisclass.m, stk_sampcrit_ei_eval.m, stk_sampcrit_ehvi_eval: - Help text has been added for all these functions. +* Calling `stk_predict_leaveoneout` with no output arguments now + automatically creates two cross-validation diagnostics in two subplots: + prediction VS observations (left panel) and normalized residuals (right + panel). +* `stk_predict_leaveoneout` uses now the virtual LOO formula. -Changes in version 2.4.0 -======================== +## `stk_dataframe` and related classes -* Choosing the optimizer used in stk_param_estim +* `stk_hrect`: Preserve column names for `stk_dataframe` inputs. - o The choice of the optimization algorithm used in stk_param_estim is now - much more flexible, thanks to a new interface based on "optimizer object" - classes. +* `@stk_dataframe/find`: Overload base function to support calling find + with an stk_dataframe as first input argument. - o The following classes are currently available: @stk_optim_octavesqp - @stk_optim_fmincon, @stk_optim_fminsearch. +* `@stk_dataframe/plotmatrix`: Overload base function to enrich + `plotmatrix` graphics with variable names when possible. - o stk_optim_octavesqp works both in Octave and in Matlab, with two possible - choices for the QP solver: 'qp' (available in Octave only, this is Octave's - core qp function) and 'quadprog' (available in Matlab from the Optimization - toolbox or from MOSEK; should be available in Octave's optim package soon). +* Logical functions - o Automatic detection of available optimizers. + + Operations that normally return logical (`lt`, `eq`, `and`...) now + return logical values for `stk_dataframe` arguments. - o stk_minimize_boxconstrained.m (new function): Perform box-constrained - minimization of a function. This function is overloaded for each optimizer - object class that supports box-constrained optimization. + + New overloaded functions for `stk_dataframe` objects: `isinf`, + `isnan`, `isfinite`. - o stk_minimize_unconstrained.m (new function): Perform unconstrained - minimization of a function. This function is overloaded for each optimizer - object class that supports unconstrained optimization. +* Testing array membership -* Covariance functions + + `@stk_dataframe/ismember`: No longer assumes `rows` flag for + consistency with the base `ismember` function. - o It is now possible to specify default bounds for the estimation of the - parameters in a user-defined covariance function. See the documentation of - stk_param_getdefaultbounds for more information. + + `stk_factorialdesign/ismember`: New function. Tests membership + for factorial designs much more efficiently than for plain arrays + or data frames. - o Experimental/undocumented feature: it is possible to provide a specialized - stk_param_init function for user-defined covariance functions. Read - stk_param_init.m if you need to do this. (This feature might be removed or - modified in future releases.) +* `stk_generate_samplepaths` now returns a plain numerical array instead of + a data frame. - o Radial basis functions (old and new): - o stk_rbf_matern, stk_rbf_matern32, stk_rbf_matern52 and stk_rbf_gauss - (previously available internally as stk_sf_* functions). - o New: stk_rbf_exponential, st_rbf_spherical. - o Bugfix: stk_rbf_matern32, stk_rbf_matern52 return 0 for very large h, - where stk_sf_matern32 and stk_sf_matern52 returned NaN. +## Miscellaneous - o New covariance functions - o Exponential (aka Matern 1/2): stk_expcov_iso, stk_expcov_aniso - o Spherical: stk_sphcov_iso, stk_sphcov_aniso +* `stk_plot_probdom2d`: New function to represent the uncertainty about a + 2D Pareto front. This function is currently considered experimental and + should not be expected to produce a reliable representation of the + uncertainty for difficult or high-dimensional optimization problems. -* Linear models +* New test case: "truss3" (Koski, 1985; Das, 1997). - o model.lm and linear model objects (stk_lm_* classes), introduced as an - experimental feature in STK 2.2.0, are now the recommended way of setting - the linear part of Gaussian process models. +* Many functions have been optimized for speed. - o model.order is deprecated (but still supported). +* `stk_plot1d`: Handle the case where `xt` is not sorted. - o As an example, the following define a Gaussian process with a Matern 5/2 - covariance function and a quadratic trend: +* Support old-style STK structures (with a `.a` field) has been removed. + +----- + + +# Changes in version 2.4.2 + +## Bug fixes + +* Fix display problem of `stk_model_gpposterior` objects in Octave 4.2 + (ticket #73). + + +# Changes in version 2.4.1 + +## Bug fixes + +* `stk_pmisclass`: Handle properly the case where `K22` is negative or + null. + +* `stk_get_optimizable_parameters`, `stk_get_optimizable_parameters`: Fix + syntax errors. + +* `stk_param_estim`: Issue a better error message when `LNV0` (the starting + point for the estimation of the lognoisevariance parameter) is either + `NaN` of infinite (ticket #72). + +## Sampling criteria + +* `stk_sampcrit_ei_eval`: The function now has a new syntax. The other + syntaxes, introduced (accidentally) in STK 2.4.0, will remain supported + in 2.4.x, but are deprecated and will be removed in a future release. + +* Unlike the older `stk_distrib_normal_ei` function, `stk_sampcrit_ei_eval` + is written for a *minimization* problem, following the usual convention + in optimization software. + +* From now on, it is recommended to use `stk_sampcrit_ei_eval` instead of + `stk_distrib_normal_ei`. + +* `stk_sampcrit_emmi_eval`: Now accepts for the input argument `ZI` a set + of observations that contains dominated solutions (rows). Dominated rows + and duplicates are removed automatically, as in `stk_sampcrit_ehvi_eval`. + +## Documentation + +* `stk_pmisclass`, `stk_sampcrit_ei_eval`, `stk_sampcrit_ehvi_eval`: Help + text has been added for all these functions. + + +# Changes in version 2.4.0 + +## Choosing the optimizer used in `stk_param_estim` + +* The choice of the optimization algorithm used in `stk_param_estim` is now + much more flexible, thanks to a new interface based on "optimizer object" + classes. + +* The following classes are currently available: `@stk_optim_octavesqp`, + `@stk_optim_fmincon`, `@stk_optim_fminsearch`. + +* `stk_optim_octavesqp` works both in Octave and in Matlab, with two + possible choices for the QP solver: `qp` (available in Octave only, this + is Octave's core `qp` function) and `quadprog` (available in Matlab from + the Optimization toolbox or from MOSEK; should be available in Octave's + optim package soon). + +* Automatic detection of available optimizers. + +* `stk_minimize_boxconstrained` (new function): Perform box-constrained + minimization of a function. This function is overloaded for each + optimizer object class that supports box-constrained optimization. + +* `stk_minimize_unconstrained` (new function): Perform unconstrained + minimization of a function. This function is overloaded for each + optimizer object class that supports unconstrained optimization. + +## Covariance functions + +* It is now possible to specify default bounds for the estimation of the + parameters in a user-defined covariance function. See the documentation + of `stk_param_getdefaultbounds` for more information. + +* Experimental/undocumented feature: it is possible to provide a + specialized `stk_param_init` function for user-defined covariance + functions. Read `stk_param_init` if you need to do this. (This feature + might be removed or modified in future releases.) + +* Radial basis functions (old and new): + + + `stk_rbf_matern`, `stk_rbf_matern32`, `stk_rbf_matern52` and + `stk_rbf_gauss` (previously available internally as `stk_sf_*` + functions). + + New: `stk_rbf_exponential`, `st_rbf_spherical`. + + Bugfix: `stk_rbf_matern32`, `stk_rbf_matern52` return 0 for very large + `h`, where `stk_sf_matern32` and `stk_sf_matern52` returned NaN. + +* New covariance functions + + + Exponential (aka Matérn 1/2): `stk_expcov_iso`, `stk_expcov_aniso` + + Spherical: `stk_sphcov_iso`, `stk_sphcov_aniso` + +## Linear models + +* `model.lm` and linear model objects (`stk_lm_*` classes), introduced as + an experimental feature in STK 2.2.0, are now the recommended way of + setting the linear part of Gaussian process models. + +* `model.order` is deprecated (but still supported). + +* As an example, the following define a Gaussian process with a Matérn 5/2 + covariance function and a quadratic trend: model = stk_model ('stk_materncov52_aniso'); model.lm = stk_lm_quadratic; - o stk_lm_polynomial (new function): Create a polynomial model of given - degree, up to cubic models. +* `stk_lm_polynomial` (new function): Create a polynomial model of given + degree, up to cubic models. + +## `stk_model_gpposterior` objects -* stk_model_gpposterior objects +* A new `stk_model_gpposterior` class is introduced to represent a Gaussian + process conditioned by observations (which is again Gaussian process). - o A new 'stk_model_gpposterior' class is introduced to represent a Gaussian - process conditioned by observations (which is again Gaussian process). +* Internally, an `stk_model_gpposterior` object currently stores the QR + factorization of the associated kriging matrix (other representations + will be implemented in the future). - o Internally, an stk_model_gpposterior object currently stores the QR - factorization of the associated kriging matrix (other representations will - be implemented in the future). +* `stk_predict` is overloaded for `stk_model_gpposterior` objects. - o stk_predict is overloaded for stk_model_gpposterior objects. +* `stk_model_update` (new function): Update a model with new observations. - o stk_model_update.m (new function): Update a model with new observations. +## Space-filling designs -* Space-filling designs +* `stk_sampling_sobol`: New function to generate points from a Sobol + sequence using the algorithm of Bratley and Fox (1988), as modified by + Joe and Kuo (2003). The C implementation under the hood is due to Steven + G. Johnson, and was borrowed from the NLopt toolbox (version 2.4.2). - o stk_sampling_sobol.m: New function to generate points from a Sobol sequence - using the algorithm of Bratley and Fox (1988), as modified by Joe and Kuo - (2003). The C implementation under the hood is due to Steven G. Johnson, - and was borrowed from the NLopt toolbox (version 2.4.2). +## Sampling criterions for sequential designs -* Sampling criterions for sequential designs +* `stk_sampcrit_ei_eval` (new function): Compute the expected improvement + (EI) criterion for single-objective noiseless optimization. - o stk_sampcrit_ei_eval.m (new function): Compute the expected improvement - (EI) criterion for single-objective noiseless optimization. +* `stk_sampcrit_ehvi_eval` (new function): Compute the expect hyper-volume + improvement (EHVI) criterion (Emmerich, Giannakoglou & Naujoks, 2006) for + multi-objective noiseless optimization. This function implements an + exact computation of the EHVI criterion, using a decomposition of the + dominated region into hyper-rectangles. - o stk_sampcrit_ehvi_eval.m (new function): Compute the expect hyper-volume - improvement (EHVI) criterion (Emmerich, Giannakoglou & Naujoks, 2006) for - multi-objective noiseless optimization. This function implements an exact - computation of the EHVI criterion, using a decomposition of the dominated - region into hyper-rectangles. +* `stk_sampcrit_emmi_eval` (new function): Compute the expected maximin + improvement (EMMI) criterion for multi-objective noiseless optimization + (Svenson & Santner, 2010). - o stk_sampcrit_emmi_eval.m (new function): Compute the expected maximin - improvement (EMMI) criterion for multi-objective noiseless optimization - (Svenson & Santner, 2010). +## Miscellaneous -* Miscellaneous +* `stk_pmisclass` (new function): Compute either the current probability of + misclassification or the expectation of the future probability of + misclassification, with respect to a given threshold. - o stk_pmisclass.m (new function): Compute either the current probability of - misclassification or the expectation of the future probability of - misclassification, with respect to a given threshold. +* `stk_dominatedhv` (new function): Compute Pareto-dominated hypervolumes, + which relies internally on the "Walking Fish Group" (WFG 1.10) + algorithm. The function can also return the underlying + inclusion-exclusion representation of the dominated region, i.e., its + representation as a collection of signed overlapping hyper-rectangles. - o stk_dominatedhv.m (new function): Compute Pareto-dominated hypervolumes, - which relies internally on the "Walking Fish Group" (WFG 1.10) - algorithm. The function can also return the underlying inclusion-exclusion - representation of the dominated region, i.e., its representation as a - collection of signed overlapping hyper-rectangles. +* `stk_predict_leaveoneout`: New function that computes leave-one-out + predictions and residuals. - o stk_predict_leaveoneout.m: New function that computes leave-one-out - predictions and residuals. +* `stk_isnoisy` (new function): Returns false for a noiseless model and + true otherwise. - o stk_isnoisy.m (new function): Returns false for a noiseless model and true - otherwise. +## Graphics -* Graphics +* All STK functions related to graphics now accept a handle to existing + axes as optional first input argument, and return a handle (or a vector + of handles when appropriate) to the graphical object created by the + function. - o All STK functions related to graphics now accept a handle to existing axes - as optional first input argument, and return a handle (or a vector of - handles when appropriate) to the graphical object created by the function. +* STK is now compatible with Matlab >= R2014b, where handles to graphical + objects are not numbers any more. - o STK is now compatible with Matlab >= R2014b, where handles to graphical - objects are not numbers any more. +* `stk_plot1d`: A nice default legend can now be created painlessly using + legend ('show'), and a struct of handles to the graphical objects + composing the plot is returned to facilitate further customization. See, + e.g., examples 1 and 2 in the "kriging basics" series. - o stk_plot1d.m: A nice default legend can now be created painlessly using - legend ('show'), and a struct of handles to the graphical objects composing - the plot is returned to facilitate further customization. See, e.g., - examples 1 and 2 in the "kriging basics" series. +* `stk_plot2d`: Removed (had been deprecated for a while). - o stk_plot2d.m: Removed (had been deprecated for a while). +* `stk_plot_predvsobs` (new function): Plot predictions against observations. - o stk_plot_predvsobs.m (new function): Plot predictions against observations. +* `stk_plot_histnormres` (new function): Plot histogram of normalized + residuals, together with the N(0, 1) pdf as a reference. - o stk_plot_histnormres.m (new function): Plot histogram of normalized - residuals, together with the N(0, 1) pdf as a reference. +## Examples -* Examples +* `stk_example_doe04`: Example script that demonstrates the use of + `stk_pmisclass`. - o stk_example_doe04.m: Example script that demonstrates the use of - stk_pmisclass (). +* `stk_example_kb10`: Example script that demonstrates the use of + leave-one-out cross-validation to produce goodness-of-fit graphical + diagnostics. - o stk_example_kb10.m: Example script that demonstrates the use of - leave-one-out cross-validation to produce goodness-of-fit graphical - diagnostics. +* `stk_testfun_borehole` (new function): New test function (the "borehole + model" response function, from Harper & Gupta 1983). - o stk_testfun_borehole.m (new function): New test function (the "borehole - model" response function, from Harper & Gupta 1983). +* `stk_testfun_twobumps` (new function): A simple 1D test function. - o stk_testfun_twobumps.m (new function): A simple 1D test function. +* `stk_dataset_twobumps` (new function): Define three datasets based on the + TwoBumps test function. - o stk_dataset_twobumps.m (new function): Define three datasets based on the - TwoBumps test function. +## stk_dataframe class -* stk_dataframe class +* New overloaded functions for stk_dataframe objects: `acos`, `acosd`, + `acosh`, `asin`, `asind`, `asinh`, `atan`, `atand`, `atanh`, `cos`, + `cosd`, `cosh`, `exp`, `expm1`, `log`, `log10`, `log1p`, `log2`, + `logical`, `sin`, `sind`, `sinh`, `sqrt`, `tan`, `tand`, `tanh`. - o New overloaded functions for stk_dataframe objects: acos, acosd, acosh, - asin, asind, asinh, atan, atand, atanh, cos, cosd, cosh, exp, expm1, log, - log10, log1p, log2, logical, sin, sind, sinh, sqrt, tan, tand, tanh. +* `@stk_dataframe/bsxfun`: Now preserve row names if possible. - o @stk_dataframe/bsxfun.m: Now preserve row names if possible. +* `@stk_dataframe/openvar` (new function): Convert `stk_dataframe` object + to table or double array before opening it the variable editor. - o @stk_dataframe/openvar.m (new function): Convert stk_dataframe object to - table or double array before opening it the variable editor. +* `stk_dataframe` arrays now accept characters indices (row/column names) + and cell array indices (list of row/column names). - o stk_dataframe arrays now accept characters indices (row/column names) and - cell array indices (list of row/column names). +* The `info` field is deprecated. - o The 'info' field is deprecated. +## Other minor changes -* Other minor changes +* `stk_plot_shadedci`: Delete invisible area object. - o stk_plot_shadedci.m: Delete invisible area object. +* `@stk_hrect/ismember`: Optimize for speed. - o @stk_hrect/ismember.m: Optimize for speed. +* `stk_predict`: In the case of discrete models, row input vectors are no + longer accepted. - o stk_predict.m: In the case of discrete models, row input vectors are no - longer accepted. +* `stk_runtests`: Now also available in the Octave package release, to + provide a convenient wrapper around __run_test_suite__ (). - o stk_runtests.m: Now also available in the Octave package release, to - provide a convenient wrapper around __run_test_suite__ (). +* `stk_maxabscorr`: No longer relies on corr (). - o stk_maxabscorr.m: No longer relies on corr (). +* `stk_kreq_qr`: Now has a default constructor, which allows to load saved + `stk_kreq_qr` objects properly. - o stk_kreq_qr.m: Now has a default constructor, which allows to load saved - stk_kreq_qr objects properly. +----- - o The info field of stk_dataframe objects is deprecated. +# Changes in version 2.3.4 -Changes in version 2.3.4 -======================== +## Bug fixes -* Bug fixes +* `@stk_hrect/ismember`: Fix - o @stk_hrect/ismember.m: Fix a bug that prevented ismember from working on - more than one point at a time, and another bug in the case where B is not - an stk_hrect object (it was incorrectly assumed to be an stk_dataframe in - this case). + + a bug that prevented `ismember` from working on more than one point at + a time, and + + another bug in the case where `B` is not an `stk_hrect` object (it was + incorrectly assumed to be an `stk_dataframe` in this case). - o @stk_hrect/subsref.m: Make sure that the returned value is still an - stk_hrect object when the number of rows (which is two) is unchanged. +* `@stk_hrect/subsref`: Make sure that the returned value is still an + `stk_hrect` object when the number of rows (which is two) is unchanged. -* Minor changes +## Minor changes - o Add a 'clean' target to the Octave package Makefile. +* Add a `clean` target to the Octave package Makefile. - o Decrease unit test verbosity. +* Decrease unit test verbosity. -Changes in version 2.3.3 -======================== +# Changes in version 2.3.3 -* Bug fixes +## Bug fixes - o stk_dist, stk_filldist, stk_gpquadform, stk_mindist: Fix segmentation - faults occuring with very large matrices (related to signed integer-based - index computation in the underlying MEX-files). +* `stk_dist`, `stk_filldist`, `stk_gpquadform`, `stk_mindist`: Fix segmentation + faults occurring with very large matrices (related to signed + integer-based index computation in the underlying MEX-files). - o stk_example_doe03.m: Use the appropriate flag for maximization. +* `stk_example_doe03`: Use the appropriate flag for maximization. - o mole/matlab/file_in_path.m: Fix two bugs (Matlab only) +* `mole/matlab/file_in_path.m`: Fix two bugs (Matlab only) -* Minor changes +## Minor changes - o stk_example_doe03.m: Display pointwise credible intervals in the upper - panel. +* `stk_example_doe03`: Display pointwise credible intervals in the upper + panel. -Changes in version 2.3.2 -======================== +# Changes in version 2.3.2 -* Bug fixes +## Bug fixes - o stk_param_estim.m: Fix a bug related to parameter objects. More precisely, - use (:) indexing systematically to access the vector of numerical - parameters corresponding to a given parameter object. +* `stk_param_estim`: Fix a bug related to parameter objects. More + precisely, use `(:)` indexing systematically to access the vector of + numerical parameters corresponding to a given parameter object. - o @stk_kreq_qr/get.m: Fix a call to dot () to make it work when there is only - one observation. +* `@stk_kreq_qr/get`: Fix a call to `dot` to make it work when there is + only one observation. - o Add missing field "Depends" to the DESCRIPTION file in the Octave package. +* Add missing field "Depends" to the `DESCRIPTION` file in the Octave + package. -* Minor changes +## Minor changes - o stk_param_getdefaultbounds.m: Return empty lower and upper bounds for - parameter classes that do not implement the stk_param_getdefaultbounds - (instead of calling error). +* `stk_param_getdefaultbounds`: Return empty lower and upper bounds for + parameter classes that do not implement the `stk_param_getdefaultbounds` + (instead of calling `error`). - o Add optional field "Autoload" to the DESCRIPTION file in the Octave package. +* Add optional field "Autoload" to the `DESCRIPTION` file in the Octave + package. -Changes in version 2.3.1 -======================== +# Changes in version 2.3.1 -* Bug fixes +## Bug fixes - o stk_optim_hasfmincon.m: Detect fmincon by trying to use it, instead of - relying on the result of the exist function (ticket #30 closed). +* `stk_optim_hasfmincon`: Detect `fmincon` by trying to use it, instead of + relying on the result of the `exist` function (ticket #30 closed). - o stk_param_estim.m: Make sure that the bounds that we use for the lnv - parameter contain the starting point lnv0 when it is provided. +* `stk_param_estim`: Make sure that the bounds that we use for the `lnv` + parameter contain the starting point `lnv0` when it is provided. - o @stk_dataframe/set.m: Fix stk_error calls (missing mnemonic). +* `@stk_dataframe/set`: Fix `stk_error` calls (missing mnemonic). - o stk_distrib_bivnorm_cdf.m: Fix a bug in the case of mixtures of - singular and non-singular cases. +* `stk_distrib_bivnorm_cdf`: Fix a bug in the case of mixtures of singular + and non-singular cases. - o @stk_dataframe/subsasgn.m: Preserve column names when deleting rows, even - if the resulting array is empty. +* `@stk_dataframe/subsasgn`: Preserve column names when deleting rows, even + if the resulting array is empty. -* Minor changes +## Minor changes - o stk_init.m: Clear persistent variables. As a consequence, stk_init can now - be used to restart STK completely. +* `stk_init`: Clear persistent variables. As a consequence, `stk_init` can + now be used to restart STK completely. - o stk_commonsize.m: Accept empty dimensions, under the condition that all - input arguments have the same empty dimensions (in which case the result is - empty). +* `stk_commonsize`: Accept empty dimensions, under the condition that all + input arguments have the same empty dimensions (in which case the result + is empty). - o stk_commonsize.m: is now faster when some arguments already have the proper - size (unnecessary calls to repmat are avoided). +* `stk_commonsize`: is now faster when some arguments already have the + proper size (unnecessary calls to `repmat` are avoided). - o stk_distrib_normal_cdf.m, stk_distrib_bivnorm_cdf.m: are now slightly - faster (unnecessary calls to stk_commonsize are avoided). +* `stk_distrib_normal_cdf`, `stk_distrib_bivnorm_cdf`: are now slightly + faster (unnecessary calls to `stk_commonsize` are avoided). -Changes in version 2.3.0 -======================== +# Changes in version 2.3.0 -* Model structures +## Model structures - o lognoisevariance is now considered a mandatory field. For backward - compatibility, a missing or empty lognoisevariance field is interpreted as - -inf. A nan value in the lognoisevariance field is now interpreted as - meaning that the variance of the noise must be estimated. +* `lognoisevariance` is now considered a mandatory field. For backward + compatibility, a missing or empty lognoisevariance field is interpreted + as `-inf`. A NaN value in the lognoisevariance field is now interpreted + as meaning that the variance of the noise must be estimated. - o model.param is set to nan by stk_model. This special value indicates that - the parameters must be estimated from the data before any prediction can - be done. +* `model.param` is set to NaN by `stk_model`. This special value indicates + that the parameters must be estimated from the data before any prediction + can be done. - o Improved documentation for stk_model. +* Improved documentation for `stk_model`. -* Parameter estimation +## Parameter estimation - o stk_param_init defaults to using the input value of model.lognoisevariance - if it is not NaN, and estimating the variance if it is NaN. The meaning of - the fifth argument, now called DO_ESTIM_LNV, has thus slightly changed: it - is used to force or prevent the estimation of the variance of the noise, - regardless of the value of model.lognoisevariance. +* `stk_param_init` defaults to using the input value of + `model.lognoisevariance` if it is not NaN, and estimating the variance if + it is NaN. The meaning of the fifth argument, now called `DO_ESTIM_LNV`, + has thus slightly changed: it is used to force or prevent the estimation + of the variance of the noise, regardless of the value of + `model.lognoisevariance`. - o stk_param_init also supports the heteroscedastic noisy case, but only when - the variance of the noise is assumed to be known. +* `stk_param_init` also supports the heteroscedastic noisy case, but only + when the variance of the noise is assumed to be known. - o stk_param_init_lnv is a new function that provides a rough estimate of the - variance of the noise (in the spirit of stk_param_init). +* `stk_param_init_lnv` is a new function that provides a rough estimate of + the variance of the noise (in the spirit of `stk_param_init`). - o stk_param_estim estimates the variance of the noise if either - a) param0lnv is provided and is not empty (as in STK <= 2.2.0), or - b) model.lognoisevariance is NaN (new behaviour). - If param0lnv is not provided, a starting point is obtained using the new - stk_param_init_lnv function. In all cases (whether lnv is estimated or not) - a meaningful value is returned for lnv (equal to model.nognoisevariance - when lnv is not estimated). +* `stk_param_estim` estimates the variance of the noise if either - o stk_param_estim can provide a value for param0 when it is missing from the - list of input arguments. + + `param0lnv` is provided and is not empty (as in STK <= 2.2.0), or + + `model.lognoisevariance` is NaN (new behaviour). - o stk_param_relik: Compute G = W' * K * W in such a way that the result is - always (?) symmetric. + If `param0lnv` is not provided, a starting point is obtained using the + new `stk_param_init_lnv` function. In all cases (whether `lnv` is + estimated or not) a meaningful value is returned for `lnv` (equal to + `model.lognoisevariance` when `lnv` is not estimated). -* Prediction +* `stk_param_estim` can provide a value for `param0` when it is missing + from the list of input arguments. - o stk_predict computes lambda_mu and RS only when necessary, - depending on the number of output arguments. +* `stk_param_relik`: Compute `G = W' * K * W` in such a way that the result + is always (?) symmetric. -* Covariance functions +## Prediction - o stk_noisecov now has a 'pairwise' argument, like the others. +* `stk_predict` computes `lambda_mu` and `RS` only when necessary, depending on + the number of output arguments. -* Sampling +## Covariance functions - o stk_sampling_randunif accepts empty dim argument when box is provided +* `stk_noisecov` now has a `pairwise` argument, like the others. -* Simulation of Gaussian process sample paths +## Sampling - o stk_generate_samplepaths.m: Do not add observation noise to the generated - sample paths. This is consistent with stk_predict, which returns posterior - variances for the unknown function, not for future noisy observations. +* `stk_sampling_randunif` accepts empty dim argument when `box` is provided - o stk_conditioning.m: Simulate sample paths conditioned on noisy observations - when the additional NOISE_SIM argument is provided. +## Simulation of Gaussian process sample paths - o stk_generate_samplepaths.m: Fix conditioning on noisy observations, which - was not implemented properly until now. +* `stk_generate_samplepaths`: Do not add observation noise to the generated + sample paths. This is consistent with `stk_predict`, which returns + posterior variances for the unknown function, not for future noisy + observations. - o stk_generate_samplepaths.m: The output is an stk_dataframe object if either - MODEL.response_name exists and is a non-empty string, or one of the input - arguments (XI, ZI, XT) is an stk_dataframe object. +* `stk_conditioning`: Simulate sample paths conditioned on noisy + observations when the additional `NOISE_SIM` argument is provided. - o stk_conditioning.m: The output is an stk_dataframe object if either LAMBDA - or ZSIM is an stk_dataframe object. +* `stk_generate_samplepaths`: Fix conditioning on noisy observations, which + was not implemented properly until now. -* Objects representing sets +* `stk_generate_samplepaths`: The output is an `stk_dataframe` object if + either `MODEL.response_name` exists and is a non-empty string, or one of + the input arguments (`XI`, `ZI`, `XT`) is an `stk_dataframe` object. - o stk_hrect: new class to describe hyper-rectangle objects. +* `stk_conditioning`: The output is an `stk_dataframe` object if either + `LAMBDA` or `ZSIM` is an `stk_dataframe` object. - o stk_boundingbox.m: constructs the bounding box for a set of points. +## Objects representing sets -* Examples +* `stk_hrect`: new class to describe hyper-rectangle objects. - o stk_example_kb04 demonstrates how it is possible to estimate the variance - of the noise without providing a initial guess for it. +* `stk_boundingbox`: constructs the bounding box for a set of points. - o stk_example_kb09.m demonstrates how to simulate conditional sample paths in - the case of noisy observations, both in the homoscedastic and in the - heteroscedastic cases. +## Examples -* Miscellaneous +* `stk_example_kb04` demonstrates how it is possible to estimate the + variance of the noise without providing a initial guess for it. - o stk_distrib_bivnorm_cdf computes bivariate normal probabilities. +* `stk_example_kb09` demonstrates how to simulate conditional sample paths + in the case of noisy observations, both in the homoscedastic and in the + heteroscedastic cases. - o stk_disp_progress.m: New function that displays a textual progress - indicator. +## Miscellaneous - o stk_feval handles cell-arrays of functions (ticket #19 closed), - multivariate outputs (ticket #20 closed), and uses vectorized calls by - default (unless a progress indicator is displayed). +* `stk_distrib_bivnorm_cdf` computes bivariate normal probabilities. - o sort, mtimes, uplus and uminus are now overloaded for stk_dataframe objects +* `stk_disp_progress`: New function that displays a textual progress + indicator. - o min, max are now able to return a second output argument (index of - mininizer or maximizer) for stk_dataframe arguments. +* `stk_feval` handles cell-arrays of functions (ticket #19 closed), + multivariate outputs (ticket #20 closed), and uses vectorized calls by + default (unless a progress indicator is displayed). - o Now the output of stk_dataframe is always an stk_dataframe object. - Previously, this wasn't true if the first input argument was, e.g., an - stk_factorialdesign object. +* `sort`, `mtimes`, `uplus` and `uminus` are now overloaded for + `stk_dataframe` objects - o stk_distrib_normal_ei, stk_distrib_student_ei: bugfix (the - optional input argument "minimize" was not taken into account). +* `min`, `max` are now able to return a second output argument (index of + mininizer or maximizer) for `stk_dataframe` arguments. - o stk_distrib_normal_cdf.m: Fix the zero-variance case. +* Now the output of `stk_dataframe` is always an `stk_dataframe` object. + Previously, this wasn't true if the first input argument was, e.g., an + `stk_factorialdesign` object. +* `stk_distrib_normal_ei`, `stk_distrib_student_ei`: bugfix (the optional + input argument "minimize" was not taken into account). -Changes in version 2.2.1 -======================== +* `stk_distrib_normal_cdf`: Fix the zero-variance case. -* Octave 4.0 compliance +----- - o Fix unit tests -* Octave package +# Changes in version 2.2.1 - o Do not ship stk_test and stk_runtests with the Octave package +## Octave 4.0 compliance +* Fix unit tests -Changes in version 2.2.0 -======================== +## Octave package -* Octave package +* Do not ship `stk_test` and `stk_runtests` with the Octave package - o The STK is now available both as an "all-purpose" Matlab/Octave toolbox (as - usual) and as a full-fledged Octave package that can be installed using - `pkg install`. -* Core +# Changes in version 2.2.0 - o stk_model now also accepts function handles for covariance_type. +## Octave package - o stk_ortho_func is deprecated and will be completeky replaced, in the 3.x - series, by linear model objects. In the meantime, stk_ortho_func has been - kept as a gateway to stk_lm_* functions and now supports the case of cubic - polynomial models. +* The STK is now available both as an "all-purpose" Matlab/Octave toolbox + (as usual) and as a full-fledged Octave package that can be installed + using `pkg install`. - o stk_cholcov: new function that adaptively adds a little bit of noise on the - diagonal of a covariance matrix to help chol succeed, when the first - factorization returned by chol is not complete (a warning is emitted when - doing so). Used in stk_param_init, @stk_kreq_qr/get, stk_param_relik... +## Core - o @stk_kreq_qr: heuristic improvement of numerical conditioning (implemented - in the new private function compute_P_scaling). +* `stk_model` now also accepts function handles for `covariance_type`. -* Covariance functions +* `stk_ortho_func` is deprecated and will be completely replaced, in the + 3.x series, by linear model objects. In the meantime, `stk_ortho_func` + has been kept as a gateway to `stk_lm_*` functions and now supports the + case of cubic polynomial models. - o Accept invRho = 0 in anisotropic covariance functions. +* `stk_cholcov`: new function that adaptively adds a little bit of noise on + the diagonal of a covariance matrix to help `chol` succeed, when the + first factorization returned by `chol` is not complete (a warning is + emitted when doing so). Used in `stk_param_init`, `@stk_kreq_qr/get`, + `stk_param_relik`... - o stk_sf_matern: Handle special cases (3/2, 5/2, Inf) explicitely, and handle - large values of the smoothness parameter nu better. +* `@stk_kreq_qr`: heuristic improvement of numerical conditioning + (implemented in the new private function `compute_P_scaling`). - o Handle the case of Gaussian isotropic and anisotropic covariance functions - in stk_param_init and stk_param_getdefaultbounds. +## Covariance functions -* Linear models +* Accept `invRho = 0` in anisotropic covariance functions. - o Introduce linear models objects. Currently, the following linear model - object classes are available: stk_lm_null, stk_lm_constant, stk_lm_affine, - stk_lm_quadratic, stk_lm_cubic and stk_lm_matrix. +* `stk_sf_matern`: Handle special cases (3/2, 5/2, infinity) explicitly, + and handle large values of the smoothness parameter `nu` better. - o Linear model objects are still considered an experimental feature. They can - be accessed by setting model.order to nan, in which case model.lm is - expected to contain a linear model object. +* Handle the case of Gaussian isotropic and anisotropic covariance + functions in `stk_param_init` and `stk_param_getdefaultbounds`. - o stk_example_misc03: New example script that demonstrates the use of linear - model objects. +## Linear models -* Sample path simulation (stk_generate_samplepaths) +* Introduce linear models objects. Currently, the following linear model + object classes are available: `stk_lm_null`, `stk_lm_constant`, + `stk_lm_affine`, `stk_lm_quadratic`, `stk_lm_cubic` and `stk_lm_matrix`. - o The simulation of conditioned sample paths has been made easier (see ticket - #3 on SF). This is demonstrated by stk_example_kb08. +* Linear model objects are still considered an experimental feature. They + can be accessed by setting `model.order` to NaN, in which case `model.lm` + is expected to contain a linear model object. - o Now uses model.response_name (if available) to create column names for the - output array, and xt.rownames (if available) to create row names. +* `stk_example_misc03`: New example script that demonstrates the use of + linear model objects. - o stk_generate_samplepaths can deal with replicated rows in xt. +## Sample path simulation (`stk_generate_samplepaths`) -* Parameter estimation +* The simulation of conditioned sample paths has been made easier (see + ticket #3 on SF). This is demonstrated by `stk_example_kb08`. - o stk_param_estim - - Warn about constant-response data. - - Return an additional 'info' structure, which currently contains the - criterion that has been used, the criterion value at the optimum, and - the bounds. - - Add a new (optional) input argument that will make it possible, in the - future, to select which estimation criterion to use. +* Now uses `model.response_name` (if available) to create column names for + the output array, and `xt.rownames` (if available) to create row names. - o stk_param_relik - - Check symmetry of G = W' * K * W and apply a naive fix if it is not - (emit a warning when doing so). - - Improved implementation, which seems to reduce the number of warnings - related to bad conditioning, and also improve the performance for - large n (about 1000, say). +* `stk_generate_samplepaths` can deal with replicated rows in `xt`. - o New optimization options (can bet set thorugh stk_options_set) - - Add global options to control upper/lower bounds for param estim. - - (Matlab) Add a 'optim_display_level' option to control the verbosity - fmincon/fminsearch. Its default value is 'off'. +## Parameter estimation - o stk_param_gls: new function that computes the GLS estimator. +* `stk_param_estim` -* Array objects (stk_dataframe, stk_factorialdesign) + * Warn about constant-response data. + * Return an additional `info` structure, which currently contains the + criterion that has been used, the criterion value at the optimum, and + the bounds. + * Add a new (optional) input argument that will make it possible, + in the future, to select which estimation criterion to use. - o stk_length: New function that returns the "length" of an array, currently - defined as its number of rows. +* `stk_param_relik` - o Improved display for both stk_dataframe and stk_factorial objects + * Check symmetry of `G = W' * K * W` and apply a naive fix if it is not + (emit a warning when doing so). + * Improved implementation, which seems to reduce the number of warnings + related to bad conditioning, and also improve the performance for + large `n` (about 1000, say). - o Fix and improve accessors (subsasgn, subsref, set, get, fieldnames) +* New optimization options (can bet set through `stk_options_set`) - o Minimalist support for linear indexing on stk_dataframe objects + * Add global options to control upper/lower bounds for `stk_param_estim`. + * (Matlab) Add a `optim_display_level` option to control the verbosity + `fmincon`/`fminsearch`. Its default value is `'off'`. - o New overloaded methods: @stk_dataframe/abs, @stk_dataframe/reshape +* `stk_param_gls`: new function that computes the GLS estimator. - o @stk_dataframe/plot: Full rewrite to improve compatibility with the base - plot function. The case where x is an stk_dataframe objects with two or - more columns is now handled in a way that is consistent with the base plot - function (i.e., if x has two columns, then we get two 1D plots). +## Array objects (`stk_dataframe`, `stk_factorialdesign`) - o @stk_dataframe/horzcat, @stk_dataframe/vertcat: Now the result is always an - stk_dataframe object, and has row names iff either one of the two arguments - doesn't have row names, or the row names of both arguments agree. +* `stk_length`: New function that returns the "length" of an array, + currently defined as its number of rows. - o @stk_dataframe/bsxfun: Modify the behaviour of bsxfun for stk_dataframe - objects. The result is always an stk_dataframe object, and has column names - iff either one of the two arguments doesn't have columns names or the - columns names of both arguments agree. +* Improved display for both `stk_dataframe` and `stk_factorial` objects -Graphics +* Fix and improve accessors (`subsasgn`, `subsref`, `set`, `get`, + `fieldnames`) - o stk_plot2d is deprecated and will be removed in the 3.x series. Use - contour, mesh, surf... directly instead (they are now overloaded for - stk_factorialdesign objects). +* Minimalist support for linear indexing on `stk_dataframe` objects - o stk_plot1d: Improved flexibility in the way input arguments are handled. +* New overloaded methods: `@stk_dataframe/abs`, `@stk_dataframe/reshape` - o stk_figure does not set the axis title any more. +* `@stk_dataframe/plot`: Full rewrite to improve compatibility with the + base plot function. The case where `x` is an `stk_dataframe` objects with + two or more columns is now handled in a way that is consistent with the + base plot function (i.e., if `x` has two columns, then we get two 1D + plots). -Pareto domination +* `@stk_dataframe/horzcat`, `@stk_dataframe/vertcat`: Now the result is + always an `stk_dataframe` object, and has row names iff either one of the + two arguments doesn't have row names, or the row names of both arguments + agree. - o stk_isdominated: New function that returns true for dominated rows. +* `@stk_dataframe/bsxfun`: Modify the behaviour of `bsxfun` for + `stk_dataframe` objects. The result is always an `stk_dataframe` object, + and has column names iff either one of the two arguments doesn't have + columns names or the columns names of both arguments agree. - o stk_paretofind: New function that finds non-dominated points. +## Graphics - o stk_example_misc04: New example script illustrating random Pareto fronts. +* `stk_plot2d` is deprecated and will be removed in the 3.x series. Use + `contour`, `mesh`, `surf`... directly instead (they are now overloaded + for `stk_factorialdesign` objects). -* Faster and less verbose startup +* `stk_plot1d`: Improved flexibility in the way input arguments are + handled. - o Stop bothering users at startup with information that they can find in the - README file anyway. +* `stk_figure` does not set the axis title any more. - o Don't display selected optimizers at startup. +## Pareto domination - o In Matlab, don't bother checking if the PCT is installed. +* `stk_isdominated`: New function that returns true for dominated rows. -* Documentation +* `stk_paretofind`: New function that finds non-dominated points. - o New HTML documentation, available in the "all-purpose" Matlab/Octave - release (doc/html directory) and online on Source-Forge at - . +* `stk_example_misc04`: New example script illustrating random Pareto fronts. - o Lots of fixes and improvements in help texts. +## Faster and less verbose startup - o Add a CITATION file, which explains how to cite STK in publications. +* Stop bothering users at startup with information that they can find in + the `README` file anyway. - o stk_testfun_braninhoo: Fix domain bounds in the documentation. +* Don't display selected optimizers at startup. -* Miscellaneous +* In Matlab, don't bother checking if the PCT is installed. - o Options set/get - - stk_options_set: Add a reset feature. - - stk_options_set: Prevent persistent from being cleared (bugfix) +## Documentation - o Remove page_screen_output (not needed anymore). +* New HTML documentation, available in the "all-purpose" Matlab/Octave + release (doc/html directory) and online on Source-Forge at + . - o Restore the stk_ prefix for distrib_* functions (distrib_normal_cdf is - renamed to stk_distrib_normal_cdf, distrib_student_ei to - stk_distrib_student_ei, etc.) +* Lots of fixes and improvements in help texts. - o Lots of internal changes, minor changes, etc. not worth mentioning here. +* Add a `CITATION` file, which explains how to cite STK in publications. +* `stk_testfun_braninhoo`: Fix domain bounds in the documentation. -Changes in version 2.1.1 -======================== +## Miscellaneous -* This is a minor bugfix release. +* Options set/get - o Fix a bug in stk_param_init. + * `stk_options_set`: Add a reset feature. + * `stk_options_set`: Prevent persistent from being cleared (bugfix) - o Add size checks to several functions. +* Remove `page_screen_output` (not needed anymore). - o Warn Octave users about the problem with MEX-files in privates folders: - Octave must be restarted when stk_init is run for the first time. +* Restore the `stk_` prefix for `distrib_*` functions (`distrib_normal_cdf` + is renamed to `stk_distrib_normal_cdf`, `distrib_student_ei` to + `stk_distrib_student_ei`, etc.) +* Lots of internal changes, minor changes, etc. not worth mentioning here. -Changes in version 2.1.0 -======================== +----- -* Several ways to get help, report bugs or ask for new features on Sourceforge - are now proposed to the user (both in README or stk_init.m) -* Examples +# Changes in version 2.1.1 - o Existing examples have been improved: descriptions rewritten; graphical - options controlled globally thanks to dedicated plotting functions - (stk_figure; stk_subplot, stk_axes, stk_title...); + lots of minor changes +## Bug fix - o New examples - - kb06: ordinary kriging VS linear trend - - kb07: simulations of Matern sample paths with different various nu - - doe03: one-dimensional Bayesian optimization (expected improvement) +* Fix a bug in `stk_param_init`. -* Covariance functions +## Minor changes - o New function: stk_gausscov_iso.m (isotropic Gaussian covariance model) +* Add size checks to several functions. - o New function: stk_gausscov_aniso.m (anisotropic Gaussian covariance model) +* Warn Octave users about the problem with MEX-files in privates folders: + Octave must be restarted when `stk_init` is run for the first time. -* Special functions - o The precision of stk_sf_matern has been improved around 0 for high nu +# Changes in version 2.1.0 - o New function: stk_sf_gausscorr (Gaussian correlation function in 1D) +## How to get help -* Design of experiments +* Several ways to get help, report bugs or ask for new features on + Sourceforge are now proposed to the user (both in `README` or + `stk_init.m`) - o New function: stk_phipcrit (phi_p criterion for space-filling designs) +## Examples - o New function: stk_maxabscorr (maximal pairwise absolute correlation) +* Existing examples have been improved: descriptions rewritten; graphical + options controlled globally thanks to dedicated plotting functions + (`stk_figure`; `stk_subplot`, `stk_axes`, `stk_title`...); + lots of + minor changes -* Probability distributions +* New examples - o A new 'probability distributions' module has been initiated - (read misc/distrib/README to understand the reasons why) + * kb06: ordinary kriging VS linear trend + * kb07: simulations of Matérn sample paths with different various `nu` + * doe03: one-dimensional Bayesian optimization (expected improvement) - o Currently provides: pdf, cdf and expected improvement (EI) for the - Gaussian and Student t distributions +## Covariance functions + +* New function: `stk_gausscov_iso` (isotropic Gaussian covariance model) + +* New function: `stk_gausscov_aniso` (anisotropic Gaussian covariance model) + +## Special functions + +* The precision of `stk_sf_matern` has been improved around 0 for high `nu` + +* New function: `stk_sf_gausscorr` (Gaussian correlation function in 1D) + +## Design of experiments + +* New function: `stk_phipcrit` (phi_p criterion for space-filling designs) + +* New function: `stk_maxabscorr` (maximal pairwise absolute correlation) + +## Probability distributions + +* A new 'probability distributions' module has been initiated (read + `misc/distrib/README` to understand the reasons why) + +* Currently provides: pdf, cdf and expected improvement (EI) for the + Gaussian and Student t distributions + +## Matlab/Octave compatibility * Matlab/Octave compatibility throughout all supported releases has been - strengthened, thanks to the creation of a Matlab/Octave Langage Extension - (MOLE) module + strengthened, thanks to the creation of a Matlab/Octave Language + Extension (MOLE) module + +* octave_quantile removed; instead, a replacement for `quantile` is + provided by the MOLE when needed. - o octave_quantile removed; instead, a replacement for quantile() is provided - by the MOLE when needed. +* new function `graphicstoolkit`, providing a kind of replacement for + `graphics_toolkit`, that also work in Matlab and old Octave releases - o new function graphicstoolkit(), providing a kind of replacement for - graphics_toolkit(), that also work in Matlab and old Octave releases +* ... - o ... +## Miscellaneous -* Miscellaneous +* `stk_plot1dsim` has been removed (use `stk_plot1d` instead) - o stk_plot1dsim has been removed (use stk_plot1d instead) +* plotting functions now work directly on the current axes - o plotting functions now work directly on the current axes +* An optional `box` argument has been added to `stk_sampling_halton_rr2` - o An optional 'box' argument has been added to stk_sampling_halton_rr2 +* `stk_feval` now uses input row names for its output - o stk_feval now uses input row names for its output +## Bugfixes -* Bugfixes +* `@stk_kreq_qr/stk_update` is now (inefficient but) working - o @stk_kreq_qr/stk_update is now (inefficient but) working +* `isequal` is now working for `stk_dataframe` and `stk_kreq_qr` objects in + Octave 3.2.x (explicit overloading was required for these old releases) - o isequal() is now working for stk_dataframe and stk_kreq_qr objects in - Octave 3.2.x (explicit overloading was required for these old releases) +* and many other tiny little things - o and many other tiny little things +----- -Changes in version 2.0.3 -======================== +# Changes in version 2.0.3 -* This is a minor bugfix release. +## Bug fix - o Fix a bug core/stk_predict.m (related to blockwise computations) +* Fix a bug `core/stk_predict.m` (related to blockwise computations) -Changes in version 2.0.2 -======================== +# Changes in version 2.0.2 -* This is a minor bugfix release. +## Bug fixes - o Fix a bug in @stk_dataframe/subsref.m (handle colnames properly when - ()-indexing is used to extract a subset of rows). +* Fix a bug in `@stk_dataframe/subsref` (handle colnames properly when + ()-indexing is used to extract a subset of rows). - o Fix a bug in @stk_dataframe/stk_dataframe.m (make sure that .data contains - numerical data) and add a copy constructor. +* Fix a bug in `@stk_dataframe/stk_dataframe` (make sure that `.data` + contains numerical data) and add a copy constructor. -Changes in version 2.0.1 -======================== +# Changes in version 2.0.1 -* This is a minor bugfix release. +## Bug fixes - o Fix a bug in stk_predict (don't compute the optional outputs lambda and mu - when they are not requested by the caller). +* Fix a bug in `stk_predict` (don't compute the optional outputs `lambda` + and `mu` when they are not requested by the caller). - o Fix a bug in stk_sampling_olhs (fail neatly when called with n = 2). +* Fix a bug in `stk_sampling_olhs` (fail neatly when called with n = 2). -Changes in version 2.0.0 -======================== +# Changes in version 2.0.0 + +## Required Octave version number * Required Octave version number has been raised to 3.2.2. -* Important changes to the public API +## Important changes to the public API + +* New R-like data structures: `@stk_dataframe`, `@stk_factorial_design`. + +* The structures previously used everywhere in STK (with a `.a` field) are + still supported but should be considered as deprecated (and will probably + be completely removed in the next major release). + +* As a result, `stk_predict` does not return a `.a`/`.v` structure any + more. Instead, it returns an stk_dataframe object with two variables + called `mean` and `var`. + +* The function that computes (the opposite of the log of) the restricted + likelihood is now called `stk_param_relik` instead of `stk_remlqrg`. + +## Internal structure + +* Many improvements in the internal structure of STK, for the sake of + clarity (for those who happen to read the code) and efficiency: - o New R-like data structures: @stk_dataframe, @stk_factorial_design. +* `@stk_kreq_qr`: new class for encapsulating basic computations related to + a Gaussian process (kriging) model. - o The structures previously used everywhere in STK (with a ".a" field) are - still supported but should be considered as deprecated (and will probably - be completely removed in the next major release). +* The old `Kx_cache`/`Px_cache` mechanism, for working efficiently on + finite spaces, has been replaced by a new covariance function: + `stk_discretecov`. - o As a result, stk_predict () does not return a ".a/.v" structure any - more. Instead, it returns an stk_dataframe object with two variables called - "mean" and "var". +* A new framework to encapsulate various approaches to parallel + computations. Currently only supporting `'none'` or `'parfor'` + (Mathworks' PCT toolbox parfor loops) engines, more to come later. - o The function that computes (the opposite of the log of) the restricted - likelihood is now called stk_param_relik instead of stk_remlqrg. +## Experimental support for parameter objects. -* Many improvements in the internal structure of STK, for the sake of clarity - (for those who happen to read the code) and efficiency: +* `model.param` is now allowed to be an object from a user-defined + class. This feature is experimental, and not really used currently in the + toolbox. - o @stk_kreq_qr: new class for encapsulating basic computations related - to a Gaussian process (kriging) model. +* A new function `stk_param_getdefaultbounds` has appeared in `./param`, + that was previously hidden in `stk_predict`. It can be overridden in the + case where `model.param` is an object from a user-defined class. - o The old Kx_cache/Px_cache mechanism, for working efficiently on finite - spaces, has been replaced by a new covariance fonction: stk_discretecov. +## New sampling algorithms and related functions - o A new framework to encapsulate various approaches to parallel - computations. Currently only supporting 'none' or 'parfor' (Mathworks' PCT - toolbox parfor loops) engines, more to come later. +* Fill-distance computation: exact (using Pronzato & Müller, Statistics & + Computing, 2011) or approximate (using a space-filling reference set). -* Experimental support for parameter objects. +* Van Der Corput and Halton RR2-scrambled sequences (quasi-MC) - o model.param is now allowed to be an object from a user-defined class. This - feature is experimental, and not really used currently in the toolbox. +* NOLHS designs (Cioppa & Lucs, Technometrics, 2007) - o A new function stk_param_getdefaultbounds () has appeared in ./param, that - was previously hidden in stk_predict (). It can be overridden in the case - where model.param is an object from a user-defined class. +## Miscellaneous -* New sampling algorithms and related functions +* `misc/options`: a new system for managing options - o Fill-distance computation: exact (using Pronzato & Müller, Statistics & - Computing, 2011) or approximate (using a space-filling reference set). +* `octave_quantile`: replacement for the missing `quantile` function in + base Matlab (Mathworks' Statistics toolbox is not a requirement of STK). - o Van Der Corput and Halton RR2-scrambled sequences (quasi-MC) +* Add MEX-files for computing "Gibbs-Paciorek quadratic forms" to support + future work on non-stationary covariance functions. - o NOLHS designs (Cioppa & Lucs, Technometrics, 2007) +* `AUTHORS`: a list of maintainers and contributors can now be found at the + root of the source tree. -* Miscellaneous +* `stk_compile_all`: now recompiles MEX-files automatically if the source code + has changed. - o misc/options: a new system for managing options +* Various new utility functions, tiny or not-so-tiny improvements, + bugfixes here and there... - o octave_quantile(): replacement for the missing quantile() function in base - Matlab (Mathworks' Statistics toolbox is not a requirement of STK). +----- - o Add MEX-files for computing "Gibbs-Paciorek quadratic forms" to support - future work on non-stationary covariance functions. - o AUTHORS: a list of maintainers and contributors can now be found at the - root of the source tree. +# Changes in version 1.2 - o stk_compile_all: now recompiles MEX-files automatically if the source code - has changed. +## `stk_predict` - o Various new utility functions, tiny or not-so-tiny improvements, - bugfixes here and there... +* Now offers the possibility to compute the posterior covariance matrix (it + is returned as a fourth optional argument). +* Has been modified to work with non-stationary covariance functions. -Changes in version 1.2 -====================== +## Covariance functions -* stk_predict - o Now offers the possibility to compute the posterior covariance - matrix (it is returned as a fourth optional argument). - o Has been modified to work with non-stationary covariance functions. +* Added a new `"pairwise"` option to all covariance functions and also to + `stk_dist` (formerly `stk_distance_matrix`). This options allows to + compute only the diagonal of the full distance/covariance matrix). -* Added a new "pairwise" option to all covariance functions and also to - stk_dist (formerly stk_distance_matrix). This options allows to compute - only the diagonal of the full distance/covariance matrix). +## Space-filling designs -* Space-filling designs - o New function (stk_filldist) to compute the (discretized) fill distance. - o New function (stk_sampling_olhs) to generate Orthogonal Latin - Hypercube (OLH) samples using the algorithm of Ye (1998). +* New function (`stk_filldist`) to compute the (discretized) fill distance. -* New (experimental) function to choose automatically the starting point for - a parameter estimation optimization procedure (stk_param_init). +* New function (`stk_sampling_olhs`) to generate Orthogonal Latin Hypercube + (OLH) samples using the algorithm of Ye (1998). -* New functions to work with boxes: stk_rescale, stk_normalize. +## Parameter estimation -* More flexible representation of data - o Improved the flexibility most functions (stk_predict, stk_param_estim, - ...), which are now accepting both matrices and "data structures" - (with an 'a' field) as input arguments. - o New function: stk_datastruct. +* New (experimental) function to choose automatically the starting point + for a parameter estimation optimization procedure (`stk_param_init`). -* Regular grids - o New function stk_plot2d() that serves has a wrapper around - {surf|contour|mesh|pcolor}-type functions, to plot data defined - over a two-dimensional regular grid. - o stk_sampling_regulargrid now also returns 'ndgrid-style' coordinate - matrices stored in new .coord field. +## New functions to work with boxes -* Examples - o Reorganized the example folder and renamed all example scripts. - o New example (stk_example_misc03) to demonstrate the effect of - adding a prior on the covariance parameters. - o Improved graphical outputs in stk_example_kb03. - o New test function: stk_testfun_braninhoo (Branin-Hoo). +* `stk_rescale`, -* Miscellaneous - o Renamed stk_distancematrix to stk_dist. - o Various new utility functions: stk_runexamples, stk_disp_framedtext, - stk_disp_examplewelcome, stk_plot_shadedci, stk_octave_config. - o Improved Octave-specific configuration. - o Lots of bugfixes and improvements. +* `stk_normalize`. +## More flexible representation of data -Changes in version 1.1 -====================== +* Improved the flexibility most functions (`stk_predict`, + `stk_param_estim`, ...), which are now accepting both matrices and "data + structures" (with an `.a` field) as input arguments. -* New special functions for the Matern 3/2 and 5/2 correlation - functions (stk_sf_matern32, stk_sf_matern52). New covariance - functions (stk_materncov32_iso, stk_materncov32_aniso, ...). +* New function: `stk_datastruct` -* New MEX-file to compute the separation distance (stk_mindist). +## Regular grids + +* New function `stk_plot2d` that serves has a wrapper around + {`surf`|`contour`|`mesh`|`pcolor`}-type functions, to plot data defined + over a two-dimensional regular grid. + +* `stk_sampling_regulargrid` now also returns 'ndgrid-style' coordinate + matrices stored in new `.coord` field. + +## Examples + +* Reorganized the example folder and renamed all example scripts. + +* New example (`stk_example_misc03`) to demonstrate the effect of adding a + prior on the covariance parameters. + +* Improved graphical outputs in `stk_example_kb03`. + +* New test function: `stk_testfun_braninhoo` (Branin-Hoo). + +## Miscellaneous + +* Renamed `stk_distancematrix` to `stk_dist`. + +* Various new utility functions: `stk_runexamples`, `stk_disp_framedtext`, + `stk_disp_examplewelcome`, `stk_plot_shadedci`, `stk_octave_config`. + +* Improved Octave-specific configuration. + +* Lots of bugfixes and improvements. + +----- + + +# Changes in version 1.1 + +* New special functions for the Matérn 3/2 and 5/2 correlation functions + (`stk_sf_matern32`, `stk_sf_matern52`). New covariance functions + (`stk_materncov32_iso`, `stk_materncov32_aniso`, ...). + +* New MEX-file to compute the separation distance (`stk_mindist`). * New function to generate random Latin Hypercube Samples - (stk_sampling_randomlhs). Renamed stk_sampling_cartesiangrid to - stk_sampling_regulargrid, and changed the meaning of the first - argument for consistency with other stk_sampling_* functions. - -* Improved stk_model function. Now provides default parameters for - several families of covariance functions. - -* Renamed fields in "model" structures (covariance_cache to Kx_cache - and P0 to Px_cache). A new field 'dim' has been added to the 'model' - structure. + (`stk_sampling_randomlhs`). Renamed `stk_sampling_cartesiangrid` to + `stk_sampling_regulargrid`, and changed the meaning of the first argument + for consistency with other `stk_sampling_*` functions. + +* Improved `stk_model` function. Now provides default parameters for several + families of covariance functions. + +* Renamed fields in model structures (`covariance_cache` to `Kx_cache` and `P0` + to `Px_cache`). A new field `dim` has been added to the model structure. * Changed the order of the arguments of the functions that use the - structure 'model'. Now, 'model' is always the first argument. + structure `model`. Now, `model` is always the first argument. -* Changed stk_param_estim to make it possible to estimate noise - variance. +* Changed `stk_param_estim` to make it possible to estimate noise variance. -* Fixed issues in stk_param_estim.m related to the definition of the - search domain and the selection of (constrained/unconstrained) - optimizer. +* Fixed issues in `stk_param_estim` related to the definition of the search + domain and the selection of (constrained/unconstrained) optimizer. -* Renamed stk_conditionning to stk_conditioning. +* Renamed `stk_conditionning` to `stk_conditioning`. * New functions for a more flexible and efficient management of STK's - configuration in stk_init (path, compilation of MEX-file, checking - for optional packages, selection of the default optimizer, ...). + configuration in `stk_init` (path, compilation of MEX-file, checking for + optional packages, selection of the default optimizer, ...). * New functions for unit testing, based on Octave's testing system - (stk_test, stk_runtests). Tests have been added to most functions in + (`stk_test`, `stk_runtests`). Tests have been added to most functions in the toolbox. * Improved documentation & new examples. diff -Nru octave-stk-2.4.2/src/get_column_number.c octave-stk-2.5.0/src/get_column_number.c --- octave-stk-2.4.2/src/get_column_number.c 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/src/get_column_number.c 2017-09-13 07:51:00.000000000 +0000 @@ -54,11 +54,11 @@ if (strcmp (s, "colnames") == 0) return ICOL_COLNAMES; - ncol = mxGetNumberOfElements(mxColNames); + ncol = mxGetNumberOfElements (mxColNames); if (ncol == 0) { - if (strcmp(s, "a") == 0 || strcmp(s, "data") == 0) /* LEGACY: .a */ + if (strcmp(s, "data") == 0) return ICOL_ENTIRE_DATAFRAME; - mexErrMsgTxt("The dataframe has no column names."); + mexErrMsgTxt ("The dataframe has no column names."); } icol = -1; diff -Nru octave-stk-2.4.2/src/stk_dominatedhv_mex.c octave-stk-2.5.0/src/stk_dominatedhv_mex.c --- octave-stk-2.4.2/src/stk_dominatedhv_mex.c 2017-05-16 20:02:00.000000000 +0000 +++ octave-stk-2.5.0/src/stk_dominatedhv_mex.c 2017-09-13 07:51:00.000000000 +0000 @@ -211,6 +211,9 @@ else { mexErrMsgTxt ("Incorrect type for argin #1: cell or double expected."); + nb_fronts = 0; /* avoids unitialized variable warning */ + fronts = NULL; /* idem */ + must_free_fronts = false; /* idem */ } if (mxIsLogicalScalar (DO_DECOMPOSITION)) @@ -220,6 +223,7 @@ else { mexErrMsgTxt ("Incorrect type for argin #2: logical scalar expected."); + do_decomposition = false; /* avoids unitialized variable warning */ } /*--- Prepare fronts for WFG -----------------------------------------------*/