-
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
28 changed files
with
211 additions
and
234 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package genovese | ||
|
||
private[genovese] trait EvaluatorCompanion: | ||
val default = SequentialEvaluator |
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,20 @@ | ||
package genovese | ||
|
||
//> using dep "org.scala-lang.modules::scala-parallel-collections::1.0.4" | ||
|
||
object ParallelCollectionsEvaluator extends Evaluator: | ||
override def evaluate(pop: Population, fitness: Vec => NormalisedFloat): Evaluated = | ||
import scala.collection.parallel.CollectionConverters.* | ||
Evaluated( | ||
IArray.unsafeFromArray( | ||
IArray | ||
.genericWrapArray(pop) | ||
.toArray | ||
.par | ||
.map(vec => vec -> fitness(vec)) | ||
.toArray | ||
) | ||
) | ||
|
||
private[genovese] trait EvaluatorCompanion: | ||
val default = ParallelCollectionsEvaluator |
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,28 @@ | ||
package genovese | ||
|
||
import scala.reflect.ClassTag | ||
|
||
final case class EnumFeatureful[T](values: IArray[T]) extends Featureful[T]: | ||
private val lookup = values.zipWithIndex.toMap | ||
override lazy val features: IArray[Feature[?]] = IArray( | ||
Feature.IntCategory(List.tabulate(values.length)(identity)) | ||
) | ||
override def toFeatures(value: T)(using | ||
RuntimeChecks | ||
): IArray[NormalisedFloat] = | ||
features.map: | ||
case f @ Feature.IntCategory(_) => | ||
f.toNormalisedFloat(lookup(value)) | ||
|
||
override def fromFeatures( | ||
fv: IArray[NormalisedFloat] | ||
): T = | ||
features(0): @unchecked match | ||
case f @ Feature.IntCategory(_) => | ||
val idx = | ||
f.fromNormalisedFloat(NormalisedFloat.applyUnsafe(fv(0))) | ||
values(idx) | ||
|
||
override def toString(): String = s"EnumFeatureful(${values.mkString(",")})" | ||
end EnumFeatureful | ||
|
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,10 @@ | ||
package genovese | ||
|
||
trait Evaluator: | ||
def evaluate(population: Population, fitness: Vec => NormalisedFloat): Evaluated | ||
|
||
object Evaluator extends EvaluatorCompanion | ||
|
||
object SequentialEvaluator extends Evaluator: | ||
override def evaluate(population: Population, fitness: Vec => NormalisedFloat): Evaluated = | ||
Evaluated(population.map(v => v -> fitness(v))) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package genovese | ||
|
||
import scala.deriving.Mirror | ||
import scala.reflect.ClassTag | ||
import scala.util.boundary | ||
import scala.annotation.nowarn | ||
|
||
case class FieldConfig(overrides: Map[String, Feature[?]]) | ||
|
||
object FieldConfig: | ||
inline def None = FieldConfig(Map.empty) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,30 @@ | ||
package genovese | ||
|
||
import scala.deriving.Mirror | ||
import scala.reflect.ClassTag | ||
import scala.util.boundary | ||
import scala.annotation.nowarn | ||
|
||
final case class OptionFeatureful[T](original: Featureful[T]) | ||
extends Featureful[Option[T]]: | ||
override lazy val features: IArray[Feature[?]] = | ||
original.features.map(Feature.Optional(_)) | ||
override def fromFeatures(fv: IArray[NormalisedFloat]): Option[T] = | ||
boundary: | ||
val decompressed = fv.map: v => | ||
if v < 0.5f then boundary.break(None) | ||
else NormalisedFloat.applyUnsafe(2 * (v - 0.5f)) | ||
Some(original.fromFeatures(decompressed)) | ||
|
||
override def toFeatures(value: Option[T])(using | ||
RuntimeChecks | ||
): IArray[NormalisedFloat] = | ||
value match | ||
case None => | ||
IArray.fill(original.features.size)(NormalisedFloat.applyUnsafe(0.25f)) | ||
case Some(value) => | ||
original | ||
.toFeatures(value) | ||
.map(v => NormalisedFloat.applyUnsafe(v / 2 + 0.5f)) | ||
end OptionFeatureful | ||
|
File renamed without changes.
File renamed without changes.
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,13 @@ | ||
package genovese | ||
|
||
final case class SingleFeatureful[T](feature: Feature[T]) extends Featureful[T]: | ||
override val features: IArray[Feature[?]] = IArray(feature) | ||
|
||
override def toFeatures(value: T)(using | ||
RuntimeChecks | ||
): IArray[NormalisedFloat] = | ||
IArray(feature.toNormalisedFloat(value)) | ||
|
||
override def fromFeatures(fv: IArray[NormalisedFloat]): T = | ||
feature.fromNormalisedFloat(fv(0).asInstanceOf[NormalisedFloat]) | ||
end SingleFeatureful |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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.