Search Comments and Ratings

go

   
Date File Comment by Comment Rating
21 Feb 2015 Random Numbers from a Discrete Distribution Simple algorithm to generate random numbers from a user-defined discrete probability distribution. Author: Tristan Ursell

Tristan Ursell (view profile)

Chi-Fu

Chi-Fu (view profile)

5
09 Jan 2015 Generate Random Numbers from a 2D Discrete Distribution Random numbers from any 2D discrete probability distribution, at any resolution. Author: Tristan Ursell

Tristan Ursell (view profile)

Steven White

Very useful - thanks!

5
17 Oct 2014 Generate Random Numbers from a 2D Discrete Distribution Random numbers from any 2D discrete probability distribution, at any resolution. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

Good catch -- I just put a check in the code to make sure the interpolated values are always positive.

Comment only
17 Oct 2014 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

@Frank -- That's an interesting idea, but I worry that it's too dependent on which point you choose as the first point. In other words, for the same vector, different starting points would give different results (although the same is true for the algorithm in general). Probably the right way to do something like that is calculate a distance matrix for all points and then do a bit of graph theory to group the points by mutual distance. Give it a try :)

Comment only
01 Oct 2014 Generate Random Numbers from a 2D Discrete Distribution Random numbers from any 2D discrete probability distribution, at any resolution. Author: Tristan Ursell

Tristan Ursell (view profile)

M S

M S (view profile)

Excellent code, and amazingly, the only FEX submission for random sampling from 2D distributions.

I did run into a little bug. When using interpolation (res>1), I occasionally get "Error: All elements of first argument, P, must be positive." thrown by gendist(). This looks like it comes from interpolation giving negative numbers. The only hint at the culprit is that the joint PDFs I'm sending to your function have very very small numbers, (e.g., 1.4822e-323). When more reasonable numbers are used, the interpolation is fine.

5
23 Aug 2014 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Frank Pennekamp

Hi,
This is a great function you've made here! But I was wondering if it is possible to find multiple closed contours in one X and Y vector?

maybe using an if statement when the starting point is closer than any other data point it closes the contour and starts a new one on the next point of your vector?

I think this would be a very nice addition to your program for when your working with big spatial datasets.

Cheers

Comment only
30 Jan 2014 Frechet Distance Calculator Estimate the similarity between curves in space using the scalar Frechet Distance. Author: Tristan Ursell

Tristan Ursell (view profile)

Venkat R

Nice submission. Has great potential application.

5
26 Oct 2013 Adaptive Colormap Function Creates a Colormap Specific to Data Easily design and fit a colormap to the values in your data! Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

Hey Blake -- found the single character bug that caused this! Be careful with the "<" vs. "<=" :)

Comment only
23 Oct 2013 Random Numbers from a Discrete Distribution Simple algorithm to generate random numbers from a user-defined discrete probability distribution. Author: Tristan Ursell

Tristan Ursell (view profile)

Senthil

Thanks. It helped me in my program

4
29 Sep 2013 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

Zheng -- found a small bug that was responsible. New version uploaded, and awaiting approval from Mathworks (or just add "bad_pts=zeros(size(Xin));") at line 235. Thanks!

Comment only
29 Sep 2013 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

Hi Zheng, I presume this was with the last example? I'll take a look.

Comment only
28 Sep 2013 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Zheng

Zheng (view profile)

Hi, I like your idea but every time I run your examples with your points2contour function, errors occur. Please help asap!

This is what showed up in the prompt window:
Undefined function or variable "bad_pts".

Error in points2contour (line 276)
temp1=find(~bad_pts);

4
22 Sep 2013 Find Image Extrema Find local maxima, local minima, saddle points, and flat regions in an image. Author: Tristan Ursell

Tristan Ursell (view profile)

Zhouxin Xi

It works very well. I used it to find the image max peaks. more accurate than the extrema2.m

5
19 Aug 2013 Adaptive Colormap Function Creates a Colormap Specific to Data Easily design and fit a colormap to the values in your data! Author: Tristan Ursell

Tristan Ursell (view profile)

GradStudent

Works great, thanks for the submission!

If anything: it would be nice if on a plot of 0-100, there was only red and black showing on the plot - there's always blue and red showing on the plots, even if no negative values are present.

Comment only
15 Aug 2013 Image Noise Reduction by Local Statistics Reduce image noise by measuring local pixel statistics and remapping intensities. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

@ Krishna, what exactly do you mean by "unknown scaling" -- the output image is the same size as the input image, so there's no scaling there, and the intensity values are not scaled, they are of course adjusted by the calculation itself. You can subtract the input from the output and verify that it removes (mostly) noise ... and hence there is no scaling.

