<commit_before># -*- coding: utf-8 -*-

import numpy as np
from sklearn.metrics.pairwise import euclidean_distances
from tsam.utils.durationRepresentation import durationRepresentation

def representations(candidates, clusterOrder, default, representationMethod=None, representationDict=None,
                    timeStepsPerPeriod=None):
    clusterCenterIndices = None
    if representationMethod is None:
        representationMethod = default
    if representationMethod == 'meanRepresentation':
        clusterCenters = meanRepresentation(candidates, clusterOrder)
    elif representationMethod == 'medoidRepresentation':
        clusterCenters, clusterCenterIndices = medoidRepresentation(candidates, clusterOrder)
    elif representationMethod == 'maxoidRepresentation':
        clusterCenters, clusterCenterIndices = maxoidRepresentation(candidates, clusterOrder)
    elif representationMethod == 'minmaxRepresentation':
        clusterCenters = minmaxmeanRepresentation(candidates, clusterOrder, representationDict, timeStepsPerPeriod)
    elif representationMethod == 'durationRepresentation':
        clusterCenters = durationRepresentation(candidates, clusterOrder, timeStepsPerPeriod)
    return clusterCenters, clusterCenterIndices


def maxoidRepresentation(candidates, clusterOrder):
    '''
    Represents the candidates of a given cluster group (clusterOrder)
    by its medoid, measured with the euclidean distance.

    :param candidates: Dissimilarity matrix where each row represents a candidate. required
    :type candidates: np.ndarray

    :param clusterOrder: Integer array where the index refers to the candidate and the
        Integer entry to the group. required
    :type clusterOrder: np.array
    '''
    # set cluster member that is farthest away from the points of the other clusters as maxoid
    clusterCenters = []
    clusterCenterIndices = []
    for clusterNum in np.unique(clusterOrder):
        indice = np.where(clusterOrder == clusterNum)
        innerDistMatrix = euclidean_distances(candidates, candidates[indice])
        mindistIdx = np.argmax(innerDistMatrix.sum(axis=0))
        clusterCenters.append(candidates[indice][mindistIdx])
        clusterCenterIndices.append(indice[0][mindistIdx])

    return clusterCenters, clusterCenterIndices<commit_msg>Update representations.py<commit_after># -*- coding: utf-8 -*-

import numpy as np
from sklearn.metrics.pairwise import euclidean_distances
from tsam.utils.durationRepresentation import durationRepresentation

def representations(candidates, clusterOrder, default, representationMethod=None, representationDict=None,
                    timeStepsPerPeriod=None):
    clusterCenterIndices = None
    if representationMethod is None:
        representationMethod = default
    if representationMethod == 'meanRepresentation':
        clusterCenters = meanRepresentation(candidates, clusterOrder)
    elif representationMethod == 'medoidRepresentation':
        clusterCenters, clusterCenterIndices = medoidRepresentation(candidates, clusterOrder)
    elif representationMethod == 'maxoidRepresentation':
        clusterCenters, clusterCenterIndices = maxoidRepresentation(candidates, clusterOrder)
    elif representationMethod == 'minmaxmeanRepresentation':
        clusterCenters = minmaxmeanRepresentation(candidates, clusterOrder, representationDict, timeStepsPerPeriod)
    elif representationMethod == 'durationRepresentation':
        clusterCenters = durationRepresentation(candidates, clusterOrder, timeStepsPerPeriod)
    return clusterCenters, clusterCenterIndices


def maxoidRepresentation(candidates, clusterOrder):
    '''
    Represents the candidates of a given cluster group (clusterOrder)
    by its medoid, measured with the euclidean distance.

    :param candidates: Dissimilarity matrix where each row represents a candidate. required
    :type candidates: np.ndarray

    :param clusterOrder: Integer array where the index refers to the candidate and the
        Integer entry to the group. required
    :type clusterOrder: np.array
    '''
    # set cluster member that is farthest away from the points of the other clusters as maxoid
    clusterCenters = []
    clusterCenterIndices = []
    for clusterNum in np.unique(clusterOrder):
        indice = np.where(clusterOrder == clusterNum)
        innerDistMatrix = euclidean_distances(candidates, candidates[indice])
        mindistIdx = np.argmax(innerDistMatrix.sum(axis=0))
        clusterCenters.append(candidates[indice][mindistIdx])
        clusterCenterIndices.append(indice[0][mindistIdx])

    return clusterCenters, clusterCenterIndices
{'fraction_non_alphanumeric': 0.06639273356401384, 'fraction_numerical': 0.0012975778546712802, 'mean_word_length': 4.619684082624544, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6504621', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1106, 'n_words': 318}