Source code: marf/FeatureExtraction/MinMaxAmplitudes/MinMaxAmplitudes.java
1 package marf.FeatureExtraction.MinMaxAmplitudes;
2
3 import marf.FeatureExtraction.FeatureExtraction;
4 import marf.FeatureExtraction.FeatureExtractionException;
5 import marf.Preprocessing.IPreprocessing;
6 import marf.util.Arrays;
7 import marf.util.Debug;
8
9
10 /**
11 * <p>Min/Max Amplitudes.</p>
12 *
13 * <p>Extracts N minimum and X maximum amplitudes from a sample as features.
14 * If incoming sample array's length is less than N + X, it is adjusted
15 * to be N + X long with the length/2 value repeated N + X - length times.</p>
16 *
17 * <p>$Id: MinMaxAmplitudes.java,v 1.12 2005/08/13 23:09:37 susan_fan Exp $</p>
18 *
19 * TODO: needs improvement to select different amplitudes as we don't want
20 * 20 the same maximums or minimus if others are avaible.
21 *
22 * @author Serguei Mokhov
23 * @version $Revision: 1.12 $
24 * @since 0.3.0
25 */
26 public class MinMaxAmplitudes
27 extends FeatureExtraction
28 {
29 /**
30 * For serialization versioning.
31 * When adding new members or make other structural
32 * changes regenerate this number with the
33 * <code>serialver</code> tool that comes with JDK.
34 * @since 0.3.0.4
35 */
36 private static final long serialVersionUID = 5096308560737883614L;
37
38 /**
39 * Default number of minimums (amplitudes) to collect.
40 */
41 public static final int MIN_AMPLITUDES = 50;
42
43 /**
44 * Default number of maximums (amplitudes) to collect.
45 */
46 public static final int MAX_AMPLITUDES = 50;
47
48 /**
49 * MinMaxAmplitudes Constructor.
50 * @param poPreprocessing Preprocessing module reference
51 */
52 public MinMaxAmplitudes(IPreprocessing poPreprocessing)
53 {
54 super(poPreprocessing);
55 }
56
57 /**
58 * MinMaxAmplitudes implementation of <code>extractFeatures()</code>.
59 * @return <code>true</code> if features were extracted, <code>false</code> otherwise
60 * @throws FeatureExtractionException
61 */
62 public final boolean extractFeatures()
63 throws FeatureExtractionException
64 {
65 try
66 {
67 Debug.debug("MinMaxAmplitudes.extractFeatures() has begun...");
68
69 // Make a copy so we can sort.
70 double[] adSample = (double[])this.oPreprocessing.getSample().getSampleArray().clone();
71 Arrays.sort(adSample);
72
73 // Defaults
74 int iMinAmplitudes = MIN_AMPLITUDES;
75 int iMaxAmplitudes = MAX_AMPLITUDES;
76
77 this.adFeatures = new double[iMinAmplitudes + iMaxAmplitudes];
78
79 if(adSample.length < this.adFeatures.length)
80 {
81 // Initially fill with the middle value and copy the remaining halves.
82 Arrays.fill(this.adFeatures, adSample[adSample.length / 2]);
83
84 iMinAmplitudes = adSample.length / 2;
85 iMaxAmplitudes = adSample.length - iMinAmplitudes;
86 }
87
88 // Copy the first and the last portions as they are sorted
89 Arrays.copy(this.adFeatures, adSample, iMinAmplitudes);
90 Arrays.copy
91 (
92 this.adFeatures,
93 this.adFeatures.length - iMaxAmplitudes,
94 adSample,
95 adSample.length - iMaxAmplitudes,
96 iMaxAmplitudes
97 );
98
99 Debug.debug("MinMaxAmplitudes.extractFeatures() has finished.");
100 Debug.debug("MinMaxAmplitudes data: " + this);
101
102 return (this.adFeatures.length > 0);
103 }
104 catch(Exception e)
105 {
106 throw new FeatureExtractionException(e);
107 }
108 }
109
110 /**
111 * Creates String representation of the inner feature vector.
112 * @return min/max data in String format
113 */
114 public String toString()
115 {
116 return "Min/Max Data: " + Arrays.arrayToVector(this.adFeatures);
117 }
118
119 /**
120 * Returns source code revision information.
121 * @return revision string
122 */
123 public static String getMARFSourceCodeRevision()
124 {
125 return "$Revision: 1.12 $";
126 }
127 }
128
129 // EOF