I designed this filter, but it is something like a cross between an averaging and median filter.

If this clarified things for you, please consider re-rating this to 5 stars.

Comment only
15 Aug 2013 Image Noise Reduction by Local Statistics Reduce image noise by measuring local pixel statistics and remapping intensities. Author: Tristan Ursell

Tristan Ursell (view profile)

Krishna Kuchibhotla

It is awesome! Worked very well for the first time without IPT and not knowing much about the algorithm in use. 2 additional things would help much better...a) the axes are being scaled to unknown values; would be better to restore the scaling of Iout vector to Iin, b) any literature references to help understand the basics of the algorithm. Thanks.

4
13 Aug 2013 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

@Roy, I included the requested feature late last month.

Comment only
05 Aug 2013 Frechet Distance Calculator Estimate the similarity between curves in space using the scalar Frechet Distance. Author: Tristan Ursell

Tristan Ursell (view profile)

you

you (view profile)

5
23 Jul 2013 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

@Roy -- good suggestion, I will try to implement that soon.

Comment only
23 Jul 2013 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Roy

Roy (view profile)

This looks great, but I have a feature request:

The built-in command 'sort' has the optional syntax

[y,i]=sort(x)

where y is a sorted version of x, and x(i)=y

This is useful if you have several data vectors that all need to be re-ordered along with x.

I think adding this feature to the program would be pretty simple, but that you could do it much faster than I could.

Thanks!

4
17 Jun 2013 Find Image Extrema Find local maxima, local minima, saddle points, and flat regions in an image. Author: Tristan Ursell

Tristan Ursell (view profile)

Tobias

Tobias (view profile)

Very valuable file, thanks for uploading!

5
17 Jun 2013 Create a Simulated Image of Diffraction Limited Spots with Noise Create images with diffraction-limited spots of varying size and intensity, with noise. Author: Tristan Ursell

Tristan Ursell (view profile)

Abani Nayak

sir
i am sorry to put you in trouble. i myself figured it out how to do that. i had not checked the imwrite function at that time.
thank you sir for your beautiful code. it will help me a lot in my project.

5
17 Jun 2013 Create a Simulated Image of Diffraction Limited Spots with Noise Create images with diffraction-limited spots of varying size and intensity, with noise. Author: Tristan Ursell

Tristan Ursell (view profile)

Abani Nayak

sir
i am new to the matlab. i am doing a similar project. this program was very helpful to me. while running the examples given above by you. i am getting the spots enclosed with red circles. i want the image as it is but without the red circle. i did some modification with your code but i couldn't find any solutions to my problem.
so i request yo to kindly help me to get the spots but without red circles enclosing the spot.
Thank you

3
10 Apr 2013 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Jay Cheng

Awesome work! It works on my data set while built in poly2cw does not.

my x=[121
121
121
121
121
121
121
121
121
121
121
121
121
121
121
121
121
122
122
122
122
122
122
122
122
122
123
123
123
123
123
124
124
124
125
125
125
125
125
125
125
125
126
126
126
127
127
127
128
128
128
128
129
129
129
130
130
130
130
131
131
131
131
132
132
133
133
134
134
135
135
136
136
137
137
138
138
139
139
140
140
141
141
142
142
143
143
144
144
145
145
145
145
146
146
147
147
148
148
149
149
150
150
151
151
152
152
153
153
154
154
155
155
156
156
157
157
158
158
159
159
160
160
161
161
162
162
163
163
164
164
165
165
166
166
167
167
168
168
169
169
170
170
171
171
171
171
172
172
173
173
174
174
175
175
175
175
175
175
176
176
176
176
177
177
178
178
179
179
180
180
181
181
182
182
183
183
184
184
184
184
185
185
186
186
187
187
188
188
189
189
190
190
190
190
190
191
191
191
191
191
191
191
191
191
192
192
192
192
192
192
192
192
192
192
192
192
192
193
193
193
193
193
193
193
];
y=[121
121
121
121
121
121
121
121
121
121
121
121
121
121
121
121
121
122
122
122
122
122
122
122
122
122
123
123
123
123
123
124
124
124
125
125
125
125
125
125
125
125
126
126
126
127
127
127
128
128
128
128
129
129
129
130
130
130
130
131
131
131
131
132
132
133
133
134
134
135
135
136
136
137
137
138
138
139
139
140
140
141
141
142
142
143
143
144
144
145
145
145
145
146
146
147
147
148
148
149
149
150
150
151
151
152
152
153
153
154
154
155
155
156
156
157
157
158
158
159
159
160
160
161
161
162
162
163
163
164
164
165
165
166
166
167
167
168
168
169
169
170
170
171
171
171
171
172
172
173
173
174
174
175
175
175
175
175
175
176
176
176
176
177
177
178
178
179
179
180
180
181
181
182
182
183
183
184
184
184
184
185
185
186
186
187
187
188
188
189
189
190
190
190
190
190
191
191
191
191
191
191
191
191
191
192
192
192
192
192
192
192
192
192
192
192
192
192
193
193
193
193
193
193
193
];

Maybe I misunderstood poly2cw. But what ever, your points2contour can sort my coordinates into correct order! Many thanks!

5
14 Dec 2012 Adaptive Colormap Function Creates a Colormap Specific to Data Easily design and fit a colormap to the values in your data! Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

I'll fix the typos in the description soon.

Comment only
15 Nov 2012 Image Noise Reduction by Local Statistics Reduce image noise by measuring local pixel statistics and remapping intensities. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

if you like this function, please consider rating it! (if you don't, please tell me why)

Comment only
26 Apr 2012 Generate Random Numbers from a 2D Discrete Distribution Random numbers from any 2D discrete probability distribution, at any resolution. Author: Tristan Ursell

Tristan Ursell (view profile)

Filip Trönnberg

Wonderful function!!

5
23 Mar 2012 Copy Files in Batches using Search Terms Copy files matching search terms, from sub-directories matching search terms into a new directory. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

@Jan, thanks. I 'char'-ed it just to be safe :)

Comment only
23 Mar 2012 Copy Files in Batches using Search Terms Copy files matching search terms, from sub-directories matching search terms into a new directory. Author: Tristan Ursell

Tristan Ursell (view profile)

Jan Simon

Jan Simon (view profile)

Just a small comment:
path_in=fullfile(fullfile(path1,Dstruct(dirs(i)).name),char(tempnames(j)))
can be written as:
path_in = fullfile(path1, Dstruct(dirs(i)).name, tempnames{j})

Comment only
15 Mar 2012 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

Here's a partial fix of the problem you mention Catherine. There is no general solution to your problem without solving the TSP -- which is NP hard :) There is however another level of fix that would require time to write, where you sample N-points ahead in the contour and search exhaustively for the shortest local N-path. That would likely get rid of most crossings and

Comment only
13 Mar 2012 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Catherine

Yes, that is interesting, in theory. In practice, this unexpected part of my project is a very annoying bottleneck. ;) Luckily, mine is a very rough shoreline (taken off a grid), and so is not really scale-independent.

Comment only
13 Mar 2012 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

Hi Catherine --

I'll be away for a few days, but yes, I was going to add a feature like that, and will try to get to it this week. Interesting that you bring up shorelines, which are fractals, and fractals, having no absolute scale do not have a definitely shortest contour. I realize that for your example its discrete and hence there is some shortest path, but it's still really hard to connect such structures because they tend to have this scale free property.

Comment only
13 Mar 2012 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Catherine

5
13 Mar 2012 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Catherine

Tristan, do you have any hints for dealing with messy dat sets? I am tracing points along a shoreline, and your program gets it almost right, just a few places where it joins points across large distances that should not be connected. Something like 'if distance between points>X, redo' in some way or other.

4
12 Mar 2012 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

@Catherine, glad to hear it's working well for you :) Please consider leaving a good rating so that others are more likely to try it.

Comment only
12 Mar 2012 Connect Randomly Ordered 2D Points into a Minimal Nearest-Neighbor Closed Contour Connects randomly ordered 2D points into a minimal nearest neighbor contour. Author: Tristan Ursell

Tristan Ursell (view profile)

Catherine

This works great, and is very fast (on my admittedly small dataset). Thanks! I've been looking for something like this.

Comment only
02 Mar 2012 Random Numbers from a Discrete Distribution Simple algorithm to generate random numbers from a user-defined discrete probability distribution. Author: Tristan Ursell

Tristan Ursell (view profile)

NNNN

NNNN (view profile)

Thanks a lot, Derek, this one is indeed a champion !

On a 2.1GHz machine, Matlab2008a 32-bit,
I got:
t2 = 0.18
VS
t2 within 18-22 for a couple of other tested methods.
Kind regards,
N

5
09 Dec 2011 Random Numbers from a Discrete Distribution Simple algorithm to generate random numbers from a user-defined discrete probability distribution. Author: Tristan Ursell

Tristan Ursell (view profile)

Derek O'Connor

Here is a function that beats those above by a mile:

function S = DiscSampVec2(x,p,ns);
%
[~,idx] = histc(rand(1,ns),[0,cumsum(p)]);
S = x(idx);

This is a slight modification of the function on page 47, Kroese, Taimre, and Botev, Handbook of Monte Carlo Methods, Wiley, 2011.

