Skip to content

Instantly share code, notes, and snippets.

@fgcallari
Last active March 11, 2016 13:56
package org.somelightprojections.skeres
import scala.reflect.ClassTag
import spire.algebra.{Trig, Field}
// Generic autodifferentiable cost functor:
// kNumResiduals: output dimension.
// N: sequence of integers, ordinately equal to the
// dimensions of the parameters blocks.
abstract class CostFunctor(val kNumResiduals: Int, val N: Int*) {
require(kNumResiduals > 0, s"Nonpositive number of residuals specified: $kNumResiduals")
require(N.forall(_ > 0), s"Nonpositive parameter block sizes specified: ${N.mkString(", ")}")
// Returns an auto-differentiable cost function computed through this functor.
def toAutodiffCostFunction = AutodiffCostFunction(this)
// Evaluate the functor on a sequence of N.length parameter blocks, ordinately of N(k) size,
// for k = 0, 1, ..., N.length.
def apply[@specialized(Double) T : Field : Trig : ClassTag](x: Array[T]*): Array[T]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment