33
Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions Preliminaries 1/1: Using kernel0 for 1-D Kernels 1/2: Using kernel0 for 2-D Kernels 1/3: Kernel as PDF Verification 1/4: Scaling Kernels, 1-D Gaussian PDF Verification 1/5: Scaling 2-D Kernels 1/6: Recentering 1-D Kernel Locations 1/7: Recentering 2-D Kernel Locations Preliminaries #2 2/1: Plotting Kernels 2/2: Plotting a Summed Kernel 2/3: Plotting the 1-D Gaussian Kernel Density Estimate 2/4: Experimenting with more Kernels Preliminaries #3 2/1: 2-D Kernel Density Estimation 2/2: Other Point Patterns 3/3: Play with many Kernel Types and properties Instructions You can insert a variety of text formats in your M-file, using: Cell -> Insert Text Markup the differences between the above text formats are only visible in the published html file. For example, you can have a bulleted list with: boldface text italisized text monospaced text; this is typically reserved for Matlab commands What to turn in: For each Lab assignment, send an e-mail to the READER [email protected] with: (i) a M-file containig the appropriate Matlab commands (ii) a .zip archive of the above html folder published via Matlab Collaboration is encouraged, but each student needs to submit his or her own M-file and .zip archive to the Reader Good luck, and remember to put your name at the top of this file... Phaedon C. Kyriakidis, April 2009. Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc... 1 of 33 4/23/2009 12:25 PM

Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

  • Upload
    others

  • View
    12

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Solutions for Geog 210C Lab Assignment #1 - 68/70

STUDENT NAME: F. Antonio MedranoDATE COMPLETED:

Contents

Instructions

Preliminaries

1/1: Using kernel0 for 1-D Kernels

1/2: Using kernel0 for 2-D Kernels

1/3: Kernel as PDF Verification

1/4: Scaling Kernels, 1-D Gaussian PDF Verification

1/5: Scaling 2-D Kernels

1/6: Recentering 1-D Kernel Locations

1/7: Recentering 2-D Kernel Locations

Preliminaries #2

2/1: Plotting Kernels

2/2: Plotting a Summed Kernel

2/3: Plotting the 1-D Gaussian Kernel Density Estimate

2/4: Experimenting with more Kernels

Preliminaries #3

2/1: 2-D Kernel Density Estimation

2/2: Other Point Patterns

3/3: Play with many Kernel Types and properties

Instructions

You can insert a variety of text formats in your M-file, using:

Cell -> Insert Text Markup

the differences between the above text formats are only visible in the published html file.

For example, you can have a bulleted list with:

boldface text

italisized text

monospaced text; this is typically reserved for Matlab commands

What to turn in:

For each Lab assignment, send an e-mail to the READER [email protected] with:

(i) a M-file containig the appropriate Matlab commands (ii) a .zip archive of the above html folder published via Matlab

Collaboration is encouraged, but each student needs to submit his or her own M-file and

.zip archive to the Reader

Good luck, and remember to put your name at the top of this file...

Phaedon C. Kyriakidis, April 2009.

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

1 of 33 4/23/2009 12:25 PM

Page 2: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Preliminaries

clear; clc;

1/1: Using kernel0 for 1-D Kernels 5/5, a better interpretation is

expected next time

% Create kernels over a fixed region and bandwidth and various typesdx0= -4:0.05:4;bandW1 = 1;kernType = [0 1 3 5]; % rectangular, triangular, Gaussian, and Epanechnikov

% display the four kernels of different types in one figurefor i = 1:4 subplot(2,2,i); output1(:,i) = kernel0({dx0}, kernType(i), bandW1, 1);end% The graphs show kernels of different shapes. Cool!

1/2: Using kernel0 for 2-D Kernels 4/5, interpretation???

% Create kernels over a fixed region and bandwidth and various typesdx0= -4:0.05:4;dy0= -4:0.05:4;bandW2 = [1 1];kernType = [0 1 3 5];

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

2 of 33 4/23/2009 12:25 PM

Page 3: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

% display the four kernels of different types in one figurefor i = 1:4 subplot(2,2,i); output2(:,:,i) = kernel0({dx0; dy0}, kernType(i), bandW2, 1);end

close all;

1/3: Kernel as PDF Verification

