mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.0 Logistic
This commit is contained in:
parent
ef87a12f40
commit
2c54a7207f
27
libraries/Logistic/.arduino-ci.yml
Normal file
27
libraries/Logistic/.arduino-ci.yml
Normal file
@ -0,0 +1,27 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
- uno
|
||||
# - due
|
||||
# - zero
|
||||
# - leonardo
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
- rpipico
|
4
libraries/Logistic/.github/FUNDING.yml
vendored
Normal file
4
libraries/Logistic/.github/FUNDING.yml
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: RobTillaart
|
||||
|
13
libraries/Logistic/.github/workflows/arduino-lint.yml
vendored
Normal file
13
libraries/Logistic/.github/workflows/arduino-lint.yml
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
name: Arduino-lint
|
||||
|
||||
on: [push, pull_request]
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
compliance: strict
|
17
libraries/Logistic/.github/workflows/arduino_test_runner.yml
vendored
Normal file
17
libraries/Logistic/.github/workflows/arduino_test_runner.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
---
|
||||
name: Arduino CI
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
runTest:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
- run: |
|
||||
gem install arduino_ci
|
||||
arduino_ci.rb
|
18
libraries/Logistic/.github/workflows/jsoncheck.yml
vendored
Normal file
18
libraries/Logistic/.github/workflows/jsoncheck.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
name: JSON check
|
||||
|
||||
on:
|
||||
push:
|
||||
paths:
|
||||
- '**.json'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
pattern: "\\.json$"
|
||||
|
10
libraries/Logistic/CHANGELOG.md
Normal file
10
libraries/Logistic/CHANGELOG.md
Normal file
@ -0,0 +1,10 @@
|
||||
# Change Log Logistic
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.0] - 2024-01-03
|
||||
- initial version
|
21
libraries/Logistic/LICENSE
Normal file
21
libraries/Logistic/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2024-2024 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
64
libraries/Logistic/Logistic.h
Normal file
64
libraries/Logistic/Logistic.h
Normal file
@ -0,0 +1,64 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: logistic.h
|
||||
// AUTHOR: Rob.Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// DATE: 2024-01-03
|
||||
// PURPOSE: Arduino library to explore the logistic formula. (chaos, bifurcation)
|
||||
// URL: https://github.com/RobTillaart/Logistic
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define LOGISTIC_LIB_VERSION (F("0.1.0"))
|
||||
|
||||
// https://en.wikipedia.org/wiki/Feigenbaum_constants
|
||||
#define FEIGENBAUM 4.66920160910299067185320382046620161
|
||||
|
||||
|
||||
class Logistic
|
||||
{
|
||||
public:
|
||||
// rate = reproduction rate = 0.0 - 4.0
|
||||
// in = input population = 0.0 - 1.0
|
||||
Logistic(float rate = 2.0, float in = 0.5)
|
||||
{
|
||||
_rate = constrain(rate, 0, 4);
|
||||
_in = in;
|
||||
}
|
||||
|
||||
void setRate(float rate)
|
||||
{
|
||||
_rate = constrain(rate, 0, 4);
|
||||
}
|
||||
|
||||
float getRate()
|
||||
{
|
||||
return _rate;
|
||||
}
|
||||
|
||||
float iterate(float in)
|
||||
{
|
||||
// range check
|
||||
_in = constrain(in, 0.0, 1.0);
|
||||
_out = _rate * _in * (1.0 - _in);
|
||||
return _out;
|
||||
}
|
||||
|
||||
float iterate()
|
||||
{
|
||||
_in = _out;
|
||||
_out = _rate * _in * (1.0 - _in);
|
||||
return _out;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
float _rate;
|
||||
float _in;
|
||||
float _out;
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
93
libraries/Logistic/README.md
Normal file
93
libraries/Logistic/README.md
Normal file
@ -0,0 +1,93 @@
|
||||
|
||||
[![Arduino CI](https://github.com/RobTillaart/Logistic/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
|
||||
[![Arduino-lint](https://github.com/RobTillaart/Logistic/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Logistic/actions/workflows/arduino-lint.yml)
|
||||
[![JSON check](https://github.com/RobTillaart/Logistic/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Logistic/actions/workflows/jsoncheck.yml)
|
||||
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/Logistic.svg)](https://github.com/RobTillaart/Logistic/issues)
|
||||
|
||||
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Logistic/blob/master/LICENSE)
|
||||
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Logistic.svg?maxAge=3600)](https://github.com/RobTillaart/Logistic/releases)
|
||||
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/Logistic.svg)](https://registry.platformio.org/libraries/robtillaart/Logistic)
|
||||
|
||||
|
||||
# Logistic
|
||||
|
||||
Arduino library to explore the logistic formula. (chaos, bifurcation)
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
The logistic function is a function known from the chaos theories.
|
||||
It represents a model of e.g. how fast a rabbits reproduce and other processes.
|
||||
|
||||
The basic function is pretty simple
|
||||
```cpp
|
||||
// reproductionRate R = 0.0 - 4.0
|
||||
// in == 0.0 - 1.0 (think percentage of some maximum population)
|
||||
out = reproductionRate * in * (1 - in);
|
||||
```
|
||||
|
||||
For values of reproductionRate R
|
||||
- below 1 the function stabilizes goes to 0
|
||||
- between 1 and 3 the function stabilizes after a few dozen iterations.
|
||||
- between 3 and ~3.57 the stabilization jumps between 2, 4, 8 values (called bifucation)
|
||||
- see around R == { 3, 3.45, 3.54, 3.56, 3.57}
|
||||
- above 3.57 the function turns to chaos with some stability zones. At least visually.
|
||||
|
||||
There are a lot of (mathematical) interesting aspects to be found in the functions behaviour.
|
||||
|
||||
If you have ideas (or links) to that should be in this library, please open an issue.
|
||||
|
||||
|
||||
|
||||
#### Related
|
||||
|
||||
- https://en.wikipedia.org/wiki/Logistic_map
|
||||
- https://en.wikipedia.org/wiki/Feigenbaum_constants
|
||||
- https://www.vanderbilt.edu/AnS/psychology/cogsci/chaos/workshop/BD.html
|
||||
|
||||
|
||||
## Interface
|
||||
|
||||
```cpp
|
||||
#include "Logistic.h"
|
||||
```
|
||||
|
||||
- **Logistic(float rate = 2.0, float in = 0.5)** Constructor
|
||||
- rate = reproduction rate = 0.0 - 4.0
|
||||
- in = input population = 0.0 - 1.0
|
||||
- **void setRate(float rate)** set / change the reproduction rate.
|
||||
- **float getRate()** get the current rate.
|
||||
- **float iterate(float in)** make one iteration given a start value.
|
||||
- **float iterate()** make an iteration with the last calculated value.
|
||||
|
||||
## Future
|
||||
|
||||
#### Must
|
||||
|
||||
- improve documentation.
|
||||
- related links (youtube?)
|
||||
- add examples
|
||||
|
||||
#### Should
|
||||
|
||||
- Look for other "logistic functions"
|
||||
- elaborate the library
|
||||
- **stable()** checks delta between previous and current value.
|
||||
- **period()** tries to find a repeating period in the values?
|
||||
- **count()** iteration counter.
|
||||
|
||||
#### Could
|
||||
|
||||
- add unit tests
|
||||
- add graphics? => user task?
|
||||
|
||||
#### Wont
|
||||
|
||||
|
||||
## Support
|
||||
|
||||
If you appreciate my libraries, you can support the development and maintenance.
|
||||
Improve the quality of the libraries by providing issues and Pull Requests, or
|
||||
donate through PayPal or GitHub sponsors.
|
||||
|
||||
Thank you,
|
@ -0,0 +1,57 @@
|
||||
// FILE: Logistic_bifurcation.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/Logistic
|
||||
//
|
||||
// although build in plotter is not an XY plotter
|
||||
// it gives some idea.
|
||||
|
||||
|
||||
#include "Logistic.h"
|
||||
|
||||
Logistic L;
|
||||
float x = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
// Serial.println(__FILE__);
|
||||
// Serial.print("LOGISTIC_LIB_VERSION: ");
|
||||
// Serial.println(LOGISTIC_LIB_VERSION);
|
||||
// Serial.println();
|
||||
|
||||
float rate = 0.0;
|
||||
while (rate < 4.00)
|
||||
{
|
||||
// initialize
|
||||
rate += 0.01;
|
||||
L.setRate(rate);
|
||||
x = L.iterate(0.5);
|
||||
|
||||
// make many iterations
|
||||
// for (int i = 0; i < 100 + random(2); i++) // the random(2) gives something of a range
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
x = L.iterate();
|
||||
}
|
||||
|
||||
// display some values.
|
||||
Serial.println(x * 100, 6); // * 100 improves plotter range
|
||||
// x = L.iterate();
|
||||
// Serial.println(x * 100, 6); // * 100 improves plotter range
|
||||
// x = L.iterate();
|
||||
// Serial.println(x * 100, 6); // * 100 improves plotter range
|
||||
// x = L.iterate();
|
||||
// Serial.println(x * 100, 6); // * 100 improves plotter range
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
@ -0,0 +1,54 @@
|
||||
// FILE: Logistic_bifurcation_2.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/Logistic
|
||||
//
|
||||
// using multiple colors shows sort of proper bifurcation.
|
||||
|
||||
|
||||
#include "Logistic.h"
|
||||
|
||||
Logistic L;
|
||||
float arr[32]; // more is possible but hard to see.
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
// Serial.println(__FILE__);
|
||||
// Serial.print("LOGISTIC_LIB_VERSION: ");
|
||||
// Serial.println(LOGISTIC_LIB_VERSION);
|
||||
// Serial.println();
|
||||
|
||||
float rate = 0.0;
|
||||
while (rate < 4.00)
|
||||
{
|
||||
// initialize
|
||||
rate += 0.01;
|
||||
L.setRate(rate);
|
||||
L.iterate(0.5);
|
||||
|
||||
// make many iterations
|
||||
// for (int i = 0; i < 100 + random(2); i++) // the random(2) gives something of a range
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
L.iterate();
|
||||
}
|
||||
for (int i = 0; i < 32; i++)
|
||||
{
|
||||
arr[i] = L.iterate();
|
||||
Serial.print(arr[i] * 100, 6);
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
41
libraries/Logistic/examples/Logistic_demo/Logistic_demo.ino
Normal file
41
libraries/Logistic/examples/Logistic_demo/Logistic_demo.ino
Normal file
@ -0,0 +1,41 @@
|
||||
// FILE: Logistic_demo.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: demo
|
||||
// URL: https://github.com/RobTillaart/Logistic
|
||||
//
|
||||
// best viewed with plotter
|
||||
|
||||
|
||||
#include "Logistic.h"
|
||||
|
||||
Logistic L;
|
||||
float x = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
while (!Serial);
|
||||
// Serial.println(__FILE__);
|
||||
// Serial.print("LOGISTIC_LIB_VERSION: ");
|
||||
// Serial.println(LOGISTIC_LIB_VERSION);
|
||||
// Serial.println();
|
||||
|
||||
// set initial rate
|
||||
L.setRate(1.0);
|
||||
// set initial value
|
||||
Serial.println(0.1 * 100, 6); // * 100 improves plotter range
|
||||
x = L.iterate(0.1);
|
||||
Serial.println(x * 100, 6);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
x = L.iterate();
|
||||
Serial.println(x * 100, 6);
|
||||
delay(10);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
16
libraries/Logistic/keywords.txt
Normal file
16
libraries/Logistic/keywords.txt
Normal file
@ -0,0 +1,16 @@
|
||||
# Syntax Colouring Map For Logistic
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
Logistic KEYWORD1
|
||||
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
setRate KEYWORD2
|
||||
getRate KEYWORD2
|
||||
|
||||
iterate KEYWORD2
|
||||
|
||||
|
||||
# Constants (LITERAL1)
|
||||
LOGISTIC_LIB_VERSION LITERAL1
|
||||
|
23
libraries/Logistic/library.json
Normal file
23
libraries/Logistic/library.json
Normal file
@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "Logistic",
|
||||
"keywords": "chaos, bifurcation",
|
||||
"description": "Arduino library to explore the logistic formula. (chaos, bifurcation).",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Logistic.git"
|
||||
},
|
||||
"version": "0.1.0",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*",
|
||||
"headers": "Logistic.h"
|
||||
}
|
11
libraries/Logistic/library.properties
Normal file
11
libraries/Logistic/library.properties
Normal file
@ -0,0 +1,11 @@
|
||||
name=Logistic
|
||||
version=0.1.0
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library to explore the logistic formula. (chaos, bifurcation)
|
||||
paragraph=
|
||||
category=Data Processing
|
||||
url=https://github.com/RobTillaart/Logistic
|
||||
architectures=*
|
||||
includes=Logistic.h
|
||||
depends=
|
50
libraries/Logistic/test/unit_test_001.cpp
Normal file
50
libraries/Logistic/test/unit_test_001.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
//
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2024-01-03
|
||||
// PURPOSE: unit tests for the Logistic function
|
||||
// https://github.com/RobTillaart/Logistic
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
|
||||
// supported assertions
|
||||
// ----------------------------
|
||||
// assertEqual(expected, actual)
|
||||
// assertNotEqual(expected, actual)
|
||||
// assertLess(expected, actual)
|
||||
// assertMore(expected, actual)
|
||||
// assertLessOrEqual(expected, actual)
|
||||
// assertMoreOrEqual(expected, actual)
|
||||
// assertTrue(actual)
|
||||
// assertFalse(actual)
|
||||
// assertNull(actual)
|
||||
|
||||
|
||||
#include <ArduinoUnitTests.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Logistic.h"
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "LOGISTIC_LIB_VERSION: %s\n", (char *) LOGISTIC_LIB_VERSION);
|
||||
}
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
Logistic L;
|
||||
|
||||
assertEqual(2.0, L.getRate());
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
|
||||
// -- END OF FILE --
|
Loading…
Reference in New Issue
Block a user