Commit 23f93486 authored by anIzycheva's avatar anIzycheva

taylor remainder is computed for initial input intervals now + moved function removeDeltasFromMap

parent 2a8f4fab
......@@ -266,7 +266,7 @@ object RelativeErrorPhase extends DaisyPhase with Taylor with ErrorFunctions{
// taylorFirst.foreach(x=>{reporter.debug(s"term is $x")})
reporter.info("Computing the error ...")
val taylorRemainder = getTaylorRemainder(relErrorExpr, newSet)
val taylorRemainder = getTaylorRemainder(relErrorExpr, inputValMap)
reporter.debug(s"The taylor remainder value is $taylorRemainder")
val errForSum = taylorFirst.map(x => {
......@@ -517,9 +517,6 @@ object RelativeErrorPhase extends DaisyPhase with Taylor with ErrorFunctions{
tmp <= 0
}
def removeDeltasFromMap(in: Map[Identifier, Interval]): Map[Identifier, Interval] ={
in.filterKeys(x => !x.isDeltaId)
}
private def mergeIntervals(listFailIntervals: Seq[Map[Identifier, Interval]],
inputMap: Map[Identifier, Interval]):
......
......@@ -133,7 +133,7 @@ object TaylorErrorPhase extends DaisyPhase with Taylor with ErrorFunctions {
}
// compute the remainder term for taylor series
val taylorRemainder = getTaylorRemainder(bodyDelta, Seq(inputValMap))
val taylorRemainder = getTaylorRemainder(bodyDelta, inputValMap)
reporter.debug(s"The taylor remainder value is $taylorRemainder")
// add the remainder to the error
val error = tmpErr.+(taylorRemainder.getOrElse(Rational.zero))
......
......@@ -467,10 +467,10 @@ trait Taylor{
/**
* Computes second derivative and evaluates the range with intervals
* @param e relative error expression
* @param intervals map with with subintervals for input vars
* @param intervals map with with intervals for input vars
* @return max estimated value for the
*/
def getTaylorRemainder(e:Expr, intervals: Seq[Map[Identifier, Interval]]): Option[Rational] = {
def getTaylorRemainder(e:Expr, intervals: Map[Identifier, Interval]): Option[Rational] = {
var secondDerivative: Option[Rational] = None
val simple = simplify(e)
......@@ -482,17 +482,12 @@ trait Taylor{
// second derivative
if (containsVariables(tmp, wrtIn.id)) {
val tmpIn = Times(wrt, Times(wrtIn, simplify(getPartialDerivative(tmp, wrtIn.id))))
val tmpVal = intervals.map(x => {
val interval = evaluateInterval(tmpIn, x)
if (interval.isDefined)
Some(maxAbs(interval.get))
else None
})
if (tmpVal.max(optionOrdering).isDefined)
val tmpVal = evaluateInterval(tmpIn, intervals)
if (tmpVal.isDefined)
if (secondDerivative.isDefined)
secondDerivative = Some(secondDerivative.get.+(tmpVal.max(optionOrdering).get))
secondDerivative = Some(secondDerivative.get.+(maxAbs(tmpVal.get)))
else
secondDerivative = Some(tmpVal.max(optionOrdering).get)
secondDerivative = Some(maxAbs(tmpVal.get))
}
})
})
......@@ -670,6 +665,16 @@ trait Taylor{
throw new IllegalArgumentException(s"Unknown expression $z. Parsing failed")
}
/**
* Removes deltas from input maps to avoid not necessary
* sub-division and reduce map dimension
* @param in map for variables and deltas
* @return map for variables
*/
def removeDeltasFromMap(in: Map[Identifier, Interval]): Map[Identifier, Interval] ={
in.filterKeys(x => !x.isDeltaId)
}
/**
* replaces all deltas in the expression with zeros
* @param expr - expression to replace deltas in
......
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