Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logistic map and github actions script #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/config-name.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

name: Run all the tests for PRs

on:
[push, pull_request]

jobs:
run-tests:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run:
python -m pip install pytest numpy math
- name: Test with pytest
run:
pytest -sv
16 changes: 16 additions & 0 deletions log_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


def logistic_map(x, r):
x_next = r * x * (1 - x)

return x_next

def iterate_f(x,r,it):
it_vec = []
for i in range(it):
xi = logistic_map(x,r)
it_vec.append(xi)
x = xi
print(it_vec)

return it_vec
38 changes: 38 additions & 0 deletions test_log_map.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
import numpy as np
from log_map import logistic_map
from log_map import iterate_f
from math import isclose

@pytest.mark.parametrize("x,r,result",
[(0.1, 2.2,0.198),
(0.2, 3.4,0.544),
(0.75, 1.7, 0.31875)])
def test_log_map_single(x,r,result):
output = logistic_map(x, r)

assert isclose(output, result)

SEED = np.random.randint(0,20)

@pytest.fixture
def random_state():
print(f'using seed {SEED}')
random_state = np.random.RandomState(SEED)
return random_state

def test_convergence(random_state):
r = 1.5
x = random_state.rand()
result = 1/3
output = iterate_f(x,r,30)[-1]

assert np.isclose(output, result,atol=0.000001)

def test_orbit(random_state):
r = 3.8
it = 100000
x = random_state.rand()
output = np.array(iterate_f(x,r,it))

assert np.all(np.logical_and(output >= 0, output <= 1))