tag:blogger.com,1999:blog-35082014186410998082017-06-22T14:24:53.561+02:00GSoC 2017: Improving the Interval PackageJoel Dahnehttp://www.blogger.com/profile/17145498048912526564noreply@blogger.comBlogger4125tag: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