{"id":13782136,"url":"https://github.com/ivanseidel/Gaussian","last_synced_at":"2025-05-11T15:32:13.741Z","repository":{"id":9622625,"uuid":"11550251","full_name":"ivanseidel/Gaussian","owner":"ivanseidel","description":"Library that makes Gaussian work easy to use with C++ and Arduino","archived":false,"fork":false,"pushed_at":"2023-03-26T18:38:21.000Z","size":211,"stargazers_count":52,"open_issues_count":4,"forks_count":12,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-18T21:26:23.859Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivanseidel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-20T17:09:13.000Z","updated_at":"2025-02-03T14:46:03.000Z","dependencies_parsed_at":"2024-08-03T18:12:45.916Z","dependency_job_id":null,"html_url":"https://github.com/ivanseidel/Gaussian","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2FGaussian","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2FGaussian/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2FGaussian/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivanseidel%2FGaussian/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivanseidel","download_url":"https://codeload.github.com/ivanseidel/Gaussian/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253588657,"owners_count":21932296,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T18:01:33.276Z","updated_at":"2025-05-11T15:32:13.390Z","avatar_url":"https://github.com/ivanseidel.png","language":"C++","readme":"# Gaussian\n\nThis library was developed targeting **`Arduino`** applications. However, works just great with any C++.\n\nThe use of Gaussians is really hard because requires a deep understanding about complex math.\n\n**Not anymore.** We have done it for you, fell free to use the fully-implemented class of `Gaussian`.\n\nDo you want to do a [Moving Average](https://en.wikipedia.org/wiki/Moving_average)? `GaussianAverage`\nis just what you are looking for. Simple or with Gaussians, it's already implemented for you.\n\nFind out more about Gaussians here: [Wikipedia::Gaussian Function](http://en.wikipedia.org/wiki/Gaussian_function).\n\n\n## Installation\n\n1. [Download](https://github.com/ivanseidel/Gaussian/archive/master.zip) the Latest release from gitHub.\n2. Unzip and modify the Folder name to \"Gaussian\" (Remove the '-version')\n3. Paste the modified folder on your Library folder (On your `Libraries` folder inside Sketchbooks or Arduino software).\n4. Download and Install [LinkedList class](https://github.com/ivanseidel/LinkedList) as well, if you are going to use `GaussianAverage` class. \n5. Restart the Arduino Software\n\n## Getting started\n\n### `Gaussian` class\n\nA class that contains a `mean` and a `variance` attribute.\n\nAlso contains methods to do sums with others `Gaussians`.\n\n#### To declare a Gaussian object:\n```c++\n// Simple Gaussian initialization and instantiation\nGaussian myGaussian = Gaussian(mean, variance);\n\n// This will declare a Gaussian with mean = 0 and variance = MAX_VARIANCE (A really big value)\nGaussian myGaussian = Gaussian();\n\n// This will do the same as above\nGaussian myGaussian();\nGaussian myGaussian(0);\n```\n\nDealing with `mean` is very easy. You can either access it direcly (attribute `mean`),\nor change it with the methods `move` and `setMean`. Both methods returns the `self`\nGaussian object, allowing you to do actions consecutively in one single line.\n\n#### Set, Change and get `mean` values\n```c++\n// Set or Get the attribute direcly to the object\nmyGaussian.mean = 10;\n\n// Increase the mean by `x`\nmyGaussian.move(10);\n\n// Set to 10 and move by -10\nmyGaussian.setMean(10).move(-10);\n```\n\nWhen dealing with the `variance`, you can also do the same as the `mean`. Access it direcly from\nthe object, or use the methods `vary` and `setVariance` to change the `variance`.\n\n#### Set, Change and get `variance` values\n```c++\n// Set or Get the attribute direcly to the object\nmyGaussian.variance = 4;\n\n// Increase the variance by `y`\nmyGaussian.vary(3);\n\n// Set to 3 and then vary 10 more\nmyGaussian.setVariance(3).vary(10);\n```\n\nOk, now that we can change both `mean` and `variance`, we can now go to the next step: Summing Gaussians.\n\nIt's already implemented all the math to do that, and it's nos so hard to understand it, after resuming\nsum of Gaussians to 'sum of pondered values'.\n\nThe operators **+, +=, =** works just good with the class `Gaussian`.\n\n#### Sum, Set and do Math with Gaussians\n```c++\nGaussian g1 = Gaussian(0, 10);\nGaussian g2(10, 10);\n\n// Simply sum both of them (the + method is overloaded on the class)\nGaussian result = g1 + g2;\n\n// Or do like this\nresult = g1;\nresult += g2;\n```\n\nThere are also two methods very usefull for plotting and generating normal distributed random values.\n\nCheck the examples `GaussianUniformPlot` and `GaussianRandomPlot`\n\n#### Plotting Gaussians and randomizing values\n```c++\n// In case you want to find out the probability of 'x' of the Gaussian,\n// make use of the plot(x) method.\nGaussian myGaussian(3, 5.4);\n\ndouble Y1 = myGaussian.plot(3);\ndouble Y2 = myGaussian.plot(7.3);\n\n// Also, if you want to generate a normaly distribute value for the\n// given Gaussian, make use of the random() method.\n\n// This will generate a random value, normaly distribute around the mean\ndouble myRandomX = myGaussian.random();\ndouble otherRandomX = myGaussian.random();\n```\n\n============================\n\n### `GaussianAverage` class\n\nThis class provides a simple but really powerfull filter called [Moving Average](https://en.wikipedia.org/wiki/Moving_average).\n\nIt's an average of the last `n` values, but using `Gaussians` to incorporate the power of uncertainty.\n\nYou can also use it as a simple `Moving Average` by setting the `variance` to a fixed value, or just not\nsetting it (The default value when a Gaussian is created is really High, and is a constant).\n\nAlso, `GaussianAverage` class EXTENDS from `Gaussian`. Instead of calculating only the average (mean), you have access\nto the variance as well.\n\n**ATTENTION: This class REQUIRES [LinkedList class](https://github.com/ivanseidel/LinkedList) as well. It MUST be included BEFORE `GaussianAverage`.**\n```c++\n#include \u003cLinkedList.h\u003e\n#include \u003cGaussianAverage.h\u003e\n```\n\n#### To declare a `GaussianAverage` object\n\n```c++\n// The default number of samples is 4\nGaussianAverage myAverage = GaussianAverage();\n\n// If you want to change it pass to constructor\n// 30 samples will be stored\nGaussianAverage myAverage = GaussianAverage(30);\n\n// The same as above\nGaussianAverage myAverage(30);\n```\n\nNow that we have our class instantiated, let's proceed to add Values (or Gaussians) to it.\n\nThere are two main ways to add values to the `Average`. Using the `sum(Gaussian)` method, or `+=` overloaded operator.\n\n#### To add values to the Moving Average just use the operator `+=`\n```c++\n// Add it through the add method\nmyAverage.add(Gaussian(32,20));\nmyAverage.add(myGaussian);\n\n// Add it with the overloaded operator +=\nmyAverage += Gaussian(32, 20);\nmyAverage += myGaussian;\n\n// You can also add an double/integer to it\n// (note that the Variance will be always the same, and very HIGH)\nmyAverage += 32;\nmyAverage += 70;\n```\n\nOk, we have created and added... What is missing? Yes, Process.\n\nThe process of calculating the average is not done every time you add something new (you migth want\nto add three samples before calculating). So, to calculate it you can use the method `process()`.\n\nOnce you have processed, the values of the `mean` and `variance` will be stored inside the object.\nNote that `process` method returns the `self` object.\n\nTo minimize the CPU usage, we have implemented a cache detector. If you use the method `process` more\nthan once before adding something new, the new average will not be calculated.\n\n#### Process the new Average\n```c++\n// This will run the calculation and store the result inside the myAverage object\n// (remember that it's also a Gaussian!)\nmyAverage.process();\n\n// Or perhaps, you want to save it\nmySavedAverage = myAverage.process();\n\n// Or you want to process, change it, and then save\nmyAverage.process();\nmyAverage.vary(30).move(10);\n\nmySavedAverage = myAverage;\n```\n\n------------------------\n\n## Library Reference\n\n### `Gaussian` class\n\n- `double` `Gaussian::mean` - Mean of the Gaussian.\n\n- `double` `Gaussian::variance` - Variance of the Gaussian.\n\n- `Gaussian::Gaussian(double _mean = 0.0, double _variance = MAX_VARIANCE)` - Constructor.\n\n- `Gaussian` `Gaussian::setMean(double _val)` - Set the mean to _val.\n\n- `Gaussian` `Gaussian::move(double _val)` - Adds _val to the mean.\n\n- `Gaussian` `Gaussian::setVariance(double _val)` - Set the variance to _val.\n\n- `Gaussian` `Gaussian::vary(double _val)` - Adds _val to the variance.\n\n- `double` `Gaussian::plot(double x)` - Returns the probability of 'x'.\n\n- `double` `Gaussian::random()` - Returns a random normaly distributed value.\n\n- `void` `Gaussian::operator=(Gaussian _gaus)` - Copies the mean and variance to current object.\n\n- `Gaussian` `Gaussian::operator+(Gaussian _gaus)` - Sum gaussians and returns the new Gaussian.\n\n- `void` `Gaussian::operator+=(Gaussian _gaus)` - Sum gaussians and saves it to itself.\n\n- **protected** `Gaussian` `sum(double _mean, double _variance)` - Return the sum of itself with _mean and _variance.\n\n=======================\n\n### `GaussianAverage` class\n\n- `GaussianAverage::GaussianAverage(int _n = 4)` - Constructor. n = number of samples to hold.\n\n- `void` `GaussianAverage::add(Gaussian g)` - Add the Gaussian g to the LinkedList.\n\n- `void` `GaussianAverage::operator+=(Gaussian _gaus)` - Add the Gaussian _gaus to the LinkedList.\n\n- `void` `GaussianAverage::operator+=(double _mean)` - Add a new Gaussian with mean _mean to the LinkedList.\n\n- `Gaussian` `GaussianAverage::process()` - Calculate the average Gaussian and returns it.\n\n- **proteced** `LinledList\u003cGaussian\u003e` `GaussianAverage::*gaussians` - Pointer to linked list that will hold the latest Gaussians.\n\n- **proteced** `int` `GaussianAverage::n` - Number of samples to hold.\n\n- **proteced** `bool` `GaussianAverage::isCached` - Flag that indicates if a process() MUST be done.\n\n- **proteced** `Gaussian` `avg` - Only a temporary helper used by process().\n\n----------------------------","funding_links":[],"categories":["Libraries"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanseidel%2FGaussian","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivanseidel%2FGaussian","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivanseidel%2FGaussian/lists"}