
it.unibo.scafi.lib.Gradients.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scafi-core_2.13 Show documentation
Show all versions of scafi-core_2.13 Show documentation
An aggregate programming toolkit on the JVM
The newest version!
/*
* Copyright (C) 2016-2019, Roberto Casadei, Mirko Viroli, and contributors.
* See the LICENSE file distributed with this work for additional information regarding copyright ownership.
*/
package it.unibo.scafi.lib
trait StdLib_Gradients {
self: StandardLibrary.Subcomponent =>
type Metric = ()=>Double
trait Gradients {
self: FieldCalculusSyntax with StandardSensors =>
case class Gradient(algorithm: (Boolean,()=>Double)=>Double, source: Boolean=false, metric: Metric = nbrRange) {
def from(s: Boolean): Gradient = this.copy(source = s)
def withMetric(m: Metric): Gradient = this.copy(metric = m)
def run(): Double = algorithm(source, metric)
}
val ClassicGradient = Gradient(classicGradient(_,_), false, nbrRange)
def classicGradient(source: Boolean, metric: () => Double = nbrRange): Double =
rep(Double.PositiveInfinity){ case d =>
mux(source){ 0.0 }{ minHoodPlus(nbr(d) + metric()) }
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy