Solver¶
Neural network approximation for function using Flax
FixpointSolver
¶
Bases: Module
Solving the fixed point problem $$ Ψ_κ[f](·) = f(·) $$ with neural network \(f_{nn}\) by $$ \min_θ ∫_{s ∈ \mathcal{S}} |Ψ_κ[f_{nn}](s; θ) - f_{nn}(s; θ)|^2 \mathrm{d}μ(s) $$
Source code in src/bprg/solver.py
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 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 | |
f(params, x)
¶
Evaluate the neural function \(f_{nn}(x; θ)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Parameters
|
model parameters |
required |
x
|
Array
|
array of vertex types |
required |
Returns:
| Type | Description |
|---|---|
Array
|
array of function values \(f_{nn}(x; θ)\) |
Source code in src/bprg/solver.py
Ψf(params, x)
¶
Evaluate the operator image \(Ψ[f](x; θ)\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Parameters
|
model parameters |
required |
x
|
Array
|
array of vertex types |
required |
Returns:
| Type | Description |
|---|---|
Array
|
array of function values \(Ψ[f](x; θ)\) |
Source code in src/bprg/solver.py
get_f(params)
¶
Return the neural function \(f_{nn}(·; θ)\) with \(θ\) fixed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Parameters
|
model parameters |
required |
Returns:
| Type | Description |
|---|---|
Function
|
function \(f_{nn}(·; θ)\) |
get_Ψf(params)
¶
Return the operator image \(Ψ[f](·; θ)\) with \(θ\) fixed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Parameters
|
model parameters |
required |
Returns:
| Type | Description |
|---|---|
Function
|
function \(Ψ[f](·; θ)\) |
train_step(params, opt_state, optimizer)
¶
Perform one training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Parameters
|
model parameters |
required |
opt_state
|
OptState
|
optimizer state |
required |
optimizer
|
GradientTransformation
|
optax optimizer (static) |
required |
Returns:
| Type | Description |
|---|---|
tuple[Parameters, OptState, float]
|
Updated params, opt_state, and loss |
Source code in src/bprg/solver.py
loss_fn(params)
¶
Compute the total loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
params
|
Parameters
|
model parameters |
required |
Returns:
| Type | Description |
|---|---|
float
|
scalar loss value |
Source code in src/bprg/solver.py
solve(epochs=EPOCHS, optimizer=OPTIMIZER, seed=SEED, verbose=False)
¶
Train the network to solve the fixed point problem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epochs
|
int
|
number of training epochs |
EPOCHS
|
optimizer
|
GradientTransformation
|
optax optimizer |
OPTIMIZER
|
seed
|
int
|
integer seed for JAX random key for initialization |
SEED
|
verbose
|
bool
|
whether to print loss at regular intervals |
False
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing trained function, Ψf operator, parameters, and losses |
Source code in src/bprg/solver.py
MonteCarloSolver
¶
Initialize the Monte Carlo solver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
κ
|
Kernel
|
kernel function |
required |
μ
|
TypeMeasure
|
type measure function |
required |
η
|
ThresholdMeasure
|
threshold measure function |
required |
S
|
TypeDomain
|
type domain |
required |
nv
|
VertexNum
|
number of vertices |
1000
|
ns
|
TypeNum
|
number of types |
100
|
Source code in src/bprg/solver.py
solve(nm=1000, seed=SEED)
¶
Run Monte Carlo simulations to estimate the final fraction of infected vertices after the bootstrap percolation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nm
|
SimulationNum
|
number of Monte Carlo simulations |
1000
|
seed
|
int
|
random seed for reproducibility |
SEED
|
Returns:
| Type | Description |
|---|---|
Array[float]
|
Array of estimated final fractions of infected vertices by type |