All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.aiddl.common.scala.learning.testing.FoldDivider.scala Maven / Gradle / Ivy

Go to download

Provides common types and algorithm implementations for the fast prototyping integrative AI systems with the AIDDL framework.

The newest version!
package org.aiddl.common.scala.learning.testing

import org.aiddl.core.scala.function.Function
import org.aiddl.core.scala.representation.*

class FoldDivider extends Function {
  override def apply(x: Term): Term = {
    val fold = x(Sym("fold")).intoInt
    val numFolds = x.getOrElse(Sym("num-folds"), Num(10)).intoInt
    val data = x(Sym("data")).asList

    val (test, train) = this(fold, numFolds, data)
    Tuple(test, train)
  }

  def apply(fold: Int, numFolds: Int, data: ListTerm): (ListTerm, ListTerm) = {
    val (test, train) = data
      .zipWithIndex
      .partition( (x, i) => i%numFolds == fold )

    (
      ListTerm(test.map((x, _) => x)),
      ListTerm(train.map((x, _) => x))
    )
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy