Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions notebooks/cookbooks/configs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@
" self.normalization = normalization\n",
" self.sigma = sigma\n",
"\n",
" def model_data_from(self, xvalues: np.ndarray) -> np.ndarray:\n",
" def model_data_from(self, xvalues: np.ndarray, xp=np) -> np.ndarray:\n",
" \"\"\"\n",
" The usual method that returns the 1D data of the `Gaussian` profile.\n",
" \"\"\"\n",
" transformed_xvalues = xvalues - self.centre\n",
"\n",
" return np.multiply(\n",
" np.divide(self.normalization, self.sigma * np.sqrt(2.0 * np.pi)),\n",
" np.exp(-0.5 * np.square(np.divide(transformed_xvalues, self.sigma))),\n",
" return xp.multiply(\n",
" xp.divide(self.normalization, self.sigma * xp.sqrt(2.0 * xp.pi)),\n",
" xp.exp(-0.5 * xp.square(xp.divide(transformed_xvalues, self.sigma))),\n",
" )\n"
],
"outputs": [],
Expand Down
3 changes: 2 additions & 1 deletion notebooks/features/graphical_models.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"simultaneously fitting 3 noisy 1D Gaussians. However, graphical models are an extensive feature and at the end of\n",
"this example we will discuss other options available in **PyAutoFit** for composing a fitting a graphical model.\n",
"\n",
"The **HowToFit** tutorials contain a chapter dedicated to composing and fitting graphical models.\n",
"The **HowToFit** tutorials contain a chapter dedicated to composing and fitting graphical models, available\n",
"in the standalone repository at https://github.com/PyAutoLabs/HowToFit (see `scripts/chapter_3_graphical_models/`).\n",
"\n",
"__Contents__\n",
"\n",
Expand Down
16 changes: 8 additions & 8 deletions notebooks/overview/overview_1_the_basics.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@
" self.normalization = normalization\n",
" self.sigma = sigma\n",
"\n",
" def model_data_from(self, xvalues: np.ndarray) -> np.ndarray:\n",
" def model_data_from(self, xvalues: np.ndarray, xp=np) -> np.ndarray:\n",
" \"\"\"\n",
" Returns the 1D Gaussian profile on a line of Cartesian x coordinates.\n",
"\n",
Expand All @@ -221,9 +221,9 @@
" \"\"\"\n",
" transformed_xvalues = xvalues - self.centre\n",
"\n",
" return np.multiply(\n",
" np.divide(self.normalization, self.sigma * np.sqrt(2.0 * np.pi)),\n",
" np.exp(-0.5 * np.square(np.divide(transformed_xvalues, self.sigma))),\n",
" return xp.multiply(\n",
" xp.divide(self.normalization, self.sigma * xp.sqrt(2.0 * xp.pi)),\n",
" xp.exp(-0.5 * xp.square(xp.divide(transformed_xvalues, self.sigma))),\n",
" )\n",
"\n",
" @property\n",
Expand Down Expand Up @@ -981,7 +981,7 @@
" self.normalization = normalization\n",
" self.rate = rate\n",
"\n",
" def model_data_from(self, xvalues: np.ndarray):\n",
" def model_data_from(self, xvalues: np.ndarray, xp=np):\n",
" \"\"\"\n",
" Returns the symmetric 1D Exponential on an input list of Cartesian x coordinates.\n",
"\n",
Expand All @@ -995,9 +995,9 @@
" xvalues\n",
" The x coordinates in the original reference frame of the data.\n",
" \"\"\"\n",
" transformed_xvalues = np.subtract(xvalues, self.centre)\n",
" return self.normalization * np.multiply(\n",
" self.rate, np.exp(-1.0 * self.rate * abs(transformed_xvalues))\n",
" transformed_xvalues = xp.subtract(xvalues, self.centre)\n",
" return self.normalization * xp.multiply(\n",
" self.rate, xp.exp(-1.0 * self.rate * abs(transformed_xvalues))\n",
" )\n"
],
"outputs": [],
Expand Down
2 changes: 1 addition & 1 deletion notebooks/overview/overview_3_statistical_methods.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"\n",
"A full description of using hierarchical models is given below:\n",
"\n",
"https://github.com/Jammy2211/autofit_workspace/blob/release/notebooks/howtofit/chapter_graphical_models/tutorial_4_hierachical_models.ipynb\n",
"https://github.com/PyAutoLabs/HowToFit/blob/main/notebooks/chapter_3_graphical_models/tutorial_4_hierachical_models.ipynb\n",
"\n",
"Model Comparison\n",
"----------------\n",
Expand Down
10 changes: 5 additions & 5 deletions scripts/cookbooks/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- Labels: Config files which specify the labels of model component parameters for visualization.
"""

# from autoconf import setup_notebook; setup_notebook()
# from autoconf import setup_notebook; setup_notebook()

import numpy as np
from os import path
Expand Down Expand Up @@ -56,15 +56,15 @@ def __init__(
self.normalization = normalization
self.sigma = sigma

def model_data_from(self, xvalues: np.ndarray) -> np.ndarray:
def model_data_from(self, xvalues: np.ndarray, xp=np) -> np.ndarray:
"""
The usual method that returns the 1D data of the `Gaussian` profile.
"""
transformed_xvalues = xvalues - self.centre

return np.multiply(
np.divide(self.normalization, self.sigma * np.sqrt(2.0 * np.pi)),
np.exp(-0.5 * np.square(np.divide(transformed_xvalues, self.sigma))),
return xp.multiply(
xp.divide(self.normalization, self.sigma * xp.sqrt(2.0 * xp.pi)),
xp.exp(-0.5 * xp.square(xp.divide(transformed_xvalues, self.sigma))),
)


Expand Down
18 changes: 9 additions & 9 deletions scripts/overview/overview_1_the_basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
To begin, lets import ``autofit`` (and ``numpy``) using the convention below:
"""

