codesimian
Class SelfPredictingPrimeHashingNumberList

java.lang.Object
  extended by codesimian.CS
      extended by codesimian.DefaultCS
          extended by codesimian.SelfPredictingPrimeHashingNumberList
All Implemented Interfaces:
CodeSimian, java.io.Serializable

public class SelfPredictingPrimeHashingNumberList
extends DefaultCS

THIS CLASS IS NOT FINISHED.

The purpose of this algorithm is to play realtime audio from any subset of a compressed file, and for each possible subset to predict the entire audio a little differently. It will not matter which individual floats from the compressed file you load into memory, any subset of single floats from any set of indexs (in array bounds) can approximate the entire original audio data. Use this to dynamicly choose which parts of the compressed file to load into memory at a time, chosen by which were most needed to predict the values (-1 to 1) of audio that were requested. Many times per second, load many new floats from the compressed file, and remove many floats from memory, changing which subset of floats is loaded into memory but keeping the same size.

Example: 500,000 floats in memory and 5,000,000 floats in a file waiting to be loaded and 50,000,000 floats in the original audio data. The MP3 file format can also do 10:1 compression on disk, but it cant do 100:1 (varies depending on quality) in memory.

Use that different set of floats to better predict the new values requested (of the original audio data). Predict which indexs (containing predictions of predictions... of audio data) will be requested by which indexs were requested recently.

------------------ALGORITHM:------------------

Start with a float[] array containing numbers between -1.0 and 1.0, representing a sequence of audio samples.

A different list (same size as the float[] array) contains unique PRIME numbers, each number's value at least 100 times bigger than the float[] array's size (for good hashing).

Each number in the float[] array is paired with one of the prime numbers.

Each index in the float[] array is approximately a prediction derived from the values at many of the other indexs.

Each index is paired with a distribution of its prime number hashing over index quantity and divided by index quantity to give a set of numbers all between 0 and 1.

Values in the float[] array should slowly change so that any set of other indexs predicts them better.

The result of this change is that you can approximate any index by using any set of other indexs, and the more indexs you have, the better you can predict others.

This algorithm is a form of LOSSY COMPRESSION (not limited to but designed for: AUDIO).

By reordering the prime numbers (so each pairs with a different index than before), you can find a float[] array that predicts itself better (and still is similar to the original audio data).

By adjusting some floats in the array more or less than the others eacy cycle, the float[] array will learn differently therefore will become a slightly different array.

When the float[] array has been through enough cycles, you can choose any arbitrary subset of floats and use them to predict any arbitrary subset of floats from the uncompressed original audio data. Save this subset of floats as the compressed file.

It is easy to predict the distribution of 1 prime number hashed over array length divided by array length. For the next biggest weight, add the prime to the current index and wrap around array length. For the next smallest, subtract and wrap. It would work better to use the square-root of [the index divided by array length] instead of index divided by array length because influence of indexs on other indexs would be more localized, and much less influence from/to the majority.

Save the whole (or part of) changed audio data to a file. Load any part of the audio data by predicting it based on which parts of the changed data are currently in memory (less than all of it). Using the prediction described above, predict, then predict based on those predictions, and form a small prediction-tree... to more accurately predict the root of the tree. Using this method, you can get more accurate numbers when predicting from a small part of the compression.

After the compressing starts, the prime numbers are never reordered, and should be saved in any file that contains a float[] array derived from those numbers.

The advantage of this algorithm for lossy audio compression is that you can decompress any part of the audio from any subset of the compressed file. You could take single floats from random places in the file and use them to predict any of the original audio data. All floats are part of all original audio data, relative to an exponent (2? 3? 6.7?) and prime number hashing.

To do the next cycle, for each index, use all (or the most-influencing subset calculated by prime numbers), to calculate the value of that index. Compare it to its current value. Modify it to be a little closer to the predicted value. After you do that for all indexs, the array is ready to predict itself and modify itself again. Each time it becomes more distorted and more compressed and each moment of sound is spread more through the whole array.

For each index x, the sum of all weight(x,y) for all indexs y, should equal 1 (and none may be negative). The final value at each index is a weighted sum of predictions of other indexs.

Combine this algorithm (above) with the neural network for natural-language and compiling I'm building 8/06???

I know it will later be better to use doubles and longs, but for now I have chosen floats for the audio data and ints for the primes. This is necessary to compress smaller than MP3s, which use 16-bit numbers.

THIS IS A COMPLEX ALGORITHM. THIS CLASS IS NOT FINISHED, BUT THE JAVADOC PROBABLY CONTAINS EVERYTHING YOU NEED TO BUILD IT (BUT NOT ORGANIZED WELL). 8/06

--------------------FILE:---------------------
For better compression in the file, maybe the float[] array should instead be saved as 24 bit unsigned ints and divided by 2^24 to become a float between 0 and 1 in memory. Or maybe use less bits per number because normal audio is only 16 bits per number. If you use anything other than the same list of prime numbers every time, you need to save the primes in the file with the floats. Use ints (32 bits) for primes, or for more efficiency, use a few less bits. Create a header which tells the sizes of: the header, the float section, and the int section. Or pair one float and one int and repeat? Many possible ways to store a file...

See Also:
Serialized Form

Field Summary
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, FUEL, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER
 
