Utilities

# pylint: disable=pointless-statement

SingletonObjects


source

SingletonObjects


def SingletonObjects(
    
):

A utility for refrencing objects that should only be declared once.

UniqueNamer


source

UniqueNamer


def UniqueNamer(
    
):

A utility for ensuring the names of functions are unique.

FunctionsList


source

FunctionsList


def FunctionsList(
    
):

A utility for storing functions created, keyed on the function name.

Memory


source

Memory


def Memory(
    
):

A utility for recording global values.

NumberStats


source

NumberStats


def NumberStats(
    
):

A utility for calculating the statistics of a number.

FunctionsData


source

FunctionsData


def FunctionsData(
    
):

Data collected for a set of functions

# for x in range(10.0):
#     NumberStats.getInstance().add(x)
#     NumberStats.getInstance().add(-x)

# NumberStats.getInstance().report()
# from pct.functions import Proportional
# prop = Proportional()
# UniqueNamer.getInstance().report()
# FunctionsList.getInstance().report()

source

dynamic_module_import


def dynamic_module_import(
    modulename, package:NoneType=None
):

source

dynamic_class_load


def dynamic_class_load(
    modulename, classname
):
#import importlib
#importlib.import_module('pct.functions', 'Constant')

source

get_drive


def get_drive(
    
):

source

loadjson


def loadjson(
    file
):
var = loadjson("ws.json")
print(var)
{'type': 'WeightedSum', 'name': 'weighted_sum', 'value': 35, 'links': {'0': 'constant', '1': 'constant1', '2': 'constant2'}, 'weights': [1, 1, 1]}

Counter


source

Counter


def Counter(
    limit:int=1000, init:int=0, step:int=1, print:int=100, pause:bool=False, display:int=10
):

Initialize self. See help(type(self)) for accurate signature.

Functions

set_dirs


source

set_dirs


def set_dirs(
    dirs
):

source

stringIntListToListOfInts


def stringIntListToListOfInts(
    strList, delimiter
):

source

stringFloatListToListOfFloats


def stringFloatListToListOfFloats(
    strList, delimiter
):

source

stringListToListOfStrings


def stringListToListOfStrings(
    strList, delimiter:str=','
):

source

listNumsToString


def listNumsToString(
    list
):

source

round_lists


def round_lists(
    alist, formatted, places
):

source

floatListsToString


def floatListsToString(
    alist, places
):

source

limit_large_float


def limit_large_float(
    val, limit:int=10000000
):

source

sigmoid


def sigmoid(
    x, range, slope
):

source

smooth


def smooth(
    new_val, old_val, smooth_factor
):

source

sigmoid_array


def sigmoid_array(
    x, range, slope
):

source

dot


def dot(
    inputs, weights
):

source

list_of_ones


def list_of_ones(
    numx
):
# li = list_of_ones(3)
# print(li)

source

limit_to_range


def limit_to_range(
    num, lower, upper
):

source

wrap_env


def wrap_env(
    env
):

source

show_video


def show_video(
    
):
import matplotlib.pyplot as plt
x = 2 #np.linspace(-5, 5, 11)
#x = -10000001
range=2
scale=2
y = sigmoid(x, range, scale)
print(y)
# plt.plot(x, y)
# plt.grid()
# plt.xlim(-6, 6)
# plt.xlabel('x')
# plt.title('expit(x)')
# plt.show()
0.7615941559557646

source

is_in_notebooks


def is_in_notebooks(
    
):

source

printtime


def printtime(
    msg
):

source

clip_value


def clip_value(
    val, range
):

get_abs_tol


source

get_abs_tol


def get_abs_tol(
    key
):

get_rel_tol


source

get_rel_tol


def get_rel_tol(
    key
):

source

map_to_int_even_range


def map_to_int_even_range(
    val:NoneType=None, inrange:NoneType=None, outrange:NoneType=None
):

source

map_to_int_odd_range


def map_to_int_odd_range(
    val:NoneType=None, inrange:NoneType=None, outrange:NoneType=None
):
limits = [-2, 2]
mapped = [1, 5]
vals = [-3.1, -2.1, -1.51, -1.5, -1.4, -0.9,-0.5, -0.1,  0, 0.1, 0.6, 1.1, 2.1, 210.1 ]
for val in vals:
    print(val, map_to_int_odd_range(val, limits, mapped))
-3.1 1
-2.1 1
-1.51 1
-1.5 1
-1.4 2
-0.9 2
-0.5 3
-0.1 3
0 3
0.1 3
0.6 4
1.1 4
2.1 5
210.1 5
#vals = [0.6]

vals = [-3.1, -2.1, -1.51, -1.5, -1.4, -0.9, -0.5, -0.1, 0, 0.1, 0.6, 1.1, 2.1, 210.1 ]
limits = [-2, 2]
mapped = [1, 4]
for val in vals:
    print(val, map_to_int_even_range(val, limits, mapped))
-3.1 1
-2.1 1
-1.51 1
-1.5 1
-1.4 1
-0.9 2
-0.5 2
-0.1 2
0 3
0.1 3
0.6 3
1.1 4
2.1 4
210.1 4

source

Timer


def Timer(
    
):

Initialize self. See help(type(self)) for accurate signature.


source

TimerError


def TimerError(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

A custom exception used to report errors in use of Timer class

timer = Timer()
timer.start()
time.sleep(1)
timer.stop()
timer.start()
time.sleep(1)
timer.stop()

print(timer.mean())
print(timer.total())
print(timer.count())
1.0116276999469846
2.0232553998939693
2

PCTRunProperties


source

PCTRunProperties


def PCTRunProperties(
    args:VAR_POSITIONAL, kwargs:VAR_KEYWORD
):

Initialize self. See help(type(self)) for accurate signature.

# property_file = 'ga-000.000-s001-1x1-m007-ARC0010-9ddcf52416e60d65f19007957d07262d-consolidated.properties'
# property_dir = ''
# print(property_dir, property_file)
# ep = PCTRunProperties.get_environment_properties(root='testfiles', env='ARC', property_dir=property_dir, property_file=property_file)
# print(ep)

source

get_ram_mb


def get_ram_mb(
    
):