Skip to main content

Introduction

This repository aims to model and uncover the properties of all kinds of stochastic processes (processes that are based on some kind of underlying phenomenon like a coin toss for which we can't know the outcome for sure).

Some of these are taken from the book, Introduction to probability models by Sheldon Ross.

The best way to demonstrate the capabilities of this library is to describe some stochastic processes it can model and show how to use it to extract some of their properties.

Installation

To install the library, run (pyray was taken on pypi):

pip install stochproc

Make sure you have all the requirements (requirements.txt) installed. If not, you can run:

pip install -r requirements.txt

Alternately, you can fork/download the code and run from the main folder:

python setup.py install

Machine reliability

Let's say we start up a machine. It stays up some random amount of time before succumbing to failure. The amount of time it stays up is a random variable. This variable models the mean time between failures.

And once the machine is down, it takes a certain amount of time to get repaired. This is the mean time to repair.

The question is at any time t, what is the probability the machine is up and running?

Chapter 11 of [1] provides a closed form. However, we want to validate this with simulation.

from stochproc.reliability.machinerepair import *

for i in range(10):
	probs = []
	stds = []
	for t in range(1,100):
		prob, std = updown(t)
		probs.append(prob)
		stds.append(std)
	plt.plot(np.arange(1,100), probs,alpha=0.4,color='pink')

xs = np.arange(1,100)
plt.plot(xs, closed_form(xs),color='red')
plt.xlabel('Time')
plt.ylabel('Reliability of system')
plt.show()

This leads to the following plot.

Image formed by above method

Coin toss sequences

Let's say you and I start tossing fair coins. What is the probability you'll reach three consecutive heads before I reach two consecutive heads? What about in general you reaching (n+1) consecutive heads before I reach n consecutive heads?

from stochproc.competitivecointoss.smallmarkov import *

ns = np.arange(2,15)
win_probs = []
for n in ns:
    # The losing markov sequence of coin tosses that needs (n-1) heads.
    lose_seq = MarkovSequence(get_consecutive_heads_mat(n))
    # The winning markov sequence of coin tosses that needs n heads.
    win_seq = MarkovSequence(get_consecutive_heads_mat(n+1))
    # If you multiply the two sequence objects, you get the probability
    # that the first one beats the second one.
    win_prob = win_seq*lose_seq
    win_probs.append(win_prob)

plt.plot(ns, win_probs)

This leads to the following plot:

Image formed by above method

Release files for stochproc 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for stochproc 0.0.10
File Interpreter ABI Platform
stochproc-0.0.10-py3-none-any.whl Python 3 none any Details

Release files / stochproc-0.0.10-py3-none-any.whl

Download URL stochproc-0.0.10-py3-none-any.whl
Size 60.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5b3c773b596cfe2177943f2b4bc1778decff790c2adbb26705281afb8fd33f37
BLAKE2b-256 checksum
How to use checksums
0c963bdfd56cd08416fa0f1ab8d233258c846d35884ccf3d62613d8d75f72bb6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0.post20200210 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

Release history Release notifications | RSS feed

This release

0.0.10 This release

1 release file

0.0.9

3 release files

0.0.8

2 release files

0.0.7

3 release files

0.0.6

3 release files

0.0.5

3 release files

0.0.4

3 release files

0.0.3

4 release files

0.0.2

1 release file

0.0.1

1 release file

0.0.0

4 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page