Rank: 85 based on 635 downloads (last 30 days) and 20 files submitted
photo

Jan Simon

E-mail
Lat/Long
49.41804, 8.671068

Personal Profile:

Professional Interests:

 

Watch this Author's files

 

Files Posted by Jan View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
12 Mar 2010 BlockMean Fast mean of rectangular subarrays (MEX). No running mean: array size is reduced by window size. Author: Jan Simon matrix, average, array, mean, rectangular, block 38 0
05 Mar 2010 Screenshot anyEq Fast check if two arrays have any common element Author: Jan Simon isequal, equal, common element, compare, any, cmex 22 0
05 Mar 2010 Screenshot fSGolayFilt Simple but fast Savitzky Golay filter as C-Mex Author: Jan Simon savitzky golay, analysis, filter design, filter, savitzky golay filter, filter analysis 58 2
  • 5.0
5.0 | 2 ratings
27 Feb 2010 Screenshot XSum Fast Sum with error compensation Author: Jan Simon knuth, kahan, long double, accuracy, sum, compensated 22 2
10 Feb 2010 Screenshot CStrCatStr Cat 2 or 3 strings/cell strings C-MEX: 10 times faster than STRCAT Author: Jan Simon concatenation, cell string, cat, mex, string, strcat 28 0
Comments and Ratings by Jan View all
Updated File Comments Rating
01 Mar 2010 XSum Fast Sum with error compensation Author: Jan Simon

Dear Bruno! Thanks for the comment!
You've observed, that your 32 bit system has a higher accuracy than your 64 bit system for "Double" and "Long". (For the MSVC++ 2008 compiler long doubles are doubles, so both methods reply the same result.)
It seems, that your 32 bit system accumulates the sum (e.g. in DoubleDim1()) in a 80 bit register, while your 64 bit system applies standard 53 bit rounding. Please check your mexopts.bat files for the compiler flags /arch:SSE2 and /fp:[precise | fast | strict]. Perhaps a "#pragma fenv_access (off)" in a header?!

You hit two important points:
1. The results of the trivial "for (i = 0; i < N; Sum += X[i++])" depends critically on the compiler directives. I've tested XSum with LCC2.4, LCC3.8, BCC5.5, OpenWatcom 1.8 and MSVC 2008 SP1 and found 5 different behaviours for "Double", "Long" and "KnuthLong". The accuracy of "Knuth" and "Knuth2" was not significantly affected by the compilers in my tests.
2. If the compiler has such an influence, it is hard to assess the quality of the results automatically. I did not found a way to let the test function draw user-friendly conclusions about the accuracy.

Summation is numerically instable and even the trivial algorithms of XSum(Double) and XSum(Long) are fragile if different compilers and floating point environments are applied (I have to stress this more explicite in the help. Thanks!). Therefore I use XSum(Knuth) and XSum(Knuth2) to improve the stability.

17 Feb 2010 C-style MATLAB preprocessor Simple, only supports ifdef/endif/else with define/undef, simple syntax for &&/||. Author: Misha Koshelev

I was really happy to see a preprocessor for M-files here, because this could solve a lot of problems.
But after downloading I am disappointed, because there is not documentation in the function!
  function [varargout]=mpp(fn,varargin)
  % Simple MATLAB C-like preprocessor
  % <Author> <Date>
That's all. So I tried to look in the code to get some informations:
Initially the function searchs for something:
  if ~exist([fn,'.m1'])
This could mean a directory, a file name anywhere in the path, a Java class. To check the existence of a file, use EXIST(FileName, 'file') ! This is much faster and less ambiguous.

Then the name of the TEMP folder is obtained:
  tempdir=tempname;
  i=length(tempdir);while tempdir(i)~=filesep&&i>0;i=i-1;end;
  tempdir(i+1:end)=[];
1. "while tempdir(i) ~= filesep && i>0" fails if [i] is 0! Swap the two statements to: "while i> 0 && tempdir(i)~=filesep"
2. Or even better call FILEPARTS:
  tempdir = fileparts(tempname);
3. Or even much better: Do not overwrite Matlab's built-in function with the same name, but use it: TEMPDIR replies the TEMP directory...

I cannot estimate what the complex processing part does. Unfortunately no comments can be found here.

Finally you add the TEMP and its subfolders to the Matlab path "addpath(genpath(tempdir))" without removing it afterwards. This can lead to unwanted side-effects.

As conclusion I confirm the description: "something quick & dirty. Seems to work."
I'd strongly suggest some general improvements: Clean up the code, add much more comments, add a help section which explain inputs, outputs and what happens. Otherwise your program is not useful or usable by members of the FEX.
The idea is really good and MPP Fex: #7150 does not satisfy my needs.

26 Jan 2010 Vector to colon notation Converts a vector into a string with its MATLAB colon notation (single resolution). Author: Javier Lopez-Calderon

See also: http://www.mathworks.com/matlabcentral/fileexchange/26453

26 Jan 2010 vector to string Converts a vector to a string, using the colon operator to represent linearly spaced subvectors. Author: Sven Bossuyt

26 Jan 2010 vector to string Converts a vector to a string, using the colon operator to represent linearly spaced subvectors. Author: Sven Bossuyt

H1-line, help section, examples, author and history (helps to search for updates in the FEX later), some comments in the source, "See also:".
This function handles non-trivial cases also: ([1 4 8;2 5 6;3 10 4]) => 'reshape([ 1:5, 10:-2:4 ],[3 3])'
BTW: This is not *vector*to-string anymore.
The author cares for usability, fixes bugs and cares about comments. Thanks!

Comments and Ratings on Jan's Files View all
Updated File Comment by Comments Rating
01 Mar 2010 XSum Fast Sum with error compensation Author: Jan Simon Simon, Jan

Dear Bruno! Thanks for the comment!
You've observed, that your 32 bit system has a higher accuracy than your 64 bit system for "Double" and "Long". (For the MSVC++ 2008 compiler long doubles are doubles, so both methods reply the same result.)
It seems, that your 32 bit system accumulates the sum (e.g. in DoubleDim1()) in a 80 bit register, while your 64 bit system applies standard 53 bit rounding. Please check your mexopts.bat files for the compiler flags /arch:SSE2 and /fp:[precise | fast | strict]. Perhaps a "#pragma fenv_access (off)" in a header?!

You hit two important points:
1. The results of the trivial "for (i = 0; i < N; Sum += X[i++])" depends critically on the compiler directives. I've tested XSum with LCC2.4, LCC3.8, BCC5.5, OpenWatcom 1.8 and MSVC 2008 SP1 and found 5 different behaviours for "Double", "Long" and "KnuthLong". The accuracy of "Knuth" and "Knuth2" was not significantly affected by the compilers in my tests.
2. If the compiler has such an influence, it is hard to assess the quality of the results automatically. I did not found a way to let the test function draw user-friendly conclusions about the accuracy.

Summation is numerically instable and even the trivial algorithms of XSum(Double) and XSum(Long) are fragile if different compilers and floating point environments are applied (I have to stress this more explicite in the help. Thanks!). Therefore I use XSum(Knuth) and XSum(Knuth2) to improve the stability.

01 Mar 2010 XSum Fast Sum with error compensation Author: Jan Simon Luong, Bruno

Hello Jan,

I'm not sure if I interpret the TestXSum correctly, but many methods ran under 2010A 64-bit Matlab seems to get worse accuracy than 2009B 32-bit Matlab (see below). Any idea why?

------------------------------------------------------------------------
32-bit 2009B, MSVC 2008 SP1

  RANDN: Absolute results, sum estimated by Knuth2, average over 20 runs:
  Smaller results are better!
  0 must be replied for Knuth2, but even Knuth should be exact.
  X = RANDN(1, 1E4):
    SUM : 2.0996538E-013
    SUM(SORT): 1.1599255E-011
    Double : 0
    Long : 0
    Kahan : 2.3092639E-015
    Knuth : 0
    Knuth2 : 0
  X = RANDN(1, 1E5):
    SUM : 2.5210056E-012
    SUM(SORT): 4.2349626E-010
    Double : 0
    Long : 0
    Kahan : 1.2478907E-014
    Knuth : 0
    Knuth2 : 0
  X = RANDN(1, 1E6):
    SUM : 1.551328E-011
    SUM(SORT): 6.7532937E-009
    Double : 1.0658141E-015
    Long : 1.0658141E-015
    Kahan : 1.3500312E-014
    Knuth : 0
    Knuth2 : 0

