-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Fake function with working tests and examples
- Loading branch information
Showing
8 changed files
with
325 additions
and
23 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,85 @@ | ||
# Copyright 2023 Ian Rankin | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy of this | ||
# software and associated documentation files (the "Software"), to deal in the Software | ||
# without restriction, including without limitation the rights to use, copy, modify, merge, | ||
# publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons | ||
# to whom the Software is furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all copies or | ||
# substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, | ||
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||
# PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE | ||
# FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | ||
# OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
# DEALINGS IN THE SOFTWARE. | ||
|
||
# plot_fake_function.py | ||
# Written Ian Rankin - January 2024 | ||
# | ||
# An example usage of plotting one of the random fake functions | ||
# This allows testing to see what the functions look like. | ||
|
||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import argparse | ||
import lop | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Fake function plotter') | ||
parser.add_argument('-f', type=str, default='logistic', help='Enter the type of function [linear squared logistic sin_exp]') | ||
parser.add_argument('-d', type=int, default=1, help='Enter the dimmensionality of the fake function (1 or 2) for plotting') | ||
args = parser.parse_args() | ||
|
||
dim = args.d | ||
|
||
fc = None | ||
if args.f == 'linear': | ||
fc = lop.FakeLinear(dim) | ||
elif args.f == 'squared': | ||
fc = lop.FakeSquared(dim) | ||
elif args.f == 'logistic': | ||
fc = lop.FakeLogistic(dim) | ||
elif args.f == 'sin_exp': | ||
fc = lop.FakeSinExp(dim) | ||
else: | ||
print('Unknown function: ' + str(args.f)) | ||
return | ||
|
||
if dim == 1: | ||
x = np.arange(0,10,0.01) | ||
y = fc(x) | ||
|
||
plt.plot(x,y) | ||
plt.xlabel('x input values') | ||
plt.ylabel('y output values') | ||
plt.show() | ||
elif dim == 2: | ||
grid = np.arange(0,5,0.1) | ||
xv, yv = np.meshgrid(grid, grid) | ||
x_l = xv.reshape(-1) | ||
y_l = yv.reshape(-1) | ||
pts = np.append(x_l[:,np.newaxis], y_l[:,np.newaxis],axis=1) | ||
z = fc(pts) | ||
|
||
z_plt = z.reshape(xv.shape) | ||
#print(z_plt) | ||
|
||
fig = plt.figure() | ||
|
||
cont = plt.contourf(xv, yv, z_plt) | ||
fig.colorbar(cont, label='output values') | ||
plt.xlabel('x') | ||
plt.ylabel('y') | ||
plt.show() | ||
|
||
else: | ||
print("I can't plot that dimmension") | ||
|
||
|
||
|
||
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
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
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
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
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
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
Oops, something went wrong.