Constructor Summary
SelfPredictingPrimeHashingNumberList()
           
 
Method Summary
 java.lang.String description()
          a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for.
 double DForProxy()
          modify data[] 1 cycle farther, to predict itself better.
 byte isIllusion(int index)
          everything is an illusion.
 java.lang.String keyword()
          For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
 int minP()
          For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.
 CS P(int index)
          WARNING: if add CSs then delete them, they are still in the param[] array and can be returned in this function, despite them being out of valid range: index at least countP().
 float predict(int index, int useThisManyNumbersToPredictIt)
          looks at useThisManyNumbersToPredictIt numbers in data[] and predicts the value at data[index] without looking at data[index] except by accident.
 float[] predictAll(float[] data, int[] primes)
           
 boolean setP(int index, CS value)
          Every CS is a list of other CSs, between size minP() and maxP() inclusive.
 float weight(int predictThisIndex, int observeMe)
          returns the weight of how much the index observeMe should be used to predict the value at predictThisIndex.
 
Methods inherited from class codesimian.DefaultCS
B, C, countP, decrementMyFuel, deleteP, F, fuel, getExec, getObject, heap, I, indexP, indexPName, insertB, insertC, insertD, insertF, insertI, insertJ, insertL, insertL, insertL1, insertP, insertS, insertZ, J, javaCode, LForProxy, LForProxy, myFuel, name, newInstance, objectToCS, objectToCSArray, objectToCSArray, prevD, prevL, PType, S, setB, setC, setCountP, setD, setD, setExec, setF, setFuel, setI, setJ, setL, setL, setL, setL1, setMyFuel, setName, setObject, setPrevExec, setS, setZ, start, toString, V, Z
 
Methods inherited from class codesimian.CS
addP, addP, addP, addP, addP, BForProxy, CForProxy, clone, cost, D, deleteP, FForProxy, IForProxy, javaCode, JForProxy, L, L, L, L, L, maxD, maxP, minD, overwrites, parent, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, setB, setC, setCost, setDescription, setF, setHeap, setI, setJ, setL, setL, setParent, setParsePriority, setProxyOf, setPType, setS, setTester, setZ, SForProxy, tester, VForProxy, voidReflect, ZForProxy
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SelfPredictingPrimeHashingNumberList

public SelfPredictingPrimeHashingNumberList()
Method Detail

DForProxy

public double DForProxy()
modify data[] 1 cycle farther, to predict itself better. countP() should equal data.length. Use the values in prime[] and data.length to compute the new values of data[].

Specified by:
DForProxy in class DefaultCS

minP

public int minP()
Description copied from class: DefaultCS
For DForProxy().
Minimum number of parameters in param[] needed to call DForProxy().
Defines which indexs of param[] DForProxy() can use.
Functions with a different number of parameters must override this.
OVERRIDE THIS FUNCTION IF EXEC USES A DIFFERENT NUMBER OF PARAMETERS.
Default is 1.

Overrides:
minP in class DefaultCS

P

public CS P(int index)
Description copied from class: DefaultCS
WARNING: if add CSs then delete them, they are still in the param[] array and can be returned in this function, despite them being out of valid range: index at least countP().

Overrides:
P in class DefaultCS
Parameters:
index - range 0 to countP()-1 inclusive
See Also:
CS.heap()

setP

public boolean setP(int index,
                    CS value)
Description copied from class: CS
Every CS is a list of other CSs, between size minP() and maxP() inclusive. setP overwrites one of those CSs or adds a new one at the end, depending on the index. If index is between 0 and countP()-1, overwrites. If it equals countP(), adds at end.

Overrides:
setP in class DefaultCS

isIllusion

public byte isIllusion(int index)
everything is an illusion. for all P(x), x is the index into a float[] array instead of a CS, and a CS from the constant-pool is returned.

Overrides:
isIllusion in class CS
See Also:
CS.overwrites(int), S.isIllusion(int)

keyword

public java.lang.String keyword()
Description copied from class: DefaultCS
For the CodeSimian language as a String.
CodeSimian language keyword, like "+" "*" "max" ">" etc.

Override this function if you want to specify a keyword other than how I derive them from the class name, like + for Add.

Some CSs might never be intended to be used in the language by their keyword.
The best example (4/05) is Num, because it is used in the language like "3.4" instead of "num()".
Default: Returns class name, minus package name (and its dots), and change the first letter to lowercase.

For example, CS.MaxParams does not override keyword(), which returns "maxP".

Overrides:
keyword in class DefaultCS
See Also:
CS.parent(), CS.newInstance(), CS.name()

description

public java.lang.String description()
Description copied from class: CS
a short description of this CS, shorter than the javadoc, but long enough to tell what the params are for. Example use: in automatically generated webpages for CodeSimian. Example: "returns sum of all params" for Add.

Overrides:
description in class DefaultCS

predictAll

public float[] predictAll(float[] data,
                          int[] primes)

predict

public float predict(int index,
                     int useThisManyNumbersToPredictIt)
looks at useThisManyNumbersToPredictIt numbers in data[] and predicts the value at data[index] without looking at data[index] except by accident. useThisManyNumbersToPredictIt is probably data.length.


weight

public float weight(int predictThisIndex,
                    int observeMe)
returns the weight of how much the index observeMe should be used to predict the value at predictThisIndex. For each index x, the sum of all weight(x,y) for all indexs y, should equal 1 (and none may be negative).