mirror of
https://github.com/ejeanboris/MDAF.git
synced 2025-06-16 01:58:40 +00:00
Reorganised the code into a PyPI package format
This commit is contained in:
70
Sample codes/Analyse_folders_and_description.ipynb
Normal file
70
Sample codes/Analyse_folders_and_description.ipynb
Normal file
@ -0,0 +1,70 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "abstract-broad",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Program to read through folders in a file-path and spit out description"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "similar-algeria",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def find_algorithm():\n",
|
||||
" import os # To enable you walk through the OS directory\n",
|
||||
" import re # To enable pattern recognition\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" # Take file-path and extract names of files in file-path as list data type\n",
|
||||
" check_folder = input(\"Please enter the file-path of the folder: \\n\")\n",
|
||||
" found_items = os.listdir(check_folder)\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" # Initialize what the pattern to be searched for should look like\n",
|
||||
" pattern = \"\\W\\W\\W\"\n",
|
||||
" \n",
|
||||
" # Look into the individual txt files and extraxt the description \n",
|
||||
" for items in range(0, len(found_items)):\n",
|
||||
" print(f\"\\n({items + 1}): I found the file named: {found_items[items]}\")\n",
|
||||
" inside_file = check_folder + '\\\\' + found_items[items]\n",
|
||||
" \n",
|
||||
" with open(inside_file, mode ='r', encoding = 'utf-8') as myfile:\n",
|
||||
" print(\"Inside the file, I found this description: \\n \")\n",
|
||||
" contents = myfile.readlines()\n",
|
||||
" \n",
|
||||
" for indexing in range(0, len(contents)):\n",
|
||||
" if re.search(pattern, contents[indexing]):\n",
|
||||
" print(contents[indexing+1])\n",
|
||||
" break\n",
|
||||
" \n",
|
||||
" print(\"\\n\\n\")"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.9.2"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
31
Sample codes/Testingground.py
Normal file
31
Sample codes/Testingground.py
Normal file
@ -0,0 +1,31 @@
|
||||
from mpl_toolkits.mplot3d import Axes3D
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import cm
|
||||
from matplotlib.ticker import LinearLocator, FormatStrFormatter
|
||||
import numpy as np
|
||||
|
||||
|
||||
fig = plt.figure()
|
||||
ax = fig.gca(projection='3d')
|
||||
|
||||
# Make data.
|
||||
X = np.arange(-5, 5, 0.25)
|
||||
Y = np.arange(-5, 5, 0.25)
|
||||
X, Y = np.meshgrid(X, Y)
|
||||
R = np.sqrt(X**2 + Y**2)
|
||||
Z = np.sin(R)
|
||||
print(Z[1])
|
||||
|
||||
# Plot the surface.
|
||||
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
|
||||
linewidth=0, antialiased=False)
|
||||
|
||||
# Customize the z axis.
|
||||
ax.set_zlim(-1.01, 1.01)
|
||||
ax.zaxis.set_major_locator(LinearLocator(10))
|
||||
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
|
||||
|
||||
# Add a color bar which maps values to colors.
|
||||
fig.colorbar(surf, shrink=0.5, aspect=5)
|
||||
|
||||
plt.show()
|
31
Sample codes/calcFeatures.R
Normal file
31
Sample codes/calcFeatures.R
Normal file
@ -0,0 +1,31 @@
|
||||
library(reticulate)
|
||||
library(flacco)
|
||||
library(parallelMap)
|
||||
library(parallel)
|
||||
|
||||
# Other packages to install
|
||||
# plyr
|
||||
# RANN
|
||||
# numDeriv
|
||||
# e1071
|
||||
# mda - needs to install gcc-fortran on Operating system
|
||||
|
||||
|
||||
genTestFeatures <- function(path,pypath, upper=10, lower=-10, n) {
|
||||
|
||||
use_python(pypath)
|
||||
source_python(path)
|
||||
|
||||
X = createInitialSample(n.obs = 500, dim = n, control = list(init_sample.type = 'lhs', init_sample.lower = lower, init_sample.upper = upper))
|
||||
|
||||
y = apply(X, 1, main)
|
||||
|
||||
testfunc <- createFeatureObject(X = X, y = y, fun = main, lower = lower, upper = upper, blocks = 10)
|
||||
|
||||
n.cores = detectCores()
|
||||
parallelStart(mode = "local", logging = FALSE, show.info = FALSE)
|
||||
system.time((levelset.par = calculateFeatures(testfunc , control = list('cm_angle.show_warnings'=TRUE, 'cm_grad.show_warnings'=TRUE, 'ic.show_warnings'=TRUE))))
|
||||
parallelStop()
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user