argiopetech / base

Bayesian Analysis for Stellar Evolution
http://webfac.db.erau.edu/~vonhippt/base9/
11 stars 4 forks source link

Configurable Interp/Extrap #41

Closed argiopetech closed 11 years ago

argiopetech commented 11 years ago

Description

Expand the capabilities of the current interpExtrap code to include specification of where (or if) extrapolation is allowed to occur. The function should return an object containing the value and the method used to obtain that value.

Specification

We need the C++ equivalent of this Haskell code:

data Method = Interp | Extrap | ExtrapOnly Direction

data Result = OnGrid Double
            | Pinned Direction Double
            | Extrapolated Direction Double

data Direction = High | Low

type LowerBound = Double
type UpperBound = Double

-- A bounded range
type Range = (LowerBound, UpperBound)

linearMapping :: Method -- ^ Whether to interpolate, extrapolate, or extrapolate in a single direction
              -> Range  -- ^ Value range
              -> Range  -- ^ interp/extrap range
              -> Double -- ^ Actual value
              -> Result -- ^ Interpolated/Extrapolated value
linearMapping m (xL, xH) (yL, yH) xActual =
    case m of
      Extrap | xActual > xH -> Extrapolated High linInterpExtrap
             | xActual < xL -> Extrapolated Low  linInterpExtrap
             | otherwise    -> OnGrid linInterpExtrap
      Interp | xActual > xH -> Pinned High yH
             | xActual < xL -> Pinned Low  yL
             | otherwise    -> OnGrid linInterpExtrap
      (ExtrapOnly High) | xActual > xH -> Extrapolated High linInterpExtrap
                        | xActual < xL -> Pinned Low yL
                        | otherwise    -> OnGrid linInterpExtrap
      (ExtrapOnly Low)  | xActual > xH -> Pinned High yH
                        | xActual < xL -> Extrapolated Low linInterpExtrap
                        | otherwise    -> OnGrid linInterpExtrap
    where linInterpExtrap = let position = (xActual - xL) / (xH - xL)
                            in yL + position * (yH - yL)

Levels of concern

  1. Minimal concern Eventually want to to note occurrence in verbose mode.
    • extrapolating off the young side of a WD model
  2. Some concern Eventually want to to note occurrence in verbose mode. And I may need to obtain a more extensive grid, depending on the study.
    • extrapolating off the low mass side of a WD model
    • extrapolating off the high mass side of a WD model
    • extrapolating off the high age side of a WD model
    • extrapolating AGBt mass
    • extrapolating off the Bergeron atmosphere table
    • extrapolating off the low [Fe/H] side of a MSRGB model
  3. Panic Dump Hex code. Freak. Hmm, maybe print a warning even in non-verbose mode and users will have to extend the model grid.
    • extrapolating MS or RGB stars off the low age side of an MSRGB model
    • extrapolating MS or RGB stars off the high age side of a MSRGB model
    • extrapolating off the high [Fe/H] side of a MSRGB model