% To be a valid Probability Density Function, the kernel must have all% positive values and the area (or volume) under the kernel must add up to% 1. NOTE: In all calculations, the results calculate the values in this% order of kernel type --> [rectangular, triangular, Gaussian, Epanechnikov]

1-Dimensional

% First the easy part, do any of the four kernels have any negative values?anyNeg1 = any(any(output1 < 0) < 0)% nope, none of the four kernels have negative values.

% now, calculate the area under each kernel using zero order interpolationarea1 = sum(output1*0.05)

% just for kicks we see that we get the same answer with 1st order% interpolationarea1 = trapz(output1*0.05)

% Let's find the mean value of each kernelmean1 = sum([dx0; dx0; dx0; dx0]' .* output1 * 0.05)

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

3 of 33 4/23/2009 12:25 PM

Page 4: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

% They are all tiny numbers, quite close to zero in fact. This is a good% thing.

% Let's find the variance for each kernelvar1 = sum([dx0; dx0; dx0; dx0]'.^2 .* output1 * 0.05)% the Gaussian variance comes out to 1, which was the bandwidth that we% gave it. The others are less than one, but we can't interpret these since% they're not Gaussian.

anyNeg1 =

0

area1 =

1.0250 1.0000 0.9999 0.9994

area1 =

1.0250 1.0000 0.9999 0.9994

mean1 =

1.0e-16 *

0.4163 -0.0997 0.0553 0.0217

var1 =

0.3587 0.1662 0.9990 0.1994

2-Dimensional

% check for any negative valuesanyNeg2 = any(any(any(output2 < 0) < 0) < 0)%

% calculate the volumesarea2 = sum(sum(output2 * 0.05.^2))% all of the areas are very close to 1, wonderful!

% create a variable grids which is a 4-layer position grid for the four% kernelsgrid2 = dx0'*dy0;grids = cat(3, grid2, grid2, grid2, grid2);

%calculate the means and variancesmean2 = sum(sum(grids .* output2 * 0.05^2))var2 = sum(sum(grids.^2 .* output2 * 0.05^2))% the mean for all of them is zero! The variance for the Gaussian is 1, all% other variances are smaller.

anyNeg2 =

0

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

4 of 33 4/23/2009 12:25 PM

Page 5: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

area2(:,:,1) =

1.0506

area2(:,:,2) =

1.0000

area2(:,:,3) =

0.9999

area2(:,:,4) =

0.9988

mean2(:,:,1) =

0

mean2(:,:,2) =

0

mean2(:,:,3) =

0

mean2(:,:,4) =

0

var2(:,:,1) =

0.1287

var2(:,:,2) =

0.0276

var2(:,:,3) =

0.9979

var2(:,:,4) =

0.0398

1/4: Scaling Kernels, 1-D Gaussian PDF Verification 5/5

% Rescale the kerlnels to have different bandwidths and recalculate

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

5 of 33 4/23/2009 12:25 PM

Page 6: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

% everything we've done alreadybandW1_4 = [1.5 0.5];

% display the two kernels of different bandwidths in separate windowsfigure(1)output1_4(:,1) = kernel0({dx0}, 3, bandW1_4(1), 1);figure(2)output1_4(:,2) = kernel0({dx0}, 3, bandW1_4(2), 1);

% First the easy part, do either of the kernels have any negative values?anyNeg1_4 = any(any(output1_4 < 0) < 0)% nope, none of the four kernels have negative values.

% now, calculate the area under each kernel using zero order interpolationarea1_4 = sum(output1_4*0.05)% The area is equal to 1 for both.

% Let's find the mean value of each kernelmean1_4 = sum([dx0; dx0]' .* output1_4 * 0.05)% They are both tiny numbers, quite close to zero in fact. This is a good% thing.

% Let's find the variance for each kernelvar1_4 = sum([dx0; dx0]'.^2 .* output1_4 * 0.05)% The first Gaussian variance comes out to 2.1020, the square root of that% is 1.45, which is pretty close to the bandwidth of 1.5 that we gave the% original function. The others are less than one. The second variance is% 0.25, the square root of which is 0.5, which was the bandwidth we gave% it. Bandwidth equals standard deviation.

anyNeg1_4 =

0

area1_4 =

0.9927 1.0000

mean1_4 =

1.0e-16 *

0.4749 -0.1587

var1_4 =

2.1020 0.2500

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

