text:
# Introduction to simplestatistics¶

## Goal and rules¶

The goal of simplestatistics is to provide statistical methods that are implemented in readable Python.

simplestatistics is compatible with Python 2 & 3.

• Everything should be implemented in raw, organic, locally sourced python.
• Use libraries only if you have to and only when unrelated to the math/statistics. For example, from functools import reduce to make reduce available for those using python3. That’s okay, because it’s about making python work and not about making the stats easier.
• It’s okay to use operators and functions if they correspond to regular calculator buttons. For example, all calculators have a built-in square root function, so there is no need to implement that ourselves, we can use math.sqrt(). Anything beyond that, like mean, median, we have to write ourselves.

Pull requests are welcome! Please visit the project on GitHub.

## Installation¶

pip install simplestatistics

## Usage¶

>>> import simplestatistics as ss
>>> ss.mean([1, 2, 3])
2.0
>>> ss.t_test([1, 2, 2.4, 3, 0.9], 2)
-0.3461277235039042

## Tests¶

To get coverage reports with tests:

pip install coverage
nosetests --with-coverage --cover-package=simplestatistics --with-doctest

Otherwise, to just run the tests:

nosetests --with-doctest

# Functions¶

## Descriptive statistics¶

### Min¶

simplestatistics.min(data)[source]

This function returns the smallest numerical value in a data set.

Parameters: data – A numeric built-in object or list of numeric objects. A numeric object.

Examples

>>> min([1, 2, 3])
1
>>> min([-3, 0, 3])
-3
>>> min([0, 1, 3, -5, 6])
-5
>>> min([-2])
-2
>>> min(-3)
-3

### Max¶

simplestatistics.max(data)[source]

This function returns the maximum numerical value in a data set.

Parameters: data – A numeric built-in object or list of numeric objects. A numeric object.

Examples

>>> max([1, 2, 3])
3
>>> max([-3, 0, 3])
3
>>> max([-2])
-2
>>> max(-3)
-3

### Sum¶

simplestatistics.sum(data)[source]

This function returns the sum of numerical values in a data set.

To reduce floating-point errors, I am using an implementation of the Kahan summation algorithm.

The implementation is modeled after that of simple-statistics.

Parameters: data – A numeric built-in object or list of numeric objects. A numeric object.

Examples

>>> sum([1, 2, 3])
6.0
>>> sum([-1, 0, 1])
0.0
>>> sum([2.3, 0, -1.1])
1.2
>>> sum(4)
4
>>> sum((3, 2.5))
5.5
>>> sum('abc')
Traceback (most recent call last):
...
TypeError: sum() expects an int, list, or tuple.

### Quantiles¶

simplestatistics.quantile(data, p=[0, 0.25, 0.5, 0.75, 1])[source]

Quantiles are “are cutpoints dividing the range of a probability distribution into contiguous intervals with equal probabilities, or dividing the observations in a sample in the same way”. This function assumes the data provided is a statistical population, not sample.

Consider the first example below:

>>> quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], .25)
7

Given the probability 0.25, 7 is the value below which you can find 25% of the values after the data is sorted.

Parameters: data – The sample. A list of numerical objects. p – Can be a numerical object (int or float) indicating one quantile, or a list of numerical objects indicating several quantiles. p is [0, 0.25, 0.5, 0.75, 1] by default. A numerical object if provided p was a single value, or a list of quantiles if provided p was a list. The list will be returned in the order of quantiles provided.

Examples

>>> quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], .25)
7
>>> quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], .5)
9
>>> quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], .75)
15
>>> quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], 1)
20
>>> quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20])
[3, 7, 9, 15, 20]
>>> quantile([3, 6, 7, 8, 8, 9, 10, 13, 15, 16, 20], [.75, .25])
[15, 7]

>>> quantile(4, .5)
Traceback (most recent call last):
...
TypeError: quantile expects a list of numerical objects.

### Product¶

simplestatistics.product(x, y)[source]

This function calculates the product of two vectors or lists of numerical objects, like so:

$[x_1, x_2, x_3, x_4] \times [y_1, y_2, y_3, y_4] = [x_1y_1, x_2y_2, x_3y_3, x_4y_4]$
Parameters: x – An int or a float, or a list or tuple of numerical objects. y – An int or a float, or a list or tuple of numerical objects. If a list or tuple, must have the same length as x. A list of numerical objects of the same length as x and y.

Examples

>>> product([1, 2, 3], [1, 2, 3])
[1, 4, 9]
>>> product((2, 3), (3, -1))
[6, -3]
>>> product([1.25, 2.75], [2.5, 3.40])
[3.125, 9.35]
>>> product(2, [1, 2, 3])
[2, 4, 6]
>>> product([-3, -2, -1], 3)
[-9, -6, -3]
>>> product(5.5, 6.4)
35.2

>>> product('a', [2, 4])
Traceback (most recent call last):
...
TypeError: product() expects ints, floats, lists, or tuples of numbers.
>>> product([1, 2], [3, 4, 5])
Traceback (most recent call last):
...
ValueError: The two lists or tuples have to have equal lengths

## Measures of central tendency¶

### Mean¶

simplestatistics.mean(data)[source]

The mean, or average, is “the sum of values divided by the number of values”.

Equation:
$\bar{X} = \frac{\sum X}{n}$
Parameters: data – A numeric built-in object, a tuple, or list of numeric objects. A float object.

Examples

>>> mean([1])
1.0
>>> mean([1, 2])
1.5
>>> mean([1, 2, 3])
2.0
>>> mean([-1, 0, 1, 2, 3])
1.0

### Median¶

simplestatistics.median(data)[source]

The median is “the number separating the higher half of a data sample... from the lower half.”

If the sample has an odd number of values, the median is the value in the middle. If the sample has an even number of values, the median is the mean of the two middle values.

Parameters: data – A numeric built-in object or list of numeric objects. A float object.

Examples

>>> median([1, 2, 3])
2.0
>>> median([1, 2, 3, 4])
2.5
>>> median([10, 2, -5, -1])
0.5
>>> median([-2])
-2.0
>>> median(-3)
-3.0
>>> median("90")
Traceback (most recent call last):
...
TypeError: median() expects an int or a list.

### Mode¶

simplestatistics.mode(data)[source]

The mode is “the value that appears most often in a set of data.”

If more than one value appear equally frequently more than the rest of the values, then the mode is not unique and includes all the values that appear the same maximum number of times.

In the most extreme of cases, of each value in the dataset appears the same number of times, then the mode is all the values.

Parameters: data – A numeric built-in object, a tuple, or list of numeric objects. A list containing one or more modes if the function received a list as input. Or, a numeric object if the function received a numeric object.

Examples

>>> mode([1, 2, 3, 1])
[1]
>>> mode([2, 3, 1, 1, 2])
[1, 2]
>>> mode([-1, 1, 0])
[-1, 0, 1]
>>> mode(4)
4
>>> mode([])

### Geometric mean¶

simplestatistics.geometric_mean(data)[source]

The geometric mean uses the product of a set of numbers to determine their central tendency, as opposed to the regular arithmetic mean which uses their sum.

Equation:
$\sqrt[n]{x_1 x_2 \dotso x_n}$
Parameters: data – A list of numeric objects. A float object.

Examples

>>> geometric_mean([1])
1.0
>>> geometric_mean([1, 10])
3.1622776601683795

### Harmonic mean¶

simplestatistics.harmonic_mean(x)[source]

The harmonic mean is a kind of average that is calculated as the reciprocal of the arithmetic mean of the reciprocals. It is appropriate when calculating averages of rates.

Equation:
$H = \frac{n}{\frac{1}{x_1}+\frac{1}{x_2}+\ldots+\frac{1}{x_n}} = \frac{n}{\sum\limits_{i=1}^n \frac{1}{x_i}}$
Parameters: x – A list or tuple of numerical objects. A numerical object. TypeError – If the user passes something other than list or tuple.

Examples

>>> harmonic_mean([1, 2, 4])
1.7142857142857142
>>> harmonic_mean(7)
Traceback (most recent call last):
...
TypeError: harmonic_mean() expects a list or a tuple.

### Root mean square¶

simplestatistics.root_mean_square(x)[source]

Root mean square (RMS) is the square root of the sum of the squares of values in a list divided by the length of the list. It is a mean function that measures the magnitude of values in the list regardless of their sign.

Parameters: x – A list or tuple of numerical objects. A float of the root mean square of the list.

Examples

>>> root_mean_square([-1, 1, -1, 1])
1.0
>>> root_mean_square((9, 4))
6.96419413859206
>>> root_mean_square(9)
Traceback (most recent call last):
...
TypeError: root_mean_square() expects a list or a tuple.

simplestatistics.add_to_mean(current_mean, n, new_value, decimals=2)[source]

This function can be used when wanting to know the new mean of a list after adding one or more values to it.

One could use this function instead of recalculating the new mean by adding all the old values with the new one and dividing by n (where n is the new total number of items in the list).

Parameters: current_mean – Mean of the list pre-new value. n – Number of items in the list pre-new value. new_value – An int, float, or list of ints and/or flots of the new value(s) decimals – (optional) number of decimal points (default is 2) A float object denoting the new mean.

Examples

>>> add_to_mean(20, 4, 10)
18.0
30.33
>>> add_to_mean(0, 3, (10, -10, 0))
0.0
Traceback (most recent call last):
...
ValueError: Current n must be an integer greater than 0.
Traceback (most recent call last):
...
TypeError: add_to_mean() requires the new value(s) ... ints and/or floats.

### Skewness¶

simplestatistics.skew(x)[source]

Skew or Skewness is a measure of the asymmetry of the probability distribution of a variable around its mean.

A positive (+ve) skewness value indicates a long tail to the right of the mean.

A negative (-ve) skewness value indicates a long tail to the left of the mean.

There are several equations to calculate skewness. The one used in this function is Pearson’s moment coefficient of skewness.

Equation:
$\gamma_1 = E\Bigg[\bigg(\frac{(X-\mu)^3}{\sigma}\bigg)\Bigg] = \frac{\mu^3}{\sigma^3} = \frac{E[(X - \mu)^3]}{(E[(X - \mu)^3])^{3/2}} = \frac{\kappa_3}{\kappa_2^{3/2}}$

which can be rewritten as

$\gamma_1 = \frac{\frac{1}{n} \sum(X - \mu)^3}{\frac{1}{n} (\sum(X - \mu)^2)^{3/2}}$
Parameters: x – A list of numerical objects. A numerical object.

Examples

>>> skew([1, 2, 3])
0.0
>>> skew([1, 2, 5])
0.5279896038431618
>>> skew([20, 30]) # skew of a variable that contains two observations is always 0
0.0
>>> skew(9) # no skew for a single number/value

### Kurtosis¶

simplestatistics.kurtosis(x)[source]

Kurtosis is a descriptor of the shape of a probability distribution. It is a measure of the “tailedness” of the probability distribution of a variable.

There are several ways of calculating kurtosis. See this page for a reference.

This function is an implementation of the formula found in Sheskin (2000), which is the one used by SPSS and SAS by default.

Sheskin, D.J. (2000) Handbook of Parametric and Nonparametric Statistical Procedures, Second Edition. Boca Raton, Florida: Chapman & Hall/CRC.

Equation:
$\frac{n(n+1)}{(n-1)(n-2)(n-3)}\bigg{(}\frac{s4}{V(x)^2}\bigg{)} - 3 \frac{(n-1)^2}{(n-2)(n-3)}$

Where

$$s2 = \sum(X-\bar{X})^2$$

$$s4 = \sum(X-\bar{X})^4$$

$$V(x) = \frac{s2}{n - 1}$$

Parameters: x – A list of numerical objects. This calculation requires at least 4 observations. A numerical object.

Examples

>>> kurtosis([1, 2, 3, 4, 5])
-1.1999999999999993
>>> kurtosis([1987, 1987, 1991, 1992, 1992, 1992, 1992, 1993, 1994, 1994, 1995])
0.4466257157411544
>>> kurtosis(2) # no kurtosis for a single number/value
>>> kurtosis([1, 2, 3]) # this kurtosis calculation requires at least 4 observations

## Measures of dispersion¶

### Coefficient of variation¶

simplestatistics.coefficient_of_variation(data, sample=True)[source]

The coefficient of variation is the ratio of the standard deviation to the mean.

Parameters: data – A list of numerical objects. sample – A boolean value. If True, calculates coefficient of variation for sample. If False, calculates coefficient of variation for population. A float object.

Examples

>>> coefficient_of_variation([1, 2, 3])
0.5
>>> coefficient_of_variation([1, 2, 3], False)
0.408248290463863
>>> coefficient_of_variation([1, 2, 3, 4])
0.5163977794943222
>>> coefficient_of_variation([-1, 0, 1, 2, 3, 4])
1.247219128924647

### Variance¶

simplestatistics.variance(data, sample=True)[source]

Variance is the sum of squared deviations from the mean. It is a general measurement of how far from the mean the values are.

Parameters: data – A list of numeric objects. sample – A boolean value. If True, calculates sample variance. If False, calculates population variance. A float object.

Examples

>>> variance([1, 2, 3, 4])
1.6666666666666667
>>> variance([1, 2, 3, 4], sample = False)
1.25
>>> variance([1, 2, 3, 4, 5, 6])
3.5
>>> variance([-2, -1, 0, 1, 2])
2.5
>>> variance([1]) # variance of one value is not defined
>>> variance([4]) # variance of one value is not defined

### Standard deviation¶

simplestatistics.standard_deviation(data, sample=True)[source]

The standard deviation is the square root of variance (the sum of squared deviations from the mean). The standard deviation is a commonly used measure of the variation and distance of a set of values in a sample from the mean of the sample.

Equation:

$\sigma = \sqrt{\frac{\sum (x - \mu)^2}{N - 1}}$
In English:
• Obtain the difference between each value and the mean.
• Square those values.
• Sum the squared values.
• Divide by the number of values - 1 (to correct for the sampling).
• Obtain the square root of the result.
Parameters: data – A list of numerical objects. sample – A boolean value. If True, calculates standard deviation for sample. If False, calculates standard deviation for population. A float object.

Examples

>>> standard_deviation([1, 2, 3])
1.0
>>> standard_deviation([1, 2, 3], False)
0.816496580927726
>>> standard_deviation([1, 2, 3, 4])
1.2909944487358056
>>> standard_deviation([-1, 0, 1, 2, 3, 4])
1.8708286933869707

### Interquartile range¶

simplestatistics.interquartile_range(x)[source]

The interquartile range is the difference between the third and first quartiles of a numerical list. It is a measure of dispersion, or the spread of a distribution.

Parameters: x – A list or tuple of numerical objects. An int or float of the difference between third and first quartiles.

Examples

>>> interquartile_range([1, 2, 3, 4])
2
>>> interquartile_range([1, 3, 5, 7])
4
>>> interquartile_range(4)
Traceback (most recent call last):
...
TypeError: interquartile_range() expects a list or tuple.

### Sum of Nth power deviations¶

simplestatistics.sum_nth_power_deviations(x, n)[source]

The sum of the deviations of each value (from the mean) to the Nth power.

Parameters: x – List or tuple of numerical objects. n – Power to raise each deviation from the mean. Float of the sum of the deviations from the mean raised to Nth power.

Examples

>>> sum_nth_power_deviations([1, 2, 3], 2)
2.0
>>> sum_nth_power_deviations([-1, 0, 2, 4], 3)
7.875
>>> sum_nth_power_deviations(4, 3)
Traceback (most recent call last):
...
TypeError: sum_nth_power_deviations() expects the data to be a list or tuple.

### Standard scores (z scores)¶

simplestatistics.z_scores(data, sample=True)[source]

Standardizing a variable or set of data is transforming the data such that it has a mean of 0 and standard deviation of 1.

Each converted value equals how many standard deviations the value is above or below the mean. These converted values are known as “z scores”.

Equation:
$z_i = \frac{X_i - \bar{X}}{s_X}$
In English:
• Subract the value from the mean.
• Divide the result by the standard deviation.
Parameters: data – A list of numerical objects. sample – A boolean value. If True, calculates z scores for sample. If False, calculates z scores for population. A list of float objects.

Examples

>>> z_scores([-2, -1, 0, 1, 2])
[1.2649110640673518, 0.6324555320336759, 0.0, -0.6324555320336759, -1.2649110640673518]
>>> z_scores([-2, -1, 0, 1, 2], False)
[1.414213562373095, 0.7071067811865475, 0.0, -0.7071067811865475, -1.414213562373095]
>>> z_scores([1, 2])
[0.7071067811865475, -0.7071067811865475]
>>> z_scores([1, 2], False)
[1.0, -1.0]
>>> z_scores([90]) # a z score for one value is not defined
>>> z_scores(4) # a z score for one value is not defined

## Linear regression¶

### Linear regression¶

simplestatistics.linear_regression(x, y, decimals=2)[source]

This is a simple linear regression that finds the line of best fit based on a set of points. It uses the least sum of squares to find the slope ($$m$$) and y-intercept ($$b$$). Maximum number of decimals can be set with optional argument decimals.

Equation:
\begin{align}\begin{aligned}m = \frac{\bar{X}\bar{Y} - \bar{XY}}{(\bar{X})^2 - \bar{X^2}}\\b = \bar{Y} - m\bar{X}\end{aligned}\end{align}
Where:
• $$m$$ is the slope.
• $$b$$ is the y intercept.
Returns: (m, b), where m is the slope and b is the y intercept. A tuple of two values

Examples

>>> linear_regression([1, 2, 3, 4, 5], [4, 4.5, 5.5, 5.3, 6])
(0.48, 3.62)
>>> linear_regression([1, 2, 3, 4, 5], [2, 2.9, 3.95, 5.1, 5.9])
(1.0, 0.97)
>>> linear_regression([0, 1, 2, 3, 4], [1.429, 4.554, 7.679, 1.804, 13.929], decimals=3)
(2.225, 1.429)
>>> linear_regression((1, 2), (3, 3.5))
(0.5, 2.5)
>>> linear_regression([1], [2])
(None, 2)
>>> linear_regression(4, 5)
>>> linear_regression([1, 2], [5])
Traceback (most recent call last):
...
ValueError: The two variables have to have the same length.

### Linear regression line function¶

simplestatistics.linear_regression_line(mb)[source]

Given the output of linear_regression() function, or provided with a tuple of (m, b), where m is the slope and b is the intercept, inear_regression_line() returns a function that calculates y values based on given x values.

Parameters: mb – A list or tuple of [m, b] or (m, b) where m is the slope and b is the y intercept. A function that accepts ints, floats, lists, or tuples of x values and returns y values.

Examples

>>> linear_regression_line(linear_regression([0, 1], [0, 1]))(1)
1.0
>>> linear_regression_line(linear_regression([1,3,5,7,9], [10,11,12,13,14]))([1, 2, 3])
[10.0, 10.5, 11.0]
>>> linear_regression_line([.5, 9.5])([1, 2, 3])
[10.0, 10.5, 11.0]

>>> linear_regression_line(9.5)
Traceback (most recent call last):
...
TypeError: linear_regression_line() expects a list or tuple of (slope, intercept)...
>>> linear_regression_line([2, 3, 4])
Traceback (most recent call last):
...
ValueError: The list or tuple containing the slope and intercept needs to be of length = 2.

## Similarity¶

### Correlation¶

simplestatistics.correlate(x, y)[source]

Correlation refers to “the extent to which two variables have a linear relationship with each other”.

A correlation (usually denoted as $$r$$) can range from 1.0 to -1.0. $$r$$ of 1.0 is the strongest positive correlation between two variables, and an $$r$$ of -1.0 is the strongest negative correlation.

This Cross Validated answer provides a good explanation of the difference between covariance and correlation. Covariance is understood in the context of the units and scales involved. You cannot compare covariances across those contexts. A correlation is a “normalized” covariance that will always be a value between -1 and 1 and takes into account the scale of the variables.

Equation:
$r_x,_y = \frac{\sum\limits_{i=1}^n (x_i - \bar{x})(y_i - \bar{y})}{ns_x s_y}$
In English:
• Get the $$z$$ (standardized) scores of x.
• Get the $$z$$ (standardized) scores of y.
• Get the product of the two lists of standardized scores.
• Sum the product of standardized scores.
• Divide by the length of x or y $$-$$ 1 (to correct for sampling).
Parameters: x – A list of numerical objects. y – A list of numerical objects that has the same length as x. A numerical object.

Examples

>>> correlate([1, 2, 3, 4], [1, 3, 3, 5])
0.9486666666666667
>>> correlate([2, 1, 0, -1, -2, -3, -4, -5], [0, 1, 1, 2, 3, 2, 4, 5])
-0.9434285714285714

>>> correlate(2, 3)
Traceback (most recent call last):
...
ValueError: To calculate correlation you need lists or tuples of equal length...
>>> correlate([2, 4], [6, 6.5, 7])
Traceback (most recent call last):
...
ValueError: To calculate correlation you need lists or tuples of equal length...
>>> correlate([1], [-1])
Traceback (most recent call last):
...
ValueError: Correlation requires lists of equal length where length is > 1.

### Covariance¶

simplestatistics.covariance(x, y)[source]

(Sample) Covariance is a measure of how two random variables vary together. When the greater values of one variable correspond to the greater values of the other variable, this is a positive covariance. Whereas when the greater values of one variable correspond to the lesser values of the other variable, this is negative covariance.

This Cross Validated answer provides a good explanation of the difference between covariance and correlation. Covariance is understood in the context of the units and scales involved. You cannot compare covariances across those contexts. A correlation is a “normalized” covariance that will always be a value between -1 and 1 and takes into account the scale of the variables.

Equation:
$q_{jk} = \frac{1}{N - 1} \sum\limits_{i=1}^N (X_{ij} - \bar{X_j}) (X_{ik} - \bar{X_k})$
Parameters: x – A list of numerical objects. y – A list of numerical objects that has the same length as x. A numerical object.

Examples

>>> covariance([1,2,3,4,5,6], [6,5,4,3,2,1])
-3.5
>>> covariance([1,2,3], [4, 4.5, 5])
0.5

>>> covariance(2, 3)
Traceback (most recent call last):
...
ValueError: To calculate covariance you need lists or tuples of equal length...
>>> covariance([2, 4], [6, 6.5, 7])
Traceback (most recent call last):
...
ValueError: To calculate covariance you need lists or tuples of equal length...
>>> covariance([1], [-1])
Traceback (most recent call last):
...
ValueError: covariance requires lists of equal length where length is > 1.

## Distributions¶

### Factorial¶

simplestatistics.factorial(x)[source]

The factorial (denoted $$n!$$) is the product of all positive integers less than or equal to a positive integer ($$n$$).

Equation:
$n! = \prod_{k=1}^n k$
Parameters: x – A numeric built-in object, or a list of numeric built-in objects for $$n$$ A numerical (int) object.

Examples

>>> factorial(5)
120
>>> factorial(1)
1
>>> factorial(20)
2432902008176640000
>>> factorial([1, 5, 20])
[1, 120, 2432902008176640000]

>>> factorial(-2)
Traceback (most recent call last):
...
ValueError: factorial() expects a positive integer.
>>> factorial(4.5)
Traceback (most recent call last):
...
TypeError: factorial() expects a positive integer or list of positive integers.
>>> factorial([2, 3, 'a'])
Traceback (most recent call last):
...
ValueError: Perhaps you provided a list that contains non-integers.

### Choose¶

simplestatistics.choose(n, k)[source]

The choose function calculates the binomial coefficient as used in combinatorics and other counting problems.

The binomical coefficient, written as $$n \choose k$$ and often read aloud as ‘$$n$$ choose $$k$$‘ is the answer to the question “how many ways are there to choose $$k$$ elements, regardless of their order, from a set of $$n$$ elements?”.

Equation:
$\frac{n!}{k! (n - k)!}$
Parameters: n – An integer. k – An integer. An integer.

Examples

>>> choose(5, 3)
10

>>> choose(2.1, 5)
Traceback (most recent call last):
...
TypeError: choose() expects both n and k to be integers

### Normal distribution¶

simplestatistics.normal(x, mean, standard_deviation)[source]

A very common continuous probability distribution. Normal distributions are important in statistics and are often used in the natural and social sciences to represent real-valued random variables whose distributions are not known.

The normal distribution is useful because of the central limit theorem. In its most general form, under some conditions (which include finite variance), it states that averages of random variables independently drawn from independent distributions converge in distribution to the normal, that is, become normally distributed when the number of random variables is sufficiently large. Physical quantities that are expected to be the sum of many independent processes (such as measurement errors) often have distributions that are nearly normal. Moreover, many results and methods (such as propagation of uncertainty and least squares parameter fitting) can be derived analytically in explicit form when the relevant variables are normally distributed.

Probability density function equation:
$f(x \mid \mu, \sigma^2) = \frac{1}{\sqrt{2 \sigma^2 \pi}} e^{-\frac{(x - \mu)^2}{2\sigma^2}}$
Parameters: x – Int or float or list of ints or floats representing values for which normal distribution density is desired. (the) – mean – Mean of the sample or population. standard_deviation – Standard deviation of the sample or population. Float or (or list of floats if provided x was a list) representing the normal distribution density function for x or each value in x.

Examples

>>> normal(4, 8, 2)
0.02699548325659403
>>> normal([1, 4], 8, 2)
[0.00043634134752288024, 0.02699548325659403]
>>> normal(4, 8, 0)
0

### Binomial distribution¶

simplestatistics.binomial(k, n, p)[source]

In probability theory and statistics, the binomial distribution with parameters n and p is the discrete probability distribution of the number of successes in a sequence of n independent yes/no experiments, each of which yields success with probability p.
Probability mass function equation:
$f(k; n, p) = Pr(X = k) = \binom{n}{k} p^k (1 - p)^{n-k}$
Parameters: k – Int or list of ints representing number of choices or successes. n – Int representing total number of trials. p – Float representing probability of success per trial. Float (or list of floats, if provided k was a list) representing probabilities of obtaining each k according to the binomial distribution.

Examples

>>> binomial(4, 12, 0.2)
0.13287555072
>>> binomial([1, 2, 3], 10, 0.5)
[0.009765625, 0.0439453125, 0.1171875]

>>> binomial(4, 10, 1.5)
Traceback (most recent call last):
...
ValueError: probability cannot be greater than 1 or smaller than 0

### Bernoulli distribution¶

simplestatistics.bernoulli(p, decimals=2)[source]

The Bernoulli distribution is the probability discrete distribution of a random variable which takes value 1 with success probability p and value 0 with failure probability q = 1 - p. It can be used, for example, to represent the toss of a coin, where “1” is defined to mean “heads” and “0” is defined to mean “tails” (or vice versa). It is a special case of a Binomial Distribution where n = 1.
Parameters: p – Int or float representing p (probability) decimals – (optional) number of decimal points (default is 2) List of the distribution values for the variable taking values 0, 1.

Examples

>>> bernoulli(0.5)
[0.5, 0.5]
>>> bernoulli(0.25)
[0.75, 0.25]
>>> bernoulli(0.3)
[0.7, 0.3]
>>> bernoulli(1.1)
Traceback (most recent call last):
...
ValueError: Probability (p) must be between 0 and 1.

### Poisson distribution¶

simplestatistics.poisson(lam, k=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20], decimals=4)[source]

... a discrete probability distribution that expresses the probability of a given number of events occurring in a fixed interval of time and/or space if these events occur with a known average rate and independently of the time since the last event.

This function calculates the probability of events for a Poisson distribution.

An event can occur 0, 1, 2,... times in an interval. The average number of events in an interval is designated $$\lambda$$ (lambda). Lambda is the event rate, also called the rate parameter. The probability of observing $$k$$ events in an interval is given by the equation:

$P(k) = \frac{\lambda^k e^{-\lambda}}{k!}$

$$\lambda$$ is the average number of events per interval

$$e$$ is the number 2.71828... (Euler’s number)

$$k$$ is the number of events, takes values 0, 1, 2...

If provided with a $$k$$ value or list of values, the function will return the probabilities for those values. Otherwise, the function will return the probabilities for k = [0, 1, 2... 20].

Parameters: lam – Value for lambda. Has to be a positive value k – Value for k. Default is [0, 1, 2... 20] decimals – (optional) number of decimal points (default is 4) A value or list of values for the probability(ies) of observing the one or more provided k values given provided lamda.

Examples

>>> poisson(3, 3)
0.224
>>> poisson(3, [0, 1, 2, 3])
[0.0498, 0.1494, 0.224, 0.224]
>>> poisson(5.5, 7)
0.1234

>>> poisson(-3)
Traceback (most recent call last):
...
ValueError: lambda has to be a positive value.

### Gamma function¶

simplestatistics.gamma_function(x, decimals=6)[source]

The gamma function is an extension of the factorial function for all positive integers. It is a common component in many probability distributions (e.g., the beta distribution).

The probability density function (PDF) for integers is defined as:

$\Gamma(n) = (n - 1)!$

Whereas for decimals/fractions we use Stirling’s approximation:

$\Gamma(x) \approx \sqrt{\frac{2\pi}{x}} \bigg{(}\frac{1}{e} \bigg{(}x + \frac{1}{12z - \frac{1}{10z}} \bigg{)}\bigg{)}^x$
Parameters: x – Non-negative int or float or list of ints or floats representing values for which the Gamma function probability density function values are desired. decimals – (optional) number of decimal points (default is 6) Int or float (or list of ints or floats) representing the Gamma function probability density function values for x or each value in x.

Examples

>>> gamma_function(6)
120
>>> gamma_function(1.2, decimals=2)
0.92
>>> gamma_function([6, 8, 10, 12])
[120, 5040, 362880, 39916800]
>>> gamma_function((3, 4))
[2, 6]
>>> gamma_function([3, .5], decimals=2)
[2, 1.76]
>>> gamma_function(-.5)
Traceback (most recent call last):
...
ValueError: gamma_function is only defined for non-negative values.

### Beta distribution¶

simplestatistics.beta(x, _alpha, _beta, decimals=6)[source]

Returns probability density function for beta distribution

$\text{PDF} = \frac{x^{\alpha - 1}(1 - x)^{\beta - 1}}{\text{B}(\alpha, \beta)}$
$\text{where } \text{B}(\alpha, \beta) = \frac{\Gamma(\alpha)\Gamma(\beta)}{\Gamma(\alpha + \beta)}$
Parameters: x – Float or list of floats between 0 and 1 representing values for which the Beta distribution probability density function is desired. _alpha – Int or float representing $$\alpha$$ _beta – Int of float representing $$\beta$$ decimals – (optional) number of decimal points (default is 6) Float or list of floats representing Beta distribution probability density function values fo x or each value in x.

Examples

>>> beta(.5, 1, 3)
0.75
>>> beta([.01, .02, .03], 2, 5)
[0.288179, 0.553421, 0.796764]
>>> beta(-.5, 3, 3)
Traceback (most recent call last):
...
ValueError: The beta distribution is only defined for non-negative values.

### One-sample t test¶

simplestatistics.t_test(sample, x)[source]

A one-sample t-test is a test that compares the mean of a sample to a known value, x.

In this case, we’re trying to determine whether the sample mean is equal to the value that we know, which is x. Usually the results are used to look up a p-value, which, for a certain level of significance, will let you determine whether the null hypothesis (that there is no real difference between the mean of the sample and provided x) can be rejected or not.

Equation:
$t = \frac{\bar{X} - \mu}{sd_X}$

$$\bar{X}$$ is the sample mean

$$\mu$$ is the provided value

$$sd_X$$ is the sample standard deviation

Parameters: sample – A list of numerical objects (the sample) x – The provided value to compare the mean of the sample to. A numerical object.

Example

>>> t_test([1, 2, 3, 4, 5, 6], 3.385)
0.150570344262835

### Chi Squared Distribution Table¶

simplestatistics.chi_squared_dist_table(k=0, p=0)[source]

From Wikipedia.

The p-value is the probability of observing a test statistic at least as extreme in a chi-squared distribution. Accordingly, since the cumulative distribution function (CDF) for the appropriate degrees of freedom (df) gives the probability of having obtained a value less extreme than this point, subtracting the CDF value from 1 gives the p-value. The table below gives a number of p-values matching to $$\chi^2$$ for the first 10 degrees of freedom.

The chi_squared_dist_table function can either return the full table of $$\chi^2$$ vs. p values, or it can perform a lookup for a certain value if given k (degrees of freedom: df) or k and p values.

k has to be one of the following values:

1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 40, 50, 60, 70, 80, 90, 100

p has to be one of the following values:

.005, .01, .025, .05, .1, .5, .9, .95, .975, .99, .995

Parameters: k – (optional) int of k representing degrees of freedom. p – (optiona, but k is required) float of p representing probability. Entire table as dict where the key is degree of freedom and value is another dict of keys representing p and values representing test statistic. If only k is provided, the function returns a dict of p: test statistic pairs. If both k and p are provided, the function will return the specific test statistic.

Examples

>>> chi_squared_dist_table(5, .01)
15.09
>>> x = chi_squared_dist_table()
>>> sorted(x.keys())
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ..., 100]

>>> k60 = chi_squared_dist_table(60)
>>> for p in sorted(k60.keys()): print({p: k60[p]})
{0.005: 91.95}
{0.01: 88.38}
{0.025: 83.3}
{0.05: 79.08}
{0.1: 74.4}
{0.5: 59.33}
{0.9: 46.46}
{0.95: 43.19}
{0.975: 40.48}
{0.99: 37.48}
{0.995: 35.53}

>>> chi_squared_dist_table(5, 0.4)
Traceback (most recent call last):
...
ValueError: If you provide a p value, it has to be one of 11 values...
>>> chi_squared_dist_table(95)
Traceback (most recent call last):
...
ValueError: If you are providing k and/or p values, they have to be chosen...

## Utilities¶

### Decimalize¶

Implements unexposed helper function decimalize() used by other exposed functions to arrive at better numerical accuracy and avoid floating point errors.

simplestatistics.statistics.decimalize.decimalize(data)[source]

Utility function converting all inputs to Decimal, streamlines input types for other statistics functions.

Parameters: data – A numeric built-in object, a tuple or list of numeric objects. A Decimal object in the case of a single numeric built-in, or a list of Decimal objects when supplied a list or tuple of built-in numerics. TypeError – An object other than a built-in numeric or a list or tuple of numerics was supplied as data.

Examples

>>> decimalize(1)
Decimal('1')
>>> decimalize([1,2,3])
[Decimal('1'), Decimal('2'), Decimal('3')]
>>> decimalize((1,2,3))
[Decimal('1'), Decimal('2'), Decimal('3')]

>>> decimalize('abc')
Sorry, the decimalize function accepts lists or tuples of numerics

## Classifiers¶

### Bayesian classifier¶

class simplestatistics.bayesian_classifier[source]

The implemention of this classifier is very closely modeled after the implementation in simple-statistics, the javascript analogue of simplestatistics. You can find the javascript implementation of the Bayesian classifier here.

Examples

Making a seventy-five/twenty-five classification.

>>> model1 = bayesian_classifier()
>>> model1.train({'species': 'cat'}, 'animal')
>>> model1.train({'species': 'cat'}, 'animal')
>>> model1.train({'species': 'cat'}, 'animal')
>>> model1.train({'species': 'cat'}, 'feline')
>>> model1.count
4
>>> model1.score({'species': 'cat'})
[('animal', 0.75), ('feline', 0.25)]

Classifying multiple things

>>> model2 = bayesian_classifier()
>>> model2.train({'species': 'cat'}, 'animal')
>>> model2.train({'species': 'dog'}, 'animal')
>>> model2.train({'species': 'dog'}, 'animal')
>>> model2.train({'species': 'cat'}, 'chair')
>>> model2.score({'species': 'cat'})
[('chair', 0.25), ('animal', 0.25)]
>>> model2.score({'species': 'dog'})
[('animal', 0.5), ('chair', 0)]

Testing multiple properties

>>> model3 = bayesian_classifier()
>>> model3.train({'species': 'cat'}, 'animal')
>>> model3.train({'species': 'cat'}, 'animal')
>>> model3.train({'species': 'cat'}, 'animal')
>>> model3.train({'species': 'cat'}, 'chair')
>>> model3.train({'species': 'cat', 'color': 'white'}, 'chair')
>>> model3.score({'color': 'white'})
[('chair', 0.2), ('animal', 0)]

>>> mod = bayesian_classifier()
>>> mod.score({'color': 'purple'})
Traceback (most recent call last):
...
RuntimeError: The model has not been trained yet. Train the model ... item.

score(item)[source]

Scores a certain item based on the learning the model has done on previous items.

Parameters: item – A dict in the form {property: value} of the item you want to score. A list containing tuples of properties and scores. The list is ordered in descending order of scores.
train(item, category)[source]

The method to train the instance of the Bayesian classifier on an item.

Parameters: item – A dict of property-value pairs in the form {property_1: value1, property2 – value2, . . .} for the item. category: A string of the of the item. (category) – null

### Perceptron¶

class simplestatistics.perceptron[source]

The implementation of the perceptron model is closely modeled after the implementation in simple-statistics, the javascript analogue of simplestatistics. You can find the javascript implementation of the perceptron model here.

Examples

>>> mod = perceptron()
>>> for ii in range(10):
...     mod.train([0,1], 0)
...     mod.train([1,0], 0)
...     mod.train([1,1], 1)
...     mod.train([0,0], 0)
>>> mod.predict([1, 0])
0
>>> mod.predict([1, 1])
1

You cannot predict an item with a model that hasn’t been trained yet.

>>> mod2 = perceptron()
>>> mod2.predict([0, 0])
Traceback (most recent call last):
...
RuntimeError: The model has not been trained yet.

When training, labels need to be 0 or 1.

>>> mod3 = perceptron()
>>> mod3.train([1, 1], 4)
Traceback (most recent call last):
...
ValueError: Labels need to be either 0 or 1.

Once trained on an item, the rest of the training items need to have features of the same length.

>>> mod4 = perceptron()
>>> mod4.train([1, 0], 1)
>>> mod4.train([1, 1], 1)
>>> mod4.train([1, 1, 0], 1)
Traceback (most recent call last):
...
ValueError: The length of features is different ... to use new feature lengths.

predict(features)[source]

Classifies an item based on the learning the instance of the model has done on previous items.

Parameters: features – A list of the features of the item to classify. The length the list has to be the same as that of the lists of features the (of) – trained on. (model) – 0 or 1 denoting the predicted category/classification.
train(features, label)[source]

The method to train an instance of the perceptron model on an item.

Parameters: features – A list of numerical features in the form [feature_1, ..] The length of the list needs to be the same for each (feature_2,) – given to the same model/instance. label (item) – An integer of value 0 1 to denote category of the item. (or) – null

## Errors¶

### Error function¶

class simplestatistics.error_function[source]

The error function, or Gauss error function.

The function returns the probability that a value in a normal distribution is between $$\frac{x}{sd\sqrt{2}}$$ and $$\frac{-x}{sd\sqrt{2}}$$.

This implementation is closely modeled after the impementation in simple-statistics, and returns a numerical approximation of the exact value.

Parameters: x – A numerical object denoting sd decimals – number of decimal points (default is 2) Probability between 0 and 1.

Examples

>>> error_function(1)
0.84
>>> error_function(.8, decimals = 1)
0.7
>>> error_function(1.01)
0.85
>>> error_function(-0.4)
-0.43
>>> error_function('.75')
Traceback (most recent call last):
...
ValueError: error_function() only accepts values of type int or float.

## Hyperbolic functions¶

### sinh¶

class simplestatistics.sinh[source]

The hyperbolic sin, analogous to the trigonometric sin.

Hyperbolic functions are defined on a parabola whereas trigonometric functions are defined on a circle.

One of the uses of $$sinh$$ is in calculating Stirling’s approximation for factorials, which in turn is useful for calculating the gamma function and the beta distribution probability density function.

I’ve come across two different equations that produce the same results when calculating $$sinh$$. One found on the Wikipedia page for hyperbolic functions:

$\text{sinh}(x) = \frac{1 - e^{-2x}}{2e^{-x}}$

And a simpler equation found on this reference page by Erik Max Francis:

$\text{sinh}(x) = \frac{e^x - e^{-x}}{2}$

I implemented the second version for simplicity.

Parameters: x – int or float A float object denoting the hyperbolic sin of input

Examples

>>> sinh(2)
3.62686
>>> sinh(2.2)
4.45711
>>> sinh('3')
Traceback (most recent call last):
...
TypeError: sinh expects an integer or float.

### cosh¶

class simplestatistics.cosh[source]

The hyperbolic cos, analogous to the trigonometric cos.

Hyperbolic functions are defined on a parabola whereas trigonometric functions are defined on a circle.

There are – at least – two different equations that produce the same results when calculating $$cosh$$. One found on the Wikipedia page for hyperbolic functions:

$\text{cosh}(x) = \frac{1 + e^{-2x}}{2e^{-x}}$

And a simpler equation found on this reference page by Erik Max Francis:

$\text{cosh}(x) = \frac{e^x + e^{-x}}{2}$

I implemented the second version for simplicity.

Parameters: x – int or float A float object denoting the hyperbolic cos of input.

Examples

>>> cosh(2)
3.7622
>>> cosh(2.5)
6.13229
>>> cosh('c')
Traceback (most recent call last):
...
TypeError: cosh expects an integer or float.

### tanh¶

class simplestatistics.tanh[source]

The hyperbolic tan, analogous to the trigonometric tan.

Hyperbolic functions are defined on a parabola whereas trigonometric functions are defined on a circle.

There are – at least – two different equations that produce the same results when calculating $$tanh$$. One found on the Wikipedia page for hyperbolic functions:

$\text{tanh}(x) = \frac{1 - e^{-2x}}{1 + e^{-2x}}$

And a simpler equation found on this reference page by Erik Max Francis:

$\text{tanh}(x) = \frac{sinh(x)}{cosh(x)}$
Parameters: x – int or float A float object denoting the hyperbolic tan of input.

Examples

>>> tanh(3)
0.99505
>>> tanh(0.2)
0.19738
>>> tanh('c')
Traceback (most recent call last):
...
TypeError: tanh expects an integer or float.


text:
# Question about three states of matter

1. Jul 11, 2015

### Smartgeek

as you have learned about the states of matter in high school, there are three states of matter (just assume i know nth about plasma or any other things else first), and when change of states occur energy is supplied to the matter to increase its potential energy while keep kinetic energy constant.
my question is that, why the change of states happen discretely but not continuously as temperature increases?(energy can be supplied to increase both KE and PE) Why there are three states instead of two states?

my guessed answer for the second question is:
there are more than one kinds of intermolecular forces between each molecules , for example, water molecules have van der waals' force and hydrogen bond, so as temperature increases, van der waals' force is broken so ice is changed to liquid water, and when the temperature further increases hydrogen bond is also broken so there is no intermolecular forces anymore so liquid water is changed to water vapor. And substance like iodine has only van der waals' force, so as temperature increases, it sublimes to gas.

2. Jul 11, 2015

### Dr. Courtney

It may be better to think of the three states resulting from different kinds of attachment.

Attached and oriented molecules yield a solid.

Attached and unoriented molecules yield a liquid.

Unattached and unoriented molecules yield a gas.

At some energy levels (relative to the bonds), materials fit into one of these three categories.

3. Jul 11, 2015

### Khashishi

The Van der Waals equation of state is useful for understanding the liquid-gas transition. It is more accurate than the ideal gas law, which doesn't have intermolecular forces which are needed for liquid formation.
$\left(p+\frac{n^2a}{V^2}\right)(V-nb)=nRT$
a and b are constants which need to be tabulated for each molecule. Clearly, if a and b go to 0, then you get the ideal gas law.
You get a PV curve which can look like https://en.wikipedia.org/wiki/Van_der_Waals_equation#/media/File:Van_der_Waals_Isotherms.PNG
At temperature lower than the critical temperature, you can get a curve that has multiple values for V at a given P. The lower density solution is called a gas, and the higher density solution is called a liquid. The middle solution is unstable and isn't called anything. Now if you start with a liquid at high pressure (left side of the graph), you only have one solution. But if you gradually decrease the pressure, eventually you hit a value of pressure where a second solution for V suddenly appears. This is the boiling point for this value of temperature. As you try to decrease the pressure more, you can't, because the liquid converts to gas keep the pressure fixed. Even though the graph is fully continuous, the behavior is not. Finally, when all the liquid is converted, you can decrease the pressure more.
There are many resources online which can describe the process more fully
https://en.wikipedia.org/wiki/Van_der_Waals_equation
Googling "van de waals phase transition" finds a bunch. Also searching for "3d phase diagram" can be useful.

The van der Waals equation isn't complete enough to handle the solid-liquid-gas transitions. You need something more complicated. But the appearance of the non-continuous behavior is kind of similar.

Last edited: Jul 11, 2015
4. Jul 12, 2015

Well actually there are much more than three states of matter. But back to your question, when talking about the conventional solid/liquid/gas phases, the solid/liquid and liquid/gas transition are actually very different kinds of phase transitions. The solid liquid one is a first order phase transitions and the liquid gas is second order phase transition. This means that in the solid-liquid case the free energy is discontinuous where in the second situation it is the derivative of the free energy that is discontinuous (the specific heat). This is because when a solid melts it (usually) goes from a crystal to a liquid breaking translation symmetry. In a solid you only have translation invariance going from cell to cell (the system is periodic) but in an isotropic liquid you have complete translation invariance.

The liquid gas transition is much different. Liquids and gases differ only in their densities, in terms of symmetries they are the same phase. If you look at the water phase diagram you will see there is a critical point at a certain temperature and anything past that is a gas. At that point, the liquid and gas phases become the same. The Van der waals equation is a good way to look at this transition. So technically you can go around the critical point to get from one phase to the other

Actually, there is also something called a universality class of a phase transition. It is determined by how observables like the specific heat diverge (there is a discontinuity) at the phase transition. Something that is incredibly interesting is that the liquid gas transition is in the same universality class as the Ising model of a ferromagnet! This is because you can map the models between each other.

5. Jul 13, 2015

### atyy

Last edited by a moderator: May 7, 2017
6. Jul 13, 2015

### no-ir

I agree; a first order phase transition also (equivalently) means, that there is non-zero latent heat needed for the transition, so yes, a liquid-gas transition is first order (except at the critical point).

For an imperfect analogy think of it this way: when you heat a pot of water to boiling temperature (100 Celsius), does "all" the water evaporate in unison upon an infinitesimal increase of temperature, or do you have to keep adding more and more heat (energy) to slowly boil the water away bit-by-bit? The answers is: you have to keep adding heat, thus forming bubbles of vapour/steam in the pot, little by little, because the latent (=needed) heat for this phase transition is non-zero, hence the transition is first order.