>> ns=10^6; n=10^3; x=1:n;
>> p = rand(1,n); p = p/sum(p);

>> t2=tic;
>> S = DiscSampVec2(x,p,ns);
>> t2=toc(t2)

0.15835

Comment only
07 Dec 2011 Random Numbers from a Discrete Distribution Simple algorithm to generate random numbers from a user-defined discrete probability distribution. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

@Derek, I am aware and glad that there are other formulations of this task. 'N' and 'M' are clearly defined in the description above. There is no overt relationship between P and N & M. P is a distribution, in the mathematical sense of the word, and because it describes the probability of picking an index of P, the sum of those values must equal one, i.e. it must be normalized.

For reference:
http://en.wikipedia.org/wiki/Probability_distribution

http://en.wikipedia.org/wiki/Normalizing_constant

Comment only
07 Dec 2011 Random Numbers from a Discrete Distribution Simple algorithm to generate random numbers from a user-defined discrete probability distribution. Author: Tristan Ursell

Tristan Ursell (view profile)

Derek O'Connor

ALSO:

See here

http://math.stackexchange.com/questions/48919/generating-a-non-uniform-discrete-random-variable

and here

http://math.stackexchange.com/questions/58060/minimize-expected-value

Comment only
07 Dec 2011 Random Numbers from a Discrete Distribution Simple algorithm to generate random numbers from a user-defined discrete probability distribution. Author: Tristan Ursell

Tristan Ursell (view profile)

Derek O'Connor

It would be useful if the author would explain clearly what P, M, N are. For example, if P is a "discrete probability distribution for the indices of P", then why does it need to be normalized? Also I think the author means "density" or "mass function" rather than "distribution".

Is M the size of the sample and is N the length of P?

I presume the author is trying to do what this simple function does:

function S = DiscITSamp1(x,p,ns);

% Generate a random sample S of size ns
% with replacement from x(1:n) with prob. % density p(1:n), using the discrete
% inverse transform method.
% Time Complexity: O(n*ns).
% Derek O'Connor, 31 July 2011.
% derekroconnor@eircom.net
%
% USE: S = DiscITSamp1([5 7 8 11],
% [0.2 0.3 0.4 0.1],1000);hist(S)

cdf = cumsum(p);
S = zeros(1,ns);
for k = 1:ns
u = rand;
i = 1;
while cdf(i) <= u
i = i+1;
end;
S(k) = x(i);
end

This is three times faster than GENDIST on a 2.3GHz machine, Matlab2008a 64-bit

>> ns=10^6;n = 10^3;x=1:n;p=rand(1,n);p=p/sum(p);
>> tic;S1 = DiscITSamp1(x,p,ns);t=toc;disp([ns t])
1e+006 5.6115

>> tic;S2 = gendist(p,1,ns);t=toc;disp([ns t])
1e+006 19.278

Comment only
06 Dec 2011 1D Non-derivative Peak Finder Up-sample and filter noisy data to find peaks without using derivatives. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

No longer uses fspecial. Bug pointed out by Andrew has been fixed.

Comment only
06 Dec 2011 1D Non-derivative Peak Finder Up-sample and filter noisy data to find peaks without using derivatives. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

Hsueh-Hsin -- I will look into that, agreed it would be preferable to not call it.

Comment only
16 Nov 2011 1D Non-derivative Peak Finder Up-sample and filter noisy data to find peaks without using derivatives. Author: Tristan Ursell

Tristan Ursell (view profile)

Hsueh-Hsin

'fspecial' from Image Processing Toolbox: could it be removed/replaced

Comment only
15 Nov 2011 1D Non-derivative Peak Finder Up-sample and filter noisy data to find peaks without using derivatives. Author: Tristan Ursell

Tristan Ursell (view profile)

Tristan Ursell

Tristan Ursell (view profile)

Andrew -- thank you -- I will fix that!

Comment only
08 Nov 2011 1D Non-derivative Peak Finder Up-sample and filter noisy data to find peaks without using derivatives. Author: Tristan Ursell

Tristan Ursell (view profile)

Andrew Davis

Thanks for posting this, it works well, and the code is nicely laid out. One small bug, in order for the fourth method of calling the function to work, line 264 should be:
if and(npeaks>1,exist('cuttype'))

Comment only
08 Nov 2011 1D Non-derivative Peak Finder Up-sample and filter noisy data to find peaks without using derivatives. Author: Tristan Ursell

Tristan Ursell (view profile)

Andrew Davis

5
07 Sep 2011 1D Non-derivative Peak Finder Up-sample and filter noisy data to find peaks without using derivatives. Author: Tristan Ursell

Tristan Ursell (view profile)

Kiran

Kiran (view profile)

5

Contact us