Utilities


source

SingletonObjects

 SingletonObjects ()

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


source

UniqueNamer

 UniqueNamer ()

A utility for ensuring the names of functions are unique.


source

FunctionsList

 FunctionsList ()

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


source

Memory

 Memory ()

A utility for recording global values.


source

NumberStats

 NumberStats ()

A utility for calculating the statistice of a number.

for num in range(10):
    NumberStats.getInstance().add(num)
    NumberStats.getInstance().add(-num)

NumberStats.getInstance().report()
--- stats report
Max: 9.000
Min: -9.000
from pct.functions import Proportional
prop = Proportional()
UniqueNamer.getInstance().report()
FunctionsList.getInstance().report()
--- functions report

source

dynamic_module_import

 dynamic_module_import (modulename, package=None)

source

dynamic_class_load

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

source

get_drive

 get_drive ()

source

loadjson

 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]}

source

Counter

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

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


source

stringIntListToListOfInts

 stringIntListToListOfInts (strList, delimiter)

source

stringFloatListToListOfFloats

 stringFloatListToListOfFloats (strList, delimiter)

source

stringListToListOfStrings

 stringListToListOfStrings (strList, delimiter=',')

source

listNumsToString

 listNumsToString (list)

source

round_lists

 round_lists (alist, formatted, places)

source

floatListsToString

 floatListsToString (alist, places)

source

limit_large_float

 limit_large_float (val, limit=10000000)

source

sigmoid

 sigmoid (x, range, slope)

source

smooth

 smooth (new_val, old_val, smooth_factor)

source

sigmoid_array

 sigmoid_array (x, range, slope)

source

dot

 dot (inputs, weights)

source

list_of_ones

 list_of_ones (num)

source

limit_to_range

 limit_to_range (num, lower, upper)
print(list_of_ones(3))
[1, 1, 1]

source

wrap_env

 wrap_env (env)

source

show_video

 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

 is_in_notebooks ()

source

printtime

 printtime (msg)

source

clip_value

 clip_value (val, range)

source

map_to_int_even_range

 map_to_int_even_range (val=None, inrange=None, outrange=None)

source

map_to_int_odd_range

 map_to_int_odd_range (val=None, inrange=None, outrange=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

 Timer ()

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


source

TimerError

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.0051114999999413
2.0102229999998826
2