Skip to content
Snippets Groups Projects
Select Git revision
  • fb9e190a7e87d5eec79443b26161bcf91d1c7fb7
  • master default
  • 3-port-RcppTUG
  • 2-refactor-pourbaix
  • v0.0.4
5 results

Rphree_SurrogateUtils.R

Blame
  • Rphree_SurrogateUtils.R 10.96 KiB
    ##  Functions for dealing with surrogate simulations
    
    ### Marco De Lucia, delucia@gfz-potsdam.de, 2009-2018
    ### Time-stamp: "Last modified 2018-05-06 20:16:47 delucia"
    
    ##' Computes the average of absolute values of a vector
    ##' @title Average of absolute values
    ##' @param x numeric vector
    ##' @return mean(abs(x))
    ##' @author MDL
    ##' @export
    mae <- function(x) mean(abs(x))
    
    ## ##' .. content for \description{} (no empty lines) ..
    ## ##'
    ## ##' .. content for \details{} ..
    ## ##' @title SoftMax transformation
    ## ##' @param obj numeric vector
    ## ##' @return 
    ## ##' @author 
    ## SoftMax <- function(obj) {
    ##     eo <- exp(obj-max(obj))
    ##     ss <- sum(eo)
    ##     scaled <- eo/ss
    ##     attr(res,"back") <- ss
    ##     return(res)
    ## }
    
    ## ## SoftMaxBackTransf <- function(vec, back) return(log(vec)+log(back))
    
    ## ##' @title Flatten out a Rphree list
    ## ##' @param list list of Rphree lists
    ## ##' @param strip logical, should we delete "ListInfo"? Defaults to
    ## ##'     true
    ## ##' @return a list whose elements are single Rphree simulations
    ## ##' @author MDL
    ## ##' @export
    ## FlattenList <- function(list) {
    ##    tot <- vector(mode="list", length=sum(sapply(stripped, length)))
    ##    k <- 1
    ##    for (i in seq_along(stripped)) {
    ##       for (j in seq_along(stripped[[i]])) {
    ##          tot[[k]] <- stripped[[i]][[j]]
    ##          k=k+1
    ##       }
    ##    }
    ##    return(tot)
    ## }
    
    
    ##' @title Find all species occurring in the ensemble
    ##' @param flatlist the flatted list of Rphree simulations
    ##' @return vector with unique occurrences of species names
    ##' @author MDL
    ##' @export
    FindAllSpeciesNames <- function(flatlist)
        unique(sort(unlist(sapply(flatlist, function(sol) rownames(sol$species)))))
    
    
    ##' @title Find all pphases occurring in the ensemble
    ##' @param flatlist the flatted list of Rphree simulations
    ##' @return vector with unique occurrences of pphases names
    ##' @author MDL
    ##' @export
    FindAllMinNames <- function(flatlist)
        unique(sort(unlist(sapply(flatlist, function(sol) rownames(sol$pphases)))))
    
    ##' @title Find all totals occurring in the ensemble
    ##' @param flatlist the flatted list of Rphree simulations
    ##' @return vector with unique occurrences of element names