up

Python Sample Programs

Programs at these websites can be freely downloaded and used.

The constructer of these websites disclaims all responsibility.

The user takes responsibility for his/her usage.

Yasuharu Okamoto

 

Another Website-1, Website-2, Website-3

 

 

Beginning Python

It is easy to install Python in Windows.

 

 

Choice of Python

When you want to use a version other than the latest one of Python, you can choose the version.

Two ways of choice of Python are explained.

 

 

Python on Anaconda

For some modules, a version of the module must be selected for the version of the Python.

These selection are automatically done by Anaconda.

 

 

Easy Ways to PyStan and PyMC3 in Windows

PyStan (the Python interface for Stan) and PyMC3 can be used easily in Windows,

when they are installed in Anaconda, which can be installed easily.

 

 

On PyStan 2.18 /Windows Errors (2018.10.28)

 

 

Python 3 on CentOS 7

An easy way to install Python3 on CenOS 7

 

 

Painting Figures in Python

A simple Python script of painting figures is presented as an example.

 

 

Calling Python Script from C/C++ Program

Python script is called from C/C++ program and

Python script calls a command.

 

 

A Simple Python Script of a Digital Clock

A simple Python script of a digital clock is presented.

 

 

Common Quantification of Categorical Data

This quantification gives numerical values to categorical items, which can be used with other numerical items in various analysis.

That is, this quantification can be used as data preprocessing in machine learning.

 

 

One Hot Encoding and Common Quantification

One Hot Encoding and common quantification are methods to preprocess categorical attributes (variables).

One Hot Encoding treats values of categorical attributes individually and is used in machine learning.

On the other hand, common quantification treats values of categorical attribute from the point of view of maximization of the variance of the attribute.

Comparison of the two methods is presented with the programs.

 

 

Principal Components Analysis with Rotation

Principal components analysis is interpreted from the point of view of

orthogonal projection of the data space onto its subspace.

 

 

Demonstration of The Curse of Dimensionality

Python scripts, which show the curse of dimensionality, were presented.

 

 

3D-Drawing of a Bivariate Normal Distribution

A simple script for drawing a bivariate normal distribution was prepared.

 

 

3D-Drawing of a Binomial Distribution in Bayesian Statistics

A joint distribution of probability parameter and frequency data

was displayed as a 3-D graphic image.

 

 

Drawing a Graph of Fisher Information Functions in IRT

A graph of item information functions and the test information function was drawn by a simple program in Python.

 

 

Random Number Generator

LfEcuyer, et al.fs (2002) algorithm of random number generation has long period, about 2**191,

and is easily partitioned into subsequences, each of which has practically sufficient long period.

Their algorithm can be easily implemented purely in Python.

 

 

MCMC with Multiprocessing in Python

Multiple Markov chains are run concurrently using multiprocessing in Python

 

 

Pickle, Stan, and Python

We can save much time by storing a Stan model and sampling results by a Stan model

using the package pickle of Python.

 

 

Pickle and PyMC3

Sampling data by PyMC3 can be saved in a file using the pickle library.

You can read out this file to use in the following analysis.

 

 

Variation of Posterior Distribution: Simulation with PyStan using pickle

Posterior distribution in Bayesian analysis depends on the data, which is sampled randomly from a population.

So, posterior distribution varies from a sample to another one. This random variation of posterior distribution was investigated by simulation.

 

 

Bayesian Point Estimates and Highest Density Intervals

Relations of highest density intervals (HDIs) and the three estimates, mean, median, and MAP estimate, were investigated by simulation.

 

 

Stan Scripts for Estimation of JND and PSE

Stan scripts for analyses of data from 2AFC experiments

which use more than two response categories were developed.

A Stan script for a usual method using binary judgment was also developed.

 

 

Bayesian Estimation of JND and PSE

Psychometric functions are estimated by Bayesian analysis of discrimination data from

two-alternative procedure (the standard method in psychophysics),

three-alternative procedure, which is proposed by some authors and allows

gdonft knowh judgment, or four-alternative procedure, in which gprobableh judgments

are allowed. Just noticeable difference (JND) and the point of subjective equality (SPE)

are estimated based on the psychometric functions.

 

 

Bayesian Analysis in Signal Detection Theory (SDT)

Python scripts using Stan (PyStan) were developed for analyses of

Data in Signal Detection Theory. The programs analyze data from a Yes/No experiment or

data from that using a rating method.

 

 

A Stan Script for IRT of Binary Items

A logistic model for binary items in Item Response Theory was employed

to develop a Stan script, which was used by a Python script.

 

 

A Stan Script for IRT of Polytomous Items

The graded response model for polytomous items was employed

to develop a Stan script, which was used by a Python script.

 

 

Posterior Probability of gEffectiveh as a Function of the Power of the Test

How the probability of gEffectiveh changes

after the results of the statistical test shows that geffectiveh is significant

is dependent on the power of the statistical test.

 

 

Linked Objects in Python

Variables in Python are references to objects, so they can be used like pointers in C/C++.

A sample program, in which objects are linked using pointer-like variables, is written in Pyhton.

 

 

Sample Programs using Stan in Python

Simple programs in Python for Bayesian analysis of univariate and multivariate data were written

using PyStan, the Python interface to Stan.

 

 

Sample Programs for PyStan 3

Simple Stan scripts for a normal distribution and a bivariate normal distribution are presented.

Scripts are written in PyStan 3.

 

 

Continued on the Next Website

 

Memorandum