Get (Ebook) Python for Probability, Statistics, and Machine Learning by José Unpingco ISBN 9783030185442, 3030185443 PDF ebook with Full Chapters Now
Get (Ebook) Python for Probability, Statistics, and Machine Learning by José Unpingco ISBN 9783030185442, 3030185443 PDF ebook with Full Chapters Now
com
https://ebooknice.com/product/python-for-probability-
statistics-and-machine-learning-10421734
DOWLOAD EBOOK
ebooknice.com
ebooknice.com
ebooknice.com
ebooknice.com
(Ebook) SAT II Success MATH 1C and 2C 2002 (Peterson's SAT
II Success) by Peterson's ISBN 9780768906677, 0768906679
https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018
ebooknice.com
ebooknice.com
ebooknice.com
https://ebooknice.com/product/probability-for-machine-learning-
discover-how-to-harness-uncertainty-with-python-23571864
ebooknice.com
Python for
Probability,
Statistics, and
Machine Learning
Second Edition
Python for Probability, Statistics, and Machine
Learning
José Unpingco
123
José Unpingco
San Diego, CA, USA
This Springer imprint is published by the registered company Springer Nature Switzerland AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
To Irene, Nicholas, and Daniella, for all
their patient support.
Preface to the Second Edition
This second edition is updated for Python version 3.6+. Furthermore, many existing
sections have been revised for clarity based on feedback from the first version. The
book is now over thirty percent larger than the original with new material about
important probability distributions, including key derivations and illustrative code
samples. Additional important statistical tests are included in the statistics chapter
including the Fisher Exact test and the Mann–Whitney–Wilcoxon Test. A new
section on survival analysis has been included. The most significant addition is the
section on deep learning for image processing with a detailed discussion of gradient
descent methods that underpin all deep learning work. There is also substan-
tial discussion regarding generalized linear models. As before, there are more
Programming Tips that illustrate effective Python modules and methods for scientific
programming and machine learning. There are 445 run-able code blocks that have
been tested for accuracy so you can try these out for yourself in your own codes.
Over 158 graphical visualizations (almost all generated using Python) illustrate the
concepts that are developed both in code and in mathematics. We also discuss and use
key Python modules such as NumPy, Scikit-learn, SymPy, SciPy, lifelines, CVXPY,
Theano, Matplotlib, Pandas, TensorFlow, StatsModels, and Keras.
As with the first edition, all of the key concepts are developed mathematically
and are reproducible in Python, to provide the reader with multiple perspectives on
the material. As before, this book is not designed to be exhaustive and reflects the
author’s eclectic industrial background. The focus remains on concepts and fun-
damentals for day-to-day work using Python in the most expressive way possible.
vii
viii Preface to the Second Edition
Acknowledgements
I would like to acknowledge the help of Brian Granger and Fernando Perez, two
of the originators of the Jupyter Notebook, for all their great work, as well as the
Python community as a whole, for all their contributions that made this book pos-
sible. Hans Petter Langtangen is the author of the Doconce [1] document preparation
system that was used to write this text. Thanks to Geoffrey Poore [2] for his work
with PythonTeX and LATEX, both key technologies used to produce this book.
References
This book will teach you the fundamental concepts that underpin probability and
statistics and illustrate how they relate to machine learning via the Python language
and its powerful extensions. This is not a good first book in any of these topics
because we assume that you already had a decent undergraduate-level introduction
to probability and statistics. Furthermore, we also assume that you have a good
grasp of the basic mechanics of the Python language itself. Having said that, this
book is appropriate if you have this basic background and want to learn how to use
the scientific Python toolchain to investigate these topics. On the other hand, if you
are comfortable with Python, perhaps through working in another scientific field,
then this book will teach you the fundamentals of probability and statistics and how
to use these ideas to interpret machine learning methods. Likewise, if you are a
practicing engineer using a commercial package (e.g., MATLAB, IDL), then you
will learn how to effectively use the scientific Python toolchain by reviewing
concepts you are already familiar with.
The most important feature of this book is that everything in it is reproducible
using Python. Specifically, all of the code, all of the figures, and (most of) the text is
available in the downloadable supplementary materials that correspond to this book
as IPython Notebooks. IPython Notebooks are live interactive documents that allow
you to change parameters, recompute plots, and generally tinker with all of the
ideas and code in this book. I urge you to download these IPython Notebooks and
follow along with the text to experiment with the topics covered. I guarantee doing
this will boost your understanding because the IPython Notebooks allow for
interactive widgets, animations, and other intuition-building features that help make
many of these abstract ideas concrete. As an open-source project, the entire sci-
entific Python toolchain, including the IPython Notebook, is freely available.
Having taught this material for many years, I am convinced that the only way to
learn is to experiment as you go. The text provides instructions on how to get
started installing and configuring your scientific Python environment.
ix
x Preface to the First Edition
This book is not designed to be exhaustive and reflects the author’s eclectic
background in industry. The focus is on fundamentals and intuitions for day-to-day
work, especially when you must explain the results of your methods to a non-
technical audience. We have tried to use the Python language in the most expressive
way possible while encouraging good Python-coding practices.
Acknowledgements
I would like to acknowledge the help of Brian Granger and Fernando Perez, two
of the originators of the Jupyter/IPython Notebook, for all their great work, as well
as the Python community as a whole, for all their contributions that made this book
possible. Additionally, I would also like to thank Juan Carlos Chavez for his
thoughtful review. Hans Petter Langtangen is the author of the Doconce [14]
document preparation system that was used to write this text. Thanks to Geoffrey
Poore [25] for his work with PythonTeX and LATEX.
xi
Visit https://ebooknice.com to
discover a wide range of
eBooks across various genres.
Enjoy exclusive deals and
discounts to enhance your
reading experience. Start your
digital reading journey today!
xii Contents
3 Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
3.2 Python Modules for Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . 124
3.2.1 Scipy Statistics Module . . . . . . . . . . . . . . . . . . . . . . . . 124
3.2.2 Sympy Statistics Module . . . . . . . . . . . . . . . . . . . . . . . 125
3.2.3 Other Python Modules for Statistics . . . . . . . . . . . . . . . 126
3.3 Types of Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
3.3.1 Almost Sure Convergence . . . . . . . . . . . . . . . . . . . . . . 126
3.3.2 Convergence in Probability . . . . . . . . . . . . . . . . . . . . . . 129
3.3.3 Convergence in Distribution . . . . . . . . . . . . . . . . . . . . . 131
3.3.4 Limit Theorems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
3.4 Estimation Using Maximum Likelihood . . . . . . . . . . . . . . . . . . . 133
3.4.1 Setting Up the Coin-Flipping Experiment . . . . . . . . . . . 135
3.4.2 Delta Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
3.5 Hypothesis Testing and P-Values . . . . . . . . . . . . . . . . . . . . . . . . 147
3.5.1 Back to the Coin-Flipping Example . . . . . . . . . . . . . . . . 149
3.5.2 Receiver Operating Characteristic . . . . . . . . . . . . . . . . . 152
3.5.3 P-Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
3.5.4 Test Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
3.5.5 Testing Multiple Hypotheses . . . . . . . . . . . . . . . . . . . . . 163
3.5.6 Fisher Exact Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
3.6 Confidence Intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
3.7 Linear Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 169
3.7.1 Extensions to Multiple Covariates . . . . . . . . . . . . . . . . . 178
3.8 Maximum A-Posteriori . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 183
3.9 Robust Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
3.10 Bootstrapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
3.10.1 Parametric Bootstrap . . . . . . . . . . . . . . . . . . . . . . . . . . 200
3.11 Gauss–Markov . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
3.12 Nonparametric Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
3.12.1 Kernel Density Estimation . . . . . . . . . . . . . . . . . . . . . . 205
3.12.2 Kernel Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
3.12.3 Nonparametric Regression Estimators . . . . . . . . . . . . . . 213
3.12.4 Nearest Neighbors Regression . . . . . . . . . . . . . . . . . . . . 214
3.12.5 Kernel Regression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
3.12.6 Curse of Dimensionality . . . . . . . . . . . . . . . . . . . . . . . . 219
3.12.7 Nonparametric Tests . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
3.13 Survival Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 228
3.13.1 Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
xiv Contents
of programming the virtual machine and these key numerical optimizations that are
crucial for scientific work?
The balance comes from Python’s native ability to bind to compiled Fortran and C
libraries. This means that you can send intensive computations to compiled libraries
directly from the interpreter. This approach has two primary advantages. First, it gives
you the fun of programming in Python, with its expressive syntax and lack of visual
clutter. This is a particular boon to scientists who typically want to use software as
a tool as opposed to developing software as a product. The second advantage is that
you can mix-and-match different compiled libraries from diverse research areas that
were not otherwise designed to work together. This works because Python makes
it easy to allocate and fill memory in the interpreter, pass it as input to compiled
libraries, and then recover the output back in the interpreter.
Moreover, Python provides a multiplatform solution for scientific codes. As an
open-source project, Python itself is available anywhere you can build it, even though
it typically comes standard nowadays, as part of many operating systems. This means
that once you have written your code in Python, you can just transfer the script to
another platform and run it, as long as the third-party compiled libraries are also
available there. What if the compiled libraries are absent? Building and configuring
compiled libraries across multiple systems used to be a painstaking job, but as scien-
tific Python has matured, a wide range of libraries have now become available across
all of the major platforms (i.e., Windows, MacOS, Linux, Unix) as prepackaged
distributions.
Finally, scientific Python facilitates maintainability of scientific codes because
Python syntax is clean, free of semi-colon litter and other visual distractions that
makes code hard to read and easy to obfuscate. Python has many built-in testing,
documentation, and development tools that ease maintenance. Scientific codes are
usually written by scientists unschooled in software development, so having solid
software development tools built into the language itself is a particular boon.
The easiest way to get started is to download the freely available Anaconda distribu-
tion provided by Anaconda (anaconda.com), which is available for all of the major
platforms. On Linux, even though most of the toolchain is available via the built-in
Linux package manager, it is still better to install the Anaconda distribution because
it provides its own powerful package manager (i.e., conda) that can keep track of
changes in the software dependencies of the packages that it supports. Note that if
you do not have administrator privileges, there is also a corresponding Miniconda
distribution that does not require these privileges. Regardless of your platform, we
recommend Python version 3.6 or better.
You may have encountered other Python variants on the web, such as IronPython
(Python implemented in C#) and Jython (Python implemented in Java). In this text,
we focus on the C implementation of Python (i.e., known as CPython), which is, by
1.1 Installation and Setup 3
far, the most popular implementation. These other Python variants permit specialized,
native interaction with libraries in C# or Java (respectively), which is still possible
(but clunky) using CPython. Even more Python variants exist that implement the low-
level machinery of Python differently for various reasons, beyond interacting with
native libraries in other languages. Most notable of these is Pypy that implements a
just-in-time compiler (JIT) and other powerful optimizations that can substantially
speed up pure Python codes. The downside of Pypy is that its coverage of some
popular scientific modules (e.g., Matplotlib, Scipy) is limited or nonexistent which
means that you cannot use those modules in code meant for Pypy.
If you want to install a Python module that is not available via the conda manager,
the pip installer is available. This installer is the main one used outside of the
scientific computing community. The key difference between the two installer is that
conda implements a satisfiability solver that checks for conflicts in versions among
and between installed packages. This can result in conda decreasing versions of
certain packages to accommodate proposed package installation. The pip installer
does not check for such conflicts checks only if the proposed package already has its
dependencies installed and will install them if not or remove existing incompatible
modules. The following command line uses pip to install the given Python module,
Terminal> pip install package_name
The pip installer will download the package you want and its dependencies and
install them in the existing directory tree. This works beautifully in the case where
the package in question is pure-Python, without any system-specific dependencies.
Otherwise, this can be a real nightmare, especially on Windows, which lacks freely
available Fortran compilers. If the module in question is a C library, one way to cope
is to install the freely available Visual Studio Community Edition, which usually
has enough to compile many C-codes. This platform dependency is the problem
that conda was designed to solve by making the binary dependencies of the various
platforms available instead of attempting to compile them. On a Windows system,
if you installed Anaconda and registered it as the default Python installation (it asks
during the install process), then you can use the high-quality Python wheel files on
Christoph Gohlke’s laboratory site at the University of California, Irvine where he
kindly makes a long list of scientific modules available.1 Failing this, you can try
the conda-forge site, which is a community-powered repository of modules that
conda is capable of installing, but which are not formally supported by Anaconda.
Note that conda-forge allows you to share scientific Python configurations with
your remote colleagues using authentication so that you can be sure that you are
downloading and running code from users you trust.
Again, if you are on Windows, and none of the above works, then you may wan-
t to consider installing a full virtual machine solution, as provided by VMWare’s
Player or Oracle’s VirtualBox (both freely available under liberal terms), or with
1 Wheel files are a Python distribution format that you download and install using pip as in pip
install file.whl. Christoph names files according to Python version (e.g., cp27 means Python
2.7) and chipset (e.g., amd32 vs. Intel win32).
4 1 Getting Started with Scientific Python
the Windows subsystem for Linux (WSL) that is built into Windows 10. Using ei-
ther of these, you can set up a Linux machine running on top of Windows, which
should cure these problems entirely! The great part of this approach is that you
can share directories between the virtual machine and the Windows system so that
you don’t have to maintain duplicate data files. Anaconda Linux images are also
available on the cloud by Platform as a Service (PaaS) providers like Amazon Web
Services and Microsoft Azure. Note that for the vast majority of users, especially
newcomers to Python, the Anaconda distribution should be more than enough on
any platform. It is just worth highlighting the Windows-specific issues and associat-
ed workarounds early on. Note that there are other well-maintained scientific Python
Windows installers like WinPython and PythonXY. These provide the spyder in-
tegrated development environment, which is very MATLAB-like environment for
transitioning MATLAB users.
1.2 Numpy
As we touched upon earlier, to use a compiled scientific library, the memory allocated
in the Python interpreter must somehow reach this library as input. Furthermore, the
output from these libraries must likewise return to the Python interpreter. This two-
way exchange of memory is essentially the core function of the Numpy (numerical
arrays in Python) module. Numpy is the de facto standard for numerical arrays in
Python. It arose as an effort by Travis Oliphant and others to unify the preexisting
numerical arrays in Python. In this section, we provide an overview and some tips
for using Numpy effectively, but for much more detail, Travis’ freely available book
[1] is a great place to start.
Numpy provides specification of byte-sized arrays in Python. For example, below
we create an array of three numbers, each of 4 bytes long (32-bits at 8-bits per byte)
as shown by the itemsize property. The first line imports Numpy as np, which is
the recommended convention. The next line creates an array of 32-bit floating-point
numbers. The itemize property shows the number of bytes per item.
>>> np.sin(np.array([1,2,3],dtype=np.float32) )
array([0.84147096, 0.9092974 , 0.14112 ], dtype=float32)
This computes the sine of the input array [1,2,3], using Numpy’s unary function,
np.sin. There is another sine function in the built-in math module, but the Numpy
version is faster because it does not require explicit looping (i.e., using a for loop)
over each of the elements in the array. That looping happens in the compiled np.sin
function itself. Otherwise, we would have to do looping explicitly as in the following:
>>> from math import sin
>>> [sin(i) for i in [1,2,3]] # list comprehension
[0.8414709848078965, 0.9092974268256817, 0.1411200080598672]
Numpy uses common-sense casting rules to resolve the output types. For example,
if the inputs had been an integer-type, the output would still have been a floating-
point type. In this example, we provided a Numpy array as input to the sine function.
We could have also used a plain Python list instead and Numpy would have built the
intermediate Numpy array (e.g., np.sin([1,1,1])). The Numpy documentation
provides a comprehensive (and very long) list of available ufuncs.
Numpy arrays come in many dimensions. For example, the following shows a
two-dimensional 2x3 array constructed from two conforming Python lists.
>>> x=np.array([ [1,2,3],[4,5,6] ])
>>> x.shape
(2, 3)
Note that Numpy is limited to 32 dimensions unless you build it for more.2 Numpy
arrays follow the usual Python slicing rules in multiple dimensions as shown below
where the : colon character selects all elements along a particular axis.
>>> x=np.array([ [1,2,3],[4,5,6] ])
>>> x[:,0] # 0th column
array([1, 4])
>>> x[:,1] # 1st column
array([2, 5])
>>> x[0,:] # 0th row
array([1, 2, 3])
>>> x[1,:] # 1st row
array([4, 5, 6])
You can also select subsections of arrays by using slicing as shown below
>>> x=np.array([ [1,2,3],[4,5,6] ])
>>> x
array([[1, 2, 3],
[4, 5, 6]])
This works because MATLAB arrays use pass-by-value semantics so that slice oper-
ations actually copy parts of the array as needed. By contrast, Numpy uses pass-by-
reference semantics so that slice operations are views into the array without implicit
copying. This is particularly helpful with large arrays that already strain available
memory. In Numpy terminology, slicing creates views (no copying) and advanced
indexing creates copies. Let’s start with advanced indexing.
If the indexing object (i.e., the item between the brackets) is a non-tuple sequence
object, another Numpy array (of type integer or boolean), or a tuple with at least
one sequence object or Numpy array, then indexing creates copies. For the above
example, to accomplish the same array extension in Numpy, you have to do something
like the following:
>>> x = np.ones((3,3))
>>> x
array([[1., 1., 1.],
[1., 1., 1.],
1.2 Numpy 7
Because of advanced indexing, the variable y has its own memory because the rele-
vant parts of x were copied. To prove it, we assign a new element to x and see that
y is not updated.
>>> x[0,0]=999 # change element in x
>>> x # changed
array([[999., 1., 1.],
[ 1., 1., 1.],
[ 1., 1., 1.]])
>>> y # not changed!
array([[1., 1., 1., 1.],
[1., 1., 1., 1.],
[1., 1., 1., 1.]])
However, if we start over and construct y by slicing (which makes it a view) as shown
below, then the change we made does affect y because a view is just a window into
the same memory.
>>> x = np.ones((3,3))
>>> y = x[:2,:2] # view of upper left piece
>>> x[0,0] = 999 # change value
>>> x
array([[999., 1., 1.],
[ 1., 1., 1.],
[ 1., 1., 1.]])
>>> y
array([[999., 1.],
[ 1., 1.]])
Note that if you want to explicitly force a copy without any indexing tricks, you
can do y=x.copy(). The code below works through another example of advanced
indexing versus slicing.
Bear in mind that as_strided does not check that you stay within memory block
bounds. So, if the size of the target matrix is not filled by the available data, the
remaining elements will come from whatever bytes are at that memory location. In
other words, there is no default filling by zeros or other strategy that defends memory
block bounds. One defense is to explicitly control the dimensions as in the following
code:
Matrices in Numpy are similar to Numpy arrays but they can only have two dimen-
sions. They implement row–column matrix multiplication as opposed to element-
wise multiplication. If you have two matrices you want to multiply, you can either
create them directly or convert them from Numpy arrays. For example, the following
shows how to create two matrices and multiply them.
>>> A=np.array([[1,2,3],[4,5,6],[7,8,9]])
>>> x=np.array([[1],[0],[0]])
>>> A.dot(x)
array([[1],
[4],
[7]])
Numpy arrays support element-wise multiplication, not row–column multiplication.
You must use Numpy matrices for this kind of multiplication unless use the inner
product np.dot, which also works in multiple dimensions (see np.tensordot for
more general dot products). Note that Python 3.x has a new @ notation for matrix
multiplication so we can re-do the last calculation as follows:
>>> A @ x
array([[1],
[4],
[7]])
It is unnecessary to cast all multiplicands to matrices for multiplication. In the
next example, everything until last line is a Numpy array and thereafter we cast the
array as a matrix with np.matrix which then uses row–column multiplication. Note
that it is unnecessary to cast the x variable as a matrix because the left-to-right order
of the evaluation takes care of that automatically. If we need to use A as a matrix
elsewhere in the code then we should bind it to another variable instead of re-casting
it every time. If you find yourself casting back and forth for large arrays, passing the
copy=False flag to matrix avoids the expense of making a copy.
>>> A=np.ones((3,3))
>>> type(A) # array not matrix
<class 'numpy.ndarray'>
>>> x=np.ones((3,1)) # array not matrix
>>> A*x
array([[1., 1., 1.],
[1., 1., 1.],
[1., 1., 1.]])
>>> np.matrix(A)*x # row-column multiplication
matrix([[3.],
[3.],
[3.]])
>>> X,Y=np.meshgrid(np.arange(2),np.arange(2))
>>> X
array([[0, 1],
[0, 1]])
>>> Y
array([[0, 0],
[1, 1]])
Numpy’s meshgrid creates two-dimensional grids. The X and Y arrays have cor-
responding entries match the coordinates of the vertices of the unit square (e.g.,
(0, 0), (0, 1), (1, 0), (1, 1)). To add the x and y-coordinates, we could use X and Y
as in X+Y shown below, The output is the sum of the vertex coordinates of the unit
square.
>>> X+Y
array([[0, 1],
[1, 2]])
Because the two arrays have compatible shapes, they can be added together element-
wise. It turns out we can skip a step here and not bother with meshgrid to implicitly
obtain the vertex coordinates by using broadcasting as shown below
>>> x = np.array([0,1])
>>> y = np.array([0,1])
>>> x
array([0, 1])
>>> y
array([0, 1])
>>> x + y[:,None] # add broadcast dimension
array([[0, 1],
[1, 2]])
>>> X+Y
array([[0, 1],
[1, 2]])
On line 7 the None Python singleton tells Numpy to make copies of y along this
dimension to create a conformable calculation. Note that np.newaxis can be used
instead of None to be more explicit. The following lines show that we obtain the
same output as when we used the X+Y Numpy arrays. Note that without broadcasting
x+y=array([0, 2]) which is not what we are trying to compute. Let’s continue
with a more complicated example where we have differing array shapes.
>>> x = np.array([0,1])
>>> y = np.array([0,1,2])
>>> X,Y = np.meshgrid(x,y)
>>> X
array([[0, 1],
12 1 Getting Started with Scientific Python
[0, 1],
[0, 1]])
>>> Y
array([[0, 0],
[1, 1],
[2, 2]])
>>> X+Y
array([[0, 1],
[1, 2],
[2, 3]])
>>> x+y[:,None] # same as with meshgrid
array([[0, 1],
[1, 2],
[2, 3]])
In this example, the array shapes are different, so the addition of x and y is
not possible without Numpy broadcasting. The last line shows that broadcasting
generates the same output as using the compatible array generated by meshgrid.
This shows that broadcasting works with different array shapes. For the sake of
comparison, on line 3, meshgrid creates two conformable arrays, X and Y. On the
last line, x+y[:,None] produces the same output as X+Y without the meshgrid. We
can also put the None dimension on the x array as x[:,None]+y which would give
the transpose of the result.
Broadcasting works in multiple dimensions also. The output shown has shape
(4,3,2). On the last line, the x+y[:,None] produces a two-dimensional array
which is then broadcast against z[:,None,None], which duplicates itself along the
two added dimensions to accommodate the two-dimensional result on its left (i.e., x
+ y[:,None]). The caveat about broadcasting is that it can potentially create large,
memory-consuming, intermediate arrays. There are methods for controlling this by
re-using previously allocated memory but that is beyond our scope here. Formulas
in physics that evaluate functions on the vertices of high dimensional grids are great
use-cases for broadcasting.
>>> x = np.array([0,1])
>>> y = np.array([0,1,2])
>>> z = np.array([0,1,2,3])
>>> x+y[:,None]+z[:,None,None]
array([[[0, 1],
[1, 2],
[2, 3]],
[[1, 2],
[2, 3],
[3, 4]],
1.2 Numpy 13
[[2, 3],
[3, 4],
[4, 5]],
[[3, 4],
[4, 5],
[5, 6]]])
So, then, why is the output not 0.3? The issue is the floating-point representation of
the two numbers and the algorithm that adds them. To represent an integer in binary,
we just write it out in powers of 2. For example, 230 = (11100110)2 . Python can
do this conversion using string formatting,
>>> print('{0:b}'.format(230))
11100110
To add integers, we just add up the corresponding bits and fit them into the allowable
number of bits. Unless there is an overflow (the results cannot be represented with
that number of bits), then there is no problem. Representing floating point is trickier
because we have to represent these numbers as binary fractions. The IEEE 754
standard requires that floating-point numbers be represented as ±C × 2 E where C is
the significand (mantissa) and E is the exponent.
To represent a regular decimal fraction as binary fraction, we need to compute
the expansion of the fraction in the following form a1 /2 + a2 /22 + a3 /23 ... In other
words, we need to find the ai coefficients. We can do this using the same process we
would use for a decimal fraction: just keep dividing by the fractional powers of 1/2
and keep track of the whole and fractional parts. Python’s divmod function can do
most of the work for this. For example, to represent 0.125 as a binary fraction,
>>> a = 0.125
>>> divmod(a*2,1)
(0.0, 0.25)
The first item in the tuple is the quotient and the other is the remainder. If the quotient
was greater than 1, then the corresponding ai term is one and is zero otherwise. For
this example, we have a1 = 0. To get the next term in the expansion, we just keep
multiplying by 2 which moves us rightward along the expansion to ai+1 and so on.
Then,
>>> a = 0.125
>>> q,a = divmod(a*2,1)
>>> print (q,a)
0.0 0.25
>>> q,a = divmod(a*2,1)
>>> print (q,a)
0.0 0.5
>>> q,a = divmod(a*2,1)
>>> print (q,a)
1.0 0.0
The algorithm stops when the remainder term is zero. Thus, we have that 0.125 =
(0.001)2 . The specification requires that the leading term in the expansion be one.
Thus, we have 0.125 = (1.000) × 2−3 . This means the significand is 1 and the
exponent is -3.
Now, let’s get back to our main problem 0.1+0.2 by developing the representation
0.1 by coding up the individual steps above.
1.2 Numpy 15
>>> a = 0.1
>>> bits = []
>>> while a>0:
... q,a = divmod(a*2,1)
... bits.append(q)
...
>>> print (''.join(['%d'%i for i in bits]))
0001100110011001100110011001100110011001100110011001101
Note that the representation has an infinitely repeating pattern. This means that we
have (1.1001)2 × 2−4 . The IEEE standard does not have a way to represent infinitely
repeating sequences. Nonetheless, we can compute this,
∞
1 1 3
+ 4n =
24n−3 2 5
n=1
Thus, 0.1 ≈ 1.6 × 2−4 . Per the IEEE 754 standard, for float type, we have
24-bits for the significand and 23-bits for the fractional part. Because we can-
not represent the infinitely repeating sequence, we have to round off at 23-bits,
10011001100110011001101. Thus, whereas the significand’s representation used
to be 1.6, with this rounding, it is Now
>>> b = '10011001100110011001101'
>>> 1+sum([int(i)/(2**n) for n,i in enumerate(b,1)])
1.600000023841858
Now, the sum has to be scaled back to fit into the significand’s available bits so the
result is 1.00110011001100110011010 with exponent -2. Computing this in the
usual way as shown below gives the result.
>>> k='00110011001100110011010'
>>> print('%0.12f'%((1+sum([int(i)/(2**n)
... for n,i in enumerate(k,1)]))/2**2))
0.300000011921
The entire process proceeds the same for 64-bit floats. Python has a fractions
and decimal modules that allow more exact number representations. The decimal
module is particularly important for certain financial computations.
Round-off Error. Let’s consider the example of adding 100,000,000 and 10 in
32-bit floating point.
>>> print('{0:b}'.format(100000000))
101111101011110000100000000
1.01111101011110000100000000
+0.00000000000000000000001010
-------------------------------
1.01111101011110000100001010
Now, we have to round off because we only have 23 bits to the right of the decimal
point and obtain 1.0111110101111000010000, thus losing the trailing 10 bits.
This effectively makes the decimal 10 = (1010)2 we started out with become 8 =
(1000)2 . Thus, using Numpy again,
>>> print(format(np.float32(100000000) + np.float32(10),'10.3f'))
100000008.000
The problem here is that the order of magnitude between the two numbers was so
great that it resulted in loss in the significand’s bits as the smaller number was right-
shifted. When summing numbers like these, the Kahan summation algorithm (see
math.fsum()) can effectively manage these round-off errors.
Cancelation Error. Cancelation error (loss of significance) results when two nearly
equal floating-point numbers are subtracted. Let’s consider subtracting 0.1111112
and 0.1111111. As binary fractions, we have the following,
1.11000111000111001000101 E-4
-1.11000111000111000110111 E-4
---------------------------
0.00000000000000000011100
Exploring the Variety of Random
Documents with Different Content
being greatest among them, who can afford to eat [18]Rice all the
Year round. Kid and Fowl, they have a few, and were all the
domestick Animals I saw.
Remark 4. On the Negroes here, their Clothing, Customs and
Religion.
The Men are well-limbed, clean Fellows; flattish-nosed, and many
with Exomphalos’s; the Effect of bad Midwifry, or straining in their
Infancy to walk; for they are never taught, but creep upon a Matt on
all Fours, till they have Strength to erect themselves; and
notwithstanding this, are seldom distorted. These do not circumcise,
but the Slaves brought from the Northward are frequently so;
perhaps from bordering on Morocco.
The Women are not nigh so well shaped as the Men: Childing, and
their Breasts always pendulous, stretches them to so unseemly a
Length and Bigness, that some, like the Ægyptians, I believe, could
suckle over their Shoulders. Their being imployed in all Labour,
makes them robust; for such as are not Gromettas, work hard in
Tillage, make Palm-Oil, or spin Cotton; and when they are free from
such work, the idle Husbands put them upon breading and fetishing
out their Wool, they being prodigious proud and curious in this sort of
Ornament; and keep them every day, for many hours together, at it.
Their Houses are low, little Hutts, not quite so bad as many in
Yorkshire, built with wooden Stockades set in the ground, in a round
or square form, thatched with Straw; they are swept clean every day;
and for Furniture, have a Matt or two to lie down upon; two or three
earthen or wooden Dishes, and Stools, with a Spoon, all of their own
making. They are idle, principally from want of Arts and domestick
Employments: for as I observed, they are so cautious of planting too
much, and wasting their Labour, that they are really improvident;
smoaking all day in long Reed-Pipes together; unplagued with To-
morrow, or the Politicks of Europe.
Whole Towns shift their Habitations, either when they do not like
their Neighbours, or have more Conveniency somewhere else; soon
clearing Ground enough for what Building and Culture they purpose.
Seignior Joseph, a Christian Negro of this Place, has lately with his
People left a clean, well-built Town, and removed further up the
River. Their Huts are mostly orbicular, forming a spacious square
Area in the middle, and in this, the doors paved with Cockle-Shells;
two or three Crosses erected, and round about, Lime-trees, Papais,
Plantanes, Pine-apples, and a few Bee-hives; the latter made out of
pieces of old Trees, three foot long, hollowed and raised on two
Poles.
In the middle of the Area was a great Curiosity, a large Tree with
500 hanging Nests at least upon it; this is a small familiar Bird, that
builds thus about their Towns, upon the extreme slenderest Twigs,
hanging like Fruit, and declares the Wisdom of Instinct, since it’s
designed a Security for their Young, against Monkeys, Parrots,
Squirrels, &c. Creatures of Prey, whose Weight cannot there be
supported.
Anointing their Body and Limbs with Palm-Oil, is a daily Practice
with both Sexes; some use [19]Civet, but all cast a strong,
disagreeable Smell; this mending it much like as melted Tallow is by
a Perfumer’s Shop.
Palaavers are their Courts of Judicature, where the principal or
elderly Men amongst them meet in a Ring or under a Lodge, to settle
the Differences that arise amongst themselves, or with the Factories;
the frequentest are in relation to Trade. Each salutes the other at
meeting, by a Bend of the Elbow, and raising his Hand to his Face.
When they have heard what each Party has to say, they determine
by Vote, who has the Reason of the thing on their side, and so
punish, or acquit. For Fornication, the Party (whether Man or
Woman) is sold for a Slave. If a white Man lies with another’s Slave,
he is bound to redeem her at a current Price. On a Charge of
Murder, Adultery, or if there can be any other more heinous Crime
among them, the suspected Person must drink of a red Water his
Judges prepare; which is called, purging the Criminal: that is, if the
suspected be of ill Life, or had Envy to the deceased, so that the
Surmizes against him are strong, though they want positive
Evidence; they will give him so much of that Liquor as shall kill him;
but if inclined to spare him, they politickly give less, or make it
weaker, whereby his Innocence appears the better to the Friends
and Relations of the deceased.
Panyarring, is a Term for Man-stealing along the whole Coast:
Here it’s used also, for stealing any thing else; and by Custom (their
Law) every Man has a right to seize of another at any Conveniency,
so much as he can prove afterwards, at the Palaaver-Court, to have
been defrauded of, by any body in the same place he was cheated.
Dancing is the Diversion of their Evenings: Men and Women make
a Ring in an open part of the Town, and one at a time shews his Skill
in antick Motions and Gesticulations, yet with a great deal of Agility,
the Company making the Musick by clapping their hands together
during the time, helped by the louder noise of two or three Drums
made of a hollowed piece of Tree, and covered with Kid-Skin.
Sometimes they are all round in a Circle laughing, and with uncouth
Notes, blame or praise somebody in the Company.
During our stay at this Port, we paid a Visit to Seignior Joseph,
about nine miles up the River. The Reason of his leaving the other
Town, he told me was, the frequent Palaavers he was engaged in,
on account of Differences between his People and the Grimattoes,
and the great Expence he was at, in so near a Neighbourhood with
the English. He has been in England and Portugal; at the last place
he was baptized, and took in that christian Erudition that he
endeavours to propagate. He has built a little Oratory for his
People’s Devotions; erected a Cross; taught several of his Kindred
Letters, dispersing among them little Romish Prayer-Books, and
many of them are known by Christian Names. Those of the Country
not yet initiated, never have but one. Mousi, or Moses; Yarrat, and
Cambar, are very common Names to the Men; Baulee, and Kibullee,
to the Women. Others take the Cognomen from their Disposition;
Lion, Lamb, Bear, Hog, &c. like our Danish Ancestors. Seignior
Joseph, who is very communicative, tells me, to the extent of his
knowledge, the People are cleanly, of good Temper, and docible; all
wishing some Missionaries would think their Conversion and Wants
worth regarding: But the Poverty of their Country will probably keep
them a long time from that Benefit. There is no Invitation in a barren
Soil, scarce of Provisions and Necessaries, Danger of wild Beasts a
mile from Home (especially Wolves;) and about their Houses, Rats,
Snakes, Toads, Musquitoes, Centipes, Scorpions, Lizards, and
innumerable Swarms of Ants, a white, black, and red sort, that build
to 8 or 9 Foot high, dig up the Foundation of their Houses in two or
three Years, or turn a Chest of Cloaths to Dust (if not watched) in as
many Weeks. This Christian Negro, by the Advantage of Trade, has
in some measure removed the Wants of his own Family (his Towns;)
they are tolerably stocked with Guinea Hens, Fish, and Venison;
while the Country fifty miles off, he says, have little to feed on but
Honey, and Manyoco Root. He received us in a Europæan Dress
(Gown, Slippers, Cap, &c.) and sent his Canoos out to shew us the
Diversion of chasing the Manatea; they brought one ashore in two
hours time, and we had stewed, roast, and boiled, with a clean
Table-cloth, Knives and Forks, and Variety of Wines and strong Beer,
for our Entertainment. The Flesh of this Creature was white, and not
fishy; but very tough, and seasoned high (as are all their Dishes)
with Ochre, Malaguetta, and Bell-pepper.
His Kinswomen came into the Room after we had dined, and to
them other Neighbours, saluting those of their own Colour, one by
one, by making a Bend of their right Elbow, so that the Hand comes
nigh the Mouth; the other to whom she addresses, is in the same
Posture, and mixing their Thumbs and middle Fingers, they snap
them gently off, and retreat with a small Quaker-like Obeysance,
decently and without Hurry or Laugh. They shewed likewise much
good-nature towards one another, in dividing two or three Biskets,
and half a Pint of Citron Water (we brought) into twenty Parts, rather
than any one should miss a Taste. In conclusion, Seignior Joseph
saw us to the Boat, and took leave with the same Complaisance he
had treated us.
The Religion here, if it may be called such, is their Veneration to
Gregries: Every one keeps in his House, in his Canoo, or about his
Person, something that he highly reverences, and that he imagines
can, and does defend him from Miscarriage, in the nature our
Country-Folks do Charms, but with more Fear: And these things are
very various; either a cleaved piece of Wood, a Bundle of peculiar
little Sticks or Bones, a Monkey’s Skull, or the like. To these, every
Family has now and then a Feast, inviting one another; but of this
more, under the Word Fetish.
The GRAIN and MALAGUETTA Coasts.
We left Sierraleon and were joined by our Consort the Weymouth,
May 1, from Gambia; we found upon Conference, that both Ships
had like to have ended their Voyage at these first Ports: She had run
on a Sand in that River, wringing three Days and Nights in a Tide’s
way, with great difficulty getting off: We, at Sierraleon letting in Water
to the Ship one Evening, had forgot the Plug, till we had 5 or 6 Foot
Water in the Hold.
The Company’s Presents, we understood by them, were received
well there by the King of Barra, and he has given the Factors leave
to build a Fortification at Gilliflee, a Town commanded by a Woman,
about 15 Miles up the River; made a Duchess by Captain
Passenger, from whence the Custom I believe has been taken up, of
distinguishing the most deserving Fellows at trading Towns by the
Titles of Knights, Colonels, and Captains, which they are very proud
of. This Duchess of Gilliflee has become very much the Factory’s
Friend there, and gives all possible Assistance in their Settlement.
Cape St. Mary’s, or the Starboard Entrance of that River, they
found no Cannibals, as commonly reported among Sailors; but a
civilized People, with whom they wooded their Ship.
On the 4th we were off Cape Monte, and next day Montzerado,
both high Lands; the former appearing in a double, the latter with a
single Hommock; the Country trenching from them, low and woody;
about 35 Fathom Water 3 Leagues from Shore. From the latter,
came off a Canoo with the Cabiceer, Captain John Hee,
distinguished by an old Hat, and Sailor’s Jackett with a greater
number of thick brass Rings on his Fingers and Toes, than his
Attendants. He seemed shy of entering the Ship, apprehending a
Panyarring; his Town’s People having often suffered by the
Treachery of Ships, and they as often returned it, sometimes with
Cruelty, which has given rise to the Report of their being Savages
and Cannibals at several places; very unlikely any where, because
they could not part with their Slaves, which are but few, if they had
this Custom, nor could they have any Trade or Neighbours: Their
Fears would make them shun their Enemies (the rest of Mankind)
and all Correspondence totally cease.
The Fetish they brought off, on this dangerous Voyage, was a
Bundle of small, black Sticks, like a hundred of Sparrowgrass put
into a Bag, knit of Silk-grass, and hanging over one of their
Shoulders, seeming to place a Security and Confidence in it; for I
would have handled and tasted it, but found it put them in a Fright,
saying, to deter me, You didee, you kicatavoo, (i. e.) if you eat, you
die presently.
The mutual Distrust between us, made their present Business only
begging old Breeches, Shirts, Rags, Biskett, and whatever else they
saw, parting in some hurry, and calling to one another for that end, in
a Note like what Butchers use in driving Cattle. They have plenty of
Milhio, Rice, Yamms, and Salt hereabouts.
We found in our coasting by Bashau, and other trading Towns, the
same Fears subsisting, coming off every day in their Canoos, and
then at a stand whether they should enter: The boldest would
sometimes come on board, bringing Rice, Malaguetta, and Teeth,
but staying under Fear and Suspicion. Here we may take these
Observations.
1. Canoos are what are used through the whole Coast for
transporting Men and Goods. Each is made of a single Cotton-tree,
chizelled and hollowed into the shape of a Boat; some of them 8 or
10 Foot broad, carrying twenty Rowers. The Negroes do not row one
way and look another, but all forward, and standing at their Paddles,
they dash together with dexterity, and if they carry a Cabiceer,
always sing; a Mark of Respect.
2. Cabiceers are the principal of the trading Men at all Towns; their
Experience, or Courage having given them that Superiority: All Acts
of Government in their several Districts, are by their Votes.
They came off to us with some English Title and Certificate; the
Favour of former Traders to them, for their Honesty and good
Service; and were they done with Caution, might be of use to Ships
as they succeed in the Trade: Whereas now they contain little Truth,
being done out of Humour, and learn them only to beg or steal with
more Impudence.
3. The Negrish Language alters a little in sailing, but as they are
Strangers to Arts, &c. restrained to a few Words, expressive of their
Necessities: This I think, because in their Meetings they are not
talkative; In their Trading the same Sound comes up often; and their
Songs, a Repetition of six Words a hundred times.
Some Negrish Words.
Didee, Eat. Attee, ho, How do you?
Malafia, } Dashee, a Present.
Govina, } Ivory. Kickatavoo, Killed, or Dead.
Malembenda, Rice. Tossu, Be gone.
Cockracoo, Fowl. Yarra, Sick.
Praam, Good. Fabra, Come.
Nino, Sleep. Brinnee, White Man.
Sam sam, all one. Bovinee, Black Man.
Acquidera, Agreed. Soquebah, Gone, lost.
Oura, Very well. Tongo, Man’s Privities.
Tomy, Arse-clout. Bombo, Woman’s.
Lastly, the Dress common to both Sexes every where, is the Tomy,
or Arse-clout, and the pleating or breading of their Wooll. The Arse-
clout the Women tie about their Hips, and falls half way down their
Thigh all round; but the Men bring it under their Twist, and fasten just
upon the girdling part behind. Both take great delight in twisting the
Wool of their Heads into Ringlets, with Gold or Stones, and bestow a
great deal of Time and Genius in it.
The Women are fondest of what they call Fetishing, setting
themselves out to attract the good Graces of the Men. They carry a
Streak round their Foreheads, of white, red, or yellow Wash, which
being thin, falls in lines before it dries. Others make Circles with it,
round the Arms and Bodies, and in this frightful Figure, please. The
Men, on the other side, have their Ornaments consist in Bracelets; or
Manilla’s, about their Wrists and Ancles, of Brass, Copper, Pewter, or
Ivory; the same again on their Fingers and Toes: a Necklace of
Monkey’s Teeth, Ivory Sticks in their Ears, with a broad head. Most
of them have one, two, or more of these Ornaments, and have an
Emulation in the number and use of them.
When the Nakedness, Poverty and Ignorance of these Species of
Men are considered; it would incline one to think it a bettering their
Condition, to transport them to the worst of Christian Slavery; but as
we find them little mended in those respects at the West-Indies, their
Patrons respecting them only as Beasts of Burthen; there is rather
Inhumanity in removing them from their Countries and Families; here
they get Ease with their spare Diet; the Woods, the Fruits, the
Rivers, and Forests, with what they produce, is equally the property
of all. By Transfretation they get the brown Bread, without the
Gospel: together, as Mr. Baxter observed, they might be good Fare,
but hard Work and Stripes without it, must be allowed an unpleasant
Change. They are fed, it’s true, but with the same Diet and Design
we do Horses; and what is an aggravating Circumstance, they have
a Property in nothing, not even in their Wives and Children. No
wonder then, Men under this View, or worse Apprehensions, should
be prompted with Opportunity frequently to sacrifice the Instruments
of it.
SESTHOS.
We anchored before Sesthos, or Sesthio, May 10th, a Place where
most of our windward Slave-ships stop to buy Rice, exchanged at
about 2s. per Quintal. The River is about half the breadth of the
Thames; a narrow Entrance only for Boats on the starboard Side,
between two Rocks, which, on great Swells and Winds, make the
shooting of it dangerous; the rest of the breadth being choaked with
Sands.
The Town is large, and built after a different Model from those we
have left; they run them up (square or round) four Foot from the
Earth; at that height, is the first and chief Room, to sit, talk, or sleep
in, lined with matted Rinds of Trees, supported with Stockades, and
in the middle of it, a Fire-place for Charcoal, that serves a double
Purpose; driving off Insects and Vermine, and drying their Rice and
Indian Corn. Of the upper Loft they make a Store-house, that runs up
pyramidal 30 foot; making the Town at distance, appear like a
number of Spires, each standing singly.
This, and every Town hereabouts, had a Palaaver-Room, a publick
Place of meeting for the People to council, and transact the Business
of the Society: They are large, and built something like our Lodges
for Carts, open, 4 foot from the Ground; then a Stage to sit, rafted
and well covered against Rain and Sun-shine. Here they meet
without distinction; King and Subject, smoaking from Morning to
Night. At this Place, it is common to bring your Traffick; brass Pans,
pewter Basins, Powder, Shot, old Chests, &c. and exchange for
Rice, Goats and Fowls. Two or three Pipes, a Charge of Powder, or
such a Trifle, buys a Fowl. A 2 pound Basin buys a Goat; and I
purchased two for an old Chest, with a Lock to it. Such a piece of
Mechanism I found a Rarity, and brought all the Country down to
admire. A Watch still encreased their Wonder; and making Paper
speak (as they call it) is a Miracle.
They bring their written Certificates hinted above, and when you
tell them the Contents, or they are made Messengers of Notes
between English Ships, they express the utmost Surprize at such
sort of Knowledge and Intercourse; it infinitely exceeds their
Understanding, and impresses a superior and advantageous Idea of
the Europeans.
The King who commands here has the Name of Pedro; he lives
about five Miles up the River, a Sample of Negro Majesty.
As there is a Dashee expected before Ships can wood and water
here; it was thought expedient to send the Royal Perquisite up by
Embassy (a Lieutenant and Purser) who being in all respects equal
to the Trust, were dismissed with proper Instructions, and being
arrived at the King’s Town, they were ushered or thrust in by some of
the Courtiers into the common Palaaver-Room (to wait the King’s
dressing, and coming from his Palace) his publick Audience being
ever in the Presence of the People. After waiting an hour, King Pedro
came attended by a hundred naked Nobles, all smoaking, and a
Horn blowing before them. The King’s Dress was very antick: He had
a dirty, red Bays Gown on, chequer’d with patch-work of other
Colours, like a Jack pudding, and a Fellow to bear the Train, which
was a narrow Slip of Culgee tacked to the bottom of the Gown. He
had an old black full-bottom’d Wig, uncombed; an old Hat not half big
enough, and so set considerably behind the Fore-top, that made his
meagre Face like a Scare-crow; coarse Shoes and Stockings,
unbuckled and unty’d, and a brass Chain of 20lib. at least about his
Neck.
To this Figure of a Man, our modern Embassadors in their Holiday
Suits, fell on their Knees, and might have continued there till this
time, for what Pedro cared: He was something surprized indeed, but
took it for the Fashion of their Country, and so kept making instant
Motions for the Dashee. This brought them from their Knees, as the
proper Attitude for presenting it; consisting in a trading Gun, two
pieces of salt Ship-beef, a Cheese, a Bottle of Brandy, a Dozen of
Pipes, and two Dozen of Congees. But Pedro, who understood the
Present better than the Bows, did not seem pleased when he saw it;
not for any defect in the Magnificence, but they were such things as
he had not present Occasion for; asking some of their Clothes and to
take those back again, particularly their Breeches, sullied a little with
kneeling in the Spittle: But on a Palaaver with his Ministers, the
Present was accepted, and the Officers dismissed back with a Glass
of Palm-Wine and Attee, ho, (the common way of Salutation with
Thumbs and Fingers mixed, and snapping off.)
To smooth the King into a good Opinion of our Generosity, we
made it up to his Son, Tom Freeman; who, to shew his good-nature,
came on board uninvited, bringing his Flagelet, and obliging us with
some wild Notes. Him we dress’d with an edg’d Hat, a Wig, and a
Sword, and gave a Patent upon a large Sheet of Parchment,
creating him Duke of Sesthos, affixing all our Hands, and the
Impress of a Butter mark on Putty.
This was taken so kindly by the Father, that he sent us a couple of
Goats in return, and his younger Son Josee for further Marks of our
Favour; whom we dignified also, on a small Consideration, with the
Title of Prince of Baxos. Several indeed had been titled, but none so
eminently, as by Patent, before; which procured us the entire good-
will of the King; suffering us at any time to hawl our Searn in the
River, where we catched good store of Mullets, Soles, Bump noses,
and Rock-fish; and to go up to their Villages unmolested.
In one of these Towns, some others of us paid a Visit to his
Majesty, whom we found at a Palace built as humble as a Hog-sty;
the entrance was narrow like a Port-hole, leading into what we may
call his Court-Yard, a slovenly little Spot, and two or three Hutts in it,
which I found to be the Apartment of his Women. From this we
popped through another short Portico, and discovered him on the left
hand, upon a place without his House, raised like a Taylor’s Shop-
board, and smoaking with two or three old Women, (the favourite
Diversion of both Sexes.) His Dress and Figure, with the novelty of
ours, created mutual Smiles which held a few Minutes, and then we
took leave with the Attee, ho.
From his Town we went to two others still farther up the River; at
one of them was a bright yellow-colour’d Man, and being curious to
know his Original, were informed (if we interpret their Signs and
Language right) that he came from a good distance in the Country,
where were more. Captain Bullfinch Lamb, and others, have since
told me, they had seen several; Mr. Thompson, that he saw one at
Angola, and another at Madagascar; a great Rarity, and as
perplexing to account for, as the black Colour.
Exomphalos’s are very common among the Negroes here. I saw
also one squint-ey’d; another without a Nose; and another with a
Hair Lip; Blemishes rare among them. Circumcision is used pretty
much; not as a religious Symbol, but at the Humour of the Parent,
who had found a Conveniency in it.
The Diet is Rice, Potatoes, Yacoes or Indian Corn, Parsly, and
other Vegetables; the Cultivation of which, and their domestick
Affairs, are all imposed on the Women.
In general may be observed, they are exceeding cowardly, like
other Countries undisciplined; a whole Town running away from a
Boat with white Men. Thievish on their own Dunghills; none of them
seeming to have any Notion of it as a Crime, and quarrel only about
a Share of what is stole. So lazy, that Scores of them will attend our
Searn for a Bisket, or the Distribution of such small Fish as are
thrown by; for tho’ their Waters afford great Plenty, they want the
Means or Inclination to catch them; chusing rather to loiter and jump
about the Sands, or play at round Holes, than endeavour to get Food
for themselves.
Cape A P O L L O N I A .
From Sesthos, we reached in two or three Days Cape Palma;
weighed Anchor from Jaque a Jaques, the 28th; from Bassau, the
30th; Assmee, the 31st; and anchored here the 6th of June. In this
part of our Sailing may be observed,
1. That the Land from Sierraleon, excepting two or three Capes,
and that about Drewin, appears low, and the first Land you see (as
the Irishman says) is Trees; runs very streight without Bays or Inlets,
which makes it difficult to distinguish, and impossible for us to land
safely at; the Surff breaking all along to a great height, by means of a
continued Swell from a vast Southern Ocean; a Sea which the
Natives only understand, and can push their Canoos through. This
seems a natural Prohibition to Strangers, and whence it follows in
respect to Trade, that Ships are obliged to send their Boats with
Goods near Shore, where the Natives meet them, and barter for
Slaves, Gold, and Ivory; for at many places a Grandee Shippee (as
they call it) affrights them, and they will venture then, as I imagine
they can swim.
2. The Ground is very tough, our Consort and we losing three
Anchors in heaving a Purchase; we stopping at Nights for fear of
over-shooting Places of Trade.
3. We find pretty equal Soundings, about 14 Fathom Water, a
League from Shore, unless at one noted place, a Lusus Naturæ,
called the bottomless Pit, 7 Leagues below Jaque a Jaques, where
the Depth is all at once unfathomable, and about three Miles over.
The great Sir Is. Newton, in his calculating the Force of Gravity,
says, Bodies decrease in their Weight, and Force of their Fall, in the
Proportion of the Squares of Distance from the Center; so that a Tun
at the Surface of the Earth would weigh but ¼ of a Tun, removed
one Semi-Diameter of the Earth higher; and at three Semi-
Diameters, but the 1/16 of a Tun. In like manner their Velocities of
Descent decrease: A Body at the Surface which would fall 16 foot in
a Second, at 12000 Miles high, or three Semi-Diameters, would fall
only 1/16, or one Foot in a Second; but at all given Distances,
something, &c.
Now, according to this Rule, heaving a Lead in great depths of
Water, the Velocity should increase with the descent or sinking of it;
since in the Progress of Gravity, the falling Body in every space of
Time receives a new Impulse, and continually acting, the same
Gravity super-adds a new Velocity; so that at the end of two
Seconds, to be double what it was at the end of the first, and so on,
which here the Weight of the super-incumbent Medium should still
more accelerate. Yet a Lead-line is drawn out perceptibly slower at
the second, than the first hundred Fathoms: But perhaps this
proceeds from the increasing quantity of Line to be drawn with it, not
so equally apt to demerge, and a Nisus in all Bodies of Water, from
below upwards, contrary to Gravity.
4. The Winds were more Southerly than above, checking the
Land-Breeze, which obtaining brings strong unwholesome Smells
from the Mangroves.
5. Their Diet being very slovenly, and much of a piece in this
Track, I shall here entertain you with two or three of their Dishes.
Slabbersauce is made of Rice and Fish, a Fowl, a Kid, or
Elephant’s Flesh, the better for being on the stink. They boil this with
a good quantity of Ochre and Palm-Oil, and is accounted a royal
Feast.
A Dog is a Rarity with some: Our Master had a little Boy-Slave of
eight years of Age, in exchange for one. At other Places, Monkeys
are a very common Diet.
Bomini is Fish dried in the Sun without Salt; stinking, they put it in
a Frying-pan with Palm-Oil, then mixed with boiled Rice, snatch it up
greedily with their Fingers.
Black Soupee is a favourite Dish, as well at our Factories, as
among the Negroes; we make it of Flesh or Fowl, stew’d sweet, with
some uncommon tasted Herbs; but the ascendant Taste is Pepper,
Ochre, and Palm-Oil. At first I thought it disagreeable, but Custom
reconciled it as the best in the Country: Men’s way of Diet being
certainly a principal Reason why in all places some of Land and Sea-
animals are approved or rejected; liked in one Country, and detested
in another.
To return to Jaque a Jaques; we met there the Robert of Bristol,
Captain Harding, who sailed from Sierraleon before us, having
purchased thirty Slaves, whereof Captain Tomba mentioned there
was one; he gave us the following melancholly Story. That this
Tomba, about a Week before, had combined with three or four of the
stoutest of his Country-men to kill the Ship’s Company, and attempt
their Escapes, while they had a Shore to fly to, and had near
effected it by means of a Woman-Slave, who being more at large,
was to watch the proper Opportunity. She brought him word one
night that there were no more than five white Men upon the Deck,
and they asleep, bringing him a Hammer at the same time (all the
Weapons that she could find) to execute the Treachery. He
encouraged the Accomplices what he could, with the Prospect of
Liberty, but could now at the Push, engage only one more and the
Woman to follow him upon Deck. He found three Sailors sleeping on
the Fore-castle, two of which he presently dispatched, with single
Strokes upon the Temples; the other rouzing with the Noise, his
Companions seized; Tomba coming soon to their Assistance, and
murdering him in the same manner. Going aft to finish the work, they
found very luckily for the rest of the Company, that these other two of
the Watch were with the Confusion already made awake, and upon
their Guard, and their Defence soon awaked the Master underneath
them, who running up and finding his Men contending for their Lives,
took a Hand-spike, the first thing he met with in the Surprize, and
redoubling his Strokes home upon Tomba, laid him at length flat
upon the Deck, securing them all in Irons.
The Reader may be curious to know their Punishment: Why,
Captain Harding weighing the Stoutness and Worth of the two
Slaves, did, as in other Countries they do by Rogues of Dignity, whip
and scarify them only; while three others, Abettors, but not Actors,
nor of Strength for it, he sentenced to cruel Deaths; making them
first eat the Heart and Liver of one of them killed. The Woman he
hoisted up by the Thumbs, whipp’d, and slashed her with Knives,
before the other Slaves till she died.
From this Ship we learned also, that the inland Country who had
suffered by the Panyarrs of the Cobelohou and Drewin People, have
lately been down, and destroyed the Towns, and the Trade is now at
a stand; and perhaps the Consciousness of this Guilt increases their
Fears of us. The Ceremony of contracting Friendship and Trade, is
dropping a little salt-water into the Eye, or taking it into their Mouth,
and spurting out again; which must be answer’d, or no Trade will
follow.
At Cape Apollonia, the Natives are of a jet black, very lively and
bold, accustomed to Trade, and better fetished than their
Neighbours; have cleaner and larger Tomys, wear Amber Beads,
Copper Rings, Cowrys, and their Wooll twisted in numberless little
Rings and Tufts, with bits of Shell, Straw, or Gold twisted in them.
They have all a Dagger † cut in their Cheek, and often in other Parts
of their Body: A Custom preserved among a few, down to the Gold
Coast. The Romans and Goths, when possessed of Barbary,
exempted the Christians from Tribute; and to know them, engraved a
+ upon their Cheeks; but this seems too distant for any Analogy with
theirs. All we learn is, its being a very ancient Custom, and
distinguishes them from the Country, who they Panyarr and sell for
Slaves, naked at 4 oz. per Head; allowing 100 per Cent. on Goods,
they cost at a medium 8l. Sterling. The Cabiceers, out of this,
demand a due of 20s. and the Palaaver-Man 10s. whence I
conjecture they are more regularly trained to Panyarring or thieving,
than the Towns we have past.
There is a great deal of Ground cleared about this Cape, and
sown with Indian Corn; first brought among the Negroes, it’s said, by
the Portuguese.
Cabo T R E S P U N T A S .
We stopped a few Hours at Axim in our Passage from Apollonia, and
anchored here June 7, most Ships doing it for the Conveniency of
watering, more difficultly supplied at any parts above. It is called
Three Points, from that number of Headlands that jutt one without
the other; within the innermost is a commodious Bay, nigh the
watering-place. John Conny, who is the principal Cabiceer, exacts a
Duty from all Ships, of an Ounce of Gold, for this Privilege; and
sends off a Servant with his Commission, a large Gold-headed
Cane, engraved John Conny, to demand it. Our Neglect herein, with
some opprobrious Treatment of the Agent, occasioned John Conny
next day to come down with a Posse and seize our Water casks
ashore, carrying away ten or a dozen of our Men Prisoners to his
Town. The Officer among them endeavouring to distinguish to John
the Difference of a King’s Ship from others, got his Head broke: John
(who understood English enough to swear) saying, by G—— me
King here, and will be paid not only for my Water, but the Trouble
has been given me in collecting it. Drink on, says he to the Sailors,
(knocking out the Head of a Half-Anchor of Brandy,) and eat what my
House affords; I know your part is to follow Orders. John, after some
trouble in negotiating, accepted in recompence, six Ounces of Gold,
and an Anchor of Brandy.
His Town stands about three Miles Westward of the watering-
place; large, and as neatly raftered and built, as most of our North or
West small Country Villages. Every Man his Coco-trees round the
House, and in the Streets (such as they are) sit People to sell the
Nuts, Limes, Soap, Indian Corn, and what is a great part of their
Food, Canky, the Work of the Women. It is made of Indian Corn,
after this manner; they pound it in a Mortar for some time, then
malaxing it with Water and Palm-Wine, they grind it still finer with a
Mull upon a great Stone, which every House almost has at the Door
for that purpose; baked or boiled in Cakes, it makes a hearty and
well-tasted Bread.
The Danish (or, as they say, the Brandenburghers) Fort was on an
adjacent Hill, of four or five Bastions, and could mount fifty Guns.
The Garison, when in being, probably taught the Natives the way of
marketing, observed only where the Factories are; but being some
few years since relinquished by them, it’s now in John Conny’s
possession, and has raised up some Contests and Palaavers with
the Dutch: for they pretending a Title of Purchase, sent a Bomb-
Vessel and two or three Frigates last Year, to demand a Surrendry;
but John being a bold and subtle Fellow, weighing their Strength,
answer’d, that he expected some Instrument should be shewed him
to confirm the Brandenburghers Sale; and even with that (says he) I
can see no Pretence but to the Guns, the Brick, and Stone of the
Building, for the Ground was not theirs to dispose of. They have paid
me Rent for it, (continues he) and since they have thought fit to
remove, I do not design to tenant it out to any other white Men while
I live. This sort of Palaaver nettled the Dutch; they threw in some
Bombs and Shot; and heating more with Rage and Brandy, very
rashly landed forty of their Men under the Command of a Lieutenant
to attack the Town: They fired once without any Damage, and then
John at the Head of his Men, rushing from under the Cover of the
Houses, outnumbred and cut them in pieces; paving the entrance of
his Palace soon after, with their Skulls.
This Advantage made him very rusty, upon what he called his
Dues from every body, tho’ just in Trade; and when we had returned
to a good Understanding, my self, with some other of our Officers
paid him a Visit: Our landing was dangerous, the Southerly Winds
making so great a Surff, nor could we do it by our own Boats, but
Canoos of his sending, paying an Accy for the Service; they count
the Seas, and know when to paddle safely on or off. John himself
stood on the Shore to receive us, attended with a Guard of twenty or
thirty Men under bright Arms, who conducted us to his House; a
Building pretty large, and raised from the Materials of the Fort. It
ascends with a double Stone Stair-case without, of twelve Steps; on
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebooknice.com