radioactiveshrimp 0.1.0__cp39-abi3-manylinux_2_28_x86_64.whl → 0.1.2__cp39-abi3-manylinux_2_28_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- radioactiveshrimp/distributions/__init.py__ +5 -0
- radioactiveshrimp/distributions/cvdistributions.py +111 -0
- radioactiveshrimp/matrix/__init.py__ +5 -0
- radioactiveshrimp/matrix/elementary.py +201 -0
- {radioactiveshrimp-0.1.0.dist-info → radioactiveshrimp-0.1.2.dist-info}/METADATA +4 -1
- radioactiveshrimp-0.1.2.dist-info/RECORD +13 -0
- {radioactiveshrimp-0.1.0.dist-info → radioactiveshrimp-0.1.2.dist-info}/WHEEL +1 -1
- radioactiveshrimp-0.1.0.dist-info/RECORD +0 -9
@@ -0,0 +1,111 @@
|
|
1
|
+
import secrets
|
2
|
+
import numpy as np
|
3
|
+
# import matplotlib.pyplot as plt
|
4
|
+
import math as m
|
5
|
+
|
6
|
+
def uniform(a:float = 0.0, b:float = 1.0)->float:
|
7
|
+
"""
|
8
|
+
Generate cryptographically Secure uniform sample
|
9
|
+
|
10
|
+
Args:
|
11
|
+
a (float): lower bound value (default 0.0)
|
12
|
+
b (float): upper bound value (default 1.0)
|
13
|
+
|
14
|
+
Returns:
|
15
|
+
float representing uniform sample
|
16
|
+
|
17
|
+
Example:
|
18
|
+
>>> uniform()
|
19
|
+
0.3546927444895387
|
20
|
+
>>> uniform()
|
21
|
+
0.21098189931876055
|
22
|
+
"""
|
23
|
+
# 53 random bits gives 53-bit precision double
|
24
|
+
u = secrets.randbits(53)/(1<<53) # in [0,1)
|
25
|
+
return a+(b-a)*u
|
26
|
+
|
27
|
+
def exponentialdist(lamb):
|
28
|
+
"""
|
29
|
+
Generate exponentially distributed sample
|
30
|
+
|
31
|
+
Args:
|
32
|
+
lamb (float or int >0): lambda value of exponential distrobution
|
33
|
+
|
34
|
+
Returns:
|
35
|
+
x: float representing the exponentially distributed sample
|
36
|
+
|
37
|
+
Raises:
|
38
|
+
ValueError: if lambda is not greater than 0
|
39
|
+
|
40
|
+
Example:
|
41
|
+
>>> uexponentialdist(1)
|
42
|
+
0.6839328417240588
|
43
|
+
>>> uexponentialdist(1)
|
44
|
+
2.901353101723147
|
45
|
+
>>> exponentialdist(.5)
|
46
|
+
2.451134119865936
|
47
|
+
"""
|
48
|
+
if lamb<=0:
|
49
|
+
raise ValueError('Lambda must be greater than 0')
|
50
|
+
|
51
|
+
y = uniform()
|
52
|
+
x = -(1/lamb)*np.log(y)
|
53
|
+
return x
|
54
|
+
|
55
|
+
|
56
|
+
def poissondist(lamb):
|
57
|
+
"""
|
58
|
+
Generate poisson distributed sample
|
59
|
+
|
60
|
+
Args:
|
61
|
+
lamb (int or float > 0): lambda value of poisson distribution
|
62
|
+
|
63
|
+
Returns:
|
64
|
+
i: int representing poisson distributed sample
|
65
|
+
|
66
|
+
Example:
|
67
|
+
>>> poissondist(1)
|
68
|
+
1
|
69
|
+
>>> poissondist(1)
|
70
|
+
3
|
71
|
+
>>> poissondist(10)
|
72
|
+
9
|
73
|
+
"""
|
74
|
+
if lamb<=0:
|
75
|
+
raise ValueError('Lambda must be greater than 0')
|
76
|
+
|
77
|
+
elamb = np.exp(-lamb)
|
78
|
+
i = 0
|
79
|
+
y = uniform()
|
80
|
+
prob = elamb
|
81
|
+
while y>prob:
|
82
|
+
i = i+1
|
83
|
+
factorial = m.factorial(i)
|
84
|
+
power = lamb**i
|
85
|
+
# print(y,i,elamb, power, factorial)
|
86
|
+
prob = prob + (power/factorial)*elamb
|
87
|
+
|
88
|
+
return i
|
89
|
+
|
90
|
+
|
91
|
+
# # draw histogram of 100,000 randomly distributed samples using exponential distribution
|
92
|
+
# samplexs = []
|
93
|
+
# for _ in range(100000):
|
94
|
+
# samplexs.append(exponentialdist(1))
|
95
|
+
|
96
|
+
# plt.figure()
|
97
|
+
# hist = plt.hist(samplexs, bins='auto', orientation='horizontal', histtype='bar')
|
98
|
+
# plt.xlabel('count')
|
99
|
+
# plt.ylabel('X')
|
100
|
+
# plt.show()
|
101
|
+
|
102
|
+
# # draw histogram of 100,000 randomly distributed samples using exponential distribution
|
103
|
+
# samplexs = []
|
104
|
+
# for _ in range(100000):
|
105
|
+
# samplexs.append(poissondist(10))
|
106
|
+
|
107
|
+
# plt.figure()
|
108
|
+
# hist = plt.hist(samplexs, bins='auto', histtype='bar')
|
109
|
+
# plt.xlabel('X')
|
110
|
+
# plt.ylabel('count')
|
111
|
+
# plt.show()
|
@@ -0,0 +1,201 @@
|
|
1
|
+
import torch
|
2
|
+
import math
|
3
|
+
|
4
|
+
def rowswap(M, idxSourceRow, idxTargetRow):
|
5
|
+
"""
|
6
|
+
Swap rows in a matrix.
|
7
|
+
|
8
|
+
Args:
|
9
|
+
M (matrix/pytorch tensor): Matrix of values
|
10
|
+
idxSourceRow (int): Index value of one of the rows to be swapped (indexing from 1)
|
11
|
+
idxTargetRow (int): Index value of one of the rows to be swapped (indexing from 1)
|
12
|
+
|
13
|
+
Returns:
|
14
|
+
mat: Matrix with the indicated rows swapped
|
15
|
+
|
16
|
+
Example:
|
17
|
+
>>> rowswap(torch.tensor([[1,2,3],[4,5,6]]), 1,2)
|
18
|
+
tensor([[4,5,6],[1,2,3]])
|
19
|
+
"""
|
20
|
+
# print("DOING ROW SWAP")
|
21
|
+
mat = M.clone()
|
22
|
+
# print('swap: ', idxSourceRow, idxTargetRow)
|
23
|
+
temptarget = M[idxTargetRow-1, :]
|
24
|
+
mat[idxTargetRow-1] = M[idxSourceRow-1]
|
25
|
+
mat[idxSourceRow-1] = temptarget
|
26
|
+
return mat
|
27
|
+
|
28
|
+
def rowscale(M, idxRow, scaleFactor):
|
29
|
+
"""
|
30
|
+
Scale one row of matrix by scalar value.
|
31
|
+
|
32
|
+
Args:
|
33
|
+
M (matrix/pytorch tensor): Matrix of values
|
34
|
+
idxRow (int): Index (starting from 1) of row to be scaled
|
35
|
+
scaleFactor (number int or float): Value to scale each element in the row by
|
36
|
+
|
37
|
+
Returns:
|
38
|
+
mat: Matrix with the indicated row scaled
|
39
|
+
|
40
|
+
Example:
|
41
|
+
>>> rowscale(torch.tensor([[1,2,3],[4,5,6]]), 1,5)
|
42
|
+
tensor([[5,10,15],[4,5,6]])
|
43
|
+
"""
|
44
|
+
# print('DOING ROW SCALE')
|
45
|
+
M[idxRow-1] = M[idxRow-1, :]*scaleFactor
|
46
|
+
return M
|
47
|
+
|
48
|
+
def rowreplacement(M, idxFirstRow, idxSecondRow, scaleJ, scaleK):
|
49
|
+
"""
|
50
|
+
Replace row in matrix by scaling and adding to other row.
|
51
|
+
|
52
|
+
Args:
|
53
|
+
M (matrix/pytorch tensor): Matrix of values
|
54
|
+
idxFirstRow (int): Index of the row to be updated
|
55
|
+
idxSecondRow (int): Index of the row to be added into the updated row
|
56
|
+
scaleJ (number int or float): Scale factor used for the firstRow elements
|
57
|
+
scaleK (number int or float): Scale factor used for the secondRow elements
|
58
|
+
|
59
|
+
Returns:
|
60
|
+
mat: Matrix with the indicated row scaled and summed with the scale of the second row
|
61
|
+
|
62
|
+
Example:
|
63
|
+
>>> rowreplacement(torch.tensor([[1,2,3],[4,5,6]]), 1,2,2,1)
|
64
|
+
tensor([[6,9,12],[4,5,6]])
|
65
|
+
"""
|
66
|
+
# print('DOING ROW REPLACE')
|
67
|
+
# print(M, idxFirstRow, idxSecondRow, scaleJ, scaleK)
|
68
|
+
mat = M.clone()
|
69
|
+
firstScaled = rowscale(mat, idxFirstRow, scaleJ)[idxFirstRow-1]
|
70
|
+
secondScaled = rowscale(mat, idxSecondRow, scaleK)[idxSecondRow-1]
|
71
|
+
firstScaled = firstScaled + secondScaled
|
72
|
+
M[idxFirstRow-1] = firstScaled
|
73
|
+
return M
|
74
|
+
|
75
|
+
def rref(M):
|
76
|
+
"""
|
77
|
+
Calculate reduced row echelon form of a matrix
|
78
|
+
|
79
|
+
Args:
|
80
|
+
M (matrix/pytorch tensor): Matrix of values
|
81
|
+
|
82
|
+
Returns:
|
83
|
+
mat: Matrix in rref
|
84
|
+
|
85
|
+
Example:
|
86
|
+
>>> rref(torch.tensor([[1,2,3],[4,5,6]]))
|
87
|
+
tensor([[ 1, 0, -1],[ 0, 1, 2]])
|
88
|
+
"""
|
89
|
+
mat = M.clone()
|
90
|
+
pivotFound = False
|
91
|
+
totalRows= mat.shape[0]
|
92
|
+
# print(totalRows)
|
93
|
+
manualRowidx = 0
|
94
|
+
for colidx in range(len(mat[0])):
|
95
|
+
if manualRowidx==totalRows:
|
96
|
+
break
|
97
|
+
for rowidx in range(manualRowidx, totalRows):
|
98
|
+
# print(rowidx, colidx)
|
99
|
+
# print(mat[rowidx, colidx].item())
|
100
|
+
if mat[rowidx, colidx].item() == 1 or mat[rowidx, colidx].item() == 1.0 :
|
101
|
+
if rowidx>manualRowidx:
|
102
|
+
mat = rowswap(mat, rowidx+1, manualRowidx+1)
|
103
|
+
# print(mat)
|
104
|
+
rowidx = manualRowidx
|
105
|
+
pivot = [rowidx,colidx]
|
106
|
+
# mat = reduceCol(mat, pivot)
|
107
|
+
pivotFound = True
|
108
|
+
break
|
109
|
+
if pivotFound == False: #no value in column = 1
|
110
|
+
if mat[manualRowidx, colidx].item()==0:
|
111
|
+
for rowidx in range(manualRowidx, totalRows):
|
112
|
+
if mat[rowidx,colidx].item() != 0:
|
113
|
+
mat = rowswap(mat, manualRowidx+1, rowidx+1)
|
114
|
+
# print(mat)
|
115
|
+
pivotFound=True
|
116
|
+
pivot = [manualRowidx, colidx]
|
117
|
+
break
|
118
|
+
else: #current pivot item not 0
|
119
|
+
pivotFound = True
|
120
|
+
pivot = [manualRowidx, colidx]
|
121
|
+
if pivotFound ==True:
|
122
|
+
mat = reduceCol(mat, pivot)
|
123
|
+
manualRowidx+=1
|
124
|
+
pivotFound = False
|
125
|
+
# print('*'*50)
|
126
|
+
# print(mat)
|
127
|
+
# print()
|
128
|
+
return mat
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
def reduceCol(M, pivot):
|
133
|
+
"""
|
134
|
+
Reduces the column of a matrix based on pivot value to acheive rref.
|
135
|
+
|
136
|
+
Args:
|
137
|
+
M (matrix/pytorch tensor): Matrix of values
|
138
|
+
pivot ([int, int]): List (len=2) of integer values representing the row, column index for the current pivot
|
139
|
+
|
140
|
+
Returns:
|
141
|
+
mat: Matrix with the column of focus reduced
|
142
|
+
|
143
|
+
Example:
|
144
|
+
>>> reduceCol(torch.tensor([[1,2],[3,4]]), [1,1])
|
145
|
+
tensor([[1,0],[1,0]])
|
146
|
+
"""
|
147
|
+
# print('doing reduction')
|
148
|
+
pivotRow = pivot[0]
|
149
|
+
pivotCol = pivot[1]
|
150
|
+
|
151
|
+
# if M[pivotRow,pivotCol].item() == 0:
|
152
|
+
# pivotCol+=1
|
153
|
+
|
154
|
+
if M[pivotRow, pivotCol].item() != 1:
|
155
|
+
try:
|
156
|
+
scale = 1/M[pivotRow, pivotCol].item()
|
157
|
+
# print(scale)
|
158
|
+
M = rowscale(M, pivotRow+1, scale)
|
159
|
+
except:
|
160
|
+
pass
|
161
|
+
|
162
|
+
|
163
|
+
for rowidx in range(len(M)):
|
164
|
+
if rowidx != pivotRow:
|
165
|
+
# print(M[rowidx, pivotCol].item())
|
166
|
+
if M[rowidx,pivotCol].item() ==0:
|
167
|
+
pass
|
168
|
+
else:
|
169
|
+
fractionCheck, _ = math.modf(M[rowidx, pivotCol].item())
|
170
|
+
if fractionCheck != 0: #check if its a fraction
|
171
|
+
scale = M[rowidx, pivotCol].item()
|
172
|
+
# print(scale)
|
173
|
+
M = rowreplacement(M, rowidx+1, pivotRow+1, 1, scale*-1)
|
174
|
+
else:
|
175
|
+
scale = M[rowidx, pivotCol].item()/1
|
176
|
+
# print(M, rowidx, pivotRow, 1, scale*-1)
|
177
|
+
M = rowreplacement(M, rowidx+1, pivotRow+1, 1, scale*-1)
|
178
|
+
return M
|
179
|
+
|
180
|
+
|
181
|
+
# Matrix = torch.tensor([[0,1,1],[1,1,6],[2,1,8]], dtype=torch.float16)
|
182
|
+
|
183
|
+
# print(rowswap(Matrix, 4,1))
|
184
|
+
# print(rowscale(Matrix, 1, 10))
|
185
|
+
# print(rowreplacement(Matrix, 1,6,16,-1))
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
# Matrix = torch.tensor([[1,3,0,0,3], [0,0,1,0,9], [0,0,0,1,-4]], dtype=torch.float16)
|
190
|
+
# print(Matrix)
|
191
|
+
# M = rowswap(Matrix, 1,2)
|
192
|
+
# print(M)
|
193
|
+
# M = rowscale(M, 1,(1/3))
|
194
|
+
# print(M)
|
195
|
+
# M = rowreplacement(M, 3, 1, 1, -3)
|
196
|
+
# print(M)
|
197
|
+
|
198
|
+
# Matrix = torch.tensor([[1,2,3],[4,5,6],[7,8,9]], dtype=torch.float16)
|
199
|
+
|
200
|
+
|
201
|
+
# print(rref(Matrix))
|
@@ -1,6 +1,9 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: radioactiveshrimp
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.2
|
4
|
+
Requires-Dist: matplotlib>=3.10.6
|
5
|
+
Requires-Dist: numpy>=2.3.3
|
6
|
+
Requires-Dist: torch>=2.8.0
|
4
7
|
Requires-Dist: twine>=6.1.0
|
5
8
|
Summary: Add your description here
|
6
9
|
Author-email: radioactiveshrimp <radioactiveshrimpmail@gmail.com>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
radioactiveshrimp-0.1.2.dist-info/METADATA,sha256=eIFvbRoU_QV2ADRG--hldQQI256vfOcPQ6leK0jYZXI,412
|
2
|
+
radioactiveshrimp-0.1.2.dist-info/WHEEL,sha256=VCoUqQjnl5wExkC-2PG3I2s7-FBXYum-vf1jh8qiYg8,97
|
3
|
+
radioactiveshrimp/__init__.py,sha256=QY4ait-Lo2WQdyx7MU8N6a1v2ZYyAmYRqzYqdNbiavI,101
|
4
|
+
radioactiveshrimp/_core.abi3.so,sha256=3IMwsP7UrgNWdKdw2Pl11_VUQF8NqPy1xyyPuzkREdA,489672
|
5
|
+
radioactiveshrimp/_core.pyi,sha256=b6oJaUXUzEzqUE5rpqefV06hl8o_JCU8pgKgIIzQgmc,33
|
6
|
+
radioactiveshrimp/differential/__init.py__,sha256=jOhQKr6xM_7TVUt0GWRddtkgBvNn5I873WZcArT-GtE,101
|
7
|
+
radioactiveshrimp/differential/discrete.py,sha256=9-w6Avz4MZfu8gFhJU8kTvryn9oT2xS1TvvYQ_8pmPU,1371
|
8
|
+
radioactiveshrimp/distributions/__init.py__,sha256=hZX2UFt54wJG4zDLuTTTonDSA-anWvfjhDmR-akYcn4,182
|
9
|
+
radioactiveshrimp/distributions/cvdistributions.py,sha256=UEiO_RYFQYqHybI_wcOdpOrxHToXRpLFsB58dwvI4vU,2599
|
10
|
+
radioactiveshrimp/matrix/__init.py__,sha256=EoerrXlfmd2lI9grb3jxqIhHn-bzLtYhRKyxI0RVgaE,166
|
11
|
+
radioactiveshrimp/matrix/elementary.py,sha256=zPiBG24F5zIncrrVWbiXEp1oFnHw2xNKy5quF0GBOuc,6333
|
12
|
+
radioactiveshrimp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
13
|
+
radioactiveshrimp-0.1.2.dist-info/RECORD,,
|
@@ -1,9 +0,0 @@
|
|
1
|
-
radioactiveshrimp-0.1.0.dist-info/METADATA,sha256=hBcyOB8eYNUHqcmuxiZE3ymZbJTnA-H15M7MmDhDaEs,322
|
2
|
-
radioactiveshrimp-0.1.0.dist-info/WHEEL,sha256=rXa1hNKJPd-J1se02jkvuZn4v_WM-W9q2R8LeAdqQiM,97
|
3
|
-
radioactiveshrimp/__init__.py,sha256=QY4ait-Lo2WQdyx7MU8N6a1v2ZYyAmYRqzYqdNbiavI,101
|
4
|
-
radioactiveshrimp/_core.abi3.so,sha256=3IMwsP7UrgNWdKdw2Pl11_VUQF8NqPy1xyyPuzkREdA,489672
|
5
|
-
radioactiveshrimp/_core.pyi,sha256=b6oJaUXUzEzqUE5rpqefV06hl8o_JCU8pgKgIIzQgmc,33
|
6
|
-
radioactiveshrimp/differential/__init.py__,sha256=jOhQKr6xM_7TVUt0GWRddtkgBvNn5I873WZcArT-GtE,101
|
7
|
-
radioactiveshrimp/differential/discrete.py,sha256=9-w6Avz4MZfu8gFhJU8kTvryn9oT2xS1TvvYQ_8pmPU,1371
|
8
|
-
radioactiveshrimp/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
9
|
-
radioactiveshrimp-0.1.0.dist-info/RECORD,,
|