diff --git a/java/source/infodynamics/measures/discrete/ActiveInformationCalculatorDiscrete.java b/java/source/infodynamics/measures/discrete/ActiveInformationCalculatorDiscrete.java
index c8d8aef..e565352 100755
--- a/java/source/infodynamics/measures/discrete/ActiveInformationCalculatorDiscrete.java
+++ b/java/source/infodynamics/measures/discrete/ActiveInformationCalculatorDiscrete.java
@@ -72,7 +72,7 @@ import infodynamics.utils.RandomGenerator;
* @author Joseph Lizier (email,
* www)
*/
-public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscreteInContextOfPastCalculator
+public class ActiveInformationCalculatorDiscrete extends UnivariateMeasureDiscreteInContextOfPastCalculator
implements EmpiricalNullDistributionComputer, AnalyticNullDistributionComputer {
protected boolean aisComputed = false;
@@ -111,7 +111,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
@Override
public void initialise() {
- initialise(base, k);
+ initialise(alphabetSize, k);
}
public void initialise(int base, int history) {
@@ -128,7 +128,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
// Initialise and store the current previous value for each column
int prevVal = 0;
for (int p = 0; p < k; p++) {
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[p];
}
@@ -142,7 +142,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
nextCount[nextVal]++;
// Update the previous value:
prevVal -= maxShiftedValue[states[t-k]];
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[t];
}
}
@@ -159,7 +159,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
for (int c = 0; c < columns; c++) {
prevVal[c] = 0;
for (int p = 0; p < k; p++) {
- prevVal[c] *= base;
+ prevVal[c] *= alphabetSize;
prevVal[c] += states[p][c];
}
}
@@ -176,13 +176,12 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
nextCount[nextVal]++;
// Update the previous value:
prevVal[c] -= maxShiftedValue[states[r-k][c]];
- prevVal[c] *= base;
+ prevVal[c] *= alphabetSize;
prevVal[c] += states[r][c];
}
}
}
- @Override
public void addObservations(int states[][][]) {
int timeSteps = states.length;
if (timeSteps == 0) {
@@ -202,7 +201,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
for (int c = 0; c < agentColumns; c++) {
prevVal[r][c] = 0;
for (int p = 0; p < k; p++) {
- prevVal[r][c] *= base;
+ prevVal[r][c] *= alphabetSize;
prevVal[r][c] += states[p][r][c];
}
}
@@ -221,14 +220,13 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
nextCount[nextVal]++;
// Update the previous value:
prevVal[r][c] -= maxShiftedValue[states[t-k][r][c]];
- prevVal[r][c] *= base;
+ prevVal[r][c] *= alphabetSize;
prevVal[r][c] += states[t][r][c];
}
}
}
}
- @Override
public void addObservations(int states[][], int col) {
int rows = states.length;
// increment the count of observations:
@@ -238,7 +236,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
int prevVal = 0;
prevVal = 0;
for (int p = 0; p < k; p++) {
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[p][col];
}
@@ -253,12 +251,11 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
nextCount[nextVal]++;
// Update the previous value:
prevVal -= maxShiftedValue[states[r-k][col]];
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[r][col];
}
}
- @Override
public void addObservations(int states[][][], int agentIndex1, int agentIndex2) {
int timeSteps = states.length;
// increment the count of observations:
@@ -268,7 +265,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
int prevVal = 0;
prevVal = 0;
for (int p = 0; p < k; p++) {
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[p][agentIndex1][agentIndex2];
}
@@ -283,7 +280,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
nextCount[nextVal]++;
// Update the previous value:
prevVal -= maxShiftedValue[states[t-k][agentIndex1][agentIndex2]];
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[t][agentIndex1][agentIndex2];
}
}
@@ -295,7 +292,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
max = 0;
min = 0;
- for (int nextVal = 0; nextVal < base; nextVal++) {
+ for (int nextVal = 0; nextVal < alphabetSize; nextVal++) {
// compute p_next
double p_next = (double) nextCount[nextVal] / (double) observations;
for (int prevVal = 0; prevVal < base_power_k; prevVal++) {
@@ -335,7 +332,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
double entRate = 0.0;
double entRateCont = 0.0;
- for (int nextVal = 0; nextVal < base; nextVal++) {
+ for (int nextVal = 0; nextVal < alphabetSize; nextVal++) {
for (int prevVal = 0; prevVal < base_power_k; prevVal++) {
// compute p_prev
double p_prev = (double) pastCount[prevVal] / (double) observations;
@@ -389,7 +386,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
// Initialise and store the current previous value for each column
int prevVal = 0;
for (int p = 0; p < k; p++) {
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[p];
}
@@ -414,7 +411,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
}
// Update the previous value:
prevVal -= maxShiftedValue[states[t-k]];
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[t];
}
average = average/(double) (timeSteps - k);
@@ -423,7 +420,6 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
}
- @Override
public double[][] computeLocalFromPreviousObservations(int states[][]){
int rows = states.length;
int columns = states[0].length;
@@ -439,7 +435,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
for (int c = 0; c < columns; c++) {
prevVal[c] = 0;
for (int p = 0; p < k; p++) {
- prevVal[c] *= base;
+ prevVal[c] *= alphabetSize;
prevVal[c] += states[p][c];
}
}
@@ -465,7 +461,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
}
// Update the previous value:
prevVal[c] -= maxShiftedValue[states[r-k][c]];
- prevVal[c] *= base;
+ prevVal[c] *= alphabetSize;
prevVal[c] += states[r][c];
}
}
@@ -475,7 +471,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
}
- @Override
+
public double[][][] computeLocalFromPreviousObservations(int states[][][]){
int timeSteps = states.length;
int agentRows = states[0].length;
@@ -493,7 +489,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
for (int c = 0; c < agentColumns; c++) {
prevVal[r][c] = 0;
for (int p = 0; p < k; p++) {
- prevVal[r][c] *= base;
+ prevVal[r][c] *= alphabetSize;
prevVal[r][c] += states[p][r][c];
}
}
@@ -521,7 +517,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
}
// Update the previous value:
prevVal[r][c] -= maxShiftedValue[states[t-k][r][c]];
- prevVal[r][c] *= base;
+ prevVal[r][c] *= alphabetSize;
prevVal[r][c] += states[t][r][c];
}
}
@@ -531,7 +527,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
return localActive;
}
- @Override
+
public double[] computeLocalFromPreviousObservations(int states[][], int col){
int rows = states.length;
//int columns = states[0].length;
@@ -546,7 +542,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
int prevVal = 0;
prevVal = 0;
for (int p = 0; p < k; p++) {
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[p][col];
}
int nextVal;
@@ -570,7 +566,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
}
// Update the previous value:
prevVal -= maxShiftedValue[states[r-k][col]];
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[r][col];
}
average = average/(double) (rows - k);
@@ -579,7 +575,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
}
- @Override
+
public double[] computeLocalFromPreviousObservations(int states[][][],
int agentIndex1, int agentIndex2){
int timeSteps = states.length;
@@ -595,7 +591,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
int prevVal = 0;
prevVal = 0;
for (int p = 0; p < k; p++) {
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[p][agentIndex1][agentIndex2];
}
int nextVal;
@@ -619,7 +615,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
}
// Update the previous value:
prevVal -= maxShiftedValue[states[t-k][agentIndex1][agentIndex2]];
- prevVal *= base;
+ prevVal *= alphabetSize;
prevVal += states[t][agentIndex1][agentIndex2];
}
average = average/(double) (timeSteps - k);
@@ -709,14 +705,14 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
MatrixUtils.fill(prevValues, prevVal, t_prev, numberOfSamplesPrev);
t_prev += numberOfSamplesPrev;
}
- for (int nextVal = 0; nextVal < base; nextVal++) {
+ for (int nextVal = 0; nextVal < alphabetSize; nextVal++) {
int numberOfSamplesNext = nextCount[nextVal];
MatrixUtils.fill(nextValues, nextVal, t_next, numberOfSamplesNext);
t_next += numberOfSamplesNext;
}
ActiveInformationCalculatorDiscrete ais2;
- ais2 = new ActiveInformationCalculatorDiscrete(base, k);
+ ais2 = new ActiveInformationCalculatorDiscrete(alphabetSize, k);
ais2.initialise();
ais2.observations = observations;
ais2.pastCount = pastCount;
@@ -754,7 +750,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
}
return new ChiSquareMeasurementDistribution(average,
observations,
- (base - 1) * (base_power_k - 1));
+ (alphabetSize - 1) * (base_power_k - 1));
}
/**
@@ -767,7 +763,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
double miCont = 0.0;
System.out.println("nextVal p(next) prevVal p(prev) p(joint) logTerm localVal");
- for (int nextVal = 0; nextVal < base; nextVal++) {
+ for (int nextVal = 0; nextVal < alphabetSize; nextVal++) {
// compute p_next
double p_next = (double) nextCount[nextVal] / (double) observations;
for (int prevVal = 0; prevVal < base_power_k; prevVal++) {
@@ -811,7 +807,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
public int computePastValue(int[] x, int t) {
int pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += x[t - k + 1 + p];
}
return pastVal;
@@ -835,7 +831,7 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
public int computePastValue(int[][] data, int column, int t) {
int pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += data[t - k + 1 + p][column];
}
return pastVal;
@@ -863,9 +859,27 @@ public class ActiveInformationCalculatorDiscrete extends SingleAgentMeasureDiscr
int agentColumn, int t) {
int pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += data[t - k + 1 + p][agentRow][agentColumn];
}
return pastVal;
}
+
+ @Override
+ public void setObservations(Object[] observations) throws Exception {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("Unimplemented method 'setObservations'");
+ }
+
+ @Override
+ public void startAddObservations() {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("Unimplemented method 'startAddObservations'");
+ }
+
+ @Override
+ public void finaliseAddObservations() throws Exception {
+ // TODO Auto-generated method stub
+ throw new UnsupportedOperationException("Unimplemented method 'finaliseAddObservations'");
+ }
}
diff --git a/java/source/infodynamics/measures/discrete/BlockEntropyCalculatorDiscrete.java b/java/source/infodynamics/measures/discrete/BlockEntropyCalculatorDiscrete.java
index 40bdda3..29eb1fb 100755
--- a/java/source/infodynamics/measures/discrete/BlockEntropyCalculatorDiscrete.java
+++ b/java/source/infodynamics/measures/discrete/BlockEntropyCalculatorDiscrete.java
@@ -104,7 +104,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
private void resetBlocksize(int blocksize) {
this.blocksize = blocksize;
- base_power_blocksize = MathsUtils.power(base, blocksize);
+ base_power_blocksize = MathsUtils.power(alphabetSize, blocksize);
if (blocksize <= 1) {
throw new RuntimeException("Blocksize " + blocksize + " is not > 1 for Block Entropy Calculator");
@@ -114,14 +114,14 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
}
// Create constants for tracking stateValues
- maxShiftedValue = new int[base];
- for (int v = 0; v < base; v++) {
- maxShiftedValue[v] = v * MathsUtils.power(base, blocksize-1);
+ maxShiftedValue = new int[alphabetSize];
+ for (int v = 0; v < alphabetSize; v++) {
+ maxShiftedValue[v] = v * MathsUtils.power(alphabetSize, blocksize-1);
}
}
public void initialise(int blocksize, int base) {
- boolean baseOrBlocksizeChanged = (this.blocksize != blocksize) || (this.base != base);
+ boolean baseOrBlocksizeChanged = (this.blocksize != blocksize) || (this.alphabetSize != base);
super.initialise(base);
if (baseOrBlocksizeChanged) {
@@ -148,7 +148,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
@Override
public void initialise() {
- initialise(blocksize, base);
+ initialise(blocksize, alphabetSize);
}
@Override
@@ -163,7 +163,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Add the contribution from this observation
stateVal += states[p];
// And shift up
- stateVal *= base;
+ stateVal *= alphabetSize;
}
// 1. Now count the tuples observed from the next row onwards
@@ -176,7 +176,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Remove the oldest observation from the state value
stateVal -= maxShiftedValue[states[r-blocksize+1]];
- stateVal *= base;
+ stateVal *= alphabetSize;
}
}
@@ -195,7 +195,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Add the contribution from this observation
stateVal[c] += states[p][c];
// And shift up
- stateVal[c] *= base;
+ stateVal[c] *= alphabetSize;
}
}
@@ -210,12 +210,12 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Remove the oldest observation from the state value
stateVal[c] -= maxShiftedValue[states[r-blocksize+1][c]];
- stateVal[c] *= base;
+ stateVal[c] *= alphabetSize;
}
}
}
- @Override
+
public void addObservations(int states[][][]) {
int timeSteps = states.length;
if (timeSteps == 0) {
@@ -238,7 +238,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Add the contribution from this observation
stateVal[r][c] += states[p][r][c];
// And shift up
- stateVal[r][c] *= base;
+ stateVal[r][c] *= alphabetSize;
}
}
}
@@ -255,13 +255,13 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Remove the oldest observation from the state value
stateVal[r][c] -= maxShiftedValue[states[t-blocksize+1][r][c]];
- stateVal[r][c] *= base;
+ stateVal[r][c] *= alphabetSize;
}
}
}
}
- @Override
+
public void addObservations(int states[][], int col) {
int rows = states.length;
// increment the count of observations:
@@ -273,7 +273,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Add the contribution from this observation
stateVal += states[p][col];
// And shift up
- stateVal *= base;
+ stateVal *= alphabetSize;
}
// 1. Count the tuples observed
@@ -286,11 +286,11 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Remove the oldest observation from the state value
stateVal -= maxShiftedValue[states[r-blocksize+1][col]];
- stateVal *= base;
+ stateVal *= alphabetSize;
}
}
- @Override
+
public void addObservations(int states[][][], int agentIndex1, int agentIndex2) {
int timeSteps = states.length;
// increment the count of observations:
@@ -302,7 +302,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Add the contribution from this observation
stateVal += states[p][agentIndex1][agentIndex2];
// And shift up
- stateVal *= base;
+ stateVal *= alphabetSize;
}
// 1. Count the tuples observed
@@ -315,7 +315,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Remove the oldest observation from the state value
stateVal -= maxShiftedValue[states[t-blocksize+1][agentIndex1][agentIndex2]];
- stateVal *= base;
+ stateVal *= alphabetSize;
}
}
@@ -348,7 +348,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
return ent;
}
- @Override
+
public double[][] computeLocalFromPreviousObservations(int states[][]){
int rows = states.length;
int columns = states[0].length;
@@ -365,7 +365,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
stateVal[c] = 0;
for (int p = 0; p < blocksize - 1; p++) {
stateVal[c] += states[p][c];
- stateVal[c] *= base;
+ stateVal[c] *= alphabetSize;
}
}
// StateVal just needs the next value put in before processing
@@ -387,7 +387,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Subtract out the oldest part of the state value:
stateVal[c] -= maxShiftedValue[states[r-blocksize+1][c]];
// And shift all upwards
- stateVal[c] *= base;
+ stateVal[c] *= alphabetSize;
}
}
average = average/(double) (columns * (rows - blocksize + 1));
@@ -396,7 +396,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
}
- @Override
+
public double[][][] computeLocalFromPreviousObservations(int states[][][]){
int timeSteps = states.length;
int agentRows, agentColumns;
@@ -425,7 +425,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
stateVal[r][c] = 0;
for (int p = 0; p < blocksize - 1; p++) {
stateVal[r][c] += states[p][r][c];
- stateVal[r][c] *= base;
+ stateVal[r][c] *= alphabetSize;
}
}
}
@@ -449,7 +449,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Subtract out the oldest part of the state value:
stateVal[r][c] -= maxShiftedValue[states[t-blocksize+1][r][c]];
// And shift all upwards
- stateVal[r][c] *= base;
+ stateVal[r][c] *= alphabetSize;
}
}
}
@@ -459,7 +459,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
}
- @Override
+
public double[] computeLocalFromPreviousObservations(int states[][], int col){
int rows = states.length;
//int columns = states[0].length;
@@ -476,7 +476,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
int stateVal = 0;
for (int p = 0; p < blocksize - 1; p++) {
stateVal += states[p][col];
- stateVal *= base;
+ stateVal *= alphabetSize;
}
// StateVal just needs the next value put in before processing
@@ -496,7 +496,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Subtract out the oldest part of the state value:
stateVal -= maxShiftedValue[states[r-blocksize+1][col]];
// And shift all upwards
- stateVal *= base;
+ stateVal *= alphabetSize;
}
average = average/(double) (rows - blocksize + 1);
@@ -504,7 +504,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
}
- @Override
+
public double[] computeLocalFromPreviousObservations(int states[][][], int agentIndex1, int agentIndex2){
int timeSteps = states.length;
//int columns = states[0].length;
@@ -521,7 +521,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
int stateVal = 0;
for (int p = 0; p < blocksize - 1; p++) {
stateVal += states[p][agentIndex1][agentIndex2];
- stateVal *= base;
+ stateVal *= alphabetSize;
}
// StateVal just needs the next value put in before processing
@@ -541,7 +541,7 @@ public class BlockEntropyCalculatorDiscrete extends EntropyCalculatorDiscrete {
// Subtract out the oldest part of the state value:
stateVal -= maxShiftedValue[states[t-blocksize+1][agentIndex1][agentIndex2]];
// And shift all upwards
- stateVal *= base;
+ stateVal *= alphabetSize;
}
average = average/(double) (timeSteps - blocksize + 1);
diff --git a/java/source/infodynamics/measures/discrete/CombinedActiveEntRateCalculatorDiscrete.java b/java/source/infodynamics/measures/discrete/CombinedActiveEntRateCalculatorDiscrete.java
index 56ee18d..d59505c 100755
--- a/java/source/infodynamics/measures/discrete/CombinedActiveEntRateCalculatorDiscrete.java
+++ b/java/source/infodynamics/measures/discrete/CombinedActiveEntRateCalculatorDiscrete.java
@@ -32,7 +32,7 @@ import infodynamics.utils.MatrixUtils;
* and typical usage pattern.
*
*
- * TODO Make this inherit from {@link SingleAgentMeasureDiscreteInContextOfPastCalculator}
+ * TODO Make this inherit from {@link UnivariateMeasureDiscreteInContextOfPastCalculator}
* like {@link ActiveInformationCalculatorDiscrete} and fix the Javadocs
*
* @author Joseph Lizier (email,
diff --git a/java/source/infodynamics/measures/discrete/ConditionalTransferEntropyCalculatorDiscrete.java b/java/source/infodynamics/measures/discrete/ConditionalTransferEntropyCalculatorDiscrete.java
index c9e8aef..9f8d13b 100644
--- a/java/source/infodynamics/measures/discrete/ConditionalTransferEntropyCalculatorDiscrete.java
+++ b/java/source/infodynamics/measures/discrete/ConditionalTransferEntropyCalculatorDiscrete.java
@@ -242,7 +242,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
public void initialise(int base, int history,
int numOtherInfoContributors, int base_others) {
- boolean paramsChanged = (this.base != base) || (k != history) ||
+ boolean paramsChanged = (this.alphabetSize != base) || (k != history) ||
(this.numOtherInfoContributors != numOtherInfoContributors) ||
(this.base_others != base_others);
super.initialise(base, history);
@@ -275,7 +275,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
@Override
public void initialise(){
- initialise(base, k, numOtherInfoContributors, base_others);
+ initialise(alphabetSize, k, numOtherInfoContributors, base_others);
}
/**
@@ -313,7 +313,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Initialise and store the current previous value
int pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += dest[p];
}
@@ -336,7 +336,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Update the previous value:
if (k > 0) {
pastVal -= maxShiftedValue[dest[r-k]];
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += dest[r];
}
}
@@ -386,7 +386,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Initialise and store the current previous value
int pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += dest[p];
}
@@ -404,7 +404,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Update the previous value:
if (k > 0) {
pastVal -= maxShiftedValue[dest[r-k]];
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += dest[r];
}
}
@@ -468,7 +468,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
for (int c = 0; c < columns; c++) {
pastVal[c] = 0;
for (int p = 0; p < k; p++) {
- pastVal[c] *= base;
+ pastVal[c] *= alphabetSize;
pastVal[c] += states[p][c];
}
}
@@ -494,7 +494,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Update the previous value:
if (k > 0) {
pastVal[c] -= maxShiftedValue[states[r-k][c]];
- pastVal[c] *= base;
+ pastVal[c] *= alphabetSize;
pastVal[c] += states[r][c];
}
}
@@ -551,7 +551,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Initialise and store the current previous value for each column
int pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += states[p][destCol];
}
@@ -575,7 +575,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Update the previous value:
if (k > 0) {
pastVal -= maxShiftedValue[states[r-k][destCol]];
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += states[r][destCol];
}
}
@@ -591,8 +591,8 @@ public class ConditionalTransferEntropyCalculatorDiscrete
double meanSqLocals = 0;
for (int othersVal = 0; othersVal < this.base_power_num_others; othersVal++) {
for (int pastVal = 0; pastVal < base_power_k; pastVal++) {
- for (int destVal = 0; destVal < base; destVal++) {
- for (int sourceVal = 0; sourceVal < base; sourceVal++) {
+ for (int destVal = 0; destVal < alphabetSize; destVal++) {
+ for (int sourceVal = 0; sourceVal < alphabetSize; sourceVal++) {
// Compute TE contribution:
if (sourceDestPastOthersCount[sourceVal][destVal][pastVal][othersVal] != 0) {
/* Double check: should never happen
@@ -650,7 +650,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Reconstruct the source values (not necessarily in order)
int[] sourceValues = new int[observations];
int t_s = 0;
- for (int sourceVal = 0; sourceVal < base; sourceVal++) {
+ for (int sourceVal = 0; sourceVal < alphabetSize; sourceVal++) {
// Count up the number of times this source value was observed:
int numberOfSamples = 0;
for (int pastVal = 0; pastVal < base_power_k; pastVal++) {
@@ -683,7 +683,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
MatrixUtils.fill(othersValues, othersVal, t_o,
pastOthersCount[pastVal][othersVal]);
t_o += pastOthersCount[pastVal][othersVal];
- for (int destVal = 0; destVal < base; destVal++) {
+ for (int destVal = 0; destVal < alphabetSize; destVal++) {
MatrixUtils.fill(destValues, destVal, t_d,
destPastOthersCount[destVal][pastVal][othersVal]);
t_d += destPastOthersCount[destVal][pastVal][othersVal];
@@ -692,7 +692,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
}
// TODO stop using deprecated method
- ConditionalTransferEntropyCalculatorDiscrete cte = newInstance(base, k, numOtherInfoContributors);
+ ConditionalTransferEntropyCalculatorDiscrete cte = newInstance(alphabetSize, k, numOtherInfoContributors);
cte.initialise();
cte.observations = observations;
cte.pastOthersCount = pastOthersCount;
@@ -733,7 +733,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
}
return new ChiSquareMeasurementDistribution(average,
observations,
- (base - 1)*(base - 1)*(base_power_k*base_power_num_others));
+ (alphabetSize - 1)*(alphabetSize - 1)*(base_power_k*base_power_num_others));
}
/**
@@ -804,7 +804,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
for (int c = 0; c < columns; c++) {
pastVal[c] = 0;
for (int p = 0; p < k; p++) {
- pastVal[c] *= base;
+ pastVal[c] *= alphabetSize;
pastVal[c] += states[p][c];
}
}
@@ -834,7 +834,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Update the previous value:
if (k > 0) {
pastVal[c] -= maxShiftedValue[states[r-k][c]];
- pastVal[c] *= base;
+ pastVal[c] *= alphabetSize;
pastVal[c] += states[r][c];
}
}
@@ -905,7 +905,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
int pastVal = 0;
pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += states[p][destCol];
}
int destVal, sourceVal, othersVal;
@@ -932,7 +932,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Update the previous value:
if (k > 0) {
pastVal -= maxShiftedValue[states[r-k][destCol]];
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += states[r][destCol];
}
}
@@ -975,7 +975,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
int pastVal = 0;
pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += dest[p];
}
int destVal, sourceVal, conditionalVal;
@@ -997,7 +997,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Update the previous value:
if (k > 0) {
pastVal -= maxShiftedValue[dest[r-k]];
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += dest[r];
}
}
@@ -1033,7 +1033,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
int pastVal = 0;
pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += dest[p];
}
int destVal, sourceVal, conditionalsVal;
@@ -1044,7 +1044,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
conditionalsVal = 0;
for (int o = 0; o < conditionals[r-1].length; o++) {
// Include this other contributor
- conditionalsVal *= base;
+ conditionalsVal *= alphabetSize;
conditionalsVal += conditionals[r-1][o];
}
// Now compute the local value
@@ -1060,7 +1060,7 @@ public class ConditionalTransferEntropyCalculatorDiscrete
// Update the previous value:
if (k > 0) {
pastVal -= maxShiftedValue[dest[r-k]];
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += dest[r];
}
}
diff --git a/java/source/infodynamics/measures/discrete/ContextOfPastMeasureCalculatorDiscrete.java b/java/source/infodynamics/measures/discrete/ContextOfPastMeasureCalculatorDiscrete.java
index 1b19801..5e095e2 100755
--- a/java/source/infodynamics/measures/discrete/ContextOfPastMeasureCalculatorDiscrete.java
+++ b/java/source/infodynamics/measures/discrete/ContextOfPastMeasureCalculatorDiscrete.java
@@ -111,7 +111,7 @@ public abstract class ContextOfPastMeasureCalculatorDiscrete extends
private void resetHistory(int history) {
k = history;
- base_power_k = MathsUtils.power(base, k);
+ base_power_k = MathsUtils.power(alphabetSize, k);
if (k < 0) {
throw new RuntimeException("History k " + history + " is not >= 0 for a ContextOfPastMeasureCalculator");
@@ -123,15 +123,15 @@ public abstract class ContextOfPastMeasureCalculatorDiscrete extends
}
// Create constants for tracking prevValues
- maxShiftedValue = new int[base];
- for (int v = 0; v < base; v++) {
- maxShiftedValue[v] = v * MathsUtils.power(base, k-1);
+ maxShiftedValue = new int[alphabetSize];
+ for (int v = 0; v < alphabetSize; v++) {
+ maxShiftedValue[v] = v * MathsUtils.power(alphabetSize, k-1);
}
}
@Override
public void initialise() {
- initialise(base, k);
+ initialise(alphabetSize, k);
}
/**
@@ -143,7 +143,7 @@ public abstract class ContextOfPastMeasureCalculatorDiscrete extends
*/
public void initialise(int base, int history) {
boolean baseOrHistoryChanged = false;
- if ((this.base != base) || (k != history)) {
+ if ((this.alphabetSize != base) || (k != history)) {
baseOrHistoryChanged = true;
}
@@ -189,7 +189,7 @@ public abstract class ContextOfPastMeasureCalculatorDiscrete extends
public int computePastValue(int[] x, int t) {
int pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += x[t - k + 1 + p];
}
return pastVal;
@@ -212,7 +212,7 @@ public abstract class ContextOfPastMeasureCalculatorDiscrete extends
public int computePastValue(int[][] data, int columnNumber, int t) {
int pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += data[t - k + 1 + p][columnNumber];
}
return pastVal;
@@ -238,7 +238,7 @@ public abstract class ContextOfPastMeasureCalculatorDiscrete extends
public int computePastValue(int[][][] data, int rowNumber, int columnNumber, int t) {
int pastVal = 0;
for (int p = 0; p < k; p++) {
- pastVal *= base;
+ pastVal *= alphabetSize;
pastVal += data[t - k + 1 + p][rowNumber][columnNumber];
}
return pastVal;
diff --git a/java/source/infodynamics/measures/discrete/EntropyCalculatorDiscrete.java b/java/source/infodynamics/measures/discrete/EntropyCalculatorDiscrete.java
index f2efc79..6dfe84d 100755
--- a/java/source/infodynamics/measures/discrete/EntropyCalculatorDiscrete.java
+++ b/java/source/infodynamics/measures/discrete/EntropyCalculatorDiscrete.java
@@ -19,6 +19,9 @@
package infodynamics.measures.discrete;
import java.util.Hashtable;
+import java.util.Map;
+import java.util.List;
+import java.util.Arrays;
import infodynamics.utils.MatrixUtils;
@@ -58,12 +61,27 @@ Theory' (John Wiley & Sons, New York, 1991).
* www)
*/
public class EntropyCalculatorDiscrete extends InfoMeasureCalculatorDiscrete
- implements SingleAgentMeasureDiscrete
+ implements UnivariateMeasureDiscrete
{
+ // TODO -- find or calculate reasonable max value. Currently 100.
protected int[] stateCount = null; // Count for i[t]
+ /**
+ * State counts in a hashtable for observations other than ints
+ * as well as for sparse observations
+ */
protected Hashtable