utils
ComputeAATS(v, v_model)
Compute the Average Absolute Truth Score (AATS) between original and model data.
Parameters:
-
v
(Tensor
) –The original data.
-
v_model
(Tensor
) –The model data.
Returns:
Source code in src/pyrkm/utils.py
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 |
|
Compute_FID(synthetic_images, real_images)
Compute the Frechet Inception Distance (FID) between synthetic and real images.
Parameters:
-
synthetic_images
(Tensor
) –The synthetic images.
-
real_images
(Tensor
) –The real images.
Returns:
-
float
–The FID score.
Source code in src/pyrkm/utils.py
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 |
|
Compute_S(v, v_gen)
Compute the relative entropy between original and generated data.
Parameters:
-
v
(Tensor
) –The original data.
-
v_gen
(Tensor
) –The generated data.
Returns:
-
float
–The relative entropy.
Source code in src/pyrkm/utils.py
324 325 326 327 328 329 330 331 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 |
|
Covariance_error(centered_data_original, centered_data_model, Nv)
Compute the covariance error between original and model data.
Parameters:
-
centered_data_original
(Tensor
) –The centered original data.
-
centered_data_model
(Tensor
) –The centered model data.
-
Nv
(int
) –The number of visible units.
Returns:
-
Tensor
–The covariance error.
Source code in src/pyrkm/utils.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
|
PowerSpectrum_MSE(v, v_model)
Compute the mean squared error of the power spectrum between original and model data.
Parameters:
-
v
(Tensor
) –The original data.
-
v_model
(Tensor
) –The model data.
Returns:
-
Tensor
–The mean squared error of the power spectrum.
Source code in src/pyrkm/utils.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
Third_moment_error(centered_data_original, centered_data_model, Nv)
Compute the third moment error between original and model data.
Parameters:
-
centered_data_original
(Tensor
) –The centered original data.
-
centered_data_model
(Tensor
) –The centered model data.
-
Nv
(int
) –The number of visible units.
Returns:
-
Tensor
–The third moment error.
Source code in src/pyrkm/utils.py
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 |
|
binarize_image(image, threshold=128)
Binarize the image using a threshold.
Parameters:
-
image
(ndarray
) –The input image.
-
threshold
(int
, default:128
) –The threshold value (default is 128).
Returns:
-
ndarray
–The binarized image.
Source code in src/pyrkm/utils.py
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
ensure_dir(dirname)
Create a directory if it does not exist.
Parameters:
-
dirname
(str
) –The name of the directory to create.
Source code in src/pyrkm/utils.py
488 489 490 491 492 493 494 495 496 497 |
|
generate_S_matrix(shape, target)
Generate a random matrix with values between 0 and 1, adjusted to achieve the desired average.
Parameters:
Returns:
-
ndarray
–The generated matrix.
Source code in src/pyrkm/utils.py
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
|
generate_synthetic_data(target_entropy, data_size, structured=True)
Generate synthetic data with the specified target entropy.
Parameters:
-
target_entropy
(float
) –The target entropy value.
-
data_size
(tuple
) –The size of the data to generate.
-
structured
(bool
, default:True
) –If True, generate structured data (default is True).
Returns:
-
ndarray
–The generated synthetic data.
Source code in src/pyrkm/utils.py
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 438 439 440 441 442 |
|
getbasebias(data)
Returns the maximum likelihood estimate of the visible bias, given the data. If no data is given the RBMs bias value is return, but is highly recommended to pass the data.
Parameters:
-
data
(array - like
) –The input data.
Returns:
-
Tensor
–The base bias.
Source code in src/pyrkm/utils.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
load_model(name, delete_previous=False, model_state_path='model_states/')
Load a model from the specified path.
Parameters:
-
name
(str
) –The name of the model to load.
-
delete_previous
(bool
, default:False
) –If True, delete previous model checkpoints except the latest one (default is False).
-
model_state_path
(str
, default:'model_states/'
) –The path to the model state directory (default is 'model_states/').
Returns:
-
bool
–True if the model is loaded successfully, False otherwise.
-
object
–The loaded model if successful, otherwise an empty list.
Source code in src/pyrkm/utils.py
18 19 20 21 22 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 |
|
make_grid(array, nrow=8, padding=2)
Create a grid of images.
Parameters:
-
array
(array - like
) –The array of images.
-
nrow
(int
, default:8
) –The number of images in each row (default is 8).
-
padding
(int
, default:2
) –The amount of padding between images (default is 2).
Returns:
-
array - like
–The grid of images.
Source code in src/pyrkm/utils.py
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 |
|
my_entropy(data)
Compute the entropy per image and per pixel.
Parameters:
-
data
(ndarray
) –The input data.
Returns:
Source code in src/pyrkm/utils.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 |
|
show_and_save(file_name, img, cmap='gray', vmin=None, vmax=None, save=False, savename='')
Display and optionally save an image.
Parameters:
-
file_name
(str
) –The title of the image.
-
img
(array - like
) –The image data.
-
cmap
(str
, default:'gray'
) –The colormap to use (default is 'gray').
-
vmin
(float
, default:None
) –The minimum data value that corresponds to colormap (default is None).
-
vmax
(float
, default:None
) –The maximum data value that corresponds to colormap (default is None).
-
save
(bool
, default:False
) –If True, save the image to a file (default is False).
-
savename
(str
, default:''
) –The name of the file to save the image (default is '').
Source code in src/pyrkm/utils.py
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 |
|
unpickle(file)
Unpickle a file.
Parameters:
-
file
(str
) –The file to unpickle.
Source code in src/pyrkm/utils.py
500 501 502 503 504 505 506 507 508 509 510 |
|