KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > JSci > maths > wavelet > DiscreteFunction


1 package JSci.maths.wavelet;
2
3 import JSci.maths.*;
4 import JSci.maths.vectors.AbstractDoubleVector;
5 import JSci.maths.vectors.DoubleVector;
6 import JSci.util.*;
7 import java.util.Arrays JavaDoc;
8
9 /**********************************************
10 * This class is used to be able to mix the wavelet
11 * and other type of functions such as given signals.
12 * @author Daniel Lemire
13 *************************************************/

14 public class DiscreteFunction extends MultiscaleFunction implements Cloneable JavaDoc {
15         protected AbstractDoubleVector data;
16
17         public DiscreteFunction(double[] v) {
18         setData(v);
19     }
20     public void setData (double[] v) {
21         data = new DoubleVector(v);
22     }
23   /*******************************
24   * Return a String representation
25   * of the object
26   ********************************/

27   public String JavaDoc toString() {
28     return(data.toString());
29   }
30   /**********************
31   * Makes the L2 norm of the
32   * internal array equal to 1.
33   ***********************/

34   public final void normalize() {
35     data = data.normalize();
36   }
37
38     /************************************************
39   * Return as an array the sampled values
40   * of the function
41     *************************************************/

42     public final double[] evaluate() {
43         return(VectorToolkit.toArray(data));
44     }
45
46   /*****************************************
47   * Check if another object is equal to this
48   * DiscreteFunction object
49   ******************************************/

50   public final boolean equals(Object JavaDoc a) {
51     if((a!=null) && (a instanceof DiscreteFunction)) {
52       DiscreteFunction iv=(DiscreteFunction)a;
53         return data.equals(iv.data);
54     }
55     return false;
56   }
57     /************************************************
58   * Return as an array the sampled values
59   * of the function
60   * @param j number of iterations (doesn't do anything)
61     *************************************************/

62     public double[] evaluate (int j) {
63         return(evaluate());
64     }
65   /******************************************
66   * Compute the mass (integral)
67   * @param a left boundary of the interval
68   * @param b right boundary of the interval
69   * @param jfin number of iterations to consider
70   * (precision)
71   **********************************************/

72     public double mass(double a, double b, int jfin) {
73                 return data.mass()/(data.dimension()-1)*Math.abs(b-a);
74     }
75     /***************************
76   * Compute the L2 norm of the
77   * signal
78     ****************************/

79   public final double norm () {
80     return(data.norm());
81   }
82     /***************************
83   * Compute the L2 norm of the
84   * function
85   * @param j number of iterations
86     ****************************/

87   public double norm (int j) {
88     return(data.norm());
89   }
90   /********************************************
91   * Return a copy of this object
92   *********************************************/

93     public Object JavaDoc clone() {
94     DiscreteFunction df=(DiscreteFunction) super.clone();
95     df.setData(VectorToolkit.toArray(data));
96     return(df);
97     }
98   /*****************************************
99   * Tells you how many samples you'll get
100   * from this function (will not depend
101   * on the parameter)
102   ******************************************/

103     public int dimension(int jfin) {
104         return(data.dimension());
105     }
106   /*****************************************
107   * Tells you how many samples you'll get
108   * from this function
109   ******************************************/

110     public final int dimension() {
111         return(data.dimension());
112     }
113     /****************************************
114   * This method is used to compute
115   * how the number of scaling functions
116   * changes from on scale to the other.
117   * Basically, if you have k scaling
118   * function and a Filter of type t, you'll
119   * have 2*k+t scaling functions at the
120   * next scale (dyadic case).
121   * Notice that this method assumes
122   * that one is working with the dyadic
123   * grid while the method "previousDimension"
124   * define in the interface "Filter" doesn't.
125     ******************************************/

126     public int getFilterType () {
127         return(data.dimension());
128     }
129 }
130
131
Popular Tags