Professional Documents
Culture Documents
Numeric Computation and Statistical Data Analysis On The Java Platform Advanced Information and Knowledge Processing Chekanov Sergei V
Numeric Computation and Statistical Data Analysis On The Java Platform Advanced Information and Knowledge Processing Chekanov Sergei V
https://textbookfull.com/product/scientific-data-analysis-using-
jython-scripting-and-java-advanced-information-and-knowledge-
processing-2010th-edition-chekanov-sergei-v/
https://textbookfull.com/product/advanced-r-statistical-
programming-and-data-models-analysis-machine-learning-and-
visualization-1st-edition-matt-wiley/
https://textbookfull.com/product/metaprogramming-in-r-advanced-
statistical-programming-for-data-science-analysis-and-
finance-1st-edition-thomas-mailund/
https://textbookfull.com/product/real-estate-analysis-in-the-
information-age-techniques-for-big-data-and-statistical-
modeling-1st-edition-winson-geideman/
Functional Programming in R: Advanced Statistical
Programming for Data Science, Analysis and Finance 1st
Edition Thomas Mailund
https://textbookfull.com/product/functional-programming-in-r-
advanced-statistical-programming-for-data-science-analysis-and-
finance-1st-edition-thomas-mailund/
https://textbookfull.com/product/advanced-object-oriented-
programming-in-r-statistical-programming-for-data-science-
analysis-and-finance-1st-edition-thomas-mailund/
https://textbookfull.com/product/statistical-data-analysis-using-
sas-intermediate-statistical-methods-mervyn-g-marasinghe/
https://textbookfull.com/product/advanced-linear-modeling-
statistical-learning-and-dependent-data-3rd-edition-
christensen-r/
Sergei V. Chekanov
Numeric
Computation and
Statistical Data
Analysis on the
Java Platform
Advanced Information and Knowledge
Processing
Series editors
Lakhmi C. Jain
Bournemouth University, Poole, UK and
University of South Australia, Adelaide, Australia
Xindong Wu
University of Vermont
Information systems and intelligent knowledge processing are playing an increasing
role in business, science and technology. Recently, advanced information systems
have evolved to facilitate the co-evolution of human and information networks
within communities. These advanced information systems use various paradigms
including artificial intelligence, knowledge management, and neural science as well
as conventional information processing paradigms. The aim of this series is to
publish books on new designs and applications of advanced information and
knowledge processing paradigms in areas including but not limited to aviation,
business, security, education, engineering, health, management, and science. Books
in the series should have a strong focus on information processing—preferably
combined with, or extended by, new results from adjacent sciences. Proposals for
research monographs, reference books, coherently integrated multi-author edited
books, and handbooks will be considered for the series and each proposal will be
reviewed by the Series Editors, with additional reviews from the editorial board and
independent reviewers where appropriate. Titles published within the Advanced
Information and Knowledge Processing series are included in Thomson Reuters’
Book Citation Index.
Numeric Computation
and Statistical Data Analysis
on the Java Platform
123
Sergei V. Chekanov
HEP Division
Argonne National Laboratory
Lemont, IL
USA
Numerical and statistical algorithms are typically confined within a specific pro-
gramming language. For example, the R open-source data-analysis software uses a
specialized scripting language, which is an implementation of the “S” programming
language. Many commercial mathematical programs follow this trend. This book is
about a platform for statistical calculations using algorithms that are not confined by
a chosen language. For example, this platform allows mixing Python and Java
numerical libraries, or using them on their own. Or, one can use this book to
program statistical code using other languages, such as Groovy, Ruby, and
BeanShell. This book is about an approach to scientific programming and visual-
ization that does not set strict requirements on specific programming languages, nor
on operating systems where such calculations are performed.
There are many books written about Java—one of the most popular program-
ming languages. There are many books written about Python, which is another very
popular programming language. This book explains how to mix them, bringing
incredible algorithmic power and cutting-edge numeric libraries to scientific com-
putations and data visualization.
In this book I did not go deep inside particular scientific research area, since the
aim was to give concrete examples which illustrate which Java libraries should be
used to perform computations. In the cases when I could not cover the subject in
detail, a sufficient number of relevant references was given, so the reader can easily
find necessary information for each chapter using external sources.
Thus this book presents practical approaches to numerical computations, data
analysis, and knowledge discovery, focusing on programming techniques. Each
chapter describes the conceptual underpinning for numerical and statistical calcu-
lations using Java libraries, covering many aspects from simple multidimensional
arrays and histograms to clustering analysis, curve fitting, neural networks, and
symbolic calculations. To make the examples as simple as possible from the
computational point of view, I fully embrace the scripting approach in the course of
this book. This leads to short and clear analysis codes, so you could concentrate on
the logic of analysis flow rather than on language-specific details.
vii
viii Preface
This book uses Python as the main programming language, since it is elegant and
easy to learn. It is a great language for teaching scientific computation. For devel-
opers, this is an ideal language for fast prototyping and debugging. The book dis-
cusses how to design code snippets for numeric computation and statistics on the
Java platform. To be more exact, we will use Jython (Python implemented in Java), a
language that uses not only native Python modules, but can also access very com-
prehensive Java classes. The reader will learn how to write analysis codes, while
numerous code snippets will give you some ideas on numeric algorithms which can
easily be incorporated into realistic research application. The book includes more
than 300 code snippets to produce data-visualization plots in 2D and 3D.
I am almost convinced myself that this book is self-contained and does not
depend on detailed knowledge of computing language, although knowledge of
Python and Java is desirable. However, the reader may still need some programming
background in order to use this book with other languages, such as Groovy,
BeanShell, and Ruby, since I did not give very detailed coverage of these languages.
This book is intended for general audiences, for those who use computing to make
sense of data surrounding us. It can be used as a source of knowledge on data
analysis and statistical calculations for students and professionals of all disciplines.
This book was written for undergraduate and graduate students, academics, pro-
fessors, and professionals of any field and any age. The book could be used as a
textbook for students.
We also hope that this book will be useful for those who study financial markets,
since the numeric algorithms discussed in this book are undoubtedly common to any
knowledge discovery research. This book equips readers with the description of a
computational platform for statistical calculations which can be viewed as an inex-
pensive alternative to costly commercial products used by financial-market analysts.
I assume the readers are not familiar with Python/Jython, the main programming
language used for code snippets in this book. But some basic understanding of
statistics and mathematics would be very helpful to understand the material of this
book.
All example codes of this book can easily be transformed to Java, Groovy,
Ruby/JRuby, or BeanShell codes. You are presumed to have knowledge of pro-
gramming in Java, if you will choose the path of moving the examples to Java, or if
you will decide to create Java libraries to be deployed as jar files for a new project.
The book will discuss how to do this, and a few Java examples will be provided.
Transformations of the example snippets to scripting languages, such as Groovy,
Ruby/JRuby, or BeanShell, may require some knowledge of these scripting
languages. The good thing is that the analysis algorithms and numerical libraries
will be exactly the same, so a little effort is required to move to other languages.
Again, we will show you how to convert Jython codes to these languages. In most
Preface ix
cases, our examples should be sufficient to get started with a new language. The
more knowledge about Groovy and Ruby/JRuby you can bring, the more you will
get out of this book.
References
This book describes a software which is a collective work of many developers who
have dedicated themselves to scientific computing. The author is grateful to all
people who contributed to scientific software, and for their inspiration and dedi-
cation to science and knowledge-discovery software.
Many numeric and graphic libraries discussed in this book were released as
open-source projects. I am grateful to the authors of such open-source programs for
their enthusiasm to share their work, and for making their software publicly
available.
You can find a list of contributions to the software packages described in this
book on the jWork.ORG web page (http://jwork.org/dmelt/). A special note of
thanks to those of you who reported bugs in a constructive way, helped with
solutions, and shared your knowledge and experience with others.
Much of this project grew out of fruitful collaboration with many of my col-
leagues who devoted themselves to high energy physics. Over the course of the past
twenty-five years I have learned a lot about programming aspects of scientific
research. I would like to thank my colleagues for checking and debugging the
examples shown in this book, and here the list will be endless.
I would like to thank everyone at Springer for their help with the production
process. In particular, managing editors H. Desmond and J. Robinson, who helped
start this book in its present form.
Not least, personal thanks go to my dear wife, Tania, and my sons, Alexey
(Alosha) and Roman, for their love and patience to a husband and father who was
only half (mentally) present after coming from his work. Without their patience and
understanding, this book would not have been possible. Finally, I also thank my
parents and sister for their support of my interests in all aspects of science.
xi
Contents
xiii
xiv Contents
2 Introduction to Jython . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.1 Code Structure and Jython Objects . . . . . . . . . . . . . . . . . . . 27
2.1.1 Numbers as Objects . . . . . . . . . . . . . . . . . . . . . . 30
2.1.2 Formatted Output . . . . . . . . . . . . . . . . . . . . . . . . 32
2.1.3 Mathematical Functions . . . . . . . . . . . . . . . . . . . . 32
2.2 Complex Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.3 Strings as Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.4 Import Statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
2.4.1 Executing Native Applications . . . . . . . . . . . . . . . 37
2.5 Comparison Tests and Loops . . . . . . . . . . . . . . . . . . . . . . . 38
2.5.1 The “if-else” Statement . . . . . . . . . . . . . . . . . . . . 38
2.5.2 Loops. The “for” Statement . . . . . . . . . . . . . . . . . 39
2.5.3 The “continue” and “break” Statements . . . . . . . . . 39
2.5.4 Loops. The “while” Statement . . . . . . . . . . . . . . . 40
2.6 Collections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.6.1 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
2.6.2 Tuples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.6.3 Dictionaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
2.6.4 Functional Programming . . . . . . . . . . . . . . . . . . . 48
2.7 Java Collections in Jython . . . . . . . . . . . . . . . . . . . . . . . . . 50
2.7.1 List. An Ordered Collection . . . . . . . . . . . . . . . . . 50
2.7.2 Set. A Collection Without Duplicate Elements . . . . 53
2.7.3 SortedSet. Sorted Unique Elements . . . . . . . . . . . . 54
2.7.4 Map. Mapping Keys to Values . . . . . . . . . . . . . . . 55
2.7.5 Java Map with Sorted Elements . . . . . . . . . . . . . . 55
2.7.6 Real-Life Example: Sorting and Removing
Duplicates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
2.8 Random Numbers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
2.9 Time Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2.9.1 Benchmarking . . . . . . . . . . . . . . . . . . . . . . . . . . 59
2.10 Python Functions and Modules. . . . . . . . . . . . . . . . . . . . . . 60
2.11 Python Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
2.11.1 Initializing a Class . . . . . . . . . . . . . . . . . . . . . . . 65
2.11.2 Classes Inherited from Other Classes. . . . . . . . . . . 65
2.11.3 Java Classes in Jython . . . . . . . . . . . . . . . . . . . . . 66
2.11.4 Not Covered Topics . . . . . . . . . . . . . . . . . . . . . . 66
2.12 Parallel Computing and Threads . . . . . . . . . . . . . . . . . . . . . 67
2.13 Arrays in Jython. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
2.13.1 Array Conversion and Transformations . . . . . . . . . 69
2.13.2 Performance Issues . . . . . . . . . . . . . . . . . . . . . . . 69
2.13.3 Used Memory . . . . . . . . . . . . . . . . . . . . . . . . . . 70
2.14 Exceptions in Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Contents xv
conventions and code layout. We even admit that some parts were not designed
with the highest possible performance for code execution in mind. The reason is
simple: it was not written by professional programmers. The numerical libraries
were written by many people at different times, most of them were students and
scientists who had to develop numerical and data visualization algorithms for their
own research programs, since commercial software companies either could not offer
similar programs or their products were too expensive. Many contributed packages
have been discontinued many years ago, but have been brought to life after their
inclusion into DMelt. In addition, some packages were written using Java 1.1, and
this had also some impact on the coding style of certain libraries.
Thus, a professional programmer may immediately find some parts of the code
that look unprofessionally written. This is true even for some examples shown in
this book. The reason for this was not because we were not aware of such coding
issues. In some cases, we did not find appealing reasons to keep very strict coding
standard at the expense of simplicity. For example, in most cases, we import all
classes inside a package using the statement:
We did not enforce the latter case to keep the examples of this book short and con-
cise, so we could fit the code snippets into the pages of this book. Also, it is possible
that you may not like to type long lists of imported classes during a code prototyp-
ing (personally, I do not like this style), since this can be done later during code
deployment.
A professorial programmer might find some other odds, like why some object
containers are designed to store only double values (like the P1D class to be
discussed below), while it is more practical to store integer values when necessary.
Again, the motivation was not because of omissions. The reason was that the reader
may not want to dive into extra complexity of dealing with different types, since
integers are only a subset of float values. There are plenty of other classes which are
well suited for storing integer values (we will discuss them in this book).
The main motivation for the DMelt project was to develop an accessible and
friendly tool to be used in scientific search, with a syntax oriented toward scientists
rather than programmers. The design of this project was mainly motivated by
simplicity: there are many programming languages which are required to learn for
many years before starting to write useful scientific and engineering projects. The
approach discussed in this book is very different: generally, the reader does not need
to know any programming language to start writing analysis codes using DMelt
libraries. However, if it happens that the reader knows either Java or Python (or
both) already, he or she will find this book to be also interesting, since DMelt is not
just a simplified entry to the world of the Java and Python computer programming. It
6 1 Java Computational Platform
shows how to use programming for practical purposes such as numeric calculations,
statistics, and data analysis.
The reader may also notice that a little attention has been paid to how to write and
use Java or Jython classes. Of course, classes are necessary for any object-oriented
language. The reason for this is the following: for the majority of scientific data
analysis programs, the logic of scripting programs is linear, i.e., an analysis code
typically consists of a well-defined sequence of statements to be evaluated one by
one, from the top to the bottom of the code. It is very unlikely that data analysis logic
will contain highly parallel algorithmic branches as those for the usual graphical
user interface (GUI) development.1 Certainly, the classes are necessary when one
develops Java libraries to be used by a scripting language. But, in this book, we
mainly concentrate on the scripting examples based on the existing Java libraries of
DMelt, rather than discussing how to write classes for numerical computation to be
deployed as external libraries.
1.1.4 Errors
This book may contain typos, omissions, or even errors. DMelt can also contain
bugs. If you notice any errors or if you have suggestions regarding the book and
code examples, I would be happy to hear from you. You can send your comments
to:
dmelt@jworks.org
One can also post bug reports to the DMelt forum accessible from the main Web
page:
http://jwork.org/dmelt/
DMelt is not a software that stands still. Therefore, this book represents a snap-
shot of the time when the DMelt version 1.4 was in use, therefore, some examples
may fall out of date. Therefore, the reader is encouraged to look at the Web page
given above to find corrected examples.
1 We should probably say that this may not be totally true in future when multi-core machines will
be rather common and one will face with the question of how to parallelize analysis codes to gain
high performance. We briefly discuss this topic in this book.
Another random document with
no related content on Scribd:
found, no attempt being made to place it in a special receptacle. The
egg is placed on the ventral surface, well behind the feet, under a
mass of matter in the alimentary canal. Shortly after being hatched
the young destroyer penetrates with its head the skin of the victim,
and in this position commences to feed; it is necessary that it should
obtain its food without killing the Cetonia larva, for it cannot prosper
on decaying food, so that if the Cetonia larva die the Scolia larva
likewise perishes; the latter, accordingly, does not withdraw its head
from the interior of the victim, but remains always in the same
position, as it grows larger extending its head forwards into the front
part of the interior of its victim; the internal organs of the latter are
consumed in a systematic order so as to delay bringing about its
death till the last moment, and thus all the interior of the Cetonia
larva is appropriated till nothing remains but an empty skin. By a
series of experiments, Fabre showed how essential it is that this
apparently revolting operation should be carried on with all details
strictly en règle. If the head of the Scolia larva be taken out from the
victim and applied to another part of the body of the Cetonia, the
result is that it cannot eat; even if it be replaced in the original
situation, after being taken away, it frequently happens that the
Cetonia larva dies, its death involving also that of the destroyer. It is
necessary, too, that the victim should be paralysed, for if an intact
Cetonia larva be taken and bound down in such a position that it
cannot move, and if a small orifice in its skin be made in the proper
spot and a young Scolia larva be placed on it, the little parasite will
avail itself of the opportunity and commence to feed on the larva
provided for it, but the latter will speedily die, and the Scolia
necessarily perishes with it. Thus both the paralysis of the victim and
the special mode of eating are essential to the life of the Scolia. The
operation of stinging the larva so as to produce the necessary
paralysis, or rather insensibility, is a difficult one, and requires great
skill and patience. The Cetonia larva is of large size, and must be
pierced in one particular spot; in order to reach this the Scolia
mounts on its victim, and is frequently dislodged by its struggles;
sooner or later, however, the proper position is obtained by the wasp,
and the larva is then stung in the exact spot necessary to allow the
sting (and the poison introduced by it) to reach the most important of
the nervous ganglia that control the movements of the body, this spot
being, in the case of the Cetonia, the line of demarcation between
the pro- and meso-thorax, on the middle line of the ventral surface of
the body. The Scolia gives but one sting to the victim, and this it will
not administer until it can do so exactly in the proper place. This
practice of devouring the victim slowly, without killing it till all is
eaten, is very widely spread in the Hymenoptera, and it is
satisfactory to find that we may infer from Fabre's observations that it
is not so horrible as it would at first appear; for it is probable that the
stinging prevents decomposition of the victim, not by reason, as
some have supposed, of the poison injected by the wasp having an
antiseptic effect, but rather by means of destroying sensibility, so that
the creature does not die from the pain, as it is believed it did in
certain cases where Fabre induced the young Scolia larva to feed on
a victim that had not been stung. We may here remark that very little
exact information exists as to the operation of stinging. Fabre
attaches great importance to the sting being inflicted on a nerve-
ganglion. Whether a sting that did not reach this part might not have
a sufficient effect appears, however, doubtful.[46]
The economy of Sapyga, the only genus, has been the subject of
difference of opinion. The views of Latreille and others that these
species are parasitic upon bees is confirmed by the observations of
Fabre, from which it appears that S. 5-punctata lives in the burrows
of species of the bee-genus Osmia, consuming the store of
provisions, consisting of honey-paste, that the bee has laid up for its
young. According to the same distinguished observer, the Sapyga
larva exhibits hypermetamorphosis (i.e. two consecutive forms), and
in its young state destroys the egg of the bee; but his observations
on this point are incomplete and need repetition. We have two
species of Sapyga in Britain; they differ in colour, and the sexes of S.
5-punctata also differ in this respect; the abdomen, spotted with
white in both sexes is in the female variegate with red. Smith found
our British Sapyga 5-punctata carrying caterpillars.
Fam. 2. Pompilidae.
The Pompilidae are perhaps the most extensive and important of the
groups of Fossores, and are distributed over all the lands of the
globe, with the exception of some islands and of the inclement arctic
regions. The sting of the Pompilidae, unlike that of most of the
Fossores, inflicts a burning and painful wound; the creatures
sometimes attain a length of two or three inches, and a sting from
one of these giants may have serious results. Although there is
considerable variety in the external form of the members of the
group, the characters given above will enable a Pompilid to be
recognised with approximate certainty. The elongation of the hind
legs includes all the parts, so that while the femur extends nearly as
far back as the extremity of the body—in dried examples at any rate
—the tibiae and the long tarsi extend far beyond it; thus these
Insects have great powers of running; they are indeed remarkable
for extreme activity and vivacity. They may frequently be seen
running rapidly on the surface of the ground, with quivering wings
and vibrating antennae, and are probably then employed in the
search for prey, or some other of the operations connected with
providing a store of food for their young. Spiders appear to be their
special, if not their only, prey. Several authors have recorded details
as to the various ways in which the prey is attacked. Fabre has
observed the habits of several species, and we select his account of
the modus operandi of species of the genera Pompilus and
Calicurgus, in their attacks on poisonous spiders that inhabit holes in
the ground or in walls. The wasp goes to the mouth of the spider's
burrow, and the latter then dashes to the entry, apparently enraged
at the audacity of its persecutor.
The Calicurgus will not actually enter a burrow when there is a spider
in it, because if it did so the spider would speedily dispose of the
aggressor by the aid of its poisonous fangs. The Calicurgus,
therefore, has recourse to strategy with the object of getting the
spider out of its nest; the wasp seizes its redoubtable foe by one foot
and pulls; probably it fails to extract the spider, and in that case
rapidly passes to another burrow to repeat its tactics; sooner or later
a spider is in some moment of inattention or incapacity dragged from
its stronghold, and, being then comparatively helpless, feels itself at
a disadvantage and offers but a feeble resistance to the wasp, which
now pounces on its body and immediately inflicts a sting between
the fangs of the foe, and thus at once paralyses these dangerous
weapons; thereafter it stings the body of the spider near to the
junction of the abdomen and cephalothorax, and so produces
complete inactivity. Having secured its prey, the wasp then seeks a
suitable hole in which to deposit it; probably an empty burrow of a
spider is selected for the purpose, and it may be at a height of
several feet in a wall; the Hymenopteron, walking backwards, drags
its heavy prey up the wall to bring it to the den. When this is
accomplished an egg is deposited on the spider, and the wasp goes
in search of a fragment or two of mortar, with which the mouth of the
burrow is finally blocked. Fabre's accounts refer to the habits of
several species, and give a good insight into some points of the
instincts of both the spider and the wasp. It seems that a sense of
superiority is produced in one or other of the foes, according as it
feels itself in suitable conditions; so that though a spider out of its
burrow and on the ground is speedily vanquished by the Pompilid,
yet if the two be confined together in a vase, both are shy and
inclined to adopt defensive or even evasive tactics, the result
probably being that the wasp will be killed by the spider during the
night, that being the period in which the attacking powers of the
spider are more usually brought into play.
Fam. 3. Sphegidae.
Pronotum free from the tegulae; when the stigmatic lobes extend
as far back as the wing-insertion, they are placed below it and
separated by a space from it.
The habits of one species of this genus have been fully described by
Fabre; he assigns to the species the name of S. flavipennis, but Kohl
considers that it is more probably S. maxillosus. This Insect forms its
nests, in the South of France, in the ground, excavating a main shaft
with which are connected cells intended for the reception of the
provisions for the young. The entrance to the burrow is formed by
piercing a hole in the side of a very slight elevation of the soil. Thus
the entrance to the construction consists of a horizontal gallery,
playing the part of a vestibule, and this is used by the Sphex as a
place of retreat and shelter for itself; at the end of the vestibule,
which may be two or three inches long, the excavation takes an
abrupt turn downwards, extending in this manner another two or
three inches, and terminating in an oval cell the larger diameter of
which is situate in a horizontal plane. When this first cell has been
completed, stored with food, and an egg laid in it, the entrance to it is
blocked up, and another similar cell is formed on one side; a third
and sometimes a fourth are afterwards made and provisioned, then
the Insect commences anew, and a fresh tunnel is formed; ten such
constructions being the number usually prepared by each wasp. The
Insect works with extreme energy, and as the period of its
constructive activity endures only about a month, it can give but two
or three days to the construction and provisioning of each of its ten
subterranean works. The provisions, according to Fabre, consist of a
large species of field-cricket, of which three or four individuals are
placed in each cell. Kohl states, however, that in Eastern Europe an
Insect that he considers to be the same species as Fabre's Sphex,
makes use of locusts as provisions, and he thinks that the habit may
vary according to the locality or to the species of Orthoptera that may
be available in the neighbourhood. However that may be, it is clear
from Fabre's account that this part of the Sphex's duties do not give
rise to much difficulty. The cricket, having been caught, is paralysed
so that it may not by its movements destroy the young larva for
whose benefit it is destined. The Sphex then carries it to the burrow
to store it in one of the cells; before entering the cell the Insect is in
the habit of depositing its prey on the ground, then of turning round,
entering the burrow backwards, seizing as it does so the cricket by
the antennae, and so dragging it into the cell, itself going backwards.
The habit of depositing its prey on the ground enabled Fabre to
observe the process of stinging; this he did by himself capturing a
cricket, and when the wasp had momentarily quitted its prey,
substituting the sound cricket for the paralysed one. The Sphex, on
finding this new and lively victim, proceeds at once to sting it, and
pounces on the cricket, which, after a brief struggle, is overcome by
the wasp; this holds it supine, and then administers three stings, one
in the neck, one in the joint between the pro- and meso-thorax, and a
third at the base of the abdomen, these three spots corresponding
with the situation of the three chief nervous centres governing the
movements of the body. The cricket is thus completely paralysed,
without, however, being killed. Fabre proved that an Insect so treated
would survive for several weeks, though deprived of all power of
movement. Three or four crickets are placed by the wasp in each
cell, 100 individuals or upwards being thus destroyed by a single
wasp. Although the sting has such an immediate and powerful effect
on the cricket, it occasions but a slight and evanescent pain to a
human being; the sting is not barbed, as it is in many bees and true
wasps, and appears to be rarely used by the Insect for any other
purpose than that of paralysing its victims. The egg is laid by the
Sphex on the ventral surface of the victim between the second and
third pairs of legs. In three or four days the young larva makes its
appearance in the form of a feeble little worm, as transparent as
crystal; this larva does not change its place, but there, where it was
hatched, pierces the skin of the cricket with its tiny head, and thus
begins the process of feeding; it does not leave the spot where it first
commenced to feed, but gradually enters by the orifice it has made,
into the interior of the cricket. This is completely emptied in the
course of six or seven days, nothing but its integument remaining;
the wasp-larva has by this time attained a length of about 12
millimetres, and makes its exit through the orifice it entered by,
changing its skin as it does so. Another cricket is then attacked and
rapidly consumed, the whole stock being devoured in ten or twelve
days from the commencement of the feeding operations; the
consumption of the later-eaten crickets is not performed in so
delicate a manner as is the eating of the first victim. When full-grown,
the process of forming a cocoon commences: this is a very elaborate
operation, for the encasement consists of three layers, in addition to
the rough silk that serves as a sort of scaffolding on the exterior: the
internal coat is polished and is of a dark colour, owing to its being
coloured with a matter from the alimentary canal: the other layers of
the cocoon are white or pale yellow. Fabre considers that the outer
layers of the cocoon are formed by matter from the silk-glands, while
the interior dark coat is furnished by the alimentary canal and applied
by the mouth of the larva: the object of this varnish is believed to be
the exclusion of moisture from the interior of the cocoon, the
subterranean tunnels being insufficient for keeping their contents dry
throughout the long months of winter. During the whole of the
process of devouring the four crickets, nothing is ejected from the
alimentary canal of the larva, but after the cocoon is formed the larva
ejects in it, once for all, the surplus contents of the intestine. Nine
months are passed by the Insect in the cocoon, the pupal state being
assumed only towards the close of this period. The pupa is at first
quite colourless, but gradually assumes the black and red colour
characteristic of the perfect wasp. Fabre exposed some specimens
of the pupa to the light in glass tubes, and found that they went
through the pupal metamorphosis in just the same manner as the
pupae that remained in the darkness natural to them during this
stage of their existence.
This is one of the smallest of the divisions of the Sphegidae, but has
a very wide distribution, being represented in both the Eastern and
Western Hemispheres. It is allied to the Sphegides, but differs by the
prolongation of the neck and of the head, and by the articulation
between the petiole and thorax being placed on the under surface of
the body; the wing-nervures are said to be of inferior importance
owing to their frequently differing in individuals of the same species.
These Insects appear to be rare in individuals, as well as few in
species, and but little has been recorded as to their habits; but it is
known that they live on cockroaches. Perkins has given a brief
sketch of the habits of Ampulex sibirica that is of great interest, but
requires confirmation. He says that this Insect, in West Africa, enters
apartments where cockroaches abound, and attacking one, that may
probably be four times its own size, succeeds, after a struggle, in
stinging it; the cockroach instantly becomes quiet and submissive,
and suffers itself to be led away and placed in confinement in some
spot such as a keyhole, and in one case was apparently prevented
from afterwards escaping, by the wasp carrying some heavy nails
into the keyhole. The larva of the Ampulex may be presumed to live
on the Blattid, as it is added that dead bodies of the cockroaches are
frequently found with the empty cocoon protruding from them. This
account, if correct, points to some features in the habits of this Insect
that are unique. A remark made by Rothney in reference to the
habits of A. (Rhinopsis) ruficornis seems to indicate some similar
instinct on the part of that species; he says, "I also saw two or three
of these wasps collar a peculiar cockroach by the antennae and lead
it off into a crack in the bark, but as the cockroach reappeared
smiling each time, I don't know what was up." The same observer
records that this species associates with Sima rufonigra, an ant it
greatly resembles in appearance, as well as with a spider that is also
of similar appearance (Fig. 72). Schurr has given a brief account of
the proceedings of Ampulex compressa, and his statements also
tend to confirm the correctness of Perkins' report. The habits of a
species of Ampulex were partially known to Réaumur, who described
them on the authority of M. Cossigni. The species is believed to be
A. compressa, which occurs not only in East India, but also in the
island of Bourbon, the locality where M. Cossigni made his
observation: his account is, like the others, a mere sketch of certain
points observed, the most important of which is that when Ampulex
cannot introduce the cockroach into a hole that it has selected as
suitable, it bites off some portions of the body in order to reduce the
poor Insect to the necessary extent.