Commit 15735196 authored by Anastasiia's avatar Anastasiia

Merge branch 'relative' into 'relative'

added parameter for subdividing the remainder

See merge request !101
parents ba5e1fb4 242e2b96
......@@ -38,6 +38,7 @@ object RelativeErrorPhase extends DaisyPhase with Subdivision with ErrorFunction
// default parameters for the complete run
var divLimit = 3
var divRemainder = 0
var rangeMethod = "interval"
var subdiv = "simple"
var approach = "taylor"
......@@ -49,6 +50,7 @@ object RelativeErrorPhase extends DaisyPhase with Subdivision with ErrorFunction
ChoiceOptionDef("rel-rangeMethod", "Method to use for range analysis",
Set("affine", "interval", "smtreuse", "smtredo", "smtcomplete"), "interval"),
ParamOptionDef("divLimit", "Max amount of interval divisions", divLimit.toString),
ParamOptionDef("divRemainder", "Max amount of interval divisions for remainder term", divRemainder.toString),
ChoiceOptionDef("subdiv", "Method to subdivide intervals", Set("simple", "model"), "simple"),
ChoiceOptionDef("approach", "Approach for expressions", Set("taylor", "naive"), "taylor"),
// fixme change name to not overlap with RangeErrorPhase or put into Main
......@@ -71,6 +73,7 @@ object RelativeErrorPhase extends DaisyPhase with Subdivision with ErrorFunction
// process relevant options
for (opt <- ctx.options) opt match {
case ParamOption("divLimit", value) => divLimit = value.toInt
case ParamOption("divRemainder", value) => divRemainder = value.toInt
case ChoiceOption("rel-rangeMethod", s) => s match {
case "interval" | "affine" | "smtreuse" | "smtredo" | "smtcomplete" =>
rangeMethod = s
......@@ -143,7 +146,7 @@ object RelativeErrorPhase extends DaisyPhase with Subdivision with ErrorFunction
for (mapEntry <- list) {
// here we compute the abs error for intervals where rel error is not possible
//todo put abs error computation back
val absError = Rational.zero//getAbsError(bodyReal, mapEntry, inputErrorMap, uniformPrecision)
val absError = getAbsError(bodyReal, mapEntry, inputErrorMap, uniformPrecision)
reporter.info(s"For intervals $mapEntry, absError: $absError, time: " +
(System.currentTimeMillis - time))
}
......@@ -180,7 +183,7 @@ object RelativeErrorPhase extends DaisyPhase with Subdivision with ErrorFunction
bodyReal: Expr,
ctx: Context ): (Option[Rational], Seq[Map[Identifier, Interval]]) = {
var listFailInterval: Seq[Map[Identifier, Interval]] = Seq.empty
var finalErr: Option[Rational] = None
// get intervals subdivision for the complete divLimit
val newSet = getSubintervals(inputValMap, bodyReal, ctx, subdiv, divLimit)
......@@ -200,43 +203,46 @@ object RelativeErrorPhase extends DaisyPhase with Subdivision with ErrorFunction
reporter.info("Computing the error ...")
// fixme for div-by-zero benchmarks subdivision parameter should be greater than 0
val remainderMap = getEqualSubintervals(inputValMap, divLimit, 0)
reporter.info(s"subdiv for remainder $divRemainder")
val remainderMap = getEqualSubintervals(inputValMap, divLimit, divRemainder)
val taylorRemainder = getTaylorRemainder(relErrorExpr, remainderMap)
reporter.info(s"The taylor remainder value is $taylorRemainder")
if (taylorRemainder.isDefined) {
val errForSum = taylorFirst.map(x => {
val (expr, wrt) = x
val tmpExpr = moreSimplify(
Times(replaceDeltasWithZeros(expr), Delta(wrt)))
reporter.debug(s"Evaluate the term $tmpExpr")
// do not call evaluation function on all subintervals
// if simplified expression is delta or RealLiteral
val tmpForMax = tmpExpr match {
case x@Delta(id) => List(evaluateOpt(tmpExpr, inputValMap, rangeMethod))
case x@Epsilon(id) => List(evaluateOpt(tmpExpr, inputValMap, rangeMethod))
case x@Variable(id) => List(evaluateOpt(tmpExpr, inputValMap, rangeMethod))
case x@RealLiteral(r) => List(evaluateOpt(tmpExpr, inputValMap, rangeMethod))
case _ => newSet.map(interval => {
val tmp = evaluateOpt(tmpExpr, interval, rangeMethod)
reporter.debug("err on " + removeDeltasFromMap(interval) + s" is $tmp")
if (tmp.isEmpty)
if (!listFailInterval.contains(interval)) listFailInterval = listFailInterval :+ interval
tmp
})
}
tmpForMax.max(optionAbsOrdering)
})
reporter.debug(s"we need to sum $errForSum")
val errForSum = taylorFirst.map(x => {
val (expr, wrt) = x
val tmpExpr = moreSimplify(
Times(replaceDeltasWithZeros(expr), Delta(wrt)))
reporter.debug(s"Evaluate the term $tmpExpr")
// do not call evaluation function on all subintervals
// if simplified expression is delta or RealLiteral
val tmpForMax = tmpExpr match {
case x @ Delta(id) => List(evaluateOpt(tmpExpr, inputValMap, rangeMethod))
case x @ Epsilon(id) => List(evaluateOpt(tmpExpr, inputValMap, rangeMethod))
case x @ Variable(id) => List(evaluateOpt(tmpExpr, inputValMap, rangeMethod))
case x @ RealLiteral(r) => List(evaluateOpt(tmpExpr, inputValMap, rangeMethod))
case _ => newSet.map(interval => {
val tmp = evaluateOpt(tmpExpr, interval, rangeMethod)
reporter.debug("err on "+removeDeltasFromMap(interval)+s" is $tmp")
if (tmp.isEmpty)
if (!listFailInterval.contains(interval)) listFailInterval = listFailInterval :+ interval
tmp
})
}
tmpForMax.max(optionAbsOrdering)
})
reporter.debug(s"we need to sum $errForSum")
var finalErr: Option[Rational] = None
errForSum.foreach(x => {
if (finalErr.isDefined)
finalErr = Some(finalErr.get.+(x.getOrElse(Rational.zero)))
else
finalErr = x
errForSum.foreach(x => {
if (finalErr.isDefined)
finalErr = Some(finalErr.get.+(x.getOrElse(Rational.zero)))
else
finalErr = x
})
if (finalErr.isDefined)
finalErr = Some(finalErr.get.+(taylorRemainder.getOrElse(Rational.zero)))
if (finalErr.isDefined)
finalErr = Some(finalErr.get.+(taylorRemainder.getOrElse(Rational.zero)))
}
listFailInterval = (listFailInterval ++ listFailed).toSet.toList
(finalErr, listFailInterval)
}
......
......@@ -22,6 +22,9 @@ trait Taylor{
var reporter: Reporter
var denormals: Boolean
var listFailed: List[Map[Identifier, Interval]] = List.empty
implicit val debugSection = DebugSectionAnalysis
implicit val zero = RealLiteral(Rational.zero)
......@@ -708,7 +711,10 @@ trait Taylor{
val interval = evaluateInterval(tmpIn, x)
if (interval.isDefined)
Some(maxAbs(interval.get))
else None
else {
listFailed = listFailed :+ x
None
}
})
tmpVal.max(optionAbsOrdering)
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment