Skip to content

Commit

Permalink
Version 1.0 Added new function
Browse files Browse the repository at this point in the history
  • Loading branch information
asigalov61 authored Aug 30, 2024
1 parent 1ae9c87 commit 5f49819
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tegridy-tools/TPLOTS.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
# Modules imports
################################################################################

from collections import Counter
from itertools import groupby

import numpy as np
Expand Down Expand Up @@ -491,6 +492,42 @@ def reduce_dimensionality_2d_distance(list_of_values, p=5):

################################################################################

def normalize_to_range(values, n):

min_val = min(values)
max_val = max(values)

range_val = max_val - min_val

normalized_values = [((value - min_val) / range_val * 2 * n) - n for value in values]

return normalized_values

################################################################################

def reduce_dimensionality_simple_pca(list_of_values, n_components=2):

'''
Reduces the dimensionality of the values using simple PCA
'''

reduced_values = []

for l in list_of_values:

norm_values = [round(v * len(l)) for v in normalize_to_range(l, (n_components+1) // 2)]

pca_values = Counter(norm_values).most_common()
pca_values = [vv[0] / len(l) for vv in pca_values]
pca_values = pca_values[:n_components]
pca_values = pca_values + [0] * (n_components - len(pca_values))

reduced_values.append(pca_values)

return reduced_values

################################################################################

def filter_and_replace_values(list_of_values,
threshold,
replace_value,
Expand Down

0 comments on commit 5f49819

Please sign in to comment.