Discrete Cosine Transform (DCT)
The Discrete Cosine Transform transforms a length N real-valued sequence in the time domain into another length N real-valued sequence in the frequency domain. A DCT class provides this functionality, implementing the DCT-II and scaling the result by 1/2β€“βˆš such that the representing matrix for the transform is unitary. No shift is applied to the transformed sequence (e.g. the 0th element of the transformed sequence is the 0th DCT coefficient and not the N/2th).
1
import org.apache.spark.ml.feature.DCT
2
import org.apache.spark.ml.linalg.Vectors
3
​
4
val data = Seq(
5
Vectors.dense(0.0, 1.0, -2.0, 3.0),
6
Vectors.dense(-1.0, 2.0, 4.0, -7.0),
7
Vectors.dense(14.0, -2.0, -5.0, 1.0))
8
​
9
val df = spark.createDataFrame(data.map(Tuple1.apply)).toDF("features")
10
​
11
val dct = new DCT()
12
.setInputCol("features")
13
.setOutputCol("featuresDCT")
14
.setInverse(false)
15
​
16
val dctDf = dct.transform(df)
17
dctDf.select("featuresDCT").show(false)
18
​
19
/*
20
Output:
21
+----------------------------------------------------------------+
22
|featuresDCT |
23
+----------------------------------------------------------------+
24
|[1.0,-1.1480502970952693,2.0000000000000004,-2.7716385975338604]|
25
|[-1.0,3.378492794482933,-7.000000000000001,2.9301512653149677] |
26
|[4.0,9.304453421915744,11.000000000000002,1.5579302036357163] |
27
+----------------------------------------------------------------+
28
​
29
*/
Copied!
Last modified 1yr ago
Copy link