#! /usr/bin/env python # def simplex01_sample ( m, n, seed ): #*****************************************************************************80 # ## SIMPLEX01_SAMPLE samples the unit simplex in M dimensions. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 June 2015 # # Author: # # John Burkardt # # Reference: # # Reuven Rubinstein, # Monte Carlo Optimization, Simulation, and Sensitivity # of Queueing Networks, # Krieger, 1992, # ISBN: 0894647644, # LC: QA298.R79. # # Parameters: # # Input, integer M, the spatial dimension. # # Input, integer N, the number of points. # # Input/output, integer SEED, a seed for the random # number generator. # # Output, real X(M,N), the points. # import numpy as np from r8vec_uniform_01 import r8vec_uniform_01 x = np.zeros ( [ m, n ] ) for j in range ( 0, n ): e, seed = r8vec_uniform_01 ( m + 1, seed ); e_sum = 0.0 for i in range ( 0, m + 1 ): e[i] = - np.log ( e[i] ) e_sum = e_sum + e[i] for i in range ( 0, m ): x[i,j] = e[i] / e_sum return x, seed def simplex01_sample_test ( ): #*****************************************************************************80 # ## SIMPLEX01_SAMPLE_TEST tests SIMPLEX01_SAMPLE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 23 June 2015 # # Author: # # John Burkardt # import platform from r8mat_transpose_print import r8mat_transpose_print print ( '' ) print ( 'SIMPLEX01_SAMPLE_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' SIMPLEX01_SAMPLE samples the unit simplex in M dimensions.' ) m = 3 n = 10 seed = 123456789 x, seed = simplex01_sample ( m, n, seed ) r8mat_transpose_print ( m, n, x, ' Sample points in the unit simplex.' ) # # Terminate. # print ( '' ) print ( 'SIMPLEX01_SAMPLE_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) simplex01_sample_test ( ) timestamp ( )