Skip to content
Draft
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: 1 addition & 7 deletions .github/workflows/documentation-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,9 @@ jobs:

- name: Build documentation
run: pixi run --environment dev docs-build

# - name: Build and Commit
# uses: sphinx-notes/pages@master
# with:
# install_requirements: true
# documentation_path: docs/src

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs/_build/html
publish_dir: ./site
3 changes: 3 additions & 0 deletions Examples/base/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Subclassing Examples

This section gathers examples which correspond to subclassing the `easyscience.base_classes.ObjBase` class.
6 changes: 0 additions & 6 deletions Examples/base/README.rst

This file was deleted.

26 changes: 13 additions & 13 deletions Examples/base/plot_baseclass1.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""
Subclassing ObjBase - Simple Pendulum
=====================================
This example shows how to subclass :class:`easyscience.base_classes.ObjBase` with parameters from
:class:`EasyScience.variable.Parameter`. For this example a simple pendulum will be modeled.
# Subclassing ObjBase - Simple Pendulum

.. math::
This example shows how to subclass `easyscience.base_classes.ObjBase` with parameters from
`EasyScience.variable.Parameter`. For this example a simple pendulum will be modeled.

$$
y = A \sin (2 \pi f t + \phi )
$$

Imports
*******
## Imports

Firstly the necessary imports. Notice that we import numpy from easyscience. This is not done for any reason other than
saving time from multiple imports.
Expand All @@ -21,8 +21,8 @@
from easyscience.variable import Parameter

# %%
# Subclassing
# ***********
# ## Subclassing
#
# To include embedded rST, use a line of >= 20 ``#``'s or ``#%%`` between your
# rST and your code. This separates your example
# into distinct text and code blocks. You can continue writing code below the
Expand Down Expand Up @@ -53,8 +53,8 @@ def plot(self, time, axis=None, **kwargs):


# %%
# Single Example
# **************
# ## Single Example
#
# To include embedded rST, use a line of >= 20 ``#``'s or ``#%%`` between your
# rST and your code. This separates your example
# into distinct text and code blocks. You can continue writing code below the
Expand Down Expand Up @@ -82,8 +82,8 @@ def plot(self, time, axis=None, **kwargs):
fig.show()

# %%
# Multiple Examples
# *****************
# ## Multiple Examples
#
# To include embedded rST, use a line of >= 20 ``#``'s or ``#%%`` between your
# rST and your code. This separates your example
# into distinct text and code blocks. You can continue writing code below the
Expand Down
5 changes: 1 addition & 4 deletions Examples/fitting/README.rst → Examples/fitting/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.. _fitting_examples:

Fitting Examples
----------------
# Fitting Examples

This section gathers examples which demonstrate fitting functionality using EasyScience's fitting capabilities.
80 changes: 80 additions & 0 deletions Examples/fitting/plot_fitting1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
"""
# Simple Fitting Example

This example demonstrates a simple fitting procedure using `easyscience.fitting.Fitter`.
"""

import numpy as np
import matplotlib.pyplot as plt

from easyscience.fitting import Fitter
from easyscience.base_classes import ObjBase
from easyscience.variable import Parameter

# %%
# ## Define the Model
#
# We define a simple linear model with parameters `m` (slope) and `c` (intercept).


class Line(ObjBase):
def __init__(self, m: Parameter, c: Parameter):
super().__init__('line', m=m, c=c)

def __call__(self, x):
return self.c.value + self.m.value * x


# Initialize parameters
m = Parameter('m', 1)
c = Parameter('c', 1)
b = Line(m, c)

# %%
# ## Define the Fitting Function
#
# The fitting function takes the independent variable `x` and returns the model prediction.


def fit_fun(x):
return b(x)


# %%
# ## Setup the Fitter
#
# Initialize the Fitter with the model object and the fitting function.

f = Fitter(b, fit_fun)

# %%
# ## Generate Data
#
# Create some synthetic data to fit.

x = np.array([1, 2, 3])
y = np.array([2, 4, 6]) - 1
# x=1, y=1. x=2, y=3. x=3, y=5.
# Expected result: m=2, c=-1.

# %%
# ## Perform Fit
#
# Run the fit.

# We need to provide weights for the fit. Since we don't have experimental errors, we use equal weights.
weights = np.ones_like(x)
f_res = f.fit(x, y, weights=weights)

print(f'Goodness of fit (chi2): {f_res.chi2}')
print(f'Reduced chi2: {f_res.reduced_chi}')
print(f'Fitted m: {b.m.value}')
print(f'Fitted c: {b.c.value}')

# %%
# ## Plot Results

plt.scatter(x, y, label='Data')
plt.plot(x, fit_fun(x), label='Fit', color='red')
plt.legend()
plt.show()
20 changes: 0 additions & 20 deletions docs/Makefile

This file was deleted.

34 changes: 34 additions & 0 deletions docs/assets/logo_light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions docs/base_examples/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Subclassing Examples

This section gathers examples which correspond to subclassing the `easyscience.base_classes.ObjBase` class.



<div class="mkd-glr-thumbcontainer" tooltip="This example shows how to subclass easyscience.base_classes.ObjBase with parameters from EasyS...">
<!--div class="figure align-default" id="id1"-->
<img alt="Subclassing ObjBase - Simple Pendulum" src="images\thumb\mkd_glr_plot_baseclass1_thumb.png" />
<p class="caption">
<span class="caption-text">
<a class="reference internal" href="plot_baseclass1">
<span class="std std-ref">Subclassing ObjBase - Simple Pendulum</span>
</a>
</span>
<!--a class="headerlink" href="#id1" title="Permalink to this image"></a-->
</p>
<!--/div-->
</div>

<div class="mkd-glr-clear"></div>

<!-- docs_base_examples -->


<div id="download_links"></div>

[:fontawesome-solid-download: Download all examples in Python source code: base_examples_python.zip](./base_examples_python.zip){ .md-button .center}

[:fontawesome-solid-download: Download all examples in Jupyter notebooks: base_examples_jupyter.zip](./base_examples_jupyter.zip){ .md-button .center}


[Gallery generated by mkdocs-gallery](https://smarie.github.io/mkdocs-gallery){: .mkd-glr-signature }
Loading
Loading