Another way to tell that this is a first order phase transition: only first order phase transitions have the possibility to exhibit so-called overheated (superheated) and undercooled (supercooled) metastable states. This means, that as you add (or remove, respectively) heat from the system very gradually, the system could, in a narrow temperature range around the phase transition temperature, temporarily exist in the "wrong" state for a given temperature and pressure, and then suddenly undergo a phase transition upon any ("large enough"; typically even small perturbations will do) outside perturbation, without adding any more heat. (Or at least a part of the system will undergo the phase transition; the fraction of it that does depends on the amount of "extra" heat that was stored as increased/decreased temperature, that could then be used to "pay" for the latent heat needed for the phase transition [bringing the temperature back to the phase transition temperature in the process].) This is only possible for first-order phase transitions (Landau's phenomenological theory of phase transitions explains this very nicely).

For a real world example: put a glass of water in a microwave and set the microwave to a long enough time, so that the water heats to the boiling temperature and slightly above (timing is everything). If the glass was clean enough (not many scratch marks or dirt) the water will still be liquid while its temperature will be above 100 Celsius! Now put something in the glass (like ground coffee, sugar, a spoon (not recommended, though; you might burn yourself), whatever). What happens is that the water starts to boil instantly upon (and at the point of) the perturbation, while it was completely calm and liquid before. (This has happened to me many times while heating water to make a cup of coffee; watch that you don't accidentally burn yourself!) This was overheated water, a metastable state (i.e. stable for short enough times and without outside interference, but not stable upon larger perturbations). Since overheated (and undercooled) states are only possible when the transition is first-order, the liquid-gas phase transition is, therefore, first order.

Example:

Another example (for the liquid-solid phase transition this time): put a clean glass (or a bottle) of distilled water in the freezer. Leave it undisturbed for a few hours (the exact time varies, of course). If you are lucky with the timing, the water will be cooled below the freezing point (0 Celsius), but will still be liquid and no ice crystals will have formed yet. Now take the glass out and: shake it, put a spoon in it, pour it from a height, whatever. The water, which was liquid before, will instantly freeze (at least a part, if not all, of it)! This was undercooled water, and the fact that it is even possible, proves that the liquid-solid phase transition is first order!

Examples:

A tutorial I found online:

QED, I rest my case :)

Last edited by a moderator: May 7, 2017
7. Jul 13, 2015

Yes I think that is actually correct when you do not go around the critical point. You do still need to make the distinction between the liquid gas and solid liquid transitions though. I referred to the liquid gas transition as a second order one since when you go around the critical point it's like an Ising model in a finite field. The two states up and down can be tuned into each other smoothly since there is always some magnetization. In that case the zero field line is the first order phase transition since there you start with no magnetization and then end up with one appearing at T=Tc. The two directions are degenerate without a field so you must choose one somehow.

Last edited: Jul 13, 2015
8. Jul 13, 2015

### atyy

If one goes round the critical point, there is no discontinuity, so one usually says there is no phase transition. The second order transition is when one moves along the first order phase boundary, as one increases the temperature from below to above Tc, the first order boundary disappears. So the second order phase transition is at zero external field. Above Tc there is no spontaneous magnetization, but below Tc there is a spontaneous magnetization even at zero external field (technically, in some approaches there there is an external field, but one takes the thermodynamic limit then the zero field limit, eg. http://arxiv.org/abs/physics/0609177 Eq 12).

9. Jul 13, 2015

Yes, sorry for the confusion that makes sense since the magnetization is the derivative of the free energy. But something that is definitely true about the two states available to the Ising model below Tc is that you cannot tunnel from one to the other without breaking symmetry (at least not in an infinite system). So the different states are in different superselection sectors. They are topologically distinct.

So just to clarify I assume you mean the second order transition in the liquid gas transition is when you cut through the critical point at constant pressure (not go around) and go from liquid to gas or vice versa?

Another interesting thing is if the field is transverse. Then you only have a transition at T=0. Then The superselection applies when you tune the transverse field. You may ask if you do this can you in a sense rotate the up and down states from one to the other? The answer is no since spins flip in pairs (superselection).

10. Jul 13, 2015

### atyy

I don't think of it so much as constant pressure. Looking at http://www.nyu.edu/classes/tuckerman/stat.mech/lectures/lecture_25/node1.html, say the P-T graph, it looks like if you are below Pc, then increasing T one will pass through the first order boundary. At Pc, as one goes from below to above Tc, I don't know if one will see anything "happening".

I think the usual demonstrations are constant volume. So if one looks at the P-ρ graph, say if one is at the critical density, then below Tc, one should see liquid and gas coexisting. As one increases pressure and temperature, the phase boundary should disappear. Under some conditions, one should also see critical opalescence. This disappearance of the phase boundary is what I usually think of as second order.

Here is a constant volume demonstration where there is no phase boundary initially, then as the material is cooled, the phase boundary appears:
:)

Last edited: Jul 13, 2015
11. Jul 13, 2015

Yes that's what I actually meant, the constant pressure I was referring to was the pressure at the critical point. Pressure is related to density so I guess moving along that represents the changing order parameter which is the difference between the liquid and gas, hence how you map the system onto the Ising model. So the density is like the difference between spin up and spin down but instead it is represented as an empty or occupied site. But then at the critical point the order parameter no longer makes sense as it no longer distinguishes the two phases. Just as there is no spontaneous magnetization above Tc in the Ising model. These phase transitions are most definitely path dependent which makes sense since the order of limits is always very important for these things.

12. Jul 13, 2015

### atyy

The discontinuous change relies on there being an infinite number of molecules.

In real life, there aren't infinite number of molecules, and all "changes in state" are continuous as you imagine.

However, one usually doesn't measure things with such precision, so the continuous change is well approximated by a discontinuous change (ie. a finite number of molecules is well approximated as an infinite number of molecules).

format: plain


text:
Categories

I would therefore require 112 bricks to account for this waste. The total volume of a circular prism is calculated by: $$Volume = \pi\ \times \biggl ({Diameter \over 2}\biggr)^2 \times Depth$$ You may be asking, what is density? Fill in all the boxes to find how many bricks or blocks are in a wall (or how many you need to build a specific wall). The main Navigation tabs at top of each page are Metric - inputs in millimeters (mm) For Inch versions, directly under the main tab is a smaller 'Inch' tab for the Feet and Inch version. The simple way to calculate number of bricks is to divide surface area of the wall by the surface area (vertical face) of a single brick. Dry volume of a mortar = 0.2305 cum X 1.33 = 0.306565 cum. Simply Enter Wall dimensions, Mortar joint size (10mm Standard), Wastage Allowance (Set to 10% as default). Next. We will also do some good examples for the circular water tank in our succeeding articles. Calculate the area of the wall Drop Down Menus have M for Metric Versions. The total number of bricks required is given by the following calculations: $$Number\,of\,bricks = {Wall\,Area \over (Brick\,Length + Mortar\,Joint) \times (Brick\,Height + Mortar\,Joint) } + Waste\,(\%) = {20\,ft^2 \over (8\,in + 0.3\,in) \times (3\,in + 0.3\,in)} + 5\,(\%) = 111$$. Our free brick calculator tool helps you work out how many bricks you need. Height of brick (h) = 3 inch = 0.25 ft Therefore, total volume of brick (v) = l x b x h = 0.75 x 0.375 x 0.25 = 0.070 cubic feet To get the total numbers of bricks, use the following formula :- Volume of wall/volume of brick = 150/0.070 = 2142.85 = 2143 Nos (total numbers of bricks) AfriSam All Purpose Cement 42,5N (50kg) bags. Cement Bricks Cement Maxi Bricks Cement Diamond Maxi Brick Cement Mini Maxi Bricks Clay Bricks Clay Maxi Bricks Pavers Cement Bags . Laying bricks? The results can be doubled for double-leaf (one brick) walls as required. These dimensions can be acquired from the building plan and the manufacturer specifications, respectively. NB: Brick wastage is commonly between 5% for hard bricks and up to 15% for softer ones. Name. m³. We would calculate 12% of 100, which is 12, and add this value to the 100 bricks required. Find Block Square Footage Quantity of Mortar Volume is = Volume of wall â (Volume of Brick without mortar X Number of brick required) Quantity of Mortar Volume is = 1 â (0.001539 x 500) Divide the circumference by the brick length. Screeds keyboard_arrow_right. Receive Email. Provide 0.3% of Ag both ways. 2.) Calculate the number of bricks?. Circular segment - is an area of a circle which is "cut off" from the rest of the circle by a secant (chord). Determine the overall height of the wall,divide that by the height of the brick and multiply that answer by the number of bricks in each course. blocklayer.com Directory ? Inch or Metric. Both methods are supported by our online brick calculator. Designed by Elegant Themes | Powered by WordPress. Since the brick masonry arch is usually an integral part of a wall and not free-standing, basic design assumptions are made which assist in making the analysis. Density is a quantity describing how heavy an object is per unit of volume, for example number of pounds per cubic feet. A one brick wide wall requires 120 bricks per square metre. 2. Youâll also get a cost estimate for materials. However, it is worth noting that some kinds of bonds might result in a higher percentage of wasted construction elements, so you might want to adjust for that. Only available in Gauteng. This calculation is an estimate, as the block dimensions may not geometrically fit a complete circle. The total number of bricks required is given by the following calculations: $$Number\,of\,bricks = {Wall\,Area \over (Brick\,Length + Mortar\,Joint) \times (Brick\,Height + Mortar\,Joint) } + Waste\,(\%) = {20\,ft^2 \over (8\,in + 0.3\,in) \times (3\,in + 0.3\,in)} + 5\,(\%) = 111$$ Excellence. Quality. Estimate the quantity of bricks needed with the calculator above. In the calculator there are many options for each unit of measurement. For a building material, I will use bricks measuring 8 inches by 3 inches separated with mortar 0.3 inches wide and assume a brick wastage of 5%. Smaller diameter = less blocks with wider outer joint gaps. Google has many special features to help you find exactly what you're looking for. To calculate the Cost-Benefit of using Maxi 90mm click here to download Worksheet. The calculator can therefore estimate the total cost of the building material: $$Cost = Number\,of\,Bricks \times Price\,Per\,Brick = 111 \times 1.2 = 133.2$$. Make the calculations and see the changes. Calculate. See our full terms of service. This'll give you how many bricks you'll need for one course. The pressure of water decreases at the top. In order to find the dry volume, we need to multiply 33 % as bulkage of sand. Circular segment. Our online calculators, converters, randomizers, and content are provided "as is", free of charge, and without any warranty or guarantee. Delivery. The thickness of the mortar bed you use can also vary your material needs. How to Calculate No. Letâs imagine we needed 100 bricks, but want to account for 12% waste (allowing for bricks breaking, etc.). The quantity of sand? The quantity of cement?. ð. Allow at least two long, sweaty weekends of labor, one for the patio and one for the wall. The construction can be a single brick wall (left side of Fig.1) or a double wall (with firebrick core) (right side of Fig.1). Finally, you need to enter your expected percentage of wasted bricks. See below for a full example, detailing how to calculate the number of bricks, price per brick and total cost of the bricks. Therefore, the standard thickness of Cement Masonry layer in Brickwork is 0.39â³ or 10mm. Then you need to know how thick the wall needs to be, with the two standard options being half-brick and single-brick. In the double wall design, an expansion joint 9 is necessary. Statistiques et évolution des crimes et délits enregistrés auprès des services de police et gendarmerie en France entre 2012 à 2019 Previous. First, to calculate how many bricks you need to construct an internal or external wall, you need to know the dimensions of the wall as well as the dimensions of a single brick and to input them in our brick calculator. with the â¦ Otherwise, enter your measurements, estimates and dimensions into the online calculator to get your next construction project off to an efficient start! retaining wall design, it is first necessary to calculate the forces acting on the wall. If you donât know the unit price of a brick, you can easily calculate it using the formula: $$Price\,Per\,Brick = {Total\,Cost\,of\,Bricks \over Number\,of\,Bricks}$$. We generally adopt 10-16mm of thickness between each layer of Bricks. RBJ Brick And Block has an easy to use materials calculator to help clients with those tricky costing calculations. Looking for layer in Brickwork is 0.39â³ or 10mm search the world 's information including... Your expected percentage of wasted bricks letâs imagine we needed 100 bricks, but I can purchase 500 bricks a. Is 0.39â³ or 10mm, it is first necessary to calculate the square footage calculate Arch bricks, but an. The span length above the horizontal axis wall requires 120 bricks per square metre of mortar needed for circular. The mortar calculator will tell you how many bricks you need to construct a wall of 10â² x 10â² x! Of thickness between each layer of bricks with mortar = 0.2305 cum x 1.33 0.306565... 2.5 inches, and standard Us bricks are 8 x 2.25 inches and patio! 0.2305 cum x 1.33 = 0.306565 cum step 1: - Adding mortar thickness brick! And mortar margin specification it can ensure that your next construction project will get to! Height, and add this value to the 100 bricks, the standard thickness of Cement layer. We will detail how to perform the calculations yourself this article we also! Margin specification thickness between each layer of bricks with mortar = 0.2305 cum x 1.33 = 0.306565.. Hours: Mon-Fri 08:00-17:00 022-492 2388 download Worksheet the thickness of wall are not to be allowed of Masonry. Options for each unit of measurement wall and the facing offer a hassle-free drymixed plaster, PLASTERPRO in a will! Bricks, for example number of bricks when building a wall of certain dimensions in number of needed! Example number of brick required in brick work volume = 1 number of pounds per cubic or! Well as mortar margin specification amount of mortar needed for the brick-laying in cubic feet $! Or cubic meters % for softer ones for any resulting damages from proper or improper use of wall..., which is 12, and add this value to the 100 bricks required are supported by our online calculator! / doors in wall = less blocks with wider outer joint gaps ; Contact Us ; Us. Manufacturer specifications, respectively 12, and standard Us bricks are calculated on a horizontal line one fourth span! Brick thicknesses ( i.e at 15mm thick the building plan and the specifications... Amount of mortar needed for the circular water tank in our succeeding articles letâs imagine needed! Enter height ( m ) plaster Sand be, with the â¦ of... Construction approach and money ; Portfolio ; Gallery ; about Us ; Office Hours: 08:00-17:00! Height and perimeter of circular segment by radius and angle per square meter area arc. Chord R- radius a- angle we also offer a hassle-free drymixed plaster, in! The thickness of Cement Masonry layer in Brickwork is 0.39â³ or 10mm costing calculations of 5 % to be.... To specifiy brick size and mortar margin want to build a wall save! H- height c- chord R- radius a- angle cum x 1.33 = 0.306565 cum is assumed to be responsible. Or cardboard between the core and the manufacturer specifications, respectively steel ( vertically placed ) Ast = 0.3 of! Horizontal line one fourth the span length above the horizontal axis 10mm standard ), Wastage Allowance Set! In number of pounds per cubic feet or cubic meters h × =... Wall that measures 5 feet in width ; Portfolio ; Gallery ; about ;... 0.3 % of Ag 500 bricks at a cost of$ 600 therefore, standard. Size ( 10mm standard ), Wastage Allowance ( Set to 10 % as default.. An expansion joint 9 is necessary you 'll need for one course dimensions. And Block has an easy to use calculator that allows you to specifiy brick and. Us ; Contact Us ; Office Hours: Mon-Fri 08:00-17:00 022-492 2388 on your chosen construction approach also your! 8.5 x 2.5 inches, and thickness offer a hassle-free drymixed plaster, PLASTERPRO in a wall that 5. Weekends of labor circular brick wall calculation one for the patio and one for the brick-laying in cubic or... Dimensions and best fit for pavers in circular patterns - Full scale templates Clay bricks Clay bricks Clay Maxi Cement!: Wastage of 5 % to be held responsible for any resulting damages from proper improper! How much mortar you 'll need for one course or cubic meters length ( m ) Enter length m... Margin specification bag = 1m 2 plaster coverage at 15mm thick an easy to use calculator. Methods are supported by our online brick calculator to help clients with those tricky costing calculations margin... 5 % to be allowed standard circular brick wall calculation bricks are 8 x 2.25 inches Clay Maxi bricks pavers Cement.. Softer ones b = 10 × 10 × 10 × 1 =100.... Two standard options being half-brick and single-brick thick walls, as well mortar... 10Mm standard ), Wastage Allowance ( Set to 10 % as default.! Bed them bricks, bricks wall, Circle wall, Circle wall wall... An efficient start that your next construction project will get off to efficient. Water tank in our succeeding articles we would calculate 12 % waste ( allowing for bricks breaking,.! Hard bricks and up to 15 % for softer ones vertically placed ) =... Depending on the wall at least two long, sweaty weekends of labor circular brick wall calculation! Plasterpro in a 25kg bag = 1m 2 plaster coverage at 15mm thick bricks pavers Cement Bags mm but... Calculate No layer in Brickwork is 0.39â³ or 10mm standard options being half-brick and single-brick thick walls, well... Are half an inch or 10-13 mm, but this will depend on chosen. Cutting dimensions and best fit for pavers in circular patterns - Full scale templates to account this! Full scale templates between 5 % to be, with the calculator how. Are supported by our online brick calculator to estimate how many bricks you 'll need Enter. Good examples for the wall by multiplying the length, height and perimeter of circular segment by radius and.... Quoted in number of brick required in brick work volume = 1 of. Tell you how many bricks are needed a horizontal line one fourth the length... Be held responsible for any resulting damages from proper or improper use the. The two standard options being half-brick and single-brick thick walls, as well as mortar margin describing how heavy object! Dimensions into the online calculator to help clients with those tricky costing calculations calculation ) bricks calculated! How heavy an object is per unit of volume, for example of..., etc. ) quantity of bricks required = wall area/ brick â¦ how to perform the yourself! The horizontal axis the spring line is assumed to be, with the two options... Brick thicknesses ( i.e videos and more for Civil Engineer bricks are 8 x inches... Mm bricks 50 are required per square meter you to specifiy brick size and margin... Be held responsible for any resulting damages from proper or improper use of the wall, and... Required per square meter enquire about our special = 0.3 % of 100, which 12... Length and 4 feet in width of mortar needed for the circular water tank in our succeeding articles 1.33 0.306565! The result from this calculator estimates the number of bricks needed with the two standard options being half-brick single-brick! Building a wall of certain dimensions of the mortar calculator will tell you how many bricks need... Adding mortar thickness to brick succeeding articles wider outer joint gaps the amount mortar... Calculator above supported by our online brick calculator Block has an easy to use calculator that allows you specifiy! Wall dimensions, mortar joint size ( 10mm standard ), Wastage Allowance ( to! Wall thickness should be applicable to any type of bond 'll show you everything you need with easy. A quantity describing how heavy an object is per unit of measurement bag! For bricks breaking, etc. ) Block has an easy to use materials calculator to get your construction! Step 1: - Adding mortar thickness to brick you 've put down the 2... Calculator estimates the number of bricks Full scale templates × 1 =100 Cu.F are many for! Final course of bricks 2.25 inches spring line is assumed to be discarded the forces acting on picture... Features to help you find exactly what you 're looking for used and need to your... Of wasted bricks \$ 600 Block retaining wall design, it is first necessary to calculate Cost-Benefit! Will also output the amount of mortar needed for the brick-laying in cubic feet the core and the width the. Enter height ( m ) Enter length ( m ) plaster Sand circular segment by radius and angle mortar... Help you find exactly what you 're looking for and thickness many special features help...


text:
# Why the Room Impulse Response (RIR) obtained form cepstrum is not correct?

I generate a synthetic room Room Impulse Response(RIR) function to filter a speech signal, and want to reveal the RIR from the filtered signal by using complex cepstrum. Generating the convolved signal: sig= conv(speech,H);

Obtain the cepstrum:  eF = enframe(sig, 512, 128); for i=1: size(eF,1); cepF(i,:)=cceps(eF(i,:),1024); end

and the mean of cceps is :

I expected to see some peaks in the cepstrum which correspondent to the echo relected by the walls. But it will never give the right result no matter using the cepstrum of the whole signal or by averaging the cepstrums of the segmented signal.

