[PYTHON] Create a poisson stepper with numpy.random

script

--Create a time series with Steps to test the Step detection algorithm --Add Gaussian noise to each point in the time series (conscious of single molecule experiment) --Pick up values according to probability distribution with numpy.random --Window average is easy if you use slices

poisson_stepper.py


#!/usr/bin/python

import numpy as np
import matplotlib.pyplot as plt

# Parameters
velocity = 60.0 # [nm/sec]
step_size = 50.0 # [nm]
k = velocity / step_size # decay constant for exponential distribution
dt = 1.0e-4 # [sec] time step for simulation
n_step = 10
sigma = 3.0 # [nm] amount of noise added to data
time_resolution = 0.01 # [sec]
n_data_averaged = int(time_resolution / dt)

# Produce trajectory
trajectory = []
for i in range(n_step+1):
    trajectory += [i*step_size]*int(np.random.exponential() / dt)

# Average data
trajectory = [np.average(trajectory[i:i+n_data_averaged]) + np.random.normal(scale = sigma)
              for i in range(0, len(trajectory), n_data_averaged)]

# Plot
plt.plot(trajectory)
plt.xlabel("time")
plt.ylabel("position")
plt.savefig("trajectory.png ")

Calculation result

trajectory.png

Recommended Posts

Create a poisson stepper with numpy.random
Create a homepage with django
Create a heatmap with pyqtgraph
Create a directory with python
Create a virtual environment with Python!
Create a file uploader with Django
Create a Python function decorator with Class
Build a blockchain with Python ① Create a class
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Create a GUI app with Python's Tkinter
Create a large text file with shellscript
Create a star system with Blender 2.80 script
Create a virtual environment with Python_Mac version
Create a VM with a YAML file (KVM)
Create a simple web app with flask
Create a word frequency counter with Python 3.4
Create a Connecting Nearest Neighbor with NetworkX
Create a web service with Docker + Flask
Create a private repository with AWS CodeArtifact
Create a car meter with raspberry pi
Create a devilish picture with Blender scripts
Create a matrix with PythonGUI (text box)
Create a graph with borders removed with matplotlib
Create a frame with transparent background with tkinter [Python]
Create a GUI executable file created with tkinter
Create a game UI from scratch with pygame2!
Create a PDF file with a random page size
Create a virtual environment with conda in Python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
Create a bulletin board with Heroku, Flask, SQLAlchemy
Create a dashboard for Network devices with Django!
Create a matrix with PythonGUI (tkinter combo box)
Create a color bar with Python + Qt (PySide)
Steps to create a Twitter bot with python
Create a decision tree from 0 with Python (1. Overview)
Create a color-specified widget with Python + Qt (PySide)
How to create a multi-platform app with kivy
Create a one-file hello world application with django
Create a Photoshop format file (.psd) with python
Create a cylinder with open3d + STL file output
Create a "Hello World" (HTTP) server with Tornado
Create a translation tool with the Translate Toolkit
Create a table of contents with IPython notebook
Create a Django schedule
Create a Python module
A4 size with python-pptx
Try to dynamically create a Checkbutton with Python's Tkinter
Create a virtual environment with Anaconda installed via Pyenv
[Python] Create a ValueObject with a complete constructor using dataclasses
Create a Todo app with the Django REST framework
Why not create a stylish table easily with Python?
Create a python development environment with vagrant + ansible + fabric
code-server Online environment (2) Create a virtual network with Boto3
Create a chatbot that supports free input with Word2Vec
Create a Todo app with Django ③ Create a task list page
Create a batch of images and inflate with ImageDataGenerator
Create a tweet heatmap with the Google Maps API
Create a random number with an arbitrary probability density