6 of 33 4/23/2009 12:25 PM

Page 7: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

1/5: Scaling 2-D Kernels 5/5

% Create kernels with alternate bandwidth and various typesdx0= -4:0.05:4;

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

7 of 33 4/23/2009 12:25 PM

Page 8: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

dy0= -4:0.05:4;bandW2_5 = [0.5 2];kernType = [0 1 3 5];

% display the four kernels of different types in one figurefor i = 1:4 subplot(2,2,i) output2_5(:,:,i) = kernel0({dx0; dy0}, kernType(i), bandW2_5, 1);end

close all;

1/6: Recentering 1-D Kernel Locations 4/5... comment on-why the shift

may be useful

% Make a Gaussian kernel that is offset to the right by 2kGaus1new = kernel0({dx0-2}, 3, bandW1, 0);plot(dx0,kGaus1new,'.');

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

8 of 33 4/23/2009 12:25 PM

Page 9: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

1/7: Recentering 2-D Kernel Locations 5/5

% Plot a Gaussian kernel centered on the location xy = [2 2]. Note the odd% scale direction for the y-axis.figure(1)xy = [2 2];kGaus2new = kernel0({dx0 - xy(1); dy0 - xy(2)}, 3, bandW2, 0);imagesc(dx0, dy0, flipud(kGaus2new));axis square;colorbar;title('2D Gaussian Kernel (bandwidths: 1,1)');

% Plot a triangular kernel centered on the location xy = [-1 3]. Not again% the odd scale direction for the y-axisfigure(2)xy = [-1 3];kGaus2new = kernel0({dx0 - xy(1); dy0 - xy(2)}, 2, bandW2, 0);imagesc(dx0, dy0, flipud(kGaus2new));axis square;colorbar;title('2D triangular Kernel (bandwidths: 1,1)');

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

9 of 33 4/23/2009 12:25 PM

Page 10: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

close all;

Preliminaries #2

clear; clc;

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

10 of 33 4/23/2009 12:25 PM

Page 11: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

m1 = 30; s1 = 10; m2 = 60; s2 = 10;randn('state', 345);xEv = [normrnd(m1, s1, 50, 1); normrnd(m2, s2, 50, 1)];nBins = 25;univstats(xEv,1,[0 2 nBins]);hold on;plot(xEv,zeros(100,1),'*');

# of data used 100Mean 46.5903Std deviation 17.6666Minimum 7.9586Lower quartile 34.7585Median 45.2884Upper quartile 60.8633Maximum 81.2099 Finished UNIVSTATS: Version #1

2/1: Plotting Kernels 5/5

kernType = 3; % Gaussian kernelx30 = 30;x60 = 60;x = 0 : 0.5 : 100;dx30 = abs(x-x30);dx60 = abs(x-x60);bandW = 10;fx30 = kernel0({dx30},kernType,bandW,0);fx60 = kernel0({dx60},kernType,bandW,0);plot(x,fx30,'.',x,fx60,'+');% This shows the two original PDFs that were used to generate the dataset.

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

11 of 33 4/23/2009 12:25 PM

Page 12: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

% Each of these PDFs have an area of 1, so if we combine them they won't be% a proper PDF unless we scale them as well.

2/2: Plotting a Summed Kernel 5/5

f = fx30 + fx60;% f isn't a proper PDF though, it's too big. Let's scale it.fcorr = f / 2; % much better!plot(x,fcorr,'r^');legend('data histogram', 'data points', 'kernel30', 'kernel60', ... 'combined scaled kernel')legend('Location', 'BestOutside')hold off;

% Check if fcorr is a proper PDFarea = sum(fcorr*0.5)% This density is a proper PDF, because the area is 1

area =

0.9994

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

12 of 33 4/23/2009 12:25 PM

Page 13: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

2/3: Plotting the 1-D Gaussian Kernel Density Estimate 5/5

bandW = 2;kernType = 3;f = kerneldensity(xEv, 1, [], {x}, kernType, bandW, 1, 0);

univstats(xEv,1,[0 2 nBins]);hold on;plot(x,f,'ro')hold off;

# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 1Output density normalized to a unit integral Finished KERNELDENSITY: Version #1# of data used 100Mean 46.5903Std deviation 17.6666

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

13 of 33 4/23/2009 12:25 PM