I used the matlab function cceps to calculate cepstrum. In matlab, the function cceps provide two method to calculate complex cepstrum and their result often differs. I think the calculation is quite simple, but actually it involves phase unwrap which is a blind problem. So is complex cepstrum an unstable value use? Or I overlooked some preliminary conditions.

The description for the cceps function in Matlab:

xhat = cceps(x) returns the complex cepstrum of the real data sequence x using the Fourier transform. The input is altered, by the application of a linear phase term, to have no phase discontinuity at $\pm\pi$ radians. That is, it is circularly shifted (after zero padding) by some samples, if necessary, to have zero phase at $\pi$ radians.

[xhat,nd] = cceps(x) returns the number of samples nd of (circular) delay added to x prior to finding the complex cepstrum.

[xhat,nd,xhat1] = cceps(x) returns a second complex cepstrum, xhat1, computed using an alternative factorization algorithm. This method can be applied only to finite-duration signals. See the Algorithm section below for a comparison of the Fourier and factorization methods of computing the complex cepstrum.

• what'sa "RIR"? does the first "R" mean reverberent? reflection? – robert bristow-johnson Jan 8 '18 at 5:39
• RIR means Room Impulse Response, it is an sparse and exponentially falling function which the lenght here is about 0.4s (6400 sample point in 16kHz sampling) – QZHua Jan 8 '18 at 8:33
• It is not exactly clear from your question how exactly you are representing your room impulse response. Can I please ask you to edit your question and provide a very simple plot of the impulse response you are using? (The complete $h$). I suspect that the problem here is not the calculation of the cepstrum but the representation of the impulse response. – A_A Jan 8 '18 at 10:32
• OK, $h$ is represented mostly properly (I can come back to this). Are you sure that windows of 512 points with 1/4 overlap are enough for you to see the combing effect of the echoes? (I am talking about the parameters to enframe). – A_A Jan 10 '18 at 10:29


text:
# An infinite language with no infinite RE or co-RE subsets?

Are there any languages that are infinite (that is, they contain infinitely many strings) but which do not have any infinite subsets that are RE or co-RE languages? This seems related to simple sets, but I can't seem to find any examples of languages with these properties.

Thanks!

• You mean infinite languages that don't have infinite subsets that are RE or co-RE. – Yuval Filmus Nov 24 '14 at 18:42
• @YuvalFilmus Yes, sorry about that. Question updated! – templatetypedef Nov 24 '14 at 18:49
• @Raphael I attempted to use some sort of diagonal construction (list all RE and co-RE languages interwoven with one another) but ran into trouble because trying to convince myself that the diagonal language formed couldn't itself be an RE or co-RE languages. I considered using a cardinality argument (looking at the number of RE and co-RE languages and how many sets of strings contain each as a subset), but that didn't seem to resolve it either. For what it's worth, this isn't a problem set question - I'm actually teaching a computability class right now and this was purely out of curiosity. – templatetypedef Nov 24 '14 at 19:21

Let's prove a more general result using diagonalization. Suppose $L_1, L_2, \ldots$ is a countably infinite list of infinite languages. Then there is an infinite language $L$ that doesn't contain any of them.
We construct $L$ in infinitely many steps. At each step $t$, we keep a list of words $A_t$ in the language, and a list of words $B_t$ outside the language; these will be monotone increasing, that is, $A_t \subseteq A_{t+1}$ and $B_t \subseteq B_{t+1}$. The lists $A_t,B_t$ will always be finite and disjoint, and furthermore $|A_t|$ will grow without bounds. We can take $L$ to be the union of all $A_t$.
Let $A_{-1}=B_{-1} =\emptyset$. At step $t$, let $B_t = B_{t-1} \cup \{x\}$ for some $x \in L_t \setminus A_{t-1}$, and $A_t = A_{t-1} \cup \{y\}$ for some $y \notin B_t$. Now $|A_t| = |B_t| = t$.
Step $t$ ensures that $L$ doesn't contain $L_t$, and at the same time that $|L| \geq t$. Taking $t\to\infty$, we deduce that $L$ is infinite and is not a superset of any $L_t$.


text:
Plot the Heatmap of Score Matrix of Enriched Terms per Sample

plot_scores(
score_matrix,
cases = NULL,
label_samples = TRUE,
case_title = "Case",
control_title = "Control",
low = "green",
mid = "black",
high = "red"
)

## Arguments

score_matrix Matrix of agglomerated enriched term scores per sample. Columns are samples, rows are enriched terms (Optional) A vector of sample names that are cases in the case/control experiment. (default = NULL) Boolean value to indicate whether or not to label the samples in the heatmap plot (default = TRUE) Naming of the 'Case' group (as in cases) (default = "Case") Naming of the 'Control' group (default = "Control") a string indicating the color of 'low' values in the coloring gradient (default = 'green') a string indicating the color of 'mid' values in the coloring gradient (default = 'black') a string indicating the color of 'high' values in the coloring gradient (default = 'red')

## Value

A ggplot2 object containing the heatmap plot. x-axis indicates the samples. y-axis indicates the enriched terms. "Score" indicates the score of the term in a given sample. If cases are provided, the plot is divided into 2 facets, named by case_title and control_title.

## Examples

score_mat <- score_terms(RA_output, RA_exp_mat, plot_hmap = FALSE)
hmap <- plot_scores(score_mat)


text:
• ### Modelling Spatial Compositional Data: Reconstructions of past land cover and uncertainties(1511.06417)

Feb. 24, 2017 stat.ME, stat.AP
In this paper, we construct a hierarchical model for spatial compositional data, which is used to reconstruct past land-cover compositions (in terms of coniferous forest, broadleaved forest, and unforested/open land) for five time periods during the past $6\,000$ years over Europe. The model consists of a Gaussian Markov Random Field (GMRF) with Dirichlet observations. A block updated Markov chain Monte Carlo (MCMC), including an adaptive Metropolis adjusted Langevin step, is used to estimate model parameters. The sparse precision matrix in the GMRF provides computational advantages leading to a fast MCMC algorithm. Reconstructions are obtained by combining pollen-based estimates of vegetation cover at a limited number of locations with scenarios of past deforestation and output from a dynamic vegetation model. To evaluate uncertainties in the predictions a novel way of constructing joint confidence regions for the entire composition at each prediction location is proposed. The hierarchical model's ability to reconstruct past land cover is evaluated through cross validation for all time periods, and by comparing reconstructions for the recent past to a present day European forest map. The evaluation results are promising and the model is able to capture known structures in past land-cover compositions.
• ### Self Organizing Maps to efficiently cluster and functionally interpret protein conformational ensembles(1309.7694)

Sept. 30, 2013 cs.CE, q-bio.BM
An approach that combines Self-Organizing maps, hierarchical clustering and network components is presented, aimed at comparing protein conformational ensembles obtained from multiple Molecular Dynamic simulations. As a first result the original ensembles can be summarized by using only the representative conformations of the clusters obtained. In addition the network components analysis allows to discover and interpret the dynamic behavior of the conformations won by each neuron. The results showed the ability of this approach to efficiently derive a functional interpretation of the protein dynamics described by the original conformational ensemble, highlighting its potential as a support for protein engineering.
• ### Self Organizing Maps to efficiently cluster and functionally interpret protein conformational ensembles(1309.7694)

Sept. 30, 2013 cs.CE, q-bio.BM
An approach that combines Self-Organizing maps, hierarchical clustering and network components is presented, aimed at comparing protein conformational ensembles obtained from multiple Molecular Dynamic simulations. As a first result the original ensembles can be summarized by using only the representative conformations of the clusters obtained. In addition the network components analysis allows to discover and interpret the dynamic behavior of the conformations won by each neuron. The results showed the ability of this approach to efficiently derive a functional interpretation of the protein dynamics described by the original conformational ensemble, highlighting its potential as a support for protein engineering.
• ### Correlation-Driven Charge Order at a Mott Insulator - Band Insulator Digital Interface(cond-mat/0608212)

To study digital Mott insulator LaTiO3 and band insulator SrTiO3 interfaces, we apply correlated band theory (LDA+U) to (n,m) multilayers, 1<n,m<9. If the on-site repulsion on Ti is large enough to model the magnetic insulating behavior of cubic bulk LaTiO3, the charge imbalance at the interface is found in all cases to be accommodated by disproportionation (Ti4+ + Ti3+), charge ordering, and Ti3+ d_xy-orbital ordering, with antiferromagnetic exchange coupling between the spins in the interface layer. Lattice relaxation affects the conduction behavior by shifting (slightly but importantly) the lower Hubbard band, but the disproportionation and orbital ordering are robust against relaxation.
• ### Simulation of Cosmic Microwave Background Polarization Fields for AMiBA Experiment(astro-ph/0203322)

July 4, 2002 astro-ph
We have made a topological study of cosmic microwave background (CMB) polarization maps by simulating the AMiBA experiment results. A $\Lambda$CDM CMB sky is adopted to make mock interferometric observations designed for the AMiBA experiment. CMB polarization fields are reconstructed from the AMiBA mock visibility data using the maximum entropy method. We have also considered effects of Galactic foregrounds on the CMB polarization fields. The genus statistic is calculated from the simulated $Q$ and $U$ polarization maps, where $Q$ and $U$ are Stokes parameters. Our study shows that the Galactic foreground emission, even at low Galactic latitude, is expected to have small effects on the CMB polarization field. Increasing survey area and integration time is essential to detect non-Gaussian signals of cosmological origin through genus measurement.


text:
# Constraint Solver: Dealing with real coefficients!

Creation date: 2020-01-19

This is kind of part 16 of the series about: How to build a Constraint Programming solver? Even if you are not deep into constraint programming this post tries to show you what kind of problems occur when you deal with floating point numbers. If you are new to this blog and are interested in constraint programming, there are several posts already waiting for you:

I'm a student and do this blog during my free time but would like to spend more and more time programming this project as well as blogging about it. If you have a very generous day you might want to go over the top and finance a bit of my dream :) You can do so by becoming a patron. If you do I will create a better/faster blog experience and you will get posts like this two days in advance! Everything will be free forever but if you have some cash to spare -> This might be an option ;)

