mirror of https://github.com/jlizier/jidt
Added implementation of differential entropy for Gaussian variables.
This commit is contained in:
parent
054044ccf6
commit
4bb762c119
|
|
@ -61,7 +61,7 @@ public class TransferEntropyCalculatorKernel
|
|||
public static final String FORCE_KERNEL_COMPARE_TO_ALL = "FORCE_KERNEL_COMPARE_TO_ALL";
|
||||
|
||||
/**
|
||||
* Default value for epsilon
|
||||
* Default value for epsilon (kernel width)
|
||||
*/
|
||||
public static final double DEFAULT_EPSILON = 0.25;
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ import java.util.Iterator;
|
|||
* <ol>
|
||||
* <li>Construct</li>
|
||||
* <li>SetProperty() for each property</li>
|
||||
* <li>intialise()</li>
|
||||
* <li>initialise()</li>
|
||||
* <li>setObservations(), or [startAddObservations(), addObservations()*, finaliseAddObservations()]
|
||||
* Note: If not using setObservations(), the results from computeLocal or getSignificance
|
||||
* are not likely to be particularly sensible.</li>
|
||||
|
|
@ -99,6 +99,9 @@ public class TransferEntropyCalculatorKraskovByMulti
|
|||
createKraskovMiCalculators();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param k history length (Schreiber k parameter, not Kraskov k parameter)
|
||||
*/
|
||||
public void initialise(int k) throws Exception {
|
||||
super.initialise(k); // calls initialise();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,90 @@
|
|||
package infodynamics.measures.continuous.lineargaussian;
|
||||
|
||||
import infodynamics.measures.continuous.EntropyCalculator;
|
||||
import infodynamics.utils.MatrixUtils;
|
||||
|
||||
/**
|
||||
* <p>Computes the differential entropy of a given set of observations, assuming that
|
||||
* the probability distribution function for these observations is Gaussian.</p>
|
||||
*
|
||||
* <p>
|
||||
* Usage:
|
||||
* <ol>
|
||||
* <li>Construct</li>
|
||||
* <li>initialise()</li>
|
||||
* <li>setObservations(), or setVariance().</li>
|
||||
* <li>computeAverageLocalOfObservations() to return the average differential
|
||||
* entropy based on either the set variance or the variance of
|
||||
* the supplied observations.</li>
|
||||
* </ol>
|
||||
* </p>
|
||||
*
|
||||
* @author Joseph Lizier joseph.lizier_at_gmail.com
|
||||
*
|
||||
*/
|
||||
public class EntropyCalculatorLinearGaussian implements EntropyCalculator {
|
||||
|
||||
/**
|
||||
* Variance of the most recently supplied observations
|
||||
*/
|
||||
protected double variance;
|
||||
|
||||
protected boolean debug;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public EntropyCalculatorLinearGaussian() {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialise the calculator ready for reuse
|
||||
*/
|
||||
public void initialise() throws Exception {
|
||||
// Nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide the observations from which to compute the entropy
|
||||
*
|
||||
* @param observations the observations to compute the entropy from
|
||||
*/
|
||||
public void setObservations(double[] observations) {
|
||||
variance = MatrixUtils.stdDev(observations);
|
||||
variance *= variance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the variance of the distribution for which we will compute the
|
||||
* entropy.
|
||||
*
|
||||
* @param variance
|
||||
*/
|
||||
public void setVariance(double variance) {
|
||||
this.variance = variance;
|
||||
}
|
||||
|
||||
/**
|
||||
* The entropy for a Gaussian-distribution random variable with
|
||||
* variance \sigma is \log_e{2*pi*e*\sigma}.
|
||||
* Here we compute the entropy assuming that the recorded estimation of the
|
||||
* variance is correct (i.e. we will not make a bias correction for limited
|
||||
* observations here).
|
||||
*
|
||||
* @return the entropy of the previously provided observations
|
||||
*/
|
||||
public double computeAverageLocalOfObservations() {
|
||||
return Math.log(2.0*Math.PI*Math.E*variance);
|
||||
}
|
||||
|
||||
public void setDebug(boolean debug) {
|
||||
this.debug = debug;
|
||||
}
|
||||
|
||||
public void setProperty(String propertyName, String propertyValue)
|
||||
throws Exception {
|
||||
// No properties to set here
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -17,6 +17,9 @@ import infodynamics.utils.RandomGenerator;
|
|||
* 2. Standalone computation from a single set of observations:
|
||||
* Call: computeLocal() or computeAverageLocal()
|
||||
*
|
||||
* @see For transfer entropy: Schreiber, PRL 85 (2) pp.461-464, 2000; http://dx.doi.org/10.1103/PhysRevLett.85.461
|
||||
* @see For local transfer entropy: Lizier et al, PRE 77, 026110, 2008; http://dx.doi.org/10.1103/PhysRevE.77.026110
|
||||
*
|
||||
* @author Joseph Lizier
|
||||
* joseph.lizier at gmail.com
|
||||
* http://lizier.me/joseph/
|
||||
|
|
@ -58,6 +61,14 @@ public class ApparentTransferEntropyCalculator extends ContextOfPastMeasureCalcu
|
|||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new TE calculator for the given base and history length.
|
||||
*
|
||||
* @param base number of quantisation levels for each variable.
|
||||
* E.g. binary variables are in base-2.
|
||||
* @param history history length of the destination to condition on -
|
||||
* this is k in Schreiber's notation.
|
||||
*/
|
||||
public ApparentTransferEntropyCalculator(int base, int history) {
|
||||
|
||||
super(base, history);
|
||||
|
|
|
|||
|
|
@ -2544,8 +2544,8 @@ public class MatrixUtils {
|
|||
|
||||
/**
|
||||
* <p>Private function to compute the determinant recursively.
|
||||
* determinant() calls this after checking the matrix dimensions. <br/>
|
||||
* See - http://mathworld.wolfram.com/Determinant.html
|
||||
* {@link determinant()} calls this after checking the matrix dimensions. <br/>
|
||||
* @see {@link http://mathworld.wolfram.com/Determinant.html}
|
||||
* </p>
|
||||
*
|
||||
* @param matrix
|
||||
|
|
|
|||
Loading…
Reference in New Issue