Force Harmonic Polynomial Module
The force_harmonic_polynomial
module implements a harmonic oscillator force with variable stiffness represented as a polynomial function of time.
Classes
- class VariableStiffnessHarmonicForcePolynomial(kappai, kappaf, tf, coef_list, continuous=False, normalized=False)[source]
Bases:
BaseHarmonicForce
Harmonic oscillator force with a variable stiffness that is a learnable parameter. The stiffness is a polynomial function of time. The center is fixed at zero.
- Parameters:
kappai (float)
kappaf (float)
tf (float)
coef_list (list)
continuous (bool)
normalized (bool)
- __init__(kappai, kappaf, tf, coef_list, continuous=False, normalized=False)[source]
- Parameters:
kappai (float) – Initial stiffness.
kappaf (float) – Final stiffness.
tf (float) – final time of the protocol.
coef_list (list) – List of coefficients for the polynomial function
time. (of)
continuous (bool) – If True, the stiffness is a continuous function
t=tf. (of time at t=0 and)
normalized (bool) – If True, the argument is normalized to be t/tf
t. (instead of)
- kappa(t)[source]
Stiffness as a polynomial function of time. If continuous = False:
kappa(t) = sum(coef_list[i] * t^i) for i in range(len(coef_list))
- If continuous = True:
- kappa(t) = kappai + (t/tf) * (kappaf - kappai)
(t/tf)*(1-t/tf)* sum(coef_list[i] * t^i) for i in range(len(coef_list))
- If normalized:
use t/tf instead of t in the polynomial.
- Parameters:
t – time to compute the stiffness
- Returns:
the stiffness value at time t
- Return type:
torch.tensor
Example Usage
Here’s an example of how to create and use a polynomial harmonic force:
import langesim_optim as lso
# Create a polynomial force with initial coefficients
force = lso.force_harmonic_polynomial.VariableStiffnessHarmonicForcePolynomial(
kappai=1.0, # Initial stiffness
kappaf=2.0, # Final stiffness
tf=1.0, # Final time
coef_list=[0.0, 0.0, 1.0], # Quadratic polynomial coefficients
continuous=True, # Enforce continuity at endpoints
normalized=True # Use normalized time t/tf
)
# Get stiffness at a specific time
t = 0.5
k = force.kappa(t)