Mercurial > forge
changeset 11194:947f42078624 octave-forge
improved computation of exponential sum
author | mmarzolla |
---|---|
date | Tue, 30 Oct 2012 14:24:56 +0000 |
parents | 447c978c7b34 |
children | 2f0c66bf783d |
files | main/queueing/Makefile main/queueing/doc/INSTALL main/queueing/inst/Makefile main/queueing/inst/private/expn.m main/queueing/inst/private/sumexpn.m main/queueing/inst/qsammm.m main/queueing/inst/qsmmm.m main/queueing/test/fntests.m |
diffstat | 8 files changed, 123 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/main/queueing/Makefile Tue Oct 30 12:13:45 2012 +0000 +++ b/main/queueing/Makefile Tue Oct 30 14:24:56 2012 +0000 @@ -6,6 +6,7 @@ SUBDIRS=inst doc test devel DISTFILES=COPYING NEWS DESCRIPTION DISTSUBDIRS=inst doc +OCTAVE=octave .PHONY: clean check @@ -54,7 +55,7 @@ uuencode $(DISTNAME).tar.gz < $(DISTNAME).tar.gz > $(DISTNAME).tar.gz.uue $(PROGNAME)-html.tar.gz: - ~/src/octave-3.6.1/run-octave -qf --eval "pkg load generate_html; pkg install -local $(DISTNAME).tar.gz; pkg load queueing; generate_package_html ('queueing', 'queueing-html', 'octave-forge'); pkg uninstall $(PROGNAME)" + ~/src/octave-3.6.1/run-octave -q --eval "pkg install -local $(DISTNAME).tar.gz; pkg load queueing; generate_package_html ('queueing', 'queueing-html', 'octave-forge'); pkg uninstall $(PROGNAME)" tar cfz $(PROGNAME)-html.tar.gz $(PROGNAME)-html uuencode $(PROGNAME)-html.tar.gz < $(PROGNAME)-html.tar.gz > $(PROGNAME)-html.tar.gz.uue
--- a/main/queueing/doc/INSTALL Tue Oct 30 12:13:45 2012 +0000 +++ b/main/queueing/doc/INSTALL Tue Oct 30 14:24:56 2012 +0000 @@ -16,7 +16,7 @@ 1.1 Installation through Octave package management system ========================================================= -The most recent version of `queueing' is 1.2.0 and can be downloaded +The most recent version of `queueing' is 2.0.0 and can be downloaded from Octave-Forge `http://octave.sourceforge.net/queueing/' @@ -48,7 +48,7 @@ Octave-Forge; then, to install the package in the system-wide location issue this command at the Octave prompt: - octave:1> pkg install _queueing-1.2.0.tar.gz_ + octave:1> pkg install _queueing-2.0.0.tar.gz_ (you may need to start Octave as root in order to allow the installation to copy the files to the target locations). After @@ -57,7 +57,7 @@ If you do not have root access, you can do a local install using: - octave:1> pkg install -local queueing-1.2.0.tar.gz + octave:1> pkg install -local queueing-2.0.0.tar.gz Note: Octave version 3.2.3 as shipped with Ubuntu 10.04 LTS seems to ignore `-local' and always tries to install the @@ -70,7 +70,7 @@ octave:1>pkg list queueing Package Name | Version | Installation directory --------------+---------+----------------------- - queueing | 1.2.0 | /home/moreno/octave/queueing-1.2.0 + queueing | 2.0.0 | /home/moreno/octave/queueing-2.0.0 4. Starting from version 1.1.1, `queueing' is no longer automatically loaded on Octave startup. To make the functions available for use, @@ -94,8 +94,8 @@ If you want to manually install `queueing' in a custom location, you can download the tarball and unpack it somewhere: - tar xvfz queueing-1.2.0.tar.gz - cd queueing-1.2.0/queueing/ + tar xvfz queueing-2.0.0.tar.gz + cd queueing-2.0.0/queueing/ Copy all `.m' files from the `inst/' directory to some target location. Then, start Octave with the `-p' option to add the target
--- a/main/queueing/inst/Makefile Tue Oct 30 12:13:45 2012 +0000 +++ b/main/queueing/inst/Makefile Tue Oct 30 14:24:56 2012 +0000 @@ -1,5 +1,5 @@ .PHONY: clean check dist -DISTFILES=$(wildcard *.m) Makefile +DISTFILES=$(wildcard *.m) $(wildcard private/*.m) Makefile ALL:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/queueing/inst/private/expn.m Tue Oct 30 14:24:56 2012 +0000 @@ -0,0 +1,32 @@ +## Copyright (C) 2012 Moreno Marzolla +## +## This file is part of the queueing toolbox. +## +## The queueing toolbox is free software: you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation, either version 3 of the +## License, or (at your option) any later version. +## +## The queueing toolbox is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the queueing toolbox. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## +## @deftypefn {Function File} {@var{r} =} expn (@var{a}, @var{n}) +## +## Compute @code{r = a^n / n!}, with @math{a>0} and @math{n @geq{} 0}. +## +## @end deftypefn +function r = expn( a, n ) + n>=0 || \ + error("n must be nonnegative"); + a>0 || \ + error("a must be positive"); + tmp = cumprod( [1 a./(1:n)] ); + r = tmp(n+1); +endfunction \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/queueing/inst/private/sumexpn.m Tue Oct 30 14:24:56 2012 +0000 @@ -0,0 +1,58 @@ +## Copyright (C) 2012 Moreno Marzolla +## +## This file is part of the queueing toolbox. +## +## The queueing toolbox is free software: you can redistribute it and/or +## modify it under the terms of the GNU General Public License as +## published by the Free Software Foundation, either version 3 of the +## License, or (at your option) any later version. +## +## The queueing toolbox is distributed in the hope that it will be +## useful, but WITHOUT ANY WARRANTY; without even the implied warranty +## of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with the queueing toolbox. If not, see <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## +## @deftypefn {Function File} {@var{r} =} sumexpn (@var{a}, @var{n}) +## +## Compute the sum: +## +## @iftex +## @tex +## $$ S(a,n) = \sum_{k=0}^n {a^k \over k!} $$ +## @end tex +## @end iftex +## @ifnottex +## @example +## n +## __ +## \ a^k +## S(a,n) = > ----- +## /__ k! +## k=0 +## @end example +## @end ifnottex +## +## with @math{a>0} and @math{n @geq{} 0}. +## +## @end deftypefn +function r = sumexpn( a, n ) + n>=0 || \ + error("n must be nonnegative"); + a>0 || \ + error("a must be positive"); + r = sum(cumprod([1 a./(1:n)])); +endfunction +%!test +%! a = 0.8; +%! n = 0; +%! assert( sumexpn(a,n), sum(a.^(0:n) ./ factorial(0:n)), 1e-6 ); + +%!test +%! a = 1.2; +%! n = 6; +%! assert( sumexpn(a,n), sum(a.^(0:n) ./ factorial(0:n)), 1e-6 ); \ No newline at end of file
--- a/main/queueing/inst/qsammm.m Tue Oct 30 12:13:45 2012 +0000 +++ b/main/queueing/inst/qsammm.m Tue Oct 30 14:24:56 2012 +0000 @@ -85,12 +85,19 @@ X = lambda; U = rho = lambda / sum(mu); Q = p0 = 0; +#{ k=[0:m-1]; p0 = 1 / ( ... sum( (m*rho).^k ./ factorial(k)) + ... (m*rho)^m / (factorial(m)*(1-rho)) ... ); pm = (m*rho)^m/(factorial(m)*(1-rho))*p0; +#} + p0 = 1 / ( ... + sumexpn( m*rho, m-1 ) + ... + expn(m*rho, m) / (1-rho) ... + ); + pm = expn(m*rho, m)*p0/(1-rho); Q = m*rho+rho / (1-rho) * pm; R = Q / X; endfunction
--- a/main/queueing/inst/qsmmm.m Tue Oct 30 12:13:45 2012 +0000 +++ b/main/queueing/inst/qsmmm.m Tue Oct 30 14:24:56 2012 +0000 @@ -125,18 +125,22 @@ X = lambda; U = rho = lambda ./ (m .* mu ); - Q = p0 = 0*lambda; - for i=1:length(lambda) # I cannot easily vectorize this - #p = zeros(1,m(i)+1); + Q = p0 = pm = 0*lambda; + for i=1:length(lambda) +#{ k=[0:m(i)-1]; p0(i) = 1 / ( ... - sum( (m(i)*rho(i)).^ k ./ factorial(k)) + ... + sum( (m(i)*rho(i)).^ k ./ factorial(k)) + ... (m(i)*rho(i))^m(i) / (factorial(m(i))*(1-rho(i))) ... ); - #p(2+k) = p(1)*( m(i)*rho(i) ).^(1+k)./factorial(1+k); - #U(i) = 1-dot( (m(i)-k)./m(i), p(k+1) ); # FIXME: check +#} + p0(i) = 1 / ( ... + sumexpn( m(i)*rho(i), m(i)-1 ) + ... + expn(m(i)*rho(i), m(i))/(1-rho(i)) ... + ); + pm(i) = expn(m(i)*rho(i),m(i))*p0(i)/(1-rho(i)); endfor - pm = (m.*rho).^m./(factorial(m).*(1-rho)).*p0; + ## pm = (m.*rho).^m./(factorial(m).*(1-rho)).*p0; Q = m .* rho .+ rho ./ (1-rho) .* pm; R = Q ./ X; endfunction
--- a/main/queueing/test/fntests.m Tue Oct 30 12:13:45 2012 +0000 +++ b/main/queueing/test/fntests.m Tue Oct 30 14:24:56 2012 +0000 @@ -98,7 +98,8 @@ dp = dn = dxf = dsk = 0; for i = 1:length (lst) nm = lst(i).name; - if (length (nm) > 5 && strcmp (nm(1:5), "test_") + if (length (nm) > 5 + && strcmp (nm(1:5), "test_") && strcmp (nm((end-1):end), ".m")) p = n = 0; ffnm = fullfile (d, nm); @@ -127,7 +128,10 @@ dp = dn = dxf = dsk = 0; for i = 1:length (lst) nm = lst(i).name; - if (lst(i).isdir && ! strcmp (nm, ".") && ! strcmp (nm, "..") + if (lst(i).isdir + && ! strcmp (nm, "private") + && ! strcmp (nm, ".") + && ! strcmp (nm, "..") && ! strcmp (nm, "CVS")) [p, n, xf, sk] = run_test_script (fid, [d, "/", nm]); dp += p;