package jsci.maths.wavelet;
import jsci.maths.*;
import jsci.maths.wavelet.*;
/****************************************************
* This class is used to encapsulate wavelet coefficients.
* @author Daniel Lemire
*****************************************/
public final class FWTCoef extends Object implements NumericalConstants, Cloneable {
protected double[][] coefs;
final static double normalisation=1.0/SQRT2;
public FWTCoef () {
}
/**********************************************
***********************************************/
public FWTCoef (double[][] v) {
coefs=v;
}
/********************************************
* Return a copy of this object
*********************************************/
public Object clone() {
try {
FWTCoef fwt=(FWTCoef) super.clone();
if(coefs!=null)
fwt.coefs=ArrayMath.copy(coefs);
return(fwt);
} catch (CloneNotSupportedException cnse) {
throw new InternalError();
}
}
/*************************************************
**************************************************/
public int getJ () {
return(coefs.length);
}
/*************************************************
**************************************************/
public int dimension(int i) {
if ((i<0)||(i>=coefs.length)) {
throw new IllegalArgumentException("This dimension doesn't exist : "+i+", "+coefs.length);
}
return(coefs[i].length);
}
/*******************************************************
********************************************************/
public double[][] getCoefs() {
return(coefs);
}
/***************************
* Compute the L2 norm of the
* coefficients
****************************/
public double[] norm() {
double[] ans=new double[coefs.length];
for(int j=0;j=coefs.length)) {
throw new IllegalArgumentException("The integer parameter "+i+" should be between 0 and "+(coefs.length-1));
}
double ans=ArrayMath.norm(coefs[i]);
return(ans);
}
/************************************
* Compute the sum of the squares of
* the coefficients
*************************************/
private double[] sumSquares() {
double[] ans=new double[coefs.length];
for(int j=0;j=coefs.length)) {
throw new IllegalArgumentException("The integer parameter "+i+" should be between 0 and "+(coefs.length-1));
}
double ans=ArrayMath.sumSquares(coefs[i]);
return(ans);
}
/************************************
*************************************/
public double mass(int i) {
if((i<0)||(i>=coefs.length)) {
throw new IllegalArgumentException("The integer parameter "+i+" should be between 0 and "+(coefs.length-1));
}
double ans=ArrayMath.mass(coefs[i]);
return(ans);
}
/************************************
*************************************/
private double[] variance() {
double[] ans=new double[coefs.length];
for(int j=0;j=coefs.length)) {
throw new IllegalArgumentException("The integer parameter "+i+" should be between 0 and "+(coefs.length-1));
}
double ans=ArrayMath.variance(coefs[i]);
return(ans);
}
/**********************************************
***********************************************/
public double sumEnergies() {
if(coefs.length<=1) {
throw new IllegalArgumentException("No wavelet coefficients!");
}
double[] energies=sumSquares();
double ans=0;
for(int k=1;k=coefs.length)) {
throw new IllegalArgumentException("The integer parameter "+i+" should be between 0 and "+(coefs.length-1));
}
if(sumEnergies()==0) {
if(coefs.length!=0) {
return(1/coefs.length);
} else {
throw new IllegalArgumentException("No energy!");
}
}
return(sumSquares(i)/sumEnergies());
}
/***********************************************
************************************************/
public double varianceRatio(int i) {
if(coefs.length<=1) {
throw new IllegalArgumentException("No wavelet coefficients!");
}
if((i<1)||(i>=coefs.length)) {
throw new IllegalArgumentException("The integer parameter "+i+" should be between 0 and "+(coefs.length-1));
}
if(sumVariance()==0) {
if(coefs.length!=0) {
return(1/coefs.length);
} else {
throw new IllegalArgumentException("No energy!");
}
}
return(variance(i)/sumVariance());
}
/***************************************************
* Compute the Shannon entropy.
****************************************************/
public double icf() {
if(coefs.length<=1) {
throw new IllegalArgumentException("No wavelet coefficients!");
}
double[] pe=new double[coefs.length-1];
for(int j=1;j=coefs.length)) {
throw new IllegalArgumentException("The integer parameter "+i+" should be between 0 and "+(coefs.length-1));
}
coefs[i]=v;
}
/**********************************************
***********************************************/
public void synthesize(Filter filtreprimaire, double[] param) {
if(coefs.length<=1) {
throw new IllegalArgumentException("No synthesis possible : "+coefs.length);
}
double[] V0=filtreprimaire.lowpass(coefs[0],param);
double[] W0=filtreprimaire.highpass(coefs[coefs.length-1],param);
V0=ArrayMath.scalarMultiply(normalisation,V0);
if(V0.length!=W0.length) {
throw new IllegalArgumentException("Synthesis impossible : bad data/multiresolution?"+coefs[0].length+", "+coefs[coefs.length-1].length+", "+V0.length+", "+W0.length);
}
V0=ArrayMath.add(V0,W0);
double[][] c=new double[coefs.length-1][];
for(int j=1;jcoefs.length-1)) {
throw new IllegalArgumentException("The integer parameter "+jmax+" must be between 0 and "+(coefs.length-1));
}
for(int j=0;jcoefs.length-1)) {
throw new IllegalArgumentException("The integer parameter "+jmax+" must be between 0 and "+(coefs.length-1));
}
for(int j=0;j=seuil) {
ans[k]=0;
}
}
return(ans);
}
/*********************************************
* Compresses by zero-ing any value below a given percentile cut-off.
* @param p percentile cut-off, must be between 0 and 1.
**********************************************/
public void compress(double p) {
for(int k=1;k= seuil) {
ans[k]=0;
}
}
return(ans);
}
/*********************************************
* Compresses by zero-ing any value below a given cut-off.
* @param p cut-off.
**********************************************/
public void compressHard(double p) {
for(int k=1;k
Ads help maintain this website.