-
Notifications
You must be signed in to change notification settings - Fork 3
Python
The Python script can be used as follows to create M sets each containing N random values that sum up to 1.0:
import numpy as np
import PieShareDistribution as PSD
# make sure we get for this example reproducible results
np.random.seed(seed=12345)
M = 3 # number of random number sets
N = 5 # number of random numbers that need to sum up to C
# matrix of random sets (# rows = M, # of columns = N)
rand = PSD.PieShareDistribution(M, N, remainder=True)The matrix contains M=3 sets each containing N=5 values:
rand[0,:] # [ 0.48492752, 0.06133198, 0.04384398, 0.08384854, 0.32604797]
rand[1,:] # [ 0.18915093, 0.21120041, 0.4866893 , 0.07378246, 0.03917689]
rand[2,:] # [ 0.29212136, 0.21071729, 0.24744715, 0.24005194, 0.00966226]They all sum up to 1.0:
np.sum(rand[:,:],axis=1) # [ 1. 1. 1.]For most applications such as Sensitivity Analysis, however, the method is providing the user with random numbers distributed between 0 and 1 that need to be used to perform the analysis.
Hence, the algorithm allows you to provide a matrix of random numbers R (M rows and N-1 columns) that will be transformed into N weights that will sum up to 1.0.
np.random.seed(seed=12345)
M = 3 # number of random number sets
N = 5 # number of random numbers that need to sum up to 1.0
R = np.random.rand(M,N-1)
rand = PSD.PieShareDistribution(M, N, remainder=True, randomnumbers=R)The matrix contains M=3 sets each containing N=5 values:
rand[0,:] # [ 0.48492752, 0.06133198, 0.04384398, 0.08384854, 0.32604797]
rand[1,:] # [ 0.18915093, 0.21120041, 0.4866893 , 0.07378246, 0.03917689]
rand[2,:] # [ 0.29212136, 0.21071729, 0.24744715, 0.24005194, 0.00966226]
© 2019-2021 - PieShareDistribution - juliane.mai@uwaterloo.ca
Funded under IMPC project of Global Water Futures program.
Table of contents