tag:blogger.com,1999:blog-35082014186410998082024-02-19T03:05:17.837+01:00GSoC 2017: Improving the Interval PackageJoel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.comBlogger12125tag:blogger.com,1999:blog-3508201418641099808.post-40861644101484431092017-08-28T14:12:00.000+02:002017-08-28T14:50:59.213+02:00Final ReportThis is the final report on my work with the <a href="https://octave.sourceforge.io/interval/">interval package</a> during Google Summer of Code 2017. This whole blog have been dedicated to the project and by reading all posts you can follow my work from beginning to end.<br />
<br />
The work has been challenging and extremely fun! I have learned a lot about interval arithmetic, the <a href="https://www.gnu.org/software/octave/">Octave</a> and
<a href="https://octave.sourceforge.io/">Octave-forge</a> project, and also how to contribute to open-source in
general. I have found the whole Octave community to be very helpful and especially I want to thank my mentor, Oliver Heimlich, and co-mentor, Kai Torben Ohlhus, for helping me during the project.<br />
<br />
Here I will give a small introduction to Octave and the interval package for new readers and a summary of how the work has gone and how you can run the code I have actually contributed with.<br />
<br />
<h2>
Octave and the Interval Package</h2>
<a href="https://www.gnu.org/software/octave/">Octave</a>, or GNU Octave, is a <a href="https://en.wikipedia.org/wiki/Free_software">free</a> program for scientific computing. It is very similar to <a href="https://en.wikipedia.org/wiki/MATLAB">Matlab</a> and its syntax is largely compatible with it. Octave comes with a large set of core functionality but can also be extended with packages from <a href="https://octave.sourceforge.io/">Octave forge</a>. These add new functionality, for example image processing, fuzzy logic or more statistic functions. One of those packages is the <a href="https://octave.sourceforge.io/interval/index.html">interval package</a> which allows you to compute with <a href="https://en.wikipedia.org/wiki/Interval_arithmetic">interval arithmetic</a> in Octave.<br />
<br />
<h2>
Summary of the Work</h2>
The goal with the project was to improve the Octave-forge interval package by implementing support for creating, and working with, N-dimensional arrays of intervals.<br />
<br />
The work has gone very well and we have just released version 3.0.0 of the interval package incorporating all the contributions I have made during the project.<br />
<br />
The package now has full support for working with N-dimensional arrays in the same way you do with ordinary floating point numbers in Octave. In addition I have also fixed some bugs not directly related to N-dimensional arrays, see for example bug <a href="https://savannah.gnu.org/bugs/?51783">#51783</a> and <a href="https://savannah.gnu.org/bugs/?51283">#51283</a>.<br />
<br />
During the project I have made a total of 108 commits. I have made changes to 332 of the packages 666 files. Some of these changes have only been changes in coding style or (mainly) automated adding of tests. Not counting these I have, manually, made changes to 110 files.<br />
<br />
If you want to take a look at all the commits I have contributed with the best way is to download the <a href="https://sourceforge.net/p/octave/interval/ci/default/tree/">repository</a> after which you can see all the commits from GSoC with<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
hg log -u joeldahne@hotmail.com -d "2017-06-01 to 2017-08-29"<br />
</span>
<br />
Unfortunately I have not found a good way of isolating commits from a specific period and author on sourceforge where the package is hosted. Instead you can find a list of all commits at the end of this blog post.<br />
<br />
The <a href="https://octave.sourceforge.io/interval/NEWS.html">NEWS-file</a> from the release of version 3.0.0 is also a pretty good overview of what I have done. While not all of the changes are a result of GSoC quite a lot of them are.<br />
<br />
<h2>
Running the Code</h2>
As mentioned above we have just released version 3.0.0 of the interval package. With the new release it is very easy to test the newly added functionality. If you already have Octave installed the easiest way to install the package is with the command “pkg install -forge interval”. This will install the latest release of the package, at the time of writing this is 3.0.0 but that will of course change in the future. You can also download version 3.0.0 directly from <a href="https://octave.sourceforge.io/download.php?package=interval-3.0.0.tar.gz">Octave-forge</a>.<br />
<br />
If you want you can also download the source code from the official <a href="https://octave.sourceforge.io/pkg-repository/interval/">repository</a> and test it with "make run" or install it with "make install". To download the repository, update to version 3.0.0 an run Octave with the package on Linux use the following<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br /> hg clone http://hg.code.sf.net/p/octave/interval octave-interval<br /> cd octave-interval<br /> hg update release-3.0.0<br /> make run</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
</span>
<br />
<h2>
A Package for Taylor Arithmetic</h2>
The task took less time than planned so I had time to work upon a project depending on my previous work. I started to work on a project for Taylor arithmetic, you can read my <a href="https://gsocinterval.blogspot.se/2017/07/a-package-for-taylor-arithmetic.html">blog post</a> about it. I created a proof of concept implementation as part of my application for Google Summer of Code and I have now started to turn that into a real package. The repository can be found <a href="https://github.com/Urathai/octave-taylor-POC">here</a>.<br />
<br />
It is still far from complete but my goal is to eventually add it as a package at Octave-Forge. How that goes depends mainly on how much time I have to spend on it the following semesters.<br />
<br />
If you want to run the code as it is now you can pull the repository and then run it with "make run", this requires that Octave and version 3.0.0 (or higher) of the interval package is installed.<br />
<br />
<h2>
List of Commits</h2>
Here is a list of all 108 commits I have done to the interval package<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/68eb1b3281c9">https://sourceforge.net/p/octave/interval/ci/68eb1b3281c9</a><br />
summary: Added Swedish translation for package metadata<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/52d6a2565ed2">https://sourceforge.net/p/octave/interval/ci/52d6a2565ed2</a><br />
summary: @infsupdec/factorial.m: Fix decoration (bug #51783)<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/cf97d56a8e2a">https://sourceforge.net/p/octave/interval/ci/cf97d56a8e2a</a><br />
summary: mpfr_function_d.cc: Cast int to octave_idx_type<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/5ed7880c917f">https://sourceforge.net/p/octave/interval/ci/5ed7880c917f</a><br />
summary: maint: Fix input to source<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/637c532ea650">https://sourceforge.net/p/octave/interval/ci/637c532ea650</a><br />
summary: @infsupdec/dot.m: Fix decoration on empty input<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/51425fd67692">https://sourceforge.net/p/octave/interval/ci/51425fd67692</a><br />
summary: @infsup/postpad.m, @infsup/prepad.m, @infsupdec/postpad.m, @infsupdec/prepad.m: Corrected identification of dimension for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/b4e7f1546e36">https://sourceforge.net/p/octave/interval/ci/b4e7f1546e36</a><br />
summary: mpfr_function_d.cc, mpfr_vector_dot_d.cc: Fixed bug when broadcasting with one size equal to zero<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/02db5199932c">https://sourceforge.net/p/octave/interval/ci/02db5199932c</a><br />
summary: doc: NEWS.texinfo: Info about vectorization for nthroot and pownrev<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/197d033fc878">https://sourceforge.net/p/octave/interval/ci/197d033fc878</a><br />
summary: @infsup/pownrev.m, @infsupdec/pownrev.m: Support for vectorization of p<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/7f8d1945264c">https://sourceforge.net/p/octave/interval/ci/7f8d1945264c</a><br />
summary: @infsup/nthroot.m, @infsupdec/nthroot.m, mpfr_function_d.cc: Support for vectorization of n<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/e841c37383d6">https://sourceforge.net/p/octave/interval/ci/e841c37383d6</a><br />
summary: doc: NEWS.texinfo: Summarized recent changes from GSoC<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/bc3e9523d42a">https://sourceforge.net/p/octave/interval/ci/bc3e9523d42a</a><br />
summary: mpfr_vector_dot_d.cc: Fixed bug when broadcasting with one size equal to zero<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/0160ff2c2134">https://sourceforge.net/p/octave/interval/ci/0160ff2c2134</a><br />
summary: doc: examples.texinfo: Updated example for the latest Symbolic package version<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/f37e1074c3ce">https://sourceforge.net/p/octave/interval/ci/f37e1074c3ce</a><br />
summary: @infsup/*.m, @infsupdec/*.m: Added missing N-dimensional versions of tests<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/eb6b9c01bf6a">https://sourceforge.net/p/octave/interval/ci/eb6b9c01bf6a</a><br />
summary: @infsup/*.m, @infsupdec/*.m: N-dimensional versions of all ternary tests<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/de71e0ad0a6e">https://sourceforge.net/p/octave/interval/ci/de71e0ad0a6e</a><br />
summary: @infsup/*.m, @infsupdec/*.m: N-dimensional versions of all binary tests<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/9440d748b4aa">https://sourceforge.net/p/octave/interval/ci/9440d748b4aa</a><br />
summary: @infsup/*.m, @infsupdec*.m: N-dimensional version of all unary tests<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/cb5b7b824400">https://sourceforge.net/p/octave/interval/ci/cb5b7b824400</a><br />
summary: @infsup/powrev2.m: Fixed bug when called with vector arguments<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/a3e8fdb85b97">https://sourceforge.net/p/octave/interval/ci/a3e8fdb85b97</a><br />
summary: @infsup/pownrev.m, @infsupdec/pownrev.m: Reworked vectorization test<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/aae143789b81">https://sourceforge.net/p/octave/interval/ci/aae143789b81</a><br />
summary: @infsup/pown.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/f05814665570">https://sourceforge.net/p/octave/interval/ci/f05814665570</a><br />
summary: @infsup/nthroot.n: Reworked vectorization test<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/c4c27574e331">https://sourceforge.net/p/octave/interval/ci/c4c27574e331</a><br />
summary: @infsup/nthroot.m, @infsupdec/nthroot.m: Clarified that N must be scalar<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/3bfd4e7e6600">https://sourceforge.net/p/octave/interval/ci/3bfd4e7e6600</a><br />
summary: @infup/pow.m, @infsupdec/pow.m: Fixed bug when called with vector arguments<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/e013c55a4e2a">https://sourceforge.net/p/octave/interval/ci/e013c55a4e2a</a><br />
summary: @infsup/overlap.m, @infsupdec/overlap.m: Fixed formatting of vector test.<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/d700a1ad4855">https://sourceforge.net/p/octave/interval/ci/d700a1ad4855</a><br />
summary: doc: Modified a test so that it now passes<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/2404686b07fb">https://sourceforge.net/p/octave/interval/ci/2404686b07fb</a><br />
summary: doc: Fixed formatting of example<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/c078807c6b32">https://sourceforge.net/p/octave/interval/ci/c078807c6b32</a><br />
summary: doc: SKIP an example that always fail in the doc-test<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/598dea2b8eb8">https://sourceforge.net/p/octave/interval/ci/598dea2b8eb8</a><br />
summary: doc: Fixed missed ending of example in Getting Started<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/66ca24edfba4">https://sourceforge.net/p/octave/interval/ci/66ca24edfba4</a><br />
summary: Updated coding style for all infsupdec-class functions<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/4c629b9000fc">https://sourceforge.net/p/octave/interval/ci/4c629b9000fc</a><br />
summary: Updated coding style for all infsup-class functions<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/3898a7ad5d93">https://sourceforge.net/p/octave/interval/ci/3898a7ad5d93</a><br />
summary: Updated coding style for all non-class functions<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/f911db83df14">https://sourceforge.net/p/octave/interval/ci/f911db83df14</a><br />
summary: @infsupdec/dot.m: Fixed wrong size of decoration when called with two empty matrices<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/8e6a9e37ee40">https://sourceforge.net/p/octave/interval/ci/8e6a9e37ee40</a><br />
summary: Small updates to documentation and comments for a lot of function to account for the support of N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/a2ef249d54ae">https://sourceforge.net/p/octave/interval/ci/a2ef249d54ae</a><br />
summary: doc: A small update to Examples, the interval Newton method can only find zeros inside the initial interval<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/76431745772f">https://sourceforge.net/p/octave/interval/ci/76431745772f</a><br />
summary: doc: Updates to Getting Started, mainly how to create N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/9821eadca12b">https://sourceforge.net/p/octave/interval/ci/9821eadca12b</a><br />
summary: doc: Small updates to Preface regarding N-dimensional arrays and fixed one link<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/0f1aadf5f13a">https://sourceforge.net/p/octave/interval/ci/0f1aadf5f13a</a><br />
summary: ctc_intersect.m, ctc_union.m: Fixed bugs when used for vectorization and when called with 0 or 1 output arguments<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/0e01dc19dc75">https://sourceforge.net/p/octave/interval/ci/0e01dc19dc75</a><br />
summary: @infsup/sumsq.m: Updated to use the new functionality of dot.m<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/2fba2056ed31">https://sourceforge.net/p/octave/interval/ci/2fba2056ed31</a><br />
summary: @infsup/dot.m, @infsupdec/dot.m, mpfr_vector_dot_d.cc: Added support for N-dimensional vectors. Moved all vectorization to the oct-file. Small changes to functionality to mimic how the sum function works.<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/05fc90112ea9">https://sourceforge.net/p/octave/interval/ci/05fc90112ea9</a><br />
summary: ctc_intersect.m, ctc_union.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/2a4d1e9fa43e">https://sourceforge.net/p/octave/interval/ci/2a4d1e9fa43e</a><br />
summary: @infsup/fsolve.m: Added support for N-dimensional arrays. Fixed problem with the function in the example. Improved performance when creating the cell used in vectorization.<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/7a96c346225a">https://sourceforge.net/p/octave/interval/ci/7a96c346225a</a><br />
summary: @infsup/disp.m: Fixed wrong enumeration of submatrices<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/933117890e45">https://sourceforge.net/p/octave/interval/ci/933117890e45</a><br />
summary: Fixed typo in NEWS.texinfo<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/67734688adb1">https://sourceforge.net/p/octave/interval/ci/67734688adb1</a><br />
summary: @infsup/diag.m: Added description of the previous bug fix in the NEWS file<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/07ebc81867cd">https://sourceforge.net/p/octave/interval/ci/07ebc81867cd</a><br />
summary: @infsup/diag.m: Fixed error when called with more than 1 argument<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/554c34fb3246">https://sourceforge.net/p/octave/interval/ci/554c34fb3246</a><br />
summary: @infsup/meshgrid.m, @infsupdec/meshgrid.m: Removed these functions, now falls back on standard implementation, also updated index<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/4bad2e7451f5">https://sourceforge.net/p/octave/interval/ci/4bad2e7451f5</a><br />
summary: @infsup/plot.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/5e0100cdc25f">https://sourceforge.net/p/octave/interval/ci/5e0100cdc25f</a><br />
summary: @infsup/plot3.m: Small change to allow for N-dimensional arrays as input<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/695a223ccbb7">https://sourceforge.net/p/octave/interval/ci/695a223ccbb7</a><br />
summary: @infsupdec/prod.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/55f570c13f01">https://sourceforge.net/p/octave/interval/ci/55f570c13f01</a><br />
summary: @infsup/prod.m: Added support for N-dimensional arrays. Removed short circuit in simple cases.<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/445d7e5150aa">https://sourceforge.net/p/octave/interval/ci/445d7e5150aa</a><br />
summary: @infsup/sum.m, @infsupdec/sum.m, mpfr_vector_sum_d.cc: Added support for N-dimensional vectors. Moved all vectorization to the oct-file. Small changes to functionality to mimic Octaves standard sum function.<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/f27ad212735e">https://sourceforge.net/p/octave/interval/ci/f27ad212735e</a><br />
summary: @infsup/fminsearch.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/19724b3f581e">https://sourceforge.net/p/octave/interval/ci/19724b3f581e</a><br />
summary: mpfr_function_d.cc: Finalized support for N-dimensional arrays with binary functions and added support for it with ternary functions.<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/023e2788e445">https://sourceforge.net/p/octave/interval/ci/023e2788e445</a><br />
summary: midrad.m: Added tests for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/617484113019">https://sourceforge.net/p/octave/interval/ci/617484113019</a><br />
summary: @infsupdec/infsupdec.m: Added full support for creating N-dimensional arrays and added tests<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/f1c28a3d48b7">https://sourceforge.net/p/octave/interval/ci/f1c28a3d48b7</a><br />
summary: @infsup/subset.m, @infsupdec/subset.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/8e9990e3ed13">https://sourceforge.net/p/octave/interval/ci/8e9990e3ed13</a><br />
summary: @infsup/strictsubset.m, @infsupdec/strictsubset.m: Fixed coding style and updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/5ca9b26b580d">https://sourceforge.net/p/octave/interval/ci/5ca9b26b580d</a><br />
summary: @infsup/strictprecedes.m, @infsupdec/strictprecedes.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/1c76721003f1">https://sourceforge.net/p/octave/interval/ci/1c76721003f1</a><br />
summary: @infsup/sdist.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/e044dea7c820">https://sourceforge.net/p/octave/interval/ci/e044dea7c820</a><br />
summary: @infsup/precedes.m, @infsupdec/precedes.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/d48ca9206299">https://sourceforge.net/p/octave/interval/ci/d48ca9206299</a><br />
summary: @infsup/overlap.m, @infsupdec/overlap.m: Fixed coding style and updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/1ad6b47f9335">https://sourceforge.net/p/octave/interval/ci/1ad6b47f9335</a><br />
summary: @infsup/issingleton.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/11dccbcfd97e">https://sourceforge.net/p/octave/interval/ci/11dccbcfd97e</a><br />
summary: @infsup/ismember.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/ade5da12cf88">https://sourceforge.net/p/octave/interval/ci/ade5da12cf88</a><br />
summary: @infsup/isentire.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/9fc874b71533">https://sourceforge.net/p/octave/interval/ci/9fc874b71533</a><br />
summary: @infsup/isempty.m, @infsupdec/isempty.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/0c5c4eaf263b">https://sourceforge.net/p/octave/interval/ci/0c5c4eaf263b</a><br />
summary: @infsup/iscommoninterval.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/c980da83b634">https://sourceforge.net/p/octave/interval/ci/c980da83b634</a><br />
summary: @infsup/interior.m, @infsupdec/interior.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/f67d78651aee">https://sourceforge.net/p/octave/interval/ci/f67d78651aee</a><br />
summary: @infsup/idist.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/70a389bd59f5">https://sourceforge.net/p/octave/interval/ci/70a389bd59f5</a><br />
summary: @infsup/hdist.m: Fixed coding style and updated documentation.<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/e34401d2a6d6">https://sourceforge.net/p/octave/interval/ci/e34401d2a6d6</a><br />
summary: @infsup/sin.m, @infsupdec/sin.m: Added workaround for bug #51283<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/fea4c6516101">https://sourceforge.net/p/octave/interval/ci/fea4c6516101</a><br />
summary: @infsup/gt.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/ce973432d240">https://sourceforge.net/p/octave/interval/ci/ce973432d240</a><br />
summary: @infsup/ge.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/a435986d4b0c">https://sourceforge.net/p/octave/interval/ci/a435986d4b0c</a><br />
summary: @infsup/lt.m, @infsupdec/lt.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/23fa89e3c461">https://sourceforge.net/p/octave/interval/ci/23fa89e3c461</a><br />
summary: @infsup/le.m, @infsupdec/le.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/730397b9e339">https://sourceforge.net/p/octave/interval/ci/730397b9e339</a><br />
summary: @infsup/disjoint.m, @infsupdec/disjoint.m: Updated documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/682ad849fc98">https://sourceforge.net/p/octave/interval/ci/682ad849fc98</a><br />
summary: mpfr_function_d.cc: Added support for N-dimensional arrays for unary functions. Also temporary support for binary functions.<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/9661e0256c51">https://sourceforge.net/p/octave/interval/ci/9661e0256c51</a><br />
summary: crlibm_function.cc: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/0ec3d29c0779">https://sourceforge.net/p/octave/interval/ci/0ec3d29c0779</a><br />
summary: @infsup/infsup.m: Fixed documentation and added missing line continuation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/ebb00e763a46">https://sourceforge.net/p/octave/interval/ci/ebb00e763a46</a><br />
summary: @infsup/disp.m: Fixed documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/1ab2749da374">https://sourceforge.net/p/octave/interval/ci/1ab2749da374</a><br />
summary: @infsup/size.m: Fixed documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/507ca8478b72">https://sourceforge.net/p/octave/interval/ci/507ca8478b72</a><br />
summary: @infsup/size.m: Fixes to the documentation<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/667da39afece">https://sourceforge.net/p/octave/interval/ci/667da39afece</a><br />
summary: nai.m: Small fix to one of the tests<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/3eb13f91065a">https://sourceforge.net/p/octave/interval/ci/3eb13f91065a</a><br />
summary: hull.m: Fixes according to Olivers review<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/20d784a6605d">https://sourceforge.net/p/octave/interval/ci/20d784a6605d</a><br />
summary: @infsup/display.m: Vectorized loop<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/fab7aa26410f">https://sourceforge.net/p/octave/interval/ci/fab7aa26410f</a><br />
summary: @infsup/disp.m: Fixes according to Olivers review, mainly details in the output<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/4959566545db">https://sourceforge.net/p/octave/interval/ci/4959566545db</a><br />
summary: @infsup/infsup.m: Updated documentation and added test for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/b25fbf0ad324">https://sourceforge.net/p/octave/interval/ci/b25fbf0ad324</a><br />
summary: @infsup/infsup.m: Fixed coding style<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/486a73046d5e">https://sourceforge.net/p/octave/interval/ci/486a73046d5e</a><br />
summary: @infsup/disp.m: Updated documentation and added more tests for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/b6a0435da31f">https://sourceforge.net/p/octave/interval/ci/b6a0435da31f</a><br />
summary: exacttointerval.m: Uppdated documentation and added tests for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/bdad0e6da132">https://sourceforge.net/p/octave/interval/ci/bdad0e6da132</a><br />
summary: @infsup/intervaltotext.m, @infsupdec/intervaltotext.m: Updated documentation and added tests for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/55a3e708aef4">https://sourceforge.net/p/octave/interval/ci/55a3e708aef4</a><br />
summary: @infsup/intervaltotext.m: Fixed coding style<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/536b0c5023ee">https://sourceforge.net/p/octave/interval/ci/536b0c5023ee</a><br />
summary: @infsup/subsref.m, @infsupdec/subsref.m: Added tests for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/c9654a4dcd8d">https://sourceforge.net/p/octave/interval/ci/c9654a4dcd8d</a><br />
summary: @infsup/size.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/636709d06194">https://sourceforge.net/p/octave/interval/ci/636709d06194</a><br />
summary: @infsup/end.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/e6451e037120">https://sourceforge.net/p/octave/interval/ci/e6451e037120</a><br />
summary: nai.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/837cccf1d627">https://sourceforge.net/p/octave/interval/ci/837cccf1d627</a><br />
summary: @infsup/resize.m, @infsupdec/resize.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/11cb9006b9ea">https://sourceforge.net/p/octave/interval/ci/11cb9006b9ea</a><br />
summary: @infsup/reshape.m, @infsupdec/reshape.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/c276af6c42ae">https://sourceforge.net/p/octave/interval/ci/c276af6c42ae</a><br />
summary: @infsup/prepad.m, @infsupdec/prepad.m: Added small parts to the documentation and tests for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/c92c829dc946">https://sourceforge.net/p/octave/interval/ci/c92c829dc946</a><br />
summary: @infsup/postpad.m, @infsupdec/postpad.m: Added small parts to the documentation and tests for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/0f8f6864123e">https://sourceforge.net/p/octave/interval/ci/0f8f6864123e</a><br />
summary: @infsup/meshgrid.m, @infsupdec/meshgrid.m: Added support for outputting 3-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/b7faafef6030">https://sourceforge.net/p/octave/interval/ci/b7faafef6030</a><br />
summary: @infsup/cat.m, @infsupdec/cat.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/d416a17a6d3d">https://sourceforge.net/p/octave/interval/ci/d416a17a6d3d</a><br />
summary: hull.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/031831f6bdfd">https://sourceforge.net/p/octave/interval/ci/031831f6bdfd</a><br />
summary: empty.m, entire.m: Added support for N-dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/2816b68b83c4">https://sourceforge.net/p/octave/interval/ci/2816b68b83c4</a><br />
summary: @infsup/display.m: Added support for displaying high dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/79c8dfa8ac54">https://sourceforge.net/p/octave/interval/ci/79c8dfa8ac54</a><br />
summary: @infsup/disp.m: Added support for displaying high dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/cc87924e52ac">https://sourceforge.net/p/octave/interval/ci/cc87924e52ac</a><br />
summary: @infsup/disp.m: Fixed coding style<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/29a6b4ecda2a">https://sourceforge.net/p/octave/interval/ci/29a6b4ecda2a</a><br />
summary: @infsupdec/infsupdec.m: Temporary fix for creating high dimensional arrays<br />
<br />
<a href="https://sourceforge.net/p/octave/interval/ci/039abcf7623d">https://sourceforge.net/p/octave/interval/ci/039abcf7623d</a><br />
summary: @infsupdec/infsupdec.m: Fixed coding styleJoel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0tag:blogger.com,1999:blog-3508201418641099808.post-1539978449745527602017-08-18T15:53:00.001+02:002017-08-18T16:01:11.708+02:00The Final PolishWe are preparing for releasing version 3.0.0 of the interval package and this last week have mainly been about fixing minor bugs related to the release. I mention two of the more interesting bugs here.<br />
<h3>
Compact Format </h3>
We (Oliver) recently added support for "format compact" when printing intervals. It turns out that the way to determine if compact format is enabled differs very much between different version of Octave. There are at least three different ways to get the information.<br />
<br />
In the older releases (< 4.2.0 I believe) you use "get (0, "FormatSpacing")" but there appear to be a bug for version < 4.0.0 for which this always return "loose".<br />
<br />
For the current tip of the development branch you can use "[~, spacing] = format ()" to get the spacing.<br />
<br />
Finally in between these two version you use "__compactformat__ ()".<br />
<br />
In the end Oliver, probably, found a way to handle this mess and compact format should now be fully supported for intervals. The function to do this is available here <a href="https://sourceforge.net/p/octave/interval/ci/default/tree/inst/@infsup/private/__loosespacing__.m">https://sourceforge.net/p/octave/interval/ci/default/tree/inst/@infsup/private/__loosespacing__.m</a>.<br />
<h3>
Dot-product of Empty Matrices</h3>
When updating "dot" to support N-dimensional arrays I also modified it so that it behaves similar to Octaves standard implementation. The difference is in how it handles empty input. Previously we had<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> x = infsupdec (ones (0, 2));<br />
> dot (x, x)<br />
ans = 0×2 interval matrix<br />
</span><br />
but with the new version we get<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> dot (x, x)<br />
ans = 1×2 interval vector<br />
[0]_com [0]_com<br />
</span><br />
which is consistent with the standard implementation.<br />
<br />
In the function we use "min" to compute the decoration for the result. Normally "min (x)" and "dot (x, x)" returns results of the same size (the dimension along which it is computed is set to 1), but they handle empty input differently. We have<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> x = ones (0, 2);<br />
> dot (x, x)<br />
ans =<br />
0 0<br />
> min (x)<br />
ans = [](0x2)<br />
</span><br />
This meant that the decoration would be incorrect since the implementation assumed they always had the same size. Fortunately the solution was very simple. If the dimension along which we are computing the dot-product is zero. the decoration should always be "com". So just adding a check for that was enough.<br />
<br />
You could argue that "min (ones (0, 2))" should return "[inf, inf]" similarly to how many of the other reductions, like "sum" or "prod", return their unit for empty input. But this would most likely be very confusing for a lot of people. And it is not compatible with how Matlab does it either.<br />
<h2>
Updates on the Taylor Package</h2>
I have also had some time to work on the Taylor package this week. The basic utility functions are now completed and I have started to work on functions for actually computing with Taylor expansions. At the moment there are only a limited amount of functions implemented. For example we can calculate the Taylor expansion of order 4 for the functions $\frac{e^x + \log(x)}{1 + x}$ at $x = 5$.<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">## Create a variable of degree 4 and with value 5 </span><br />
<span style="font-family: "courier new" , "courier" , monospace;">> x = taylor (infsupdec (5), 4)<br />x = [5]_com + [1]_com X + [0]_com X^2 + [0]_com X^3 + [0]_com X^4</span><br />
<span style="font-family: "courier new" , "courier" , monospace;">## Calculate the function </span><br />
<span style="font-family: "courier new" , "courier" , monospace;">> (exp (x) + log (x))./(1 + x)<br />ans = [25.003, 25.004]_com + [20.601, 20.602]_com X + [8.9308, 8.9309]_com X^2 + [2.6345, 2.6346]_com X^3 + [0.59148, 0.59149]_com X^4<br />
</span><br />
<br />
<br />Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com3tag:blogger.com,1999:blog-3508201418641099808.post-69913378885500340682017-08-11T14:04:00.002+02:002017-08-11T14:04:54.192+02:00Improving the Automatic TestsOliver and I have been working on improving the test framework used for the interval package. The package shares a large number of tests with other interval packages through an interval test framework that Oliver created. Here is the <a href="https://github.com/oheim/ITF1788">repository</a>.<br />
<br />
<h2>
Creating the Tests</h2>
Previously these tests were separated from the rest of the package and you usually ran them with help of the Makefile. Now Oliver has moved them to the m-files and you can run them, together with the other tests for the function, with <i>test @infsup/function</i> in Octave. This makes it much easier to test the functions directly.<br />
<br />
In addition to making the tests easier to use we also wanted to extend them to not only test scalar evaluation but also vector evaluation. The test data, input ad expected output, is stored in a cell array and when performing the scalar testing we simply loop over that cell and run the function for each element. The actual code looks like this (in this case for <i>plus</i>)<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
%!test<br />%! # Scalar evaluation<br />%! testcases = testdata.NoSignal.infsup.add;<br />%! for testcase = [testcases]'<br />%! assert (isequaln (...<br />%! plus (testcase.in{1}, testcase.in{2}), ...<br />%! testcase.out));<br />%! endfor<br />
</span>
<br />
For testing the vector evaluation we simply concatenate the cell array into a vector and give that to the function. Here is what that code looks like<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
%! # Vector evaluation<br />%! testcases = testdata.NoSignal.infsup.add;<br />%! in1 = vertcat (vertcat (testcases.in){:, 1});<br />%! in2 = vertcat (vertcat (testcases.in){:, 2});<br />%! out = vertcat (testcases.out);<br />%! assert (isequaln (plus (in1, in2), out));<br />
</span>
<br />
Lastly we also wanted to test evaluation of N-dimensional arrays. This is done by concatenating the data into a vector and then reshape that vector into an N-dimensional array. But what size should we use for the array? Well, we want to have at least three dimensions because otherwise we are not really testing N-dimensional arrays. My solution was to completely factor the length of the vector and use that as size, <i>testsize = factor (length (in1))</i>, and if the length of the vector has two or fewer factors we add a few elements to the end until we get at least three factors. This is the code for that<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
%!test<br />%! # N-dimensional array evaluation<br />%! testcases = testdata.NoSignal.infsup.add;<br />%! in1 = vertcat (vertcat (testcases.in){:, 1});<br />%! in2 = vertcat (vertcat (testcases.in){:, 2});<br />%! out = vertcat (testcases.out);<br />%! # Reshape data<br />%! i = -1;<br />%! do<br />%! i = i + 1;<br />%! testsize = factor (numel (in1) + i);<br />%! until (numel (testsize) > 2)<br />%! in1 = reshape ([in1; in1(1:i)], testsize);<br />%! in2 = reshape ([in2; in2(1:i)], testsize);<br />%! out = reshape ([out; out(1:i)], testsize);<br />%! assert (isequaln (plus (in1, in2), out));<br />
</span>
<br />
This works very well, except when the number of test cases is to small. If the number of test is less than four this will fail. But there are only a handful of functions with that few tests so I fixed those independently.<br />
<h2>
Running the tests</h2>
Okay, so we have created a bunch of new tests for the package. Do we actually find any new bugs with them? Yes!<br />
<br />
The function <i>pow.m</i> failed on the vector test. The problem? In one place $\&\&$ was used instead of $\&$. For scalar input I believe these behave the same but they differ for vector input.<br />
<br />
Both the function <i>nthroot.m </i>and the function <i>pownrev.m</i> failed the vector test. Neither allowed vectorization of the integer parameter. For <i>nthroot.m</i> this is the same for standard Octave version so it should perhaps not be treated as a bug. The function <i>pownrev.m</i> uses <i>nthroot.m</i> internally so it also had the same limitation. This time I would however treat it as a bug because the function <i>pown.m</i> does allow vectorization of the integer parameter and if that supports it the reverse function should probably also do it. So I implemented support for vectorization of the integer parameter for both <i>nthroot.m and pownrev.m </i>and they now pass the test.<br />
<br />
No problems were found with the N-dimensional tests that the vector tests did not find. This is a good indication that the support for N-dimensional arrays is at least partly correct. Always good to know!Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0tag:blogger.com,1999:blog-3508201418641099808.post-60010620882918607362017-07-28T20:56:00.000+02:002017-07-28T20:56:13.818+02:00A Package for Taylor ArithmeticIn the last blog post I wrote about what was left to do with implementing support for N-dimensional arrays in the interval package. There are still some things to do but I have had, and most likely will have, some time to work on other things. Before the summer I started to work on a proof of concept implementation of Taylor arithmetic in Octave and this week I have continued to work on that. This blog post will be about that.<br />
<br />
<h2>
A Short Introduction to Taylor Arithmetic</h2>
Taylor arithmetic is a way to calculate with truncated Taylor expansions of functions. The main benefit is that it can be used to calculate derivatives of arbitrary order.<br />
<br />
Taylor expansion or Taylor series (I will use these words interchangeably) are well known and from Wikipedia we have: The Taylor series of real or complex valued function $f(x)$ that is infinitely differentiable at a real or complex number $a$ is the power series<br />
$$<br />
f(a) + \frac{f'(a)}{1!}(x-a) + \frac{f''(a)}{2!}(x-a)^2 + \frac{f'''(a)}{3!}(x-a)^3 + ....<br />
$$<br />
From the definition it is clear that if we happen to know the coefficients of the Taylor series of $f$ at the point $a$ we can also calculate all derivatives of $f$ at that point by simply multiplying a coefficient with the corresponding factorial.<br />
<br />
The simplest example of Taylor arithmetic is addition of two Taylor series. If $f$ has the Taylor series $\sum_{n=0}^\infty (f)_n (x-a)^n$ and $g$ the Taylor series $\sum_{n=0}^\infty (g)_n (x-a)^n$ then $f + g$ will have the Taylor series<br />
$$<br />
\sum_{n=0}^\infty (f + g)_n (x-a)^n = \sum_{n=0}^\infty ((f)_n + (g)_n)(x-a)^n$<br />
$$<br />
If we instead consider the product, $fg$, we get<br />
$$<br />
\sum_{n=0}^\infty (fg)_n (x-a)^n = \sum_{n=0}^\infty \left(\sum_{i=0}^n (f)_n(g)_n\right)(x-a)^n.<br />
$$<br />
<br />
With a bit of work you can find similar formulas for other standard functions. For example the coefficients, $(e^f)_n$, of the Taylor expansion of $\exp(f)$ is given by $(e^f)_0 = e^{(f)_0}$ and for $n > 0$<br />
$$<br />
(e^f)_n = \frac{1}{n}\sum_{i=0}^{n-1}(k-j)(e^f)_i(f)_{n-i}.<br />
$$<br />
<br />
When doing the computations on a computer we consider truncated Taylor series, we choose an order and keep only coefficients up to that order. There is also nothing that stops us from using intervals as coefficients, this allows us to get rigorous enclosures of derivatives of functions.<br />
<br />
For a more complete introduction to Taylor arithmetic in conjunction with interval arithmetic see [1] which was my first encounter to it. For another implementation of it in code take a look at [2].<br />
<h2>
Current Implementation Status</h2>
As mentioned in the last post my repository can be found <a href="https://github.com/Urathai/octave-taylor-POC">here</a><br />
<br />
When I started to write on the package, before summer, my main goal was to get something working quickly. Thus I implemented the basic functions needed to do some kind of Taylor arithmetic, a constructor, some help functions and a few functions like $\exp$ and $\sin$.<br />
<br />
This last week I have focused on implementing the basic utility functions, for example $size$, and rewriting the constructor. In the process I think I have broken the arithmetic functions, I will fix them later.<br />
<br />
You can at least create and display Taylor expansions now. For example creating a variable $x$ with value 5 of order 3<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> x = taylor (infsupdec (5), 3)<br />
x = [5]_com + [1]_com X + [0]_com X^2 + [0]_com X^3<br />
</span><br />
or a matrix with 4 variables of order 2<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> X = taylor (infsupdec ([1, 2; 3, 4]), 2)<br />
X = 2×2 Taylor matrix of order 2<br /><br />ans(:,1) =<br /><br /> [1]_com + [1]_com X + [0]_com X^2<br /> [3]_com + [1]_com X + [0]_com X^2<br /><br />ans(:,2) =<br /><br /> [2]_com + [1]_com X + [0]_com X^2<br /> [4]_com + [1]_com X + [0]_com X^2<br />
</span><br />
If you want you can create a Taylor expansion with explicitly given coefficients you can do that as well<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> f = taylor (infsupdec ([1; -2; 3, -4))<br />
f = [1]_com + [-2]_com X + [3]_com X^2 + [-4]_com X^3<br />
</span><br />
This would represent a function $f$ with $f(a) = 1$, $f'(a) = -2$, $f''(a) = 3 \cdot 2! = 6$ and $f'''(a) = -4 \cdot 3! = -24$.<br />
<h2>
Creating a Package</h2>
My goal is to create a full package for Taylor arithmetic along with some functions making use of it. The most important step is of course to create a working implementation but there are other things to consider as well. I have a few things I have not completely understood about it. Depending on how much time I have next week I will try to read a bit more about it probably ask some questions on the mailing list. Here are at least some of the things I have been thinking about<br />
<h3>
Mercurial vs Git?</h3>
I have understood that most of the Octave forge packages uses Mercurial for version control. I was not familiar with Mercurial before so the natural choice for me was to use Git. Now I feel I could switch to Mercurial if needed but I would like to know the potential benefits better, I'm still new to Mercurial so I don't have the full picture. One benefit is of course that it is easier if most packages use the same system, but other than that?<br />
<h3>
How much work is it?</h3>
If I were to manage a package for Taylor arithmetic how much work is it? This summer I have been working full time with Octave so I have had lots of time but this will of course not always be the case. I know it takes time if I want to continue to improve the package, but how much, and what, continuous work is there?<br />
<h3>
What is needed besides the implementation?</h3>
From what I have understood there are a couple of things that should be included in a package besides the actual m-files. For example a Makefile for creating the release, an INDEX-file and a CITATION-file. I should probably also include some kind of documentation, especially since Taylor arithmetic is not that well known. Is there anything else I need to think about? <br />
<h3>
What is the process to get a package approved?</h3>
If I were to apply (whatever that means) for the package to go to Octave forge what is the process for that? What is required before it can be approved and what is required after it is approved?<br />
<br />
<br />
[1] W. Tucker, Validated Numerics, Princeton University Press, 2011.<br />
[2] F. Blomquist, W. Hofschuster, W. Krämer, Real and complex taylor arithmetic in C-XSC, Preprint 2005/4, Bergische Universität Wuppertal.Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0tag:blogger.com,1999:blog-3508201418641099808.post-77085844244945800762017-07-14T15:59:00.001+02:002017-07-14T15:59:08.488+02:00Ahead of the TimelineOne of my first posts on this blog was a <a href="https://gsocinterval.blogspot.se/2017/05/timeline.html">timeline</a> for my work during the project. Predicting the amount of time something takes is always hard to do. Often time you tend to underestimate the complexity of parts of the work. This time however I overestimated the time the work would take.<br />
<br />
If my timeline would have been correct I would have just started to work on Folding Functions (or reductions as they are often called). Instead I have completed the work on them and also for functions regarding plotting. In addition I have started to work on the documentation for the package as well as checking everything an extra time.<br />
<br />
In this blog post I will go through what I have done this week, what I think is left to do and a little bit about what I might do if I complete the work on N-dimensional arrays in good time. <br />
<br />
<h2>
This Week</h2>
<h3>
The Dot Function</h3>
The $dot$-function was the last function left to implement support for N-dimensional arrays in. It is very similar to the $sum$-function so I already had an idea of how to do it. As with $sum$ I moved most of the handling of the vectorization from the m-files to the oct-file, the main reason being improved performance.<br />
<br />
The $dot$-functions for intervals is actually a bit different from the standard one. First of all it supports vectorization which the standard one does not<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> dot ([1, 2, 3; 4, 5, 6], 5)<br />
error: dot: size of X and Y must match<br />
> dot (infsupdec ([1, 2, 3; 4, 5, 6], 5)<br />
ans = 1x3 interval vector<br />
<br />
[25]_com [35]_com [45]_com<br />
</span><br />
It also treats empty arrays a little different, see <a href="https://savannah.gnu.org/bugs/?51333">bug #51333</a>,<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> dot ([], [])<br />
ans = [](1x0)<br />
> dot (infsupdec ([]), [])<br />
ans = [0]_com</span><br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
</span><br />
<h3>
Package Documentation</h3>
I have done the minimal required changes to the documentation. That is I moved support for N-dimensional arrays from Limitation to Features and added some simple examples on how to create N-dimensional arrays.<br />
<br />
<h3>
Searching for Misses</h3>
During the work I have tried to update the documentation for all functions to account for the support of N-dimensional arrays and I have also tried to update some of the comments for the code. But as always, especially when working with a lot of files, you miss things, both in the documentation and old comments.<br />
<br />
I did a quick grep for the words "matrix" and "matrices" since they are candidates for being changed to "array". Doing this I found 35 files where I missed things. It was mainly minor things, comments using the "matrix" which I now changed to "array", but also some documentation which I had forgotten to update.<br />
<br />
<h2>
What is Left?</h2>
<h3>
Package Documentation - Examples</h3>
As mentioned above I have done the minimal required changes to the documentation. It would be very nice to add some more interesting example using N-dimensional arrays of intervals in a useful way. Ironically I have not been able to come up with an interesting example but I will continue to think about it. If you have an example that you think would be interesting and want to share, please let me know!<br />
<br />
<h3>
Coding Style</h3>
As I mentioned in one of the first blog posts, the coding style for the interval package was not following the standard for Octave. During my work I have adapted all files I have worked with to the coding standard for Octave. A lot of the files I have not needed to do any changes to, so they are still using the old style. It would probably be a good idea to update them as well.<br />
<br />
<h3>
Testing - ITF1788</h3>
<a href="https://github.com/oheim/ITF1788">The interval framwork libary</a> developed by Oliver is used to test the correctness of many of the functions in the package. At the moment it tests evaluation of scalars but in principle it should be no problem to use it for testing vectorization or even broadcasting. Oliver has already started to work on <a href="https://github.com/oheim/ITF1788/issues/8">this</a>.<br />
<br />
<h2>
After N-dimensional arrays?</h2>
If I continue at this pace I will finish the work on N-dimensional arrays before the time of the project is over. Of course the things that are left might take longer than expected, they usually do, but there is a chance that I will have time left after everything is done. So what should I do then? There are more thing that can be done on the interval package, for example adding more examples to the documentation, however I think I would like to start working on a new package for Taylor arithmetics.<br />
<br />
Before GSoC I started to implement a proof of concept for Taylor arithmetics in Ocatve which can be found <a href="https://github.com/Urathai/octave-taylor-POC">here</a>. I would then start to work on implementing a proper version of it, where I would actually make use of N-dimensional interval arrays. If I want to create a package for this I would also need to learn a lot of other things, one of them being how to manage a package on octave forge.<br />
<br />
At the moment I will try to finish my work on N-dimensional arrays. Then I can discuss it with Oliver and see what he thinks about it.Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0tag:blogger.com,1999:blog-3508201418641099808.post-85256159847002398582017-07-07T14:25:00.000+02:002017-07-13T09:24:52.375+02:00Set inversion with fsolveThis week my work have mainly been focused on the interval version of <i>fsolve</i>. I was not sure if and how this could make use of N-dimensional arrays and to find that out I had to understand the function. In the end it turned out that the only generalization that could be done were trivial and required very few changes. However I did find some other problems with the functions that I have been able to fix. Connected to <i>fsolve</i> are the functions <i>ctc_intersect</i> and <i>ctc_union</i>. The also needed only minor changes to allow for N-dimensional input. I will start by giving an introduction to <i>fsolve, ctc_union</i> and <i>ctc_intersect</i> and then I will mention the changes I have done to them.<br />
<br />
<h2>
Introduction to <i>fsolve</i></h2>
The standard version of <i>fsolve </i>in Octave is used to solve systems of nonlinear equations<i>. </i>That is, given a functions $f$ and a starting point $x_0$ it returns a value $x$ such that $f(x)$ is close to zero. The interval version of <i>fsolve </i>does much more than this. It is used to enclose the preimage of a set $Y$ under $f$. Given a domain $X$, a set $Y$ and a function $f$ it returns an enclosure of the set<br />
$$<br />
f^{-1}(Y) = \{x \in X: f(x) \in Y\}.<br />
$$ <br />
By letting $Y = 0$ we get similar functionality as the standard <i>fsolve</i>, with the difference that the output is an enclosure of all zeros to the function (compared to one point for which $f$ returns close to zero).<br />
<h3>
Example: The Unit Circle</h3>
Consider the function $f(x, y) = \sqrt{x^2 + y^2} - 1$ which is zero exactly on the unit circle. Plugging this in to the standard <i>fsolve</i> we get with $(0.5, 0.5)$ as a starting guess<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> x = fsolve (@(x) f(x(1), x(2)), [0.5, 0.5])<br />
x = 0.70711 0.70711<br />
</span><br />
which indeed is close to a zero. But we get no information about other zeros.<br />
<br />
Using the interval version of <i>fsolve</i> with $X = [-3, 3] \times [-3, 3]$ as starting domain we get<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> [x paving] = fsolve (f, infsup ([-3, -3], [3, 3]));<br />
> x<br />
x ⊂ 2×1 interval vector<br /><br /> [-1.002, +1.002]<br /> [-1.0079, +1.0079]<br />
</span><br />
Plotting the paving we get the picture<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_a92pQSfGCrYvkcKEKLTmNYHGmSGfFoaa1CvgJ3kSOUHMD_nviJLJqKqoHUI6PqNu3EMG0w-kGGDJJ-Nf57NPLmtgwsQ5Rug04v0yl4zrmqoWrOzaEtBKPEtiRFyacAxysrV6PZ6j0G9V/s1600/circle.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="900" data-original-width="1200" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg_a92pQSfGCrYvkcKEKLTmNYHGmSGfFoaa1CvgJ3kSOUHMD_nviJLJqKqoHUI6PqNu3EMG0w-kGGDJJ-Nf57NPLmtgwsQ5Rug04v0yl4zrmqoWrOzaEtBKPEtiRFyacAxysrV6PZ6j0G9V/s400/circle.png" width="400" /></a></div>
which indeed is a good enclosure of the unit circle.<br />
<h3>
How it works </h3>
In its simplest form <i>fsolve</i> uses a simple bisection scheme to find the enclosure. Using interval methods we can find enclosure to images of sets. Given a set $X_0 \subset X$ we have three different possibilities<br />
<ul>
<li>$f(X_0) \subset Y$ in which case we add $X_0$ to the paving</li>
<li>$f(X_0) \cap Y = \emptyset$ in which case we discard $X_0$</li>
<li>Otherwise we bisect $X_0$ and continue on the parts</li>
</ul>
By setting a tolerance of when to stop bisecting boxes we get the algorithm to terminate in a finite number of steps.<br />
<h3>
Contractors</h3>
Using bisection is not always very efficient, especially when the domain has many dimensions. One way to speed up the convergence is with what's called contractors. In short a contractor is a function that can take the set $X_0$ and returns a set $X_0' \subset X_0$ with the property that $f(X_0 \setminus X_0') \cap Y = \emptyset$. It's a way of making $X_0$ smaller without having to bisect it that many times.<br />
<br />
When you construct a contractor you use the reverse operations definer on intervals. I will not go into how this works, if you are interested you can find more information in the package documentation [1] and in these youtube videos about Set Inversion Via Interval Analysis (SIVIA) [2].<br />
<br />
The functions <i>ctc_union</i> and <i>ctc_intersect</i> are used to combine contractors on sets into contractors on unions or intersections of these sets.<br />
<h2>
Generalization to N-dimensional arrays</h2>
How can <i>fsolve</i> be generalized to N-dimensional arrays? The only natural thing to do is to allow for the input and output of $f$ to be N-dimensional arrays. This also is no problem to do. While you mathematically probably would say that <i>fsolve</i> is used to do set inversion for functions $f: \mathbb{R}^n \to \mathbb{R}^m$ it can of course also be used for example on functions $f: \mathbb{R}^{n_1}\times \mathbb{R}^{n_2} \to \mathbb{R}^{m_1}\times \mathbb{R}^{m_2}$.<br />
<br />
This is however a bit different when using vectorization. When not using vectorization (and not using contractions) <i>fsolve</i> expects that the functions takes one argument which is an array with each element corresponding to a variable. If vectorization is used it instead assumes that the functions takes one argument for each variable. Every argument is then given as a vector with each element corresponding to one value of the variable for which to compute the function. Here we have no use of N-dimensional arrays.<br />
<h2>
Modifications</h2>
The only change in functionality that I have done to the functions is to allow for N-dimensional arrays as input and output when vectorization is not used. This required only minor changes, essentially changing expressions like
<span style="font-family: "courier new" , "courier" , monospace;"><br />
max (max (wid (interval)))
</span>
<br />
to
<span style="font-family: "courier new" , "courier" , monospace;"><br />
max (wid (interval)(:))
</span>
<br />
It was also enough to do these changes in <i>ctc_union</i> and <i>ctc_intersect</i> to have these support N-dimensional arrays.<br />
<br />
I have made no functional changes when vectorization is used. I have however made an optimization in the construction of the arguments to the function. The arguments are stored in an array but before being given to the function they need to be split up into the different variables. This is done by creating a cell array with each element being a vector with the values of one of the variables. Previously the construction of this cell array was very inefficient, it split the interval into its lower and upper part and then called the constructor to create an interval again. Now it copies the intervals into the cell without having to call the constructor. This actually seems have been quite a big improvement, using the old version the example with the unit circle from above took around 0.129 seconds and with the new version it takes about 0.092 seconds. This is of course only one benchmark, but a speed up of about 40% for this test is promising!<br />
<br />
Lastly I noticed a problem in the example used in the documentation of the function. The function used is<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
# Solve x1 ^ 2 + x2 ^ 2 = 1 for -3 ≤ x1, x2 ≤ 3 again,<br /># but now contractions speed up the algorithm.<br />function [fval, cx1, cx2] = f (y, x1, x2)<br /> # Forward evaluation<br /> x1_sqr = x1 .^ 2;<br /> x2_sqr = x2 .^ 2;<br /> fval = hypot (x1, x2);<br /> # Reverse evaluation and contraction<br /> y = intersect (y, fval);<br /> # Contract the squares<br /> x1_sqr = intersect (x1_sqr, y - x2_sqr);<br /> x2_sqr = intersect (x2_sqr, y - x1_sqr);<br /> # Contract the parameters<br /> cx1 = sqrrev (x1_sqr, x1);<br /> cx2 = sqrrev (x2_sqr, x2);<br />endfunction<br />
</span><br />
Do you see the problem? I think it took me more than a day to realize that the problems I was having was not because of a bug in <i>fsolve</i> but because this function computes the wrong thing. The function is supposed to be $f(x_1, x_2) = x_1^2 + x_2^2$ but when calculating the value it calls hypot which is given by $hypot(x_1, x_2) = \sqrt{x_1^2 + x_2^2}$. For $f(x_1, x_2) = 1$, which is used in the example, it gives the same result, but otherwise it will of course not work.<br />
<br />
[1] <a href="https://octave.sourceforge.io/interval/package_doc/Parameter-Estimation.html#Parameter-Estimation">https://octave.sourceforge.io/interval/package_doc/Parameter-Estimation.html#Parameter-Estimation</a><br />
[2] <a href="https://www.youtube.com/watch?v=kxYh2cXHdNQ">https://www.youtube.com/watch?v=kxYh2cXHdNQ</a><br />
<br />
<br />Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com2tag:blogger.com,1999:blog-3508201418641099808.post-88968232709948897392017-06-30T15:38:00.000+02:002017-06-30T15:38:02.601+02:00One Month InNow one month of GSoC has passed and so far everything has gone much better than I expected! According to my <a href="https://gsocinterval.blogspot.se/2017/05/timeline.html">timeline</a> this week would have been the first of two were I work on vectorization. Instead I have already mostly finished the vectorization and have started to work on other things. In this blog post I'll give a summary of what work I have completed and what I have left to do. I'll structure it according to where the functions are listed in the $INDEX$-file [1]. The number after the heading is the number of functions in that category.<br />
<br />
Since this will mainly be a list of which files have been modified and which are left to do this might not be very interesting if you are not familiar with the structure of the interval package.<br />
<h3>
Interval constant (3)</h3>
All of these have been modified to support N-dimensional arrays.<br />
<h3>
Interval constructor (5)</h3>
All of these have been modified to support N-dimensional arrays.<br />
<h3>
Interval function (most with tightest accuracy) (63)</h3>
Almost all of these functions worked out of the box! At least after the API functions to the MPFR and crlibm libraries were fixed, they are further down in the list.<br />
<br />
The only function that did not work immediately were $linspace$. Even though this function could be generalized to N-dimensinal arrays the standard Octave function only works for matrices (I think the Matlab version only allows scalars). This means that adding support for N-dimensional vectors for the interval version is not a priority. I might do it later on but it is not necessary. <br />
<h3>
Interval matrix operation (16)</h3>
Most of the matrix functions does not make sense for N-dimensional arrays. For example matrix multiplication and matrix inversion only makes sense for matrices. However all of the reduction functions are also here, they include $dot$, $prod$, $sum$, $sumabs$ and $sumsq$.<br />
<br />
At the moment I have implemented support for N-dimensional arrays for $sum$, $sumabs$ and $prod$. The functions $dot$ and $sumsq$ are not ready, I'm waiting to see what happens with bug #51333 [2] before I continue with that work. Depending on the bug I might also have to modify the behaviour of $sum$, $sumabs$ and $prod$ slightly.<br />
<h3>
Interval comparison (19)</h3>
All of these have been modified to support N-dimensional arrays.<br />
<h3>
Set operation (7)</h3>
All of these functions have been modified to support N-dimensional arrays except one, $mince$. The function $mince$ is an interval version of $linspace$ and reasoning here is the same as that for $linspace$ above.<br />
<h3>
Interval reverse operation (12)</h3>
Like the interval functions above, all of the functions worked out of the box!<br />
<h3>
Interval numeric function (11)</h3>
Also these functions worked out of the box, with some small modifications to the documentation for some of them.<br />
<h3>
Interval input and output (9)</h3>
Here there are some functions which require some comments, the ones I do not comment about have all gotten support for N-dimensional arrays.<br />
<br />
$interval\_bitpack$<br />
I think that this function does not make sense to generalize to N-dimensions. It could perhaps take an N-dimensional arrays as input, but it will always return a row vector. I have left it as it is for now at least.<br />
<br />
$disp$ and $display$<br />
These are functions that might be subject to change later on. At the moment it prints N-dimensional arrays of intervals in the same way Octave does for normal arrays. It's however not clear how to handle the $\subset$ symbol and we might decide to change it.<br />
<h3>
Interval solver or optimizer (5)</h3>
The functions $gauss$ and $polyval$ are not generalizable to N-dimensional vectors. I don't think that $fzero$ can be generalized either, for it to work the functions must be real-valued.<br />
<br />
The function $fsolve$ can perhaps be modified to support N-dimensional vectors. It uses the SIVIA algorithm [3] and I have to dive deeper into how it works to see if it can be done.<br />
<br />
For $fminsearch$ nothing needed to be done, it worked for N-dimensional arrays directly. <br />
<h3>
Interval contractor arithmetic (2)</h3>
Both of these functions are used together with $fsolve$ so they also depend on if SIVIA can be generalized or not.<br />
<h3>
Verified solver or optimizer (6)</h3>
All of these functions work on matrices and cannot be generalized.<br />
<h3>
Utility function (29)</h3>
All of these for which it made sense have been modified to support N-dimensional arrays. Some of them only works for matrices, these are $ctranspose$, $diag$, $transpose$, $tril$ and $triu$. I have left them as they were, though I fixed a bug in $diag$.<br />
<h3>
API function to the MPFR and crlibm libraries (8)</h3>
These are the functions that in general required most work. The ones I have added full support for N-dimensional arrays in are $crlibm\_function$, $mpfr\_function\_d$ and $mpfr\_vector\_sum\_d$. Some of them cannot be generalized, these are $mpfr\_matrix\_mul_d$, $mpfr\_matrix\_sqr\_d$ and $mpfr\_to\_string\_d$. The functions $mpfr\_linspace\_d$ and $mpfr\_vector\_dot\_d$ are related to what I mentioned above for $linspace$ and $dot$.<br />
<h3>
Summary</h3>
So summing up the functions that still require some work are<br />
<ul>
<li>Functions related to $fsolve$</li>
<li>The functions $dot$ and $sumsq$</li>
<li>The functions $linspace$ and $mince$</li>
</ul>
Especially the functions related to $fsolve$ might take some time to handle. My goal is to dive deeper into this next week.<br />
<br />
Apart from this there are also some more things that needs to be considered. The documentation for the package will need to be updated. This includes adding some examples which make use of the new functionality.<br />
<br />
The interval package also did not follow the coding style for Octave. All the functions which I have made changes to have been updated with the correct coding style, but many of the functions that worked out of the box still use the old style. It might be that we want to unify the coding standard for all files before the next release. <br />
<br />
[1] The $INDEX$ file <a href="https://sourceforge.net/u/urathai/octave/ci/default/tree/INDEX">https://sourceforge.net/u/urathai/octave/ci/default/tree/INDEX</a><br />
[2] Bug #51333 <a href="https://savannah.gnu.org/bugs/index.php?51333">https://savannah.gnu.org/bugs/index.php?51333</a><br />
[3] The SIVIA algorithm <a href="https://www.youtube.com/watch?v=kxYh2cXHdNQ">https://www.youtube.com/watch?v=kxYh2cXHdNQ</a>Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0tag:blogger.com,1999:blog-3508201418641099808.post-30092066601123350102017-06-22T16:12:00.000+02:002017-06-22T16:12:44.288+02:00Vectorization and broadcastingAt the moment I'm actually ahead of my <a href="https://gsocinterval.blogspot.se/2017/05/timeline.html">schedule</a> and this week I started to work on support for vectorization on N-dimensional arrays. The by far biggest challenge was to implement proper broadcasting and most of this post will be devoted to going through that. At the end I also mention some of the other things I have done during the week.<br />
<br />
<h2>
Broadcasting arrays</h2>
At the moment I have implement support for broadcasting on all binary functions. Since all binary functions behave similarly in respect to broadcasting I will use $+$ in all my example below, but this could in principle be any binary function working on intervals.<br />
<br />
When adding to arrays, $A, B$, of the same size the result is just an arrays of the same size with each entry containing the sum of the corresponding entries in $A$ and $B$. If $A$ and $B$ does not have the same size then we try to perform broadcasting. The simplest form of broadcasting is when $A$ is an arrays and $B$ is a scalar. Then we just take the value of $B$ and add to every element in $A$. For example<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> A = infsupdec ([1, 2; 3, 4])<br />A = 2×2 interval matrix<br /> [1]_com [2]_com<br /> [3]_com [4]_com<br />> B = infsupdec (5)<br />B = [5]_com<br />
> A + B<br />ans = 2×2 interval matrix<br /> [6]_com [7]_com<br /> [8]_com [9]_com<br />
</span><br />
However it is not only when one of the inputs is a scalar that broadcasting can be performed. Broadcasting is performed separately for each dimension of the input. We require either that the dimensions are equal, and no broadcasting is performed, or that one of the inputs have that dimension equal to $1$, we then concatenate this input along that dimension until they are of equal size. If for example $A$ has dimension $4\times4\times4$ and $B$ dimension $4\times4\times1$ we concatenate $B$ with itself along the third dimension four times to get two arrays of the same size. Since a scalar has all dimensions equal to 1 we see that it can be broadcasted to any size. Both $A$ and $B$ can also be broadcasted at the same time, along different dimensions, for example<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> A = infsupdec (ones (1, 5, 2))<br />A = 1×5×2 interval array<br />ans(:,:,1) =<br /> [1]_com [1]_com [1]_com [1]_com [1]_com<br />ans(:,:,2) =<br /> [1]_com [1]_com [1]_com [1]_com [1]_com<br />> B = infsupdec ([1, 2, 3, 4, 5; 6, 7, 8, 9, 10])<br />B = 2×5 interval matrix<br /> [1]_com [2]_com [3]_com [4]_com [5]_com<br /> [6]_com [7]_com [8]_com [9]_com [10]_com<br />
> A + B<br />ans = 2×5×2 interval array<br />ans(:,:,1) =<br /> [2]_com [3]_com [4]_com [5]_com [6]_com<br /> [7]_com [8]_com [9]_com [10]_com [11]_com<br />ans(:,:,2) =<br /> [2]_com [3]_com [4]_com [5]_com [6]_com<br /> [7]_com [8]_com [9]_com [10]_com [11]_com<br />
</span><br />
<h3>
The implementation</h3>
I'll go through a little bit about my implementation. I warn you that I'm not that familiar with the internals of Octave so some things I say might be wrong, or at least not totally correct.<br />
<br />
Internally all, numerical, arrays are stored as a linear vector and the dimensions are only metadata. This means that the most efficient way to walk through an array is with a linearly increasing index. When $A$ and $B$ have the same size the most efficient way to sum them is to linearly go through the arrays. In pseudo code<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
// Calculate C = A + B<br />
for (int i = 0; i < numel (A); i++) {<br />
C(i) = A(i) + B(i);<br />
}<br />
</span><br />
This works fine, and apart from unrolling the loop or doing optimizations like that it is probably the most efficient way to do it.<br />
<br />
If $A$ and $B$ are not of the same size then one way to do it would be to simply extend $A$ or/and $B$ along the needed dimensions. This would however require coping a lot of data, something we want to avoid (memory access is expensive). Instead we try to be smart with our indexing to access the right data from both $A$ and $B$.<br />
<br />
After asking on the IRC-channel I got pointed to <a href="http://hg.savannah.gnu.org/hgweb/octave/file/be69ea3de7a3/liboctave/numeric/bsxfun-defs.cc#l37">this</a> Octave function which performs broadcasting. My implementation, which can be found <a href="https://sourceforge.net/u/urathai/octave/ci/default/tree/src/mpfr_function_d.cc#l63">here</a>, is heavily inspired by that function.<br />
<h3>
Performance</h3>
Here I compare the performance of the new implementation with the old one. Since the old one could only handle matrices we are limited by that. We can measure the time it takes to add two matrices $A$, $B$ with the code<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
tic; A + B; toc;<br />
</span><br />
We do 10 runs for each test and all times are in seconds. <br />
<h4>
Addition of large matrices</h4>
Case 1: A = B = infsupdec (ones (1000, 1000));<br />
Old New<br />
0.324722 0.277179<br />
0.320914 0.276116<br />
0.322018 0.276075<br />
0.318713 0.279258<br />
0.332041 0.279593<br />
0.318429 0.279987<br />
0.323752 0.279089<br />
0.317823 0.276036<br />
0.320509 0.280964<br />
0.320610 0.281123<br />
Mean: 0.32195 0.27854<br />
Case 2: A = B = infsupdec (ones (10, 100000));<br />
Old New<br />
0.299321 0.272691<br />
0.297020 0.282591<br />
0.296460 0.274298<br />
0.294541 0.279661<br />
0.298306 0.277274<br />
0.301532 0.275531<br />
0.298163 0.278576<br />
0.298954 0.279868<br />
0.302849 0.275991<br />
0.297765 0.278806<br />
Mean: 0.29849 0.27753<br />
<br />
Case 3: A = B = infsupdec (ones (100000, 10));<br />
Old New<br />
0.286433 0.279107<br />
0.289503 0.278251<br />
0.297562 0.279579<br />
0.292759 0.283311<br />
0.292983 0.281306<br />
0.290947 0.282310<br />
0.293025 0.286172<br />
0.294153 0.278886<br />
0.293457 0.278625<br />
0.296661 0.280804<br />
Mean: 0.29275 0.28084 <br />
<h4>
Broadcasting scalars</h4>
Case 4: A = infsupdec (ones (1000, 1000));<br />
B = infsupdec (1);<br />
Old New<br />
0.298695 0.292419<br />
0.298158 0.292274<br />
0.305242 0.296036<br />
0.295867 0.291311<br />
0.296971 0.297255<br />
0.304297 0.292871<br />
0.298172 0.300329<br />
0.297251 0.291668<br />
0.299236 0.294128<br />
0.300457 0.298005<br />
Mean; 0.29943 0.29463 <br />
<br />
Case 5: A = infsupdec (1);<br />
B = infsupdec (ones (1000, 1000));<br />
Old New<br />
0.317276 0.291100<br />
0.316858 0.296519<br />
0.316617 0.292958<br />
0.316159 0.299662<br />
0.317939 0.301558<br />
0.322162 0.295338<br />
0.321277 0.293561<br />
0.314640 0.291500<br />
0.317211 0.295487<br />
0.317177 0.294376<br />
Mean: 0.31773 0.29521<br />
<h4>
Broadcasting vectors</h4>
Case 6: A = infsupdec (ones (1000, 1000));<br />
B = infsupdec (ones (1000, 1));<br />
Old New<br />
0.299546 0.284229<br />
0.301177 0.284458<br />
0.300725 0.276269<br />
0.299368 0.276957<br />
0.303953 0.278034<br />
0.300894 0.275058<br />
0.301776 0.276692<br />
0.302462 0.282946<br />
0.304010 0.275573<br />
0.301196 0.273109<br />
Mean: 0.30151 0.27833 <br />
<br />
Case 7: A = infsupdec (ones (1000, 1000));<br />
B = infsupdec (ones (1, 1000)); <br />
Old New<br />
0.300554 0.295892<br />
0.301361 0.294287<br />
0.302575 0.299116<br />
0.304808 0.294184<br />
0.306700 0.291606<br />
0.301233 0.298059<br />
0.301591 0.292777<br />
0.302998 0.290288<br />
0.300452 0.291975<br />
0.305531 0.290178<br />
Mean: 0.30278 0.29384<br />
<br />
We see that in all cases the new version is faster or at least equally fast as the old version. In the old version the order of the input made a slight difference in performance (case 4 vs case 5). In the new version both inputs are treated in exactly the same way so we no longer see that difference.<br />
<h3>
Possible improvements</h3>
In theory the cases when we broadcast a scalar could be the fastest ones. If $B$ is a scalar we could, in pseudo code, do something similar to<br />
<span style="font-family: "courier new" , "courier" , monospace;">// Calculate C = A + B with B scalar<br />
for (int i = 0; i < numel (A); i++) {<br />
C(i) = A(i) + B;<br />
}
</span><br />
This is however not implemented at the moment. Instead we use the ordinary routine to calculate the index for $B$ (since it is a scalar it will always evaluate to $1$). If we would like to optimize more for this case we could add a check for if $A$ or $B$ are scalars and then optimize for that. Of course this would also make the code more complicated, something to watch out for. At the moment I leave it like this but if we later want to optimize for that case it could be done.<br />
<h2>
Other work</h2>
Apart from the work to fix the broadcasting for binary functions there were very little to do for many of the functions. All binary functions that use this code, and all unary functions using an even simpler code, worked directly after fixing the oct-files. Some of them required small changes to the documentation but other than that the octave-scripts were fine. So mainly it has been a matter of actually going through all files and check that they actually did work.<br />
<h3>
Bug #51283</h3>
When going through all the functions I noticed a bug in the interval version of $\sin$,<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> sin (infsupdec (0))<br />ans = [0]_com<br />
> sin (infsupdec ([0, 0]))<br />ans = 1×2 interval vector<br /> [0, -0]_com [0, -0]_com<br />
</span><br />
The second version here is wrong, $-0$ should never be allowed as a value for the supremum of an interval. I was able to track this down to how Octaves $\max$ function works, see <a href="https://savannah.gnu.org/bugs/index.php?51283">bug #51283</a>. As Oliver writes there the exact behaviour of the $\max$-function is not specified in <span id="hidsubpartcontentdiscussion">IEEE Std 754-2008 so we cannot rely on that. To solve this I have added a line to manually set all $-0$ to $+0$ in the supremum of the interval.</span><br />
<h3>
</h3>
Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0tag:blogger.com,1999:blog-3508201418641099808.post-19310234811192722872017-06-16T13:07:00.000+02:002017-06-16T13:07:55.086+02:00Construction and PrintingThis week I have started to work on methods for constructing and printing N-dimensional arrays of intervals. In my timeline I estimated that this work would take 2 weeks. However in this first week I have managed to complete most of the work. I will give some comments on how I have worked with the Mercurial repository, how the work went and different things I encountered along the path.<br />
<br />
<h2>
Working with Mercurial</h2>
This is essentially the first time I'm using Mercurial for revision control, though I have used git before. However I quickly learned how to use it for the basic tasks that I need, committing, comparing files and checking the history. As mentioned in a previous post you can find my repository here [1].<br />
<h3>
Coding style</h3>
When I started to work with the files I realized that they did not follow Octaves coding standard [2]. After a short discussion on the mailing list we decided that I will update the files I change to follow the standard coding style. Usually it is not a good idea to change coding style and add functionality in the same commit. However most of the changes to coding style are only white space changes so they can be ignored using the -w flag in Mercurial. Thus we decided that as long as the coding style changes are only such that it is ignored with -w I will do it in the same commit as the added functionality. If there are some coding style changes that's not only white space, the most common example is to long lines, I do a commit with only changes to the coding style first. So if you want to take a look at the functionality I have added you will probably want to use the -w flag. Note however that I have not updated the coding style for any files I have not changed otherwise.<br />
<h3>
Committing</h3>
Normally I do one commit for each file, though in many cases the bare intervals and the decorated intervals have almost identical functions and in that case I commit changes to them both at the same time. Of course it also happens that I have to go back and do more changes to a files, in that case I just do another commit.<br />
<h2>
The actual work</h2>
The work went much faster than I expected. The main reason for this is that Octave has very good support for indexing. For example expressions like<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">
isnai(x.inf <= x.sup) = false; <br />
</span>
<br />
works just as well for matrices as for N-dimensional arrays. In fact the constructor for bare intervals even worked for N-dimensional arrays from the beginning, there I only had to do slight modification to the documentation and add some tests! <br />
<br />
Not all functions were that easy though. Some functions that have not been updated in a while clearly assumed the input was a matrix, for example in $hull$<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">
sizes1 = cellfun ("size", l, 1);<br />
sizes2 = cellfun ("size", l, 2);
</span><br />
<br />
In most cases I only needed to add more general indexing, often times even making the code clearer.<br />
<br />
In some functions all I had to do was to remove the check on the input data so that it would accept N-dimensional arrays. This was true in for example $cat$ were all I had to do was to remove the check and do some minor modifications to the documentation.<br />
<br />
I can conclude with saying that Octave has great support for working with N-dimensional arrays. Since internally the data for intervals are stored only as arrays I could make good use of it!<br />
<h2>
Noteworthy things</h2>
While most functions were straight forward to modify some required some thought. How should they even work for N-dimensional input?<br />
<h3>
Disp</h3>
When modifying the $disp$-function I chose to mimic how Octave handles displaying N-dimensional arrays. I noticed that this is different from how Matlab handles it. In Matlab we have<br />
<span style="font-family: "courier new" , "courier" , monospace;">
<br />
> x = zeros (2, 2, 2)<br /><br />x(:,:,1) =<br /><br /> 0 0<br /> 0 0<br /><br /><br />x(:,:,2) =<br /><br /> 0 0<br /> 0 0<br />
<br />
</span><br />
while in Octave it's<br />
<span style="font-family: "courier new" , "courier" , monospace;">
<br />
> x = zeros (2, 2, 2)<br />x =<br /><br />ans(:,:,1) =<br /><br /> 0 0<br /> 0 0<br /><br />ans(:,:,2) =<br /><br /> 0 0<br /> 0 0<br /><br />
</span><br />
I don't know the choice behind Octaves version. At least at first glance I think I prefer the way Matlab does it. But since I'm working in Octave I chose that style.<br />
<br />
The next question was how to handle the subset symbol, $\subset$. The interval package uses $=$ or $\subset$ depending on if the string representation is exact or not. For example<br />
<span style="font-family: "courier new" , "courier" , monospace;">
<br />
> x = infsup (1/2048, 1 + 1/2048);<br />
> format short; x<br />
x ⊂ [0.00048828, 1.0005]<br />
> format long; x<br />
x = [0.00048828125, 1.00048828125]<br />
</span><br />
How should this be handled for N-dimensional arrays? One way would be to switch all $=$ to $\subset$ is the representation is not exact. Another to use $\subset$ on all submatrices that does not have an exact string representation. The third way, and how it is implemented now, is to only change the first $=$ to $\subset$, the one after the variable name. Like this<br />
<span style="font-family: "courier new" , "courier" , monospace;">
<br />
> x(1,1,1:2) = infsup (1/2048, 1 + 1/2048)<br />
x ⊂ 1×1×2 interval array<br /><br />ans(:,:,1) = [0.00048828, 1.0005]<br />ans(:,:,2) = [0.00048828, 1.0005]<br /><br />
</span><br />
This might be a bit odd when you first look at it, on some places we use $=$ and on some $\subset$. Though I think it somehow makes sense, we are saying that $x$ is a subset of the $1\times1\times2$ interval array given by<br />
<span style="font-family: "courier new" , "courier" , monospace;">
<br />
ans(:,:,1) = [0.00048828, 1.0005]<br />ans(:,:,2) = [0.00048828, 1.0005]<br />
</span><br />
which actually is true. Anyway I will leave like this for now and then we might decide to switch it up later.<br />
<h3>
linspace and mince</h3>
The standard implementation of $linspace$ only supports scalar or vector input. It could be generalized to N-dimensional arrays by for example returning a N+1-dimensional array were the last dimension corresponds to the linearly spaced elements. But since this has not been done in the standard implementation I will at least wait with adding for intervals.<br />
<br />
The function $mince$ can be seen as a interval generalization of $linspace$. It takes an interval and returns an array of intervals whose union cover it. This could similarly be expanded to N dimensions by creating the array along the N+1 dimension. But again we choose to at least wait with adding this.<br />
<h3>
meshgrid and ndgrid</h3>
The interval package already has an implementation of $meshgrid$. But since it previously did not support 3-dimensional arrays it had to fit 3-d data in a 2-d matrix. Now that it supports 3-d data it can output that instead.<br />
<br />
Currently the interval package does not implement $ndgrid$. When I looked into it I realized that the standard implementation of $ndgrid$ actually works for interval arrays as well. I have not looked into the internals but in principle it should only need the $cat$ function, which is implemented for intervals. Further I noticed that the standard $meshgrid$ also works for intervals. However the interval implementation differs in that it converts all input to intervals, were as the standard implementation allows for non-uniform output. Using the interval implementation of $meshgrid$ we have<br />
<br />
<span style="font-family: "courier new" , "courier" , monospace;">
> [X Y] = meshgrid (infsup (1:3), 4:6)<br />
X = 3×3 interval matrix<br />
<br />
[1] [2] [3]<br />
[1] [2] [3]<br />
[1] [2] [3]<br />
<br />
Y = 3×3 interval matrix<br />
<br />
[4] [4] [4]<br />
[5] [5] [5]<br />
[6] [6] [6]<br />
</span><br />
but if we fall back to the standard implementation (by removing the interval implementation) we get<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
> [X Y] = meshgrid (infsup (1:3), 4:6)<br />
X = 3×3 interval matrix<br />
<br />
[1] [2] [3]<br />
[1] [2] [3]<br />
[1] [2] [3]<br />
<br />
Y =<br />
<br />
4 4 4<br />
5 5 5<br />
6 6 6<br />
</span><br />
Note that the last matrix is not an interval matrix.<br />
<br />
So the question is, should we implement a version of $ndgrid$ that converts everything to intervals or should we remove the implementation of $meshgrid$? It's at least most likely not a good idea that the functions are different. I think that removing the implementation of $meshgrid$ makes most sense. First of all it's less code to maintain, which is always nice. Secondly you can manually convert all input to the function to intervals if you want uniform output. If you do not want uniform output then the standard implementation works were as the interval implementation does not, so the standard implementation is more general in a sense.<br />
<br />
We have to choose what to do, but for now I leave it as it is.<br />
<h3>
Non-generalizable functions</h3>
From what I have found there is no way to create a 3-dimensional array in Octave in the same way you can create a 2-dimensional one with for example<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
M = [1, 2; 3, 4];<br />
</span><br />
Instead higher dimensional arrays have to be created using other functions, for example $reshape$ or $zeros$, or by specifying the submatrices directly<br />
<span style="font-family: "courier new" , "courier" , monospace;"><br />
M(:,:,1) = [1, 2; 3, 4];<br />
M(:,:,2) = [5, 6; 7, 8];<br />
</span><br />
This means that the functions $\_\_split\_interval\_literals\_\_$, which is used to split a string like $"[1, 2; 3, 4]"$ into its separate components, cannot really be generalized to N dimensions.<br />
<br />
<br />
[1] <a href="https://sourceforge.net/u/urathai/octave/ci/default/tree/">https://sourceforge.net/u/urathai/octave/ci/default/tree/</a> <br />
[2] <a href="http://wiki.octave.org/Octave_style_guide">http://wiki.octave.org/Octave_style_guide</a> Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0tag:blogger.com,1999:blog-3508201418641099808.post-40374413123932790072017-05-31T16:38:00.000+02:002017-05-31T16:38:01.890+02:00The first day and my repositoryYesterday I handed in the last exam for the semester(!) and today I started to work on the project full time. I begun by setting up a <a href="https://sourceforge.net/u/urathai/octave/ci/default/tree/">repository</a> for my code. At the moment I have only cloned the interval package, I'm still to make my own changes to it.<br />
<br />
I started to read the constructor for intervals to see how it works. While doing that I realized that there is much less to do than I thought. The constructor can actually handle creating intervals from numerical arrays of any dimension. The function displaying the interval can only handle up to two dimension but if you look at the internal state it actually has more dimensions. It is not perfect though, it does not work for decorated intervals and it cannot handle strings and cells as input. But still, it makes it much easier for me.<br />
<br />
I will continue to work and hopefully I have actually committed something by the end of the week. Next week I will be away but after that I will code for the rest of the summer.Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0tag:blogger.com,1999:blog-3508201418641099808.post-81588969439042456392017-05-28T19:30:00.000+02:002017-05-28T19:30:37.347+02:00TimelineThis post will be about specifying a timeline for my work this summer. As I mentioned in the introductory post the work will be about implementing support for higher dimensional arrays in the interval package. To begin with I have divided the work into 5 different parts:<br />
<h4>
1. Construction and Printing</h4>
This part will be about implementing functions for creating and printing arrays. It will mainly consist of modifying the standard constructor and all the different functions used for printing intervals so they can handle higher dimensional arrays.<br />
<h4>
2. Vectorized Functions</h4>
Here I will work on generalizing all functions supporting vectorization to also support arrays of higher dimensions.<br />
<h4>
3. Folding Functions</h4>
Here I will work on generalizing all functions implementing some sort of folding to support higher dimensions. By folding I mean taking a multidimensional array as input and returning an array of lower dimension. Examples of these functions are $sum$, $prod$ and $dot$. <br />
<h4>
4. Plotting</h4>
I'm not sure what support Octave has for plotting higher dimensional arrays, but if there are some functions which could also be useful for intervals I will try to implement them here. <br />
<h4>
5. Documentation</h4>
I'll write the documentation alongside the rest of the work. In the end I will try to add some usage examples and integrate it better with the standard documentation.<br />
<br />
So these are the parts in which I have divided my work in and the timeline will be<br />
<br />
<ul>
<li>Phase 1 (30/5 - 30/6)</li>
<ul>
<li>Week 1: Setting up</li>
<li>Week 2-3: Construction and Printing</li>
<li>Week 4: Vectorized Functions</li>
</ul>
<li>Phase 2 (3/7 - 28/7)</li>
<ul>
<li>Week 5: Continue on Vectorized Functions </li>
<li>Week 6-7: Folding Functions</li>
<li>Week 8: Plotting</li>
</ul>
<li>Phase 3 (31/7 - 25/8)</li>
<ul>
<li>Week 9: Continue on Plotting</li>
<li>Week 10-11: Documentation</li>
<li>Week 12: Finishing up!</li>
</ul>
</ul>
<br />
My first week will be rather short since I have an exam due in the middle of the week. After that I will also be away for a week not working on the project, I have no counted that week in the timeline above.Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0tag:blogger.com,1999:blog-3508201418641099808.post-75847054354507634052017-05-21T21:36:00.000+02:002017-05-21T21:36:19.253+02:00IntroductionHi! I'm Joel Dahne and I will be using this blog to share the progress of my work for Google Summer of Code 2017 under GNU Octave where I will be working on improving the interval package.<br />
<br />
<h2>
About me</h2>
Currently I'm a master student in mathematics at Uppsala University, Sweden, I'm just about to complete my first year and have one more to go. I first encountered interval numerics with my bachelor thesis, during which I tried to generalize the method described in <a href="http://www.sciencedirect.com/science/article/pii/S0377042708005074">this paper</a> to higher dimensions. The code from the project is available on GitHub, <a href="https://github.com/Urathai/generateZeros">https://github.com/Urathai/generateZeros</a>. Working on that project ignited my interest for interval numerics and I want to work to increase its availability to the common user.<br />
<h2>
The project</h2>
In short my project is about adding support for N-dimensional arrays in the interval package. At the moment the package only has support for up to 2-dimensional arrays. Most of the time this is enough but sometimes it is limiting. The goal is to have the syntax identical to the one for normal arrays. Switching from floats to intervals should be as easy as adding $infsup$ in front of the variable.<br />
<br />
During my time preparing I have also noticed that some of the folding functions (e.g. $sum$, $prod$ and $dot$) handle some edge cases differently than the standard implementation. Hopefully this can be resolved at the same time.<br />
<h2>
This blog</h2>
During my project I will try to update this blog with my current progress. It's my first time writing a blog so we will see how it goes. The next step for me is to create more detailed plan of how I should structure my work during the summer, this will most likely be the subject of my next post.Joel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.com0