Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

B. Mathematical Formulas > Gaussian Function

Gaussian Function

The Gaussian function is the probability density function of the normal curve. It is used in this book as a weighting function for weighted k-nearest neighbors, since it starts high and falls off quickly but never reaches 0.

The formula for a Gaussian with a variance of σis shown in Figure B-9.

Gaussian function

Figure B-9. Gaussian function

This can be implemented as a two-line function directly translating the formula:

import math
def gaussian(dist,sigma=10.0):
  exp=math.e**(-dist**2/(2*sigma**2))
  return (1/(sigma*(2*math.pi)**.5))*exp

In Chapter 8, the Gaussian function is given as a possible weighting function for building a numerical predictor.


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint