Skip to content

Commit

Permalink
Added code to generate another plot for the journal paper
Browse files Browse the repository at this point in the history
  • Loading branch information
mariolpantunes committed Mar 7, 2024
1 parent f7a8066 commit 386b94b
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
61 changes: 61 additions & 0 deletions examples/plot_journal_function.py
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()
8 changes: 5 additions & 3 deletions requirements.txt
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

0 comments on commit 386b94b

Please sign in to comment.