added introduction chapter

This commit is contained in:
mhjensen
2018-05-21 10:59:37 -04:00
parent 6437af32ef
commit 06c18466e5
55 changed files with 4077 additions and 2764 deletions
+170 -275
View File
@@ -6,9 +6,9 @@ Automatically generated HTML file from DocOnce source
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<meta name="description" content="Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<title>Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</title>
<!-- Bootstrap style: bootstrap -->
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
@@ -41,68 +41,70 @@ Automatically generated HTML file from DocOnce source
<!-- tocinfo
{'highest level': 2,
'sections': [('Introduction', 2, None, '___sec0'),
('Learning outcomes', 2, None, '___sec1'),
('Types of Machine Learning', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Software and needed installations', 2, None, '___sec1'),
('Python installers', 2, None, '___sec2'),
('Installing R, C++, cython or Julia', 2, None, '___sec3'),
('Installing R, C++, cython or Julia', 2, None, '___sec4'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Simple regression model', 2, None, '___sec9'),
'___sec5'),
('Representing data, more examples', 2, None, '___sec6'),
('Simple regression model', 2, None, '___sec7'),
('Simple regression model, now using _scikit-learn_',
2,
None,
'___sec10'),
'___sec8'),
('Simple regression model with gradient descent',
2,
None,
'___sec11'),
'___sec9'),
('Simple regression model with stochastic gradient descent',
2,
None,
'___sec12'),
('Polynomial regression', 2, None, '___sec13'),
('Predator-Prey model from ecology', 2, None, '___sec14'),
('Case study from Hudson bay', 2, None, '___sec15'),
('Hudson bay data', 2, None, '___sec16'),
('Plotting the data', 2, None, '___sec17'),
'___sec10'),
('Polynomial regression', 2, None, '___sec11'),
('Predator-Prey model from ecology', 2, None, '___sec12'),
('Case study from Hudson bay', 2, None, '___sec13'),
('Hudson bay data', 2, None, '___sec14'),
('Plotting the data', 2, None, '___sec15'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec18'),
'___sec16'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec19'),
('The traditional (top-down) approach', 2, None, '___sec20'),
('Basic mathematics notation', 2, None, '___sec21'),
'___sec17'),
('The traditional (top-down) approach', 2, None, '___sec18'),
('Basic mathematics notation', 2, None, '___sec19'),
('Basic dynamics of the population of hares',
2,
None,
'___sec22'),
('Basic dynamics of the population of lynx', 2, None, '___sec23'),
('Evolution equations', 2, None, '___sec24'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec25'),
('The program', 2, None, '___sec26'),
('The plot', 2, None, '___sec27'),
('Linear regression in Python', 2, None, '___sec28'),
('Linear Least squares in R', 2, None, '___sec29'),
('Non-Linear Least squares in R', 2, None, '___sec30'),
('Example: ecoli lab experiment', 2, None, '___sec31'),
('The program', 2, None, '___sec32'),
('The output', 2, None, '___sec33'),
('Parameter estimation', 2, None, '___sec34'),
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25'),
('Linear regression in Python', 2, None, '___sec26'),
('Linear Least squares in R', 2, None, '___sec27'),
('Non-Linear Least squares in R', 2, None, '___sec28'),
('Example: ecoli lab experiment', 2, None, '___sec29'),
('The program', 2, None, '___sec30'),
('The output', 2, None, '___sec31'),
('Parameter estimation', 2, None, '___sec32'),
('A program relevant for the biological problem',
2,
None,
'___sec35'),
('Simulating financial transcations', 2, None, '___sec36'),
('Simulation of Transactions', 3, None, '___sec37')]}
'___sec33'),
('Simulating financial transcations', 2, None, '___sec34'),
('Simulation of Transactions', 3, None, '___sec35'),
('Particle in one dimension an velocity distribution',
2,
None,
'___sec36')]}
end of tocinfo -->
<body>
@@ -132,7 +134,7 @@ MathJax.Hub.Config({
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Introduction and Representing data</a>
<a class="navbar-brand" href="How2ReadData-bs.html">Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</a>
</div>
<div class="navbar-collapse collapse navbar-responsive-collapse">
@@ -141,43 +143,42 @@ MathJax.Hub.Config({
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
<ul class="dropdown-menu">
<!-- navigation toc: --> <li><a href="#___sec0" style="font-size: 80%;"><b>Introduction</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec1" style="font-size: 80%;"><b>Learning outcomes</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec2" style="font-size: 80%;"><b>Types of Machine Learning</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;"><b>Software and needed installations</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;"><b>Python installers</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;"><b>Introduction to Jupyter notebook and available tools</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;"><b>Representing data, more examples</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;"><b>Simple regression model</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;"><b>Simple regression model, now using <b>scikit-learn</b></b></a></li>
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;"><b>Simple regression model with gradient descent</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;"><b>Simple regression model with stochastic gradient descent</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;"><b>Polynomial regression</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;"><b>Predator-Prey model from ecology</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;"><b>Case study from Hudson bay</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;"><b>Hudson bay data</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;"><b>Plotting the data</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;"><b>Hares and lynx in Hudson bay from 1900 to 1920</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;"><b>Why now create a computer model for the hare and lynx populations?</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;"><b>The traditional (top-down) approach</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;"><b>Basic mathematics notation</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;"><b>Basic dynamics of the population of hares</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;"><b>Basic dynamics of the population of lynx</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;"><b>Evolution equations</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec25" style="font-size: 80%;"><b>Adapt the model to the Hudson Bay case</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec26" style="font-size: 80%;"><b>The program</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec27" style="font-size: 80%;"><b>The plot</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec28" style="font-size: 80%;"><b>Linear regression in Python</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec29" style="font-size: 80%;"><b>Linear Least squares in R</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec30" style="font-size: 80%;"><b>Non-Linear Least squares in R</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec31" style="font-size: 80%;"><b>Example: ecoli lab experiment</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec32" style="font-size: 80%;"><b>The program</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec33" style="font-size: 80%;"><b>The output</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec34" style="font-size: 80%;"><b>Parameter estimation</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;"><b>A program relevant for the biological problem</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;"><b>Simulating financial transcations</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec37" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Simulation of Transactions</a></li>
<!-- navigation toc: --> <li><a href="#___sec1" style="font-size: 80%;"><b>Software and needed installations</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec2" style="font-size: 80%;"><b>Python installers</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec3" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec4" style="font-size: 80%;"><b>Installing R, C++, cython or Julia</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec5" style="font-size: 80%;"><b>Introduction to Jupyter notebook and available tools</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec6" style="font-size: 80%;"><b>Representing data, more examples</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;"><b>Simple regression model</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;"><b>Simple regression model, now using <b>scikit-learn</b></b></a></li>
<!-- navigation toc: --> <li><a href="#___sec9" style="font-size: 80%;"><b>Simple regression model with gradient descent</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec10" style="font-size: 80%;"><b>Simple regression model with stochastic gradient descent</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec11" style="font-size: 80%;"><b>Polynomial regression</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec12" style="font-size: 80%;"><b>Predator-Prey model from ecology</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec13" style="font-size: 80%;"><b>Case study from Hudson bay</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec14" style="font-size: 80%;"><b>Hudson bay data</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec15" style="font-size: 80%;"><b>Plotting the data</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec16" style="font-size: 80%;"><b>Hares and lynx in Hudson bay from 1900 to 1920</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec17" style="font-size: 80%;"><b>Why now create a computer model for the hare and lynx populations?</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec18" style="font-size: 80%;"><b>The traditional (top-down) approach</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec19" style="font-size: 80%;"><b>Basic mathematics notation</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec20" style="font-size: 80%;"><b>Basic dynamics of the population of hares</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec21" style="font-size: 80%;"><b>Basic dynamics of the population of lynx</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec22" style="font-size: 80%;"><b>Evolution equations</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec23" style="font-size: 80%;"><b>Adapt the model to the Hudson Bay case</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec24" style="font-size: 80%;"><b>The program</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec25" style="font-size: 80%;"><b>The plot</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec26" style="font-size: 80%;"><b>Linear regression in Python</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec27" style="font-size: 80%;"><b>Linear Least squares in R</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec28" style="font-size: 80%;"><b>Non-Linear Least squares in R</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec29" style="font-size: 80%;"><b>Example: ecoli lab experiment</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec30" style="font-size: 80%;"><b>The program</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec31" style="font-size: 80%;"><b>The output</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec32" style="font-size: 80%;"><b>Parameter estimation</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec33" style="font-size: 80%;"><b>A program relevant for the biological problem</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec34" style="font-size: 80%;"><b>Simulating financial transcations</b></a></li>
<!-- navigation toc: --> <li><a href="#___sec35" style="font-size: 80%;">&nbsp;&nbsp;&nbsp;Simulation of Transactions</a></li>
<!-- navigation toc: --> <li><a href="#___sec36" style="font-size: 80%;"><b>Particle in one dimension an velocity distribution</b></a></li>
</ul>
</li>
@@ -195,7 +196,7 @@ MathJax.Hub.Config({
<div class="jumbotron">
<center><h1>Data Analysis and Machine Learning: Introduction and Representing data</h1></center> <!-- document title -->
<center><h1>Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</h1></center> <!-- document title -->
<p>
<!-- author(s): Morten Hjorth-Jensen -->
@@ -211,7 +212,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>May 11, 2018</h4></center> <!-- date -->
<center><h4>May 21, 2018</h4></center> <!-- date -->
<br>
<p>
<!-- potential-jumbotron-button -->
@@ -222,166 +223,7 @@ MathJax.Hub.Config({
<h2 id="___sec0" class="anchor">Introduction </h2>
<p>
Statistics, data science and machine learning form important fields of
research in modern science. They describe how to learn and make
predictions from data, as well allowing us to extract important
correlations about physical process and the underlying laws of motion
in large data sets. The latter, big data sets, appear
frequently in essentially all disciplines, from the traditional Science,
Technology, Mathematics and Engineering fields to Life Science, Law, education research,
the Humanities and
the Social Sciences. It has become more and more common to see
research projects on big data in for example the Social
Sciences where extracting patterns from complicated survey data is one of many research directions.
Having a solid grasp of data analysis and machine learning
is thus becoming central to scientific computing in many
fields, and competences and skills within the fields of machine learning
and scientific computing are nowadays strongly requested by many
potential employers. The latter cannot be overstated, familiarity with
machine learning has almost become a prerequisite for many of the most
exciting employment opportunities, whether they are in bioinformatics,
life science, physics or finance, in the private or the public
sector. This author has had several students or met students who have
been hired recently based on their skills and competences in
scientific computing and data science, often with marginal knowledge
of machine learning.
<p>
Machine learning is a subfield of computer science, and is closely
related to computational statistics. It evolved from the study of
pattern recognition in artificial intelligence (AI) research, and has
made contributions to AI tasks like computer vision, natural language
processing and speech recognition.
Machine learning represents the
science of giving computers the ability to learn without being
explicitly programmed. The idea is that there exist generic
algorithms which can be used to find patterns in a broad class of data
sets without having to write code specifically for each problem. The
algorithm will build its own logic based on the data.
<p>
Machine learning is an extremely rich field, in spite of its young age. The
increases we have seen during the last three decades in computational
capabilities have been followed by developments of methods and
techniques for analyzing and handling large date sets, relying heavily
on statistics, computer science and mathematics. The field is rather
new and developing rapidly. Popular software packages written in
Python for machine learning like <a href="http://scikit-learn.org/stable/" target="_self">Scikit-learn</a>, <a href="https://www.tensorflow.org/" target="_self">Tensorflow</a>,
<a href="http://pytorch.org/" target="_self">PyTorch</a> and <a href="https://keras.io/" target="_self">Keras</a>, all freely available at their respective GitHub sites,
encompass communities of developers in the thousands or more. And the number
of code developers and contributors keeps increasing. Not all the
algorithms and methods can be given a rigorous mathematical
justification, opening up thereby large rooms for experimenting
and trial and error and thereby exciting new developments.
However, a solid command of linear algebra, multivariate theory,
probability theory, statistical data analysis,
understanding errors and Monte Carlo methods are central elements in a proper understanding of many of
algorithms and methods we will discuss.
<p>
<!-- !split -->
<h2 id="___sec1" class="anchor">Learning outcomes </h2>
<p>
These lectures aim at giving you an overview of central aspects of
statistical data analysis as well as some of the central algorithms
used in machine learning. We will introduce a variety of central
algorithms and methods essential for studies of data analysis and
machine learning.
<p>
Hands-on projects and experimenting with data and algorithms plays a central role in
these lectures, and our hope is, through the various
projects and exercies, to expose you to fundamental
research problems in these fields, with the aim to reproduce state of
the art scientific results. You will learn to develop and
structure large codes for studying these systems, get acquainted with
computing facilities and learn to handle large scientific projects. A
good scientific and ethical conduct is emphasized throughout the
course. More specifically, you will
<ol>
<li> learn about basic data analysis, Bayesian statistics, Monte Carlo methods, data optimization and machine learning;</li>
<li> be capable of extending the acquired knowledge to other systems and cases;</li>
<li> Have an understanding of central algorithms used in data analysis and machine learning;</li>
<li> Gain knowledge of central aspects of Monte Carlo methods, Markov chains, Gibbs samplers and their possible applications, from numerical integration to simulation of stock markets;</li>
<li> Understand methods for regression and classification;</li>
<li> Learn about neural network, genetic algorithms and Boltzmann machines;</li>
<li> Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++, in addition to a basic knowledge of linear algebra (typically taught during the first one or two years of undergraduate studies).</li>
</ol>
There are several topics we will cover here, spanning from a
statistical data analysis and its basic concepts such expectation
values, variance, covariance, correlation functions and errors, via
well-known probability distribution functions like uniform
distribution, the binomial distribution, the Poisson distribution and
simple and multivariate normal distributions to central elements of
Bayesian statistics and modeling. We will also remind the reader about
central elements from linear algebra and standard methods based on
linear algebra used to fit functions such Cubic splines and gradient
methods for data optimization and the Singular-value decomposition and
least square methods for parameterizing data.
<p>
We will also cover Monte Carlo methods, Markov chains, well-known
algorithms for sampling stochastic events like the Metropolis-Hastings
and Gibbs sampling methods. An important aspect of all our
calculations is a proper estimation of errors. Here we will also
discuss famous resampling techniques like the blocking, bootstrapping
and jackknife methods.
<p>
The second part of the material covers several algorithms used in
machine learning.
<p>
<!-- !split -->
<h2 id="___sec2" class="anchor">Types of Machine Learning </h2>
<p>
The approaches to machine learning are many, but are often split into two main categories.
In <em>supervised learning</em> we know the answer to a problem,
and let the computer deduce the logic behind it. On the other hand, <em>unsupervised learning</em>
is a method for finding patterns and relationship in data sets without any prior knowledge of the system.
Some authours also operate with a third category, namely <em>reinforcement learning</em>. This is a paradigm
of learning inspired by behavioral psychology, where learning is achieved by trial-and-error,
solely from rewards and punishment.
<p>
Another way to categorize machine learning tasks is to consider the desired output of a system.
Some of the most common tasks are:
<ul>
<li> Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.</li>
<li> Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.</li>
<li> Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.</li>
</ul>
The methods we cover have three main topics in common, irrespective of
whether we deal with supervised or unsupervised learning. The first
ingredient is normally our data set, the second is a model which is
normally a function of some parameters. The last ingredient is a
so-called <b>cost</b> function which allows us to present an estimate on
how good our model is in reproducing the data it is supposed to train.
<p>
Here we will build our machine learning approach on elements of the
statistical foundation discussed above, with elements from data
analysis, stochastic processes etc. We will discuss the following
machine learning algorithms
<ol>
<li> Linear regression and its variants, in essence polynomial regression</li>
<li> Decision tree algorithms, from simpler to more complex ones</li>
<li> Nearest neighbors models</li>
<li> Bayesian statistics and regression</li>
<li> Support vector machines and finally various variants of</li>
<li> Artifical neural networks and deep learning</li>
</ol>
Before we proceed however, there are several practicalities with data
Before we proceed there are several practicalities with data
analysis and software tools we would like to present. These tools will
help us in our understanding of various machine learning algorithms.
@@ -407,7 +249,7 @@ Finally, our last example consists of economic data from the OECD.
<p>
<!-- !split -->
<h2 id="___sec3" class="anchor">Software and needed installations </h2>
<h2 id="___sec1" class="anchor">Software and needed installations </h2>
<p>
We will make intensive use of python as programming language and the myriad of available libraries.
@@ -444,7 +286,7 @@ etc etc.
<p>
<!-- !split -->
<h2 id="___sec4" class="anchor">Python installers </h2>
<h2 id="___sec2" class="anchor">Python installers </h2>
If you don't want to perform these operations separately, we recommend two widely used distrubutions which set up
all relevant dependencies for Python, namely
@@ -455,7 +297,7 @@ all relevant dependencies for Python, namely
<!-- !split -->
<h2 id="___sec5" class="anchor">Installing R, C++, cython or Julia </h2>
<h2 id="___sec3" class="anchor">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R.
@@ -468,7 +310,7 @@ To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-ke
<p>
<!-- !split -->
<h2 id="___sec6" class="anchor">Installing R, C++, cython or Julia </h2>
<h2 id="___sec4" class="anchor">Installing R, C++, cython or Julia </h2>
<p>
For the C++ aficionados, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
@@ -492,7 +334,7 @@ formats, ipython notebooks, latex files, pdf files etc.
<p>
<!-- !split -->
<h2 id="___sec7" class="anchor">Introduction to Jupyter notebook and available tools </h2>
<h2 id="___sec5" class="anchor">Introduction to Jupyter notebook and available tools </h2>
<p>
<div class="panel panel-default">
@@ -526,7 +368,7 @@ display(data_pandas)
<p>
<!-- !split -->
<h2 id="___sec8" class="anchor">Representing data, more examples </h2>
<h2 id="___sec6" class="anchor">Representing data, more examples </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
@@ -558,7 +400,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split -->
<h2 id="___sec9" class="anchor">Simple regression model </h2>
<h2 id="___sec7" class="anchor">Simple regression model </h2>
Add info about the equations
<p>
@@ -588,7 +430,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split -->
<h2 id="___sec10" class="anchor">Simple regression model, now using <b>scikit-learn</b> </h2>
<h2 id="___sec8" class="anchor">Simple regression model, now using <b>scikit-learn</b> </h2>
Add info about the equations
<p>
@@ -617,7 +459,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split -->
<h2 id="___sec11" class="anchor">Simple regression model with gradient descent </h2>
<h2 id="___sec9" class="anchor">Simple regression model with gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -661,7 +503,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split -->
<h2 id="___sec12" class="anchor">Simple regression model with stochastic gradient descent </h2>
<h2 id="___sec10" class="anchor">Simple regression model with stochastic gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -686,7 +528,7 @@ sgdreg<span style="color: #666666">.</span>fit(x,y<span style="color: #666666">.
<p>
<!-- !split -->
<h2 id="___sec13" class="anchor">Polynomial regression </h2>
<h2 id="___sec11" class="anchor">Polynomial regression </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
@@ -695,7 +537,7 @@ sgdreg<span style="color: #666666">.</span>fit(x,y<span style="color: #666666">.
<p>
<!-- !split -->
<h2 id="___sec14" class="anchor">Predator-Prey model from ecology </h2>
<h2 id="___sec12" class="anchor">Predator-Prey model from ecology </h2>
<p>
<div class="panel panel-default">
@@ -720,7 +562,7 @@ scientific method:
<p>
<!-- !split -->
<h2 id="___sec15" class="anchor">Case study from Hudson bay </h2>
<h2 id="___sec13" class="anchor">Case study from Hudson bay </h2>
<p>
<div class="panel panel-default">
@@ -742,7 +584,7 @@ Here we start by
<p>
<!-- !split -->
<h2 id="___sec16" class="anchor">Hudson bay data </h2>
<h2 id="___sec14" class="anchor">Hudson bay data </h2>
<p>
<div class="panel panel-default">
@@ -797,7 +639,7 @@ One reason that this particular system has been so extensively studied is that t
<p>
<!-- !split -->
<h2 id="___sec17" class="anchor">Plotting the data </h2>
<h2 id="___sec15" class="anchor">Plotting the data </h2>
<p>
<div class="panel panel-default">
@@ -834,7 +676,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split -->
<h2 id="___sec18" class="anchor">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<h2 id="___sec16" class="anchor">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
@@ -842,7 +684,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split -->
<h2 id="___sec19" class="anchor">Why now create a computer model for the hare and lynx populations? </h2>
<h2 id="___sec17" class="anchor">Why now create a computer model for the hare and lynx populations? </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
@@ -876,7 +718,7 @@ climate and other complicating factors. How significant are these?
<p>
<!-- !split -->
<h2 id="___sec20" class="anchor">The traditional (top-down) approach </h2>
<h2 id="___sec18" class="anchor">The traditional (top-down) approach </h2>
<p>
<div class="panel panel-default">
@@ -910,7 +752,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split -->
<h2 id="___sec21" class="anchor">Basic mathematics notation </h2>
<h2 id="___sec19" class="anchor">Basic mathematics notation </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
@@ -931,7 +773,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split -->
<h2 id="___sec22" class="anchor">Basic dynamics of the population of hares </h2>
<h2 id="___sec20" class="anchor">Basic dynamics of the population of hares </h2>
<p>
<div class="panel panel-default">
@@ -960,7 +802,7 @@ $$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
<p>
<!-- !split -->
<h2 id="___sec23" class="anchor">Basic dynamics of the population of lynx </h2>
<h2 id="___sec21" class="anchor">Basic dynamics of the population of lynx </h2>
<p>
<div class="panel panel-default">
@@ -991,7 +833,7 @@ $$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
<p>
<!-- !split -->
<h2 id="___sec24" class="anchor">Evolution equations </h2>
<h2 id="___sec22" class="anchor">Evolution equations </h2>
<p>
<div class="panel panel-default">
@@ -1021,7 +863,7 @@ Note:
<p>
<!-- !split -->
<h2 id="___sec25" class="anchor">Adapt the model to the Hudson Bay case </h2>
<h2 id="___sec23" class="anchor">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="panel panel-default">
@@ -1045,7 +887,7 @@ Note:
<p>
<!-- !split -->
<h2 id="___sec26" class="anchor">The program </h2>
<h2 id="___sec24" class="anchor">The program </h2>
<p>
<div class="panel panel-default">
@@ -1106,7 +948,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split -->
<h2 id="___sec27" class="anchor">The plot </h2>
<h2 id="___sec25" class="anchor">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
@@ -1117,7 +959,7 @@ If we perform a least-square fitting, we can find optimal values for the paramet
<p>
<!-- !split -->
<h2 id="___sec28" class="anchor">Linear regression in Python </h2>
<h2 id="___sec26" class="anchor">Linear regression in Python </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
@@ -1151,7 +993,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split -->
<h2 id="___sec29" class="anchor">Linear Least squares in R </h2>
<h2 id="___sec27" class="anchor">Linear Least squares in R </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
@@ -1186,7 +1028,7 @@ predict(linearMod,<span style="color: #B00040">data.frame</span>(Year<span style
<p>
<!-- !split -->
<h2 id="___sec30" class="anchor">Non-Linear Least squares in R </h2>
<h2 id="___sec28" class="anchor">Non-Linear Least squares in R </h2>
<div class="panel panel-default">
<div class="panel-body">
<p> <!-- subsequent paragraphs come in larger fonts, so start with a paragraph -->
@@ -1221,7 +1063,7 @@ text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</sp
<p>
<!-- !split -->
<h2 id="___sec31" class="anchor">Example: ecoli lab experiment </h2>
<h2 id="___sec29" class="anchor">Example: ecoli lab experiment </h2>
<p>
<div class="panel panel-primary">
@@ -1259,7 +1101,7 @@ The population grows faster and faster. <a href="http://www.zo.utexas.edu/course
<p>
<!-- !split -->
<h2 id="___sec32" class="anchor">The program </h2>
<h2 id="___sec30" class="anchor">The program </h2>
<p>
<div class="panel panel-default">
@@ -1293,7 +1135,7 @@ r <span style="color: #666666">=</span> <span style="color: #666666">0.5</span>
% if FORMAT != 'ipynb':
<!-- !split -->
<h2 id="___sec33" class="anchor">The output </h2>
<h2 id="___sec31" class="anchor">The output </h2>
<p>
@@ -1325,7 +1167,7 @@ N[20]=86.7
<p>
<!-- !split -->
<h2 id="___sec34" class="anchor">Parameter estimation </h2>
<h2 id="___sec32" class="anchor">Parameter estimation </h2>
<p>
<div class="panel panel-default">
@@ -1355,7 +1197,7 @@ Use experimental data in the fraction, say \( t_1=600 \), \( t_2=1200 \),
<p>
<!-- !split -->
<h2 id="___sec35" class="anchor">A program relevant for the biological problem </h2>
<h2 id="___sec33" class="anchor">A program relevant for the biological problem </h2>
<p>
<!-- exact r = 0.000694 -->
@@ -1404,7 +1246,7 @@ Change <code>r</code> in the program and play around to make a better fit!
<p>
<!-- !split -->
<h2 id="___sec36" class="anchor">Simulating financial transcations </h2>
<h2 id="___sec34" class="anchor">Simulating financial transcations </h2>
<p>
The aim here is to simulate financial transactions among financial agents
@@ -1478,7 +1320,7 @@ exponentially decreases with \( m' \).
We assume that we have \( N=500 \) agents. In each simulation, we need a sufficiently large number of transactions, say \( 10^7 \). Our aim is find the final equilibrium distribution \( w_m \). In order to do that we would need
several runs of the above simulations, at least \( 10^3-10^4 \) runs (experiments).
<h3 id="___sec37" class="anchor">Simulation of Transactions </h3>
<h3 id="___sec35" class="anchor">Simulation of Transactions </h3>
Our task is to first set up an algorithm which simulates the above transactions with an initial
amount \( m_0 \).
@@ -1606,7 +1448,60 @@ $$
p_{ij} \propto \vert m_i-m_j\vert^{-\alpha}\left(c_{ij}+1\right)^{\gamma},
$$
where \( c_{ij} \) represents the number of previous interactions that have taken place between \( i \) and \( j \). The factor \( 1 \) is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with \( N=1000 \), \( \alpha=1.0 \) and \( \alpha=2.0 \) using \( \gamma = 0.0, 1.0, 2.0, 3.0 \) and \( 4.0 \). Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving \( \lambda \) in each transaction. Comment your results and compare them with figures 5 and 6 of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_self">Goswami and Sen</a>.
where \( c_{ij} \) represents the number of previous interactions that have taken place between \( i \) and \( j \). The factor \( 1 \) is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with \( N=1000 \), \( \alpha=1.0 \) and \( \alpha=2.0 \) using \( \gamma = 0.0, 1.0, 2.0, 3.0 \) and \( 4.0 \). Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving \( \lambda \) in each transaction. Comment your results and compare them with figures 5 and 6 of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_self">Goswami and Sen</a>.
<p>
<!-- !split -->
<h2 id="___sec36" class="anchor">Particle in one dimension an velocity distribution </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Program to test the Metropolis algorithm with one particle at given temp in one dimension</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.mlab</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">mlab</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">random</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">math</span> <span style="color: #008000; font-weight: bold">import</span> sqrt, exp, log
<span style="color: #408080; font-style: italic"># initialize the rng with a seed</span>
random<span style="color: #666666">.</span>seed()
<span style="color: #408080; font-style: italic"># Hard coding of input parameters</span>
MCcycles <span style="color: #666666">=</span> <span style="color: #666666">100000</span>
Temperature <span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
beta <span style="color: #666666">=</span> <span style="color: #666666">1./</span>Temperature
InitialVelocity <span style="color: #666666">=</span> <span style="color: #666666">-2.0</span>
CurrentVelocity <span style="color: #666666">=</span> InitialVelocity
Energy <span style="color: #666666">=</span> <span style="color: #666666">0.5*</span>InitialVelocity<span style="color: #666666">*</span>InitialVelocity
VelocityRange <span style="color: #666666">=</span> <span style="color: #666666">10*</span>sqrt(Temperature)
VelocityStep <span style="color: #666666">=</span> <span style="color: #666666">2*</span>VelocityRange<span style="color: #666666">/10.</span>
AverageEnergy <span style="color: #666666">=</span> Energy
AverageEnergy2 <span style="color: #666666">=</span> Energy<span style="color: #666666">*</span>Energy
VelocityValues <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(MCcycles)
<span style="color: #408080; font-style: italic"># The Monte Carlo sampling with Metropolis starts here</span>
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span> (<span style="color: #666666">1</span>, MCcycles, <span style="color: #666666">1</span>):
TrialVelocity <span style="color: #666666">=</span> CurrentVelocity <span style="color: #666666">+</span> (<span style="color: #666666">2.0*</span>random<span style="color: #666666">.</span>random() <span style="color: #666666">-</span> <span style="color: #666666">1.0</span>)<span style="color: #666666">*</span>VelocityStep
EnergyChange <span style="color: #666666">=</span> <span style="color: #666666">0.5*</span>(TrialVelocity<span style="color: #666666">*</span>TrialVelocity <span style="color: #666666">-</span>CurrentVelocity<span style="color: #666666">*</span>CurrentVelocity);
<span style="color: #008000; font-weight: bold">if</span> random<span style="color: #666666">.</span>random() <span style="color: #666666">&lt;=</span> exp(<span style="color: #666666">-</span>beta<span style="color: #666666">*</span>EnergyChange):
CurrentVelocity <span style="color: #666666">=</span> TrialVelocity
Energy <span style="color: #666666">+=</span> EnergyChange
VelocityValues[i] <span style="color: #666666">=</span> CurrentVelocity
AverageEnergy <span style="color: #666666">+=</span> Energy
AverageEnergy2 <span style="color: #666666">+=</span> Energy<span style="color: #666666">*</span>Energy
<span style="color: #408080; font-style: italic">#Final averages</span>
AverageEnergy <span style="color: #666666">=</span> AverageEnergy<span style="color: #666666">/</span>MCcycles
AverageEnergy2 <span style="color: #666666">=</span> AverageEnergy2<span style="color: #666666">/</span>MCcycles
Variance <span style="color: #666666">=</span> AverageEnergy2 <span style="color: #666666">-</span> AverageEnergy<span style="color: #666666">*</span>AverageEnergy
<span style="color: #008000; font-weight: bold">print</span>(AverageEnergy, Variance)
n, bins, patches <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>hist(VelocityValues, <span style="color: #666666">400</span>, facecolor<span style="color: #666666">=</span><span style="color: #BA2121">&#39;green&#39;</span>)
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">&#39;$v$&#39;</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">&#39;Velocity distribution P(v)&#39;</span>)
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r&#39;Velocity histogram at $k_BT=2$&#39;</span>)
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">-5</span>, <span style="color: #666666">5</span>, <span style="color: #666666">0</span>, <span style="color: #666666">600</span>])
plt<span style="color: #666666">.</span>grid(<span style="color: #008000">True</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
<!-- ------------------- end of main content --------------- -->
@@ -3,9 +3,9 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<meta name="description" content="Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<title>Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</title>
@@ -132,7 +132,7 @@ MathJax.Hub.Config({
<center><h1 style="text-align: center;">Data Analysis and Machine Learning: Introduction and Representing data</h1></center> <!-- document title -->
<center><h1 style="text-align: center;">Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</h1></center> <!-- document title -->
<p>
<!-- author(s): Morten Hjorth-Jensen -->
@@ -148,7 +148,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>&nbsp;<br>
<center><h4>May 11, 2018</h4></center> <!-- date -->
<center><h4>May 21, 2018</h4></center> <!-- date -->
<br>
<p>
@@ -162,172 +162,7 @@ MathJax.Hub.Config({
<h2 id="___sec0">Introduction </h2>
<p>
Statistics, data science and machine learning form important fields of
research in modern science. They describe how to learn and make
predictions from data, as well allowing us to extract important
correlations about physical process and the underlying laws of motion
in large data sets. The latter, big data sets, appear
frequently in essentially all disciplines, from the traditional Science,
Technology, Mathematics and Engineering fields to Life Science, Law, education research,
the Humanities and
the Social Sciences. It has become more and more common to see
research projects on big data in for example the Social
Sciences where extracting patterns from complicated survey data is one of many research directions.
Having a solid grasp of data analysis and machine learning
is thus becoming central to scientific computing in many
fields, and competences and skills within the fields of machine learning
and scientific computing are nowadays strongly requested by many
potential employers. The latter cannot be overstated, familiarity with
machine learning has almost become a prerequisite for many of the most
exciting employment opportunities, whether they are in bioinformatics,
life science, physics or finance, in the private or the public
sector. This author has had several students or met students who have
been hired recently based on their skills and competences in
scientific computing and data science, often with marginal knowledge
of machine learning.
<p>
Machine learning is a subfield of computer science, and is closely
related to computational statistics. It evolved from the study of
pattern recognition in artificial intelligence (AI) research, and has
made contributions to AI tasks like computer vision, natural language
processing and speech recognition.
Machine learning represents the
science of giving computers the ability to learn without being
explicitly programmed. The idea is that there exist generic
algorithms which can be used to find patterns in a broad class of data
sets without having to write code specifically for each problem. The
algorithm will build its own logic based on the data.
<p>
Machine learning is an extremely rich field, in spite of its young age. The
increases we have seen during the last three decades in computational
capabilities have been followed by developments of methods and
techniques for analyzing and handling large date sets, relying heavily
on statistics, computer science and mathematics. The field is rather
new and developing rapidly. Popular software packages written in
Python for machine learning like <a href="http://scikit-learn.org/stable/" target="_blank">Scikit-learn</a>, <a href="https://www.tensorflow.org/" target="_blank">Tensorflow</a>,
<a href="http://pytorch.org/" target="_blank">PyTorch</a> and <a href="https://keras.io/" target="_blank">Keras</a>, all freely available at their respective GitHub sites,
encompass communities of developers in the thousands or more. And the number
of code developers and contributors keeps increasing. Not all the
algorithms and methods can be given a rigorous mathematical
justification, opening up thereby large rooms for experimenting
and trial and error and thereby exciting new developments.
However, a solid command of linear algebra, multivariate theory,
probability theory, statistical data analysis,
understanding errors and Monte Carlo methods are central elements in a proper understanding of many of
algorithms and methods we will discuss.
</section>
<section>
<h2 id="___sec1">Learning outcomes </h2>
<p>
These lectures aim at giving you an overview of central aspects of
statistical data analysis as well as some of the central algorithms
used in machine learning. We will introduce a variety of central
algorithms and methods essential for studies of data analysis and
machine learning.
<p>
Hands-on projects and experimenting with data and algorithms plays a central role in
these lectures, and our hope is, through the various
projects and exercies, to expose you to fundamental
research problems in these fields, with the aim to reproduce state of
the art scientific results. You will learn to develop and
structure large codes for studying these systems, get acquainted with
computing facilities and learn to handle large scientific projects. A
good scientific and ethical conduct is emphasized throughout the
course. More specifically, you will
<ol>
<p><li> learn about basic data analysis, Bayesian statistics, Monte Carlo methods, data optimization and machine learning;</li>
<p><li> be capable of extending the acquired knowledge to other systems and cases;</li>
<p><li> Have an understanding of central algorithms used in data analysis and machine learning;</li>
<p><li> Gain knowledge of central aspects of Monte Carlo methods, Markov chains, Gibbs samplers and their possible applications, from numerical integration to simulation of stock markets;</li>
<p><li> Understand methods for regression and classification;</li>
<p><li> Learn about neural network, genetic algorithms and Boltzmann machines;</li>
<p><li> Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++, in addition to a basic knowledge of linear algebra (typically taught during the first one or two years of undergraduate studies).</li>
</ol>
<p>
There are several topics we will cover here, spanning from a
statistical data analysis and its basic concepts such expectation
values, variance, covariance, correlation functions and errors, via
well-known probability distribution functions like uniform
distribution, the binomial distribution, the Poisson distribution and
simple and multivariate normal distributions to central elements of
Bayesian statistics and modeling. We will also remind the reader about
central elements from linear algebra and standard methods based on
linear algebra used to fit functions such Cubic splines and gradient
methods for data optimization and the Singular-value decomposition and
least square methods for parameterizing data.
<p>
We will also cover Monte Carlo methods, Markov chains, well-known
algorithms for sampling stochastic events like the Metropolis-Hastings
and Gibbs sampling methods. An important aspect of all our
calculations is a proper estimation of errors. Here we will also
discuss famous resampling techniques like the blocking, bootstrapping
and jackknife methods.
<p>
The second part of the material covers several algorithms used in
machine learning.
</section>
<section>
<h2 id="___sec2">Types of Machine Learning </h2>
<p>
The approaches to machine learning are many, but are often split into two main categories.
In <em>supervised learning</em> we know the answer to a problem,
and let the computer deduce the logic behind it. On the other hand, <em>unsupervised learning</em>
is a method for finding patterns and relationship in data sets without any prior knowledge of the system.
Some authours also operate with a third category, namely <em>reinforcement learning</em>. This is a paradigm
of learning inspired by behavioral psychology, where learning is achieved by trial-and-error,
solely from rewards and punishment.
<p>
Another way to categorize machine learning tasks is to consider the desired output of a system.
Some of the most common tasks are:
<ul>
<p><li> Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.</li>
<p><li> Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.</li>
<p><li> Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.</li>
</ul>
<p>
The methods we cover have three main topics in common, irrespective of
whether we deal with supervised or unsupervised learning. The first
ingredient is normally our data set, the second is a model which is
normally a function of some parameters. The last ingredient is a
so-called <b>cost</b> function which allows us to present an estimate on
how good our model is in reproducing the data it is supposed to train.
<p>
Here we will build our machine learning approach on elements of the
statistical foundation discussed above, with elements from data
analysis, stochastic processes etc. We will discuss the following
machine learning algorithms
<ol>
<p><li> Linear regression and its variants, in essence polynomial regression</li>
<p><li> Decision tree algorithms, from simpler to more complex ones</li>
<p><li> Nearest neighbors models</li>
<p><li> Bayesian statistics and regression</li>
<p><li> Support vector machines and finally various variants of</li>
<p><li> Artifical neural networks and deep learning</li>
</ol>
<p>
Before we proceed however, there are several practicalities with data
Before we proceed there are several practicalities with data
analysis and software tools we would like to present. These tools will
help us in our understanding of various machine learning algorithms.
@@ -353,7 +188,7 @@ Finally, our last example consists of economic data from the OECD.
<section>
<h2 id="___sec3">Software and needed installations </h2>
<h2 id="___sec1">Software and needed installations </h2>
<p>
We will make intensive use of python as programming language and the myriad of available libraries.
@@ -393,7 +228,7 @@ etc etc.
<section>
<h2 id="___sec4">Python installers </h2>
<h2 id="___sec2">Python installers </h2>
If you don't want to perform these operations separately, we recommend two widely used distrubutions which set up
all relevant dependencies for Python, namely
@@ -405,7 +240,7 @@ all relevant dependencies for Python, namely
<section>
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<h2 id="___sec3">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R.
@@ -418,7 +253,7 @@ To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-ke
<section>
<h2 id="___sec6">Installing R, C++, cython or Julia </h2>
<h2 id="___sec4">Installing R, C++, cython or Julia </h2>
<p>
For the C++ aficionados, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
@@ -442,7 +277,7 @@ formats, ipython notebooks, latex files, pdf files etc.
<section>
<h2 id="___sec7">Introduction to Jupyter notebook and available tools </h2>
<h2 id="___sec5">Introduction to Jupyter notebook and available tools </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -473,7 +308,7 @@ display(data_pandas)
<section>
<h2 id="___sec8">Representing data, more examples </h2>
<h2 id="___sec6">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -502,7 +337,7 @@ plt.show()
<section>
<h2 id="___sec9">Simple regression model </h2>
<h2 id="___sec7">Simple regression model </h2>
Add info about the equations
<p>
@@ -533,7 +368,7 @@ plt.show()
<section>
<h2 id="___sec10">Simple regression model, now using <b>scikit-learn</b> </h2>
<h2 id="___sec8">Simple regression model, now using <b>scikit-learn</b> </h2>
Add info about the equations
<p>
@@ -563,7 +398,7 @@ plt.show()
<section>
<h2 id="___sec11">Simple regression model with gradient descent </h2>
<h2 id="___sec9">Simple regression model with gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -608,7 +443,7 @@ plt.show()
<section>
<h2 id="___sec12">Simple regression model with stochastic gradient descent </h2>
<h2 id="___sec10">Simple regression model with stochastic gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -634,7 +469,7 @@ sgdreg.fit(x,y.ravel())
<section>
<h2 id="___sec13">Polynomial regression </h2>
<h2 id="___sec11">Polynomial regression </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
@@ -644,7 +479,7 @@ sgdreg.fit(x,y.ravel())
<section>
<h2 id="___sec14">Predator-Prey model from ecology </h2>
<h2 id="___sec12">Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -667,7 +502,7 @@ scientific method:
<section>
<h2 id="___sec15">Case study from Hudson bay </h2>
<h2 id="___sec13">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -687,7 +522,7 @@ Here we start by
<section>
<h2 id="___sec16">Hudson bay data </h2>
<h2 id="___sec14">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -733,7 +568,7 @@ One reason that this particular system has been so extensively studied is that t
<section>
<h2 id="___sec17">Plotting the data </h2>
<h2 id="___sec15">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -767,7 +602,7 @@ plt.show()
<section>
<h2 id="___sec18">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<h2 id="___sec16">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
@@ -775,7 +610,7 @@ plt.show()
<section>
<h2 id="___sec19">Why now create a computer model for the hare and lynx populations? </h2>
<h2 id="___sec17">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -807,7 +642,7 @@ climate and other complicating factors. How significant are these?
<section>
<h2 id="___sec20">The traditional (top-down) approach </h2>
<h2 id="___sec18">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -842,7 +677,7 @@ ODEs</em> (which cannot be solved)
<section>
<h2 id="___sec21">Basic mathematics notation </h2>
<h2 id="___sec19">Basic mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<ul>
@@ -859,7 +694,7 @@ ODEs</em> (which cannot be solved)
<section>
<h2 id="___sec22">Basic dynamics of the population of hares </h2>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -890,7 +725,7 @@ $$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
<section>
<h2 id="___sec23">Basic dynamics of the population of lynx </h2>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -919,7 +754,7 @@ $$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
<section>
<h2 id="___sec24">Evolution equations </h2>
<h2 id="___sec22">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -950,7 +785,7 @@ Note:
<section>
<h2 id="___sec25">Adapt the model to the Hudson Bay case </h2>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -970,7 +805,7 @@ Note:
<section>
<h2 id="___sec26">The program </h2>
<h2 id="___sec24">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1028,7 +863,7 @@ plt.show()
<section>
<h2 id="___sec27">The plot </h2>
<h2 id="___sec25">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
@@ -1039,7 +874,7 @@ If we perform a least-square fitting, we can find optimal values for the paramet
<section>
<h2 id="___sec28">Linear regression in Python </h2>
<h2 id="___sec26">Linear regression in Python </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1070,7 +905,7 @@ plt.show()
<section>
<h2 id="___sec29">Linear Least squares in R </h2>
<h2 id="___sec27">Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1102,7 +937,7 @@ predict(linearMod,<span style="color: #00688B; font-weight: bold">data.frame</sp
<section>
<h2 id="___sec30">Non-Linear Least squares in R </h2>
<h2 id="___sec28">Non-Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1134,7 +969,7 @@ text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</sp
<section>
<h2 id="___sec31">Example: ecoli lab experiment </h2>
<h2 id="___sec29">Example: ecoli lab experiment </h2>
<p>
<div class="alert alert-block alert-notice alert-text-normal">
@@ -1164,7 +999,7 @@ The population grows faster and faster. <a href="http://www.zo.utexas.edu/course
<section>
<h2 id="___sec32">The program </h2>
<h2 id="___sec30">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1198,7 +1033,7 @@ r = <span style="color: #B452CD">0.5</span>
<section>
<h2 id="___sec33">The output </h2>
<h2 id="___sec31">The output </h2>
<p>
@@ -1230,7 +1065,7 @@ N[20]=86.7
<section>
<h2 id="___sec34">Parameter estimation </h2>
<h2 id="___sec32">Parameter estimation </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1261,7 +1096,7 @@ Use experimental data in the fraction, say \( t_1=600 \), \( t_2=1200 \),
<section>
<h2 id="___sec35">A program relevant for the biological problem </h2>
<h2 id="___sec33">A program relevant for the biological problem </h2>
<p>
<!-- exact r = 0.000694 -->
@@ -1307,7 +1142,7 @@ Change <code>r</code> in the program and play around to make a better fit!
<section>
<h2 id="___sec36">Simulating financial transcations </h2>
<h2 id="___sec34">Simulating financial transcations </h2>
<p>
The aim here is to simulate financial transactions among financial agents
@@ -1393,7 +1228,7 @@ exponentially decreases with \( m' \).
We assume that we have \( N=500 \) agents. In each simulation, we need a sufficiently large number of transactions, say \( 10^7 \). Our aim is find the final equilibrium distribution \( w_m \). In order to do that we would need
several runs of the above simulations, at least \( 10^3-10^4 \) runs (experiments).
<h3 id="___sec37">Simulation of Transactions </h3>
<h3 id="___sec35">Simulation of Transactions </h3>
Our task is to first set up an algorithm which simulates the above transactions with an initial
amount \( m_0 \).
@@ -1541,6 +1376,58 @@ where \( c_{ij} \) represents the number of previous interactions that have tak
</section>
<section>
<h2 id="___sec36">Particle in one dimension an velocity distribution </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Program to test the Metropolis algorithm with one particle at given temp in one dimension</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.mlab</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">mlab</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">random</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">math</span> <span style="color: #8B008B; font-weight: bold">import</span> sqrt, exp, log
<span style="color: #228B22"># initialize the rng with a seed</span>
random.seed()
<span style="color: #228B22"># Hard coding of input parameters</span>
MCcycles = <span style="color: #B452CD">100000</span>
Temperature = <span style="color: #B452CD">2.0</span>
beta = <span style="color: #B452CD">1.</span>/Temperature
InitialVelocity = -<span style="color: #B452CD">2.0</span>
CurrentVelocity = InitialVelocity
Energy = <span style="color: #B452CD">0.5</span>*InitialVelocity*InitialVelocity
VelocityRange = <span style="color: #B452CD">10</span>*sqrt(Temperature)
VelocityStep = <span style="color: #B452CD">2</span>*VelocityRange/<span style="color: #B452CD">10.</span>
AverageEnergy = Energy
AverageEnergy2 = Energy*Energy
VelocityValues = np.zeros(MCcycles)
<span style="color: #228B22"># The Monte Carlo sampling with Metropolis starts here</span>
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span> (<span style="color: #B452CD">1</span>, MCcycles, <span style="color: #B452CD">1</span>):
TrialVelocity = CurrentVelocity + (<span style="color: #B452CD">2.0</span>*random.random() - <span style="color: #B452CD">1.0</span>)*VelocityStep
EnergyChange = <span style="color: #B452CD">0.5</span>*(TrialVelocity*TrialVelocity -CurrentVelocity*CurrentVelocity);
<span style="color: #8B008B; font-weight: bold">if</span> random.random() &lt;= exp(-beta*EnergyChange):
CurrentVelocity = TrialVelocity
Energy += EnergyChange
VelocityValues[i] = CurrentVelocity
AverageEnergy += Energy
AverageEnergy2 += Energy*Energy
<span style="color: #228B22">#Final averages</span>
AverageEnergy = AverageEnergy/MCcycles
AverageEnergy2 = AverageEnergy2/MCcycles
Variance = AverageEnergy2 - AverageEnergy*AverageEnergy
<span style="color: #8B008B; font-weight: bold">print</span>(AverageEnergy, Variance)
n, bins, patches = plt.hist(VelocityValues, <span style="color: #B452CD">400</span>, facecolor=<span style="color: #CD5555">&#39;green&#39;</span>)
plt.xlabel(<span style="color: #CD5555">&#39;$v$&#39;</span>)
plt.ylabel(<span style="color: #CD5555">&#39;Velocity distribution P(v)&#39;</span>)
plt.title(<span style="color: #CD5555">r&#39;Velocity histogram at $k_BT=2$&#39;</span>)
plt.axis([-<span style="color: #B452CD">5</span>, <span style="color: #B452CD">5</span>, <span style="color: #B452CD">0</span>, <span style="color: #B452CD">600</span>])
plt.grid(<span style="color: #658b00">True</span>)
plt.show()
</pre></div>
</section>
</div> <!-- class="slides" -->
</div> <!-- class="reveal" -->
@@ -6,9 +6,9 @@ Automatically generated HTML file from DocOnce source
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<meta name="description" content="Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<title>Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</title>
<link href="https://cdn.rawgit.com/hplgit/doconce/master/bundled/html_styles/style_solarized_box/css/solarized_light_code.css" rel="stylesheet" type="text/css" title="light"/>
@@ -61,68 +61,70 @@ div { text-align: justify; text-justify: inter-word; }
<!-- tocinfo
{'highest level': 2,
'sections': [('Introduction', 2, None, '___sec0'),
('Learning outcomes', 2, None, '___sec1'),
('Types of Machine Learning', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Software and needed installations', 2, None, '___sec1'),
('Python installers', 2, None, '___sec2'),
('Installing R, C++, cython or Julia', 2, None, '___sec3'),
('Installing R, C++, cython or Julia', 2, None, '___sec4'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Simple regression model', 2, None, '___sec9'),
'___sec5'),
('Representing data, more examples', 2, None, '___sec6'),
('Simple regression model', 2, None, '___sec7'),
('Simple regression model, now using _scikit-learn_',
2,
None,
'___sec10'),
'___sec8'),
('Simple regression model with gradient descent',
2,
None,
'___sec11'),
'___sec9'),
('Simple regression model with stochastic gradient descent',
2,
None,
'___sec12'),
('Polynomial regression', 2, None, '___sec13'),
('Predator-Prey model from ecology', 2, None, '___sec14'),
('Case study from Hudson bay', 2, None, '___sec15'),
('Hudson bay data', 2, None, '___sec16'),
('Plotting the data', 2, None, '___sec17'),
'___sec10'),
('Polynomial regression', 2, None, '___sec11'),
('Predator-Prey model from ecology', 2, None, '___sec12'),
('Case study from Hudson bay', 2, None, '___sec13'),
('Hudson bay data', 2, None, '___sec14'),
('Plotting the data', 2, None, '___sec15'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec18'),
'___sec16'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec19'),
('The traditional (top-down) approach', 2, None, '___sec20'),
('Basic mathematics notation', 2, None, '___sec21'),
'___sec17'),
('The traditional (top-down) approach', 2, None, '___sec18'),
('Basic mathematics notation', 2, None, '___sec19'),
('Basic dynamics of the population of hares',
2,
None,
'___sec22'),
('Basic dynamics of the population of lynx', 2, None, '___sec23'),
('Evolution equations', 2, None, '___sec24'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec25'),
('The program', 2, None, '___sec26'),
('The plot', 2, None, '___sec27'),
('Linear regression in Python', 2, None, '___sec28'),
('Linear Least squares in R', 2, None, '___sec29'),
('Non-Linear Least squares in R', 2, None, '___sec30'),
('Example: ecoli lab experiment', 2, None, '___sec31'),
('The program', 2, None, '___sec32'),
('The output', 2, None, '___sec33'),
('Parameter estimation', 2, None, '___sec34'),
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25'),
('Linear regression in Python', 2, None, '___sec26'),
('Linear Least squares in R', 2, None, '___sec27'),
('Non-Linear Least squares in R', 2, None, '___sec28'),
('Example: ecoli lab experiment', 2, None, '___sec29'),
('The program', 2, None, '___sec30'),
('The output', 2, None, '___sec31'),
('Parameter estimation', 2, None, '___sec32'),
('A program relevant for the biological problem',
2,
None,
'___sec35'),
('Simulating financial transcations', 2, None, '___sec36'),
('Simulation of Transactions', 3, None, '___sec37')]}
'___sec33'),
('Simulating financial transcations', 2, None, '___sec34'),
('Simulation of Transactions', 3, None, '___sec35'),
('Particle in one dimension an velocity distribution',
2,
None,
'___sec36')]}
end of tocinfo -->
<body>
@@ -148,7 +150,7 @@ MathJax.Hub.Config({
<center><h1>Data Analysis and Machine Learning: Introduction and Representing data</h1></center> <!-- document title -->
<center><h1>Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</h1></center> <!-- document title -->
<p>
<!-- author(s): Morten Hjorth-Jensen -->
@@ -164,7 +166,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>May 11, 2018</h4></center> <!-- date -->
<center><h4>May 21, 2018</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -172,166 +174,7 @@ MathJax.Hub.Config({
<h2 id="___sec0">Introduction </h2>
<p>
Statistics, data science and machine learning form important fields of
research in modern science. They describe how to learn and make
predictions from data, as well allowing us to extract important
correlations about physical process and the underlying laws of motion
in large data sets. The latter, big data sets, appear
frequently in essentially all disciplines, from the traditional Science,
Technology, Mathematics and Engineering fields to Life Science, Law, education research,
the Humanities and
the Social Sciences. It has become more and more common to see
research projects on big data in for example the Social
Sciences where extracting patterns from complicated survey data is one of many research directions.
Having a solid grasp of data analysis and machine learning
is thus becoming central to scientific computing in many
fields, and competences and skills within the fields of machine learning
and scientific computing are nowadays strongly requested by many
potential employers. The latter cannot be overstated, familiarity with
machine learning has almost become a prerequisite for many of the most
exciting employment opportunities, whether they are in bioinformatics,
life science, physics or finance, in the private or the public
sector. This author has had several students or met students who have
been hired recently based on their skills and competences in
scientific computing and data science, often with marginal knowledge
of machine learning.
<p>
Machine learning is a subfield of computer science, and is closely
related to computational statistics. It evolved from the study of
pattern recognition in artificial intelligence (AI) research, and has
made contributions to AI tasks like computer vision, natural language
processing and speech recognition.
Machine learning represents the
science of giving computers the ability to learn without being
explicitly programmed. The idea is that there exist generic
algorithms which can be used to find patterns in a broad class of data
sets without having to write code specifically for each problem. The
algorithm will build its own logic based on the data.
<p>
Machine learning is an extremely rich field, in spite of its young age. The
increases we have seen during the last three decades in computational
capabilities have been followed by developments of methods and
techniques for analyzing and handling large date sets, relying heavily
on statistics, computer science and mathematics. The field is rather
new and developing rapidly. Popular software packages written in
Python for machine learning like <a href="http://scikit-learn.org/stable/" target="_blank">Scikit-learn</a>, <a href="https://www.tensorflow.org/" target="_blank">Tensorflow</a>,
<a href="http://pytorch.org/" target="_blank">PyTorch</a> and <a href="https://keras.io/" target="_blank">Keras</a>, all freely available at their respective GitHub sites,
encompass communities of developers in the thousands or more. And the number
of code developers and contributors keeps increasing. Not all the
algorithms and methods can be given a rigorous mathematical
justification, opening up thereby large rooms for experimenting
and trial and error and thereby exciting new developments.
However, a solid command of linear algebra, multivariate theory,
probability theory, statistical data analysis,
understanding errors and Monte Carlo methods are central elements in a proper understanding of many of
algorithms and methods we will discuss.
<p>
<!-- !split -->
<h2 id="___sec1">Learning outcomes </h2>
<p>
These lectures aim at giving you an overview of central aspects of
statistical data analysis as well as some of the central algorithms
used in machine learning. We will introduce a variety of central
algorithms and methods essential for studies of data analysis and
machine learning.
<p>
Hands-on projects and experimenting with data and algorithms plays a central role in
these lectures, and our hope is, through the various
projects and exercies, to expose you to fundamental
research problems in these fields, with the aim to reproduce state of
the art scientific results. You will learn to develop and
structure large codes for studying these systems, get acquainted with
computing facilities and learn to handle large scientific projects. A
good scientific and ethical conduct is emphasized throughout the
course. More specifically, you will
<ol>
<li> learn about basic data analysis, Bayesian statistics, Monte Carlo methods, data optimization and machine learning;</li>
<li> be capable of extending the acquired knowledge to other systems and cases;</li>
<li> Have an understanding of central algorithms used in data analysis and machine learning;</li>
<li> Gain knowledge of central aspects of Monte Carlo methods, Markov chains, Gibbs samplers and their possible applications, from numerical integration to simulation of stock markets;</li>
<li> Understand methods for regression and classification;</li>
<li> Learn about neural network, genetic algorithms and Boltzmann machines;</li>
<li> Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++, in addition to a basic knowledge of linear algebra (typically taught during the first one or two years of undergraduate studies).</li>
</ol>
There are several topics we will cover here, spanning from a
statistical data analysis and its basic concepts such expectation
values, variance, covariance, correlation functions and errors, via
well-known probability distribution functions like uniform
distribution, the binomial distribution, the Poisson distribution and
simple and multivariate normal distributions to central elements of
Bayesian statistics and modeling. We will also remind the reader about
central elements from linear algebra and standard methods based on
linear algebra used to fit functions such Cubic splines and gradient
methods for data optimization and the Singular-value decomposition and
least square methods for parameterizing data.
<p>
We will also cover Monte Carlo methods, Markov chains, well-known
algorithms for sampling stochastic events like the Metropolis-Hastings
and Gibbs sampling methods. An important aspect of all our
calculations is a proper estimation of errors. Here we will also
discuss famous resampling techniques like the blocking, bootstrapping
and jackknife methods.
<p>
The second part of the material covers several algorithms used in
machine learning.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec2">Types of Machine Learning </h2>
<p>
The approaches to machine learning are many, but are often split into two main categories.
In <em>supervised learning</em> we know the answer to a problem,
and let the computer deduce the logic behind it. On the other hand, <em>unsupervised learning</em>
is a method for finding patterns and relationship in data sets without any prior knowledge of the system.
Some authours also operate with a third category, namely <em>reinforcement learning</em>. This is a paradigm
of learning inspired by behavioral psychology, where learning is achieved by trial-and-error,
solely from rewards and punishment.
<p>
Another way to categorize machine learning tasks is to consider the desired output of a system.
Some of the most common tasks are:
<ul>
<li> Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.</li>
<li> Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.</li>
<li> Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.</li>
</ul>
The methods we cover have three main topics in common, irrespective of
whether we deal with supervised or unsupervised learning. The first
ingredient is normally our data set, the second is a model which is
normally a function of some parameters. The last ingredient is a
so-called <b>cost</b> function which allows us to present an estimate on
how good our model is in reproducing the data it is supposed to train.
<p>
Here we will build our machine learning approach on elements of the
statistical foundation discussed above, with elements from data
analysis, stochastic processes etc. We will discuss the following
machine learning algorithms
<ol>
<li> Linear regression and its variants, in essence polynomial regression</li>
<li> Decision tree algorithms, from simpler to more complex ones</li>
<li> Nearest neighbors models</li>
<li> Bayesian statistics and regression</li>
<li> Support vector machines and finally various variants of</li>
<li> Artifical neural networks and deep learning</li>
</ol>
Before we proceed however, there are several practicalities with data
Before we proceed there are several practicalities with data
analysis and software tools we would like to present. These tools will
help us in our understanding of various machine learning algorithms.
@@ -357,7 +200,7 @@ Finally, our last example consists of economic data from the OECD.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec3">Software and needed installations </h2>
<h2 id="___sec1">Software and needed installations </h2>
<p>
We will make intensive use of python as programming language and the myriad of available libraries.
@@ -394,7 +237,7 @@ etc etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec4">Python installers </h2>
<h2 id="___sec2">Python installers </h2>
If you don't want to perform these operations separately, we recommend two widely used distrubutions which set up
all relevant dependencies for Python, namely
@@ -405,7 +248,7 @@ all relevant dependencies for Python, namely
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<h2 id="___sec3">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R.
@@ -418,7 +261,7 @@ To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-ke
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec6">Installing R, C++, cython or Julia </h2>
<h2 id="___sec4">Installing R, C++, cython or Julia </h2>
<p>
For the C++ aficionados, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
@@ -442,7 +285,7 @@ formats, ipython notebooks, latex files, pdf files etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec7">Introduction to Jupyter notebook and available tools </h2>
<h2 id="___sec5">Introduction to Jupyter notebook and available tools </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -475,7 +318,7 @@ display(data_pandas)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec8">Representing data, more examples </h2>
<h2 id="___sec6">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -506,7 +349,7 @@ plt.show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec9">Simple regression model </h2>
<h2 id="___sec7">Simple regression model </h2>
Add info about the equations
<p>
@@ -536,7 +379,7 @@ plt.show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Simple regression model, now using <b>scikit-learn</b> </h2>
<h2 id="___sec8">Simple regression model, now using <b>scikit-learn</b> </h2>
Add info about the equations
<p>
@@ -565,7 +408,7 @@ plt.show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec11">Simple regression model with gradient descent </h2>
<h2 id="___sec9">Simple regression model with gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -609,7 +452,7 @@ plt.show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec12">Simple regression model with stochastic gradient descent </h2>
<h2 id="___sec10">Simple regression model with stochastic gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -634,7 +477,7 @@ sgdreg.fit(x,y.ravel())
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec13">Polynomial regression </h2>
<h2 id="___sec11">Polynomial regression </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
@@ -643,7 +486,7 @@ sgdreg.fit(x,y.ravel())
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec14">Predator-Prey model from ecology </h2>
<h2 id="___sec12">Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -667,7 +510,7 @@ scientific method:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">Case study from Hudson bay </h2>
<h2 id="___sec13">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -688,7 +531,7 @@ Here we start by
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Hudson bay data </h2>
<h2 id="___sec14">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -737,7 +580,7 @@ One reason that this particular system has been so extensively studied is that t
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">Plotting the data </h2>
<h2 id="___sec15">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -773,7 +616,7 @@ plt.show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec18">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<h2 id="___sec16">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
@@ -781,7 +624,7 @@ plt.show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec19">Why now create a computer model for the hare and lynx populations? </h2>
<h2 id="___sec17">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -814,7 +657,7 @@ climate and other complicating factors. How significant are these?
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec20">The traditional (top-down) approach </h2>
<h2 id="___sec18">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -847,7 +690,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec21">Basic mathematics notation </h2>
<h2 id="___sec19">Basic mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -867,7 +710,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec22">Basic dynamics of the population of hares </h2>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -895,7 +738,7 @@ $$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec23">Basic dynamics of the population of lynx </h2>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -924,7 +767,7 @@ $$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec24">Evolution equations </h2>
<h2 id="___sec22">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -953,7 +796,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec25">Adapt the model to the Hudson Bay case </h2>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -976,7 +819,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec26">The program </h2>
<h2 id="___sec24">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1036,7 +879,7 @@ plt.show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec27">The plot </h2>
<h2 id="___sec25">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
@@ -1047,7 +890,7 @@ If we perform a least-square fitting, we can find optimal values for the paramet
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec28">Linear regression in Python </h2>
<h2 id="___sec26">Linear regression in Python </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1080,7 +923,7 @@ plt.show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec29">Linear Least squares in R </h2>
<h2 id="___sec27">Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1114,7 +957,7 @@ predict(linearMod,<span style="color: #00688B; font-weight: bold">data.frame</sp
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec30">Non-Linear Least squares in R </h2>
<h2 id="___sec28">Non-Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1148,7 +991,7 @@ text(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">0.5</sp
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec31">Example: ecoli lab experiment </h2>
<h2 id="___sec29">Example: ecoli lab experiment </h2>
<p>
<div class="alert alert-block alert-notice alert-text-normal">
@@ -1181,7 +1024,7 @@ The population grows faster and faster. <a href="http://www.zo.utexas.edu/course
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec32">The program </h2>
<h2 id="___sec30">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1214,7 +1057,7 @@ r = <span style="color: #B452CD">0.5</span>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec33">The output </h2>
<h2 id="___sec31">The output </h2>
<p>
@@ -1246,7 +1089,7 @@ N[20]=86.7
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec34">Parameter estimation </h2>
<h2 id="___sec32">Parameter estimation </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1275,7 +1118,7 @@ Use experimental data in the fraction, say \( t_1=600 \), \( t_2=1200 \),
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec35">A program relevant for the biological problem </h2>
<h2 id="___sec33">A program relevant for the biological problem </h2>
<p>
<!-- exact r = 0.000694 -->
@@ -1323,7 +1166,7 @@ Change <code>r</code> in the program and play around to make a better fit!
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec36">Simulating financial transcations </h2>
<h2 id="___sec34">Simulating financial transcations </h2>
<p>
The aim here is to simulate financial transactions among financial agents
@@ -1397,7 +1240,7 @@ exponentially decreases with \( m' \).
We assume that we have \( N=500 \) agents. In each simulation, we need a sufficiently large number of transactions, say \( 10^7 \). Our aim is find the final equilibrium distribution \( w_m \). In order to do that we would need
several runs of the above simulations, at least \( 10^3-10^4 \) runs (experiments).
<h3 id="___sec37">Simulation of Transactions </h3>
<h3 id="___sec35">Simulation of Transactions </h3>
Our task is to first set up an algorithm which simulates the above transactions with an initial
amount \( m_0 \).
@@ -1525,7 +1368,60 @@ $$
p_{ij} \propto \vert m_i-m_j\vert^{-\alpha}\left(c_{ij}+1\right)^{\gamma},
$$
where \( c_{ij} \) represents the number of previous interactions that have taken place between \( i \) and \( j \). The factor \( 1 \) is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with \( N=1000 \), \( \alpha=1.0 \) and \( \alpha=2.0 \) using \( \gamma = 0.0, 1.0, 2.0, 3.0 \) and \( 4.0 \). Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving \( \lambda \) in each transaction. Comment your results and compare them with figures 5 and 6 of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_blank">Goswami and Sen</a>.
where \( c_{ij} \) represents the number of previous interactions that have taken place between \( i \) and \( j \). The factor \( 1 \) is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with \( N=1000 \), \( \alpha=1.0 \) and \( \alpha=2.0 \) using \( \gamma = 0.0, 1.0, 2.0, 3.0 \) and \( 4.0 \). Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving \( \lambda \) in each transaction. Comment your results and compare them with figures 5 and 6 of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_blank">Goswami and Sen</a>.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec36">Particle in one dimension an velocity distribution </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22"># Program to test the Metropolis algorithm with one particle at given temp in one dimension</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.mlab</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">mlab</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">matplotlib.pyplot</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">plt</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">random</span>
<span style="color: #8B008B; font-weight: bold">from</span> <span style="color: #008b45; text-decoration: underline">math</span> <span style="color: #8B008B; font-weight: bold">import</span> sqrt, exp, log
<span style="color: #228B22"># initialize the rng with a seed</span>
random.seed()
<span style="color: #228B22"># Hard coding of input parameters</span>
MCcycles = <span style="color: #B452CD">100000</span>
Temperature = <span style="color: #B452CD">2.0</span>
beta = <span style="color: #B452CD">1.</span>/Temperature
InitialVelocity = -<span style="color: #B452CD">2.0</span>
CurrentVelocity = InitialVelocity
Energy = <span style="color: #B452CD">0.5</span>*InitialVelocity*InitialVelocity
VelocityRange = <span style="color: #B452CD">10</span>*sqrt(Temperature)
VelocityStep = <span style="color: #B452CD">2</span>*VelocityRange/<span style="color: #B452CD">10.</span>
AverageEnergy = Energy
AverageEnergy2 = Energy*Energy
VelocityValues = np.zeros(MCcycles)
<span style="color: #228B22"># The Monte Carlo sampling with Metropolis starts here</span>
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span> (<span style="color: #B452CD">1</span>, MCcycles, <span style="color: #B452CD">1</span>):
TrialVelocity = CurrentVelocity + (<span style="color: #B452CD">2.0</span>*random.random() - <span style="color: #B452CD">1.0</span>)*VelocityStep
EnergyChange = <span style="color: #B452CD">0.5</span>*(TrialVelocity*TrialVelocity -CurrentVelocity*CurrentVelocity);
<span style="color: #8B008B; font-weight: bold">if</span> random.random() &lt;= exp(-beta*EnergyChange):
CurrentVelocity = TrialVelocity
Energy += EnergyChange
VelocityValues[i] = CurrentVelocity
AverageEnergy += Energy
AverageEnergy2 += Energy*Energy
<span style="color: #228B22">#Final averages</span>
AverageEnergy = AverageEnergy/MCcycles
AverageEnergy2 = AverageEnergy2/MCcycles
Variance = AverageEnergy2 - AverageEnergy*AverageEnergy
<span style="color: #8B008B; font-weight: bold">print</span>(AverageEnergy, Variance)
n, bins, patches = plt.hist(VelocityValues, <span style="color: #B452CD">400</span>, facecolor=<span style="color: #CD5555">&#39;green&#39;</span>)
plt.xlabel(<span style="color: #CD5555">&#39;$v$&#39;</span>)
plt.ylabel(<span style="color: #CD5555">&#39;Velocity distribution P(v)&#39;</span>)
plt.title(<span style="color: #CD5555">r&#39;Velocity histogram at $k_BT=2$&#39;</span>)
plt.axis([-<span style="color: #B452CD">5</span>, <span style="color: #B452CD">5</span>, <span style="color: #B452CD">0</span>, <span style="color: #B452CD">600</span>])
plt.grid(<span style="color: #658b00">True</span>)
plt.show()
</pre></div>
<p>
<!-- ------------------- end of main content --------------- -->
+133 -237
View File
@@ -6,9 +6,9 @@ Automatically generated HTML file from DocOnce source
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="DocOnce: https://github.com/hplgit/doconce/" />
<meta name="description" content="Data Analysis and Machine Learning: Introduction and Representing data">
<meta name="description" content="Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters">
<title>Data Analysis and Machine Learning: Introduction and Representing data</title>
<title>Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</title>
<style type="text/css">
@@ -66,68 +66,70 @@ div { text-align: justify; text-justify: inter-word; }
<!-- tocinfo
{'highest level': 2,
'sections': [('Introduction', 2, None, '___sec0'),
('Learning outcomes', 2, None, '___sec1'),
('Types of Machine Learning', 2, None, '___sec2'),
('Software and needed installations', 2, None, '___sec3'),
('Python installers', 2, None, '___sec4'),
('Installing R, C++, cython or Julia', 2, None, '___sec5'),
('Installing R, C++, cython or Julia', 2, None, '___sec6'),
('Software and needed installations', 2, None, '___sec1'),
('Python installers', 2, None, '___sec2'),
('Installing R, C++, cython or Julia', 2, None, '___sec3'),
('Installing R, C++, cython or Julia', 2, None, '___sec4'),
('Introduction to Jupyter notebook and available tools',
2,
None,
'___sec7'),
('Representing data, more examples', 2, None, '___sec8'),
('Simple regression model', 2, None, '___sec9'),
'___sec5'),
('Representing data, more examples', 2, None, '___sec6'),
('Simple regression model', 2, None, '___sec7'),
('Simple regression model, now using _scikit-learn_',
2,
None,
'___sec10'),
'___sec8'),
('Simple regression model with gradient descent',
2,
None,
'___sec11'),
'___sec9'),
('Simple regression model with stochastic gradient descent',
2,
None,
'___sec12'),
('Polynomial regression', 2, None, '___sec13'),
('Predator-Prey model from ecology', 2, None, '___sec14'),
('Case study from Hudson bay', 2, None, '___sec15'),
('Hudson bay data', 2, None, '___sec16'),
('Plotting the data', 2, None, '___sec17'),
'___sec10'),
('Polynomial regression', 2, None, '___sec11'),
('Predator-Prey model from ecology', 2, None, '___sec12'),
('Case study from Hudson bay', 2, None, '___sec13'),
('Hudson bay data', 2, None, '___sec14'),
('Plotting the data', 2, None, '___sec15'),
('Hares and lynx in Hudson bay from 1900 to 1920',
2,
None,
'___sec18'),
'___sec16'),
('Why now create a computer model for the hare and lynx '
'populations?',
2,
None,
'___sec19'),
('The traditional (top-down) approach', 2, None, '___sec20'),
('Basic mathematics notation', 2, None, '___sec21'),
'___sec17'),
('The traditional (top-down) approach', 2, None, '___sec18'),
('Basic mathematics notation', 2, None, '___sec19'),
('Basic dynamics of the population of hares',
2,
None,
'___sec22'),
('Basic dynamics of the population of lynx', 2, None, '___sec23'),
('Evolution equations', 2, None, '___sec24'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec25'),
('The program', 2, None, '___sec26'),
('The plot', 2, None, '___sec27'),
('Linear regression in Python', 2, None, '___sec28'),
('Linear Least squares in R', 2, None, '___sec29'),
('Non-Linear Least squares in R', 2, None, '___sec30'),
('Example: ecoli lab experiment', 2, None, '___sec31'),
('The program', 2, None, '___sec32'),
('The output', 2, None, '___sec33'),
('Parameter estimation', 2, None, '___sec34'),
'___sec20'),
('Basic dynamics of the population of lynx', 2, None, '___sec21'),
('Evolution equations', 2, None, '___sec22'),
('Adapt the model to the Hudson Bay case', 2, None, '___sec23'),
('The program', 2, None, '___sec24'),
('The plot', 2, None, '___sec25'),
('Linear regression in Python', 2, None, '___sec26'),
('Linear Least squares in R', 2, None, '___sec27'),
('Non-Linear Least squares in R', 2, None, '___sec28'),
('Example: ecoli lab experiment', 2, None, '___sec29'),
('The program', 2, None, '___sec30'),
('The output', 2, None, '___sec31'),
('Parameter estimation', 2, None, '___sec32'),
('A program relevant for the biological problem',
2,
None,
'___sec35'),
('Simulating financial transcations', 2, None, '___sec36'),
('Simulation of Transactions', 3, None, '___sec37')]}
'___sec33'),
('Simulating financial transcations', 2, None, '___sec34'),
('Simulation of Transactions', 3, None, '___sec35'),
('Particle in one dimension an velocity distribution',
2,
None,
'___sec36')]}
end of tocinfo -->
<body>
@@ -153,7 +155,7 @@ MathJax.Hub.Config({
<center><h1>Data Analysis and Machine Learning: Introduction and Representing data</h1></center> <!-- document title -->
<center><h1>Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters</h1></center> <!-- document title -->
<p>
<!-- author(s): Morten Hjorth-Jensen -->
@@ -169,7 +171,7 @@ MathJax.Hub.Config({
<center>[2] <b>Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University</b></center>
<br>
<p>
<center><h4>May 11, 2018</h4></center> <!-- date -->
<center><h4>May 21, 2018</h4></center> <!-- date -->
<br>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
@@ -177,166 +179,7 @@ MathJax.Hub.Config({
<h2 id="___sec0">Introduction </h2>
<p>
Statistics, data science and machine learning form important fields of
research in modern science. They describe how to learn and make
predictions from data, as well allowing us to extract important
correlations about physical process and the underlying laws of motion
in large data sets. The latter, big data sets, appear
frequently in essentially all disciplines, from the traditional Science,
Technology, Mathematics and Engineering fields to Life Science, Law, education research,
the Humanities and
the Social Sciences. It has become more and more common to see
research projects on big data in for example the Social
Sciences where extracting patterns from complicated survey data is one of many research directions.
Having a solid grasp of data analysis and machine learning
is thus becoming central to scientific computing in many
fields, and competences and skills within the fields of machine learning
and scientific computing are nowadays strongly requested by many
potential employers. The latter cannot be overstated, familiarity with
machine learning has almost become a prerequisite for many of the most
exciting employment opportunities, whether they are in bioinformatics,
life science, physics or finance, in the private or the public
sector. This author has had several students or met students who have
been hired recently based on their skills and competences in
scientific computing and data science, often with marginal knowledge
of machine learning.
<p>
Machine learning is a subfield of computer science, and is closely
related to computational statistics. It evolved from the study of
pattern recognition in artificial intelligence (AI) research, and has
made contributions to AI tasks like computer vision, natural language
processing and speech recognition.
Machine learning represents the
science of giving computers the ability to learn without being
explicitly programmed. The idea is that there exist generic
algorithms which can be used to find patterns in a broad class of data
sets without having to write code specifically for each problem. The
algorithm will build its own logic based on the data.
<p>
Machine learning is an extremely rich field, in spite of its young age. The
increases we have seen during the last three decades in computational
capabilities have been followed by developments of methods and
techniques for analyzing and handling large date sets, relying heavily
on statistics, computer science and mathematics. The field is rather
new and developing rapidly. Popular software packages written in
Python for machine learning like <a href="http://scikit-learn.org/stable/" target="_blank">Scikit-learn</a>, <a href="https://www.tensorflow.org/" target="_blank">Tensorflow</a>,
<a href="http://pytorch.org/" target="_blank">PyTorch</a> and <a href="https://keras.io/" target="_blank">Keras</a>, all freely available at their respective GitHub sites,
encompass communities of developers in the thousands or more. And the number
of code developers and contributors keeps increasing. Not all the
algorithms and methods can be given a rigorous mathematical
justification, opening up thereby large rooms for experimenting
and trial and error and thereby exciting new developments.
However, a solid command of linear algebra, multivariate theory,
probability theory, statistical data analysis,
understanding errors and Monte Carlo methods are central elements in a proper understanding of many of
algorithms and methods we will discuss.
<p>
<!-- !split -->
<h2 id="___sec1">Learning outcomes </h2>
<p>
These lectures aim at giving you an overview of central aspects of
statistical data analysis as well as some of the central algorithms
used in machine learning. We will introduce a variety of central
algorithms and methods essential for studies of data analysis and
machine learning.
<p>
Hands-on projects and experimenting with data and algorithms plays a central role in
these lectures, and our hope is, through the various
projects and exercies, to expose you to fundamental
research problems in these fields, with the aim to reproduce state of
the art scientific results. You will learn to develop and
structure large codes for studying these systems, get acquainted with
computing facilities and learn to handle large scientific projects. A
good scientific and ethical conduct is emphasized throughout the
course. More specifically, you will
<ol>
<li> learn about basic data analysis, Bayesian statistics, Monte Carlo methods, data optimization and machine learning;</li>
<li> be capable of extending the acquired knowledge to other systems and cases;</li>
<li> Have an understanding of central algorithms used in data analysis and machine learning;</li>
<li> Gain knowledge of central aspects of Monte Carlo methods, Markov chains, Gibbs samplers and their possible applications, from numerical integration to simulation of stock markets;</li>
<li> Understand methods for regression and classification;</li>
<li> Learn about neural network, genetic algorithms and Boltzmann machines;</li>
<li> Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++, in addition to a basic knowledge of linear algebra (typically taught during the first one or two years of undergraduate studies).</li>
</ol>
There are several topics we will cover here, spanning from a
statistical data analysis and its basic concepts such expectation
values, variance, covariance, correlation functions and errors, via
well-known probability distribution functions like uniform
distribution, the binomial distribution, the Poisson distribution and
simple and multivariate normal distributions to central elements of
Bayesian statistics and modeling. We will also remind the reader about
central elements from linear algebra and standard methods based on
linear algebra used to fit functions such Cubic splines and gradient
methods for data optimization and the Singular-value decomposition and
least square methods for parameterizing data.
<p>
We will also cover Monte Carlo methods, Markov chains, well-known
algorithms for sampling stochastic events like the Metropolis-Hastings
and Gibbs sampling methods. An important aspect of all our
calculations is a proper estimation of errors. Here we will also
discuss famous resampling techniques like the blocking, bootstrapping
and jackknife methods.
<p>
The second part of the material covers several algorithms used in
machine learning.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec2">Types of Machine Learning </h2>
<p>
The approaches to machine learning are many, but are often split into two main categories.
In <em>supervised learning</em> we know the answer to a problem,
and let the computer deduce the logic behind it. On the other hand, <em>unsupervised learning</em>
is a method for finding patterns and relationship in data sets without any prior knowledge of the system.
Some authours also operate with a third category, namely <em>reinforcement learning</em>. This is a paradigm
of learning inspired by behavioral psychology, where learning is achieved by trial-and-error,
solely from rewards and punishment.
<p>
Another way to categorize machine learning tasks is to consider the desired output of a system.
Some of the most common tasks are:
<ul>
<li> Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.</li>
<li> Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.</li>
<li> Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.</li>
</ul>
The methods we cover have three main topics in common, irrespective of
whether we deal with supervised or unsupervised learning. The first
ingredient is normally our data set, the second is a model which is
normally a function of some parameters. The last ingredient is a
so-called <b>cost</b> function which allows us to present an estimate on
how good our model is in reproducing the data it is supposed to train.
<p>
Here we will build our machine learning approach on elements of the
statistical foundation discussed above, with elements from data
analysis, stochastic processes etc. We will discuss the following
machine learning algorithms
<ol>
<li> Linear regression and its variants, in essence polynomial regression</li>
<li> Decision tree algorithms, from simpler to more complex ones</li>
<li> Nearest neighbors models</li>
<li> Bayesian statistics and regression</li>
<li> Support vector machines and finally various variants of</li>
<li> Artifical neural networks and deep learning</li>
</ol>
Before we proceed however, there are several practicalities with data
Before we proceed there are several practicalities with data
analysis and software tools we would like to present. These tools will
help us in our understanding of various machine learning algorithms.
@@ -362,7 +205,7 @@ Finally, our last example consists of economic data from the OECD.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec3">Software and needed installations </h2>
<h2 id="___sec1">Software and needed installations </h2>
<p>
We will make intensive use of python as programming language and the myriad of available libraries.
@@ -399,7 +242,7 @@ etc etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec4">Python installers </h2>
<h2 id="___sec2">Python installers </h2>
If you don't want to perform these operations separately, we recommend two widely used distrubutions which set up
all relevant dependencies for Python, namely
@@ -410,7 +253,7 @@ all relevant dependencies for Python, namely
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec5">Installing R, C++, cython or Julia </h2>
<h2 id="___sec3">Installing R, C++, cython or Julia </h2>
<p>
You will also find it convenient to utilize R.
@@ -423,7 +266,7 @@ To install <b>R</b> with Jupyter notebook <a href="https://mpacer.org/maths/r-ke
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec6">Installing R, C++, cython or Julia </h2>
<h2 id="___sec4">Installing R, C++, cython or Julia </h2>
<p>
For the C++ aficionados, Jupyter/IPython notebook allows you also to install C++ and run codes written in this language
@@ -447,7 +290,7 @@ formats, ipython notebooks, latex files, pdf files etc.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec7">Introduction to Jupyter notebook and available tools </h2>
<h2 id="___sec5">Introduction to Jupyter notebook and available tools </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -480,7 +323,7 @@ display(data_pandas)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec8">Representing data, more examples </h2>
<h2 id="___sec6">Representing data, more examples </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -511,7 +354,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec9">Simple regression model </h2>
<h2 id="___sec7">Simple regression model </h2>
Add info about the equations
<p>
@@ -541,7 +384,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Simple regression model, now using <b>scikit-learn</b> </h2>
<h2 id="___sec8">Simple regression model, now using <b>scikit-learn</b> </h2>
Add info about the equations
<p>
@@ -570,7 +413,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec11">Simple regression model with gradient descent </h2>
<h2 id="___sec9">Simple regression model with gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -614,7 +457,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec12">Simple regression model with stochastic gradient descent </h2>
<h2 id="___sec10">Simple regression model with stochastic gradient descent </h2>
Add info about the equations, play around with different learning rates
<p>
@@ -639,7 +482,7 @@ sgdreg<span style="color: #666666">.</span>fit(x,y<span style="color: #666666">.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec13">Polynomial regression </h2>
<h2 id="___sec11">Polynomial regression </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
@@ -648,7 +491,7 @@ sgdreg<span style="color: #666666">.</span>fit(x,y<span style="color: #666666">.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec14">Predator-Prey model from ecology </h2>
<h2 id="___sec12">Predator-Prey model from ecology </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -672,7 +515,7 @@ scientific method:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">Case study from Hudson bay </h2>
<h2 id="___sec13">Case study from Hudson bay </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -693,7 +536,7 @@ Here we start by
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Hudson bay data </h2>
<h2 id="___sec14">Hudson bay data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -742,7 +585,7 @@ One reason that this particular system has been so extensively studied is that t
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">Plotting the data </h2>
<h2 id="___sec15">Plotting the data </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -778,7 +621,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec18">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<h2 id="___sec16">Hares and lynx in Hudson bay from 1900 to 1920 </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_data.png" align="bottom" width=700></p></center><br /><br />
@@ -786,7 +629,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec19">Why now create a computer model for the hare and lynx populations? </h2>
<h2 id="___sec17">Why now create a computer model for the hare and lynx populations? </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -819,7 +662,7 @@ climate and other complicating factors. How significant are these?
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec20">The traditional (top-down) approach </h2>
<h2 id="___sec18">The traditional (top-down) approach </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -852,7 +695,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec21">Basic mathematics notation </h2>
<h2 id="___sec19">Basic mathematics notation </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -872,7 +715,7 @@ ODEs</em> (which cannot be solved)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec22">Basic dynamics of the population of hares </h2>
<h2 id="___sec20">Basic dynamics of the population of hares </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -900,7 +743,7 @@ $$ \Delta H = a\Delta t H^n - b \Delta t H^nL^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec23">Basic dynamics of the population of lynx </h2>
<h2 id="___sec21">Basic dynamics of the population of lynx </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -929,7 +772,7 @@ $$ \Delta L = d\Delta t H^nL^n - c\Delta t L^n$$
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec24">Evolution equations </h2>
<h2 id="___sec22">Evolution equations </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -958,7 +801,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec25">Adapt the model to the Hudson Bay case </h2>
<h2 id="___sec23">Adapt the model to the Hudson Bay case </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -981,7 +824,7 @@ Note:
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec26">The program </h2>
<h2 id="___sec24">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1041,7 +884,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec27">The plot </h2>
<h2 id="___sec25">The plot </h2>
<p>
<br /><br /><center><p><img src="fig/Hudson_Bay_sim.png" align="bottom" width=700></p></center><br /><br />
@@ -1052,7 +895,7 @@ If we perform a least-square fitting, we can find optimal values for the paramet
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec28">Linear regression in Python </h2>
<h2 id="___sec26">Linear regression in Python </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1085,7 +928,7 @@ plt<span style="color: #666666">.</span>show()
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec29">Linear Least squares in R </h2>
<h2 id="___sec27">Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1119,7 +962,7 @@ predict(linearMod,<span style="color: #B00040">data.frame</span>(Year<span style
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec30">Non-Linear Least squares in R </h2>
<h2 id="___sec28">Non-Linear Least squares in R </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -1153,7 +996,7 @@ text(<span style="color: #666666">0</span>, <span style="color: #666666">0.5</sp
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec31">Example: ecoli lab experiment </h2>
<h2 id="___sec29">Example: ecoli lab experiment </h2>
<p>
<div class="alert alert-block alert-notice alert-text-normal">
@@ -1186,7 +1029,7 @@ The population grows faster and faster. <a href="http://www.zo.utexas.edu/course
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec32">The program </h2>
<h2 id="___sec30">The program </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1219,7 +1062,7 @@ r <span style="color: #666666">=</span> <span style="color: #666666">0.5</span>
% if FORMAT != 'ipynb':
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec33">The output </h2>
<h2 id="___sec31">The output </h2>
<p>
@@ -1251,7 +1094,7 @@ N[20]=86.7
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec34">Parameter estimation </h2>
<h2 id="___sec32">Parameter estimation </h2>
<p>
<div class="alert alert-block alert-block alert-text-normal">
@@ -1280,7 +1123,7 @@ Use experimental data in the fraction, say \( t_1=600 \), \( t_2=1200 \),
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec35">A program relevant for the biological problem </h2>
<h2 id="___sec33">A program relevant for the biological problem </h2>
<p>
<!-- exact r = 0.000694 -->
@@ -1328,7 +1171,7 @@ Change <code>r</code> in the program and play around to make a better fit!
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec36">Simulating financial transcations </h2>
<h2 id="___sec34">Simulating financial transcations </h2>
<p>
The aim here is to simulate financial transactions among financial agents
@@ -1402,7 +1245,7 @@ exponentially decreases with \( m' \).
We assume that we have \( N=500 \) agents. In each simulation, we need a sufficiently large number of transactions, say \( 10^7 \). Our aim is find the final equilibrium distribution \( w_m \). In order to do that we would need
several runs of the above simulations, at least \( 10^3-10^4 \) runs (experiments).
<h3 id="___sec37">Simulation of Transactions </h3>
<h3 id="___sec35">Simulation of Transactions </h3>
Our task is to first set up an algorithm which simulates the above transactions with an initial
amount \( m_0 \).
@@ -1530,7 +1373,60 @@ $$
p_{ij} \propto \vert m_i-m_j\vert^{-\alpha}\left(c_{ij}+1\right)^{\gamma},
$$
where \( c_{ij} \) represents the number of previous interactions that have taken place between \( i \) and \( j \). The factor \( 1 \) is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with \( N=1000 \), \( \alpha=1.0 \) and \( \alpha=2.0 \) using \( \gamma = 0.0, 1.0, 2.0, 3.0 \) and \( 4.0 \). Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving \( \lambda \) in each transaction. Comment your results and compare them with figures 5 and 6 of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_blank">Goswami and Sen</a>.
where \( c_{ij} \) represents the number of previous interactions that have taken place between \( i \) and \( j \). The factor \( 1 \) is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with \( N=1000 \), \( \alpha=1.0 \) and \( \alpha=2.0 \) using \( \gamma = 0.0, 1.0, 2.0, 3.0 \) and \( 4.0 \). Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving \( \lambda \) in each transaction. Comment your results and compare them with figures 5 and 6 of <a href="http://www.sciencedirect.com/science/article/pii/S0378437114006967" target="_blank">Goswami and Sen</a>.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec36">Particle in one dimension an velocity distribution </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Program to test the Metropolis algorithm with one particle at given temp in one dimension</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.mlab</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">mlab</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">matplotlib.pyplot</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">plt</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">random</span>
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">math</span> <span style="color: #008000; font-weight: bold">import</span> sqrt, exp, log
<span style="color: #408080; font-style: italic"># initialize the rng with a seed</span>
random<span style="color: #666666">.</span>seed()
<span style="color: #408080; font-style: italic"># Hard coding of input parameters</span>
MCcycles <span style="color: #666666">=</span> <span style="color: #666666">100000</span>
Temperature <span style="color: #666666">=</span> <span style="color: #666666">2.0</span>
beta <span style="color: #666666">=</span> <span style="color: #666666">1./</span>Temperature
InitialVelocity <span style="color: #666666">=</span> <span style="color: #666666">-2.0</span>
CurrentVelocity <span style="color: #666666">=</span> InitialVelocity
Energy <span style="color: #666666">=</span> <span style="color: #666666">0.5*</span>InitialVelocity<span style="color: #666666">*</span>InitialVelocity
VelocityRange <span style="color: #666666">=</span> <span style="color: #666666">10*</span>sqrt(Temperature)
VelocityStep <span style="color: #666666">=</span> <span style="color: #666666">2*</span>VelocityRange<span style="color: #666666">/10.</span>
AverageEnergy <span style="color: #666666">=</span> Energy
AverageEnergy2 <span style="color: #666666">=</span> Energy<span style="color: #666666">*</span>Energy
VelocityValues <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros(MCcycles)
<span style="color: #408080; font-style: italic"># The Monte Carlo sampling with Metropolis starts here</span>
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span> (<span style="color: #666666">1</span>, MCcycles, <span style="color: #666666">1</span>):
TrialVelocity <span style="color: #666666">=</span> CurrentVelocity <span style="color: #666666">+</span> (<span style="color: #666666">2.0*</span>random<span style="color: #666666">.</span>random() <span style="color: #666666">-</span> <span style="color: #666666">1.0</span>)<span style="color: #666666">*</span>VelocityStep
EnergyChange <span style="color: #666666">=</span> <span style="color: #666666">0.5*</span>(TrialVelocity<span style="color: #666666">*</span>TrialVelocity <span style="color: #666666">-</span>CurrentVelocity<span style="color: #666666">*</span>CurrentVelocity);
<span style="color: #008000; font-weight: bold">if</span> random<span style="color: #666666">.</span>random() <span style="color: #666666">&lt;=</span> exp(<span style="color: #666666">-</span>beta<span style="color: #666666">*</span>EnergyChange):
CurrentVelocity <span style="color: #666666">=</span> TrialVelocity
Energy <span style="color: #666666">+=</span> EnergyChange
VelocityValues[i] <span style="color: #666666">=</span> CurrentVelocity
AverageEnergy <span style="color: #666666">+=</span> Energy
AverageEnergy2 <span style="color: #666666">+=</span> Energy<span style="color: #666666">*</span>Energy
<span style="color: #408080; font-style: italic">#Final averages</span>
AverageEnergy <span style="color: #666666">=</span> AverageEnergy<span style="color: #666666">/</span>MCcycles
AverageEnergy2 <span style="color: #666666">=</span> AverageEnergy2<span style="color: #666666">/</span>MCcycles
Variance <span style="color: #666666">=</span> AverageEnergy2 <span style="color: #666666">-</span> AverageEnergy<span style="color: #666666">*</span>AverageEnergy
<span style="color: #008000; font-weight: bold">print</span>(AverageEnergy, Variance)
n, bins, patches <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>hist(VelocityValues, <span style="color: #666666">400</span>, facecolor<span style="color: #666666">=</span><span style="color: #BA2121">&#39;green&#39;</span>)
plt<span style="color: #666666">.</span>xlabel(<span style="color: #BA2121">&#39;$v$&#39;</span>)
plt<span style="color: #666666">.</span>ylabel(<span style="color: #BA2121">&#39;Velocity distribution P(v)&#39;</span>)
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">r&#39;Velocity histogram at $k_BT=2$&#39;</span>)
plt<span style="color: #666666">.</span>axis([<span style="color: #666666">-5</span>, <span style="color: #666666">5</span>, <span style="color: #666666">0</span>, <span style="color: #666666">600</span>])
plt<span style="color: #666666">.</span>grid(<span style="color: #008000">True</span>)
plt<span style="color: #666666">.</span>show()
</pre></div>
<p>
<!-- ------------------- end of main content --------------- -->
@@ -1,3 +1,8 @@
.idea/
*.iml
*.iws
*.eml
out/
.DS_Store
.svn
log/*.log
@@ -5,4 +10,4 @@ tmp/**
node_modules/
.sass-cache
css/reveal.min.css
js/reveal.min.js
js/reveal.min.js
@@ -1,5 +1,7 @@
language: node_js
node_js:
- 0.10
- 4
before_script:
- npm install -g grunt-cli
- npm install -g grunt-cli
after_script:
- grunt retire
+1 -1
View File
@@ -1,4 +1,4 @@
Copyright (C) 2015 Hakim El Hattab, http://hakim.se
Copyright (C) 2017 Hakim El Hattab, http://hakim.se, and reveal.js contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
+393 -199
View File
@@ -1,12 +1,58 @@
# reveal.js [![Build Status](https://travis-ci.org/hakimel/reveal.js.svg?branch=master)](https://travis-ci.org/hakimel/reveal.js)
# reveal.js [![Build Status](https://travis-ci.org/hakimel/reveal.js.svg?branch=master)](https://travis-ci.org/hakimel/reveal.js) <a href="https://slides.com?ref=github"><img src="https://s3.amazonaws.com/static.slid.es/images/slides-github-banner-320x40.png?1" alt="Slides" width="160" height="20"></a>
A framework for easily creating beautiful presentations using HTML. [Check out the live demo](http://lab.hakim.se/reveal-js/).
A framework for easily creating beautiful presentations using HTML. [Check out the live demo](http://revealjs.com/).
reveal.js comes with a broad range of features including [nested slides](https://github.com/hakimel/reveal.js#markup), [Markdown contents](https://github.com/hakimel/reveal.js#markdown), [PDF export](https://github.com/hakimel/reveal.js#pdf-export), [speaker notes](https://github.com/hakimel/reveal.js#speaker-notes) and a [JavaScript API](https://github.com/hakimel/reveal.js#api). It's best viewed in a modern browser but [fallbacks](https://github.com/hakimel/reveal.js/wiki/Browser-Support) are available to make sure your presentation can still be viewed elsewhere.
reveal.js comes with a broad range of features including [nested slides](https://github.com/hakimel/reveal.js#markup), [Markdown contents](https://github.com/hakimel/reveal.js#markdown), [PDF export](https://github.com/hakimel/reveal.js#pdf-export), [speaker notes](https://github.com/hakimel/reveal.js#speaker-notes) and a [JavaScript API](https://github.com/hakimel/reveal.js#api). There's also a fully featured visual editor and platform for sharing reveal.js presentations at [slides.com](https://slides.com?ref=github).
## Table of contents
- [Online Editor](#online-editor)
- [Instructions](#instructions)
- [Markup](#markup)
- [Markdown](#markdown)
- [Element Attributes](#element-attributes)
- [Slide Attributes](#slide-attributes)
- [Configuration](#configuration)
- [Presentation Size](#presentation-size)
- [Dependencies](#dependencies)
- [Ready Event](#ready-event)
- [Auto-sliding](#auto-sliding)
- [Keyboard Bindings](#keyboard-bindings)
- [Touch Navigation](#touch-navigation)
- [Lazy Loading](#lazy-loading)
- [API](#api)
- [Slide Changed Event](#slide-changed-event)
- [Presentation State](#presentation-state)
- [Slide States](#slide-states)
- [Slide Backgrounds](#slide-backgrounds)
- [Parallax Background](#parallax-background)
- [Slide Transitions](#slide-transitions)
- [Internal links](#internal-links)
- [Fragments](#fragments)
- [Fragment events](#fragment-events)
- [Code syntax highlighting](#code-syntax-highlighting)
- [Slide number](#slide-number)
- [Overview mode](#overview-mode)
- [Fullscreen mode](#fullscreen-mode)
- [Embedded media](#embedded-media)
- [Stretching elements](#stretching-elements)
- [postMessage API](#postmessage-api)
- [PDF Export](#pdf-export)
- [Theming](#theming)
- [Speaker Notes](#speaker-notes)
- [Share and Print Speaker Notes](#share-and-print-speaker-notes)
- [Server Side Speaker Notes](#server-side-speaker-notes)
- [Multiplexing](#multiplexing)
- [Master presentation](#master-presentation)
- [Client presentation](#client-presentation)
- [Socket.io server](#socketio-server)
- [MathJax](#mathjax)
- [Installation](#installation)
- [Basic setup](#basic-setup)
- [Full setup](#full-setup)
- [Folder Structure](#folder-structure)
- [License](#license)
#### More reading:
- [Installation](#installation): Step-by-step instructions for getting reveal.js running on your computer.
#### More reading
- [Changelog](https://github.com/hakimel/reveal.js/releases): Up-to-date version history.
- [Examples](https://github.com/hakimel/reveal.js/wiki/Example-Presentations): Presentations created with reveal.js, add your own!
- [Browser Support](https://github.com/hakimel/reveal.js/wiki/Browser-Support): Explanation of browser support and fallbacks.
@@ -14,14 +60,36 @@ reveal.js comes with a broad range of features including [nested slides](https:/
## Online Editor
Presentations are written using HTML or Markdown but there's also an online editor for those of you who prefer a graphical interface. Give it a try at [http://slides.com](http://slides.com).
Presentations are written using HTML or Markdown but there's also an online editor for those of you who prefer a graphical interface. Give it a try at [https://slides.com](https://slides.com?ref=github).
## Instructions
### Markup
Markup hierarchy needs to be ``<div class="reveal"> <div class="slides"> <section>`` where the ``<section>`` represents one slide and can be repeated indefinitely. If you place multiple ``<section>``'s inside of another ``<section>`` they will be shown as vertical slides. The first of the vertical slides is the "root" of the others (at the top), and it will be included in the horizontal sequence. For example:
Here's a barebones example of a fully working reveal.js presentation:
```html
<html>
<head>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/white.css">
</head>
<body>
<div class="reveal">
<div class="slides">
<section>Slide 1</section>
<section>Slide 2</section>
</div>
</div>
<script src="js/reveal.js"></script>
<script>
Reveal.initialize();
</script>
</body>
</html>
```
The presentation markup hierarchy needs to be `.reveal > .slides > section` where the `section` represents one slide and can be repeated indefinitely. If you place multiple `section` elements inside of another `section` they will be shown as vertical slides. The first of the vertical slides is the "root" of the others (at the top), and will be included in the horizontal sequence. For example:
```html
<div class="reveal">
@@ -37,32 +105,36 @@ Markup hierarchy needs to be ``<div class="reveal"> <div class="slides"> <sectio
### Markdown
It's possible to write your slides using Markdown. To enable Markdown, add the ```data-markdown``` attribute to your ```<section>``` elements and wrap the contents in a ```<script type="text/template">``` like the example below.
It's possible to write your slides using Markdown. To enable Markdown, add the `data-markdown` attribute to your `<section>` elements and wrap the contents in a `<textarea data-template>` like the example below. You'll also need to add the `plugin/markdown/marked.js` and `plugin/markdown/markdown.js` scripts (in that order) to your HTML file.
This is based on [data-markdown](https://gist.github.com/1343518) from [Paul Irish](https://github.com/paulirish) modified to use [marked](https://github.com/chjj/marked) to support [Github Flavoured Markdown](https://help.github.com/articles/github-flavored-markdown). Sensitive to indentation (avoid mixing tabs and spaces) and line breaks (avoid consecutive breaks).
This is based on [data-markdown](https://gist.github.com/1343518) from [Paul Irish](https://github.com/paulirish) modified to use [marked](https://github.com/chjj/marked) to support [GitHub Flavored Markdown](https://help.github.com/articles/github-flavored-markdown). Sensitive to indentation (avoid mixing tabs and spaces) and line breaks (avoid consecutive breaks).
```html
<section data-markdown>
<script type="text/template">
<textarea data-template>
## Page title
A paragraph with some text and a [link](http://hakim.se).
</script>
</textarea>
</section>
```
#### External Markdown
You can write your content as a separate file and have reveal.js load it at runtime. Note the separator arguments which determine how slides are delimited in the external file. The ```data-charset``` attribute is optional and specifies which charset to use when loading the external file.
You can write your content as a separate file and have reveal.js load it at runtime. Note the separator arguments which determine how slides are delimited in the external file: the `data-separator` attribute defines a regular expression for horizontal slides (defaults to `^\r?\n---\r?\n$`, a newline-bounded horizontal rule) and `data-separator-vertical` defines vertical slides (disabled by default). The `data-separator-notes` attribute is a regular expression for specifying the beginning of the current slide's speaker notes (defaults to `note:`). The `data-charset` attribute is optional and specifies which charset to use when loading the external file.
When used locally, this feature requires that reveal.js [runs from a local web server](#full-setup).
When used locally, this feature requires that reveal.js [runs from a local web server](#full-setup). The following example customises all available options:
```html
<section data-markdown="example.md"
data-separator="^\n\n\n"
data-separator-vertical="^\n\n"
data-separator-notes="^Note:"
<section data-markdown="example.md"
data-separator="^\n\n\n"
data-separator-vertical="^\n\n"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
<!--
Note that Windows uses `\r\n` instead of `\n` as its linefeed character.
For a regex that supports all operating systems, use `\r?\n` instead of `\n`.
-->
</section>
```
@@ -92,6 +164,19 @@ Special syntax (in html comment) is available for adding attributes to the slide
</section>
```
#### Configuring *marked*
We use [marked](https://github.com/chjj/marked) to parse Markdown. To customise marked's rendering, you can pass in options when [configuring Reveal](#configuration):
```javascript
Reveal.initialize({
// Options which are passed into marked
// See https://github.com/chjj/marked#options-1
markdown: {
smartypants: true
}
});
```
### Configuration
@@ -100,12 +185,26 @@ At the end of your page you need to initialize reveal by running the following c
```javascript
Reveal.initialize({
// Display controls in the bottom right corner
// Display presentation control arrows
controls: true,
// Help the user learn the controls by providing hints, for example by
// bouncing the down arrow when they first encounter a vertical slide
controlsTutorial: true,
// Determines where controls appear, "edges" or "bottom-right"
controlsLayout: 'bottom-right',
// Visibility rule for backwards navigation arrows; "faded", "hidden"
// or "visible"
controlsBackArrows: 'faded',
// Display a presentation progress bar
progress: true,
// Set default timing of 2 minutes per slide
defaultTiming: 120,
// Display the page number of the current slide
slideNumber: false,
@@ -130,6 +229,9 @@ Reveal.initialize({
// Change the presentation direction to be RTL
rtl: false,
// Randomizes the order of slides each time the presentation loads
shuffle: false,
// Turns fragments on and off globally
fragments: true,
@@ -141,6 +243,15 @@ Reveal.initialize({
// key is pressed
help: true,
// Flags if speaker notes should be visible to all viewers
showNotes: false,
// Global override for autoplaying embedded media (video/audio/iframe)
// - null: Media will only autoplay if data-autoplay is present
// - true: All media will autoplay, regardless of individual setting
// - false: No media will autoplay, regardless of individual setting
autoPlayMedia: null,
// Number of milliseconds between automatically proceeding to the
// next slide, disabled when set to 0, this value can be overwritten
// by using a data-autoslide attribute on your slides
@@ -149,6 +260,9 @@ Reveal.initialize({
// Stop auto-sliding after user input
autoSlideStoppable: true,
// Use this method for navigation when auto-sliding
autoSlideMethod: Reveal.navigateNext,
// Enable slide navigation via mouse wheel
mouseWheel: false,
@@ -156,16 +270,18 @@ Reveal.initialize({
hideAddressBar: true,
// Opens links in an iframe preview overlay
// Add `data-preview-link` and `data-preview-link="false"` to customise each link
// individually
previewLinks: false,
// Transition style
transition: 'default', // none/fade/slide/convex/concave/zoom
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Transition speed
transitionSpeed: 'default', // default/fast/slow
// Transition style for full page slide backgrounds
backgroundTransition: 'default', // none/fade/slide/convex/concave/zoom
backgroundTransition: 'fade', // none/fade/slide/convex/concave/zoom
// Number of slides away from the current that are visible
viewDistance: 3,
@@ -176,10 +292,14 @@ Reveal.initialize({
// Parallax background size
parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px"
// Amount to move parallax background (horizontal and vertical) on slide change
// Number, e.g. 100
parallaxBackgroundHorizontal: '',
parallaxBackgroundVertical: ''
// Number of pixels to move the parallax background per slide
// - Calculated automatically unless specified
// - Set to 0 to disable movement along an axis
parallaxBackgroundHorizontal: null,
parallaxBackgroundVertical: null,
// The display mode that will be used to show slides
display: 'block'
});
```
@@ -196,56 +316,6 @@ Reveal.configure({ autoSlide: 5000 });
```
### Dependencies
Reveal.js doesn't _rely_ on any third party scripts to work but a few optional libraries are included by default. These libraries are loaded as dependencies in the order they appear, for example:
```javascript
Reveal.initialize({
dependencies: [
// Cross-browser shim that fully implements classList - https://github.com/eligrey/classList.js/
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
// Interpret Markdown in <section> elements
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
// Syntax highlight for <code> elements
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
// Zoom in and out with Alt+click
{ src: 'plugin/zoom-js/zoom.js', async: true },
// Speaker notes
{ src: 'plugin/notes/notes.js', async: true },
// Remote control your reveal.js presentation using a touch device
{ src: 'plugin/remotes/remotes.js', async: true },
// MathJax
{ src: 'plugin/math/math.js', async: true }
]
});
```
You can add your own extensions using the same syntax. The following properties are available for each dependency object:
- **src**: Path to the script to load
- **async**: [optional] Flags if the script should load after reveal.js has started, defaults to false
- **callback**: [optional] Function to execute when the script has loaded
- **condition**: [optional] Function which must return true for the script to be loaded
### Ready Event
A 'ready' event is fired when reveal.js has loaded all non-async dependencies and is ready to start navigating. To check if reveal.js is already 'ready' you can call `Reveal.isReady()`.
```javascript
Reveal.addEventListener( 'ready', function( event ) {
// event.currentSlide, event.indexh, event.indexv
} );
```
### Presentation Size
All presentations have a normal size, that is the resolution at which they are authored. The framework will automatically scale presentations uniformly based on this size to ensure that everything fits on any given display or viewport.
@@ -273,6 +343,69 @@ Reveal.initialize({
});
```
If you wish to disable this behavior and do your own scaling (e.g. using media queries), try these settings:
```javascript
Reveal.initialize({
...
width: "100%",
height: "100%",
margin: 0,
minScale: 1,
maxScale: 1
});
```
### Dependencies
Reveal.js doesn't _rely_ on any third party scripts to work but a few optional libraries are included by default. These libraries are loaded as dependencies in the order they appear, for example:
```javascript
Reveal.initialize({
dependencies: [
// Cross-browser shim that fully implements classList - https://github.com/eligrey/classList.js/
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
// Interpret Markdown in <section> elements
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
// Syntax highlight for <code> elements
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } },
// Zoom in and out with Alt+click
{ src: 'plugin/zoom-js/zoom.js', async: true },
// Speaker notes
{ src: 'plugin/notes/notes.js', async: true },
// MathJax
{ src: 'plugin/math/math.js', async: true }
]
});
```
You can add your own extensions using the same syntax. The following properties are available for each dependency object:
- **src**: Path to the script to load
- **async**: [optional] Flags if the script should load after reveal.js has started, defaults to false
- **callback**: [optional] Function to execute when the script has loaded
- **condition**: [optional] Function which must return true for the script to be loaded
To load these dependencies, reveal.js requires [head.js](http://headjs.com/) *(a script loading library)* to be loaded before reveal.js.
### Ready Event
A 'ready' event is fired when reveal.js has loaded all non-async dependencies and is ready to start navigating. To check if reveal.js is already 'ready' you can call `Reveal.isReady()`.
```javascript
Reveal.addEventListener( 'ready', function( event ) {
// event.currentSlide, event.indexh, event.indexv
} );
```
Note that we also add a `.ready` class to the `.reveal` element so that you can hook into this with CSS.
### Auto-sliding
@@ -296,6 +429,8 @@ You can also override the slide duration for individual slides and fragments by
</section>
```
To override the method used for navigation when auto-sliding, you can specify the ```autoSlideMethod``` setting. To only navigate along the top layer and ignore vertical slides, set this to ```Reveal.navigateRight```.
Whenever the auto-slide mode is resumed or paused the ```autoslideresumed``` and ```autoslidepaused``` events are fired.
@@ -313,6 +448,13 @@ Reveal.configure({
});
```
### Touch Navigation
You can swipe to navigate through a presentation on any touch-enabled device. Horizontal swipes change between horizontal slides, vertical swipes change between vertical slides. If you wish to disable this you can set the `touch` config option to false when initializing reveal.js.
If there's some part of your content that needs to remain accessible to touch events you'll need to highlight this by adding a `data-prevent-swipe` attribute to the element. One common example where this is useful is elements that need to be scrolled.
### Lazy Loading
When working on presentation with a lot of media or iframe content it's important to load lazily. Lazy loading means that reveal.js will only load content for the few slides nearest to the current slide. The number of slides that are preloaded is determined by the `viewDistance` configuration option.
@@ -347,11 +489,18 @@ Reveal.next();
Reveal.prevFragment();
Reveal.nextFragment();
// Randomize the order of slides
Reveal.shuffle();
// Toggle presentation states, optionally pass true/false to force on/off
Reveal.toggleOverview();
Reveal.togglePause();
Reveal.toggleAutoSlide();
// Shows a help overlay with keyboard shortcuts, optionally pass true/false
// to force on/off
Reveal.toggleHelp();
// Change a config value at runtime
Reveal.configure({ controls: true });
@@ -365,9 +514,14 @@ Reveal.getScale();
Reveal.getPreviousSlide();
Reveal.getCurrentSlide();
Reveal.getIndices(); // { h: 0, v: 0 } }
Reveal.getProgress(); // 0-1
Reveal.getTotalSlides();
Reveal.getIndices(); // { h: 0, v: 0 } }
Reveal.getPastSlideCount();
Reveal.getProgress(); // (0 == first slide, 1 == last slide)
Reveal.getSlides(); // Array of all slides
Reveal.getTotalSlides(); // total number of slides
// Returns the speaker notes for the current slide
Reveal.getSlideNotes();
// State checks
Reveal.isFirstSlide();
@@ -420,26 +574,59 @@ Reveal.addEventListener( 'somestate', function() {
### Slide Backgrounds
Slides are contained within a limited portion of the screen by default to allow them to fit any display and scale uniformly. You can apply full page backgrounds outside of the slide area by adding a ```data-background``` attribute to your ```<section>``` elements. Four different types of backgrounds are supported: color, image, video and iframe. Below are a few examples.
Slides are contained within a limited portion of the screen by default to allow them to fit any display and scale uniformly. You can apply full page backgrounds outside of the slide area by adding a ```data-background``` attribute to your ```<section>``` elements. Four different types of backgrounds are supported: color, image, video and iframe.
#### Color Backgrounds
All CSS color formats are supported, like rgba() or hsl().
```html
<section data-background="#ff0000">
<h2>All CSS color formats are supported, like rgba() or hsl().</h2>
</section>
<section data-background="http://example.com/image.png">
<h2>This slide will have a full-size background image.</h2>
</section>
<section data-background="http://example.com/image.png" data-background-size="100px" data-background-repeat="repeat">
<h2>This background image will be sized to 100px and repeated.</h2>
</section>
<section data-background-video="https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.mp4,https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.webm" data-background-video-loop>
<h2>Video. Multiple sources can be defined using a comma separated list. Video will loop when the data-background-video-loop attribute is provided.</h2>
</section>
<section data-background-iframe="https://slides.com">
<h2>Embeds a web page as a background. Note that the page won't be interactive.</h2>
<section data-background-color="#ff0000">
<h2>Color</h2>
</section>
```
#### Image Backgrounds
By default, background images are resized to cover the full page. Available options:
| Attribute | Default | Description |
| :--------------------------- | :--------- | :---------- |
| data-background-image | | URL of the image to show. GIFs restart when the slide opens. |
| data-background-size | cover | See [background-size](https://developer.mozilla.org/docs/Web/CSS/background-size) on MDN. |
| data-background-position | center | See [background-position](https://developer.mozilla.org/docs/Web/CSS/background-position) on MDN. |
| data-background-repeat | no-repeat | See [background-repeat](https://developer.mozilla.org/docs/Web/CSS/background-repeat) on MDN. |
```html
<section data-background-image="http://example.com/image.png">
<h2>Image</h2>
</section>
<section data-background-image="http://example.com/image.png" data-background-size="100px" data-background-repeat="repeat">
<h2>This background image will be sized to 100px and repeated</h2>
</section>
```
#### Video Backgrounds
Automatically plays a full size video behind the slide.
| Attribute | Default | Description |
| :--------------------------- | :------ | :---------- |
| data-background-video | | A single video source, or a comma separated list of video sources. |
| data-background-video-loop | false | Flags if the video should play repeatedly. |
| data-background-video-muted | false | Flags if the audio should be muted. |
| data-background-size | cover | Use `cover` for full screen and some cropping or `contain` for letterboxing. |
```html
<section data-background-video="https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.mp4,https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.webm" data-background-video-loop data-background-video-muted>
<h2>Video</h2>
</section>
```
#### Iframe Backgrounds
Embeds a web page as a slide background that covers 100% of the reveal.js width and height. The iframe is in the background layer, behind your slides, and as such it's not possible to interact with it by default. To make your background interactive, you can add the `data-background-interactive` attribute.
```html
<section data-background-iframe="https://slides.com" data-background-interactive>
<h2>Iframe</h2>
</section>
```
#### Background Transitions
Backgrounds transition using a fade animation by default. This can be changed to a linear sliding transition by passing ```backgroundTransition: 'slide'``` to the ```Reveal.initialize()``` call. Alternatively you can set ```data-background-transition``` on any section with a background to override that specific transition.
@@ -456,16 +643,16 @@ Reveal.initialize({
// Parallax background size
parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px" - currently only pixels are supported (don't use % or auto)
// Amount of pixels to move the parallax background per slide step,
// a value of 0 disables movement along the given axis
// These are optional, if they aren't specified they'll be calculated automatically
// Number of pixels to move the parallax background per slide
// - Calculated automatically unless specified
// - Set to 0 to disable movement along an axis
parallaxBackgroundHorizontal: 200,
parallaxBackgroundVertical: 50
});
```
Make sure that the background size is much bigger than screen size to allow for some scrolling. [View example](http://lab.hakim.se/reveal-js/?parallaxBackgroundImage=https%3A%2F%2Fs3.amazonaws.com%2Fhakim-static%2Freveal-js%2Freveal-parallax-1.jpg&parallaxBackgroundSize=2100px%20900px).
Make sure that the background size is much bigger than screen size to allow for some scrolling. [View example](http://revealjs.com/?parallaxBackgroundImage=https%3A%2F%2Fs3.amazonaws.com%2Fhakim-static%2Freveal-js%2Freveal-parallax-1.jpg&parallaxBackgroundSize=2100px%20900px).
@@ -486,15 +673,15 @@ You can also use different in and out transitions for the same slide:
```html
<section data-transition="slide">
The train goes on …
The train goes on …
</section>
<section data-transition="slide">
and on …
<section data-transition="slide">
and on …
</section>
<section data-transition="slide-in fade-out">
<section data-transition="slide-in fade-out">
and stops.
</section>
<section data-transition="fade-in slide-out">
<section data-transition="fade-in slide-out">
(Passengers entering and leaving)
</section>
<section data-transition="slide">
@@ -503,9 +690,6 @@ You can also use different in and out transitions for the same slide:
```
Note that this does not work with the page and cube transitions.
### Internal links
It's easy to link between slides. The first example below targets the index of another slide whereas the second targets a slide with an ID attribute (```<section id="some-slide">```):
@@ -528,7 +712,7 @@ You can also add relative navigation links, similar to the built in reveal.js co
### Fragments
Fragments are used to highlight individual elements on a slide. Every element with the class ```fragment``` will be stepped through before moving on to the next slide. Here's an example: http://lab.hakim.se/reveal-js/#/fragments
Fragments are used to highlight individual elements on a slide. Every element with the class ```fragment``` will be stepped through before moving on to the next slide. Here's an example: http://revealjs.com/#/fragments
The default fragment style is to start out invisible and fade in. This style can be changed by appending a different class to the fragment:
@@ -537,6 +721,7 @@ The default fragment style is to start out invisible and fade in. This style can
<p class="fragment grow">grow</p>
<p class="fragment shrink">shrink</p>
<p class="fragment fade-out">fade-out</p>
<p class="fragment fade-up">fade-up (also down, left and right!)</p>
<p class="fragment current-visible">visible only once</p>
<p class="fragment highlight-current-blue">blue only once</p>
<p class="fragment highlight-red">highlight-red</p>
@@ -582,33 +767,41 @@ Reveal.addEventListener( 'fragmenthidden', function( event ) {
### Code syntax highlighting
By default, Reveal is configured with [highlight.js](http://softwaremaniacs.org/soft/highlight/en/) for code syntax highlighting. Below is an example with clojure code that will be syntax highlighted. When the `data-trim` attribute is present surrounding whitespace is automatically removed.
By default, Reveal is configured with [highlight.js](https://highlightjs.org/) for code syntax highlighting. To enable syntax highlighting, you'll have to load the highlight plugin ([plugin/highlight/highlight.js](plugin/highlight/highlight.js)) and a highlight.js CSS theme (Reveal comes packaged with the zenburn theme: [lib/css/zenburn.css](lib/css/zenburn.css)).
Below is an example with clojure code that will be syntax highlighted. When the `data-trim` attribute is present, surrounding whitespace is automatically removed. HTML will be escaped by default. To avoid this, for example if you are using `<mark>` to call out a line of code, add the `data-noescape` attribute to the `<code>` element.
```html
<section>
<pre><code data-trim>
<pre><code data-trim data-noescape>
(def lazy-fib
(concat
[0 1]
((fn rfib [a b]
<mark>((fn rfib [a b]</mark>
(lazy-cons (+ a b) (rfib b (+ a b)))) 0 1)))
</code></pre>
</section>
```
### Slide number
If you would like to display the page number of the current slide you can do so using the ```slideNumber``` configuration value.
If you would like to display the page number of the current slide you can do so using the ```slideNumber``` and ```showSlideNumber``` configuration values.
```javascript
// Shows the slide number using default formatting
Reveal.configure({ slideNumber: true });
// Slide number formatting can be configured using these variables:
// h: current slide's horizontal index
// v: current slide's vertical index
// c: current slide index (flattened)
// t: total number of slides (flattened)
Reveal.configure({ slideNumber: 'c / t' });
// "h.v": horizontal . vertical slide number (default)
// "h/v": horizontal / vertical slide number
// "c": flattened slide number
// "c/t": flattened slide number / total slides
Reveal.configure({ slideNumber: 'c/t' });
// Control which views the slide number displays on using the "showSlideNumber" value:
// "all": show on all views (default)
// "speaker": only show slide numbers on speaker notes view
// "print": only show slide numbers when printing to PDF
Reveal.configure({ showSlideNumber: 'speaker' });
```
@@ -626,20 +819,26 @@ Reveal.addEventListener( 'overviewhidden', function( event ) { /* ... */ } );
Reveal.toggleOverview();
```
### Fullscreen mode
Just press »F« on your keyboard to show your presentation in fullscreen mode. Press the »ESC« key to exit fullscreen mode.
### Embedded media
Embedded HTML5 `<video>`/`<audio>` and YouTube iframes are automatically paused when you navigate away from a slide. This can be disabled by decorating your element with a `data-ignore` attribute.
Add `data-autoplay` to your media element if you want it to automatically start playing when the slide is shown:
```html
<video data-autoplay src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"></video>
```
Additionally the framework automatically pushes two [post messages](https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage) to all iframes, ```slide:start``` when the slide containing the iframe is made visible and ```slide:stop``` when it is hidden.
If you want to enable or disable autoplay globally, for all embedded media, you can use the `autoPlayMedia` configuration option. If you set this to `true` ALL media will autoplay regardless of individual `data-autoplay` attributes. If you initialize with `autoPlayMedia: false` NO media will autoplay.
Note that embedded HTML5 `<video>`/`<audio>` and YouTube/Vimeo iframes are automatically paused when you navigate away from a slide. This can be disabled by decorating your element with a `data-ignore` attribute.
### Embedded iframes
reveal.js automatically pushes two [post messages](https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage) to embedded iframes. ```slide:start``` when the slide containing the iframe is made visible and ```slide:stop``` when it is hidden.
### Stretching elements
@@ -669,7 +868,7 @@ When reveal.js runs inside of an iframe it can optionally bubble all of its even
```javascript
window.addEventListener( 'message', function( event ) {
var data = JSON.parse( event.data );
if( data.namespace === 'reveal' && data.eventName ='slidechanged' ) {
if( data.namespace === 'reveal' && data.eventName ==='slidechanged' ) {
// Slide changed, see data.state for slide number
}
} );
@@ -692,17 +891,36 @@ Reveal.initialize({
## PDF Export
Presentations can be exported to PDF via a special print stylesheet. This feature requires that you use [Google Chrome](http://google.com/chrome) or [Chromium](https://www.chromium.org/Home).
Presentations can be exported to PDF via a special print stylesheet. This feature requires that you use [Google Chrome](http://google.com/chrome) or [Chromium](https://www.chromium.org/Home) and to be serving the presentation from a webserver.
Here's an example of an exported presentation that's been uploaded to SlideShare: http://www.slideshare.net/hakimel/revealjs-300.
1. Open your presentation with `print-pdf` included anywhere in the query string. This triggers the default index HTML to load the PDF print stylesheet ([css/print/pdf.css](https://github.com/hakimel/reveal.js/blob/master/css/print/pdf.css)). You can test this with [lab.hakim.se/reveal-js?print-pdf](http://lab.hakim.se/reveal-js?print-pdf).
2. Open the in-browser print dialog (CMD+P).
3. Change the **Destination** setting to **Save as PDF**.
4. Change the **Layout** to **Landscape**.
5. Change the **Margins** to **None**.
6. Click **Save**.
### Page size
Export dimensions are inferred from the configured [presentation size](#presentation-size). Slides that are too tall to fit within a single page will expand onto multiple pages. You can limit how many pages a slide may expand onto using the `pdfMaxPagesPerSlide` config option, for example `Reveal.configure({ pdfMaxPagesPerSlide: 1 })` ensures that no slide ever grows to more than one printed page.
![Chrome Print Settings](https://s3.amazonaws.com/hakim-static/reveal-js/pdf-print-settings.png)
### Print stylesheet
To enable the PDF print capability in your presentation, the special print stylesheet at [/css/print/pdf.css](https://github.com/hakimel/reveal.js/blob/master/css/print/pdf.css) must be loaded. The default index.html file handles this for you when `print-pdf` is included in the query string. If you're using a different HTML template, you can add this to your HEAD:
```html
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
```
### Instructions
1. Open your presentation with `print-pdf` included in the query string i.e. http://localhost:8000/?print-pdf. You can test this with [revealjs.com?print-pdf](http://revealjs.com?print-pdf).
* If you want to include [speaker notes](#speaker-notes) in your export, you can append `showNotes=true` to the query string: http://localhost:8000/?print-pdf&showNotes=true
1. Open the in-browser print dialog (CTRL/CMD+P).
1. Change the **Destination** setting to **Save as PDF**.
1. Change the **Layout** to **Landscape**.
1. Change the **Margins** to **None**.
1. Enable the **Background graphics** option.
1. Click **Save**.
![Chrome Print Settings](https://s3.amazonaws.com/hakim-static/reveal-js/pdf-print-settings-2.png)
Alternatively you can use the [decktape](https://github.com/astefanutti/decktape) project.
@@ -733,8 +951,12 @@ If you want to add a theme of your own see the instructions here: [/css/theme/RE
reveal.js comes with a speaker notes plugin which can be used to present per-slide notes in a separate browser window. The notes window also gives you a preview of the next upcoming slide so it may be helpful even if you haven't written any notes. Press the 's' key on your keyboard to open the notes window.
A speaker timer starts as soon as the speaker view is opened. You can reset it to 00:00:00 at any time by simply clicking/tapping on it.
Notes are defined by appending an ```<aside>``` element to a slide as seen below. You can add the ```data-markdown``` attribute to the aside element if you prefer writing notes using Markdown.
Alternatively you can add your notes in a `data-notes` attribute on the slide. Like `<section data-notes="Something important"></section>`.
When used locally, this feature requires that reveal.js [runs from a local web server](#full-setup).
```html
@@ -761,6 +983,23 @@ Note:
This will only display in the notes window.
```
#### Share and Print Speaker Notes
Notes are only visible to the speaker inside of the speaker view. If you wish to share your notes with others you can initialize reveal.js with the `showNotes` config value set to `true`. Notes will appear along the bottom of the presentations.
When `showNotes` is enabled notes are also included when you [export to PDF](https://github.com/hakimel/reveal.js#pdf-export). By default, notes are printed in a semi-transparent box on top of the slide. If you'd rather print them on a separate page after the slide, set `showNotes: "separate-page"`.
#### Speaker notes clock and timers
The speaker notes window will also show:
- Time elapsed since the beginning of the presentation. If you hover the mouse above this section, a timer reset button will appear.
- Current wall-clock time
- (Optionally) a pacing timer which indicates whether the current pace of the presentation is on track for the right timing (shown in green), and if not, whether the presenter should speed up (shown in red) or has the luxury of slowing down (blue).
The pacing timer can be enabled by configuring by the `defaultTiming` parameter in the `Reveal` configuration block, which specifies the number of seconds per slide. 120 can be a reasonable rule of thumb. Timings can also be given per slide `<section>` by setting the `data-timing` attribute. Both values are in numbers of seconds.
## Server Side Speaker Notes
In some cases it can be desirable to run notes on a separate device from the one you're presenting on. The Node.js-based notes plugin lets you do this using the same note definitions as its client side counterpart. Include the required scripts by adding the following dependencies:
@@ -778,14 +1017,14 @@ Reveal.initialize({
Then:
1. Install [Node.js](http://nodejs.org/)
1. Install [Node.js](http://nodejs.org/) (4.0.0 or later)
2. Run ```npm install```
3. Run ```node plugin/notes-server```
## Multiplexing
The multiplex plugin allows your audience to view the slides of the presentation you are controlling on their own phone, tablet or laptop. As the master presentation navigates the slides, all client presentations will update in real time. See a demo at [http://revealjs.jit.su/](http://revealjs.jit.su).
The multiplex plugin allows your audience to view the slides of the presentation you are controlling on their own phone, tablet or laptop. As the master presentation navigates the slides, all client presentations will update in real time. See a demo at [https://reveal-js-multiplex-ccjbegmaii.now.sh/](https://reveal-js-multiplex-ccjbegmaii.now.sh/).
The multiplex plugin needs the following 3 things to operate:
@@ -796,7 +1035,7 @@ The multiplex plugin needs the following 3 things to operate:
More details:
#### Master presentation
Served from a static file server accessible (preferably) only to the presenter. This need only be on your (the presenter's) computer. (It's safer to run the master presentation from your own computer, so if the venue's Internet goes down it doesn't stop the show.) An example would be to execute the following commands in the directory of your master presentation:
Served from a static file server accessible (preferably) only to the presenter. This need only be on your (the presenter's) computer. (It's safer to run the master presentation from your own computer, so if the venue's Internet goes down it doesn't stop the show.) An example would be to execute the following commands in the directory of your master presentation:
1. ```npm install node-static```
2. ```static```
@@ -814,12 +1053,12 @@ Reveal.initialize({
// Example values. To generate your own, see the socket.io server instructions.
secret: '13652805320794272084', // Obtained from the socket.io server. Gives this (the master) control of the presentation
id: '1ea875674b17ca76', // Obtained from socket.io server
url: 'revealjs.jit.su:80' // Location of socket.io server
url: 'https://reveal-js-multiplex-ccjbegmaii.now.sh' // Location of socket.io server
},
// Don't forget to add the dependencies
dependencies: [
{ src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js', async: true },
{ src: '//cdn.socket.io/socket.io-1.3.5.js', async: true },
{ src: 'plugin/multiplex/master.js', async: true },
// and if you want speaker notes
@@ -842,12 +1081,12 @@ Reveal.initialize({
// Example values. To generate your own, see the socket.io server instructions.
secret: null, // null so the clients do not have control of the master presentation
id: '1ea875674b17ca76', // id, obtained from socket.io server
url: 'revealjs.jit.su:80' // Location of socket.io server
url: 'https://reveal-js-multiplex-ccjbegmaii.now.sh' // Location of socket.io server
},
// Don't forget to add the dependencies
dependencies: [
{ src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js', async: true },
{ src: '//cdn.socket.io/socket.io-1.3.5.js', async: true },
{ src: 'plugin/multiplex/client.js', async: true }
// other dependencies...
@@ -861,15 +1100,17 @@ Server that receives the slideChanged events from the master presentation and br
1. ```npm install```
2. ```node plugin/multiplex```
Or you use the socket.io server at [http://revealjs.jit.su](http://revealjs.jit.su).
Or you can use the socket.io server at [https://reveal-js-multiplex-ccjbegmaii.now.sh/](https://reveal-js-multiplex-ccjbegmaii.now.sh/).
You'll need to generate a unique secret and token pair for your master and client presentations. To do so, visit ```http://example.com/token```, where ```http://example.com``` is the location of your socket.io server. Or if you're going to use the socket.io server at [http://revealjs.jit.su](http://revealjs.jit.su), visit [http://revealjs.jit.su/token](http://revealjs.jit.su/token).
You'll need to generate a unique secret and token pair for your master and client presentations. To do so, visit ```http://example.com/token```, where ```http://example.com``` is the location of your socket.io server. Or if you're going to use the socket.io server at [https://reveal-js-multiplex-ccjbegmaii.now.sh/](https://reveal-js-multiplex-ccjbegmaii.now.sh/), visit [https://reveal-js-multiplex-ccjbegmaii.now.sh/token](https://reveal-js-multiplex-ccjbegmaii.now.sh/token).
You are very welcome to point your presentations at the Socket.io server running at [http://revealjs.jit.su](http://revealjs.jit.su), but availability and stability are not guaranteed. For anything mission critical I recommend you run your own server. It is simple to deploy to nodejitsu, heroku, your own environment, etc.
You are very welcome to point your presentations at the Socket.io server running at [https://reveal-js-multiplex-ccjbegmaii.now.sh/](https://reveal-js-multiplex-ccjbegmaii.now.sh/), but availability and stability are not guaranteed.
For anything mission critical I recommend you run your own server. The easiest way to do this is by installing [now](https://zeit.co/now). With that installed, deploying your own Multiplex server is as easy running the following command from the reveal.js folder: `now plugin/multiplex`.
##### socket.io server as file static server
The socket.io server can play the role of static file server for your client presentation, as in the example at [http://revealjs.jit.su](http://revealjs.jit.su). (Open [http://revealjs.jit.su](http://revealjs.jit.su) in two browsers. Navigate through the slides on one, and the other will update to match.)
The socket.io server can play the role of static file server for your client presentation, as in the example at [https://reveal-js-multiplex-ccjbegmaii.now.sh/](https://reveal-js-multiplex-ccjbegmaii.now.sh/). (Open [https://reveal-js-multiplex-ccjbegmaii.now.sh/](https://reveal-js-multiplex-ccjbegmaii.now.sh/) in two browsers. Navigate through the slides on one, and the other will update to match.)
Example configuration:
```javascript
@@ -885,14 +1126,14 @@ Reveal.initialize({
// Don't forget to add the dependencies
dependencies: [
{ src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js', async: true },
{ src: '//cdn.socket.io/socket.io-1.3.5.js', async: true },
{ src: 'plugin/multiplex/client.js', async: true }
// other dependencies...
]
```
It can also play the role of static file server for your master presentation and client presentations at the same time (as long as you don't want to use speaker notes). (Open [http://revealjs.jit.su](http://revealjs.jit.su) in two browsers. Navigate through the slides on one, and the other will update to match. Navigate through the slides on the second, and the first will update to match.) This is probably not desirable, because you don't want your audience to mess with your slides while you're presenting. ;)
It can also play the role of static file server for your master presentation and client presentations at the same time (as long as you don't want to use speaker notes). (Open [https://reveal-js-multiplex-ccjbegmaii.now.sh/](https://reveal-js-multiplex-ccjbegmaii.now.sh/) in two browsers. Navigate through the slides on one, and the other will update to match. Navigate through the slides on the second, and the first will update to match.) This is probably not desirable, because you don't want your audience to mess with your slides while you're presenting. ;)
Example configuration:
```javascript
@@ -908,7 +1149,7 @@ Reveal.initialize({
// Don't forget to add the dependencies
dependencies: [
{ src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/0.9.16/socket.io.min.js', async: true },
{ src: '//cdn.socket.io/socket.io-1.3.5.js', async: true },
{ src: 'plugin/multiplex/master.js', async: true },
{ src: 'plugin/multiplex/client.js', async: true }
@@ -917,56 +1158,11 @@ Reveal.initialize({
});
```
## Leap Motion
The Leap Motion plugin lets you utilize your [Leap Motion](https://www.leapmotion.com/) device to control basic navigation of your presentation. The gestures currently supported are:
##### 1 to 2 fingers
Pointer &mdash; Point to anything on screen. Move your finger past the device to expand the pointer.
##### 1 hand + 3 or more fingers (left/right/up/down)
Navigate through your slides. See config options to invert movements.
##### 2 hands upwards
Toggle the overview mode. Do it a second time to exit the overview.
#### Config Options
You can edit the following options:
| Property | Default | Description
| ----------------- |:-----------------:| :-------------
| autoCenter | true | Center the pointer based on where you put your finger into the leap motions detection field.
| gestureDelay | 500 | How long to delay between gestures in milliseconds.
| naturalSwipe | true | Swipe as though you were touching a touch screen. Set to false to invert.
| pointerColor | #00aaff | The color of the pointer.
| pointerOpacity | 0.7 | The opacity of the pointer.
| pointerSize | 15 | The minimum height and width of the pointer.
| pointerTolerance | 120 | Bigger = slower pointer.
Example configuration:
```js
Reveal.initialize({
// other options...
leap: {
naturalSwipe : false, // Invert swipe gestures
pointerOpacity : 0.5, // Set pointer opacity to 0.5
pointerColor : '#d80000' // Red pointer
},
dependencies: [
{ src: 'plugin/leap/leap.js', async: true }
]
});
```
## MathJax
If you want to display math equations in your presentation you can easily do so by including this plugin. The plugin is a very thin wrapper around the [MathJax](http://www.mathjax.org/) library. To use it you'll need to include it as a reveal.js dependency, [find our more about dependencies here](#dependencies).
The plugin defaults to using [LaTeX](http://en.wikipedia.org/wiki/LaTeX) but that can be adjusted through the ```math``` configuration object. Note that MathJax is loaded from a remote server. If you want to use it offline you'll need to download a copy of the library and adjust the ```mathjax``` configuration value.
The plugin defaults to using [LaTeX](http://en.wikipedia.org/wiki/LaTeX) but that can be adjusted through the ```math``` configuration object. Note that MathJax is loaded from a remote server. If you want to use it offline you'll need to download a copy of the library and adjust the ```mathjax``` configuration value.
Below is an example of how the plugin can be configured. If you don't intend to change these values you do not need to include the ```math``` config object at all.
@@ -976,10 +1172,10 @@ Reveal.initialize({
// other options ...
math: {
mathjax: 'https://cdn.mathjax.org/mathjax/latest/MathJax.js',
mathjax: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js',
config: 'TeX-AMS_HTML-full' // See http://docs.mathjax.org/en/latest/config-files.html
},
dependencies: [
{ src: 'plugin/math/math.js', async: true }
]
@@ -1009,33 +1205,31 @@ The core of reveal.js is very easy to install. You'll simply need to download a
Some reveal.js features, like external Markdown and speaker notes, require that presentations run from a local web server. The following instructions will set up such a server as well as all of the development tasks needed to make edits to the reveal.js source code.
1. Install [Node.js](http://nodejs.org/)
1. Install [Node.js](http://nodejs.org/) (4.0.0 or later)
2. Install [Grunt](http://gruntjs.com/getting-started#installing-the-cli)
4. Clone the reveal.js repository
1. Clone the reveal.js repository
```sh
$ git clone https://github.com/hakimel/reveal.js.git
```
5. Navigate to the reveal.js folder
1. Navigate to the reveal.js folder
```sh
$ cd reveal.js
```
6. Install dependencies
1. Install dependencies
```sh
$ npm install
```
7. Serve the presentation and monitor source files for changes
1. Serve the presentation and monitor source files for changes
```sh
$ grunt serve
$ npm start
```
8. Open <http://localhost:8000> to view your presentation
1. Open <http://localhost:8000> to view your presentation
You can change the port by using `grunt serve --port 8001`.
You can change the port by using `npm start -- --port=8001`.
### Folder Structure
@@ -1049,4 +1243,4 @@ Some reveal.js features, like external Markdown and speaker notes, require that
MIT licensed
Copyright (C) 2015 Hakim El Hattab, http://hakim.se
Copyright (C) 2017 Hakim El Hattab, http://hakim.se
@@ -1,18 +1,18 @@
{
"name": "reveal.js",
"version": "3.1.0",
"version": "3.6.0",
"main": [
"js/reveal.js",
"css/reveal.css"
],
"homepage": "http://lab.hakim.se/reveal-js/",
"homepage": "http://revealjs.com",
"license": "MIT",
"description": "The HTML Presentation Framework",
"authors": [
"Hakim El Hattab <hakim.elhattab@gmail.com>"
],
"dependencies": {
"headjs": "~0.9.6"
"headjs": "~1.0.3"
},
"repository": {
"type": "git",
@@ -38,7 +38,8 @@
.share-reveal,
.state-background,
.reveal .progress,
.reveal .backgrounds {
.reveal .backgrounds,
.reveal .slide-number {
display: none !important;
}
@@ -141,7 +142,7 @@
.reveal .slides section {
visibility: visible !important;
position: static !important;
width: 100% !important;
width: auto !important;
height: auto !important;
display: block !important;
overflow: visible !important;
@@ -199,4 +200,4 @@
font-size: 0.8em;
}
}
}
@@ -1,15 +1,9 @@
/* Default Print Stylesheet Template
by Rob Glazebrook of CSSnewbie.com
Last Updated: June 4, 2008
Feel free (nay, compelled) to edit, append, and
manipulate this file as you see fit. */
/* SECTION 1: Set default width, margin, float, and
background. This prevents elements from extending
beyond the edge of the printed page, and prevents
unnecessary background images from printing */
/**
* This stylesheet is used to print reveal.js
* presentations to PDF.
*
* https://github.com/hakimel/reveal.js#pdf-export
*/
* {
-webkit-print-color-adjust: exact;
@@ -29,12 +23,10 @@ html {
overflow: visible;
}
/* SECTION 2: Remove any elements not needed in print.
This would include navigation, ads, sidebars, etc. */
/* Remove any elements not needed in print. */
.nestedarrow,
.reveal .controls,
.reveal .progress,
.reveal .slide-number,
.reveal .playback,
.reveal.overview,
.fork-reveal,
@@ -43,16 +35,7 @@ html {
display: none !important;
}
/* SECTION 3: Set body font face, size, and color.
Consider using a serif font for readability. */
body, p, td, li, div {
}
/* SECTION 4: Set heading font face, sizes, and color.
Differentiate your headings from your body text.
Perhaps use a large sans-serif for distinction. */
h1,h2,h3,h4,h5,h6 {
h1, h2, h3, h4, h5, h6 {
text-shadow: 0 0 0 #000 !important;
}
@@ -61,8 +44,6 @@ h1,h2,h3,h4,h5,h6 {
font-family: Courier, 'Courier New', monospace !important;
}
/* SECTION 5: more reveal.js specific additions by @skypanther */
ul, ol, div, p {
visibility: visible;
position: static;
@@ -79,8 +60,9 @@ ul, ol, div, p {
}
.reveal .slides {
position: static;
width: 100%;
height: auto;
width: 100% !important;
height: auto !important;
zoom: 1 !important;
left: auto;
top: auto;
@@ -100,13 +82,19 @@ ul, ol, div, p {
-ms-perspective-origin: 50% 50%;
perspective-origin: 50% 50%;
}
.reveal .slides section {
page-break-after: always !important;
.reveal .slides .pdf-page {
position: relative;
overflow: hidden;
z-index: 1;
page-break-after: always;
}
.reveal .slides section {
visibility: visible !important;
position: relative !important;
display: block !important;
position: relative !important;
position: absolute !important;
margin: 0 !important;
padding: 0 !important;
@@ -125,33 +113,66 @@ ul, ol, div, p {
-ms-transform: none !important;
transform: none !important;
}
.reveal section.stack {
position: relative !important;
margin: 0 !important;
padding: 0 !important;
page-break-after: avoid !important;
height: auto !important;
min-height: auto !important;
}
.reveal img {
box-shadow: none;
}
.reveal .roll {
overflow: visible;
line-height: 1em;
}
/* Slide backgrounds are placed inside of their slide when exporting to PDF */
.reveal section .slide-background {
.reveal .slide-background {
display: block !important;
position: absolute;
top: 0;
left: 0;
width: 100%;
z-index: -1;
}
/* All elements should be above the slide-background */
.reveal section>* {
position: relative;
z-index: 1;
height: 100%;
z-index: auto !important;
}
/* Display slide speaker notes when 'showNotes' is enabled */
.reveal.show-notes {
max-width: none;
max-height: none;
}
.reveal .speaker-notes-pdf {
display: block;
width: 100%;
height: auto;
max-height: none;
top: auto;
right: auto;
bottom: auto;
left: auto;
z-index: 100;
}
/* Layout option which makes notes appear on a separate page */
.reveal .speaker-notes-pdf[data-layout="separate-page"] {
position: relative;
color: inherit;
background-color: transparent;
padding: 20px;
page-break-after: always;
border: 0;
}
/* Display slide numbers when 'slideNumber' is enabled */
.reveal .slide-number-pdf {
display: block;
position: absolute;
font-size: 14px;
}
@@ -1,9 +1,9 @@
/*!
* reveal.js
* http://lab.hakim.se/reveal-js
* http://revealjs.com
* MIT licensed
*
* Copyright (C) 2015 Hakim El Hattab, http://hakim.se
* Copyright (C) 2017 Hakim El Hattab, http://hakim.se
*/
@@ -23,7 +23,7 @@ html, body, .reveal div, .reveal span, .reveal applet, .reveal object, .reveal i
.reveal article, .reveal aside, .reveal canvas, .reveal details, .reveal embed,
.reveal figure, .reveal figcaption, .reveal footer, .reveal header, .reveal hgroup,
.reveal menu, .reveal nav, .reveal output, .reveal ruby, .reveal section, .reveal summary,
.reveal time, .reveal mark, .reveal audio, video {
.reveal time, .reveal mark, .reveal audio, .reveal video {
margin: 0;
padding: 0;
border: 0;
@@ -69,13 +69,13 @@ body {
&.visible {
opacity: 1;
visibility: visible;
visibility: inherit;
}
}
.reveal .slides section .fragment.grow {
opacity: 1;
visibility: visible;
visibility: inherit;
&.visible {
transform: scale( 1.3 );
@@ -84,7 +84,7 @@ body {
.reveal .slides section .fragment.shrink {
opacity: 1;
visibility: visible;
visibility: inherit;
&.visible {
transform: scale( 0.7 );
@@ -101,7 +101,7 @@ body {
.reveal .slides section .fragment.fade-out {
opacity: 1;
visibility: visible;
visibility: inherit;
&.visible {
opacity: 0;
@@ -111,29 +111,62 @@ body {
.reveal .slides section .fragment.semi-fade-out {
opacity: 1;
visibility: visible;
visibility: inherit;
&.visible {
opacity: 0.5;
visibility: visible;
visibility: inherit;
}
}
.reveal .slides section .fragment.strike {
opacity: 1;
visibility: inherit;
&.visible {
text-decoration: line-through;
}
}
.reveal .slides section .fragment.fade-up {
transform: translate(0, 20%);
&.visible {
transform: translate(0, 0);
}
}
.reveal .slides section .fragment.fade-down {
transform: translate(0, -20%);
&.visible {
transform: translate(0, 0);
}
}
.reveal .slides section .fragment.fade-right {
transform: translate(-20%, 0);
&.visible {
transform: translate(0, 0);
}
}
.reveal .slides section .fragment.fade-left {
transform: translate(20%, 0);
&.visible {
transform: translate(0, 0);
}
}
.reveal .slides section .fragment.current-visible {
opacity: 0;
visibility: hidden;
&.current-fragment {
opacity: 1;
visibility: visible;
visibility: inherit;
}
}
@@ -144,7 +177,7 @@ body {
.reveal .slides section .fragment.highlight-blue,
.reveal .slides section .fragment.highlight-current-blue {
opacity: 1;
visibility: visible;
visibility: inherit;
}
.reveal .slides section .fragment.highlight-red.visible {
color: #ff2c2d
@@ -202,88 +235,279 @@ body {
* CONTROLS
*********************************************/
@keyframes bounce-right {
0%, 10%, 25%, 40%, 50% {transform: translateX(0);}
20% {transform: translateX(10px);}
30% {transform: translateX(-5px);}
}
@keyframes bounce-down {
0%, 10%, 25%, 40%, 50% {transform: translateY(0);}
20% {transform: translateY(10px);}
30% {transform: translateY(-5px);}
}
$controlArrowSize: 3.6em;
$controlArrowSpacing: 1.4em;
$controlArrowLength: 2.6em;
$controlArrowThickness: 0.5em;
$controlsArrowAngle: 45deg;
$controlsArrowAngleHover: 40deg;
$controlsArrowAngleActive: 36deg;
@mixin controlsArrowTransform( $angle ) {
&:before {
transform: translateX(($controlArrowSize - $controlArrowLength)/2) translateY(($controlArrowSize - $controlArrowThickness)/2) rotate( $angle );
}
&:after {
transform: translateX(($controlArrowSize - $controlArrowLength)/2) translateY(($controlArrowSize - $controlArrowThickness)/2) rotate( -$angle );
}
}
.reveal .controls {
$spacing: 12px;
display: none;
position: fixed;
width: 110px;
height: 110px;
z-index: 30;
right: 10px;
bottom: 10px;
-webkit-user-select: none;
}
.reveal .controls div {
position: absolute;
opacity: 0.05;
width: 0;
height: 0;
border: 12px solid transparent;
transform: scale(.9999);
transition: all 0.2s ease;
top: auto;
bottom: $spacing;
right: $spacing;
left: auto;
z-index: 1;
color: #000;
pointer-events: none;
font-size: 10px;
-webkit-tap-highlight-color: rgba( 0, 0, 0, 0 );
button {
position: absolute;
padding: 0;
background-color: transparent;
border: 0;
outline: 0;
cursor: pointer;
color: currentColor;
transform: scale(.9999);
transition: color 0.2s ease,
opacity 0.2s ease,
transform 0.2s ease;
z-index: 2; // above slides
pointer-events: auto;
font-size: inherit;
visibility: hidden;
opacity: 0;
-webkit-appearance: none;
-webkit-tap-highlight-color: rgba( 0, 0, 0, 0 );
}
.controls-arrow:before,
.controls-arrow:after {
content: '';
position: absolute;
top: 0;
left: 0;
width: $controlArrowLength;
height: $controlArrowThickness;
border-radius: $controlArrowThickness/2;
background-color: currentColor;
transition: all 0.15s ease, background-color 0.8s ease;
transform-origin: floor(($controlArrowThickness/2)*10)/10 50%;
will-change: transform;
}
.controls-arrow {
position: relative;
width: $controlArrowSize;
height: $controlArrowSize;
@include controlsArrowTransform( $controlsArrowAngle );
&:hover {
@include controlsArrowTransform( $controlsArrowAngleHover );
}
&:active {
@include controlsArrowTransform( $controlsArrowAngleActive );
}
}
.navigate-left {
right: $controlArrowSize + $controlArrowSpacing*2;
bottom: $controlArrowSpacing + $controlArrowSize/2;
transform: translateX( -10px );
}
.navigate-right {
right: 0;
bottom: $controlArrowSpacing + $controlArrowSize/2;
transform: translateX( 10px );
.controls-arrow {
transform: rotate( 180deg );
}
&.highlight {
animation: bounce-right 2s 50 both ease-out;
}
}
.navigate-up {
right: $controlArrowSpacing + $controlArrowSize/2;
bottom: $controlArrowSpacing*2 + $controlArrowSize;
transform: translateY( -10px );
.controls-arrow {
transform: rotate( 90deg );
}
}
.navigate-down {
right: $controlArrowSpacing + $controlArrowSize/2;
bottom: 0;
transform: translateY( 10px );
.controls-arrow {
transform: rotate( -90deg );
}
&.highlight {
animation: bounce-down 2s 50 both ease-out;
}
}
// Back arrow style: "faded":
// Deemphasize backwards navigation arrows in favor of drawing
// attention to forwards navigation
&[data-controls-back-arrows="faded"] .navigate-left.enabled,
&[data-controls-back-arrows="faded"] .navigate-up.enabled {
opacity: 0.3;
&:hover {
opacity: 1;
}
}
// Back arrow style: "hidden":
// Never show arrows for backwards navigation
&[data-controls-back-arrows="hidden"] .navigate-left.enabled,
&[data-controls-back-arrows="hidden"] .navigate-up.enabled {
opacity: 0;
visibility: hidden;
}
// Any control button that can be clicked is "enabled"
.enabled {
visibility: visible;
opacity: 0.9;
cursor: pointer;
transform: none;
}
// Any control button that leads to showing or hiding
// a fragment
.enabled.fragmented {
opacity: 0.5;
}
.enabled:hover,
.enabled.fragmented:hover {
opacity: 1;
}
}
.reveal .controls div.enabled {
opacity: 0.7;
cursor: pointer;
// Adjust the layout when there are no vertical slides
.reveal:not(.has-vertical-slides) .controls .navigate-left {
bottom: $controlArrowSpacing;
right: 0.5em + $controlArrowSpacing + $controlArrowSize;
}
.reveal .controls div.enabled:active {
margin-top: 1px;
.reveal:not(.has-vertical-slides) .controls .navigate-right {
bottom: $controlArrowSpacing;
right: 0.5em;
}
.reveal .controls div.navigate-left {
top: 42px;
// Adjust the layout when there are no horizontal slides
.reveal:not(.has-horizontal-slides) .controls .navigate-up {
right: $controlArrowSpacing;
bottom: $controlArrowSpacing + $controlArrowSize;
}
.reveal:not(.has-horizontal-slides) .controls .navigate-down {
right: $controlArrowSpacing;
bottom: 0.5em;
}
border-right-width: 22px;
border-right-color: #000;
}
.reveal .controls div.navigate-left.fragmented {
opacity: 0.3;
// Invert arrows based on background color
.reveal.has-dark-background .controls {
color: #fff;
}
.reveal.has-light-background .controls {
color: #000;
}
// Disable active states on touch devices
.reveal.no-hover .controls .controls-arrow:hover,
.reveal.no-hover .controls .controls-arrow:active {
@include controlsArrowTransform( $controlsArrowAngle );
}
// Edge aligned controls layout
@media screen and (min-width: 500px) {
$spacing: 8px;
.reveal .controls[data-controls-layout="edges"] {
& {
top: 0;
right: 0;
bottom: 0;
left: 0;
}
.reveal .controls div.navigate-right {
left: 74px;
top: 42px;
border-left-width: 22px;
border-left-color: #000;
}
.reveal .controls div.navigate-right.fragmented {
opacity: 0.3;
.navigate-left,
.navigate-right,
.navigate-up,
.navigate-down {
bottom: auto;
right: auto;
}
.reveal .controls div.navigate-up {
left: 42px;
border-bottom-width: 22px;
border-bottom-color: #000;
}
.reveal .controls div.navigate-up.fragmented {
opacity: 0.3;
.navigate-left {
top: 50%;
left: $spacing;
margin-top: -$controlArrowSize/2;
}
.reveal .controls div.navigate-down {
left: 42px;
top: 74px;
border-top-width: 22px;
border-top-color: #000;
}
.reveal .controls div.navigate-down.fragmented {
opacity: 0.3;
.navigate-right {
top: 50%;
right: $spacing;
margin-top: -$controlArrowSize/2;
}
.navigate-up {
top: $spacing;
left: 50%;
margin-left: -$controlArrowSize/2;
}
.navigate-down {
bottom: $spacing;
left: 50%;
margin-left: -$controlArrowSize/2;
}
}
}
/*********************************************
* PROGRESS BAR
*********************************************/
.reveal .progress {
position: fixed;
position: absolute;
display: none;
height: 3px;
width: 100%;
@@ -292,21 +516,22 @@ body {
z-index: 10;
background-color: rgba( 0, 0, 0, 0.2 );
color: #fff;
}
.reveal .progress:after {
content: '';
display: block;
position: absolute;
height: 20px;
height: 10px;
width: 100%;
top: -20px;
top: -10px;
}
.reveal .progress span {
display: block;
height: 100%;
width: 0px;
background-color: #000;
background-color: currentColor;
transition: width 800ms cubic-bezier(0.260, 0.860, 0.440, 0.985);
}
@@ -317,11 +542,19 @@ body {
.reveal .slide-number {
position: fixed;
display: block;
right: 15px;
bottom: 15px;
opacity: 0.5;
right: 8px;
bottom: 8px;
z-index: 31;
font-family: Helvetica, sans-serif;
font-size: 12px;
line-height: 1;
color: #fff;
background-color: rgba( 0, 0, 0, 0.4 );
padding: 5px;
}
.reveal .slide-number-delimiter {
margin: 0 3px;
}
/*********************************************
@@ -336,6 +569,16 @@ body {
touch-action: none;
}
// Mobile Safari sometimes overlays a header at the top
// of the page when in landscape mode. Using fixed
// positioning ensures that reveal.js reduces its height
// when this header is visible.
@media only screen and (orientation : landscape) {
.reveal.ua-iphone {
position: fixed;
}
}
.reveal .slides {
position: absolute;
width: 100%;
@@ -345,6 +588,7 @@ body {
bottom: 0;
left: 0;
margin: auto;
pointer-events: none;
overflow: visible;
z-index: 1;
@@ -363,9 +607,10 @@ body {
position: absolute;
width: 100%;
padding: 20px 0px;
pointer-events: auto;
z-index: 10;
transform-style: preserve-3d;
transform-style: flat;
transition: transform-origin 800ms cubic-bezier(0.260, 0.860, 0.440, 0.985),
transform 800ms cubic-bezier(0.260, 0.860, 0.440, 0.985),
visibility 800ms cubic-bezier(0.260, 0.860, 0.440, 0.985),
@@ -400,6 +645,13 @@ body {
opacity: 1;
}
.reveal .slides>section:empty,
.reveal .slides>section>section:empty,
.reveal .slides>section[data-background-interactive],
.reveal .slides>section>section[data-background-interactive] {
pointer-events: none;
}
.reveal.center,
.reveal.center .slides,
.reveal.center .slides section {
@@ -432,8 +684,14 @@ body {
*********************************************/
@mixin transition-global($style) {
.reveal .slides>section[data-transition=#{$style}],
.reveal.#{$style} .slides>section:not([data-transition]) {
.reveal .slides section[data-transition=#{$style}],
.reveal.#{$style} .slides section:not([data-transition]) {
@content;
}
}
@mixin transition-stack($style) {
.reveal .slides section[data-transition=#{$style}].stack,
.reveal.#{$style} .slides section.stack {
@content;
}
}
@@ -496,6 +754,10 @@ body {
*********************************************/
@each $stylename in default, convex {
@include transition-stack(#{$stylename}) {
transform-style: preserve-3d;
}
@include transition-horizontal-past(#{$stylename}) {
transform: translate3d(-100%, 0, 0) rotateY(-90deg) translate3d(-100%, 0, 0);
}
@@ -514,6 +776,10 @@ body {
* CONCAVE TRANSITION
*********************************************/
@include transition-stack(concave) {
transform-style: preserve-3d;
}
@include transition-horizontal-past(concave) {
transform: translate3d(-100%, 0, 0) rotateY(90deg) translate3d(-100%, 0, 0);
}
@@ -553,6 +819,10 @@ body {
/*********************************************
* CUBE TRANSITION
*
* WARNING:
* this is deprecated and will be removed in a
* future version.
*********************************************/
.reveal.cube .slides {
@@ -564,6 +834,7 @@ body {
min-height: 700px;
backface-visibility: hidden;
box-sizing: border-box;
transform-style: preserve-3d;
}
.reveal.center.cube .slides section {
min-height: 0;
@@ -624,6 +895,10 @@ body {
/*********************************************
* PAGE TRANSITION
*
* WARNING:
* this is deprecated and will be removed in a
* future version.
*********************************************/
.reveal.page .slides {
@@ -635,6 +910,7 @@ body {
padding: 30px;
min-height: 700px;
box-sizing: border-box;
transform-style: preserve-3d;
}
.reveal.page .slides section.past {
z-index: 12;
@@ -807,6 +1083,7 @@ body {
height: 100%;
opacity: 0;
visibility: hidden;
overflow: hidden;
background-color: rgba( 0, 0, 0, 0 );
background-position: 50% 50%;
@@ -823,6 +1100,7 @@ body {
.reveal .slide-background.present {
opacity: 1;
visibility: visible;
z-index: 2;
}
.print-pdf .reveal .slide-background {
@@ -839,7 +1117,11 @@ body {
max-height: none;
top: 0;
left: 0;
object-fit: cover;
}
.reveal .slide-background[data-background-size="contain"] video {
object-fit: contain;
}
/* Immediate transition style */
.reveal[data-background-transition=none]>.backgrounds .slide-background,
@@ -969,8 +1251,15 @@ body {
perspective-origin: 50% 50%;
perspective: 700px;
.slides {
// Fixes overview rendering errors in FF48+, not applied to
// other browsers since it degrades performance
-moz-transform-style: preserve-3d;
}
.slides section {
height: 700px;
height: 100%;
top: 0 !important;
opacity: 1 !important;
overflow: hidden;
visibility: visible !important;
@@ -1000,6 +1289,10 @@ body {
.backgrounds {
perspective: inherit;
// Fixes overview rendering errors in FF48+, not applied to
// other browsers since it degrades performance
-moz-transform-style: preserve-3d;
}
.backgrounds .slide-background {
@@ -1010,6 +1303,10 @@ body {
outline: 10px solid rgba(150,150,150,0.1);
outline-offset: 10px;
}
.backgrounds .slide-background.stack {
overflow: visible;
}
}
// Disable transitions transitions while we're activating
@@ -1024,10 +1321,6 @@ body {
transition: none;
}
.reveal.overview-animated .slides {
transition: transform 0.4s ease;
}
/*********************************************
* RTL SUPPORT
@@ -1125,6 +1418,7 @@ body {
display: inline-block;
width: 40px;
height: 40px;
line-height: 36px;
padding: 0 10px;
float: right;
opacity: 0.6;
@@ -1152,6 +1446,7 @@ body {
.reveal .overlay .viewport {
position: absolute;
display: flex;
top: 40px;
right: 0;
bottom: 0;
@@ -1175,6 +1470,23 @@ body {
visibility: visible;
}
.reveal .overlay.overlay-preview.loaded .viewport-inner {
position: absolute;
z-index: -1;
left: 0;
top: 45%;
width: 100%;
text-align: center;
letter-spacing: normal;
}
.reveal .overlay.overlay-preview .x-frame-error {
opacity: 0;
transition: opacity 0.3s ease 0.3s;
}
.reveal .overlay.overlay-preview.loaded .x-frame-error {
opacity: 1;
}
.reveal .overlay.overlay-preview.loaded .spinner {
opacity: 0;
visibility: hidden;
@@ -1188,8 +1500,8 @@ body {
.reveal .overlay.overlay-help .viewport .viewport-inner {
width: 600px;
margin: 0 auto;
padding: 60px;
margin: auto;
padding: 20px 20px 80px 20px;
text-align: center;
letter-spacing: normal;
}
@@ -1201,13 +1513,13 @@ body {
.reveal .overlay.overlay-help .viewport .viewport-inner table {
border: 1px solid #fff;
border-collapse: collapse;
font-size: 14px;
font-size: 16px;
}
.reveal .overlay.overlay-help .viewport .viewport-inner table th,
.reveal .overlay.overlay-help .viewport .viewport-inner table td {
width: 200px;
padding: 10px;
padding: 14px;
border: 1px solid #fff;
vertical-align: middle;
}
@@ -1224,12 +1536,13 @@ body {
*********************************************/
.reveal .playback {
position: fixed;
position: absolute;
left: 15px;
bottom: 15px;
bottom: 20px;
z-index: 30;
cursor: pointer;
transition: all 400ms ease;
-webkit-tap-highlight-color: rgba( 0, 0, 0, 0 );
}
.reveal.overview .playback {
@@ -1288,10 +1601,97 @@ body {
* SPEAKER NOTES
*********************************************/
// Hide on-page notes
.reveal aside.notes {
display: none;
}
// An interface element that can optionally be used to show the
// speaker notes to all viewers, on top of the presentation
.reveal .speaker-notes {
display: none;
position: absolute;
width: 25vw;
height: 100%;
top: 0;
left: 100%;
padding: 14px 18px 14px 18px;
z-index: 1;
font-size: 18px;
line-height: 1.4;
border: 1px solid rgba( 0, 0, 0, 0.05 );
color: #222;
background-color: #f5f5f5;
overflow: auto;
box-sizing: border-box;
text-align: left;
font-family: Helvetica, sans-serif;
-webkit-overflow-scrolling: touch;
.notes-placeholder {
color: #ccc;
font-style: italic;
}
&:focus {
outline: none;
}
&:before {
content: 'Speaker notes';
display: block;
margin-bottom: 10px;
opacity: 0.5;
}
}
.reveal.show-notes {
max-width: 75vw;
overflow: visible;
}
.reveal.show-notes .speaker-notes {
display: block;
}
@media screen and (min-width: 1600px) {
.reveal .speaker-notes {
font-size: 20px;
}
}
@media screen and (max-width: 1024px) {
.reveal.show-notes {
border-left: 0;
max-width: none;
max-height: 70%;
overflow: visible;
}
.reveal.show-notes .speaker-notes {
top: 100%;
left: 0;
width: 100%;
height: (30/0.7)*1%;
}
}
@media screen and (max-width: 600px) {
.reveal.show-notes {
max-height: 60%;
}
.reveal.show-notes .speaker-notes {
top: 100%;
height: (40/0.6)*1%;
}
.reveal .speaker-notes {
font-size: 14px;
}
}
/*********************************************
* ZOOM PLUGIN
@@ -1315,5 +1715,3 @@ body {
.zoomed .reveal .roll span:after {
visibility: hidden;
}
@@ -1,10 +1,10 @@
## Dependencies
Themes are written using Sass to keep things modular and reduce the need for repeated selectors across files. Make sure that you have the reveal.js development environment including the Grunt dependencies installed before proceding: https://github.com/hakimel/reveal.js#full-setup
Themes are written using Sass to keep things modular and reduce the need for repeated selectors across files. Make sure that you have the reveal.js development environment including the Grunt dependencies installed before proceeding: https://github.com/hakimel/reveal.js#full-setup
## Creating a Theme
To create your own theme, start by duplicating any ```.scss``` file in [/css/theme/source](https://github.com/hakimel/reveal.js/blob/master/css/theme/source) and adding it to the compilation list in the [Gruntfile](https://github.com/hakimel/reveal.js/blob/master/Gruntfile.js).
To create your own theme, start by duplicating a ```.scss``` file in [/css/theme/source](https://github.com/hakimel/reveal.js/blob/master/css/theme/source). It will be automatically compiled by Grunt from Sass to CSS (see the [Gruntfile](https://github.com/hakimel/reveal.js/blob/master/Gruntfile.js)) when you run `npm run build -- css-themes`.
Each theme file does four things in the following order:
@@ -19,5 +19,3 @@ This is where you override the default theme. Either by specifying variables (se
4. **Include [/css/theme/template/theme.scss](https://github.com/hakimel/reveal.js/blob/master/css/theme/template/theme.scss)**
The template theme file which will generate final CSS output based on the currently defined variables.
When you are done, run `grunt css-themes` to compile the Sass file to CSS and you are ready to use your new theme.
@@ -1,7 +1,7 @@
/**
* Black theme for reveal.js. This is the opposite of the 'white' theme.
*
* Copyright (C) 2015 Hakim El Hattab, http://hakim.se
* By Hakim El Hattab, http://hakim.se
*/
@@ -21,7 +21,7 @@ $backgroundColor: #222;
$mainColor: #fff;
$headingColor: #fff;
$mainFontSize: 38px;
$mainFontSize: 42px;
$mainFont: 'Source Sans Pro', Helvetica, sans-serif;
$headingFont: 'Source Sans Pro', Helvetica, sans-serif;
$headingTextShadow: none;
@@ -1,7 +1,7 @@
/**
* White theme for reveal.js. This is the opposite of the 'black' theme.
*
* Copyright (C) 2015 Hakim El Hattab, http://hakim.se
* By Hakim El Hattab, http://hakim.se
*/
@@ -21,7 +21,7 @@ $backgroundColor: #fff;
$mainColor: #222;
$headingColor: #222;
$mainFontSize: 38px;
$mainFontSize: 42px;
$mainFont: 'Source Sans Pro', Helvetica, sans-serif;
$headingFont: 'Source Sans Pro', Helvetica, sans-serif;
$headingTextShadow: none;
+14 -376
View File
@@ -1,23 +1,15 @@
<!doctype html>
<html lang="en">
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>reveal.js - The HTML Presentation Framework</title>
<meta name="description" content="A framework for easily creating beautiful presentations using HTML">
<meta name="author" content="Hakim El Hattab">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<title>reveal.js</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css" id="theme">
<link rel="stylesheet" href="css/theme/black.css">
<!-- Code syntax highlighting -->
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
@@ -28,384 +20,30 @@
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1>Reveal.js</h1>
<h3>The HTML Presentation Framework</h3>
<p>
<small>Created by <a href="http://hakim.se">Hakim El Hattab</a> / <a href="http://twitter.com/hakimel">@hakimel</a></small>
</p>
</section>
<section>
<h2>Hello There</h2>
<p>
reveal.js enables you to create beautiful interactive slide decks using HTML. This presentation will show you examples of what it can do.
</p>
</section>
<!-- Example of nested vertical slides -->
<section>
<section>
<h2>Vertical Slides</h2>
<p>Slides can be nested inside of each other.</p>
<p>Use the <em>Space</em> key to navigate through all slides.</p>
<br>
<a href="#" class="navigate-down">
<img width="178" height="238" data-src="https://s3.amazonaws.com/hakim-static/reveal-js/arrow.png" alt="Down arrow">
</a>
</section>
<section>
<h2>Basement Level 1</h2>
<p>Nested slides are useful for adding additional detail underneath a high level horizontal slide.</p>
</section>
<section>
<h2>Basement Level 2</h2>
<p>That's it, time to go back up.</p>
<br>
<a href="#/2">
<img width="178" height="238" data-src="https://s3.amazonaws.com/hakim-static/reveal-js/arrow.png" alt="Up arrow" style="transform: rotate(180deg); -webkit-transform: rotate(180deg);">
</a>
</section>
</section>
<section>
<h2>Slides</h2>
<p>
Not a coder? Not a problem. There's a fully-featured visual editor for authoring these, try it out at <a href="http://slides.com" target="_blank">http://slides.com</a>.
</p>
</section>
<section>
<h2>Point of View</h2>
<p>
Press <strong>ESC</strong> to enter the slide overview.
</p>
<p>
Hold down alt and click on any element to zoom in on it using <a href="http://lab.hakim.se/zoom-js">zoom.js</a>. Alt + click anywhere to zoom back out.
</p>
</section>
<section>
<h2>Touch Optimized</h2>
<p>
Presentations look great on touch devices, like mobile phones and tablets. Simply swipe through your slides.
</p>
</section>
<section data-markdown>
<script type="text/template">
## Markdown support
Write content using inline or external Markdown.
Instructions and more info available in the [readme](https://github.com/hakimel/reveal.js#markdown).
```
<section data-markdown>
## Markdown support
Write content using inline or external Markdown.
Instructions and more info available in the [readme](https://github.com/hakimel/reveal.js#markdown).
</section>
```
</script>
</section>
<section>
<section id="fragments">
<h2>Fragments</h2>
<p>Hit the next arrow...</p>
<p class="fragment">... to step through ...</p>
<p><span class="fragment">... a</span> <span class="fragment">fragmented</span> <span class="fragment">slide.</span></p>
<aside class="notes">
This slide has fragments which are also stepped through in the notes window.
</aside>
</section>
<section>
<h2>Fragment Styles</h2>
<p>There's different types of fragments, like:</p>
<p class="fragment grow">grow</p>
<p class="fragment shrink">shrink</p>
<p class="fragment fade-out">fade-out</p>
<p class="fragment current-visible">current-visible</p>
<p class="fragment highlight-red">highlight-red</p>
<p class="fragment highlight-blue">highlight-blue</p>
</section>
</section>
<section id="transitions">
<h2>Transition Styles</h2>
<p>
You can select from different transitions, like: <br>
<a href="?transition=none#/transitions">None</a> -
<a href="?transition=fade#/transitions">Fade</a> -
<a href="?transition=slide#/transitions">Slide</a> -
<a href="?transition=convex#/transitions">Convex</a> -
<a href="?transition=concave#/transitions">Concave</a> -
<a href="?transition=zoom#/transitions">Zoom</a>
</p>
</section>
<section id="themes">
<h2>Themes</h2>
<p>
reveal.js comes with a few themes built in: <br>
<!-- Hacks to swap themes after the page has loaded. Not flexible and only intended for the reveal.js demo deck. -->
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/black.css'); return false;">Black (default)</a> -
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/white.css'); return false;">White</a> -
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/league.css'); return false;">League</a> -
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/sky.css'); return false;">Sky</a> -
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/beige.css'); return false;">Beige</a> -
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/simple.css'); return false;">Simple</a> <br>
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/serif.css'); return false;">Serif</a> -
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/blood.css'); return false;">Blood</a> -
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/night.css'); return false;">Night</a> -
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/moon.css'); return false;">Moon</a> -
<a href="#" onclick="document.getElementById('theme').setAttribute('href','css/theme/solarized.css'); return false;">Solarized</a>
</p>
</section>
<section>
<section data-background="#dddddd">
<h2>Slide Backgrounds</h2>
<p>
Set <code>data-background="#dddddd"</code> on a slide to change the background color. All CSS color formats are supported.
</p>
<a href="#" class="navigate-down">
<img width="178" height="238" data-src="https://s3.amazonaws.com/hakim-static/reveal-js/arrow.png" alt="Down arrow">
</a>
</section>
<section data-background="https://s3.amazonaws.com/hakim-static/reveal-js/image-placeholder.png">
<h2>Image Backgrounds</h2>
<pre><code>&lt;section data-background="image.png"&gt;</code></pre>
</section>
<section data-background="https://s3.amazonaws.com/hakim-static/reveal-js/image-placeholder.png" data-background-repeat="repeat" data-background-size="100px">
<h2>Tiled Backgrounds</h2>
<pre><code style="word-wrap: break-word;">&lt;section data-background="image.png" data-background-repeat="repeat" data-background-size="100px"&gt;</code></pre>
</section>
<section data-background-video="https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.mp4,https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.webm" data-background-color="#000000">
<div style="background-color: rgba(0, 0, 0, 0.9); color: #fff; padding: 20px;">
<h2>Video Backgrounds</h2>
<pre><code style="word-wrap: break-word;">&lt;section data-background-video="video.mp4,video.webm"&gt;</code></pre>
</div>
</section>
<section data-background="http://i.giphy.com/90F8aUepslB84.gif">
<h2>... and GIFs!</h2>
</section>
</section>
<section data-transition="slide" data-background="#4d7e65" data-background-transition="zoom">
<h2>Background Transitions</h2>
<p>
Different background transitions are available via the backgroundTransition option. This one's called "zoom".
</p>
<pre><code>Reveal.configure({ backgroundTransition: 'zoom' })</code></pre>
</section>
<section data-transition="slide" data-background="#b5533c" data-background-transition="zoom">
<h2>Background Transitions</h2>
<p>
You can override background transitions per-slide.
</p>
<pre><code style="word-wrap: break-word;">&lt;section data-background-transition="zoom"&gt;</code></pre>
</section>
<section>
<h2>Pretty Code</h2>
<pre><code data-trim contenteditable>
function linkify( selector ) {
if( supports3DTransforms ) {
var nodes = document.querySelectorAll( selector );
for( var i = 0, len = nodes.length; i &lt; len; i++ ) {
var node = nodes[i];
if( !node.className ) {
node.className += ' roll';
}
}
}
}
</code></pre>
<p>Code syntax highlighting courtesy of <a href="http://softwaremaniacs.org/soft/highlight/en/description/">highlight.js</a>.</p>
</section>
<section>
<h2>Marvelous List</h2>
<ul>
<li>No order here</li>
<li>Or here</li>
<li>Or here</li>
<li>Or here</li>
</ul>
</section>
<section>
<h2>Fantastic Ordered List</h2>
<ol>
<li>One is smaller than...</li>
<li>Two is smaller than...</li>
<li>Three!</li>
</ol>
</section>
<section>
<h2>Tabular Tables</h2>
<table>
<thead>
<tr>
<th>Item</th>
<th>Value</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr>
<td>Apples</td>
<td>$1</td>
<td>7</td>
</tr>
<tr>
<td>Lemonade</td>
<td>$2</td>
<td>18</td>
</tr>
<tr>
<td>Bread</td>
<td>$3</td>
<td>2</td>
</tr>
</tbody>
</table>
</section>
<section>
<h2>Clever Quotes</h2>
<p>
These guys come in two forms, inline: <q cite="http://searchservervirtualization.techtarget.com/definition/Our-Favorite-Technology-Quotations">
&ldquo;The nice thing about standards is that there are so many to choose from&rdquo;</q> and block:
</p>
<blockquote cite="http://searchservervirtualization.techtarget.com/definition/Our-Favorite-Technology-Quotations">
&ldquo;For years there has been a theory that millions of monkeys typing at random on millions of typewriters would
reproduce the entire works of Shakespeare. The Internet has proven this theory to be untrue.&rdquo;
</blockquote>
</section>
<section>
<h2>Intergalactic Interconnections</h2>
<p>
You can link between slides internally,
<a href="#/2/3">like this</a>.
</p>
</section>
<section>
<h2>Speaker View</h2>
<p>There's a <a href="https://github.com/hakimel/reveal.js#speaker-notes">speaker view</a>. It includes a timer, preview of the upcoming slide as well as your speaker notes.</p>
<p>Press the <em>S</em> key to try it out.</p>
<aside class="notes">
Oh hey, these are some notes. They'll be hidden in your presentation, but you can see them if you open the speaker notes window (hit 's' on your keyboard).
</aside>
</section>
<section>
<h2>Export to PDF</h2>
<p>Presentations can be <a href="https://github.com/hakimel/reveal.js#pdf-export">exported to PDF</a>, here's an example:</p>
<iframe src="//www.slideshare.net/slideshow/embed_code/42840540" width="445" height="355" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" style="border:3px solid #666; margin-bottom:5px; max-width: 100%;" allowfullscreen> </iframe>
</section>
<section>
<h2>Global State</h2>
<p>
Set <code>data-state="something"</code> on a slide and <code>"something"</code>
will be added as a class to the document element when the slide is open. This lets you
apply broader style changes, like switching the page background.
</p>
</section>
<section data-state="customevent">
<h2>State Events</h2>
<p>
Additionally custom events can be triggered on a per slide basis by binding to the <code>data-state</code> name.
</p>
<pre><code class="javascript" data-trim contenteditable style="font-size: 18px;">
Reveal.addEventListener( 'customevent', function() {
console.log( '"customevent" has fired' );
} );
</code></pre>
</section>
<section>
<h2>Take a Moment</h2>
<p>
Press B or . on your keyboard to pause the presentation. This is helpful when you're on stage and want to take distracting slides off the screen.
</p>
</section>
<section>
<h2>Much more</h2>
<ul>
<li>Right-to-left support</li>
<li><a href="https://github.com/hakimel/reveal.js#api">Extensive JavaScript API</a></li>
<li><a href="https://github.com/hakimel/reveal.js#auto-sliding">Auto-progression</a></li>
<li><a href="https://github.com/hakimel/reveal.js#parallax-background">Parallax backgrounds</a></li>
<li><a href="https://github.com/hakimel/reveal.js#keyboard-bindings">Custom keyboard bindings</a></li>
</ul>
</section>
<section style="text-align: left;">
<h1>THE END</h1>
<p>
- <a href="http://slides.com">Try the online editor</a> <br>
- <a href="https://github.com/hakimel/reveal.js">Source code &amp; documentation</a>
</p>
</section>
<section>Slide 1</section>
<section>Slide 2</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true }
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>
File diff suppressed because it is too large Load Diff
@@ -6,112 +6,75 @@ based on dark.css by Ivan Sagalaev
*/
.hljs {
display: block; padding: 0.5em;
background: #3F3F3F;
color: #DCDCDC;
display: block;
overflow-x: auto;
padding: 0.5em;
background: #3f3f3f;
color: #dcdcdc;
}
.hljs-keyword,
.hljs-tag,
.css .hljs-class,
.css .hljs-id,
.lisp .hljs-title,
.nginx .hljs-title,
.hljs-request,
.hljs-status,
.clojure .hljs-attribute {
color: #E3CEAB;
.hljs-selector-tag,
.hljs-tag {
color: #e3ceab;
}
.django .hljs-template_tag,
.django .hljs-variable,
.django .hljs-filter .hljs-argument {
color: #DCDCDC;
.hljs-template-tag {
color: #dcdcdc;
}
.hljs-number,
.hljs-date {
color: #8CD0D3;
.hljs-number {
color: #8cd0d3;
}
.dos .hljs-envvar,
.dos .hljs-stream,
.hljs-variable,
.apache .hljs-sqbracket {
color: #EFDCBC;
.hljs-template-variable,
.hljs-attribute {
color: #efdcbc;
}
.dos .hljs-flow,
.diff .hljs-change,
.python .exception,
.python .hljs-built_in,
.hljs-literal,
.tex .hljs-special {
color: #EFEFAF;
.hljs-literal {
color: #efefaf;
}
.diff .hljs-chunk,
.hljs-subst {
color: #8F8F8F;
color: #8f8f8f;
}
.dos .hljs-keyword,
.python .hljs-decorator,
.hljs-title,
.haskell .hljs-type,
.diff .hljs-header,
.ruby .hljs-class .hljs-parent,
.apache .hljs-tag,
.nginx .hljs-built_in,
.tex .hljs-command,
.hljs-prompt {
color: #efef8f;
.hljs-name,
.hljs-selector-id,
.hljs-selector-class,
.hljs-section,
.hljs-type {
color: #efef8f;
}
.dos .hljs-winutils,
.ruby .hljs-symbol,
.ruby .hljs-symbol .hljs-string,
.ruby .hljs-string {
color: #DCA3A3;
.hljs-symbol,
.hljs-bullet,
.hljs-link {
color: #dca3a3;
}
.diff .hljs-deletion,
.hljs-deletion,
.hljs-string,
.hljs-tag .hljs-value,
.hljs-preprocessor,
.hljs-pragma,
.hljs-built_in,
.sql .hljs-aggregate,
.hljs-javadoc,
.smalltalk .hljs-class,
.smalltalk .hljs-localvars,
.smalltalk .hljs-array,
.css .hljs-rules .hljs-value,
.hljs-attr_selector,
.hljs-pseudo,
.apache .hljs-cbracket,
.tex .hljs-formula,
.coffeescript .hljs-attribute {
color: #CC9393;
.hljs-builtin-name {
color: #cc9393;
}
.hljs-shebang,
.diff .hljs-addition,
.hljs-addition,
.hljs-comment,
.java .hljs-annotation,
.hljs-template_comment,
.hljs-pi,
.hljs-doctype {
color: #7F9F7F;
.hljs-quote,
.hljs-meta {
color: #7f9f7f;
}
.coffeescript .javascript,
.javascript .xml,
.tex .hljs-formula,
.xml .javascript,
.xml .vbscript,
.xml .css,
.xml .hljs-cdata {
opacity: 0.5;
.hljs-emphasis {
font-style: italic;
}
.hljs-strong {
font-weight: bold;
}
+9 -8
View File
@@ -1,8 +1,9 @@
/**
Head JS The only script in your <HEAD>
Copyright Tero Piirainen (tipiirai)
License MIT / http://bit.ly/mit-license
Version 0.96
http://headjs.com
*/(function(a){function z(){d||(d=!0,s(e,function(a){p(a)}))}function y(c,d){var e=a.createElement("script");e.type="text/"+(c.type||"javascript"),e.src=c.src||c,e.async=!1,e.onreadystatechange=e.onload=function(){var a=e.readyState;!d.done&&(!a||/loaded|complete/.test(a))&&(d.done=!0,d())},(a.body||b).appendChild(e)}function x(a,b){if(a.state==o)return b&&b();if(a.state==n)return k.ready(a.name,b);if(a.state==m)return a.onpreload.push(function(){x(a,b)});a.state=n,y(a.url,function(){a.state=o,b&&b(),s(g[a.name],function(a){p(a)}),u()&&d&&s(g.ALL,function(a){p(a)})})}function w(a,b){a.state===undefined&&(a.state=m,a.onpreload=[],y({src:a.url,type:"cache"},function(){v(a)}))}function v(a){a.state=l,s(a.onpreload,function(a){a.call()})}function u(a){a=a||h;var b;for(var c in a){if(a.hasOwnProperty(c)&&a[c].state!=o)return!1;b=!0}return b}function t(a){return Object.prototype.toString.call(a)=="[object Function]"}function s(a,b){if(!!a){typeof a=="object"&&(a=[].slice.call(a));for(var c=0;c<a.length;c++)b.call(a,a[c],c)}}function r(a){var b;if(typeof a=="object")for(var c in a)a[c]&&(b={name:c,url:a[c]});else b={name:q(a),url:a};var d=h[b.name];if(d&&d.url===b.url)return d;h[b.name]=b;return b}function q(a){var b=a.split("/"),c=b[b.length-1],d=c.indexOf("?");return d!=-1?c.substring(0,d):c}function p(a){a._done||(a(),a._done=1)}var b=a.documentElement,c,d,e=[],f=[],g={},h={},i=a.createElement("script").async===!0||"MozAppearance"in a.documentElement.style||window.opera,j=window.head_conf&&head_conf.head||"head",k=window[j]=window[j]||function(){k.ready.apply(null,arguments)},l=1,m=2,n=3,o=4;i?k.js=function(){var a=arguments,b=a[a.length-1],c={};t(b)||(b=null),s(a,function(d,e){d!=b&&(d=r(d),c[d.name]=d,x(d,b&&e==a.length-2?function(){u(c)&&p(b)}:null))});return k}:k.js=function(){var a=arguments,b=[].slice.call(a,1),d=b[0];if(!c){f.push(function(){k.js.apply(null,a)});return k}d?(s(b,function(a){t(a)||w(r(a))}),x(r(a[0]),t(d)?d:function(){k.js.apply(null,b)})):x(r(a[0]));return k},k.ready=function(b,c){if(b==a){d?p(c):e.push(c);return k}t(b)&&(c=b,b="ALL");if(typeof b!="string"||!t(c))return k;var f=h[b];if(f&&f.state==o||b=="ALL"&&u()&&d){p(c);return k}var i=g[b];i?i.push(c):i=g[b]=[c];return k},k.ready(a,function(){u()&&s(g.ALL,function(a){p(a)}),k.feature&&k.feature("domloaded",!0)});if(window.addEventListener)a.addEventListener("DOMContentLoaded",z,!1),window.addEventListener("load",z,!1);else if(window.attachEvent){a.attachEvent("onreadystatechange",function(){a.readyState==="complete"&&z()});var A=1;try{A=window.frameElement}catch(B){}!A&&b.doScroll&&function(){try{b.doScroll("left"),z()}catch(a){setTimeout(arguments.callee,1);return}}(),window.attachEvent("onload",z)}!a.readyState&&a.addEventListener&&(a.readyState="loading",a.addEventListener("DOMContentLoaded",handler=function(){a.removeEventListener("DOMContentLoaded",handler,!1),a.readyState="complete"},!1)),setTimeout(function(){c=!0,s(f,function(a){a()})},300)})(document)
/*! head.core - v1.0.2 */
(function(n,t){"use strict";function r(n){a[a.length]=n}function k(n){var t=new RegExp(" ?\\b"+n+"\\b");c.className=c.className.replace(t,"")}function p(n,t){for(var i=0,r=n.length;i<r;i++)t.call(n,n[i],i)}function tt(){var t,e,f,o;c.className=c.className.replace(/ (w-|eq-|gt-|gte-|lt-|lte-|portrait|no-portrait|landscape|no-landscape)\d+/g,"");t=n.innerWidth||c.clientWidth;e=n.outerWidth||n.screen.width;u.screen.innerWidth=t;u.screen.outerWidth=e;r("w-"+t);p(i.screens,function(n){t>n?(i.screensCss.gt&&r("gt-"+n),i.screensCss.gte&&r("gte-"+n)):t<n?(i.screensCss.lt&&r("lt-"+n),i.screensCss.lte&&r("lte-"+n)):t===n&&(i.screensCss.lte&&r("lte-"+n),i.screensCss.eq&&r("e-q"+n),i.screensCss.gte&&r("gte-"+n))});f=n.innerHeight||c.clientHeight;o=n.outerHeight||n.screen.height;u.screen.innerHeight=f;u.screen.outerHeight=o;u.feature("portrait",f>t);u.feature("landscape",f<t)}function it(){n.clearTimeout(b);b=n.setTimeout(tt,50)}var y=n.document,rt=n.navigator,ut=n.location,c=y.documentElement,a=[],i={screens:[240,320,480,640,768,800,1024,1280,1440,1680,1920],screensCss:{gt:!0,gte:!1,lt:!0,lte:!1,eq:!1},browsers:[{ie:{min:6,max:11}}],browserCss:{gt:!0,gte:!1,lt:!0,lte:!1,eq:!0},html5:!0,page:"-page",section:"-section",head:"head"},v,u,s,w,o,h,l,d,f,g,nt,e,b;if(n.head_conf)for(v in n.head_conf)n.head_conf[v]!==t&&(i[v]=n.head_conf[v]);u=n[i.head]=function(){u.ready.apply(null,arguments)};u.feature=function(n,t,i){return n?(Object.prototype.toString.call(t)==="[object Function]"&&(t=t.call()),r((t?"":"no-")+n),u[n]=!!t,i||(k("no-"+n),k(n),u.feature()),u):(c.className+=" "+a.join(" "),a=[],u)};u.feature("js",!0);s=rt.userAgent.toLowerCase();w=/mobile|android|kindle|silk|midp|phone|(windows .+arm|touch)/.test(s);u.feature("mobile",w,!0);u.feature("desktop",!w,!0);s=/(chrome|firefox)[ \/]([\w.]+)/.exec(s)||/(iphone|ipad|ipod)(?:.*version)?[ \/]([\w.]+)/.exec(s)||/(android)(?:.*version)?[ \/]([\w.]+)/.exec(s)||/(webkit|opera)(?:.*version)?[ \/]([\w.]+)/.exec(s)||/(msie) ([\w.]+)/.exec(s)||/(trident).+rv:(\w.)+/.exec(s)||[];o=s[1];h=parseFloat(s[2]);switch(o){case"msie":case"trident":o="ie";h=y.documentMode||h;break;case"firefox":o="ff";break;case"ipod":case"ipad":case"iphone":o="ios";break;case"webkit":o="safari"}for(u.browser={name:o,version:h},u.browser[o]=!0,l=0,d=i.browsers.length;l<d;l++)for(f in i.browsers[l])if(o===f)for(r(f),g=i.browsers[l][f].min,nt=i.browsers[l][f].max,e=g;e<=nt;e++)h>e?(i.browserCss.gt&&r("gt-"+f+e),i.browserCss.gte&&r("gte-"+f+e)):h<e?(i.browserCss.lt&&r("lt-"+f+e),i.browserCss.lte&&r("lte-"+f+e)):h===e&&(i.browserCss.lte&&r("lte-"+f+e),i.browserCss.eq&&r("eq-"+f+e),i.browserCss.gte&&r("gte-"+f+e));else r("no-"+f);r(o);r(o+parseInt(h,10));i.html5&&o==="ie"&&h<9&&p("abbr|article|aside|audio|canvas|details|figcaption|figure|footer|header|hgroup|main|mark|meter|nav|output|progress|section|summary|time|video".split("|"),function(n){y.createElement(n)});p(ut.pathname.split("/"),function(n,u){if(this.length>2&&this[u+1]!==t)u&&r(this.slice(u,u+1).join("-").toLowerCase()+i.section);else{var f=n||"index",e=f.indexOf(".");e>0&&(f=f.substring(0,e));c.id=f.toLowerCase()+i.page;u||r("root"+i.section)}});u.screen={height:n.screen.height,width:n.screen.width};tt();b=0;n.addEventListener?n.addEventListener("resize",it,!1):n.attachEvent("onresize",it)})(window);
/*! head.css3 - v1.0.0 */
(function(n,t){"use strict";function a(n){for(var r in n)if(i[n[r]]!==t)return!0;return!1}function r(n){var t=n.charAt(0).toUpperCase()+n.substr(1),i=(n+" "+c.join(t+" ")+t).split(" ");return!!a(i)}var h=n.document,o=h.createElement("i"),i=o.style,s=" -o- -moz- -ms- -webkit- -khtml- ".split(" "),c="Webkit Moz O ms Khtml".split(" "),l=n.head_conf&&n.head_conf.head||"head",u=n[l],f={gradient:function(){var n="background-image:";return i.cssText=(n+s.join("gradient(linear,left top,right bottom,from(#9f9),to(#fff));"+n)+s.join("linear-gradient(left top,#eee,#fff);"+n)).slice(0,-n.length),!!i.backgroundImage},rgba:function(){return i.cssText="background-color:rgba(0,0,0,0.5)",!!i.backgroundColor},opacity:function(){return o.style.opacity===""},textshadow:function(){return i.textShadow===""},multiplebgs:function(){i.cssText="background:url(https://),url(https://),red url(https://)";var n=(i.background||"").match(/url/g);return Object.prototype.toString.call(n)==="[object Array]"&&n.length===3},boxshadow:function(){return r("boxShadow")},borderimage:function(){return r("borderImage")},borderradius:function(){return r("borderRadius")},cssreflections:function(){return r("boxReflect")},csstransforms:function(){return r("transform")},csstransitions:function(){return r("transition")},touch:function(){return"ontouchstart"in n},retina:function(){return n.devicePixelRatio>1},fontface:function(){var t=u.browser.name,n=u.browser.version;switch(t){case"ie":return n>=9;case"chrome":return n>=13;case"ff":return n>=6;case"ios":return n>=5;case"android":return!1;case"webkit":return n>=5.1;case"opera":return n>=10;default:return!1}}};for(var e in f)f[e]&&u.feature(e,f[e].call(),!0);u.feature()})(window);
/*! head.load - v1.0.3 */
(function(n,t){"use strict";function w(){}function u(n,t){if(n){typeof n=="object"&&(n=[].slice.call(n));for(var i=0,r=n.length;i<r;i++)t.call(n,n[i],i)}}function it(n,i){var r=Object.prototype.toString.call(i).slice(8,-1);return i!==t&&i!==null&&r===n}function s(n){return it("Function",n)}function a(n){return it("Array",n)}function et(n){var i=n.split("/"),t=i[i.length-1],r=t.indexOf("?");return r!==-1?t.substring(0,r):t}function f(n){(n=n||w,n._done)||(n(),n._done=1)}function ot(n,t,r,u){var f=typeof n=="object"?n:{test:n,success:!t?!1:a(t)?t:[t],failure:!r?!1:a(r)?r:[r],callback:u||w},e=!!f.test;return e&&!!f.success?(f.success.push(f.callback),i.load.apply(null,f.success)):e||!f.failure?u():(f.failure.push(f.callback),i.load.apply(null,f.failure)),i}function v(n){var t={},i,r;if(typeof n=="object")for(i in n)!n[i]||(t={name:i,url:n[i]});else t={name:et(n),url:n};return(r=c[t.name],r&&r.url===t.url)?r:(c[t.name]=t,t)}function y(n){n=n||c;for(var t in n)if(n.hasOwnProperty(t)&&n[t].state!==l)return!1;return!0}function st(n){n.state=ft;u(n.onpreload,function(n){n.call()})}function ht(n){n.state===t&&(n.state=nt,n.onpreload=[],rt({url:n.url,type:"cache"},function(){st(n)}))}function ct(){var n=arguments,t=n[n.length-1],r=[].slice.call(n,1),f=r[0];return(s(t)||(t=null),a(n[0]))?(n[0].push(t),i.load.apply(null,n[0]),i):(f?(u(r,function(n){s(n)||!n||ht(v(n))}),b(v(n[0]),s(f)?f:function(){i.load.apply(null,r)})):b(v(n[0])),i)}function lt(){var n=arguments,t=n[n.length-1],r={};return(s(t)||(t=null),a(n[0]))?(n[0].push(t),i.load.apply(null,n[0]),i):(u(n,function(n){n!==t&&(n=v(n),r[n.name]=n)}),u(n,function(n){n!==t&&(n=v(n),b(n,function(){y(r)&&f(t)}))}),i)}function b(n,t){if(t=t||w,n.state===l){t();return}if(n.state===tt){i.ready(n.name,t);return}if(n.state===nt){n.onpreload.push(function(){b(n,t)});return}n.state=tt;rt(n,function(){n.state=l;t();u(h[n.name],function(n){f(n)});o&&y()&&u(h.ALL,function(n){f(n)})})}function at(n){n=n||"";var t=n.split("?")[0].split(".");return t[t.length-1].toLowerCase()}function rt(t,i){function e(t){t=t||n.event;u.onload=u.onreadystatechange=u.onerror=null;i()}function o(f){f=f||n.event;(f.type==="load"||/loaded|complete/.test(u.readyState)&&(!r.documentMode||r.documentMode<9))&&(n.clearTimeout(t.errorTimeout),n.clearTimeout(t.cssTimeout),u.onload=u.onreadystatechange=u.onerror=null,i())}function s(){if(t.state!==l&&t.cssRetries<=20){for(var i=0,f=r.styleSheets.length;i<f;i++)if(r.styleSheets[i].href===u.href){o({type:"load"});return}t.cssRetries++;t.cssTimeout=n.setTimeout(s,250)}}var u,h,f;i=i||w;h=at(t.url);h==="css"?(u=r.createElement("link"),u.type="text/"+(t.type||"css"),u.rel="stylesheet",u.href=t.url,t.cssRetries=0,t.cssTimeout=n.setTimeout(s,500)):(u=r.createElement("script"),u.type="text/"+(t.type||"javascript"),u.src=t.url);u.onload=u.onreadystatechange=o;u.onerror=e;u.async=!1;u.defer=!1;t.errorTimeout=n.setTimeout(function(){e({type:"timeout"})},7e3);f=r.head||r.getElementsByTagName("head")[0];f.insertBefore(u,f.lastChild)}function vt(){for(var t,u=r.getElementsByTagName("script"),n=0,f=u.length;n<f;n++)if(t=u[n].getAttribute("data-headjs-load"),!!t){i.load(t);return}}function yt(n,t){var v,p,e;return n===r?(o?f(t):d.push(t),i):(s(n)&&(t=n,n="ALL"),a(n))?(v={},u(n,function(n){v[n]=c[n];i.ready(n,function(){y(v)&&f(t)})}),i):typeof n!="string"||!s(t)?i:(p=c[n],p&&p.state===l||n==="ALL"&&y()&&o)?(f(t),i):(e=h[n],e?e.push(t):e=h[n]=[t],i)}function e(){if(!r.body){n.clearTimeout(i.readyTimeout);i.readyTimeout=n.setTimeout(e,50);return}o||(o=!0,vt(),u(d,function(n){f(n)}))}function k(){r.addEventListener?(r.removeEventListener("DOMContentLoaded",k,!1),e()):r.readyState==="complete"&&(r.detachEvent("onreadystatechange",k),e())}var r=n.document,d=[],h={},c={},ut="async"in r.createElement("script")||"MozAppearance"in r.documentElement.style||n.opera,o,g=n.head_conf&&n.head_conf.head||"head",i=n[g]=n[g]||function(){i.ready.apply(null,arguments)},nt=1,ft=2,tt=3,l=4,p;if(r.readyState==="complete")e();else if(r.addEventListener)r.addEventListener("DOMContentLoaded",k,!1),n.addEventListener("load",e,!1);else{r.attachEvent("onreadystatechange",k);n.attachEvent("onload",e);p=!1;try{p=!n.frameElement&&r.documentElement}catch(wt){}p&&p.doScroll&&function pt(){if(!o){try{p.doScroll("left")}catch(t){n.clearTimeout(i.readyTimeout);i.readyTimeout=n.setTimeout(pt,50);return}e()}}()}i.load=i.js=ut?lt:ct;i.test=ot;i.ready=yt;i.ready(r,function(){y()&&u(h.ALL,function(n){f(n)});i.feature&&i.feature("domloaded",!0)})})(window);
/*
//# sourceMappingURL=head.min.js.map
*/
@@ -1,13 +1,14 @@
{
"name": "reveal.js",
"version": "3.1.0",
"version": "3.6.0",
"description": "The HTML Presentation Framework",
"homepage": "http://lab.hakim.se/reveal-js",
"homepage": "http://revealjs.com",
"subdomain": "revealjs",
"main": "js/reveal.js",
"scripts": {
"test": "grunt test",
"start": "grunt serve"
"start": "grunt serve",
"build": "grunt"
},
"author": {
"name": "Hakim El Hattab",
@@ -19,27 +20,24 @@
"url": "git://github.com/hakimel/reveal.js.git"
},
"engines": {
"node": "~0.10.0"
},
"dependencies": {
"underscore": "~1.5.1",
"express": "~2.5.9",
"mustache": "~0.7.2",
"socket.io": "~0.9.16"
"node": ">=4.0.0"
},
"devDependencies": {
"grunt-contrib-qunit": "~0.5.2",
"grunt-contrib-jshint": "~0.6.4",
"grunt-contrib-cssmin": "~0.12.2",
"grunt-contrib-uglify": "~0.2.4",
"grunt-contrib-watch": "~0.5.3",
"grunt-sass": "~0.14.0",
"grunt-contrib-connect": "~0.8.0",
"grunt-autoprefixer": "~1.0.1",
"grunt-zip": "~0.7.0",
"grunt": "~0.4.0",
"node-sass": "~0.9.3"
"express": "^4.15.2",
"grunt": "^1.0.1",
"grunt-autoprefixer": "^3.0.4",
"grunt-cli": "^1.2.0",
"grunt-contrib-connect": "^1.0.2",
"grunt-contrib-cssmin": "^2.1.0",
"grunt-contrib-jshint": "^1.1.0",
"grunt-contrib-qunit": "~1.2.0",
"grunt-contrib-uglify": "^2.3.0",
"grunt-contrib-watch": "^1.0.0",
"grunt-sass": "^2.0.0",
"grunt-retire": "^1.0.7",
"grunt-zip": "~0.17.1",
"mustache": "^2.3.0",
"socket.io": "^1.7.3"
},
"license": "MIT"
}
File diff suppressed because one or more lines are too long
@@ -99,6 +99,13 @@
</script>
</section>
<!-- Images -->
<section data-markdown>
<script type="text/template">
![Sample image](https://s3.amazonaws.com/static.slid.es/logo/v2/slides-symbol-512x512.png)
</script>
</section>
</div>
</div>
@@ -29,3 +29,8 @@ Content 3.1
## External 3.2
Content 3.2
## External 3.3
![External Image](https://s3.amazonaws.com/static.slid.es/logo/v2/slides-symbol-512x512.png)
@@ -4,33 +4,26 @@
* of external markdown documents.
*/
(function( root, factory ) {
if( typeof exports === 'object' ) {
if (typeof define === 'function' && define.amd) {
root.marked = require( './marked' );
root.RevealMarkdown = factory( root.marked );
root.RevealMarkdown.initialize();
} else if( typeof exports === 'object' ) {
module.exports = factory( require( './marked' ) );
}
else {
} else {
// Browser globals (root is window)
root.RevealMarkdown = factory( root.marked );
root.RevealMarkdown.initialize();
}
}( this, function( marked ) {
if( typeof marked === 'undefined' ) {
throw 'The reveal.js Markdown plugin requires marked to be loaded';
}
if( typeof hljs !== 'undefined' ) {
marked.setOptions({
highlight: function( lang, code ) {
return hljs.highlightAuto( lang, code ).value;
}
});
}
var DEFAULT_SLIDE_SEPARATOR = '^\r?\n---\r?\n$',
DEFAULT_NOTES_SEPARATOR = 'note:',
DEFAULT_NOTES_SEPARATOR = 'notes?:',
DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR = '\\\.element\\\s*?(.+?)$',
DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR = '\\\.slide:\\\s*?(\\\S.+?)$';
var SCRIPT_END_PLACEHOLDER = '__SCRIPT_END__';
/**
* Retrieves the markdown contents of a slide section
@@ -38,11 +31,15 @@
*/
function getMarkdownFromSlide( section ) {
var template = section.querySelector( 'script' );
// look for a <script> or <textarea data-template> wrapper
var template = section.querySelector( '[data-template]' ) || section.querySelector( 'script' );
// strip leading whitespace so it isn't evaluated as code
var text = ( template || section ).textContent;
// restore script end tags
text = text.replace( new RegExp( SCRIPT_END_PLACEHOLDER, 'g' ), '</script>' );
var leadingWs = text.match( /^\n?(\s*)/ )[1].length,
leadingTabs = text.match( /^\n?(\t*)/ )[1].length;
@@ -112,9 +109,13 @@
var notesMatch = content.split( new RegExp( options.notesSeparator, 'mgi' ) );
if( notesMatch.length === 2 ) {
content = notesMatch[0] + '<aside class="notes" data-markdown>' + notesMatch[1].trim() + '</aside>';
content = notesMatch[0] + '<aside class="notes">' + marked(notesMatch[1].trim()) + '</aside>';
}
// prevent script end tags in the content from interfering
// with parsing
content = content.replace( /<\/script>/g, SCRIPT_END_PLACEHOLDER );
return '<script type="text/template">' + content + '</script>';
}
@@ -177,7 +178,7 @@
markdownSections += '<section '+ options.attributes +'>';
sectionStack[i].forEach( function( child ) {
markdownSections += '<section data-markdown>' + createMarkdownSlide( child, options ) + '</section>';
markdownSections += '<section data-markdown>' + createMarkdownSlide( child, options ) + '</section>';
} );
markdownSections += '</section>';
@@ -379,6 +380,24 @@
return {
initialize: function() {
if( typeof marked === 'undefined' ) {
throw 'The reveal.js Markdown plugin requires marked to be loaded';
}
if( typeof hljs !== 'undefined' ) {
marked.setOptions({
highlight: function( code, lang ) {
return hljs.highlightAuto( code, [lang] ).value;
}
});
}
var options = Reveal.getConfig().markdown;
if ( options ) {
marked.setOptions( options );
}
processSlides();
convertSlides();
},
File diff suppressed because one or more lines are too long
@@ -7,14 +7,17 @@
var RevealMath = window.RevealMath || (function(){
var options = Reveal.getConfig().math || {};
options.mathjax = options.mathjax || 'https://cdn.mathjax.org/mathjax/latest/MathJax.js';
options.mathjax = options.mathjax || 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js';
options.config = options.config || 'TeX-AMS_HTML-full';
loadScript( options.mathjax + '?config=' + options.config, function() {
MathJax.Hub.Config({
messageStyle: 'none',
tex2jax: { inlineMath: [['$','$'],['\\(','\\)']] },
tex2jax: {
inlineMath: [['$','$'],['\\(','\\)']] ,
skipTags: ['script','noscript','style','textarea','pre']
},
skipStartupTypeset: true
});
@@ -8,6 +8,6 @@
if (data.socketId !== socketId) { return; }
if( window.location.host === 'localhost:1947' ) return;
Reveal.slide(data.indexh, data.indexv, data.indexf, 'remote');
Reveal.setState(data.state);
});
}());
@@ -1,37 +1,45 @@
var http = require('http');
var express = require('express');
var fs = require('fs');
var io = require('socket.io');
var crypto = require('crypto');
var app = express.createServer();
var staticDir = express.static;
var app = express();
var staticDir = express.static;
var server = http.createServer(app);
io = io.listen(app);
io = io(server);
var opts = {
port: process.env.PORT || 1948,
baseDir : __dirname + '/../../'
};
io.sockets.on('connection', function(socket) {
socket.on('slidechanged', function(slideData) {
if (typeof slideData.secret == 'undefined' || slideData.secret == null || slideData.secret === '') return;
if (createHash(slideData.secret) === slideData.socketId) {
slideData.secret = null;
socket.broadcast.emit(slideData.socketId, slideData);
io.on( 'connection', function( socket ) {
socket.on('multiplex-statechanged', function(data) {
if (typeof data.secret == 'undefined' || data.secret == null || data.secret === '') return;
if (createHash(data.secret) === data.socketId) {
data.secret = null;
socket.broadcast.emit(data.socketId, data);
};
});
});
app.configure(function() {
[ 'css', 'js', 'plugin', 'lib' ].forEach(function(dir) {
app.use('/' + dir, staticDir(opts.baseDir + dir));
});
[ 'css', 'js', 'plugin', 'lib' ].forEach(function(dir) {
app.use('/' + dir, staticDir(opts.baseDir + dir));
});
app.get("/", function(req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
fs.createReadStream(opts.baseDir + '/index.html').pipe(res);
var stream = fs.createReadStream(opts.baseDir + '/index.html');
stream.on('error', function( error ) {
res.write('<style>body{font-family: sans-serif;}</style><h2>reveal.js multiplex server.</h2><a href="/token">Generate token</a>');
res.end();
});
stream.on('readable', function() {
stream.pipe(res);
});
});
app.get("/token", function(req,res) {
@@ -47,7 +55,7 @@ var createHash = function(secret) {
};
// Actually listen
app.listen(opts.port || null);
server.listen( opts.port || null );
var brown = '\033[33m',
green = '\033[32m',
@@ -1,51 +1,34 @@
(function() {
// Don't emit events from inside of notes windows
if ( window.location.search.match( /receiver/gi ) ) { return; }
var multiplex = Reveal.getConfig().multiplex;
var socket = io.connect(multiplex.url);
var socket = io.connect( multiplex.url );
var notify = function( slideElement, indexh, indexv, origin ) {
if( typeof origin === 'undefined' && origin !== 'remote' ) {
var nextindexh;
var nextindexv;
function post() {
var fragmentindex = Reveal.getIndices().f;
if (typeof fragmentindex == 'undefined') {
fragmentindex = 0;
}
var messageData = {
state: Reveal.getState(),
secret: multiplex.secret,
socketId: multiplex.id
};
if (slideElement.nextElementSibling && slideElement.parentNode.nodeName == 'SECTION') {
nextindexh = indexh;
nextindexv = indexv + 1;
} else {
nextindexh = indexh + 1;
nextindexv = 0;
}
socket.emit( 'multiplex-statechanged', messageData );
var slideData = {
indexh : indexh,
indexv : indexv,
indexf : fragmentindex,
nextindexh : nextindexh,
nextindexv : nextindexv,
secret: multiplex.secret,
socketId : multiplex.id
};
socket.emit('slidechanged', slideData);
}
}
Reveal.addEventListener( 'slidechanged', function( event ) {
notify( event.currentSlide, event.indexh, event.indexv, event.origin );
} );
var fragmentNotify = function( event ) {
notify( Reveal.getCurrentSlide(), Reveal.getIndices().h, Reveal.getIndices().v, event.origin );
};
Reveal.addEventListener( 'fragmentshown', fragmentNotify );
Reveal.addEventListener( 'fragmenthidden', fragmentNotify );
}());
// post once the page is loaded, so the client follows also on "open URL".
window.addEventListener( 'load', post );
// Monitor events that trigger a change in state
Reveal.addEventListener( 'slidechanged', post );
Reveal.addEventListener( 'fragmentshown', post );
Reveal.addEventListener( 'fragmenthidden', post );
Reveal.addEventListener( 'overviewhidden', post );
Reveal.addEventListener( 'overviewshown', post );
Reveal.addEventListener( 'paused', post );
Reveal.addEventListener( 'resumed', post );
}());
@@ -41,10 +41,15 @@
}
// When a new notes window connects, post our current state
socket.on( 'connect', function( data ) {
socket.on( 'new-subscriber', function( data ) {
post();
} );
// When the state changes from inside of the speaker view
socket.on( 'statechanged-speaker', function( data ) {
Reveal.setState( data.state );
} );
// Monitor events that trigger a change in state
Reveal.addEventListener( 'slidechanged', post );
Reveal.addEventListener( 'fragmentshown', post );
@@ -1,37 +1,40 @@
var http = require('http');
var express = require('express');
var fs = require('fs');
var io = require('socket.io');
var _ = require('underscore');
var Mustache = require('mustache');
var app = express.createServer();
var app = express();
var staticDir = express.static;
var server = http.createServer(app);
io = io.listen(app);
io = io(server);
var opts = {
port : 1947,
baseDir : __dirname + '/../../'
};
io.sockets.on( 'connection', function( socket ) {
io.on( 'connection', function( socket ) {
socket.on( 'connect', function( data ) {
socket.broadcast.emit( 'connect', data );
socket.on( 'new-subscriber', function( data ) {
socket.broadcast.emit( 'new-subscriber', data );
});
socket.on( 'statechanged', function( data ) {
delete data.state.overview;
socket.broadcast.emit( 'statechanged', data );
});
socket.on( 'statechanged-speaker', function( data ) {
delete data.state.overview;
socket.broadcast.emit( 'statechanged-speaker', data );
});
});
app.configure( function() {
[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
});
[ 'css', 'js', 'images', 'plugin', 'lib' ].forEach( function( dir ) {
app.use( '/' + dir, staticDir( opts.baseDir + dir ) );
});
app.get('/', function( req, res ) {
@@ -52,7 +55,7 @@ app.get( '/notes/:socketId', function( req, res ) {
});
// Actually listen
app.listen( opts.port || null );
server.listen( opts.port || null );
var brown = '\033[33m',
green = '\033[32m',
@@ -62,5 +65,5 @@ var slidesLocation = 'http://localhost' + ( opts.port ? ( ':' + opts.port ) : ''
console.log( brown + 'reveal.js - Speaker Notes' + reset );
console.log( '1. Open the slides at ' + green + slidesLocation + reset );
console.log( '2. Click on the link your JS console to go to the notes page' );
console.log( '2. Click on the link in your JS console to go to the notes page' );
console.log( '3. Advance through your slides and your notes will advance automatically' );
@@ -8,6 +8,7 @@
<style>
body {
font-family: Helvetica;
font-size: 18px;
}
#current-slide,
@@ -30,15 +31,26 @@
position: absolute;
top: 10px;
left: 10px;
font-weight: bold;
font-size: 14px;
z-index: 2;
color: rgba( 255, 255, 255, 0.9 );
}
.overlay-element {
height: 34px;
line-height: 34px;
padding: 0 10px;
text-shadow: none;
background: rgba( 220, 220, 220, 0.8 );
color: #222;
font-size: 14px;
}
.overlay-element.interactive:hover {
background: rgba( 220, 220, 220, 1 );
}
#current-slide {
position: absolute;
width: 65%;
width: 60%;
height: 100%;
top: 0;
left: 0;
@@ -47,19 +59,20 @@
#upcoming-slide {
position: absolute;
width: 35%;
width: 40%;
height: 40%;
right: 0;
top: 0;
}
/* Speaker controls */
#speaker-controls {
position: absolute;
top: 40%;
right: 0;
width: 35%;
width: 40%;
height: 60%;
overflow: auto;
font-size: 18px;
}
@@ -124,26 +137,108 @@
font-size: 1.2em;
}
/* Layout selector */
#speaker-layout {
position: absolute;
top: 10px;
right: 10px;
color: #222;
z-index: 10;
}
#speaker-layout select {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
border: 0;
box-shadow: 0;
cursor: pointer;
opacity: 0;
font-size: 1em;
background-color: transparent;
-moz-appearance: none;
-webkit-appearance: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
#speaker-layout select:focus {
outline: none;
box-shadow: none;
}
.clear {
clear: both;
}
@media screen and (max-width: 1080px) {
#speaker-controls {
font-size: 16px;
}
/* Speaker layout: Wide */
body[data-speaker-layout="wide"] #current-slide,
body[data-speaker-layout="wide"] #upcoming-slide {
width: 50%;
height: 45%;
padding: 6px;
}
@media screen and (max-width: 900px) {
#speaker-controls {
font-size: 14px;
}
body[data-speaker-layout="wide"] #current-slide {
top: 0;
left: 0;
}
@media screen and (max-width: 800px) {
#speaker-controls {
font-size: 12px;
}
body[data-speaker-layout="wide"] #upcoming-slide {
top: 0;
left: 50%;
}
body[data-speaker-layout="wide"] #speaker-controls {
top: 45%;
left: 0;
width: 100%;
height: 50%;
font-size: 1.25em;
}
/* Speaker layout: Tall */
body[data-speaker-layout="tall"] #current-slide,
body[data-speaker-layout="tall"] #upcoming-slide {
width: 45%;
height: 50%;
padding: 6px;
}
body[data-speaker-layout="tall"] #current-slide {
top: 0;
left: 0;
}
body[data-speaker-layout="tall"] #upcoming-slide {
top: 50%;
left: 0;
}
body[data-speaker-layout="tall"] #speaker-controls {
padding-top: 40px;
top: 0;
left: 45%;
width: 55%;
height: 100%;
font-size: 1.25em;
}
/* Speaker layout: Notes only */
body[data-speaker-layout="notes-only"] #current-slide,
body[data-speaker-layout="notes-only"] #upcoming-slide {
display: none;
}
body[data-speaker-layout="notes-only"] #speaker-controls {
padding-top: 40px;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 1.25em;
}
</style>
@@ -152,7 +247,7 @@
<body>
<div id="current-slide"></div>
<div id="upcoming-slide"><span class="label">UPCOMING:</span></div>
<div id="upcoming-slide"><span class="overlay-element label">Upcoming</span></div>
<div id="speaker-controls">
<div class="speaker-controls-time">
<h4 class="label">Time <span class="reset-button">Click to Reset</span></h4>
@@ -170,6 +265,10 @@
<div class="value"></div>
</div>
</div>
<div id="speaker-layout" class="overlay-element interactive">
<span class="speaker-layout-label"></span>
<select class="speaker-layout-dropdown"></select>
</div>
<script src="/socket.io/socket.io.js"></script>
<script src="/plugin/markdown/marked.js"></script>
@@ -182,11 +281,20 @@
currentState,
currentSlide,
upcomingSlide,
layoutLabel,
layoutDropdown,
connected = false;
var socket = io.connect( window.location.origin ),
socketId = '{{socketId}}';
var SPEAKER_LAYOUTS = {
'default': 'Default',
'wide': 'Wide',
'tall': 'Tall',
'notes-only': 'Notes only'
};
socket.on( 'statechanged', function( data ) {
// ignore data from sockets that aren't ours
@@ -195,7 +303,6 @@
if( connected === false ) {
connected = true;
setupIframes( data );
setupKeyboard();
setupNotes();
setupTimer();
@@ -206,13 +313,28 @@
} );
setupLayout();
// Load our presentation iframes
setupIframes();
// Once the iframes have loaded, emit a signal saying there's
// a new subscriber which will trigger a 'statechanged'
// message to be sent back
window.addEventListener( 'message', function( event ) {
var data = JSON.parse( event.data );
if( data && data.namespace === 'reveal' ) {
if( /ready/.test( data.eventName ) ) {
socket.emit( 'connect', { socketId: socketId } );
socket.emit( 'new-subscriber', { socketId: socketId } );
}
}
// Messages sent by reveal.js inside of the current slide preview
if( data && data.namespace === 'reveal' ) {
if( /slidechanged|fragmentshown|fragmenthidden|overviewshown|overviewhidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
socket.emit( 'statechanged-speaker', { state: data.state } );
}
}
@@ -267,7 +389,7 @@
/**
* Creates the preview iframes.
*/
function setupIframes( data ) {
function setupIframes() {
var params = [
'receiver',
@@ -277,9 +399,8 @@
'backgroundTransition=none'
].join( '&' );
var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
var currentURL = '/?' + params + '&postMessageEvents=true' + hash;
var upcomingURL = '/?' + params + '&controls=false' + hash;
var currentURL = '/?' + params + '&postMessageEvents=true';
var upcomingURL = '/?' + params + '&controls=false';
currentSlide = document.createElement( 'iframe' );
currentSlide.setAttribute( 'width', 1280 );
@@ -351,6 +472,74 @@
}
/**
* Sets up the speaker view layout and layout selector.
*/
function setupLayout() {
layoutDropdown = document.querySelector( '.speaker-layout-dropdown' );
layoutLabel = document.querySelector( '.speaker-layout-label' );
// Render the list of available layouts
for( var id in SPEAKER_LAYOUTS ) {
var option = document.createElement( 'option' );
option.setAttribute( 'value', id );
option.textContent = SPEAKER_LAYOUTS[ id ];
layoutDropdown.appendChild( option );
}
// Monitor the dropdown for changes
layoutDropdown.addEventListener( 'change', function( event ) {
setLayout( layoutDropdown.value );
}, false );
// Restore any currently persisted layout
setLayout( getLayout() );
}
/**
* Sets a new speaker view layout. The layout is persisted
* in local storage.
*/
function setLayout( value ) {
var title = SPEAKER_LAYOUTS[ value ];
layoutLabel.innerHTML = 'Layout' + ( title ? ( ': ' + title ) : '' );
layoutDropdown.value = value;
document.body.setAttribute( 'data-speaker-layout', value );
// Persist locally
if( window.localStorage ) {
window.localStorage.setItem( 'reveal-speaker-layout', value );
}
}
/**
* Returns the ID of the most recently set speaker layout
* or our default layout if none has been set.
*/
function getLayout() {
if( window.localStorage ) {
var layout = window.localStorage.getItem( 'reveal-speaker-layout' );
if( layout ) {
return layout;
}
}
// Default to the first record in the layouts hash
for( var id in SPEAKER_LAYOUTS ) {
return id;
}
}
function zeroPadInteger( num ) {
var str = '00' + parseInt( num );
@@ -8,6 +8,7 @@
<style>
body {
font-family: Helvetica;
font-size: 18px;
}
#current-slide,
@@ -30,15 +31,26 @@
position: absolute;
top: 10px;
left: 10px;
font-weight: bold;
font-size: 14px;
z-index: 2;
color: rgba( 255, 255, 255, 0.9 );
}
.overlay-element {
height: 34px;
line-height: 34px;
padding: 0 10px;
text-shadow: none;
background: rgba( 220, 220, 220, 0.8 );
color: #222;
font-size: 14px;
}
.overlay-element.interactive:hover {
background: rgba( 220, 220, 220, 1 );
}
#current-slide {
position: absolute;
width: 65%;
width: 60%;
height: 100%;
top: 0;
left: 0;
@@ -47,20 +59,20 @@
#upcoming-slide {
position: absolute;
width: 35%;
width: 40%;
height: 40%;
right: 0;
top: 0;
}
/* Speaker controls */
#speaker-controls {
position: absolute;
top: 40%;
right: 0;
width: 35%;
width: 40%;
height: 60%;
overflow: auto;
font-size: 18px;
}
@@ -70,6 +82,7 @@
}
.speaker-controls-time .label,
.speaker-controls-pace .label,
.speaker-controls-notes .label {
text-transform: uppercase;
font-weight: normal;
@@ -78,7 +91,7 @@
margin: 0;
}
.speaker-controls-time {
.speaker-controls-time, .speaker-controls-pace {
border-bottom: 1px solid rgba( 200, 200, 200, 0.5 );
margin-bottom: 10px;
padding: 10px 16px;
@@ -99,6 +112,13 @@
.speaker-controls-time .timer,
.speaker-controls-time .clock {
width: 50%;
}
.speaker-controls-time .timer,
.speaker-controls-time .clock,
.speaker-controls-time .pacing .hours-value,
.speaker-controls-time .pacing .minutes-value,
.speaker-controls-time .pacing .seconds-value {
font-size: 1.9em;
}
@@ -112,7 +132,23 @@
}
.speaker-controls-time span.mute {
color: #bbb;
opacity: 0.3;
}
.speaker-controls-time .pacing-title {
margin-top: 5px;
}
.speaker-controls-time .pacing.ahead {
color: blue;
}
.speaker-controls-time .pacing.on-track {
color: green;
}
.speaker-controls-time .pacing.behind {
color: red;
}
.speaker-controls-notes {
@@ -125,24 +161,124 @@
font-size: 1.2em;
}
/* Layout selector */
#speaker-layout {
position: absolute;
top: 10px;
right: 10px;
color: #222;
z-index: 10;
}
#speaker-layout select {
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
border: 0;
box-shadow: 0;
cursor: pointer;
opacity: 0;
font-size: 1em;
background-color: transparent;
-moz-appearance: none;
-webkit-appearance: none;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
#speaker-layout select:focus {
outline: none;
box-shadow: none;
}
.clear {
clear: both;
}
/* Speaker layout: Wide */
body[data-speaker-layout="wide"] #current-slide,
body[data-speaker-layout="wide"] #upcoming-slide {
width: 50%;
height: 45%;
padding: 6px;
}
body[data-speaker-layout="wide"] #current-slide {
top: 0;
left: 0;
}
body[data-speaker-layout="wide"] #upcoming-slide {
top: 0;
left: 50%;
}
body[data-speaker-layout="wide"] #speaker-controls {
top: 45%;
left: 0;
width: 100%;
height: 50%;
font-size: 1.25em;
}
/* Speaker layout: Tall */
body[data-speaker-layout="tall"] #current-slide,
body[data-speaker-layout="tall"] #upcoming-slide {
width: 45%;
height: 50%;
padding: 6px;
}
body[data-speaker-layout="tall"] #current-slide {
top: 0;
left: 0;
}
body[data-speaker-layout="tall"] #upcoming-slide {
top: 50%;
left: 0;
}
body[data-speaker-layout="tall"] #speaker-controls {
padding-top: 40px;
top: 0;
left: 45%;
width: 55%;
height: 100%;
font-size: 1.25em;
}
/* Speaker layout: Notes only */
body[data-speaker-layout="notes-only"] #current-slide,
body[data-speaker-layout="notes-only"] #upcoming-slide {
display: none;
}
body[data-speaker-layout="notes-only"] #speaker-controls {
padding-top: 40px;
top: 0;
left: 0;
width: 100%;
height: 100%;
font-size: 1.25em;
}
@media screen and (max-width: 1080px) {
#speaker-controls {
body[data-speaker-layout="default"] #speaker-controls {
font-size: 16px;
}
}
@media screen and (max-width: 900px) {
#speaker-controls {
body[data-speaker-layout="default"] #speaker-controls {
font-size: 14px;
}
}
@media screen and (max-width: 800px) {
#speaker-controls {
body[data-speaker-layout="default"] #speaker-controls {
font-size: 12px;
}
}
@@ -153,7 +289,7 @@
<body>
<div id="current-slide"></div>
<div id="upcoming-slide"><span class="label">UPCOMING:</span></div>
<div id="upcoming-slide"><span class="overlay-element label">Upcoming</span></div>
<div id="speaker-controls">
<div class="speaker-controls-time">
<h4 class="label">Time <span class="reset-button">Click to Reset</span></h4>
@@ -164,6 +300,11 @@
<span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
</div>
<div class="clear"></div>
<h4 class="label pacing-title" style="display: none">Pacing Time to finish current slide</h4>
<div class="pacing" style="display: none">
<span class="hours-value">00</span><span class="minutes-value">:00</span><span class="seconds-value">:00</span>
</div>
</div>
<div class="speaker-controls-notes hidden">
@@ -171,6 +312,10 @@
<div class="value"></div>
</div>
</div>
<div id="speaker-layout" class="overlay-element interactive">
<span class="speaker-layout-label"></span>
<select class="speaker-layout-dropdown"></select>
</div>
<script src="../../plugin/markdown/marked.js"></script>
<script>
@@ -182,12 +327,27 @@
currentState,
currentSlide,
upcomingSlide,
layoutLabel,
layoutDropdown,
connected = false;
var SPEAKER_LAYOUTS = {
'default': 'Default',
'wide': 'Wide',
'tall': 'Tall',
'notes-only': 'Notes only'
};
setupLayout();
window.addEventListener( 'message', function( event ) {
var data = JSON.parse( event.data );
// The overview mode is only useful to the reveal.js instance
// where navigation occurs so we don't sync it
if( data.state ) delete data.state.overview;
// Messages sent by the notes plugin inside of the main window
if( data && data.namespace === 'reveal-notes' ) {
if( data.type === 'connect' ) {
@@ -203,8 +363,10 @@
// Send a message back to notify that the handshake is complete
window.opener.postMessage( JSON.stringify({ namespace: 'reveal-notes', type: 'connected'} ), '*' );
}
else if( /slidechanged|fragmentshown|fragmenthidden|overviewshown|overviewhidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
else if( /slidechanged|fragmentshown|fragmenthidden|paused|resumed/.test( data.eventName ) && currentState !== JSON.stringify( data.state ) ) {
window.opener.postMessage( JSON.stringify({ method: 'setState', args: [ data.state ]} ), '*' );
}
}
@@ -239,6 +401,7 @@
// No need for updating the notes in case of fragment changes
if ( data.notes ) {
notes.classList.remove( 'hidden' );
notesValue.style.whiteSpace = data.whitespace;
if( data.markdown ) {
notesValue.innerHTML = marked( data.notes );
}
@@ -287,9 +450,10 @@
'backgroundTransition=none'
].join( '&' );
var urlSeparator = /\?/.test(data.url) ? '&' : '?';
var hash = '#/' + data.state.indexh + '/' + data.state.indexv;
var currentURL = data.url + '?' + params + '&postMessageEvents=true' + hash;
var upcomingURL = data.url + '?' + params + '&controls=false' + hash;
var currentURL = data.url + urlSeparator + params + '&postMessageEvents=true' + hash;
var upcomingURL = data.url + urlSeparator + params + '&controls=false' + hash;
currentSlide = document.createElement( 'iframe' );
currentSlide.setAttribute( 'width', 1280 );
@@ -315,6 +479,47 @@
}
function getTimings() {
var slides = Reveal.getSlides();
var defaultTiming = Reveal.getConfig().defaultTiming;
if (defaultTiming == null) {
return null;
}
var timings = [];
for ( var i in slides ) {
var slide = slides[i];
var timing = defaultTiming;
if( slide.hasAttribute( 'data-timing' )) {
var t = slide.getAttribute( 'data-timing' );
timing = parseInt(t);
if( isNaN(timing) ) {
console.warn("Could not parse timing '" + t + "' of slide " + i + "; using default of " + defaultTiming);
timing = defaultTiming;
}
}
timings.push(timing);
}
return timings;
}
/**
* Return the number of seconds allocated for presenting
* all slides up to and including this one.
*/
function getTimeAllocated(timings) {
var slides = Reveal.getSlides();
var allocated = 0;
var currentSlide = Reveal.getSlidePastCount();
for (var i in slides.slice(0, currentSlide + 1)) {
allocated += timings[i];
}
return allocated;
}
/**
* Create the timer and clock and start updating them
* at an interval.
@@ -322,28 +527,78 @@
function setupTimer() {
var start = new Date(),
timeEl = document.querySelector( '.speaker-controls-time' ),
clockEl = timeEl.querySelector( '.clock-value' ),
hoursEl = timeEl.querySelector( '.hours-value' ),
minutesEl = timeEl.querySelector( '.minutes-value' ),
secondsEl = timeEl.querySelector( '.seconds-value' );
timeEl = document.querySelector( '.speaker-controls-time' ),
clockEl = timeEl.querySelector( '.clock-value' ),
hoursEl = timeEl.querySelector( '.hours-value' ),
minutesEl = timeEl.querySelector( '.minutes-value' ),
secondsEl = timeEl.querySelector( '.seconds-value' ),
pacingTitleEl = timeEl.querySelector( '.pacing-title' ),
pacingEl = timeEl.querySelector( '.pacing' ),
pacingHoursEl = pacingEl.querySelector( '.hours-value' ),
pacingMinutesEl = pacingEl.querySelector( '.minutes-value' ),
pacingSecondsEl = pacingEl.querySelector( '.seconds-value' );
var timings = getTimings();
if (timings !== null) {
pacingTitleEl.style.removeProperty('display');
pacingEl.style.removeProperty('display');
}
function _displayTime( hrEl, minEl, secEl, time) {
var sign = Math.sign(time) == -1 ? "-" : "";
time = Math.abs(Math.round(time / 1000));
var seconds = time % 60;
var minutes = Math.floor( time / 60 ) % 60 ;
var hours = Math.floor( time / ( 60 * 60 )) ;
hrEl.innerHTML = sign + zeroPadInteger( hours );
if (hours == 0) {
hrEl.classList.add( 'mute' );
}
else {
hrEl.classList.remove( 'mute' );
}
minEl.innerHTML = ':' + zeroPadInteger( minutes );
if (hours == 0 && minutes == 0) {
minEl.classList.add( 'mute' );
}
else {
minEl.classList.remove( 'mute' );
}
secEl.innerHTML = ':' + zeroPadInteger( seconds );
}
function _updateTimer() {
var diff, hours, minutes, seconds,
now = new Date();
now = new Date();
diff = now.getTime() - start.getTime();
hours = Math.floor( diff / ( 1000 * 60 * 60 ) );
minutes = Math.floor( ( diff / ( 1000 * 60 ) ) % 60 );
seconds = Math.floor( ( diff / 1000 ) % 60 );
clockEl.innerHTML = now.toLocaleTimeString( 'en-US', { hour12: true, hour: '2-digit', minute:'2-digit' } );
hoursEl.innerHTML = zeroPadInteger( hours );
hoursEl.className = hours > 0 ? '' : 'mute';
minutesEl.innerHTML = ':' + zeroPadInteger( minutes );
minutesEl.className = minutes > 0 ? '' : 'mute';
secondsEl.innerHTML = ':' + zeroPadInteger( seconds );
_displayTime( hoursEl, minutesEl, secondsEl, diff );
if (timings !== null) {
_updatePacing(diff);
}
}
function _updatePacing(diff) {
var slideEndTiming = getTimeAllocated(timings) * 1000;
var currentSlide = Reveal.getSlidePastCount();
var currentSlideTiming = timings[currentSlide] * 1000;
var timeLeftCurrentSlide = slideEndTiming - diff;
if (timeLeftCurrentSlide < 0) {
pacingEl.className = 'pacing behind';
}
else if (timeLeftCurrentSlide < currentSlideTiming) {
pacingEl.className = 'pacing on-track';
}
else {
pacingEl.className = 'pacing ahead';
}
_displayTime( pacingHoursEl, pacingMinutesEl, pacingSecondsEl, timeLeftCurrentSlide );
}
@@ -353,14 +608,112 @@
// Then update every second
setInterval( _updateTimer, 1000 );
timeEl.addEventListener( 'click', function() {
start = new Date();
function _resetTimer() {
if (timings == null) {
start = new Date();
}
else {
// Reset timer to beginning of current slide
var slideEndTiming = getTimeAllocated(timings) * 1000;
var currentSlide = Reveal.getSlidePastCount();
var currentSlideTiming = timings[currentSlide] * 1000;
var previousSlidesTiming = slideEndTiming - currentSlideTiming;
var now = new Date();
start = new Date(now.getTime() - previousSlidesTiming);
}
_updateTimer();
}
timeEl.addEventListener( 'click', function() {
_resetTimer();
return false;
} );
}
/**
* Sets up the speaker view layout and layout selector.
*/
function setupLayout() {
layoutDropdown = document.querySelector( '.speaker-layout-dropdown' );
layoutLabel = document.querySelector( '.speaker-layout-label' );
// Render the list of available layouts
for( var id in SPEAKER_LAYOUTS ) {
var option = document.createElement( 'option' );
option.setAttribute( 'value', id );
option.textContent = SPEAKER_LAYOUTS[ id ];
layoutDropdown.appendChild( option );
}
// Monitor the dropdown for changes
layoutDropdown.addEventListener( 'change', function( event ) {
setLayout( layoutDropdown.value );
}, false );
// Restore any currently persisted layout
setLayout( getLayout() );
}
/**
* Sets a new speaker view layout. The layout is persisted
* in local storage.
*/
function setLayout( value ) {
var title = SPEAKER_LAYOUTS[ value ];
layoutLabel.innerHTML = 'Layout' + ( title ? ( ': ' + title ) : '' );
layoutDropdown.value = value;
document.body.setAttribute( 'data-speaker-layout', value );
// Persist locally
if( supportsLocalStorage() ) {
window.localStorage.setItem( 'reveal-speaker-layout', value );
}
}
/**
* Returns the ID of the most recently set speaker layout
* or our default layout if none has been set.
*/
function getLayout() {
if( supportsLocalStorage() ) {
var layout = window.localStorage.getItem( 'reveal-speaker-layout' );
if( layout ) {
return layout;
}
}
// Default to the first record in the layouts hash
for( var id in SPEAKER_LAYOUTS ) {
return id;
}
}
function supportsLocalStorage() {
try {
localStorage.setItem('test', 'test');
localStorage.removeItem('test');
return true;
}
catch( e ) {
return false;
}
}
function zeroPadInteger( num ) {
var str = '00' + parseInt( num );
@@ -11,10 +11,18 @@
*/
var RevealNotes = (function() {
function openNotes() {
var jsFileLocation = document.querySelector('script[src$="notes.js"]').src; // this js file path
jsFileLocation = jsFileLocation.replace(/notes\.js(\?.*)?$/, ''); // the js folder path
var notesPopup = window.open( jsFileLocation + 'notes.html', 'reveal.js - Notes', 'width=1100,height=700' );
function openNotes( notesFilePath ) {
if( !notesFilePath ) {
var jsFileLocation = document.querySelector('script[src$="notes.js"]').src; // this js file path
jsFileLocation = jsFileLocation.replace(/notes\.js(\?.*)?$/, ''); // the js folder path
notesFilePath = jsFileLocation + 'notes.html';
}
var notesPopup = window.open( notesFilePath, 'reveal.js - Notes', 'width=1100,height=700' );
// Allow popup window access to Reveal API
notesPopup.Reveal = this.Reveal;
/**
* Connect to the notes window through a postmessage handshake.
@@ -45,22 +53,40 @@ var RevealNotes = (function() {
/**
* Posts the current slide data to the notes window
*/
function post() {
function post( event ) {
var slideElement = Reveal.getCurrentSlide(),
notesElement = slideElement.querySelector( 'aside.notes' );
notesElement = slideElement.querySelector( 'aside.notes' ),
fragmentElement = slideElement.querySelector( '.current-fragment' );
var messageData = {
namespace: 'reveal-notes',
type: 'state',
notes: '',
markdown: false,
whitespace: 'normal',
state: Reveal.getState()
};
// Look for notes defined in a slide attribute
if( slideElement.hasAttribute( 'data-notes' ) ) {
messageData.notes = slideElement.getAttribute( 'data-notes' );
messageData.whitespace = 'pre-wrap';
}
// Look for notes defined in a fragment
if( fragmentElement ) {
var fragmentNotes = fragmentElement.querySelector( 'aside.notes' );
if( fragmentNotes ) {
notesElement = fragmentNotes;
}
else if( fragmentElement.hasAttribute( 'data-notes' ) ) {
messageData.notes = fragmentElement.getAttribute( 'data-notes' );
messageData.whitespace = 'pre-wrap';
// In case there are slide notes
notesElement = null;
}
}
// Look for notes defined in an aside element
@@ -94,6 +120,7 @@ var RevealNotes = (function() {
}
connect();
}
if( !/receiver/i.test( window.location.search ) ) {
@@ -109,12 +136,18 @@ var RevealNotes = (function() {
// modifier is present
if ( document.querySelector( ':focus' ) !== null || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;
// Disregard the event if keyboard is disabled
if ( Reveal.getConfig().keyboard === false ) return;
if( event.keyCode === 83 ) {
event.preventDefault();
openNotes();
}
}, false );
// Show our keyboard shortcut in the reveal.js help overlay
if( window.Reveal ) Reveal.registerKeyboardShortcut( 'S', 'Speaker notes view' );
}
return { open: openNotes };
@@ -2,32 +2,18 @@
* phantomjs script for printing presentations to PDF.
*
* Example:
* phantomjs print-pdf.js "http://lab.hakim.se/reveal-js?print-pdf" reveal-demo.pdf
* phantomjs print-pdf.js "http://revealjs.com?print-pdf" reveal-demo.pdf
*
* By Manuel Bieh (https://github.com/manuelbieh)
* @author Manuel Bieh (https://github.com/manuelbieh)
* @author Hakim El Hattab (https://github.com/hakimel)
* @author Manuel Riezebosch (https://github.com/riezebosch)
*/
// html2pdf.js
var page = new WebPage();
var system = require( 'system' );
var slideWidth = system.args[3] ? system.args[3].split( 'x' )[0] : 960;
var slideHeight = system.args[3] ? system.args[3].split( 'x' )[1] : 700;
page.viewportSize = {
width: slideWidth,
height: slideHeight
};
// TODO
// Something is wrong with these config values. An input
// paper width of 1920px actually results in a 756px wide
// PDF.
page.paperSize = {
width: Math.round( slideWidth * 2 ),
height: Math.round( slideHeight * 2 ),
border: 0
};
var probePage = new WebPage();
var printPage = new WebPage();
var inputFile = system.args[1] || 'index.html?print-pdf';
var outputFile = system.args[2] || 'slides.pdf';
@@ -36,13 +22,48 @@ if( outputFile.match( /\.pdf$/gi ) === null ) {
outputFile += '.pdf';
}
console.log( 'Printing PDF (Paper size: '+ page.paperSize.width + 'x' + page.paperSize.height +')' );
console.log( 'Export PDF: Reading reveal.js config [1/4]' );
page.open( inputFile, function( status ) {
window.setTimeout( function() {
console.log( 'Printed succesfully' );
page.render( outputFile );
phantom.exit();
}, 1000 );
probePage.open( inputFile, function( status ) {
console.log( 'Export PDF: Preparing print layout [2/4]' );
var config = probePage.evaluate( function() {
return Reveal.getConfig();
} );
if( config ) {
printPage.paperSize = {
width: Math.floor( config.width * ( 1 + config.margin ) ),
height: Math.floor( config.height * ( 1 + config.margin ) ),
border: 0
};
printPage.open( inputFile, function( status ) {
console.log( 'Export PDF: Preparing pdf [3/4]')
printPage.evaluate(function() {
Reveal.isReady() ? window.callPhantom() : Reveal.addEventListener( 'pdf-ready', window.callPhantom );
});
} );
printPage.onCallback = function(data) {
// For some reason we need to "jump the queue" for syntax highlighting to work.
// See: http://stackoverflow.com/a/3580132/129269
setTimeout(function() {
console.log( 'Export PDF: Writing file [4/4]' );
printPage.render( outputFile );
console.log( 'Export PDF: Finished successfully!' );
phantom.exit();
}, 0);
};
}
else {
console.log( 'Export PDF: Unable to read reveal.js config. Make sure the input address points to a reveal.js page.' );
phantom.exit(1);
}
} );
@@ -21,7 +21,7 @@ function Hilitor(id, tag)
var targetNode = document.getElementById(id) || document.body;
var hiliteTag = tag || "EM";
var skipTags = new RegExp("^(?:" + hiliteTag + "|SCRIPT|FORM|SPAN)$");
var skipTags = new RegExp("^(?:" + hiliteTag + "|SCRIPT|FORM)$");
var colors = ["#ff6", "#a0ffff", "#9f9", "#f99", "#f6f"];
var wordColor = [];
var colorIdx = 0;
@@ -53,11 +53,11 @@ function Hilitor(id, tag)
if(node.nodeType == 3) { // NODE_TEXT
if((nv = node.nodeValue) && (regs = matchRegex.exec(nv))) {
//find the slide's section element and save it in our list of matching slides
var secnode = node.parentNode;
while (secnode.nodeName != 'SECTION') {
var secnode = node;
while (secnode != null && secnode.nodeName != 'SECTION') {
secnode = secnode.parentNode;
}
var slideIndex = Reveal.getIndices(secnode);
var slidelen = matchingSlides.length;
var alreadyAdded = false;
@@ -69,7 +69,7 @@ function Hilitor(id, tag)
if (! alreadyAdded) {
matchingSlides.push(slideIndex);
}
if(!wordColor[regs[0].toLowerCase()]) {
wordColor[regs[0].toLowerCase()] = colors[colorIdx++ % colors.length];
}
@@ -110,20 +110,26 @@ function Hilitor(id, tag)
function openSearch() {
//ensure the search term input dialog is visible and has focus:
var inputboxdiv = document.getElementById("searchinputdiv");
var inputbox = document.getElementById("searchinput");
inputbox.style.display = "inline";
inputboxdiv.style.display = "inline";
inputbox.focus();
inputbox.select();
}
function closeSearch() {
var inputboxdiv = document.getElementById("searchinputdiv");
inputboxdiv.style.display = "none";
if(myHilitor) myHilitor.remove();
}
function toggleSearch() {
var inputbox = document.getElementById("searchinput");
if (inputbox.style.display !== "inline") {
var inputboxdiv = document.getElementById("searchinputdiv");
if (inputboxdiv.style.display !== "inline") {
openSearch();
}
else {
inputbox.style.display = "none";
myHilitor.remove();
closeSearch();
}
}
@@ -132,19 +138,27 @@ function Hilitor(id, tag)
if (searchboxDirty) {
var searchstring = document.getElementById("searchinput").value;
//find the keyword amongst the slides
myHilitor = new Hilitor("slidecontent");
matchedSlides = myHilitor.apply(searchstring);
currentMatchedIndex = 0;
if (searchstring === '') {
if(myHilitor) myHilitor.remove();
matchedSlides = null;
}
else {
//find the keyword amongst the slides
myHilitor = new Hilitor("slidecontent");
matchedSlides = myHilitor.apply(searchstring);
currentMatchedIndex = 0;
}
}
//navigate to the next slide that has the keyword, wrapping to the first if necessary
if (matchedSlides.length && (matchedSlides.length <= currentMatchedIndex)) {
currentMatchedIndex = 0;
}
if (matchedSlides.length > currentMatchedIndex) {
Reveal.slide(matchedSlides[currentMatchedIndex].h, matchedSlides[currentMatchedIndex].v);
currentMatchedIndex++;
if (matchedSlides) {
//navigate to the next slide that has the keyword, wrapping to the first if necessary
if (matchedSlides.length && (matchedSlides.length <= currentMatchedIndex)) {
currentMatchedIndex = 0;
}
if (matchedSlides.length > currentMatchedIndex) {
Reveal.slide(matchedSlides[currentMatchedIndex].h, matchedSlides[currentMatchedIndex].v);
currentMatchedIndex++;
}
}
}
@@ -157,7 +171,8 @@ function Hilitor(id, tag)
searchElement.classList.add( 'searchdiv' );
searchElement.style.position = 'absolute';
searchElement.style.top = '10px';
searchElement.style.left = '10px';
searchElement.style.right = '10px';
searchElement.style.zIndex = 10;
//embedded base64 search icon Designed by Sketchdock - http://www.sketchdock.com/:
searchElement.innerHTML = '<span><input type="search" id="searchinput" class="searchinput" style="vertical-align: top;"/><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAJiSURBVHjatFZNaxNBGH5md+Mmu92NVdKDRipSAyqCghgQD4L4cRe86UUtAQ+eFCxoa4/25EXBFi8eBE+eRPoDhB6KgiiixdAPCEkx2pjvTXadd9yNsflwuyUDD/O+u8PzzDPvzOwyx3EwyCZhwG3gAkp7MnpjgbopjsltcD4gjuXZZKeAR348MYLYTm3LzOs/y3j3JTfZxgXWXmTuwPHIc4VmoOmv5IrI53+AO2DdHLjkDWQ3GoEEVFXtXQOvkSnPWcyUceviLhwbDYv8/XIVj97kse7TodLvZXxYxrPUHkQ1ufXs3FEdybEIxucySOesoNvUgWU1cP3MkCBfTFdw9fGaAMVmRELq7LBw2Q3/FaAxxWIRpw+ZIr/7IouPqzUBiqmdHAv7EuhRAwf1er2Vy4x1jW3b2d5Jfvu5IPp7l2LYbcgCFFNb+FoJ7oBqEAqFMPNqFcmEgVMJDfMT+1tvN0pNjERlMS6QA5pFOKxiKVPFhakPeL3It+WGJUDxt2wFR+JhzI7v5ctkd8DXOZAkCYYxhO+lKm4+Xfqz/rIixBuNBl7eOYzkQQNzqX249mRl6zUgEcYkaJrGhUwBinVdh6IouPzwE6/DL5w4oLkH8y981aDf+uq6hlKpJESiUdNfDZi7/ehG9K6KfiA3pml0PLcsq+cSMTj2NL9ukc4UOmz7AZ3+crkC4mHujFvXNaMFB3bEr8xPS6p5O+jXxq4VZtaen7/PwzrntjcLUE0iHPS1Ud1cdiEJl/8WivZk0wXd7zWOMkeF8s0CcAmkNrC2nvXZDbbbN73ccYnZoH9bfgswAFzAe9/h3dbKAAAAAElFTkSuQmCC" id="searchbutton" class="searchicon" style="vertical-align: top; margin-top: -1px;"/></span>';
dom.wrapper.appendChild( searchElement );
@@ -179,18 +194,13 @@ function Hilitor(id, tag)
}
}, false );
// Open the search when the 's' key is hit (yes, this conflicts with the notes plugin, disabling for now)
/*
document.addEventListener( 'keydown', function( event ) {
// Disregard the event if the target is editable or a
// modifier is present
if ( document.querySelector( ':focus' ) !== null || event.shiftKey || event.altKey || event.ctrlKey || event.metaKey ) return;
if( event.keyCode === 83 ) {
if( event.key == "F" && (event.ctrlKey || event.metaKey) ) {//Control+Shift+f
event.preventDefault();
openSearch();
toggleSearch();
}
}, false );
*/
if( window.Reveal ) Reveal.registerKeyboardShortcut( 'Ctrl-Shift-F', 'Search' );
closeSearch();
return { open: openSearch };
})();
@@ -1,30 +1,27 @@
// Custom reveal.js integration
(function(){
var isEnabled = true;
var revealElement = document.querySelector( '.reveal' );
if( revealElement ) {
document.querySelector( '.reveal .slides' ).addEventListener( 'mousedown', function( event ) {
var modifier = ( Reveal.getConfig().zoomKey ? Reveal.getConfig().zoomKey : 'alt' ) + 'Key';
revealElement.addEventListener( 'mousedown', function( event ) {
var defaultModifier = /Linux/.test( window.navigator.platform ) ? 'ctrl' : 'alt';
var zoomPadding = 20;
var revealScale = Reveal.getScale();
var modifier = ( Reveal.getConfig().zoomKey ? Reveal.getConfig().zoomKey : defaultModifier ) + 'Key';
var zoomLevel = ( Reveal.getConfig().zoomLevel ? Reveal.getConfig().zoomLevel : 2 );
if( event[ modifier ] && isEnabled ) {
event.preventDefault();
if( event[ modifier ] && !Reveal.isOverview() ) {
event.preventDefault();
var bounds = event.target.getBoundingClientRect();
zoom.to({
x: event.clientX,
y: event.clientY,
scale: zoomLevel,
pan: false
});
}
} );
zoom.to({
x: ( bounds.left * revealScale ) - zoomPadding,
y: ( bounds.top * revealScale ) - zoomPadding,
width: ( bounds.width * revealScale ) + ( zoomPadding * 2 ),
height: ( bounds.height * revealScale ) + ( zoomPadding * 2 ),
pan: false
});
}
} );
Reveal.addEventListener( 'overviewshown', function() { isEnabled = false; } );
Reveal.addEventListener( 'overviewhidden', function() { isEnabled = true; } );
}
})();
/*!
@@ -273,6 +270,3 @@ var zoom = (function(){
}
})();
@@ -169,7 +169,7 @@
transition: 'linear',
math: {
// mathjax: 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',
// mathjax: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js',
config: 'TeX-AMS_HTML-full'
},
@@ -93,7 +93,7 @@
<h2>Video background</h2>
</section>
<section data-background-iframe="https://slides.com">
<section data-background-iframe="https://slides.com/news/make-better-presentations/embed?style=hidden&autoSlide=4000">
<h2>Iframe background</h2>
</section>
@@ -13,7 +13,7 @@
<body style="overflow: auto;">
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<div id="qunit-fixture"></div>
<div class="reveal" style="display: none;">
@@ -24,10 +24,11 @@
<img data-src="fake-url.png">
<video data-src="fake-url.mp4"></video>
<audio data-src="fake-url.mp3"></audio>
<aside class="notes">speaker notes 1</aside>
</section>
<section>
<section data-background="examples/assets/image2.png">
<section data-background="examples/assets/image2.png" data-notes="speaker notes 2">
<h1>2.1</h1>
</section>
<section>
@@ -89,7 +89,7 @@ Reveal.addEventListener( 'ready', function() {
test( 'Reveal.isLastSlide after vertical slide', function() {
var lastSlideIndex = document.querySelectorAll( '.reveal .slides>section' ).length - 1;
Reveal.slide( 1, 1 );
Reveal.slide( lastSlideIndex );
strictEqual( Reveal.isLastSlide(), true, 'true after Reveal.slide( 1, 1 ) and then Reveal.slide( '+ lastSlideIndex +', 0 )' );
@@ -139,6 +139,14 @@ Reveal.addEventListener( 'ready', function() {
strictEqual( Reveal.getSlideBackground( 1, 100 ), undefined, 'undefined when out of vertical bounds' );
});
test( 'Reveal.getSlideNotes', function() {
Reveal.slide( 0, 0 );
ok( Reveal.getSlideNotes() === 'speaker notes 1', 'works with <aside class="notes">' );
Reveal.slide( 1, 0 );
ok( Reveal.getSlideNotes() === 'speaker notes 2', 'works with <section data-notes="">' );
});
test( 'Reveal.getPreviousSlide/getCurrentSlide', function() {
Reveal.slide( 0, 0 );
Reveal.slide( 1, 0 );
+60 -162
View File
@@ -4,13 +4,13 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"<!-- dom:TITLE: Data Analysis and Machine Learning: Introduction and Representing data -->\n",
"# Data Analysis and Machine Learning: Introduction and Representing data\n",
"<!-- dom:TITLE: Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters -->\n",
"# Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters\n",
"<!-- dom:AUTHOR: Morten Hjorth-Jensen at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University -->\n",
"<!-- Author: --> \n",
"**Morten Hjorth-Jensen**, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University\n",
"\n",
"Date: **May 11, 2018**\n",
"Date: **May 21, 2018**\n",
"\n",
"Copyright 1999-2018, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license\n",
"\n",
@@ -19,164 +19,7 @@
"\n",
"## Introduction\n",
"\n",
"Statistics, data science and machine learning form important fields of\n",
"research in modern science. They describe how to learn and make\n",
"predictions from data, as well allowing us to extract important\n",
"correlations about physical process and the underlying laws of motion\n",
"in large data sets. The latter, big data sets, appear\n",
"frequently in essentially all disciplines, from the traditional Science,\n",
"Technology, Mathematics and Engineering fields to Life Science, Law, education research, \n",
"the Humanities and\n",
"the Social Sciences. It has become more and more common to see\n",
"research projects on big data in for example the Social\n",
"Sciences where extracting patterns from complicated survey data is one of many research directions. \n",
"Having a solid grasp of data analysis and machine learning\n",
"is thus becoming central to scientific computing in many\n",
"fields, and competences and skills within the fields of machine learning\n",
"and scientific computing are nowadays strongly requested by many\n",
"potential employers. The latter cannot be overstated, familiarity with\n",
"machine learning has almost become a prerequisite for many of the most\n",
"exciting employment opportunities, whether they are in bioinformatics,\n",
"life science, physics or finance, in the private or the public\n",
"sector. This author has had several students or met students who have\n",
"been hired recently based on their skills and competences in\n",
"scientific computing and data science, often with marginal knowledge\n",
"of machine learning.\n",
"\n",
"Machine learning is a subfield of computer science, and is closely\n",
"related to computational statistics. It evolved from the study of\n",
"pattern recognition in artificial intelligence (AI) research, and has\n",
"made contributions to AI tasks like computer vision, natural language\n",
"processing and speech recognition. \n",
"Machine learning represents the\n",
"science of giving computers the ability to learn without being\n",
"explicitly programmed. The idea is that there exist generic\n",
"algorithms which can be used to find patterns in a broad class of data\n",
"sets without having to write code specifically for each problem. The\n",
"algorithm will build its own logic based on the data. \n",
"\n",
"Machine learning is an extremely rich field, in spite of its young age. The\n",
"increases we have seen during the last three decades in computational\n",
"capabilities have been followed by developments of methods and\n",
"techniques for analyzing and handling large date sets, relying heavily\n",
"on statistics, computer science and mathematics. The field is rather\n",
"new and developing rapidly. Popular software packages written in\n",
"Python for machine learning like [Scikit-learn](http://scikit-learn.org/stable/), [Tensorflow](https://www.tensorflow.org/),\n",
"[PyTorch](http://pytorch.org/) and [Keras](https://keras.io/), all freely available at their respective GitHub sites,\n",
"encompass communities of developers in the thousands or more. And the number\n",
"of code developers and contributors keeps increasing. Not all the\n",
"algorithms and methods can be given a rigorous mathematical\n",
"justification, opening up thereby large rooms for experimenting\n",
"and trial and error and thereby exciting new developments. \n",
"However, a solid command of linear algebra, multivariate theory, \n",
"probability theory, statistical data analysis,\n",
"understanding errors and Monte Carlo methods are central elements in a proper understanding of many of \n",
"algorithms and methods we will discuss. \n",
"\n",
"<!-- !split -->\n",
"## Learning outcomes\n",
"\n",
"These lectures aim at giving you an overview of central aspects of\n",
"statistical data analysis as well as some of the central algorithms\n",
"used in machine learning. We will introduce a variety of central\n",
"algorithms and methods essential for studies of data analysis and\n",
"machine learning. \n",
"\n",
"Hands-on projects and experimenting with data and algorithms plays a central role in\n",
"these lectures, and our hope is, through the various\n",
"projects and exercies, to expose you to fundamental\n",
"research problems in these fields, with the aim to reproduce state of\n",
"the art scientific results. You will learn to develop and\n",
"structure large codes for studying these systems, get acquainted with\n",
"computing facilities and learn to handle large scientific projects. A\n",
"good scientific and ethical conduct is emphasized throughout the\n",
"course. More specifically, you will\n",
"\n",
"1. learn about basic data analysis, Bayesian statistics, Monte Carlo methods, data optimization and machine learning;\n",
"\n",
"2. be capable of extending the acquired knowledge to other systems and cases;\n",
"\n",
"3. Have an understanding of central algorithms used in data analysis and machine learning;\n",
"\n",
"4. Gain knowledge of central aspects of Monte Carlo methods, Markov chains, Gibbs samplers and their possible applications, from numerical integration to simulation of stock markets;\n",
"\n",
"5. Understand methods for regression and classification;\n",
"\n",
"6. Learn about neural network, genetic algorithms and Boltzmann machines;\n",
"\n",
"7. Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++, in addition to a basic knowledge of linear algebra (typically taught during the first one or two years of undergraduate studies).\n",
"\n",
"There are several topics we will cover here, spanning from a\n",
"statistical data analysis and its basic concepts such expectation\n",
"values, variance, covariance, correlation functions and errors, via\n",
"well-known probability distribution functions like uniform\n",
"distribution, the binomial distribution, the Poisson distribution and\n",
"simple and multivariate normal distributions to central elements of\n",
"Bayesian statistics and modeling. We will also remind the reader about\n",
"central elements from linear algebra and standard methods based on\n",
"linear algebra used to fit functions such Cubic splines and gradient\n",
"methods for data optimization and the Singular-value decomposition and\n",
"least square methods for parameterizing data.\n",
"\n",
"We will also cover Monte Carlo methods, Markov chains, well-known\n",
"algorithms for sampling stochastic events like the Metropolis-Hastings\n",
"and Gibbs sampling methods. An important aspect of all our\n",
"calculations is a proper estimation of errors. Here we will also\n",
"discuss famous resampling techniques like the blocking, bootstrapping\n",
"and jackknife methods.\n",
"\n",
"The second part of the material covers several algorithms used in\n",
"machine learning.\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"## Types of Machine Learning\n",
"\n",
"\n",
"The approaches to machine learning are many, but are often split into two main categories. \n",
"In *supervised learning* we know the answer to a problem,\n",
"and let the computer deduce the logic behind it. On the other hand, *unsupervised learning*\n",
"is a method for finding patterns and relationship in data sets without any prior knowledge of the system.\n",
"Some authours also operate with a third category, namely *reinforcement learning*. This is a paradigm \n",
"of learning inspired by behavioral psychology, where learning is achieved by trial-and-error, \n",
"solely from rewards and punishment.\n",
"\n",
"Another way to categorize machine learning tasks is to consider the desired output of a system.\n",
"Some of the most common tasks are:\n",
"\n",
" * Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.\n",
"\n",
" * Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.\n",
"\n",
" * Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.\n",
"\n",
"The methods we cover have three main topics in common, irrespective of\n",
"whether we deal with supervised or unsupervised learning. The first\n",
"ingredient is normally our data set, the second is a model which is\n",
"normally a function of some parameters. The last ingredient is a\n",
"so-called **cost** function which allows us to present an estimate on\n",
"how good our model is in reproducing the data it is supposed to train.\n",
"\n",
"Here we will build our machine learning approach on elements of the\n",
"statistical foundation discussed above, with elements from data\n",
"analysis, stochastic processes etc. We will discuss the following\n",
"machine learning algorithms\n",
"\n",
"1. Linear regression and its variants, in essence polynomial regression\n",
"\n",
"2. Decision tree algorithms, from simpler to more complex ones\n",
"\n",
"3. Nearest neighbors models\n",
"\n",
"4. Bayesian statistics and regression\n",
"\n",
"5. Support vector machines and finally various variants of\n",
"\n",
"6. Artifical neural networks and deep learning\n",
"\n",
"Before we proceed however, there are several practicalities with data\n",
"Before we proceed there are several practicalities with data\n",
"analysis and software tools we would like to present. These tools will\n",
"help us in our understanding of various machine learning algorithms.\n",
"\n",
@@ -1552,7 +1395,62 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"where $c_{ij}$ represents the number of previous interactions that have taken place between $i$ and $j$. The factor $1$ is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with $N=1000$, $\\alpha=1.0$ and $\\alpha=2.0$ using $\\gamma = 0.0, 1.0, 2.0, 3.0$ and $4.0$. Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving $\\lambda$ in each transaction. Comment your results and compare them with figures 5 and 6 of [Goswami and Sen](http://www.sciencedirect.com/science/article/pii/S0378437114006967)."
"where $c_{ij}$ represents the number of previous interactions that have taken place between $i$ and $j$. The factor $1$ is added in order to ensure that if they have not interacted earlier they can still interact. Perform similar studies as above with $N=1000$, $\\alpha=1.0$ and $\\alpha=2.0$ using $\\gamma = 0.0, 1.0, 2.0, 3.0$ and $4.0$. Plot the wealth distributions for these cases and try to extract eventual power law tails with and without a saving $\\lambda$ in each transaction. Comment your results and compare them with figures 5 and 6 of [Goswami and Sen](http://www.sciencedirect.com/science/article/pii/S0378437114006967). \n",
"\n",
"## Particle in one dimension an velocity distribution"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Program to test the Metropolis algorithm with one particle at given temp in one dimension\n",
"import numpy as np\n",
"import matplotlib.mlab as mlab\n",
"import matplotlib.pyplot as plt\n",
"import random\n",
"from math import sqrt, exp, log\n",
"# initialize the rng with a seed\n",
"random.seed()\n",
"# Hard coding of input parameters\n",
"MCcycles = 100000\n",
"Temperature = 2.0\n",
"beta = 1./Temperature\n",
"InitialVelocity = -2.0\n",
"CurrentVelocity = InitialVelocity\n",
"Energy = 0.5*InitialVelocity*InitialVelocity\n",
"VelocityRange = 10*sqrt(Temperature)\n",
"VelocityStep = 2*VelocityRange/10.\n",
"AverageEnergy = Energy\n",
"AverageEnergy2 = Energy*Energy\n",
"VelocityValues = np.zeros(MCcycles)\n",
"# The Monte Carlo sampling with Metropolis starts here\n",
"for i in range (1, MCcycles, 1):\n",
" TrialVelocity = CurrentVelocity + (2.0*random.random() - 1.0)*VelocityStep\n",
" EnergyChange = 0.5*(TrialVelocity*TrialVelocity -CurrentVelocity*CurrentVelocity);\n",
" if random.random() <= exp(-beta*EnergyChange):\n",
" CurrentVelocity = TrialVelocity\n",
" Energy += EnergyChange\n",
" VelocityValues[i] = CurrentVelocity\n",
" AverageEnergy += Energy\n",
" AverageEnergy2 += Energy*Energy\n",
"#Final averages\n",
"AverageEnergy = AverageEnergy/MCcycles\n",
"AverageEnergy2 = AverageEnergy2/MCcycles\n",
"Variance = AverageEnergy2 - AverageEnergy*AverageEnergy\n",
"print(AverageEnergy, Variance)\n",
"n, bins, patches = plt.hist(VelocityValues, 400, facecolor='green')\n",
"\n",
"plt.xlabel('$v$')\n",
"plt.ylabel('Velocity distribution P(v)')\n",
"plt.title(r'Velocity histogram at $k_BT=2$')\n",
"plt.axis([-5, 5, 0, 600])\n",
"plt.grid(True)\n",
"plt.show()"
]
}
],
Binary file not shown.
Binary file not shown.
+2 -151
View File
@@ -1,4 +1,4 @@
TITLE: Data Analysis and Machine Learning: Introduction and Representing data
TITLE: Data Analysis and Machine Learning: Getting started, our first data and Machine Learning encounters
AUTHOR: Morten Hjorth-Jensen {copyright, 1999-present|CC BY-NC} at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
DATE: today
@@ -6,156 +6,7 @@ DATE: today
!split
===== Introduction =====
Statistics, data science and machine learning form important fields of
research in modern science. They describe how to learn and make
predictions from data, as well allowing us to extract important
correlations about physical process and the underlying laws of motion
in large data sets. The latter, big data sets, appear
frequently in essentially all disciplines, from the traditional Science,
Technology, Mathematics and Engineering fields to Life Science, Law, education research,
the Humanities and
the Social Sciences. It has become more and more common to see
research projects on big data in for example the Social
Sciences where extracting patterns from complicated survey data is one of many research directions.
Having a solid grasp of data analysis and machine learning
is thus becoming central to scientific computing in many
fields, and competences and skills within the fields of machine learning
and scientific computing are nowadays strongly requested by many
potential employers. The latter cannot be overstated, familiarity with
machine learning has almost become a prerequisite for many of the most
exciting employment opportunities, whether they are in bioinformatics,
life science, physics or finance, in the private or the public
sector. This author has had several students or met students who have
been hired recently based on their skills and competences in
scientific computing and data science, often with marginal knowledge
of machine learning.
Machine learning is a subfield of computer science, and is closely
related to computational statistics. It evolved from the study of
pattern recognition in artificial intelligence (AI) research, and has
made contributions to AI tasks like computer vision, natural language
processing and speech recognition.
Machine learning represents the
science of giving computers the ability to learn without being
explicitly programmed. The idea is that there exist generic
algorithms which can be used to find patterns in a broad class of data
sets without having to write code specifically for each problem. The
algorithm will build its own logic based on the data.
Machine learning is an extremely rich field, in spite of its young age. The
increases we have seen during the last three decades in computational
capabilities have been followed by developments of methods and
techniques for analyzing and handling large date sets, relying heavily
on statistics, computer science and mathematics. The field is rather
new and developing rapidly. Popular software packages written in
Python for machine learning like "Scikit-learn":"http://scikit-learn.org/stable/", "Tensorflow":"https://www.tensorflow.org/",
"PyTorch":"http://pytorch.org/" and "Keras":"https://keras.io/", all freely available at their respective GitHub sites,
encompass communities of developers in the thousands or more. And the number
of code developers and contributors keeps increasing. Not all the
algorithms and methods can be given a rigorous mathematical
justification, opening up thereby large rooms for experimenting
and trial and error and thereby exciting new developments.
However, a solid command of linear algebra, multivariate theory,
probability theory, statistical data analysis,
understanding errors and Monte Carlo methods are central elements in a proper understanding of many of
algorithms and methods we will discuss.
!split
===== Learning outcomes =====
These lectures aim at giving you an overview of central aspects of
statistical data analysis as well as some of the central algorithms
used in machine learning. We will introduce a variety of central
algorithms and methods essential for studies of data analysis and
machine learning.
Hands-on projects and experimenting with data and algorithms plays a central role in
these lectures, and our hope is, through the various
projects and exercies, to expose you to fundamental
research problems in these fields, with the aim to reproduce state of
the art scientific results. You will learn to develop and
structure large codes for studying these systems, get acquainted with
computing facilities and learn to handle large scientific projects. A
good scientific and ethical conduct is emphasized throughout the
course. More specifically, you will
o learn about basic data analysis, Bayesian statistics, Monte Carlo methods, data optimization and machine learning;
o be capable of extending the acquired knowledge to other systems and cases;
o Have an understanding of central algorithms used in data analysis and machine learning;
o Gain knowledge of central aspects of Monte Carlo methods, Markov chains, Gibbs samplers and their possible applications, from numerical integration to simulation of stock markets;
o Understand methods for regression and classification;
o Learn about neural network, genetic algorithms and Boltzmann machines;
o Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++, in addition to a basic knowledge of linear algebra (typically taught during the first one or two years of undergraduate studies).
There are several topics we will cover here, spanning from a
statistical data analysis and its basic concepts such expectation
values, variance, covariance, correlation functions and errors, via
well-known probability distribution functions like uniform
distribution, the binomial distribution, the Poisson distribution and
simple and multivariate normal distributions to central elements of
Bayesian statistics and modeling. We will also remind the reader about
central elements from linear algebra and standard methods based on
linear algebra used to fit functions such Cubic splines and gradient
methods for data optimization and the Singular-value decomposition and
least square methods for parameterizing data.
We will also cover Monte Carlo methods, Markov chains, well-known
algorithms for sampling stochastic events like the Metropolis-Hastings
and Gibbs sampling methods. An important aspect of all our
calculations is a proper estimation of errors. Here we will also
discuss famous resampling techniques like the blocking, bootstrapping
and jackknife methods.
The second part of the material covers several algorithms used in
machine learning.
!split
===== Types of Machine Learning =====
The approaches to machine learning are many, but are often split into two main categories.
In *supervised learning* we know the answer to a problem,
and let the computer deduce the logic behind it. On the other hand, *unsupervised learning*
is a method for finding patterns and relationship in data sets without any prior knowledge of the system.
Some authours also operate with a third category, namely *reinforcement learning*. This is a paradigm
of learning inspired by behavioral psychology, where learning is achieved by trial-and-error,
solely from rewards and punishment.
Another way to categorize machine learning tasks is to consider the desired output of a system.
Some of the most common tasks are:
* Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.
* Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.
* Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.
The methods we cover have three main topics in common, irrespective of
whether we deal with supervised or unsupervised learning. The first
ingredient is normally our data set, the second is a model which is
normally a function of some parameters. The last ingredient is a
so-called _cost_ function which allows us to present an estimate on
how good our model is in reproducing the data it is supposed to train.
Here we will build our machine learning approach on elements of the
statistical foundation discussed above, with elements from data
analysis, stochastic processes etc. We will discuss the following
machine learning algorithms
o Linear regression and its variants, in essence polynomial regression
o Decision tree algorithms, from simpler to more complex ones
o Nearest neighbors models
o Bayesian statistics and regression
o Support vector machines and finally various variants of
o Artifical neural networks and deep learning
Before we proceed however, there are several practicalities with data
Before we proceed there are several practicalities with data
analysis and software tools we would like to present. These tools will
help us in our understanding of various machine learning algorithms.
+157
View File
@@ -0,0 +1,157 @@
TITLE: Data Analysis and Machine Learning: Representing data
AUTHOR: Morten Hjorth-Jensen {copyright, 1999-present|CC BY-NC} at Department of Physics, University of Oslo & Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
DATE: today
!split
===== Introduction =====
Statistics, data science and machine learning form important fields of
research in modern science. They describe how to learn and make
predictions from data, as well as allowing us to extract important
correlations about physical process and the underlying laws of motion
in large data sets. The latter, big data sets, appear
frequently in essentially all disciplines, from the traditional Science,
Technology, Mathematics and Engineering fields to Life Science, Law, education research,
the Humanities and
the Social Sciences. It has become more and more common to see
research projects on big data in for example the Social
Sciences where extracting patterns from complicated survey data is one of many research directions.
Having a solid grasp of data analysis and machine learning
is thus becoming central to scientific computing in many
fields, and competences and skills within the fields of machine learning
and scientific computing are nowadays strongly requested by many
potential employers. The latter cannot be overstated, familiarity with
machine learning has almost become a prerequisite for many of the most
exciting employment opportunities, whether they are in bioinformatics,
life science, physics or finance, in the private or the public
sector. This author has had several students or met students who have
been hired recently based on their skills and competences in
scientific computing and data science, often with marginal knowledge
of machine learning.
Machine learning is a subfield of computer science, and is closely
related to computational statistics. It evolved from the study of
pattern recognition in artificial intelligence (AI) research, and has
made contributions to AI tasks like computer vision, natural language
processing and speech recognition.
Machine learning represents the
science of giving computers the ability to learn without being
explicitly programmed. The idea is that there exist generic
algorithms which can be used to find patterns in a broad class of data
sets without having to write code specifically for each problem. The
algorithm will build its own logic based on the data.
Machine learning is an extremely rich field, in spite of its young age. The
increases we have seen during the last three decades in computational
capabilities have been followed by developments of methods and
techniques for analyzing and handling large date sets, relying heavily
on statistics, computer science and mathematics. The field is rather
new and developing rapidly. Popular software packages written in
Python for machine learning like "Scikit-learn":"http://scikit-learn.org/stable/", "Tensorflow":"https://www.tensorflow.org/",
"PyTorch":"http://pytorch.org/" and "Keras":"https://keras.io/", all freely available at their respective GitHub sites,
encompass communities of developers in the thousands or more. And the number
of code developers and contributors keeps increasing. Not all the
algorithms and methods can be given a rigorous mathematical
justification, opening up thereby large rooms for experimenting
and trial and error and thereby exciting new developments.
However, a solid command of linear algebra, multivariate theory,
probability theory, statistical data analysis,
understanding errors and Monte Carlo methods are central elements in a proper understanding of many of
algorithms and methods we will discuss.
!split
===== Learning outcomes =====
These lectures aim at giving you an overview of central aspects of
statistical data analysis as well as some of the central algorithms
used in machine learning. We will introduce a variety of central
algorithms and methods essential for studies of data analysis and
machine learning.
Hands-on projects and experimenting with data and algorithms plays a central role in
these lectures, and our hope is, through the various
projects and exercies, to expose you to fundamental
research problems in these fields, with the aim to reproduce state of
the art scientific results. You will learn to develop and
structure large codes for studying these systems, get acquainted with
computing facilities and learn to handle large scientific projects. A
good scientific and ethical conduct is emphasized throughout the
course. More specifically, you will
o learn about basic data analysis, Bayesian statistics, Monte Carlo methods, data optimization and machine learning;
o be capable of extending the acquired knowledge to other systems and cases;
o Have an understanding of central algorithms used in data analysis and machine learning;
o Gain knowledge of central aspects of Monte Carlo methods, Markov chains, Gibbs samplers and their possible applications, from numerical integration to simulation of stock markets;
o Understand methods for regression and classification;
o Learn about neural network, genetic algorithms and Boltzmann machines;
o Work on numerical projects to illustrate the theory. The projects play a central role and you are expected to know modern programming languages like Python or C++, in addition to a basic knowledge of linear algebra (typically taught during the first one or two years of undergraduate studies).
There are several topics we will cover here, spanning from a
statistical data analysis and its basic concepts such expectation
values, variance, covariance, correlation functions and errors, via
well-known probability distribution functions like uniform
distribution, the binomial distribution, the Poisson distribution and
simple and multivariate normal distributions to central elements of
Bayesian statistics and modeling. We will also remind the reader about
central elements from linear algebra and standard methods based on
linear algebra used to fit functions such Cubic splines and gradient
methods for data optimization and the Singular-value decomposition and
least square methods for parameterizing data.
We will also cover Monte Carlo methods, Markov chains, well-known
algorithms for sampling stochastic events like the Metropolis-Hastings
and Gibbs sampling methods. An important aspect of all our
calculations is a proper estimation of errors. Here we will also
discuss famous resampling techniques like the blocking, bootstrapping
and jackknife methods.
The second part of the material covers several algorithms used in
machine learning.
!split
===== Types of Machine Learning =====
The approaches to machine learning are many, but are often split into two main categories.
In *supervised learning* we know the answer to a problem,
and let the computer deduce the logic behind it. On the other hand, *unsupervised learning*
is a method for finding patterns and relationship in data sets without any prior knowledge of the system.
Some authours also operate with a third category, namely *reinforcement learning*. This is a paradigm
of learning inspired by behavioral psychology, where learning is achieved by trial-and-error,
solely from rewards and punishment.
Another way to categorize machine learning tasks is to consider the desired output of a system.
Some of the most common tasks are:
* Classification: Outputs are divided into two or more classes. The goal is to produce a model that assigns inputs into one of these classes. An example is to identify digits based on pictures of hand-written ones. Classification is typically supervised learning.
* Regression: Finding a functional relationship between an input data set and a reference data set. The goal is to construct a function that maps input data to continuous output values.
* Clustering: Data are divided into groups with certain common traits, without knowing the different groups beforehand. It is thus a form of unsupervised learning.
The methods we cover have three main topics in common, irrespective of
whether we deal with supervised or unsupervised learning. The first
ingredient is normally our data set, the second is a model which is
normally a function of some parameters. The last ingredient is a
so-called _cost_ function which allows us to present an estimate on
how good our model is in reproducing the data it is supposed to train.
Here we will build our machine learning approach on elements of the
statistical foundation discussed above, with elements from data
analysis, stochastic processes etc. We will discuss the following
machine learning algorithms
o Linear regression and its variants, in essence polynomial regression
o Decision tree algorithms, from simpler to more complex ones
o Nearest neighbors models
o Bayesian statistics and regression
o Support vector machines and finally various variants of
o Artifical neural networks and deep learning
@@ -0,0 +1,12 @@
\mode<presentation>
\usecolortheme[rgb={0.8, 0.2, 0}]{structure}
\usefonttheme[onlysmall]{structurebold}
\setbeamertemplate{navigation symbols}{}
%\setbeamertemplate{footline}[frame number]
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,backgrounds,decorations,mindmap}
\mode
<all>
@@ -0,0 +1,15 @@
\mode<presentation>
\useoutertheme{smoothbars}
\useinnertheme[shadow=true]{rounded}
\usecolortheme{orchid}
\usecolortheme{whale}
\usecolortheme[rgb={0.7, 0.2, 0}]{structure} % (darker red)
\useoutertheme{shadow}
\usefonttheme[onlysmall]{structurebold}
\setbeamercolor{title}{use=structure,fg=white,bg=structure.fg}
\setbeamerfont{block title}{size={}}
\mode
<all>
+3
View File
@@ -0,0 +1,3 @@
#!/bin/sh
doconce clean
rm -rf *.pdf *.tex ipynb*.tar.gz *.html ._*.html *~ reveal.js Trash README.txt
+118
View File
@@ -0,0 +1,118 @@
#!/bin/sh
set -x
function system {
"$@"
if [ $? -ne 0 ]; then
echo "make.sh: unsuccessful command $@"
echo "abort!"
exit 1
fi
}
if [ $# -eq 0 ]; then
echo 'bash make.sh slides1|slides2'
exit 1
fi
name=$1
rm -f *.tar.gz
opt="--encoding=utf-8"
# Note: Makefile examples contain constructions like ${PROG} which
# looks like Mako constructions, but they are not. Use --no_mako
# to turn off Mako processing.
opt="--no_mako"
rm -f *.aux
html=${name}-reveal
system doconce format html $name --pygments_html_style=perldoc --keep_pygments_html_bg --html_links_in_new_window --html_output=$html $opt
system doconce slides_html $html reveal --html_slide_theme=beige
# Plain HTML documents
html=${name}-solarized
system doconce format html $name --pygments_html_style=perldoc --html_style=solarized3 --html_links_in_new_window --html_output=$html $opt
system doconce split_html $html.html --method=space10
html=${name}
system doconce format html $name --pygments_html_style=default --html_style=bloodish --html_links_in_new_window --html_output=$html $opt
system doconce split_html $html.html --method=space10
# Bootstrap style
html=${name}-bs
system doconce format html $name --html_style=bootstrap --pygments_html_style=default --html_admon=bootstrap_panel --html_output=$html $opt
#system doconce split_html $html.html --method=split --pagination --nav_button=bottom
# IPython notebook
system doconce format ipynb $name $opt
# LaTeX Beamer slides
beamertheme=red_plain
system doconce format pdflatex $name --latex_title_layout=beamer --latex_table_format=footnotesize $opt
system doconce ptex2tex $name envir=minted
# Add special packages
doconce subst "% Add user's preamble" "\g<1>\n\\usepackage{simplewick}" $name.tex
system doconce slides_beamer $name --beamer_slide_theme=$beamertheme
system pdflatex -shell-escape ${name}
system pdflatex -shell-escape ${name}
cp $name.pdf ${name}-beamer.pdf
cp $name.tex ${name}-beamer.tex
# Handouts
system doconce format pdflatex $name --latex_title_layout=beamer --latex_table_format=footnotesize $opt
system doconce ptex2tex $name envir=minted
# Add special packages
doconce subst "% Add user's preamble" "\g<1>\n\\usepackage{simplewick}" $name.tex
system doconce slides_beamer $name --beamer_slide_theme=red_shadow --handout
system pdflatex -shell-escape $name
pdflatex -shell-escape $name
pdflatex -shell-escape $name
pdfnup --nup 2x3 --frame true --delta "1cm 1cm" --scale 0.9 --outfile ${name}-beamer-handouts2x3.pdf ${name}.pdf
rm -f ${name}.pdf
# Ordinary plain LaTeX document
rm -f *.aux # important after beamer
system doconce format pdflatex $name --minted_latex_style=trac --latex_admon=paragraph $opt
system doconce ptex2tex $name envir=minted
# Add special packages
doconce subst "% Add user's preamble" "\g<1>\n\\usepackage{simplewick}" $name.tex
doconce replace 'section{' 'section*{' $name.tex
pdflatex -shell-escape $name
pdflatex -shell-escape $name
mv -f $name.pdf ${name}-minted.pdf
cp $name.tex ${name}-plain-minted.tex
# Publish
dest=../../pub
if [ ! -d $dest/$name ]; then
mkdir $dest/$name
mkdir $dest/$name/pdf
mkdir $dest/$name/html
mkdir $dest/$name/ipynb
fi
cp ${name}*.pdf $dest/$name/pdf
cp -r ${name}*.html ._${name}*.html reveal.js $dest/$name/html
# Figures: cannot just copy link, need to physically copy the files
if [ -d fig-${name} ]; then
if [ ! -d $dest/$name/html/fig-$name ]; then
mkdir $dest/$name/html/fig-$name
fi
cp -r fig-${name}/* $dest/$name/html/fig-$name
fi
cp ${name}.ipynb $dest/$name/ipynb
ipynb_tarfile=ipynb-${name}-src.tar.gz
if [ ! -f ${ipynb_tarfile} ]; then
cat > README.txt <<EOF
This IPython notebook ${name}.ipynb does not require any additional
programs.
EOF
tar czf ${ipynb_tarfile} README.txt
fi
cp ${ipynb_tarfile} $dest/$name/ipynb
+4 -3
View File
@@ -10,13 +10,14 @@ AUTHOR: "Morten Hjorth-Jensen":"http://mhjgit.github.io/info/doc/web/" at Depart
<%
pub_url = 'https://compphysics.github.io/MachineLearning/doc/pub'
published = ['How2ReadData', 'Linalg', 'Statistics', 'Regression', 'Splines', 'NeuralNet', 'Bayesian', 'DecisionTrees', 'svm', 'BM',]
published = ['Introduction', 'How2ReadData', 'Linalg', 'Statistics', 'Splines', 'Regression', 'NeuralNet', 'Bayesian', 'DecisionTrees', 'svm', 'BM',]
chapters = {
'How2ReadData': 'Introduction and handling of data',
'Introduction': 'Introduction to Data Analysis and Machine Learning',
'How2ReadData': 'Getting started with Machine Learning',
'Linalg': 'Review of central linear algebra elements',
'Statistics': 'Monte Carlo methods and elements of probability theory',
'Regression': 'Linear regression and beyond',
'Splines': 'Splines and Gradient methods',
'Regression': 'Regression Methods',
'NeuralNet': 'Neural Networks',
'Bayesian': 'Elements of Bayesian theory',
'DecisionTrees': 'Decision trees, from simple to random ones',
+118 -75
View File
@@ -68,40 +68,47 @@ div { text-align: justify; text-justify: inter-word; }
<!-- tocinfo
{'highest level': 2,
'sections': [('Introduction and handling of data', 2, None, '___sec0'),
('Review of central linear algebra elements', 2, None, '___sec1'),
'sections': [('Introduction to Data Analysis and Machine Learning',
2,
None,
'___sec0'),
('Getting started with Machine Learning', 2, None, '___sec1'),
('Review of central linear algebra elements', 2, None, '___sec2'),
('Monte Carlo methods and elements of probability theory',
2,
None,
'___sec2'),
('Linear regression and beyond', 2, None, '___sec3'),
'___sec3'),
('Splines and Gradient methods', 2, None, '___sec4'),
('Neural Networks', 2, None, '___sec5'),
('Elements of Bayesian theory', 2, None, '___sec6'),
('Regression Methods', 2, None, '___sec5'),
('Neural Networks', 2, None, '___sec6'),
('Elements of Bayesian theory', 2, None, '___sec7'),
('Decision trees, from simple to random ones',
2,
None,
'___sec7'),
('Support Vector Machines', 2, None, '___sec8'),
('Unsupervised Learning, Boltzmann Machines', 2, None, '___sec9'),
('Python and Scikit Learn, a short guide', 2, None, '___sec10'),
('Teach yourself C++', 2, None, '___sec11'),
('Projects Fall 2017', 2, None, '___sec12'),
('Project', 3, None, '___sec13'),
('Course content', 3, None, '___sec14'),
('Learning outcomes', 2, None, '___sec15'),
('Prerequisites', 2, None, '___sec16'),
('The course has two central parts', 2, None, '___sec17'),
'___sec8'),
('Support Vector Machines', 2, None, '___sec9'),
('Unsupervised Learning, Boltzmann Machines',
2,
None,
'___sec10'),
('Python and Scikit Learn, a short guide', 2, None, '___sec11'),
('Teach yourself C++', 2, None, '___sec12'),
('Projects Fall 2017', 2, None, '___sec13'),
('Project', 3, None, '___sec14'),
('Course content', 3, None, '___sec15'),
('Learning outcomes', 2, None, '___sec16'),
('Prerequisites', 2, None, '___sec17'),
('The course has two central parts', 2, None, '___sec18'),
('Statistical analysis and optimization of data',
3,
None,
'___sec18'),
('Machine learning', 3, None, '___sec19'),
'___sec19'),
('Machine learning', 3, None, '___sec20'),
('"Possible '
'textbooks":"https://github.com/CompPhysics/MachineLearning/tree/master/doc/Textbooks"',
2,
None,
'___sec20')]}
'___sec21')]}
end of tocinfo -->
<body>
@@ -164,7 +171,43 @@ formulas in HTML or ipython notebook files.
</div>
<h2 id="___sec0">Introduction and handling of data </h2>
<h2 id="___sec0">Introduction to Data Analysis and Machine Learning </h2>
<ul>
<li> LaTeX PDF:</li>
<ul>
<li> For printing:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Introduction/pdf/Introduction-minted.pdf" target="_self">Standard one-page format</a></li>
</ul>
<li> For screen viewing:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Introduction/pdf/Introduction-beamer.pdf" target="_self">standard Beamer format</a></li>
</ul>
</ul>
<li> HTML:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Introduction/html/Introduction.html" target="_self">Plain html</a></li>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Introduction/html/Introduction-reveal.html" target="_self">reveal.js beige slide style</a></li>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Introduction/html/Introduction-bs.html" target="_self">Bootstrap slide style, easy for reading on mobile devices</a></li>
</ul>
<li> iPython notebook:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Introduction/ipynb/Introduction.ipynb" target="_self">ipynb file</a></li>
</ul>
</ul>
<h2 id="___sec1">Getting started with Machine Learning </h2>
<ul>
<li> LaTeX PDF:</li>
@@ -200,7 +243,7 @@ formulas in HTML or ipython notebook files.
</ul>
<h2 id="___sec1">Review of central linear algebra elements </h2>
<h2 id="___sec2">Review of central linear algebra elements </h2>
<ul>
<li> LaTeX PDF:</li>
@@ -236,7 +279,7 @@ formulas in HTML or ipython notebook files.
</ul>
<h2 id="___sec2">Monte Carlo methods and elements of probability theory </h2>
<h2 id="___sec3">Monte Carlo methods and elements of probability theory </h2>
<ul>
<li> LaTeX PDF:</li>
@@ -272,42 +315,6 @@ formulas in HTML or ipython notebook files.
</ul>
<h2 id="___sec3">Linear regression and beyond </h2>
<ul>
<li> LaTeX PDF:</li>
<ul>
<li> For printing:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/pdf/Regression-minted.pdf" target="_self">Standard one-page format</a></li>
</ul>
<li> For screen viewing:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/pdf/Regression-beamer.pdf" target="_self">standard Beamer format</a></li>
</ul>
</ul>
<li> HTML:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/html/Regression.html" target="_self">Plain html</a></li>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/html/Regression-reveal.html" target="_self">reveal.js beige slide style</a></li>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/html/Regression-bs.html" target="_self">Bootstrap slide style, easy for reading on mobile devices</a></li>
</ul>
<li> iPython notebook:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/ipynb/Regression.ipynb" target="_self">ipynb file</a></li>
</ul>
</ul>
<h2 id="___sec4">Splines and Gradient methods </h2>
<ul>
@@ -344,7 +351,43 @@ formulas in HTML or ipython notebook files.
</ul>
<h2 id="___sec5">Neural Networks </h2>
<h2 id="___sec5">Regression Methods </h2>
<ul>
<li> LaTeX PDF:</li>
<ul>
<li> For printing:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/pdf/Regression-minted.pdf" target="_self">Standard one-page format</a></li>
</ul>
<li> For screen viewing:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/pdf/Regression-beamer.pdf" target="_self">standard Beamer format</a></li>
</ul>
</ul>
<li> HTML:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/html/Regression.html" target="_self">Plain html</a></li>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/html/Regression-reveal.html" target="_self">reveal.js beige slide style</a></li>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/html/Regression-bs.html" target="_self">Bootstrap slide style, easy for reading on mobile devices</a></li>
</ul>
<li> iPython notebook:</li>
<ul>
<li> <a href="https://compphysics.github.io/MachineLearning/doc/pub/Regression/ipynb/Regression.ipynb" target="_self">ipynb file</a></li>
</ul>
</ul>
<h2 id="___sec6">Neural Networks </h2>
<ul>
<li> LaTeX PDF:</li>
@@ -380,7 +423,7 @@ formulas in HTML or ipython notebook files.
</ul>
<h2 id="___sec6">Elements of Bayesian theory </h2>
<h2 id="___sec7">Elements of Bayesian theory </h2>
<ul>
<li> LaTeX PDF:</li>
@@ -416,7 +459,7 @@ formulas in HTML or ipython notebook files.
</ul>
<h2 id="___sec7">Decision trees, from simple to random ones </h2>
<h2 id="___sec8">Decision trees, from simple to random ones </h2>
<ul>
<li> LaTeX PDF:</li>
@@ -452,7 +495,7 @@ formulas in HTML or ipython notebook files.
</ul>
<h2 id="___sec8">Support Vector Machines </h2>
<h2 id="___sec9">Support Vector Machines </h2>
<ul>
<li> LaTeX PDF:</li>
@@ -488,7 +531,7 @@ formulas in HTML or ipython notebook files.
</ul>
<h2 id="___sec9">Unsupervised Learning, Boltzmann Machines </h2>
<h2 id="___sec10">Unsupervised Learning, Boltzmann Machines </h2>
<ul>
<li> LaTeX PDF:</li>
@@ -526,7 +569,7 @@ formulas in HTML or ipython notebook files.
<!-- !split -->
<h2 id="___sec10">Python and Scikit Learn, a short guide </h2>
<h2 id="___sec11">Python and Scikit Learn, a short guide </h2>
<ul>
<li> HTML format only:</li>
@@ -539,7 +582,7 @@ formulas in HTML or ipython notebook files.
<!-- !split -->
<h2 id="___sec11">Teach yourself C++ </h2>
<h2 id="___sec12">Teach yourself C++ </h2>
<ul>
<li> HTML format only:</li>
@@ -552,9 +595,9 @@ formulas in HTML or ipython notebook files.
<!-- !split -->
<h2 id="___sec12">Projects Fall 2017 </h2>
<h2 id="___sec13">Projects Fall 2017 </h2>
<h3 id="___sec13">Project </h3>
<h3 id="___sec14">Project </h3>
<ul>
<li> LaTeX and PDF:</li>
@@ -573,7 +616,7 @@ formulas in HTML or ipython notebook files.
</ul>
<h3 id="___sec14">Course content </h3>
<h3 id="___sec15">Course content </h3>
<p>
Probability theory and statistical methods play a central role in science. Nowadays we are
@@ -592,7 +635,7 @@ tools of probability theory, the aim of this course is to expose you to central
This course covers thus topics like Monte Carlo methods and Markov chains, Bayesian statistics, error estimates, various linear methods, optimization of data and error analysis and central algorithms in machine learning.
The course has several numerical projects and numerical exercises that are meant to illustrate the theory.
<h2 id="___sec15">Learning outcomes </h2>
<h2 id="___sec16">Learning outcomes </h2>
<p>
The course introduces a variety of central algorithms and methods
@@ -609,19 +652,19 @@ essential for studies of data analysis and machine learning. The course is proje
<li> Work on numerical projects to illustrate the theory. The projects play a central role and students are expected to know modern programming languages like Python or C++.</li>
</ul>
<h2 id="___sec16">Prerequisites </h2>
<h2 id="___sec17">Prerequisites </h2>
<p>
Basic knowledge in programming and numerics. Required courses are the equivalents to the University of Oslo mathematics courses MAT1100, MAT1110, MAT1120 and at least one of the corresponding computing and programming courses INF1000/INF1110 or MAT-INF1100/MAT-INF1100L/BIOS1100/KJM-INF1xxx.
<h2 id="___sec17">The course has two central parts </h2>
<h2 id="___sec18">The course has two central parts </h2>
<ol>
<li> Statistical analysis and optimization of data</li>
<li> Machine learning</li>
</ol>
<h3 id="___sec18">Statistical analysis and optimization of data </h3>
<h3 id="___sec19">Statistical analysis and optimization of data </h3>
<p>
The following topics will be covered
@@ -638,7 +681,7 @@ The following topics will be covered
<li> Practical optimization using Singular-value decomposition and least squares for parameterizing data.</li>
</ul>
<h3 id="___sec19">Machine learning </h3>
<h3 id="___sec20">Machine learning </h3>
<p>
The following topics will be covered
@@ -654,7 +697,7 @@ The following topics will be covered
All the above topics will be supported by examples, hands-on exercises and project work.
<h2 id="___sec20"><a href="https://github.com/CompPhysics/MachineLearning/tree/master/doc/Textbooks" target="_self">Possible textbooks</a> </h2>
<h2 id="___sec21"><a href="https://github.com/CompPhysics/MachineLearning/tree/master/doc/Textbooks" target="_self">Possible textbooks</a> </h2>
<p>
<b>General learning book on statistical analysis</b>: