Code Monkey home page Code Monkey logo

average's People

Contributors

abythell avatar catox0 avatar jonathanchristison avatar majenkotech avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

average's Issues

STDDEV function not proprely working

Hello,
I'm using this library with an Arduino Mega.
I defined the object so:

Average<int> avgintbuffer(intbuffer_size);

and then i push 4 values:

avgintbuffer.push(5);
avgintbuffer.push(5);
avgintbuffer.push(5);
avgintbuffer.push(5);
Serial.println(avgintbuffer.mean());
Serial.println(avgintbuffer.stddev());

I get as ouptut: 5 (mean), 2.5 (stddev)

The standard deviation should be 0....

Cumulative max number of samples?

I'm attempting to keep averages of temperature and humidity. I could do over 200 with a single Average. With two Averages initiated, if I specify more than 140 samples my program fails to run. It uploads and there aren't any errors. If I try to initiate a 3rd average with 140 samples it fails again. I didn't bother to find out what the max value for 3 Averages was, but if I set them to just 10 it works.

resize function

Hi,

I needed to able to set the size of the array while in the setup but the array had to be global... So I wrote a little void function to resize... It basically reset the array and resize the pointer... Which is what I needed I didn't care that it was a destructive resize... Anyway realloc should not be used too much it might get corrupted after a while... In my case I do it once in setup...

I have dip switches so the end user can select which averaging he wants for the displayed values...

Here is what I added, feel free to integrate it if you want...
template <class T> void Average<T>::resize(uint32_t size) { clear(); _size = size; _count = 0; _store = (T *)realloc(_store, sizeof(T) * size); _position = 0; // track position for circular storage _sum = 0; // track sum for fast mean calculation for (uint32_t i = 0; i < size; i++) { _store[i] = 0; } }

rollingAgerage?

The function rollingAverage(history_array, slice_count, value) doesn't seem to be installed...
There is no trace of it in Average.h

Bug with get

After 3 loops, the get is not working properly. As you can see on the photo, there is an index issue so the data is not red from the good array position. I found that because the min fonction was giving a wrong output
capture d ecran 2016-10-07 a 15 39 09

Compiler warning about signed/unsigned comparison

Compilation with strict code checking gives:

/tmp/arduino_build_131539/sketch/Average/Average.h:248:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (cindex >= _size) cindex -= _size;
                ^

Thus, line 247 of the get function should read uint32_t cindex = start + index; instead of int32_t.

Here is the fixed function:

template <class T> T Average<T>::get(uint32_t index) {
    if (index >= _count) {
        return -1;
    }

    int32_t start = _position - _count;
    if (start < 0) start += _size;
    uint32_t cindex = start + index;
    if (cindex >= _size) cindex -= _size;
    return _store[cindex];
}

Thanks for the code!

minimum() returns wrong minat value

Observe the code comments below to see the issue:

Average<int> ave(5);
void loop()
{
int minat = 0;
    ave.push(-4); // If this value is the minimum, minat=0
    ave.push(5); // If this value is the minimum, minat=4
    ave.push(5); // If this value is the minimum, minat=3
    ave.push(5); // If this value is the minimum, minat=2
    ave.push(5); // If this value is the minimum, minat=1
    Serial.print("min: "); Serial.println(ave.minimum(&minat));
    Serial.print("minat: "); Serial.println(minat);
}

The first value in the buffer is at 0, but then counts down from 4 to 1.

Average interference with I2C ?

Hello,
I recently found the Average class, and decided to try it out (to make my long program look shorter and easy to maintain).
It seem to have several nice features that I can use with thanks.

I replaced my several self built moving average (runs nicely, but not proof) with the Average class 'rolling' in several locations within my Arduino Mega.
Unfortunately, while it compiles nicely, in actual run with the Arduino I receive I2C "read nack on transmit of address". This error is also shown with previous version of my program that does not use the Average, and has no Average include, but problem is gone if I remove the Average.h file from the Arduino library.
In simple words: The pretense alone of the class Average (with the Wire class??) cause the problem

To me, analysis of the problem seems quite complex, thus before trying going deep into it (or abandoning the Average), I prefer asking the 'Average' experts.

Looks like there is some interference of the Average class and the Wire even if the Wire is not included, but is present in the lib. (There are unfortunately several versions of Wire)
I wonder why use 'get' and 'push' as Average commands, while those two words are common keywords that are used internally with many programs. Can this be the reason?

Here are my includes:

include "PID_v1.h"

include "Wire.h"

include "Streaming.h"

include "EEPROM.h"

include "LiquidCrystal.h"

include "Average.h"

Feature Request - Index number for Min and Max

Nice library. Thanks for sharing. I don't know if you're taking feature requests, but I thought I'd submit one anyway.

While tracking more than one Average, it would be nice to be able to lookup the corresponding value.

For example when tracking Temperature and Humidity I would be able to look at what the humidity was at the max temperature.

Predict Example

Hello,

I am wondering what is the value of the variable X in the predict function? (The parameter we pass)..

Say I have 3 values pushed to the Average storage.

Lets say: 1, 2 and 4

And I want to predict what value comes next given this set. What should I pass as X or as predict parameter?

Thanks in advance.

Multiple bucket allocation

When I tried to work with multiple buckets, like:

Average ave1(10);
Average ave2(10);
Average ave3(10);

sometimes (not allways, 98% of time works correctly) when calling to ave2.get(9) it gets the ave1(1) value instead of the ave2(9) value... it seems to be a problem with the memory allocation of the buckets.
Have you experiencied that?
Is it easy to solve?

Thanks!!

Example Question

I'm trying to understand the two variables from the example code:

    int minat = 0;
    int maxat = 0;

Any chance someone could explain what they do? Would be great to have this added as a comment to the example as well.
Thanks.

mode always gets the first number

I am getting wrong values for mode.

For example, for {4, 3, 3}, I am getting 4 for mode. It is as if, I am getting the first number for mode.

Here are a few examples with arrays of 3 and 4:

4.00 3.00 3.00
Mean: 3.33
Mode: 4.00

4.00 0.00 0.00
Mean: 1.33
Mode: 4.00
Smooth: 2.67

0.00 2.00 2.00
Mean: 1.33
Mode: 0.00
Smooth: 0.67

3.00 3.00 4.00
Mean: 3.33
Mode: 3.00
Smooth: 3.33

4.00 0.00 0.00 2.00
Mean: 1.50
Mode: 4.00

2.00 4.00 3.00 3.00
Mean: 3.00
Mode: 2.00

4.00 3.00 3.00 0.00
Mean: 2.50
Mode: 4.00

Please see below the code:

SmoothObject.ino.zip

Do you know if this is a bug or a result of my code? If it is a result of my code, I would appreciate hearing how to fix it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.