-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code to generate another plot for the journal paper
- Loading branch information
1 parent
f7a8066
commit 386b94b
Showing
2 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env python3 | ||
# coding: utf-8 | ||
|
||
__author__ = 'Mário Antunes' | ||
__version__ = '0.1' | ||
__email__ = '[email protected]' | ||
__status__ = 'Development' | ||
__license__ = 'MIT' | ||
__copyright__ = ''' | ||
Copyright (c) 2021-2023 Stony Brook University | ||
Copyright (c) 2021-2023 The Research Foundation of SUNY | ||
''' | ||
|
||
|
||
import jax | ||
import logging | ||
import numpy as np | ||
import jax.numpy as jnp | ||
import jax.scipy.optimize | ||
import matplotlib.pyplot as plt | ||
|
||
import pyBlindOpt.pso as pso | ||
|
||
plt.style.use('seaborn-v0_8-paper') | ||
plt.rcParams['figure.autolayout'] = True | ||
plt.rcParams['figure.figsize'] = (4, 4) | ||
plt.rcParams['lines.linewidth'] = 2 | ||
|
||
|
||
def function(x): | ||
return 1/x | ||
|
||
|
||
def make_curvature(f): | ||
fp = jax.vmap(jax.grad(f)) | ||
fpp = jax.vmap(jax.grad(jax.grad(f))) | ||
return lambda x: fpp(x)/jnp.power((1.0+jnp.power(fp(x), 2.0)), 1.5) | ||
|
||
|
||
def main(): | ||
x_axis_min = 0.0 | ||
x_axis_max = 3.0 | ||
x = jnp.arange(x_axis_min, x_axis_max, 0.2) | ||
y = function(x) | ||
|
||
# compute the curvature (using numerical methods and JAX) | ||
kf = make_curvature(function) | ||
k = kf(x) | ||
|
||
# find the max of kf | ||
bounds = np.asarray([(x_axis_min, x_axis_max)]) | ||
max_kf, _ = pso.particle_swarm_optimization(lambda x: -kf(x), bounds, n_pop=15, n_iter=15, verbose=False) | ||
|
||
plt.plot(x,y) | ||
plt.plot(x,k) | ||
plt.axvline(x = max_kf[0], color = 'b', label = 'axvline - full height') | ||
|
||
plt.show() | ||
|
||
if __name__ == '__main__': | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
tqdm>=4.66.1 | ||
tqdm>=4.66.1 | ||
pdoc>=14.3.0 | ||
numpy>=1.26.2 | ||
imageio>=2.33.1 | ||
imageio>=2.33.1 | ||
jax[cpu]>=0.4.25 | ||
pyBlindOpt>=0.1.1 | ||
matplotlib>=3.8.2 | ||
scikit-learn>=1.3.2 | ||
exectimeit>=0.1.1 | ||
exectimeit>=0.1.1 | ||
pyUTSAlgorithms>=0.1.2 |