Commit cb25a81e authored by Anastasiia's avatar Anastasiia

always subdivide for taylor remainder fixed amount of times

parent cbcc52d7
......@@ -219,7 +219,13 @@ object RelativeErrorPhase extends DaisyPhase with Taylor with ErrorFunctions{
}
private def getEqualSubintervals(inputValMap: Map[Identifier, Interval]): Seq[Map[Identifier, Interval]] = {
private def getEqualSubintervals(inputValMap: Map[Identifier, Interval],
divParameter: Int = 0):
Seq[Map[Identifier, Interval]] = {
val split = if (divParameter!=0)
divParameter
else
Math.pow(2, divLimit).toInt
var srcCartesian: Map[Identifier, Seq[Interval]] = Map.empty
// set of vectors. each vector contains the maps for one var
for (inputVal <- inputValMap ){
......@@ -228,7 +234,7 @@ object RelativeErrorPhase extends DaisyPhase with Taylor with ErrorFunctions{
}
else {
val (id, interval) = inputVal
val oneVar = interval.divide(Math.pow(2, divLimit).toInt)
val oneVar = interval.divide(split)
srcCartesian += (id -> oneVar)
}
}
......@@ -267,7 +273,8 @@ 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, inputValMap)
val remainderMap = getEqualSubintervals(inputValMap, 3)
val taylorRemainder = getTaylorRemainder(relErrorExpr, remainderMap)
reporter.info(s"The taylor remainder value is $taylorRemainder")
val errForSum = taylorFirst.map(x => {
......
......@@ -39,7 +39,7 @@ object TaylorErrorPhase extends DaisyPhase with Taylor with ErrorFunctions {
override def run(ctx: Context, prg: Program): (Context, Program) = {
reporter = ctx.reporter
reporter.info(s"\nStarting $name")
val timer = ctx.timers.relError.start
val timer = ctx.timers.taylor.start
// default range method: intervals
var rangeMethod = "interval"
var errorMethod = "affine" // only one supported so far
......@@ -135,7 +135,7 @@ object TaylorErrorPhase extends DaisyPhase with Taylor with ErrorFunctions {
}
// compute the remainder term for taylor series
val taylorRemainder = getTaylorRemainder(bodyDelta, inputValMap)
val taylorRemainder = getTaylorRemainder(bodyDelta, Seq(inputValMap))
reporter.debug(s"The taylor remainder value is $taylorRemainder")
// add the remainder to the error
val error = tmpErr.+(taylorRemainder.getOrElse(Rational.zero))
......
......@@ -470,7 +470,7 @@ trait Taylor{
* @param intervals map with with intervals for input vars
* @return max estimated value for the
*/
def getTaylorRemainder(e:Expr, intervals: Map[Identifier, Interval]): Option[Rational] = {
def getTaylorRemainder(e:Expr, intervals: Seq[Map[Identifier, Interval]]): Option[Rational] = {
var secondDerivative: Option[Rational] = None
val simple = simplify(e)
......@@ -482,12 +482,17 @@ trait Taylor{
// second derivative
if (containsVariables(tmp, wrtIn.id)) {
val tmpIn = Times(wrt, Times(wrtIn, simplify(getPartialDerivative(tmp, wrtIn.id))))
val tmpVal = evaluateInterval(tmpIn, intervals)
if (tmpVal.isDefined)
val tmpVal = intervals.map(x => {
val interval = evaluateInterval(tmpIn, x)
if (interval.isDefined)
Some(maxAbs(interval.get))
else None
})//evaluateInterval(tmpIn, intervals)
if (tmpVal.max(optionOrdering).isDefined)
if (secondDerivative.isDefined)
secondDerivative = Some(secondDerivative.get.+(maxAbs(tmpVal.get)))
secondDerivative = Some(secondDerivative.get.+(tmpVal.max(optionOrdering).get))
else
secondDerivative = Some(maxAbs(tmpVal.get))
secondDerivative = Some(tmpVal.max(optionOrdering).get)
}
})
})
......
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