# from autoconf import setup_notebook; setup_notebook()
# from autoconf import setup_notebook; setup_notebook()

import autofit as af
import autofit.plot as aplt
Expand Down Expand Up @@ -150,7 +150,7 @@ def __init__(
self.normalization = normalization
self.sigma = sigma

def model_data_from(self, xvalues: np.ndarray) -> np.ndarray:
def model_data_from(self, xvalues: np.ndarray, xp=np) -> np.ndarray:
"""
Returns the 1D Gaussian profile on a line of Cartesian x coordinates.

Expand All @@ -167,9 +167,9 @@ def model_data_from(self, xvalues: np.ndarray) -> np.ndarray:
"""
transformed_xvalues = xvalues - self.centre

return np.multiply(
np.divide(self.normalization, self.sigma * np.sqrt(2.0 * np.pi)),
np.exp(-0.5 * np.square(np.divide(transformed_xvalues, self.sigma))),
return xp.multiply(
xp.divide(self.normalization, self.sigma * xp.sqrt(2.0 * xp.pi)),
xp.exp(-0.5 * xp.square(xp.divide(transformed_xvalues, self.sigma))),
)

@property
Expand Down Expand Up @@ -665,7 +665,7 @@ def __init__(
self.normalization = normalization
self.rate = rate

def model_data_from(self, xvalues: np.ndarray):
def model_data_from(self, xvalues: np.ndarray, xp=np):
"""
Returns the symmetric 1D Exponential on an input list of Cartesian x coordinates.

Expand All @@ -679,9 +679,9 @@ def model_data_from(self, xvalues: np.ndarray):
xvalues
The x coordinates in the original reference frame of the data.
"""
transformed_xvalues = np.subtract(xvalues, self.centre)
return self.normalization * np.multiply(
self.rate, np.exp(-1.0 * self.rate * abs(transformed_xvalues))
transformed_xvalues = xp.subtract(xvalues, self.centre)
return self.normalization * xp.multiply(
self.rate, xp.exp(-1.0 * self.rate * abs(transformed_xvalues))
)


Expand Down
Loading