Skip to content

Commit

Permalink
combinations #23, subsets #25
Browse files Browse the repository at this point in the history
  • Loading branch information
vsuthichai committed Aug 18, 2016
1 parent 4ea92e7 commit d770cbc
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
4 changes: 0 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>com.github.dpaukov</groupId>
<artifactId>combinatoricslib3</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ package com.eharmony.spotz.optimizer.hyperparam
import scala.collection.mutable
import scala.util.Random

trait CombinatoricRandomSampler[T] extends RandomSampler[Iterable[Iterable[T]]]
trait IterableRandomSampler[T] extends RandomSampler[Iterable[T]]

/**
*
* @param iterable
Expand Down Expand Up @@ -46,10 +43,9 @@ abstract class AbstractCombinations[T](

while (combo.size < k) {
val index = rng.nextInt(values.length)
val element = values(rng.nextInt(values.length))
if (!indices.contains(index)) {
indices.add(index)
combo.add(element)
combo.add(values(index))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ import scala.util.Random
trait RandomSampler[T] extends Serializable {
def apply(rng: Random): T
}

trait CombinatoricRandomSampler[T] extends RandomSampler[Iterable[Iterable[T]]]
trait IterableRandomSampler[T] extends RandomSampler[Iterable[T]]
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ package com.eharmony.spotz.optimizer.hyperparam
import scala.collection.mutable
import scala.util.Random

/**
*
* @param iterable
* @param k
* @param replacement
* @param ord
* @tparam T
*/
abstract class AbstractSubset[T](iterable: Iterable[T], k: Int, replacement: Boolean = false)(implicit ord: Ordering[T]) extends Serializable {
protected val values = iterable.toIndexedSeq

Expand All @@ -13,20 +21,27 @@ abstract class AbstractSubset[T](iterable: Iterable[T], k: Int, replacement: Boo

while (subset.size < sampleSize) {
val index = rng.nextInt(values.size)
val element = values(index)

if (replacement) {
subset.add(element)
subset.add(values(index))
} else if (!indices.contains(index)) {
indices.add(index)
subset.add(element)
subset.add(values(index))
}
}

subset.toIndexedSeq
}
}

/**
*
* @param iterable
* @param k
* @param replacement
* @param ord
* @tparam T
*/
case class Subset[T](
iterable: Iterable[T],
k: Int,
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@
<joda.convert.version>1.8.1</joda.convert.version>
<vfs2.version>2.1</vfs2.version>
<slf4j.version>1.7.21</slf4j.version>
<combinatoricslib3.version>3.0.0</combinatoricslib3.version>
<logback.classic.version>1.1.7</logback.classic.version>
<junit.version>4.11</junit.version>
<hamcrest.version>1.3</hamcrest.version>
Expand Down

0 comments on commit d770cbc

Please sign in to comment.