Changeset 4066


Ignore:
Timestamp:
Aug 5, 2021, 12:20:06 PM (11 months ago)
Author:
Peter
Message:

merge trunk changes into branch

Location:
branches/kendall-score
Files:
35 edited
10 copied

Legend:

Unmodified
Added
Removed
  • branches/kendall-score

  • branches/kendall-score/NEWS

    r4038 r4066  
    44
    55version 0.19 (released NOT YET)
     6  - classifier::Target::labels(void) is now const (issue #972)
     7  - statistics::correlation now takes a const Matrix& instead of Matrix
    68
    79  A complete list of closed tickets can be found here [[br]]
  • branches/kendall-score/m4/ax_boost_base.m4

    r3782 r4066  
    3434#   warranty.
    3535
    36 #serial 45
     36#serial 49
    3737
    3838# example boost program (need to pass version)
     
    114114    AS_CASE([${host_cpu}],
    115115      [x86_64],[libsubdirs="lib64 libx32 lib lib64"],
    116       [ppc64|powerpc64|s390x|sparc64|aarch64|ppc64le|powerpc64le|riscv64],[libsubdirs="lib64 lib lib64"],
     116      [mips*64*],[libsubdirs="lib64 lib32 lib lib64"],
     117      [ppc64|powerpc64|s390x|sparc64|aarch64|ppc64le|powerpc64le|riscv64|e2k],[libsubdirs="lib64 lib lib64"],
    117118      [libsubdirs="lib"]
    118119    )
     
    123124    AS_CASE([${host_cpu}],
    124125      [i?86],[multiarch_libsubdir="lib/i386-${host_os}"],
     126      [armv7l],[multiarch_libsubdir="lib/arm-${host_os}"],
    125127      [multiarch_libsubdir="lib/${host_cpu}-${host_os}"]
    126128    )
  • branches/kendall-score/m4/ax_boost_iostreams.m4

    r3791 r4066  
    3030#   warranty.
    3131
    32 #serial 21
     32#serial 22
    3333
    3434AC_DEFUN([AX_BOOST_IOSTREAMS],
     
    104104            fi
    105105            if test "x$ax_lib" = "x"; then
    106                 AC_MSG_ERROR(Could not find a version of the library!)
     106                AC_MSG_ERROR(Could not find a version of the Boost::IOStreams library!)
    107107            fi
    108108      if test "x$link_iostreams" != "xyes"; then
  • branches/kendall-score/m4/ax_compiler_vendor.m4

    r3782 r4066  
    99# DESCRIPTION
    1010#
    11 #   Determine the vendor of the C/C++ compiler, e.g., gnu, intel, ibm, sun,
    12 #   hp, borland, comeau, dec, cray, kai, lcc, metrowerks, sgi, microsoft,
    13 #   watcom, etc. The vendor is returned in the cache variable
    14 #   $ax_cv_c_compiler_vendor for C and $ax_cv_cxx_compiler_vendor for C++.
     11#   Determine the vendor of the C, C++ or Fortran compiler.  The vendor is
     12#   returned in the cache variable $ax_cv_c_compiler_vendor for C,
     13#   $ax_cv_cxx_compiler_vendor for C++ or $ax_cv_fc_compiler_vendor for
     14#   (modern) Fortran.  The value is one of "intel", "ibm", "pathscale",
     15#   "clang" (LLVM), "cray", "fujitsu", "sdcc", "sx", "portland" (PGI), "gnu"
     16#   (GCC), "sun" (Oracle Developer Studio), "hp", "dec", "borland",
     17#   "comeau", "kai", "lcc", "sgi", "microsoft", "metrowerks", "watcom",
     18#   "tcc" (Tiny CC) or "unknown" (if the compiler cannot be determined).
     19#
     20#   To check for a Fortran compiler, you must first call AC_FC_PP_SRCEXT
     21#   with an appropriate preprocessor-enabled extension.  For example:
     22#
     23#     AC_LANG_PUSH([Fortran])
     24#     AC_PROG_FC
     25#     AC_FC_PP_SRCEXT([F])
     26#     AX_COMPILER_VENDOR
     27#     AC_LANG_POP([Fortran])
    1528#
    1629# LICENSE
     
    1831#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
    1932#   Copyright (c) 2008 Matteo Frigo
     33#   Copyright (c) 2018-19 John Zaitseff <J.Zaitseff@zap.org.au>
    2034#
    2135#   This program is free software: you can redistribute it and/or modify it
     
    4559#   exception to the GPL to apply to your modified version as well.
    4660
    47 #serial 17
     61#serial 30
    4862
    49 AC_DEFUN([AX_COMPILER_VENDOR],
    50 [AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor,
    51   dnl Please add if possible support to ax_compiler_version.m4
    52   [# note: don't check for gcc first since some other compilers define __GNUC__
    53   vendors="intel:     __ICC,__ECC,__INTEL_COMPILER
    54            ibm:       __xlc__,__xlC__,__IBMC__,__IBMCPP__
    55            pathscale: __PATHCC__,__PATHSCALE__
    56            clang:     __clang__
    57            cray:      _CRAYC
    58            fujitsu:   __FUJITSU
    59            sdcc:      SDCC, __SDCC
    60            gnu:       __GNUC__
    61            sun:       __SUNPRO_C,__SUNPRO_CC
    62            hp:        __HP_cc,__HP_aCC
    63            dec:       __DECC,__DECCXX,__DECC_VER,__DECCXX_VER
    64            borland:   __BORLANDC__,__CODEGEARC__,__TURBOC__
    65            comeau:    __COMO__
    66            kai:       __KCC
    67            lcc:       __LCC__
    68            sgi:       __sgi,sgi
    69            microsoft: _MSC_VER
    70            metrowerks: __MWERKS__
    71            watcom:    __WATCOMC__
    72            portland:  __PGI
    73      tcc:       __TINYC__
    74            unknown:   UNKNOWN"
    75   for ventest in $vendors; do
    76     case $ventest in
    77       *:) vendor=$ventest; continue ;;
    78       *)  vencpp="defined("`echo $ventest | sed 's/,/) || defined(/g'`")" ;;
    79     esac
    80     AC_COMPILE_IFELSE([AC_LANG_PROGRAM(,[
    81       #if !($vencpp)
    82         thisisanerror;
    83       #endif
    84     ])], [break])
    85   done
    86   ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=`echo $vendor | cut -d: -f1`
    87  ])
    88 ])
     63AC_DEFUN([AX_COMPILER_VENDOR], [dnl
     64    AC_CACHE_CHECK([for _AC_LANG compiler vendor], ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor, [dnl
     65  dnl  If you modify this list of vendors, please add similar support
     66  dnl  to ax_compiler_version.m4 if at all possible.
     67  dnl
     68  dnl  Note: Do NOT check for GCC first since some other compilers
     69  dnl  define __GNUC__ to remain compatible with it.  Compilers that
     70  dnl  are very slow to start (such as Intel) are listed first.
     71
     72  vendors="
     73    intel:    __ICC,__ECC,__INTEL_COMPILER
     74    ibm:    __xlc__,__xlC__,__IBMC__,__IBMCPP__,__ibmxl__
     75    pathscale:  __PATHCC__,__PATHSCALE__
     76    clang:    __clang__
     77    cray:   _CRAYC
     78    fujitsu:  __FUJITSU
     79    sdcc:   SDCC,__SDCC
     80    sx:   _SX
     81    portland: __PGI
     82    gnu:    __GNUC__
     83    sun:    __SUNPRO_C,__SUNPRO_CC,__SUNPRO_F90,__SUNPRO_F95
     84    hp:   __HP_cc,__HP_aCC
     85    dec:    __DECC,__DECCXX,__DECC_VER,__DECCXX_VER
     86    borland:  __BORLANDC__,__CODEGEARC__,__TURBOC__
     87    comeau:   __COMO__
     88    kai:    __KCC
     89    lcc:    __LCC__
     90    sgi:    __sgi,sgi
     91    microsoft:  _MSC_VER
     92    metrowerks: __MWERKS__
     93    watcom:   __WATCOMC__
     94    tcc:    __TINYC__
     95    unknown:  UNKNOWN
     96  "
     97  for ventest in $vendors; do
     98      case $ventest in
     99    *:)
     100        vendor=$ventest
     101        continue
     102        ;;
     103    *)
     104        vencpp="defined("`echo $ventest | sed 's/,/) || defined(/g'`")"
     105        ;;
     106      esac
     107
     108      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[
     109#if !($vencpp)
     110      thisisanerror;
     111#endif
     112      ]])], [break])
     113  done
     114
     115  ax_cv_[]_AC_LANG_ABBREV[]_compiler_vendor=`echo $vendor | cut -d: -f1`
     116    ])
     117])dnl
  • branches/kendall-score/m4/ax_cxx_compile_stdcxx.m4

    r3937 r4066  
    1717#   extended mode (e.g. -std=gnu++11) or a strict conformance mode (e.g.
    1818#   -std=c++11).  If neither is specified, you get whatever works, with
    19 #   preference for an extended mode.
     19#   preference for no added switch, and then for an extended mode.
    2020#
    2121#   The third argument, if specified 'mandatory' or if left unspecified,
     
    3535#   Copyright (c) 2015 Moritz Klammler <moritz@klammler.eu>
    3636#   Copyright (c) 2016, 2018 Krzesimir Nowak <qdlacz@gmail.com>
     37#   Copyright (c) 2019 Enji Cooper <yaneurabeya@gmail.com>
     38#   Copyright (c) 2020 Jason Merrill <jason@redhat.com>
    3739#
    3840#   Copying and distribution of this file, with or without modification, are
     
    4143#   warranty.
    4244
    43 #serial 10
     45#serial 12
    4446
    4547dnl  This macro is based on the code from the AX_CXX_COMPILE_STDCXX_11 macro
     
    6163  AC_LANG_PUSH([C++])dnl
    6264  ac_success=no
     65
     66  m4_if([$2], [], [dnl
     67    AC_CACHE_CHECK(whether $CXX supports C++$1 features by default,
     68       ax_cv_cxx_compile_cxx$1,
     69      [AC_COMPILE_IFELSE([AC_LANG_SOURCE([_AX_CXX_COMPILE_STDCXX_testbody_$1])],
     70        [ax_cv_cxx_compile_cxx$1=yes],
     71        [ax_cv_cxx_compile_cxx$1=no])])
     72    if test x$ax_cv_cxx_compile_cxx$1 = xyes; then
     73      ac_success=yes
     74    fi])
    6375
    6476  m4_if([$2], [noext], [], [dnl
     
    190202    struct Base
    191203    {
     204      virtual ~Base() {}
    192205      virtual void f() {}
    193206    };
     
    195208    struct Derived : public Base
    196209    {
     210      virtual ~Derived() override {}
    197211      virtual void f() override {}
    198212    };
  • branches/kendall-score/test/Makefile.am

    r4038 r4066  
    55# Copyright (C) 2005 Jari Häkkinen, Peter Johansson
    66# Copyright (C) 2006, 2007, 2008 Jari Häkkinen, Peter Johansson, Markus Ringnér
    7 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Peter Johansson
     7# Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021 Peter Johansson
    88#
    99# This file is part of the yat library, http://dev.thep.lu.se/yat
     
    4242  test/bam_pair.test \
    4343  test/bam_pair_analyse.test \
     44  test/bam_pair_buffer.test \
    4445  test/bam_iterator.test \
    4546  test/bam_read_filter.test \
     
    8889  test/matrix_expression.test \
    8990  test/matrix_weighted.test test/merge.test \
    90   test/merge_iterator.test test/nbc.test \
     91  test/merge_iterator.test \
     92  test/multiprocess.test \
     93  test/nbc.test \
    9194  test/ncc.test \
    9295  test/negative_binomial.test \
     
    102105  test/poisson.test \
    103106  test/queue.test test/queue2.test \
     107  test/queue3.test \
    104108  test/range.test \
    105109  test/ranking.test \
    106110  test/regression.test test/rnd.test \
    107111  test/rng-mt.test \
    108   test/roc.test \
     112  test/round.test \
    109113  test/score.test \
    110114  test/scheduler.test \
     
    128132  test/vcf_file.test \
    129133  test/vcf_file2.test \
     134  test/vcf_file3.test \
    130135  test/vcf_header.test \
    131136  test/vector_expression.test \
  • branches/kendall-score/test/Suite.cc

    r3999 r4066  
    101101
    102102
     103  Generator::Generator(void)
     104    : k_(0)
     105  {}
     106
     107
     108  double Generator::operator()(void)
     109  {
     110    ++k_;
     111    return sin(k_);
     112  }
     113
     114
    103115  std::string filename(const std::string& path)
    104116  {
  • branches/kendall-score/test/Suite.h

    r3987 r4066  
    188188    unsigned int known_issues_;
    189189    bool ok_;
     190  };
     191
     192
     193  struct Generator
     194  {
     195    Generator(void);
     196    double operator()(void);
     197  private:
     198    size_t k_;
    190199  };
    191200
  • branches/kendall-score/test/doxygen_test.sh

    r3943 r4066  
    44
    55# Copyright (C) 2008 Jari Häkkinen, Peter Johansson
    6 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2019, 2020 Peter Johansson
     6# Copyright (C) 2009, 2010, 2011, 2012, 2013, 2019, 2020, 2021 Peter Johansson
    77#
    88# This file is part of the yat library, http://dev.thep.lu.se/yat
     
    3737# 'yat/utility/BLAS_level2.h'
    3838#
    39 # Here let's assume issue will not be solved in doxygen 1.8.x but will
    40 # be gone in 1.9
    41 if echo x$version | grep "^x1.8.1[5-9]$" > /dev/null || \
    42         echo x$version | grep "^x1.8.[2-9]" > /dev/null; then
    43     cat ${error_file} \
    44         | grep -v 'yat/utility/BLAS_level2.h.*relates' && exit_fail
     39# Here let's assume issue will not be solved in doxygen 1.8.x; it is
     40# still present in 1.9.1. Let's hope it's fixed in 1.10
     41if echo x$version | grep "^x1\.8\.1[5-9]$" > /dev/null || \
     42   echo x$version | grep "^x1\.8\.[2-9]$" > /dev/null || \
     43   echo x$version | grep "^x1\.9\." > /dev/null; then
     44     cat ${error_file} \
     45     | grep -v 'yat/utility/BLAS_level2.h.*relates' && exit_fail
    4546else
    4647    test -s ${error_file} && exit_fail
  • branches/kendall-score/test/statistics.cc

    r3875 r4066  
    150150void test_correlation(test::Suite& suite)
    151151{
    152   utility::Matrix x(10,100);
     152  utility::Matrix x(100,10);
     153  for (size_t i=0; i<x.rows(); ++i)
     154    for (size_t j=0; j<x.columns(); ++j)
     155      x(i, j) = sin(5*i + j);
    153156  utility::Matrix C = statistics::correlation(x);
    154157  if (!suite.equal(C(0,0), 1.0)) {
     
    156159    suite.err() << "correlation element(0, 0) not unity\n";
    157160  }
     161
     162  for (size_t i=0; i<C.rows(); ++i)
     163    for (size_t j=0; j<C.columns(); ++j) {
     164      statistics::AveragerPair ap;
     165      add(ap, x.begin_column(i), x.end_column(i), x.begin_column(j));
     166      if (!suite.equal(C(i, j), ap.correlation(), 10)) {
     167        suite.add(false);
     168        suite.err() << "error: C(" << i << ", " << j << ") is " << C(i,j)
     169                    << "; expected " << ap.correlation() << "\n";
     170      }
     171    }
     172
    158173}
    159174
  • branches/kendall-score/test/yat-hello/configure.ac

    r3330 r4066  
    3030AC_PROG_CXXCPP
    3131AC_PROG_CXX
    32 AC_PROG_LIBTOOL
     32LT_INIT
    3333YAT_CHECK_YAT([0.4],[],[AC_MSG_ERROR([could not find required version of yat])])
    3434AC_CONFIG_FILES([Makefile])
  • branches/kendall-score/yat/classifier/Perceptron.cc

    r3709 r4066  
    107107        y(i) = 1.0;
    108108
     109    // We use the Iteratively Rewighted Least Square algorithm as described
     110    // https://en.wikipedia.org/wiki/Logistic_regression
     111
    109112    size_t max_epochs = 100;
    110113    double sum_squared = 1.0; // some (relatively) large number
  • branches/kendall-score/yat/classifier/Perceptron.h

    r3709 r4066  
    3535     \brief A Single-layer Perceptron
    3636
    37      Data are modeled as \f$ y = \frac{1}{1 + \exp(-wx)} \f$
     37     Data are modeled as \f$ \mu = \frac{1}{1 + \exp(-wx)} \f$
    3838
    3939     \since New in yat 0.16
     
    8686       \brief train the model
    8787
     88       Model parameters, \f$w\f$, are calculated such that the
     89       log-likelihood,
     90       \f$ \log \mathcal{L} = \sum y_i \log \left(\mu_i\right) +
     91       (1-y_i) \log \left(1 - \mu_i\right) \f$,
     92       is maximized.
     93
    8894       \param x each row corresponds to a data point and each column a
    8995       feature.
  • branches/kendall-score/yat/classifier/Target.cc

    r3855 r4066  
    55  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    66  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    7   Copyright (C) 2012, 2017, 2019 Peter Johansson
     7  Copyright (C) 2012, 2017, 2019, 2021 Peter Johansson
    88
    99  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    4747  {
    4848  }
    49  
     49
    5050
    5151  Target::Target(const std::vector<std::string>& label)
     
    5353    init(label);
    5454  }
    55  
     55
    5656
    5757  Target::Target(const std::vector<std::string>& label,
     
    6262    labels_ = t.labels_;
    6363    classes_.reserve(label.size());
    64     for (std::vector<std::string>::const_iterator lab=label.begin(); 
     64    for (std::vector<std::string>::const_iterator lab=label.begin();
    6565         lab!=label.end(); ++lab) {
    6666      std::map<std::string,size_t>::iterator i=class_map_.lower_bound(*lab);
     
    8585      if(sep=='\0')
    8686        ok=!(is>>word).fail();
    87       else 
     87      else
    8888        ok=!getline(is, word, sep).fail();
    8989
     
    9191      if (!word.size() || !ok )
    9292        continue;
    93      
     93
    9494      vec.push_back(word);
    9595    }
     
    100100    init(vec);
    101101  }
    102  
    103 
    104   Target::Target(const Target& t, 
     102
     103
     104  Target::Target(const Target& t,
    105105                 const utility::Index& index)
    106106    : class_map_(t.class_map_)
     
    131131  }
    132132
    133   void Target::init(const std::vector<std::string>& label) 
     133  void Target::init(const std::vector<std::string>& label)
    134134  {
    135135    classes_.clear();
     
    137137    class_map_.clear();
    138138    labels_.clear();
    139    
     139
    140140    for (size_t i=0; i<label.size(); i++) {
    141       std::map<std::string,size_t>::iterator iter = 
     141      std::map<std::string,size_t>::iterator iter =
    142142        class_map_.lower_bound(label[i]);
    143143
    144144      // label in map
    145       if (iter != class_map_.end() && 
     145      if (iter != class_map_.end() &&
    146146          !(class_map_.key_comp()(label[i],iter->first)) ){
    147147
     
    151151      else{
    152152        classes_.push_back(class_map_.size());
    153         class_map_.insert(iter, std::make_pair(label[i],classes_[i])); 
     153        class_map_.insert(iter, std::make_pair(label[i],classes_[i]));
    154154        labels_.push_back(label[i]);
    155155      }
     
    157157    // setting binary to false for every class
    158158    binary_=std::vector<char>(nof_classes(),false);
    159    
     159
    160160    set_binary(0,true);
    161161  }
    162162
    163   const std::vector<std::string>& Target::labels(void)
     163  const std::vector<std::string>& Target::labels(void) const
    164164  {
    165165    return labels_;
     
    182182  }
    183183
    184   size_t Target::size(const std::string& label) const 
    185   {
    186     std::map<std::string,size_t>::const_iterator i=class_map_.find(label);   
     184  size_t Target::size(const std::string& label) const
     185  {
     186    std::map<std::string,size_t>::const_iterator i=class_map_.find(label);
    187187    if(i==class_map_.end())
    188188      return 0;
     
    190190    return size(i->second);
    191191  }
    192  
     192
    193193  size_t Target::size(void) const
    194194  {
  • branches/kendall-score/yat/classifier/Target.h

    r3855 r4066  
    1 #ifndef _theplu_yat_classifier_target_ 
    2 #define _theplu_yat_classifier_target_ 
     1#ifndef _theplu_yat_classifier_target_
     2#define _theplu_yat_classifier_target_
    33
    44// $Id$
     
    88  Copyright (C) 2006 Jari Häkkinen, Peter Johansson, Markus Ringnér
    99  Copyright (C) 2007, 2008 Jari Häkkinen, Peter Johansson
    10   Copyright (C) 2009, 2019 Peter Johansson
     10  Copyright (C) 2009, 2019, 2021 Peter Johansson
    1111
    1212  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    4040    class Index;
    4141  }
    42 namespace classifier { 
     42namespace classifier {
    4343
    4444  ///
     
    4747  class Target
    4848  {
    49  
     49
    5050  public:
    5151    /**
     
    6060
    6161    /**
    62        @brief Constructor 
     62       @brief Constructor
    6363    */
    6464    Target(const std::vector<std::string>& labels, const Target&);
     
    8787    ///
    8888    const std::map<std::string,size_t>& classes(void) const;
    89    
     89
    9090    /**
    9191       This function is equivalent to Target::classes().size()
    92        
     92
    9393       \return number of classes
    94        
     94
    9595       \note there might be empty classes, i.e., classes with zero
    96        samples. This may happen when using 
     96       samples. This may happen when using
    9797       Target(const std::vector<std::string>& labels, const Target&) or
    9898       Target(const Target& org, const std::vector<size_t>& vec).
     
    109109    ///
    110110    bool binary(size_t i) const;
    111    
     111
    112112    ///
    113113    /// The size of returned vector is equal to number of classes. To
     
    117117    /// @return vector of labels for classes
    118118    ///
    119     const std::vector<std::string>& labels(void);
     119    const std::vector<std::string>& labels(void) const;
    120120
    121121    ///
     
    154154    ///
    155155    size_t operator()(size_t sample) const;
    156    
     156
    157157    ///
    158158    /// @return the class of @a sample
     
    169169
    170170  private:
    171     /// @brief Copy Constructor 
     171    /// @brief Copy Constructor
    172172    // using compiler generated constructor
    173     //Target(const Target& other); 
     173    //Target(const Target& other);
    174174
    175175    // binary target for class i
     
    177177    std::vector<size_t> classes_; // class of sample i
    178178    // map between class label and class index (inverse of labels_)
    179     std::map<std::string,size_t> class_map_; 
     179    std::map<std::string,size_t> class_map_;
    180180    std::vector<std::string> labels_; // label of class i
    181    
     181
    182182    void init(const std::vector<std::string>&);
    183183
    184   }; 
    185  
     184  };
     185
    186186  ///
    187187  /// The output operator for the Target class.
  • branches/kendall-score/yat/normalizer/Makefile.am

    r3999 r4066  
    2121yat_libyat_la_SOURCES += \
    2222  yat/normalizer/qQuantileNormalizer.cc \
    23   yat/normalizer/QuantileNormalizer.cc
     23  yat/normalizer/QuantileNormalizer.cc \
     24  yat/normalizer/Zscore.cc
    2425
    2526nobase_include_HEADERS += \
  • branches/kendall-score/yat/normalizer/Zscore.h

    r3550 r4066  
    4242
    4343     Shift and scale the values in a range as: \f$ y_i =
    44      \frac{x_i-m}{s} \f$ where \a m is the mean and \a s is the
    45      standard deviation. After normalization, the range will have zero
    46      mean and unity variance.
     44     \frac{x_i-m}{k*s} \f$ where \a m is the mean, \a s is the
     45     standard deviation, and \a k is set in constructor (default:
     46     1.0). After normalization, the range will have zero mean and
     47     variance = \f$ 1/k^2 \f$.
    4748
    4849       Type Requirements:
     
    5758  {
    5859  public:
     60    /**
     61       \param k In the scaling step elements are divided by \c k times
     62       the standard deviation
     63
     64       \since New in yat 0.19
     65     */
     66    explicit Zscore(double k=1.0);
     67
     68    /**
     69       \return the k-factor set in constructor
     70
     71       \since new in yat 0.19
     72     */
     73    double k(void) const;
     74
    5975    /**
    6076       The element in range [result, result + (last-first)) is
     
    8096
    8197  private:
     98    double k_;
     99
     100
    82101    template<class ForwardIterator, class OutputIterator>
    83102    void normalize(ForwardIterator first, ForwardIterator last,
     
    95114      add(a, first, last);
    96115      double m = a.mean();
    97       double std = a.std();
     116      double factor = 1.0 / (a.std() * k_);
    98117      while (first!=last) {
    99         *result = (*first - m) / std;
     118        *result = (*first - m) * factor;
    100119        ++first;
    101120        ++result;
     
    120139      add(a, first, last);
    121140      double m = a.mean();
    122       double std = a.std();
     141      double factor = 1.0 / (a.std() * k_);
    123142      utility::iterator_traits<ForwardIterator> in_trait;
    124143      utility::iterator_traits<OutputIterator> out_trait;
    125144      while (first!=last) {
    126         out_trait.data(result) = (in_trait.data(first) - m) / std;
     145        out_trait.data(result) = (in_trait.data(first) - m) * factor;
    127146        ++first;
    128147        ++result;
  • branches/kendall-score/yat/omic/BamPairIterator.h

    r4038 r4066  
    5151
    5252     This iterator works on a sorted range [begin, end) and provides a
    53      covenient way to access the pairs rather than the reads
     53     convenient way to access the pairs rather than the reads
    5454     individually. When BamPairIterator is incremented, rather than
    5555     just step to next element in [begin, end), BamPairIterator keeps
    5656     stepping until it finds a read whose mate it has already seen, and
    5757     operator* return the pair of BamReads.
     58
     59     The resulting iterator is sorted with respect to \c second().
    5860
    5961     Note that BamPairIterator is a single-pass iterator, i.e., once it
  • branches/kendall-score/yat/omic/BamPairIterator2.h

    r4038 r4066  
    55
    66/*
    7   Copyright (C) 2020 Peter Johansson
     7  Copyright (C) 2020, 2021 Peter Johansson
    88
    99  This file is part of the yat library, http://dev.thep.lu.se/yat
     
    6060     Note that BamPairIterator2 is a single-pass iterator, i.e., once it
    6161     is incremented the behaviour of its copies is undefined.
     62
     63     \see BamPairBuffer
    6264
    6365     \since New in yat 0.18
  • branches/kendall-score/yat/omic/Codon.cc

    r3516 r4066  
    5555      ss << e.what() << "\n"
    5656         << "Codon::Codon(1) invalid argument: " << str;
    57       throw std::invalid_argument(ss.str());
     57      std::throw_with_nested(std::invalid_argument(ss.str()));
    5858    }
    5959  }
  • branches/kendall-score/yat/omic/DNA.cc

    r3550 r4066  
    4949      msg += c;
    5050      msg += "')";
    51       throw std::invalid_argument(msg);
     51      std::throw_with_nested(std::invalid_argument(msg));
    5252    }
    5353    assert(code_<16);
  • branches/kendall-score/yat/omic/DnaComplementer.cc

    r3792 r4066  
    4141      std::stringstream ss;
    4242      ss << e.what() << "\nDnaComplementer: " << x;
    43       throw std::invalid_argument(ss.str());
     43      std::throw_with_nested(std::invalid_argument(ss.str()));
    4444    }
    4545    assert(0 && "we should not end up here");
  • branches/kendall-score/yat/omic/Fasta.cc

    r4038 r4066  
    101101        std::ostringstream msg;
    102102        msg << "failed fetching sequence for '" << chr << "'";
    103         throw utility::runtime_error(msg.str());
     103        std::throw_with_nested(utility::runtime_error(msg.str()));
    104104      }
    105105      throw; // retrow e
  • branches/kendall-score/yat/omic/Makefile.am

    r3999 r4066  
    4646nobase_include_HEADERS += $(srcdir)/yat/omic/BamHeader.h
    4747nobase_include_HEADERS += $(srcdir)/yat/omic/BamPair.h
     48nobase_include_HEADERS += $(srcdir)/yat/omic/BamPairBuffer.h
    4849nobase_include_HEADERS += $(srcdir)/yat/omic/BamPairIterator.h
    4950nobase_include_HEADERS += $(srcdir)/yat/omic/BamPairIterator2.h
  • branches/kendall-score/yat/omic/VcfFile.cc

    r3792 r4066  
    133133        os << "an uncompressed ";
    134134      os << "VCF file: " << e.what();
    135       throw utility::runtime_error(os.str());
     135      std::throw_with_nested(utility::runtime_error(os.str()));
    136136    }
    137137    assert(header_);
  • branches/kendall-score/yat/omic/VcfHeader.cc

    r3891 r4066  
    22
    33/*
    4   Copyright (C) 2018, 2020 Peter Johansson
     4  Copyright (C) 2018, 2020, 2021 Peter Johansson
    55
    66  The yat library is free software; you can redistribute it and/or
     
    3232#include <ostream>
    3333#include <sstream>
    34 
    35 #include <iostream>
     34#include <utility>
    3635
    3736namespace theplu {
     
    6261    std::string line;
    6362    while (getline(is, line)) {
    64       lines_.push_back(line);
     63      lines_.push_back(std::move(line));
    6564      if (is.peek()!='#') // next line does not start with '#'
    6665        break;
     
    7675    line += value;
    7776    if (lines_.empty()) {
    78       lines_.push_back(line);
     77      lines_.push_back(std::move(line));
    7978      return;
    8079    }
     
    288287    std::string hdr("#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT");
    289288    if (lines_.size() &&  lines_.back().size()>1 && lines_.back()[1]!='#')
    290       lines_.back() = hdr;
     289      lines_.back() = std::move(hdr);
    291290    else
    292       lines_.push_back(hdr);
     291      lines_.push_back(std::move(hdr));
    293292
    294293    for (size_t i=0; i<s.size(); ++i) {
     
    345344                                 const std::string& prefix) const
    346345  {
    347     return s.substr(0, prefix.size()) == prefix;
     346    return s.size() >= prefix.size() &&
     347      std::equal(prefix.begin(), prefix.end(), s.begin());
    348348  }
    349349
  • branches/kendall-score/yat/statistics/utility.cc

    r3792 r4066  
    2727#include "utility.h"
    2828
    29 #include "yat/normalizer/Centralizer.h"
    30 #include "yat/normalizer/ColumnNormalizer.h"
    31 
    3229#include <gsl/gsl_cdf.h>
    3330#include <gsl/gsl_randist.h>
     
    5047
    5148
    52   utility::Matrix correlation(utility::Matrix x)
     49  utility::Matrix correlation(const utility::Matrix& X)
    5350  {
    54     using utility::Matrix;
    55     size_t n = x.columns();
    56     // centralise
    57     normalizer::ColumnNormalizer<normalizer::Centralizer<> > normalizer;
    58     normalizer(x, x);
    59 
    60     Matrix cov(n, n);
    61     for (size_t i=0; i<n; ++i) {
    62       for (size_t j=i; j<n; ++j) {
    63         cov(i, j) = x.column_const_view(i) * x.column_const_view(j);
    64         cov(j, i) = cov(i, j);
    65       }
     51    size_t cols = X.columns();
     52    size_t rows = X.rows();
     53    utility::Vector m(cols);
     54    utility::Vector x2(cols);
     55    utility::Vector stddev(cols);
     56    for (size_t i=0; i<cols; ++i) {
     57      utility::VectorConstView vec = X.column_const_view(i);
     58      m(i) = sum(vec);
     59      x2(i) = vec * vec;
     60      // scaled standard deviation
     61      stddev(i) = std::sqrt(x2(i) - m(i) * m(i) / rows);
    6662    }
    6763
    68     utility::Vector stddev(n);
    69     for (size_t i=0; i<n; ++i)
    70       stddev(i) = std::sqrt(cov(i, i));
     64    utility::Matrix corr(cols, cols, 1.0);
     65    for (size_t i=0; i<cols; ++i)
     66      for (size_t j=i+1; j<cols; ++j) {
     67        corr(i,j) =
     68          X.column_const_view(i) * X.column_const_view(j) - m(i)*m(j)/rows;
     69        corr(i, j) /= stddev(i) * stddev(j);
     70        // symmetry
     71        corr(j, i) = corr(i,j);
     72      }
    7173
    72     Matrix corr(cov);
    73     for (size_t i=0; i<n; ++i) {
    74       corr(i, i) = 1.0;
    75       for (size_t j=0; j<i; ++j) {
    76         corr(i, j) = cov(i, j) / (stddev(i) * stddev(j));
    77         corr(j, i) = corr(i, j);
    78       }
    79     }
    8074    return corr;
    8175  }
  • branches/kendall-score/yat/statistics/utility.h

    r3875 r4066  
    145145     \since New in yat 0.16
    146146   */
    147   utility::Matrix correlation(utility::Matrix x);
     147  utility::Matrix correlation(const utility::Matrix& x);
    148148
    149149
  • branches/kendall-score/yat/utility/BasicQueue.h

    r3999 r4066  
    44// $Id$
    55//
    6 // Copyright (C) 2017, 2018, 2020 Peter Johansson
     6// Copyright (C) 2017, 2018, 2020, 2021 Peter Johansson
    77//
    88// This program is free software; you can redistribute it and/or modify
     
    2222
    2323#include <condition_variable>
     24#include <limits>
    2425#include <mutex>
    2526
     
    4748       Default constructor
    4849     */
    49     BasicQueue(void) {}
     50    BasicQueue(void)
     51      : capacity_(std::numeric_limits<size_t>::max())
     52    {}
    5053
    5154    /**
     
    5659      std::unique_lock<std::mutex> lock(other.mutex_);
    5760      q_ = other.q_;
     61      capacity_ = other.capacity_;
    5862    } // lock is released here
    5963
     
    6165       Construct queue from underlying Container
    6266     */
    63     explicit BasicQueue(const Container& container) : q_(container) {}
     67    explicit BasicQueue(const Container& container)
     68      : q_(container), capacity_(std::numeric_limits<size_t>::max())
     69    {}
     70
     71
     72    /**
     73       \return maximal number of element stored in container
     74
     75       \since New in yat 0.19
     76     */
     77    size_t capacity(void)
     78    {
     79      std::unique_lock<std::mutex> lock(mutex_);
     80      return capacity_;
     81    }
     82
     83
     84    /**
     85       \brief change maximal number of element stored in container
     86
     87       \since New in yat 0.19
     88    */
     89    void capacity(size_t c)
     90    {
     91      std::unique_lock<std::mutex> lock(mutex_);
     92      capacity_ = c;
     93
     94      lock.unlock();
     95      // Notify pushers that there is potentially space
     96      push_condition_.notify_all();
     97    }
    6498
    6599    /**
     
    71105    {
    72106      std::unique_lock<std::mutex> lock(mutex_);
    73       return q_.clear();
     107      q_.clear();
     108      lock.unlock(); // unlock the mutex
     109
     110      // Notify pushers that there is space to push
     111      push_condition_.notify_all();
    74112    }
    75113
     
    96134      std::unique_lock<std::mutex> lock(mutex_);
    97135      while (q_.empty())
    98         condition_.wait(lock);
     136        pop_condition_.wait(lock);
    99137      // The obvious choice would be to create a temp copy of front,
    100138      // pop the queue and then return by-value. This is, however,
     
    103141      // pass via passed reference.
    104142      static_cast<Derived*>(this)->pop_impl(value, lock);
     143      lock.unlock(); // unlock the mutex
     144      push_condition_.notify_one();
    105145    } // lock is released here
    106146
     
    108148    /**
    109149       \brief insert an element into container
     150
     151       If size of queue is equal (or greater) to its capacity, the
     152       function is waiting until this is not the case.
    110153     */
    111154    void push(const T& t)
    112155    {
    113156      std::unique_lock<std::mutex> lock(mutex_);
     157      while (q_.size() >= capacity_)
     158        push_condition_.wait(lock);
    114159      static_cast<Derived*>(this)->push_impl(t, lock);
    115160      lock.unlock(); // unlock the mutex
    116161
    117162      // Notify others that data is ready after we have unlocked
    118       condition_.notify_one();
     163      pop_condition_.notify_one();
    119164    }
    120165
     
    123168       \brief insert an element into container
    124169
    125        \note only available if configured and built with cxx11 support
    126 
    127170       \since New in yat 0.15
    128171     */
     
    130173    {
    131174      std::unique_lock<std::mutex> lock(mutex_);
     175      while (q_.size() >= capacity_)
     176        push_condition_.wait(lock);
    132177      static_cast<Derived*>(this)->push_impl(std::move(t), lock);
    133178      lock.unlock(); // unlock the mutex
    134179
    135180      // Notify others that data is ready after we have unlocked
    136       condition_.notify_one();
     181      pop_condition_.notify_one();
    137182    }
    138183
     
    158203        return false;
    159204      static_cast<Derived*>(this)->pop_impl(value, lock);
     205      lock.unlock(); // unlock the mutex
     206
     207      // Notify others that data is ready after we have unlocked
     208      push_condition_.notify_one();
     209      return true;
     210    } // lock is released here
     211
     212
     213    /**
     214       If Queue size is less than capacity push \a value and return \c
     215       true; otherwise return \c false
     216
     217       \since New in yat 0.19
     218     */
     219    bool try_push(T& value)
     220    {
     221      std::unique_lock<std::mutex> lock(mutex_);
     222      if (q_.size() >= capacity_)
     223        return false;
     224      static_cast<Derived*>(this)->push_impl(value, lock);
     225      lock.unlock(); // unlock the mutex
     226
     227      // Notify others that data is ready after we have unlocked
     228      pop_condition_.notify_one();
     229      return true;
     230    } // lock is released here
     231
     232
     233    /**
     234       If Queue size is less than capacity push \a value and return \c
     235       true; otherwise return \c false
     236
     237       \since New in yat 0.19
     238     */
     239    bool try_push(T&& value)
     240    {
     241      std::unique_lock<std::mutex> lock(mutex_);
     242      if (q_.size() >= capacity_)
     243        return false;
     244      static_cast<Derived*>(this)->push_impl(std::move(value), lock);
     245      lock.unlock(); // unlock the mutex
     246
     247      // Notify others that data is ready after we have unlocked
     248      pop_condition_.notify_one();
    160249      return true;
    161250    } // lock is released here
     
    177266                                                std::adopt_lock_t());
    178267        q_ = other.q_;
     268        capacity_ = other.capacity_;
    179269      }
    180270    }
     
    184274  private:
    185275    mutable std::mutex mutex_;
    186     std::condition_variable condition_;
     276    std::condition_variable pop_condition_;
     277    std::condition_variable push_condition_;
     278    size_t capacity_;
    187279  };
    188280
  • branches/kendall-score/yat/utility/Makefile.am

    r4064 r4066  
    101101  $(srcdir)/yat/utility/merge.h \
    102102  $(srcdir)/yat/utility/MergeIterator.h \
     103  $(srcdir)/yat/utility/multiprocess.h \
    103104  $(srcdir)/yat/utility/NNI.h \
    104105  $(srcdir)/yat/utility/Option.h \
     
    117118  $(srcdir)/yat/utility/ranking/NodeBase.h \
    118119  $(srcdir)/yat/utility/ranking/NodeValue.h \
     120  $(srcdir)/yat/utility/round.h \
    119121  $(srcdir)/yat/utility/Scheduler.h \
    120122  $(srcdir)/yat/utility/Segment.h \
     
    124126  $(srcdir)/yat/utility/SmartPtr.h \
    125127  $(srcdir)/yat/utility/SmithWaterman.h \
     128  $(srcdir)/yat/utility/SortedBuffer.h \
    126129  $(srcdir)/yat/utility/sort_index.h \
    127130  $(srcdir)/yat/utility/split.h \
  • branches/kendall-score/yat/utility/Matrix.cc

    r3938 r4066  
    9595      std::stringstream ss(e.what());
    9696      ss << "\nMatrix(std::istream&): invalid dimensions\n";
    97       throw IO_error(ss.str());
     97      std::throw_with_nested(IO_error(ss.str()));
    9898    }
    9999    catch (runtime_error& e) {
    100100      std::stringstream ss(e.what());
    101101      ss << "\nMatrix(std::istream&): invalid matrix element\n";
    102       throw IO_error(ss.str());
     102      std::throw_with_nested(IO_error(ss.str()));
    103103    }
    104104
  • branches/kendall-score/yat/utility/MatrixWeighted.cc

    r3938 r4066  
    8585      std::stringstream ss(e.what());
    8686      ss << "\nMatrixWeighted(std::istream&): invalid dimensions\n";
    87       throw IO_error(ss.str());
     87      std::throw_with_nested(IO_error(ss.str()));
    8888    }
    8989    catch (runtime_error& e) {
    9090      std::stringstream ss(e.what());
    9191      ss << "\nMatrixWeighted(std::istream&): invalid matrix element\n";
    92       throw IO_error(ss.str());
     92      std::throw_with_nested(IO_error(ss.str()));
    9393    }
    9494
  • branches/kendall-score/yat/utility/SegmentSet.h

    r4038 r4066  
    6363     */
    6464    typename me::const_iterator
    65     insert_merge(const typename me::value_type& segment)
     65    insert_merge(const Segment<T, Compare>& segment)
    6666    {
    6767      std::pair<typename me::iterator, typename me::iterator> p =
     
    7878     */
    7979    typename me::const_iterator
    80     insert_merge(typename me::value_type&& segment)
     80    insert_merge(Segment<T, Compare>&& segment)
    8181    {
    8282      std::pair<typename me::iterator, typename me::iterator> p =
     
    9696     */
    9797    typename me::iterator insert_merge(typename me::iterator hint,
    98                                        const typename me::value_type& segment)
    99     {
    100       typename me::value_type tmp(segment);
     98                                       const Segment<T, Compare>& segment)
     99    {
     100      Segment<T, Compare> tmp(segment);
    101101      return insert_merge(hint, std::move(tmp));
    102102    }
     
    108108    typename me::iterator
    109109    insert_merge(typename me::iterator hint,
    110                  typename me::value_type&& segment)
     110                 Segment<T, Compare>&& segment)
    111111    {
    112112      std::pair<typename me::iterator, typename me::iterator> p(hint, hint);
     
    171171    move_insert_merge(const std::pair<typename me::iterator,
    172172                                      typename me::iterator>& p,
    173                       typename me::value_type&& segment)
     173                      Segment<T, Compare>&& segment)
    174174    {
    175175      YAT_ASSERT(p.first==this->end() || !compare(*p.first, segment));
  • branches/kendall-score/yat/utility/Vector.cc

    r3999 r4066  
    9292      std::stringstream ss(e.what());
    9393      ss << "\nVector(std::istream&): invalid dimensions\n";
    94       throw IO_error(ss.str());
     94      std::throw_with_nested(IO_error(ss.str()));
    9595    }
    9696    catch (runtime_error& e) {
    9797      std::stringstream ss(e.what());
    9898      ss << "\nVector(std::istream&): invalid vector element\n";
    99       throw IO_error(ss.str());
     99      std::throw_with_nested(IO_error(ss.str()));
    100100    }
    101101
Note: See TracChangeset for help on using the changeset viewer.