def mergeArrays2(firstVector, secondVector, length):

    if length == 0:
        length = firstVector.size

    results = normalize_array(firstVector, 0)
    firstNumStates = results[0]
    firstNormalisedVector = results[1]

    results = normalize_array(secondVector, 0)
    secondNumStates = results[0]
    secondNormalisedVector = results[1]

    stateCount = 1
    stateMap = np.zeros(shape=(firstNumStates * secondNumStates, ))
    merge = np.zeros(shape=(length, ))

    for i in range(0, length):
        curIndex = firstNormalisedVector[i] + (secondNormalisedVector[i] *
                                               firstNumStates)
        if stateMap[int(curIndex)] == 0:
            stateMap[int(curIndex)] = stateCount
            stateCount = stateCount + 1
        merge[i] = stateMap[int(curIndex)]

    results = []
    results.append(stateCount)
    results.append(merge)

    return results
Exemple #2
0
def joint_probability(firstVector, secondVector, length):
    if length == 0:
        length = firstVector.size

    results = normalize_array(firstVector, 0)
    firstNumStates = results[0]
    firstNormalisedVector = results[1]

    results = normalize_array(secondVector, 0)
    secondNumStates = results[0]
    secondNormalisedVector = results[1]

    jointNumStates = firstNumStates * secondNumStates

    firstStateProbs = find_probs(firstNormalisedVector)
    secondStateProbs = find_probs(secondNormalisedVector)
    jointStateProbs = np.zeros(shape=(jointNumStates, ))

    # Joint probabilities
    jointStates = np.column_stack(
        (firstNormalisedVector, secondNormalisedVector))
    jointIndices, jointCounts = np.unique(jointStates,
                                          axis=0,
                                          return_counts=True)
    jointIndices = jointIndices.T
    jointIndices = jointIndices[1] * firstNumStates + jointIndices[0]
    jointIndices = jointIndices.astype(int)
    jointStateProbs[jointIndices] = jointCounts
    jointStateProbs /= length

    results = []
    results.append(jointStateProbs)
    results.append(jointNumStates)
    results.append(firstStateProbs)
    results.append(firstNumStates)
    results.append(secondStateProbs)
    results.append(secondNumStates)
    return results
def mergeArrays(firstVector, secondVector, length):

    if length == 0:
        length = firstVector.size

    results = normalize_array(firstVector, 0)
    firstNumStates = results[0]
    firstNormalisedVector = results[1]

    results = normalize_array(secondVector, 0)
    secondNumStates = results[0]
    secondNormalisedVector = results[1]

    stateCount = 1
    stateMap = np.zeros(shape=(firstNumStates * secondNumStates, ))
    merge = np.zeros(shape=(length, ))

    joint_states = np.column_stack((firstVector, secondVector))
    uniques, merge = np.unique(joint_states, axis=0, return_inverse=True)
    stateCount = len(uniques)
    results = []
    results.append(stateCount)
    results.append(merge)
    return results