Page 14: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Minimum 7.9586Lower quartile 34.7585Median 45.2884Upper quartile 60.8633Maximum 81.2099 Finished UNIVSTATS: Version #1

2/4: Experimenting with more Kernels 5/5

kernType = [0 1 3 5]; % do four kinds of kernelsbandW = [2 3 5 4]; %make them various bandwidths

for i = 1:4 figure(i); output1(:,i) = kerneldensity(xEv, 1, [], {x}, kernType(i), bandW(i), 1, 3);end% The bandwidth and kernel type both have a major effect on the smoothness% of the plot. A Gaussian kernel, being non-compact, in general gives the% smoothest graph at the cost of losing detail. The rectangular kernel% gives the most pointy results. The others are more in the middle, with% the triangular a little less pointy than the rectangular, and the% Epanechnikov is even less pointy, closer to the Gaussian. The smoother% the kernel, the smoother the final PDF, but you might lose out on some% detail. If you make your kernel narrow and pointy, you might miss out on% some of the macro-structure of your data. It's best to have some physics% justification for your kernel type and bandwidth.

# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

14 of 33 4/23/2009 12:25 PM

Page 15: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 1Output density normalized to a unit integral Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 1Output density normalized to a unit integral Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.99929Output density normalized to a unit integral Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

15 of 33 4/23/2009 12:25 PM

Page 16: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Computing integral of estimated density... Integral of estimated discrete density = 0.99998Output density normalized to a unit integral Finished KERNELDENSITY: Version #1

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

16 of 33 4/23/2009 12:25 PM

Page 17: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

close all;

Preliminaries #3

clear; clc;

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

17 of 33 4/23/2009 12:25 PM

Page 18: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

load pointData.mat

% the area is 100x100, and there are 100 points in each one, so the lambda% is equal to 0.01 (assuming a 1x1 unit area) for all three data sets. The% lambda does not contain any information on the spatial distribution of% the three point patterns though, since all the patterns have the same% lambda but very different distributions.

2/1: 2-D Kernel Density Estimation 5/5

% plot the data setplot(pointsRand(:,1),pointsRand(:,2),'*'); axis([0 100 0 100]);axis square;

now make a 2-D Kernel Density estimation

x = 0:100;y = 0:100;kernType = 3;bandW = [3 3];figure(1)f = kerneldensity(pointsRand,[1 2],[],{x,y},kernType,bandW,1,2);colorbar;% The pattern looks fairly random, with a few clusters and a few sparse% areas. This is reflected by the colors of the density estimation too,% with some regions of dark blue and some regions of bright red. The% intensity ranges from 0 to 0.0005.

# of rows in DataIn = 100

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

18 of 33 4/23/2009 12:25 PM

Page 19: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.96629Output density normalized to a unit integral Irregular rasterAxes limits-0.5 100.5 -0.5 100.5 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1

2/2: Other Point Patterns 5/5

figure(2)f = kerneldensity(pointsClus,[1 2],[],{x,y},kernType,bandW,1,2);colorbar;% This data has clusters of points, where most of the area is dark blue%representing low density, with small regions of extremeley dense bright% red clusters. These dense clusters reach higher density estimation

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

19 of 33 4/23/2009 12:25 PM

Page 20: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

% values, up to 0.0025.

figure(3)f = kerneldensity(pointsStrat,[1 2],[],{x,y},kernType,bandW,1,2);colorbar;% This data is mostly regularly distributed, so most of the density is in% the middle range of light blue. There is only one fairly minor cluster,% so the peak density only reaches a value of 0.00035

# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.97524Output density normalized to a unit integral Irregular rasterAxes limits-0.5 100.5 -0.5 100.5 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.97419Output density normalized to a unit integral Irregular rasterAxes limits-0.5 100.5 -0.5 100.5 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

20 of 33 4/23/2009 12:25 PM

Page 21: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

close all;

3/3: Play with many Kernel Types and properties 5/5

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

21 of 33 4/23/2009 12:25 PM

Page 22: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

% different discretization for the non-rectangular kernelsxd = 0:0.5:100;yd = 0:0.5:100;

% combine all the data into a single data structuredata = cat(3,pointsRand, pointsClus, pointsStrat);

for i = 1:3 figure(4*i-3)

kernType = 0; % rectangular kernel bandW = [3 3]; f = kerneldensity(data(:,:,i),[1 2],[],{x,y},kernType,bandW,1,2); colorbar;

figure(4*i-2) kernType = 1; % triangular kernel bandW = [10 10]; f = kerneldensity(data(:,:,i),[1 2],[],{xd,yd},kernType,bandW,1,2); colorbar;

figure(4*i-1) kernType = 3; % gaussian kernel bandW = [1 8]; f = kerneldensity(data(:,:,i),[1 2],[],{xd,yd},kernType,bandW,1,2); colorbar;

figure(4*i) kernType = 5; % Epanechnikov bandW = [10 5]; f = kerneldensity(data(:,:,i),[1 2],[],{xd,yd},kernType,bandW,1,2); colorbar;end

% So many choices!!! It takes a lot of artistic "feel" as well as cold% science to choose the right kernel type, bandwidth size, and bandwidth% dimensions ratio to choose something that makes physical sense as well as% containing the right amount of detail (not too smooth or too rough). It's% something that you definitely would improve on with the more experience% you have. And there may be times when you want employ assymetrical% kernels, such as if you're modeling a process where there is wind blowing% pollen or ash, or water currents pushing particulate matter through% rivers or oceans.

# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 1.3319Output density normalized to a unit integral Irregular rasterAxes limits

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

22 of 33 4/23/2009 12:25 PM

Page 23: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

-0.5 100.5 -0.5 100.5 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.94987Output density normalized to a unit integral Irregular rasterAxes limits-0.25 100.25 -0.25 100.25 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.94236Output density normalized to a unit integral Irregular rasterAxes limits-0.25 100.25 -0.25 100.25 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

23 of 33 4/23/2009 12:25 PM

Page 24: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.95888Output density normalized to a unit integral Irregular rasterAxes limits-0.25 100.25 -0.25 100.25 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.99Output density normalized to a unit integral Irregular rasterAxes limits-0.5 100.5 -0.5 100.5 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.95786Output density normalized to a unit integral Irregular rasterAxes limits-0.25 100.25 -0.25 100.25 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

24 of 33 4/23/2009 12:25 PM

Page 25: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.93689Output density normalized to a unit integral Irregular rasterAxes limits-0.25 100.25 -0.25 100.25 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.96927Output density normalized to a unit integral Irregular rasterAxes limits-0.25 100.25 -0.25 100.25 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 1.3504Output density normalized to a unit integral

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

25 of 33 4/23/2009 12:25 PM

Page 26: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Irregular rasterAxes limits-0.5 100.5 -0.5 100.5 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.95043Output density normalized to a unit integral Irregular rasterAxes limits-0.25 100.25 -0.25 100.25 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.94056Output density normalized to a unit integral Irregular rasterAxes limits-0.25 100.25 -0.25 100.25 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1# of rows in DataIn = 100# of data actually used = 100Computing kernel for datum #10Computing kernel for datum #20Computing kernel for datum #30Computing kernel for datum #40Computing kernel for datum #50Computing kernel for datum #60Computing kernel for datum #70

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

26 of 33 4/23/2009 12:25 PM

Page 27: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Computing kernel for datum #80Computing kernel for datum #90Computing kernel for datum #100 Computing integral of estimated density... Integral of estimated discrete density = 0.96181Output density normalized to a unit integral Irregular rasterAxes limits-0.25 100.25 -0.25 100.25 Finished RASTERMAP: Version #1 Finished KERNELDENSITY: Version #1

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

27 of 33 4/23/2009 12:25 PM

Page 28: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

28 of 33 4/23/2009 12:25 PM

Page 29: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

29 of 33 4/23/2009 12:25 PM

Page 30: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

30 of 33 4/23/2009 12:25 PM

Page 31: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

31 of 33 4/23/2009 12:25 PM

Page 32: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

32 of 33 4/23/2009 12:25 PM

Page 33: Solutions for Geog 210C Labchris/Medrano_GEO 210C/GEO 210C...Solutions for Geog 210C Lab Assignment #1 - 68/70 STUDENT NAME: F. Antonio Medrano DATE COMPLETED: Contents Instructions

close all

Published with MATLAB® 7.4

Solutions for Geog 210C Lab Assignment #1 file:///C:/Documents%20and%20Settings/Micah/My%20Documents/Doc...

33 of 33 4/23/2009 12:25 PM