------------------------------------------------------------------------
64-bit 2010A, MSVC 2008 SP1
  RANDN: Absolute results, sum estimated by Knuth2, average over 20 runs:
  Smaller results are better!
  0 must be replied for Knuth2, but even Knuth should be exact.
  X = RANDN(1, 1E4):
    SUM : 2.0996538E-013
    SUM(SORT): 1.1599255E-011
    Double : 2.0996538E-013
    Long : 2.0996538E-013
    Kahan : 2.3092639E-015
    Knuth : 0
    Knuth2 : 0
  X = RANDN(1, 1E5):
    SUM : 2.5210056E-012
    SUM(SORT): 4.2349626E-010
    Double : 3.2762681E-012
    Long : 3.2762681E-012
    Kahan : 1.2478907E-014
    Knuth : 0
    Knuth2 : 0
  X = RANDN(1, 1E6):
    SUM : 1.551328E-011
    SUM(SORT): 6.7532937E-009
    Double : 2.3623414E-011
    Long : 2.3623414E-011
    Kahan : 1.3500312E-014
    Knuth : 0
    Knuth2 : 0

22 Jan 2010 VChooseK Choose K elements from a vector - MEX: 100 times faster than NCHOOSEK Author: Jan Simon Simon, Jan

For choosing with/without Repitions and Order see also my submissions:
O: http://www.mathworks.com/matlabcentral/fileexchange/26397
R: http://www.mathworks.com/matlabcentral/fileexchange/26277
RO: http://www.mathworks.com/matlabcentral/fileexchange/26242

03 Jan 2010 CStr2String Fast concatenation of cell strings to a CHAR vector (mex) Author: Jan Simon Simon, Jan

The test data for the determination of speed have been unrealistic! I've used: C = cell(1, 1000); C(:)={blanks(n)}; This creates strings with shared data, which is an advantage for CStr2String and a disadvantage for CAT and SPRINTF. Sorry!
For realistic cell strings, e.g. 100 strings of length 10, CStr2String is 3 (not 4.1) times faster than CAT. For 10.000 strings of length 10 the speed gain is about 6.5 (not 61) (Matlab 7.8, WinXP). At least CStr2String is faster...
An updated test function and screen shot is coming soon!

01 Jan 2010 CStrAinBP Overlapping elements of 2 cell strings. 10-20 times faster than INTERSECT/ISMEMBER/SETDIFF. Author: Jan Simon Michael

Works well- thanks!

Top Tags Applied by Jan
choose, cmex, combinations, nchoosek, permutations
Files Tagged by Jan View all
Updated   File Tags Downloads
(last 30 days)
Comments Rating
12 Mar 2010 BlockMean Fast mean of rectangular subarrays (MEX). No running mean: array size is reduced by window size. Author: Jan Simon matrix, average, array, mean, rectangular, block 38 0
05 Mar 2010 Screenshot anyEq Fast check if two arrays have any common element Author: Jan Simon isequal, equal, common element, compare, any, cmex 22 0
05 Mar 2010 Screenshot fSGolayFilt Simple but fast Savitzky Golay filter as C-Mex Author: Jan Simon savitzky golay, analysis, filter design, filter, savitzky golay filter, filter analysis 58 2
  • 5.0
5.0 | 2 ratings
27 Feb 2010 Screenshot XSum Fast Sum with error compensation Author: Jan Simon knuth, kahan, long double, accuracy, sum, compensated 22 2
10 Feb 2010 Screenshot CStrCatStr Cat 2 or 3 strings/cell strings C-MEX: 10 times faster than STRCAT Author: Jan Simon concatenation, cell string, cat, mex, string, strcat 28 0
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com