Distributions (polykin.distributions)¤
This module implements methods to create, visualize, fit, combine, integrate, etc. theoretical and experimental chain-length distributions.
DataDistribution ¤
Arbitrary numerical chain-length distribution, defined by chain size and pdf data.
PARAMETER | DESCRIPTION |
---|---|
size_data
|
Chain length or molar mass data.
TYPE:
|
pdf_data
|
Distribution data.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
M0
|
Molar mass of the repeating unit, \(M_0\). Unit = kg/mol.
TYPE:
|
name
|
Name.
TYPE:
|
Source code in src/polykin/distributions/datadistribution.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
cdf ¤
cdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the cumulative distribution function:
or
where \(m\) is the order (0: number, 1: mass).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Cumulative probability. |
Source code in src/polykin/distributions/base.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
fit ¤
fit(
dist_class: Union[
type[Flory],
type[Poisson],
type[LogNormal],
type[SchulzZimm],
],
dim: int = 1,
display_table: bool = True,
) -> Optional[
Union[AnalyticalDistribution, MixtureDistribution]
]
Fit (deconvolute) a DataDistribution
into a linear combination of
AnalyticalDistribution
(s).
PARAMETER | DESCRIPTION |
---|---|
dist_class
|
Type of distribution to be used in the fit.
TYPE:
|
dim
|
Number of individual components to use in the fit.
TYPE:
|
display_table
|
Option to display results table with information about individual components.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
AnalyticalDistribution | MixtureDistribution | None
|
If fit successful, it returns the fitted distribution. |
Source code in src/polykin/distributions/datadistribution.py
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
pdf ¤
pdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass", "gpc"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the probability density function, \(p(k)\).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Probability density. |
Source code in src/polykin/distributions/base.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
plot ¤
plot(
kind: Union[
Literal["number", "mass", "gpc"],
list[Literal["number", "mass", "gpc"]],
] = "mass",
sizeasmass: bool = False,
xscale: Literal["auto", "linear", "log"] = "auto",
xrange: Union[tuple[float, float], None] = None,
cdf: Literal[0, 1, 2] = 0,
title: Optional[str] = None,
axes: Optional[list[Axes]] = None,
return_objects: bool = False,
) -> Optional[tuple[Optional[Figure], list[Axes]]]
Plot the chain-length distribution.
PARAMETER | DESCRIPTION |
---|---|
kind
|
Kind(s) of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
xscale
|
x-axis scale.
TYPE:
|
xrange
|
x-axis range.
TYPE:
|
cdf
|
y-axis where cdf is displayed. If
TYPE:
|
title
|
Title of plot. If
TYPE:
|
axes
|
Matplotlib Axes object.
TYPE:
|
return_objects
|
If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Figure | None, list[Axes]] | None
|
Figure and Axes objects if return_objects is |
Source code in src/polykin/distributions/base.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
Flory ¤
Flory-Schulz (aka most-probable) chain-length distribution.
This distribution is based on the following number probability density function:
where \(a=1-1/DP_n\). Mathematically speaking, this is a geometric distribution.
PARAMETER | DESCRIPTION |
---|---|
DPn
|
Number-average degree of polymerization, \(DP_n\).
TYPE:
|
M0
|
Molar mass of the repeating unit, \(M_0\). Unit = kg/mol.
TYPE:
|
name
|
Name
TYPE:
|
Examples:
Define a Flory distribution and evaluate the corresponding probability density function and cumulative distribution function for representative chain lengths.
>>> from polykin.distributions import Flory
>>> a = Flory(100, M0=0.050, name='A')
>>> a
type: Flory
name: A
DPn: 100.0
DPw: 199.0
DPz: 298.5
PDI: 1.99
M0: 0.050 kg/mol
Mn: 5.000 kg/mol
Mw: 9.950 kg/mol
Mz: 14.925 kg/mol
>>> a.pdf(a.DPn)
0.003697296376497271
>>> a.cdf([a.DPn, a.DPw, a.DPz])
array([0.26793532, 0.59535432, 0.80159978])
Source code in src/polykin/distributions/analyticaldistributions.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|
cdf ¤
cdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the cumulative distribution function:
or
where \(m\) is the order (0: number, 1: mass).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Cumulative probability. |
Source code in src/polykin/distributions/base.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
pdf ¤
pdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass", "gpc"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the probability density function, \(p(k)\).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Probability density. |
Source code in src/polykin/distributions/base.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
plot ¤
plot(
kind: Union[
Literal["number", "mass", "gpc"],
list[Literal["number", "mass", "gpc"]],
] = "mass",
sizeasmass: bool = False,
xscale: Literal["auto", "linear", "log"] = "auto",
xrange: Union[tuple[float, float], None] = None,
cdf: Literal[0, 1, 2] = 0,
title: Optional[str] = None,
axes: Optional[list[Axes]] = None,
return_objects: bool = False,
) -> Optional[tuple[Optional[Figure], list[Axes]]]
Plot the chain-length distribution.
PARAMETER | DESCRIPTION |
---|---|
kind
|
Kind(s) of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
xscale
|
x-axis scale.
TYPE:
|
xrange
|
x-axis range.
TYPE:
|
cdf
|
y-axis where cdf is displayed. If
TYPE:
|
title
|
Title of plot. If
TYPE:
|
axes
|
Matplotlib Axes object.
TYPE:
|
return_objects
|
If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Figure | None, list[Axes]] | None
|
Figure and Axes objects if return_objects is |
Source code in src/polykin/distributions/base.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
random ¤
random(
shape: Optional[Union[int, tuple[int, ...]]] = None
) -> Union[int, IntArray]
Generate random sample of chain lengths according to the corresponding number probability density/mass function.
PARAMETER | DESCRIPTION |
---|---|
shape
|
Sample shape.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int | IntArray
|
Random sample of chain lengths. |
Source code in src/polykin/distributions/base.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
|
LogNormal ¤
Log-normal chain-length distribution.
This distribution is based on the following number probability density function:
where \(\mu = \ln{(DP_n/\sqrt{PDI})}\) and \(\sigma=\sqrt{\ln(PDI)}\).
PARAMETER | DESCRIPTION |
---|---|
DPn
|
Number-average degree of polymerization, \(DP_n\).
TYPE:
|
PDI
|
Polydispersity index, \(PDI\).
TYPE:
|
M0
|
Molar mass of the repeating unit, \(M_0\). Unit = kg/mol.
TYPE:
|
name
|
Name.
TYPE:
|
Examples:
Define a log-normal distribution and evaluate the corresponding probability density function and cumulative distribution function for representative chain lengths.
>>> from polykin.distributions import LogNormal
>>> a = LogNormal(100, PDI=3., M0=0.050, name='A')
>>> a
type: LogNormal
name: A
DPn: 100.0
DPw: 300.0
DPz: 900.0
PDI: 3.00
M0: 0.050 kg/mol
Mn: 5.000 kg/mol
Mw: 15.000 kg/mol
Mz: 45.000 kg/mol
>>> a.pdf(a.DPn)
0.003317780747597256
>>> a.cdf([a.DPn, a.DPw, a.DPz])
array([0.3001137, 0.6998863, 0.9420503])
Source code in src/polykin/distributions/analyticaldistributions.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 |
|
cdf ¤
cdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the cumulative distribution function:
or
where \(m\) is the order (0: number, 1: mass).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Cumulative probability. |
Source code in src/polykin/distributions/base.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
pdf ¤
pdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass", "gpc"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the probability density function, \(p(k)\).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Probability density. |
Source code in src/polykin/distributions/base.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
plot ¤
plot(
kind: Union[
Literal["number", "mass", "gpc"],
list[Literal["number", "mass", "gpc"]],
] = "mass",
sizeasmass: bool = False,
xscale: Literal["auto", "linear", "log"] = "auto",
xrange: Union[tuple[float, float], None] = None,
cdf: Literal[0, 1, 2] = 0,
title: Optional[str] = None,
axes: Optional[list[Axes]] = None,
return_objects: bool = False,
) -> Optional[tuple[Optional[Figure], list[Axes]]]
Plot the chain-length distribution.
PARAMETER | DESCRIPTION |
---|---|
kind
|
Kind(s) of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
xscale
|
x-axis scale.
TYPE:
|
xrange
|
x-axis range.
TYPE:
|
cdf
|
y-axis where cdf is displayed. If
TYPE:
|
title
|
Title of plot. If
TYPE:
|
axes
|
Matplotlib Axes object.
TYPE:
|
return_objects
|
If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Figure | None, list[Axes]] | None
|
Figure and Axes objects if return_objects is |
Source code in src/polykin/distributions/base.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
random ¤
random(
shape: Optional[Union[int, tuple[int, ...]]] = None
) -> Union[int, IntArray]
Generate random sample of chain lengths according to the corresponding number probability density/mass function.
PARAMETER | DESCRIPTION |
---|---|
shape
|
Sample shape.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int | IntArray
|
Random sample of chain lengths. |
Source code in src/polykin/distributions/base.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
|
Poisson ¤
Poisson chain-length distribution.
This distribution is based on the following number probability density function:
where \(a=DP_n-1\).
PARAMETER | DESCRIPTION |
---|---|
DPn
|
Number-average degree of polymerization, \(DP_n\).
TYPE:
|
M0
|
Molar mass of the repeating unit, \(M_0\). Unit = kg/mol.
TYPE:
|
name
|
Name
TYPE:
|
Examples:
Define a Poisson distribution and evaluate the corresponding probability density function and cumulative distribution function for representative chain lengths.
>>> from polykin.distributions import Poisson
>>> a = Poisson(100, M0=0.050, name='A')
>>> a
type: Poisson
name: A
DPn: 100.0
DPw: 101.0
DPz: 102.0
PDI: 1.01
M0: 0.050 kg/mol
Mn: 5.000 kg/mol
Mw: 5.050 kg/mol
Mz: 5.099 kg/mol
>>> a.pdf(a.DPn)
0.04006147193133002
>>> a.cdf([a.DPn, a.DPw, a.DPz])
array([0.48703481, 0.52669305, 0.56558077])
Source code in src/polykin/distributions/analyticaldistributions.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
cdf ¤
cdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the cumulative distribution function:
or
where \(m\) is the order (0: number, 1: mass).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Cumulative probability. |
Source code in src/polykin/distributions/base.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
pdf ¤
pdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass", "gpc"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the probability density function, \(p(k)\).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Probability density. |
Source code in src/polykin/distributions/base.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
plot ¤
plot(
kind: Union[
Literal["number", "mass", "gpc"],
list[Literal["number", "mass", "gpc"]],
] = "mass",
sizeasmass: bool = False,
xscale: Literal["auto", "linear", "log"] = "auto",
xrange: Union[tuple[float, float], None] = None,
cdf: Literal[0, 1, 2] = 0,
title: Optional[str] = None,
axes: Optional[list[Axes]] = None,
return_objects: bool = False,
) -> Optional[tuple[Optional[Figure], list[Axes]]]
Plot the chain-length distribution.
PARAMETER | DESCRIPTION |
---|---|
kind
|
Kind(s) of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
xscale
|
x-axis scale.
TYPE:
|
xrange
|
x-axis range.
TYPE:
|
cdf
|
y-axis where cdf is displayed. If
TYPE:
|
title
|
Title of plot. If
TYPE:
|
axes
|
Matplotlib Axes object.
TYPE:
|
return_objects
|
If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Figure | None, list[Axes]] | None
|
Figure and Axes objects if return_objects is |
Source code in src/polykin/distributions/base.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
random ¤
random(
shape: Optional[Union[int, tuple[int, ...]]] = None
) -> Union[int, IntArray]
Generate random sample of chain lengths according to the corresponding number probability density/mass function.
PARAMETER | DESCRIPTION |
---|---|
shape
|
Sample shape.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int | IntArray
|
Random sample of chain lengths. |
Source code in src/polykin/distributions/base.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
|
SchulzZimm ¤
Schulz-Zimm chain-length distribution.
This distribution is based on the following number probability density function:
where \(k = 1/(DP_n-1)\) and \(\theta = DP_n(PDI-1)\). Mathematically speaking, this is a Gamma distribution.
PARAMETER | DESCRIPTION |
---|---|
DPn
|
Number-average degree of polymerization, \(DP_n\).
TYPE:
|
PDI
|
Polydispersity index, \(PDI\).
TYPE:
|
M0
|
Molar mass of the repeating unit, \(M_0\). Unit = kg/mol.
TYPE:
|
name
|
Name.
TYPE:
|
Examples:
Define a Schulz-Zimm distribution and evaluate the corresponding probability density function and cumulative distribution function for representative chain lengths.
>>> from polykin.distributions import SchulzZimm
>>> a = SchulzZimm(100, PDI=3., M0=0.050, name='A')
>>> a
type: SchulzZimm
name: A
DPn: 100.0
DPw: 300.0
DPz: 500.0
PDI: 3.00
M0: 0.050 kg/mol
Mn: 5.000 kg/mol
Mw: 15.000 kg/mol
Mz: 25.000 kg/mol
>>> a.pdf(a.DPn)
0.0024197072451914337
>>> a.cdf([a.DPn, a.DPw, a.DPz])
array([0.19874804, 0.60837482, 0.82820286])
Source code in src/polykin/distributions/analyticaldistributions.py
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
|
cdf ¤
cdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the cumulative distribution function:
or
where \(m\) is the order (0: number, 1: mass).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Cumulative probability. |
Source code in src/polykin/distributions/base.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
|
pdf ¤
pdf(
size: Union[float, FloatArrayLike],
kind: Literal["number", "mass", "gpc"] = "mass",
sizeasmass: bool = False,
) -> Union[float, FloatArray]
Evaluate the probability density function, \(p(k)\).
PARAMETER | DESCRIPTION |
---|---|
size
|
Chain length or molar mass.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Probability density. |
Source code in src/polykin/distributions/base.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
|
plot ¤
plot(
kind: Union[
Literal["number", "mass", "gpc"],
list[Literal["number", "mass", "gpc"]],
] = "mass",
sizeasmass: bool = False,
xscale: Literal["auto", "linear", "log"] = "auto",
xrange: Union[tuple[float, float], None] = None,
cdf: Literal[0, 1, 2] = 0,
title: Optional[str] = None,
axes: Optional[list[Axes]] = None,
return_objects: bool = False,
) -> Optional[tuple[Optional[Figure], list[Axes]]]
Plot the chain-length distribution.
PARAMETER | DESCRIPTION |
---|---|
kind
|
Kind(s) of distribution.
TYPE:
|
sizeasmass
|
Switch size input between chain-length (if
TYPE:
|
xscale
|
x-axis scale.
TYPE:
|
xrange
|
x-axis range.
TYPE:
|
cdf
|
y-axis where cdf is displayed. If
TYPE:
|
title
|
Title of plot. If
TYPE:
|
axes
|
Matplotlib Axes object.
TYPE:
|
return_objects
|
If
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[Figure | None, list[Axes]] | None
|
Figure and Axes objects if return_objects is |
Source code in src/polykin/distributions/base.py
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
random ¤
random(
shape: Optional[Union[int, tuple[int, ...]]] = None
) -> Union[int, IntArray]
Generate random sample of chain lengths according to the corresponding number probability density/mass function.
PARAMETER | DESCRIPTION |
---|---|
shape
|
Sample shape.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
int | IntArray
|
Random sample of chain lengths. |
Source code in src/polykin/distributions/base.py
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
|
WeibullNycanderGold_pdf ¤
WeibullNycanderGold_pdf(
k: Union[int, IntArrayLike], v: float, r: float
) -> Union[float, FloatArray]
Weibull, Nycander and Golds's analytical chain-length distribution for living polymerization with different initiation and polymerization rate coefficients.
For a living polymerization with only initiation and propagation (i.e., constant number of chains), the number fraction of chains of length \(k\) can computed in two steps. First, the number fraction of unreacted initiator molecules, \(p_0=p(0)\), is found by solving the equation:
where \(v\) denotes the number-average degree of polymerization of all chains, including unreacted initiator molecules, and \(r=k_p/k_i\) is the ratio of the polymerization and initiation rate coefficients. Then, the number fraction of chains with \(k \ge 1\) monomer units can be evaluated by:
where \(\Gamma\) is the regularized upper incomplete gamma function. For \(r>1\), the argument of \(\Gamma\) is always positive, while for \(r<1\) it is negative. This analytical solution has an obvious singularity at \(r=1\); in that case, the solution reduces to the well-known Poisson distribution:
valid for \(k \ge 0\).
Note
- The solution is numerically unstable in certain domains, namely for \(r\) close to 1, and also for \(k>>v\). This is an intrinsic feature of the equation.
- For \(|r-1|<10^{-2}\), the algorithm automatically switches to the Poisson distribution. Some numerical discontinuity at this boundary is to be expected.
- For \(r<1\), no solution is currently computed, because the incomplete gamma function algorithm available in SciPy is restricted to positive arguments.
References
- Weibull, B.; Nycander, E.. "The Distribution of Compounds Formed in the Reaction." Acta Chemica Scandinavica 49 (1995): 207-216.
- Gold, L. "Statistics of polymer molecular size distribution for an invariant number of propagating chains." The Journal of Chemical Physics 28.1 (1958): 91-99.
PARAMETER | DESCRIPTION |
---|---|
k
|
Chain length (>=0).
TYPE:
|
v
|
Number-average degree of polymerization considering chains with zero length.
TYPE:
|
r
|
Ratio of propagation and initiation rate coefficients.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
float | FloatArray
|
Number probability density. |
Examples:
Compute the fraction of chains with lengths 0 to 2 for a system with \(r=5\) and \(v=1\).
>>> from polykin.distributions import WeibullNycanderGold_pdf
>>> WeibullNycanderGold_pdf([0, 1, 2], 1., 5)
array([0.58958989, 0.1295864 , 0.11493254])
Source code in src/polykin/distributions/analyticaldistributions.py
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 |
|
convolve_moments ¤
convolve_moments(
q0: float,
q1: float,
q2: float,
r0: float,
r1: float,
r2: float,
) -> tuple[float, float, float]
Compute the first three moments of the convolution of two distributions.
If \(P = Q * R\) is the convolution of \(Q\) and \(R\), defined as:
then the first three moments of \(P\) are related to the moments of \(Q\) and \(R\) by:
where \(p_i\), \(q_i\) and \(r_i\) denote the \(i\)-th moments of \(P\), \(Q\) and \(R\), respectively.
PARAMETER | DESCRIPTION |
---|---|
q0
|
0-th moment of \(Q\).
TYPE:
|
q1
|
1-st moment of \(Q\).
TYPE:
|
q2
|
2-nd moment of \(Q\).
TYPE:
|
r0
|
0-th moment of \(R\).
TYPE:
|
r1
|
1-st moment of \(R\).
TYPE:
|
r2
|
2-nd moment of \(R\).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[float, float, float]
|
0-th, 1-st and 2-nd moments of \(P=Q*R\). |
Examples:
>>> from polykin.distributions import convolve_moments
>>> convolve_moments(1., 1e2, 2e4, 1., 50., 5e4)
(1.0, 150.0, 80000.0)
Source code in src/polykin/distributions/base.py
900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 |
|
convolve_moments_self ¤
convolve_moments_self(
q0: float, q1: float, q2: float, order: int = 1
) -> tuple[float, float, float]
Compute the first three moments of the k-th order convolution of a distribution with itself.
If \(P^k\) is the \(k\)-th order convolution of \(Q\) with itself, defined as:
then the first three moments of \(P^k\) are related to the moments of \(Q\) by:
where \(p_i\) and \(q_i\) denote the \(i\)-th moments of \(P^k\) and \(Q\), respectively.
PARAMETER | DESCRIPTION |
---|---|
q0
|
0-th moment of \(Q\).
TYPE:
|
q1
|
1-st moment of \(Q\).
TYPE:
|
q2
|
2-nd moment of \(Q\).
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tuple[float, float, float]
|
0-th, 1-st and 2-nd moments of \(P^k=(Q*Q)*...\). |
Examples:
>>> from polykin.distributions import convolve_moments_self
>>> convolve_moments_self(1., 1e2, 2e4, 2)
(1.0, 300.0, 120000.0)
Source code in src/polykin/distributions/base.py
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 |
|
plotdists ¤
plotdists(
dists: list[Distribution],
kind: Literal["number", "mass", "gpc"],
title: Optional[str] = None,
**kwargs
) -> Figure
Plot a list of distributions in a joint plot.
PARAMETER | DESCRIPTION |
---|---|
dists
|
List of distributions to be ploted together.
TYPE:
|
kind
|
Kind of distribution.
TYPE:
|
title
|
Title of plot.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Figure
|
Matplotlib Figure object holding the joint plot. |
Examples:
>>> from polykin.distributions import Flory, LogNormal, plotdists
>>> a = Flory(100, M0=0.050, name='A')
>>> b = LogNormal(100, PDI=3., M0=0.050, name='B')
>>> fig = plotdists([a, b], kind='gpc', xrange=(1, 1e4), cdf=2)
>>> fig.show()
Source code in src/polykin/distributions/base.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 |
|