Class TransientSolution<R,S>

java.lang.Object
org.oristool.models.stpn.TransientSolution<R,S>
Type Parameters:
R - type of initial states (such as regenerations)
S - type of reachable states (such as markings)

public class TransientSolution<R,S> extends Object
Transient probabilities from many initial states.
  • Constructor Details

    • TransientSolution

      public TransientSolution(BigDecimal timeBound, BigDecimal timeStep, List<R> regenerations, List<S> columnStates, R initialRegeneration)
      Prepares a new instance and allocates the vector of probabilities.
      Parameters:
      timeBound - time bound for of the time series
      timeStep - time step
      regenerations - initial states
      columnStates - reachable states
      initialRegeneration - first initial state
  • Method Details

    • fromArray

      public static <S> TransientSolution<S,S> fromArray(double[][] probs, double step, Map<S,Integer> statePos, S initialState)
      Prepares a new instance from a given array.
      Type Parameters:
      S - type of reachable states (such as markings)
      Parameters:
      probs - array of transient probabilities for each time/state
      step - time step between solutions in the array
      statePos - mapping from states to position
      initialState - initial state of the analysis
      Returns:
      a new transient solution backed by the input parameters
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • writeCSV

      public void writeCSV(String filepath, int floatDigits)
    • writeCSV

      public void writeCSV(Writer writer, int floatDigits)
    • readCSV

      public static TransientSolution<String,String> readCSV(String filepath)
    • readCSV

      public static TransientSolution<String,String> readCSV(Reader reader)
    • getInitialRegeneration

      public R getInitialRegeneration()
      Returns the first initial state of the analysis.
      Returns:
      first initial state
    • getTimeLimit

      public BigDecimal getTimeLimit()
    • getStep

      public BigDecimal getStep()
    • getSamplesNumber

      public int getSamplesNumber()
    • getRegenerations

      public List<R> getRegenerations()
    • getColumnStates

      public List<S> getColumnStates()
    • getSolution

      public double[][][] getSolution()
    • computeIntegralSolution

      public TransientSolution<R,S> computeIntegralSolution()
      Computes the integral of each time series.
      Returns:
      a transient solution with cumulative values
    • computeDerivativeSolution

      public TransientSolution<R,S> computeDerivativeSolution()
      Computes the derivative of each time series.
      Returns:
      a transient solution with finite differences
    • klDivergence

      public static double klDivergence(double px, double py)
      Computes the Kullback-Leibler divergence on the input probability values.
      Parameters:
      px - probability value according to PDF X
      py - probability value according to PDF Y
      Returns:
      KL divergence
    • klDivergence

      public <T, U> double klDivergence(TransientSolution<T,U> other, int i, int j, int u, int v)
      Computes the Kullback-Leibler divergence between the time series of state (i,j) for this solution, and (u,v) for the other.
      Parameters:
      other - another solution
      i - initial regeneration of this solution
      j - state of this solution solution (over time should give a PDF)
      u - initial regeneration of the other solution
      v - state of the other solution solution (over time should give a PDF)
      Returns:
      KL divergence
    • jsDistance

      public <U, T> double jsDistance(TransientSolution<T,U> other, int i, int j, int u, int v)
      Computes the Jensen-Shannon distance between the time series of state (i,j) for this solution, and (u,v) for the other.
      Parameters:
      other - another solution
      i - initial regeneration of this solution
      j - state of this solution solution (over time should give a PDF)
      u - initial regeneration of the other solution
      v - state of the other solution solution (over time should give a PDF)
      Returns:
      JS distance
    • computeAggregateSolution

      public static <R> TransientSolution<R,MarkingCondition> computeAggregateSolution(TransientSolution<R,Marking> solution, String markingConditions)
      Aggregates the marking probabilities based on a predicate.
      Type Parameters:
      R - type of initial states (such as regenerations)
      Parameters:
      solution - input solution
      markingConditions - string of marking conditions separated by comma
      Returns:
      transient probabilities for each marking condition
    • computeAggregateSolution

      public static <R> TransientSolution<R,MarkingCondition> computeAggregateSolution(TransientSolution<R,Marking> solution, R initialRegeneration, MarkingCondition... markingConditions)
      Aggregates the marking probabilities based on a predicate.
      Type Parameters:
      R - type of initial states (such as regenerations)
      Parameters:
      solution - input solution
      initialRegeneration - first initial state
      markingConditions - marking conditions
      Returns:
      transient probabilities for each marking condition
    • rewardRates

      public static RewardRate[] rewardRates(String rewardRates)
      Creates reward evaluators from a string of expressions separated by semicolon.
      Parameters:
      rewardRates - list of rewards separated by semicolon
      Returns:
      reward rate evaluators
    • computeRewards

      public static <R> TransientSolution<R,RewardRate> computeRewards(boolean cumulative, TransientSolution<R,Marking> solution, String rewardRates)
      Computes rewards from a transient solution (only for the first initial state).
      Type Parameters:
      R - type of initial states (such as regenerations)
      Parameters:
      cumulative - whether to compute cumulative rewards
      solution - input transient solution
      rewardRates - list of rewards separated by semicolon
      Returns:
      transient rewards for each reward expression
    • computeRewards

      public static <R> TransientSolution<R,RewardRate> computeRewards(boolean cumulative, TransientSolution<R,Marking> solution, RewardRate... rewardRates)
      Computes rewards from a transient solution (only for the first initial state).
      Type Parameters:
      R - type of initial states (such as regenerations)
      Parameters:
      cumulative - whether to compute cumulative rewards
      solution - input transient solution
      rewardRates - list of rewards separated by semicolon
      Returns:
      transient rewards for each reward expression
    • isClose

      public boolean isClose(TransientSolution<String,String> other, double epsilon)
    • sumsToOne

      public boolean sumsToOne(double epsilon)