The module "mbootstrap_idx" of the Mastrave modelling library


Daniele de Rigo


Copyright and license notice of the function mbootstrap_idx



Copyright © 2009,2010,2011,2012,2013,2014,2015 Daniele de Rigo

The file mbootstrap_idx.m is part of Mastrave.

Mastrave is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Mastrave is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Mastrave. If not, see

Function declaration



[resampled_vals, resampled_pos, category_glossary] = 
   mbootstrap_idx( values          , 
                   n_runs          ,  
                   weights    = [] ,  
                   categories = [] ,  
                   rand_func  = [] ) 




Module to compute a bootstrap statistical resampling over an array of values . Pseudo-random sampling with replacement is applied to the position of each element in values . The statistical resampling generates n_runs vectors of bootstrapped positions, returned as the columns of the matrix resampled_pos . Each column has the same number of lines as the ones of the original values . The corresponding matrix of bootstrapped values is returned in resampled_vals . Within each bootstrapped column, the sampling with replacement implies that a given element may be missing while another one may be resampled multiple times. For equally weighted elements, each bootstrapping run contains on average about 63.2 % of distinct elements sampled from values .

To each element of values , an optional weight may be associated so as to alter the frequency with which that particular element is resampled. For this purpose, an array weights may be passed as optional input argument. Higher weights increase the frequency of resampling of the corresponding elements in values .

An optional array of categories may be passed to identify a partition of values in subsets. Each bootstrap run preserves the number of elements resampled from each category. The array category_glossary is returned with the unique categories.

Finally, the handle to a custom function rand_func may be passed so as for the pseudo-random sampling to be generated with it.

Input arguments



 values             ::numeric,col_vector::
                    Array of elements to be boostrapped.

 n_runs             ::scalar_index::
                    Number of bootstrap runs.

 weights            ::nonnegative,col_vector::
                    Array of custom weights associated to the elements
                    of  values .
                    If  weights  is an empty matrix [], the same weight
                    is associated to each element of  values .
                    If omitted, the default value is an empty matrix: [].

 categories         ::integer,col_vector::
                    Array of custom categories associated to the elements
                    of  values . 
                    If  categories  is an empty matrix [], the same 
                    category is associated to each element of  values .
                    If omitted, the default value is an empty matrix: [].

 rand_func          ::function_handle::
                    Handle to a custom function which generates the
                    pseudo-random resampling.
                    If  rand_func  is an empty matrix [], the function 
                    @rand is used.
                    If omitted, the default value is an empty matrix: [].

Example of usage



   n_vals     = 8
   categories = ceil( rand( n_vals, 1 )*3 )*10;
   values     = categories * 100 + [1:n_vals].';
   weights    = [1:n_vals].';
   disp( 'values weights categories' )
   disp( [values weights categories] )

   [ res_vals, res_pos, category_glossary ] = ...
       mbootstrap_idx( values, 5, weights, categories );


   values( res_pos )
   assert( isequal( res_vals , values( res_pos ) ) ) 

See also:


Version: 0.3.8




The Mastrave modelling library is committed to provide reusable and general - but also robust and scalable - modules for research modellers dealing with computational science.  You can help the Mastrave project by providing feedbacks on unexpected behaviours of this module.  Despite all efforts, all of us - either developers or users - (should) know that errors are unavoidable.  However, the free software paradigm successfully highlights that scientific knowledge freedom also implies an impressive opportunity for collectively evolve the tools and ideas upon which our daily work is based.  Reporting a problem that you found using Mastrave may help the developer team to find a possible bug.  Please, be aware that Mastrave is entirely based on voluntary efforts: in order for your help to be as effective as possible, please read carefully the section on reporting problems.  Thank you for your collaboration.

Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016 Daniele de Rigo

This page is licensed under a Creative Commons Attribution-NoDerivs 3.0 Italy License.

This document is also part of the book:
de Rigo, D. (2012). Semantic Array Programming with Mastrave - Introduction to Semantic Computational Modelling.

Valid XHTML 1.0 Transitional