java.net
public class: LinearInterpolator [javadoc |
source]
java.lang.Object
java.net.LinearInterpolator
All Implemented Interfaces:
Interpolator
This class is an implementation of the
Interpolator interface and it uses
a statistical approach called
fixed point interpolation that I created during my master degree thesis.
The transmission line model and the level model are described by a linear curve like the following:
y=A*x+b
The model is composed of two interpolation curve:
- the first is used for the compression time
- the second is used for the compression ratio
The model is completed by the preceding sample point. So every model keeps five coefficients: A and B
for compression time, A and B for compression ratio, and X for the last sample point.
This interpolator keeps a model for the transmission line and a model for every compression level.
For a complete description of the approach see
my thesis.
Field Summary |
---|
protected double[] | line | Data needed to model the transmission line. It's an array composed of five elements. |
protected double[][] | levels | Data needed to model levels. It's an array with the same number of elements as the supported levels
and every entry is an array of five elements like the line field. |
protected int | num_levels | The number of supported levels as reported by the compression engine. |
protected static int | At | |
protected static int | Bt | |
protected static int | Ac | |
protected static int | Bc | |
protected static int | Xprec | |
Methods from java.lang.Object: |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method from java.net.LinearInterpolator Detail: |
public int computeLevel(int dim) {
double a,b;
double[] data;
a=line[At];
b=line[Bt];
for (int i=num_levels-1; i >0; i--) {
data=levels[i];
if (dim >(a*data[Bc]+data[Bt])/(a*(1-data[Ac])-data[At]))
return i;
}
return 0;
}
This method choose the best level to use to compress data based on an iterative algorithm I did in
my thesis.
Basically it's a loop starting from the most compressing level downward and during every step
it calculates a threshold for the level and compares it with the dimension of the object to compress.
If the dimension is over the threshold, the level is selected.
If you are interested in the mathematical background behind the choice, see my mythesis . |
public boolean create(Integer num) {
num_levels=num.intValue();
line=new double[2];
levels=new double[num_levels][5];
for (int i=0; i< num_levels ;i++) {
levels[i][At]=1;
levels[i][Bt]=0;
levels[i][Ac]=1;
levels[i][Bc]=0;
levels[i][Xprec]=0;
}
return true;
}
This method is the real constructor and it's responsible for data allocation and initialization. |
public boolean destroy() {
return true;
}
Entry point for some explicit and synchronous clean up. |
public void finalize() throws Throwable {
if (destroy()==false)
throw new Exception("Unclean exception.");
}
|
public boolean update(int level,
int dim,
double compress_time,
double compress_dim,
double trans_time) {
D.p("update level "+level+" for dimension "+dim+" reduced in "+compress_dim+" just in "+compress_time+"ms and transmitted in "+trans_time+" ms");
String toPrint=Double.toString((1-(compress_time+trans_time)/((dim/compress_dim)*trans_time))*100);
D.p("current efficiency is "+toPrint.substring(0,Math.min(toPrint.length(),toPrint.indexOf('.')+3))+"%");
double[] data=levels[level];
double a,b,xprec;
xprec=data[Xprec];
updateLine(dim,trans_time,xprec);
if (level< 1) return true;
a=data[At];
b=data[Bt];
data[At]=(a*xprec+b-compress_time)/(xprec-compress_time);
data[Bt]=(compress_time-a*dim);
a=data[Ac];
b=data[Bc];
data[Ac]=(a*xprec+b-compress_dim)/(xprec-compress_dim);
data[Bc]=(compress_dim-a*dim);
data[Xprec]=dim;
levels[level]=data;
return true;
}
This method is responsible for updating the selected level model.
If you are interested in the mathematical aspect, see my thesis. |
public boolean updateLine(int dim,
double trans_time,
double Xprec) {
double a,b;
a=line[At];
b=line[Bt];
line[At]=(a*Xprec+b-trans_time)/(Xprec-dim);
line[Bt]=(trans_time-a*dim);
return true;
}
This method is responsible for updating the transmission line model.
If you are interested in the mathematical aspect, see my thesis. |