-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
301 additions
and
338 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 4 additions & 4 deletions
8
src/main/scala/eu/easyminer/discretization/algorithm/CutpointsResolver.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 18 additions & 14 deletions
32
src/main/scala/eu/easyminer/discretization/algorithm/EquidistantIntervals.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,29 @@ | ||
package eu.easyminer.discretization.algorithm | ||
|
||
import eu.easyminer.discretization.impl.{ExclusiveIntervalBound, InclusiveIntervalBound, Interval} | ||
import eu.easyminer.discretization.{impl, _} | ||
import eu.easyminer.discretization.impl | ||
import eu.easyminer.discretization.impl.{Interval, IntervalBound} | ||
|
||
/** | ||
* Created by propan on 17. 3. 2017. | ||
*/ | ||
class EquidistantIntervals[T] private[algorithm](bins: Int)(implicit val n: Numeric[T]) extends Discretization[T] { | ||
|
||
def discretize(data: Iterable[T]): Seq[impl.Interval] = data.iterator | ||
.map(x => (x, x)) | ||
.reduceOption((x, y) => n.min(x._1, y._1) -> n.max(x._2, y._2)) | ||
.map(x => n.toDouble(x._1) -> n.toDouble(x._2)) | ||
.toList | ||
.flatMap { case (min, max) => | ||
val intervalSize = (max - min) / bins | ||
for (binNumber <- 0 until bins) yield { | ||
val leftBound = InclusiveIntervalBound(min + intervalSize * binNumber) | ||
val rightBound = if (binNumber + 1 == bins) InclusiveIntervalBound(max) else ExclusiveIntervalBound(leftBound.value + intervalSize) | ||
Interval(leftBound, rightBound) | ||
} | ||
def discretize(data: Traversable[T]): Traversable[impl.Interval] = new Traversable[impl.Interval] { | ||
def foreach[U](f: Interval => U): Unit = { | ||
data.view | ||
.map(x => (x, x)) | ||
.reduceOption((x, y) => n.min(x._1, y._1) -> n.max(x._2, y._2)) | ||
.map(x => n.toDouble(x._1) -> n.toDouble(x._2)) | ||
.toIterator | ||
.flatMap { case (min, max) => | ||
val intervalSize = (max - min) / bins | ||
for (binNumber <- 0 until bins) yield { | ||
val leftBound = IntervalBound.Inclusive(min + intervalSize * binNumber) | ||
val rightBound = if (binNumber + 1 == bins) IntervalBound.Inclusive(max) else IntervalBound.Exclusive(leftBound.value + intervalSize) | ||
Interval(leftBound, rightBound) | ||
} | ||
}.foreach(f) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/scala/eu/easyminer/discretization/impl/IntervalFrequency.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package eu.easyminer.discretization.impl | ||
|
||
/** | ||
* Created by Vaclav Zeman on 16. 2. 2018. | ||
*/ | ||
case class IntervalFrequency(interval: Interval, frequency: Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
src/main/scala/eu/easyminer/discretization/impl/PersistentNumericIterable.scala
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/main/scala/eu/easyminer/discretization/impl/PersistentNumericTraversable.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package eu.easyminer.discretization.impl | ||
|
||
import java.io._ | ||
|
||
import eu.easyminer.discretization.util.NumericByteArray._ | ||
import eu.easyminer.discretization.util.PersistentTraversableOps._ | ||
|
||
/** | ||
* Created by propan on 17. 3. 2017. | ||
*/ | ||
class PersistentNumericTraversable[T] private(col: Traversable[T], file: File)(implicit n: Numeric[T]) extends Traversable[T] { | ||
//implicit private val b2n: Array[Byte] => T = byteArrayToNumber[T] | ||
def foreach[U](f: T => U): Unit = if (file.exists()) inputStreamTraversable[T](new FileInputStream(file)).foreach(f) else outputStreamTraversable(col, new FileOutputStream(file)) | ||
} | ||
|
||
object PersistentNumericTraversable { | ||
|
||
def apply[A, B](col: Traversable[A], file: File)(f: Traversable[A] => B)(implicit n: Numeric[A]): B = { | ||
val pni = new PersistentNumericTraversable(col, file) | ||
try { | ||
f(pni) | ||
} finally { | ||
file.delete() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.