Skip to content

Commit cd86252

Browse files
Add @SInCE tags to mllib.fpm
1 parent d538919 commit cd86252

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

mllib/src/main/scala/org/apache/spark/mllib/fpm/AssociationRules.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,24 @@ import org.apache.spark.rdd.RDD
3131
*
3232
* Generates association rules from a [[RDD[FreqItemset[Item]]]. This method only generates
3333
* association rules which have a single item as the consequent.
34+
*
35+
* @since 1.5.0
3436
*/
3537
@Experimental
3638
class AssociationRules private[fpm] (
3739
private var minConfidence: Double) extends Logging with Serializable {
3840

3941
/**
4042
* Constructs a default instance with default parameters {minConfidence = 0.8}.
43+
*
44+
* @since 1.5.0
4145
*/
4246
def this() = this(0.8)
4347

4448
/**
4549
* Sets the minimal confidence (default: `0.8`).
50+
*
51+
* @since 1.5.0
4652
*/
4753
def setMinConfidence(minConfidence: Double): this.type = {
4854
require(minConfidence >= 0.0 && minConfidence <= 1.0)
@@ -54,6 +60,8 @@ class AssociationRules private[fpm] (
5460
* Computes the association rules with confidence above [[minConfidence]].
5561
* @param freqItemsets frequent itemset model obtained from [[FPGrowth]]
5662
* @return a [[Set[Rule[Item]]] containing the assocation rules.
63+
*
64+
* @since 1.5.0
5765
*/
5866
def run[Item: ClassTag](freqItemsets: RDD[FreqItemset[Item]]): RDD[Rule[Item]] = {
5967
// For candidate rule X => Y, generate (X, (Y, freq(X union Y)))
@@ -90,6 +98,8 @@ object AssociationRules {
9098
* @param antecedent hypotheses of the rule
9199
* @param consequent conclusion of the rule
92100
* @tparam Item item type
101+
*
102+
* @since 1.5.0
93103
*/
94104
@Experimental
95105
class Rule[Item] private[fpm] (

mllib/src/main/scala/org/apache/spark/mllib/fpm/FPGrowth.scala

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@ import org.apache.spark.storage.StorageLevel
3838
* Model trained by [[FPGrowth]], which holds frequent itemsets.
3939
* @param freqItemsets frequent itemset, which is an RDD of [[FreqItemset]]
4040
* @tparam Item item type
41+
*
42+
* @since 1.5.0
4143
*/
4244
@Experimental
4345
class FPGrowthModel[Item: ClassTag](val freqItemsets: RDD[FreqItemset[Item]]) extends Serializable {
4446
/**
4547
* Generates association rules for the [[Item]]s in [[freqItemsets]].
4648
* @param confidence minimal confidence of the rules produced
49+
* @since 1.5.0
4750
*/
4851
def generateAssociationRules(confidence: Double): RDD[AssociationRules.Rule[Item]] = {
4952
val associationRules = new AssociationRules(confidence)
@@ -67,6 +70,8 @@ class FPGrowthModel[Item: ClassTag](val freqItemsets: RDD[FreqItemset[Item]]) ex
6770
*
6871
* @see [[http://en.wikipedia.org/wiki/Association_rule_learning Association rule learning
6972
* (Wikipedia)]]
73+
*
74+
* @since 1.5.0
7075
*/
7176
@Experimental
7277
class FPGrowth private (
@@ -76,11 +81,15 @@ class FPGrowth private (
7681
/**
7782
* Constructs a default instance with default parameters {minSupport: `0.3`, numPartitions: same
7883
* as the input data}.
84+
*
85+
* @since 1.5.0
7986
*/
8087
def this() = this(0.3, -1)
8188

8289
/**
8390
* Sets the minimal support level (default: `0.3`).
91+
*
92+
* @since 1.5.0
8493
*/
8594
def setMinSupport(minSupport: Double): this.type = {
8695
this.minSupport = minSupport
@@ -89,6 +98,8 @@ class FPGrowth private (
8998

9099
/**
91100
* Sets the number of partitions used by parallel FP-growth (default: same as input data).
101+
*
102+
* @since 1.5.0
92103
*/
93104
def setNumPartitions(numPartitions: Int): this.type = {
94105
this.numPartitions = numPartitions
@@ -99,6 +110,8 @@ class FPGrowth private (
99110
* Computes an FP-Growth model that contains frequent itemsets.
100111
* @param data input data set, each element contains a transaction
101112
* @return an [[FPGrowthModel]]
113+
*
114+
* @since 1.5.0
102115
*/
103116
def run[Item: ClassTag](data: RDD[Array[Item]]): FPGrowthModel[Item] = {
104117
if (data.getStorageLevel == StorageLevel.NONE) {
@@ -123,6 +136,8 @@ class FPGrowth private (
123136
* @param minCount minimum count for frequent itemsets
124137
* @param partitioner partitioner used to distribute items
125138
* @return array of frequent pattern ordered by their frequencies
139+
*
140+
* @since 1.5.0
126141
*/
127142
private def genFreqItems[Item: ClassTag](
128143
data: RDD[Array[Item]],
@@ -149,6 +164,8 @@ class FPGrowth private (
149164
* @param freqItems frequent items
150165
* @param partitioner partitioner used to distribute transactions
151166
* @return an RDD of (frequent itemset, count)
167+
*
168+
* @since 1.5.0
152169
*/
153170
private def genFreqItemsets[Item: ClassTag](
154171
data: RDD[Array[Item]],
@@ -174,6 +191,8 @@ class FPGrowth private (
174191
* @param itemToRank map from item to their rank
175192
* @param partitioner partitioner used to distribute transactions
176193
* @return a map of (target partition, conditional transaction)
194+
*
195+
* @since 1.5.0
177196
*/
178197
private def genCondTransactions[Item: ClassTag](
179198
transaction: Array[Item],
@@ -199,6 +218,8 @@ class FPGrowth private (
199218

200219
/**
201220
* :: Experimental ::
221+
*
222+
* @since 1.5.0
202223
*/
203224
@Experimental
204225
object FPGrowth {
@@ -208,11 +229,15 @@ object FPGrowth {
208229
* @param items items in this itemset. Java users should call [[FreqItemset#javaItems]] instead.
209230
* @param freq frequency
210231
* @tparam Item item type
232+
*
233+
* @since 1.5.0
211234
*/
212235
class FreqItemset[Item](val items: Array[Item], val freq: Long) extends Serializable {
213236

214237
/**
215238
* Returns items in a Java List.
239+
*
240+
* @since 1.5.0
216241
*/
217242
def javaItems: java.util.List[Item] = {
218243
items.toList.asJava

mllib/src/main/scala/org/apache/spark/mllib/fpm/FPTree.scala

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import scala.collection.mutable.ListBuffer
2323
/**
2424
* FP-Tree data structure used in FP-Growth.
2525
* @tparam T item type
26+
*
27+
* @since 1.5.0
2628
*/
2729
private[fpm] class FPTree[T] extends Serializable {
2830

@@ -32,7 +34,11 @@ private[fpm] class FPTree[T] extends Serializable {
3234

3335
private val summaries: mutable.Map[T, Summary[T]] = mutable.Map.empty
3436

35-
/** Adds a transaction with count. */
37+
/**
38+
* Adds a transaction with count.
39+
*
40+
* @since 1.5.0
41+
*/
3642
def add(t: Iterable[T], count: Long = 1L): this.type = {
3743
require(count > 0)
3844
var curr = root
@@ -52,15 +58,23 @@ private[fpm] class FPTree[T] extends Serializable {
5258
this
5359
}
5460

55-
/** Merges another FP-Tree. */
61+
/**
62+
* Merges another FP-Tree.
63+
*
64+
* @since 1.5.0
65+
*/
5666
def merge(other: FPTree[T]): this.type = {
5767
other.transactions.foreach { case (t, c) =>
5868
add(t, c)
5969
}
6070
this
6171
}
6272

63-
/** Gets a subtree with the suffix. */
73+
/**
74+
* Gets a subtree with the suffix.
75+
*
76+
* @since 1.5.0
77+
*/
6478
private def project(suffix: T): FPTree[T] = {
6579
val tree = new FPTree[T]
6680
if (summaries.contains(suffix)) {
@@ -78,10 +92,18 @@ private[fpm] class FPTree[T] extends Serializable {
7892
tree
7993
}
8094

81-
/** Returns all transactions in an iterator. */
95+
/**
96+
* Returns all transactions in an iterator.
97+
*
98+
* @since 1.5.0
99+
*/
82100
def transactions: Iterator[(List[T], Long)] = getTransactions(root)
83101

84-
/** Returns all transactions under this node. */
102+
/**
103+
* Returns all transactions under this node.
104+
*
105+
* @since 1.5.0
106+
*/
85107
private def getTransactions(node: Node[T]): Iterator[(List[T], Long)] = {
86108
var count = node.count
87109
node.children.iterator.flatMap { case (item, child) =>
@@ -98,7 +120,11 @@ private[fpm] class FPTree[T] extends Serializable {
98120
}
99121
}
100122

101-
/** Extracts all patterns with valid suffix and minimum count. */
123+
/**
124+
* Extracts all patterns with valid suffix and minimum count.
125+
*
126+
* @since 1.5.0
127+
*/
102128
def extract(
103129
minCount: Long,
104130
validateSuffix: T => Boolean = _ => true): Iterator[(List[T], Long)] = {
@@ -117,7 +143,11 @@ private[fpm] class FPTree[T] extends Serializable {
117143

118144
private[fpm] object FPTree {
119145

120-
/** Representing a node in an FP-Tree. */
146+
/**
147+
* Representing a node in an FP-Tree.
148+
*
149+
* @since 1.5.0
150+
*/
121151
class Node[T](val parent: Node[T]) extends Serializable {
122152
var item: T = _
123153
var count: Long = 0L
@@ -126,7 +156,11 @@ private[fpm] object FPTree {
126156
def isRoot: Boolean = parent == null
127157
}
128158

129-
/** Summary of a item in an FP-Tree. */
159+
/**
160+
* Summary of a item in an FP-Tree.
161+
*
162+
* @since 1.5.0
163+
*/
130164
private class Summary[T] extends Serializable {
131165
var count: Long = 0L
132166
val nodes: ListBuffer[Node[T]] = ListBuffer.empty

0 commit comments

Comments
 (0)