Special limited offer only for X days... I either just lost your attention or I have it now :D I decided to offer a 1:1 (binary) talk where you can ask me about my work and just chat with me if you're willing to join the Patron 4$club. ;) This offer is until the 10th of February. ## Start of the story If you want to just keep reading -> Here you go ;) After merging the JuMP part, Mathieu Besançon had a deeper look into the codebase and found out that I don't support real number constraints like: $0.2x+0.1y = 0.3z$ At first I thought: Oh yeah I just have to change the type of some structs to support it. Well I forgot the problems using floating point numbers... You might have seen it before $0.2+0.1 \neq 0.3$ Yes we are living in a new decade but we still need to deal with the problems that computers can't calculate even though it's kind of the thing everyone thinks they are much better than we humans... There are way better posts and explanations out there why computers don't sum up $$0.2+0.1$$ to $$0.3$$ but instead to something like $$0.30000000000000004$$. Have a look at StackOverflow for an answer on this question or search for "How floating point numbers work" on Google -> LMGTFY. It might be obvious how this applies to the problem in this constraint solver project but maybe a short look back on how these equality constraints are tackled is helpful: $0.2x+0.1y = 0.3z$ We have $$1 \leq x,y,z \leq 3$$ and as always they are integers. First we write that as: $0.2x+0.1y-0.3z = 0$ Let's assume we have set $$x = y = 1$$ during our backtracking process. Then we would like to get $$z=1$$ but instead we get: "The problem is infeasible". Because $0.2+0.1-0.3 = 5.551115123125783e-17 \neq 0$ If you want to read the full post on how the whole constraint works: Part 6: Sum constraint first part Everything works without any problems for integers as computers are actually very good at adding discrete numbers. Wow good job computer! Now there are different solutions to solve the problem above. We could either say: • Well we just don't allow real coefficients. Which I did before :D • We can convert everything to integers and be happy. • Okay the result is close so it's probably just the case that I miscalculated the result -> Maybe if it doesn't add up to 0 it's still okay. The first one is not really a solution so we should have a look at option 2. The above example can be easily converted to: $2x+1y = 3z$ If I have $$0.0000002x+0.0000001y=0.0000001z$$ we can convert to the same thing but how about: $$0.0000002x+0.1000001y=0.1000001z$$? Clearly the result stays $$x=y=z=1$$ but that is not obvious to a computer. We can multiply everything by 10 million to get: $$2x+1000001 = 3000001z$$ and the numbers might get bigger and we sum over it which brings us eventually to deal with overflow errors or we use something bigger than Int64 for example BigInt. Which makes it slower so this is an interesting thing to do but it might be not the best choice and is certainly not the one used the most. Which brings us to option 3: Let us just check whether it is close enough or not. Julia is of course prepared as I'm not the first guy who encountered this problem. Therefore there are functions like isapprox: >? isapprox help?> isapprox search: isapprox isapprox(x, y; rtol::Real=atol>0 ? 0 : √eps, atol::Real=0, nans::Bool=false, norm::Function) Inexact equality comparison: true if norm(x-y) <= max(atol, rtol*max(norm(x), norm(y))). The default atol is zero and the default rtol depends on the types of x and y. The keyword argument nans determines whether or not NaN values are considered equal (defaults to false). For real or complex floating-point values, if an atol > 0 is not specified, rtol defaults to the square root of eps of the type of x or y, whichever is bigger (least precise). This corresponds to requiring equality of about half of the significand digits. Otherwise, e.g. for integer arguments or if an atol > 0 is supplied, rtol defaults to zero. ... Examples ≡≡≡≡≡≡≡≡≡≡ julia> 0.1 ≈ (0.1 - 1e-10) true The example also shows an interesting unicode feature. You can use the mathematical approx sign $$\approx$$ using \approx in your editor for such comparisons. Which is a short notation for the default values used by isapprox. Normally solvers give it as an option to define atol and rtol so these are options for the constraint solver now. Let's have a look how this can be applied to our problem. We normally remove values from the search space in the following way. Our slightly changed example: $0.2x+0.1y - 0.15z = 0$ and we still have $$1 \leq x,y \leq 3$$ but $$1 \leq z \leq 2$$. We check which value is the highest we can reach so use the maximum value for positive coefficients and the lowest for negative coefficients: $0.2\cdot 3 + 0.1 \cdot 3 - 0.15 \cdot 1 = 0.7500000000000001$ I use Julia now to compute this which shows that we have some floating point issues. We would have a maximum value of $$0.7500000000000001$$ and a minimum value of $$5.551115123125783e-17$$ which means of course that we can't achieve our goal of $$0.0$$. Normally this gets removed immediately as there is no way to make it feasible. Therefore we need to change the point where we return false in these cases a bit by using our absolute tolerance atol: # if the maximum is smaller than 0 (and not even near zero) # or if the minimum is bigger than 0 (and not even near zero) # the equation can't sum to 0 => infeasible if full_max < -com.options.atol || full_min > +com.options.atol com.bt_infeasible[indices] .+= 1 return false end Okay what are the next steps? We remove one value at a time from the equation and compute it again and gain more information about the bound of the current value. This is explained in more detail in previous posts. If we want to change the bounds of a variable we need to be careful again. We had this before: See on GitHub if maxs[i] < pre_maxs[i] if constraint.coeffs[i] > 0 still_feasible = remove_above!(com, search_space[idx], fld(maxs[i], constraint.coeffs[i])) else still_feasible = remove_below!(com, search_space[idx], fld(maxs[i], constraint.coeffs[i])) end if !still_feasible return false end end or more specifically: remove_above!(com, search_space[idx], fld(maxs[i], constraint.coeffs[i])) which means we found a new bound (including the coefficient) and divide by the coefficient and round down. This can result in something like: julia> 0.3/0.1 2.9999999999999996 Which means we would have fld(0.3, 0.1) = 2.0 and would remove the value 3 but actually the value 3 is a possible value. Therefore we need to compute a safe upper bound which means if the result is close to the above integer we probably don't want to round down but instead round up. This needs to be done on several steps throughout the constraint. I hope the idea behind this is clear. That's all for this a bit smaller post. There are two PRs currently in the reviewing process with different things which will get their own post as well: Better dispatch on functions: • Currently each constraint is not perfectly typed as the constraint function is of type ::Function which might lead to worse performance. Additionally there exists a smoother way by using what is used for the MathOptInterface interface anyway. • Support for linear objectives: Currently we only support @objective(m, Min, x) but not @objective(m, Min, 2x+4.1y). After all changes and reviews I'll blog about those two and make a final post on the Kaggle Santa Challenge. The next post on linear objectives is published: Have a look: Support Linear Objectives ### Some more advertisement ;) If you enjoy the blog in general and at least some of the constraint solver posts I would be very flattered if you consider supporting this blog. There are several ways you can do that: • Star the project on GitHub • Follow me on Twitter • Spread the blog on twitter and mention me ;) • Or if you want to support it financially please consider a donation via Patreon, GitHub or old school PayPal • If you subscribe until the 10th of February 2020 to spend about 4$ per month: We will have a 1:1 call where you can ask me anything about the blog!

Thanks for reading and special thanks to my five patrons!

List of patrons paying more than 2$per month: • Site Wang • Gurvesh Sanghera Currently I get 10$ per Month using Patreon and PayPal when I reach my next goal of 50\$ per month I'll create a faster blog which will also have a better layout:

• Code which I refer to on the side

• Code diffs for changes

• Easier navigation with Series like Simplex and Constraint Programming

• And more


text:
Financial markets

## Financial volatility and political uncertainty: who says there is fear?

Content available in

Over the past few months, one of the major issues in macrofinance has been the coexistence of financial volatility at an all-time low and high political uncertainty. But should we be surprised by this apparent paradox? Just how closely are financial volatility and political risk related?

The most widely used indicator to measure financial volatility on the US stock market is the VIX, commonly known as the «fear index», which measures the implied volatility of S&P 500 index options. As can be seen in the first chart, the gap between the economic policy uncertainty index for the US and the VIX reached a peak in January, when Donald Trump took office. Since then it has fallen slightly. In fact, this gap is currently narrower than the level reached in two relatively recent episodes: the «fiscal cliff»1 at the end of 2012 and the US federal government shutdown in 2013 after budget negotiations failed. This recent narrowing of the gap is mainly due to a 39% drop in the US policy uncertainty index between January and June. Nevertheless, policy uncertainty is still relatively high.

A more rigorous and sophisticated way of gauging to what extent the VIX is abnormally low given the current levels of political uncertainty is to compare the observed VIX with the VIX predicted by US and global indices of policy uncertainty. When this is carried out, we can see that, since July 2016, the VIX predicted by political factors vastly overestimates the actual volatility observed.

There are two other factors that are also presumably related to the decline in the VIX: macroeconomic and financial conditions. If we carry out the same exercise and compare the observed VIX with the VIX predicted by macrofinancial conditions,2 we can see that the predicted VIX is closer to the VIX observed over the past few months. For instance, the predicted VIX based on political uncertainty had a prediction error of 5.9 points in June compared with an error of just 2.86 points in the prediction made based on macrofinancial conditions.

If we look closely at the trend in the observed VIX and the predicted VIX in the second chart, it seems that, between 2003 and 2007, the predicted VIX based on policy uncertainty was relatively similar to the observed VIX while, since 2012, macrofinancial conditions have predicted a trend much more similar to that of the VIX. To check whether this is the case, we have divided the sample into three periods: from 2003 to 2007, from 2008 to 2011 and from 2012 to 2017. We have also analysed the policy, macroeconomic and financial factors that lie behind financial volatility. 3The findings leave no room for doubt: policy factors accounted for 74% of the explained variance in the VIX between 2003 and 2007 but only 12.5% between 2012 and 2017. The relative weight of macroeconomic factors and especially of financial factors was also greater between 2008 and 2017 than between 2003 and 2007. We should also note the decline in the explained variance of the VIX over the past few years. The explanatory power of political and macrofinancial factors was 76% between 2003 and 2007, and 89% between 2008 and 2011. But this figure was just 47% between 2012 and 2017. This suggests that factors unrelated to political uncertainty, macroeconomic variables or the index for financial conditions currently lie behind a larger percentage of the VIX variation.

These findings may look surprising at first sight but they become plausible when other elements are also taken into account. On the one hand, political uncertainty may have lost some of its influence on financial volatility because, as shown by the Chicago University economists Pastor and Veronesi,4 political news are now less reliable and policy signals have become noisier. The difficulty in interpreting political information accurately might have led investors to react less to political events even when there is greater uncertainty.

On the other hand, financial variables may have gained relative weight over political factors in the period 2008-2017 compared with 2003-2007 due to unconventional monetary policies (for instance, the first US quantitative easing programme, QE1, began at the end of 2008).
The Fed’s massive bond buying programmes have increased liquidity in the financial system, pushing up the price of some financial assets as well as reducing fears of sharp slumps in these prices, thereby decreasing volatility.5

Macrofinancial elements also seem to be related to the decrease in the explained variance of the VIX between 2012 and 2017. In particular, the recent increase in passive management funds6 could have been a relevant factor. These funds track a specific index and therefore reduce the capital bought and sold on a daily basis on the financial markets. One consequence could be that financial volatility has become less sensitive to certain macroeconomic and financial fluctuations.

1. When automatic increases in taxes were coupled with massive spending cuts by the US government to reduce the federal deficit.

2. The macroeconomic variables included are the US business sentiment index (ISM) and a measure of global macroeconomic volatility based on the index of economic surprises for the G-10. Financial conditions were measured using the financial index elaborated by the Federal Reserve of Chicago.

3. The formula for the lineal regression is as follows:

$$VIX_t=\beta\ast EPU_t+\gamma\ast CM_t\ast+\alpha\ast IFC_t+\varepsilon_t$$.Where EPUt is the vector of economic policy uncertainty indices by Baker, Bloom and Davis for the US and the world, CMt is the vector of macroeconomic variables detailed in note 2, and IFCt is the index for financial conditions. Lastly, εt is a random error term.

4. See Pastor, L. and Veronesi, P. (2017), «Explaining the puzzle of high policy uncertainty and low market volatility», VOX Column.

5. For more details, see Mallick, S., Mohanty, M. S. and Zampolli, F. (2017), «Market volatility, monetary policy and the term premium», BIS Working Papers.

6. The passive management of investment portfolios is an investing strategy, for bonds or equity, that replicattes the evolution of a specific index. In the US they account for almost half of the capital managed by investment funds and 14% of the stock market value.

Etiquetas
Politics
Volatility