Skip to content

Commit

Permalink
added more content, set up modules
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronmore committed Dec 16, 2024
1 parent 00578d1 commit 70df9e4
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dev/
statsy.egg-info
dev.py
dev.py
src/statsy/__pycache__/
16 changes: 16 additions & 0 deletions src/statsy/Constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from .main import *

e = summation(None,None,lambda n: 1/(math.factorial(n)), [[n for n in range (1000)]])

def pi()->Number:
"""
Returns pi
"""
return math.pi

def e_specified(depth:int) -> Number:
"""
A specified depth to calculate the constant e.
"""
depth_list = [n for n in range (depth)]
return summation(None,None,lambda n: 1/(math.factorial(n)), [depth_list])
13 changes: 13 additions & 0 deletions src/statsy/Conversion.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from .main import *

def Celcius_to_Fahrenheit(C:Number) -> Number:
"""
Returns the Fahrenheit value of a Celcius value.
"""
return (1.8 * C) + 32

def Fahrenheit_to_Celcius(F:Number) -> Number:
"""
Returns the Celcius value of a Fahrenheit value.
"""
return (F - 32)/1.8
14 changes: 14 additions & 0 deletions src/statsy/Logarithms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from .main import *
import math, statistics

def ln(a:Number)->Number:
"""
Returns the natural log.
"""
return math.log(a)

def log(base:Number,a:Number)->Number:
"""
Returns any logarithm for base and value.
"""
return (math.log10(a)/math.log10(base))
54 changes: 54 additions & 0 deletions src/statsy/Methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from .main import *
from .Logarithms import *

def Sturges_rule(number_of_points:Number)->Number:
"""
Sturges' rule for determining the approx. number of intervals for histograms.
"""
return round(1 + log(2,number_of_points))

def Rice_rule(number_of_points:Number)->Number:
"""
Rice rule for determining the approx. number of intervals for histograms.
"""
return round(2 * (root(3,number_of_points)))

def arithmetic_mean(data:list)->Number:
"""
Returns the arithmetic mean of a list of data points.
"""
return (summation(None,None,None,[data])) / len(data)

def median(data:list)->Number:
"""
Returns the simple mean of an ordered quantitative list.
"""
total_length = len(data)
if total_length & 1:
return data[int((total_length+1)/2)-1]
else:
return (data[ int((total_length/2)-1)] + data[int((total_length/2)+1)])/2

def mode(data:list)->any:
"""
A shortcut for statistics.mode(data)
"""
return statistics.mode(data)

def trimean(data:list)->Number:
"""
Returns the trimean of a set of data.
Be sure to order list in an increasing order.
"""
p25 = get_value_from_percentile(25,data)
p50 = get_value_from_percentile(50,data)
p75 = get_value_from_percentile(75,data)
print(p25,p50,p75)

return ( (p25 + (2 * p50) + p75 ) / 4 )

def geometric_mean(data:list)->Number:
"""
Returns the geometric mean of a list of data.
"""
return (product_notation(None,None,None,[data]) ** (1/len(data)))
4 changes: 4 additions & 0 deletions src/statsy/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
from .main import *
from .Conversion import *
from .Constants import *
from .Logarithms import *
from .Methods import *
54 changes: 53 additions & 1 deletion src/statsy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ def get_value_from_percentile(percentile:Number,data:list) -> Number:
value = (diff * fr) + lowest
return value


def summation(i:int,range:int,expression:Callable,data:List[List[Number]]) -> Number:
"""
i = beginning of the range to execute. \n
Expand Down Expand Up @@ -64,3 +63,56 @@ def summation(i:int,range:int,expression:Callable,data:List[List[Number]]) -> Nu

return sum(evaluated_list)

def multiply_elements(data:list)->Number:
"""
Multiplies all elements in a list together.
"""
res = 1
for element in data:
res = res * element
return res

def product_notation(i:int,range:int,expression:Callable,data:List[List[Number]]) -> Number:
"""
i = beginning of the range to execute. \n
range = range to execute \n
expression = function to apply to the data \n
data = list of lists that contain values to evaluate \n
This function returns the value of a product notation.
"""
if expression is None:
expression = lambda x: x
if len(inspect.signature(expression).parameters) != len(data):
raise ValueError("There must be the same number of input data lists as expression inputs")
lists_ready_to_eval = []
# For each list in the data, return the range to be evaluated
for input_list in data:
# If no start and range are specified, pass the entire list to evaluate
if i is None and range is None:
lists_ready_to_eval.append(input_list)
# If a range is given, slice that part of the list and return it to the list of lists to evaluate
else:
lists_ready_to_eval.append(input_list[i-1:range+1])
# Create a list containing all the evaluated values in the range of interest
evaluated_list = []
# Check for multi-variable functions by checking the number of input lists. These two numbers should be the same.
if len(data) > 1:
# If multi-variable function is given:
range_of_list_to_eval = len(lists_ready_to_eval[0])
current_index_of_list_to_eval = 0
# Use zip to iterate through all lists at the same time and '*' to unpack the lists. This returns a tuple where each item in the tuple has the same index across all lists
for val in zip(*lists_ready_to_eval):
# Use * to unpack the tuple and input into the function and add to evaluated list
evaluated_list.append(expression(*val))
else:
for val in lists_ready_to_eval[0]:
# Evaluate expression and add to evaluated list
evaluated_list.append(expression(val))

return multiply_elements(evaluated_list)

def root(root_value:Number,root_input:Number)->Number:
"""
Returns the arbitrary root of an input.
"""
return root_input ** (1/root_value)

0 comments on commit 70df9e4

Please sign in to comment.