Probnet: Geometric Extrapolation of Integer Sequences with error prediction

[ ai, forecasting, library, math, mit, sequences ] [ Propose Tags ]

Solves thousands of math functions just in one, Probnet . A new way to calculate and predict results from the data source without knowing the function who composes a data set. Aplications in math, AI, infromation compresion when the data source follows math patterns. Describe the 100 % accuracy functions in 3 fraction parameters and 1 parameter for the index.

[Skip to Readme]


Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Versions [RSS],,,,
Change log
Dependencies base (>=4.11 && <=4.15) [details]
License MIT
Copyright Cobalt Technologies S.A
Author Vicent Nos
Category Math, AI
Home page
Uploaded by vnos at 2021-06-02T04:29:59Z
Downloads 819 total (15 in the last 30 days)
Rating 2.25 (votes: 2) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2021-06-02 [all 1 reports]

Readme for Probnet-

[back to package description]



ghci Probnet.hs

> probnet 1 [1,2,3,5,8]


Geometric Extrapolation of Integer Sequences with error prediction

The problem

In many situations, we have finite sequences of integer values, and we would like to predict which would be the next one, or the next several ones, without the knowledge of the mathematical definition of the sequence.

A solution based just on the available data has applications on the following areas, among others:

  • time series forecasting
  • uncertain prediction
  • data modeling
  • risk modeling
  • data encoder decoder

A geometric way of prediction

Simple base solution

We start with a simple geometric solution, that is to calculate the ratio (quotient) of the last value relative to the previous one, and apply it to the last value to calculate the next one.

For example, if we have some values of the Fibonacci sequence:

fibo = [1,2,3,5,8,13]

we get the ratios of each element relative to its previous one:

percents fibo

Then, we predict the next element as the product of the last element by the last ratio:

13 * 1.625 = 21.125

Improving the result with the prediction of the error

We can get the predicted value for each subsequence of initial values of the original sequence.

drop 2 (inits fibo)

fmap predict1 it

Then, we can calculate the difference between the predicted value and the real value. This way, we get a sequence of the errors, and we can calculate the predicted value of the next error, wich we will add to the simple prediction, notably improving the result.

err = zipWith subtract it (drop 2 fibo)

predict1 it

21.125 - 0.1333333333333331 = 20.991666666666667

We round the result to get the integer predicted value.

Sequences with quasi-cyclic pattern

When a sequence is not monothonic, we assume that it has a repetitive pattern, so that the ratio used for prediction will be the one of the element whose value is closest to the last element.

For example, in the next sequence, the value closest to the last one is the first 3, and the ratio of that position is 4/3, so the predicted value will be 3*(4/3):

percents [1,2,3,4,5,1,2,3,4,1,2,3]

predict1 [1,2,3,4,5,1,2,3,4,1,2,3]

Recursive layers of predictions

Once we have predicted the next value of a sequence, we can append it to the original sequence and predict another element. We can do this as many times as we want. We call "layers" to the number of recursions. Then, if we apply 3 layers to our fibonacci secuence fib = [1,2,3,5,8,13], we get 3 more values:

probnet 3 fibo

Problems and limitations

The geometric way, that is, a way based on ratios of values, can only be valid for non-zero values, and is not suitable for sequences with negative and positive values. In that case it should be more appropiate the use of a usual diferential method, which can be very simmilar to the one presented here, but using diferences of elements instead of quotients of elements.

The case of zero values is not solved here. The function will just return an error if any element is 0.

Tecnical details

Data types

The type signature of the function is such that any RealFrac data type can be used for the values of the elements in the input sequence. The internal calculations will be done in that data type, preserving the precicion of it.

For example, if the type is a 32 bit Float, the calculus would be made with about 21 decimal digits of precision, but if the input elements are Rational, the intermediate calculus would preserve infinite precision, until the rounding for the Ìntegeroutput. That is the reason for importingData.Ratio`.

fibo = [1,2,3,5,8,13 :: Float]
predic1 fibo

fibo = [1,2,3,5,8,13 :: Rational]
predict1 fibo
169 % 8

It also implies that the input sequence can not be of any Integral type, it must be previously converted to a RealFrac type by using, for example, fromInteger conversion function. It is done this way on the testing file test-probnet.hs.

Arithmetic equivalent method

It can be noticed that an arithmetic, instead of geometric, method for the extrapolation can be coded by just changing the quotient sub-function in the percentsfunction by the standardsubtract, and the product (*) in the predict1` function by addition (+).

Such method would not require that every element in the sequence be different than 0, and the method would be suitable for sequences with negative and positive values.


The file test-probnet.hs contains a function testoeis to bulk testing the function probnet against a range of OEIS sequences, giving the numbers after the 'A' on the OEIS sequence ID.

testoeis 1 20

The testing is made using just the first 10 values for predicting the 11 one, and comparing it with the real 11th element, counting it as valid when both, predicted and real, are equal.


sequence = [1,2,3,5]

f1(x,y) =  (x) / y

d1 = f1 (3,2)

d2 = f1 (5,3)

m = last sequence (5)

n = last $ last sequence

-- Next Out Sequence

fnos (m,n,d1,d2) = round ( ( ( n * d1 ) - m ) + ( m * d2  ) )

Example :

round $ ((3*1.66)-5) + (5*1.6) = 8 

Author - Vicent Nos Ripolles

Dev Pedro S

Dev Enrique S

All rights are reserved for commercial purposes of any derivatives of this document and source code.