Skip to main content

an installable package for Hybrid fitting of Sine and Cosine functions

Project description

Sublime's custom image

HOBIT: Harmonic Oscillator hyBrid fIT

Efficient fit of sine/cosine functions using a hybrid method

Read our blog

HOBIT is a Python library that combines Optuna's TPE algorithm with the flexibility of scikit-learn's LinearRegression to efficiently fit functions of the form

f(x) = y_0 + y_1 * Sin(omega * x + phi)
f(x) = y_0 + y_1 * Cos(omega * x + phi)

commonly used to describe harmonic oscillators.

Install

pip install HOBIT

Requirements

HOBIT requires Python >= 3.11 and will install the following dependencies:

  • pandas >= 2.0.0
  • numpy >= 1.26.0
  • optuna >= 3.0.0
  • scikit-learn >= 1.4.0

Get started

In the test_scripts/ folder you will find the following examples:

  1. scipy_and_gradient_descent.py — fit of a cosine function using scipy's curve_fit and a walkthrough of gradient descent.
  2. only_optuna.py — fit of a cosine function using Optuna's TPE sampler directly.
  3. hybrid_method_cos.py — fit of a cosine function using HOBIT.
  4. hybrid_method_sin.py — fit of a sine function using HOBIT.

Quick example

import numpy as np
from HOBIT import RegressionForTrigonometric

x = np.linspace(-5, 5, 100)
y = 10 + 5 * np.cos(3 * x + 2) + 1.5 * np.random.normal(size=100)

model = RegressionForTrigonometric()
model.fit_cos(x, y, n_trials=500)

print(model.best_parameters)
# {'omega': ..., 'phi': ..., 'intercept': ..., 'amplitude': ...}

y_pred = model.predict(x)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hobit-1.0.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hobit-1.0.0-py3-none-any.whl (3.1 kB view details)

Uploaded Python 3

File details

Details for the file hobit-1.0.0.tar.gz.

File metadata

  • Download URL: hobit-1.0.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.13.14 Linux/6.17.0-1018-azure

File hashes

Hashes for hobit-1.0.0.tar.gz
Algorithm Hash digest
SHA256 aa3a32751c74f9db473b42198010baf556f351fd695ed37e9014879a88184091
MD5 939bc453354ca58bedcf709e710bbc81
BLAKE2b-256 0a3b1ee7be7481821fb3b92556bbd130b1aefc819bd2f86960eb55b6307bbf58

See more details on using hashes here.

File details

Details for the file hobit-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: hobit-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 3.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.4.1 CPython/3.13.14 Linux/6.17.0-1018-azure

File hashes

Hashes for hobit-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be12a9f655f802a071ea70aed009a958a62ab79e7fa1822752c19790d3e62c2c
MD5 d47112d6689fef17dcc0a137254f4ba7
BLAKE2b-256 6a6bb4e5797a2956e8fb09babeac2f93173e866e43bee52762d84e236a588526

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page