feat: Allows you to pass in rng to generate monte carlo dipoles
All checks were successful
gitea-physics/pdme/pipeline/head This commit looks good

This commit is contained in:
2022-04-18 11:46:44 -05:00
parent ccbb048d26
commit ab244ed91d
2 changed files with 19 additions and 8 deletions

View File

@@ -88,20 +88,28 @@ class FixedMagnitudeModel(Model):
[OscillatingDipole(numpy.array([px, py, pz]), s_pts, frequency)]
)
def get_n_single_dipoles(self, n: int, max_frequency: float) -> numpy.ndarray:
def get_n_single_dipoles(
self, n: int, max_frequency: float, rng_to_use: numpy.random.Generator = None
) -> numpy.ndarray:
# psw
theta = 2 * numpy.pi * self.rng.random(n)
phi = numpy.arccos(2 * self.rng.random(n) - 1)
rng: numpy.random.Generator
if rng_to_use is None:
rng = self.rng
else:
rng = rng_to_use
theta = 2 * numpy.pi * rng.random(n)
phi = numpy.arccos(2 * rng.random(n) - 1)
px = self.pfixed * numpy.cos(theta) * numpy.sin(phi)
py = self.pfixed * numpy.sin(theta) * numpy.sin(phi)
pz = self.pfixed * numpy.cos(phi)
sx = self.rng.uniform(self.xmin, self.xmax, n)
sy = self.rng.uniform(self.ymin, self.ymax, n)
sz = self.rng.uniform(self.zmin, self.zmax, n)
sx = rng.uniform(self.xmin, self.xmax, n)
sy = rng.uniform(self.ymin, self.ymax, n)
sz = rng.uniform(self.zmin, self.zmax, n)
w = self.rng.uniform(1, max_frequency, n)
w = rng.uniform(1, max_frequency, n)
return numpy.array([px, py, pz, sx, sy, sz, w]).T

View File

@@ -1,4 +1,5 @@
import numpy
import numpy.random
import scipy.optimize
from typing import Callable, Sequence, Tuple, List
from pdme.measurement import (
@@ -30,7 +31,9 @@ class Model:
def get_dipoles(self, frequency: float) -> OscillatingDipoleArrangement:
raise NotImplementedError
def get_n_single_dipoles(self, n: int, max_frequency: float) -> numpy.ndarray:
def get_n_single_dipoles(
self, n: int, max_frequency: float, rng: numpy.random.Generator = None
) -> numpy.ndarray:
raise NotImplementedError
def solution_single_dipole(self, pt: numpy.ndarray) -> OscillatingDipole: