spectrum_functions.py
def plotDensityMap(scores):
    """Plots, given a set of scores, the density map on a triangle.

    Parameters
    ----------
    scores : list
        List of scores, where each score is a 3-dimensional list.

    """


    TRIANGLE = np.array([[math.cos(math.pi*0.5), math.sin(math.pi*0.5)],
                        [math.cos(math.pi*1.166), math.sin(math.pi*1.166)],
                        [math.cos(math.pi*1.833), math.sin(math.pi*1.833)]])


        
        
    pointsX = [score.dot(TRIANGLE)[0] for score in scores]
    pointsY = [score.dot(TRIANGLE)[1] for score in scores]

    vertices = []
    vertices.append(np.array([1,0,0]).dot(TRIANGLE))
    vertices.append(np.array([0,1,0]).dot(TRIANGLE))
    vertices.append(np.array([0,0,1]).dot(TRIANGLE))
    for i in range(3):
        p1 = vertices[i]
        if i == 2:
            p2 = vertices[0]
        else:
            p2 = vertices[i+1]
        c = 0.5 * (p1 + p2)
        plt.plot([p1[0], p2[0]], [p1[1], p2[1]], color='k', linestyle='-', linewidth=2)
        plt.plot([0, c[0]], [0, c[1]], color='k', linestyle='-', linewidth=1)



    ax = plt.gca()
    ax.set_xlim([-1.2, 1.32])
    ax.set_ylim([-0.7,1.3])

    ax.text(0.8, -0.6, 'Bipolar')
    ax.text(-1.1, -0.6, 'Healthy')
    ax.text(-0.15, 1.05, 'Borderline')


    data = [[pointsX[i], pointsY[i]] for i in range(len(pointsX))]

    H, _, _=np.histogram2d(pointsX,pointsY,bins=40,normed=True)
    norm=H.sum()
    contour1=0.75
    target1=norm*contour1
    def objective(limit, target):
        w = np.where(H>limit)
        count = H[w]
        return count.sum() - target

    level1 = scipy.optimize.bisect(objective, H.min(), H.max(), args=(target1,))
    levels = [level1]

    data = np.array(data)

    sns.kdeplot(np.array(pointsX), np.array(pointsY), shade=True, ax=ax)
    sns.kdeplot(np.array(pointsX), np.array(pointsY), n_levels=3, ax=ax, cmap="Reds")
    plt.show()
Plots, given a set of scores, the density map on a triangle.

    Parameters
    ----------
    scores : list
        List of scores, where each score is a 3-dimensional list.

    
Plots, given a set of scores, the density map on a triangle.
Parameters

scores : list
List of scores, where each score is a 3-dimensional list.
Plots given a set of scores the density map on a triangle . Parameters scores : list List of scores where each score is a 3 - dimensional list .
def plotDensityMap(scores):
    TRIANGLE = np.array([[math.cos(math.pi*0.5), math.sin(math.pi*0.5)],
                        [math.cos(math.pi*1.166), math.sin(math.pi*1.166)],
                        [math.cos(math.pi*1.833), math.sin(math.pi*1.833)]])
    pointsX = [score.dot(TRIANGLE)[0] for score in scores]
    pointsY = [score.dot(TRIANGLE)[1] for score in scores]
    vertices = []
    vertices.append(np.array([1,0,0]).dot(TRIANGLE))
    vertices.append(np.array([0,1,0]).dot(TRIANGLE))
    vertices.append(np.array([0,0,1]).dot(TRIANGLE))
    for i in range(3):
        p1 = vertices[i]
        if i == 2:
            p2 = vertices[0]
        else:
            p2 = vertices[i+1]
        c = 0.5 * (p1 + p2)
        plt.plot([p1[0], p2[0]], [p1[1], p2[1]], color='k', linestyle='-', linewidth=2)
        plt.plot([0, c[0]], [0, c[1]], color='k', linestyle='-', linewidth=1)
    ax = plt.gca()
    ax.set_xlim([-1.2, 1.32])
    ax.set_ylim([-0.7,1.3])
    ax.text(0.8, -0.6, 'Bipolar')
    ax.text(-1.1, -0.6, 'Healthy')
    ax.text(-0.15, 1.05, 'Borderline')
    data = [[pointsX[i], pointsY[i]] for i in range(len(pointsX))]
    H, _, _=np.histogram2d(pointsX,pointsY,bins=40,normed=True)
    norm=H.sum()
    contour1=0.75
    target1=norm*contour1
    def objective(limit, target):
        w = np.where(H>limit)
        count = H[w]
        return count.sum() - target
    level1 = scipy.optimize.bisect(objective, H.min(), H.max(), args=(target1,))
    levels = [level1]
    data = np.array(data)
    sns.kdeplot(np.array(pointsX), np.array(pointsY), shade=True, ax=ax)
    sns.kdeplot(np.array(pointsX), np.array(pointsY), n_levels=3, ax=ax, cmap="Reds")
    plt.show()
def plotDensityMap ( scores ) : TRIANGLE = np . array ( [ [ math . cos ( math . pi * 0.5 ) , math . sin ( math . pi * 0.5 ) ] , [ math . cos ( math . pi * 1.166 ) , math . sin ( math . pi * 1.166 ) ] , [ math . cos ( math . pi * 1.833 ) , math . sin ( math . pi * 1.833 ) ] ] ) pointsX = [ score . dot ( TRIANGLE ) [ 0 ] for score in scores ] pointsY = [ score . dot ( TRIANGLE ) [ 1 ] for score in scores ] vertices = [ ] vertices . append ( np . array ( [ 1 , 0 , 0 ] ) . dot ( TRIANGLE ) ) vertices . append ( np . array ( [ 0 , 1 , 0 ] ) . dot ( TRIANGLE ) ) vertices . append ( np . array ( [ 0 , 0 , 1 ] ) . dot ( TRIANGLE ) ) for i in range ( 3 ) : p1 = vertices [ i ] if i == 2 : p2 = vertices [ 0 ] else : p2 = vertices [ i + 1 ] c = 0.5 * ( p1 + p2 ) plt . plot ( [ p1 [ 0 ] , p2 [ 0 ] ] , [ p1 [ 1 ] , p2 [ 1 ] ] , color = 'k' , linestyle = '-' , linewidth = 2 ) plt . plot ( [ 0 , c [ 0 ] ] , [ 0 , c [ 1 ] ] , color = 'k' , linestyle = '-' , linewidth = 1 ) ax = plt . gca ( ) ax . set_xlim ( [ - 1.2 , 1.32 ] ) ax . set_ylim ( [ - 0.7 , 1.3 ] ) ax . text ( 0.8 , - 0.6 , 'Bipolar' ) ax . text ( - 1.1 , - 0.6 , 'Healthy' ) ax . text ( - 0.15 , 1.05 , 'Borderline' ) data = [ [ pointsX [ i ] , pointsY [ i ] ] for i in range ( len ( pointsX ) ) ] H , _ , _ = np . histogram2d ( pointsX , pointsY , bins = 40 , normed = True ) norm = H . sum ( ) contour1 = 0.75 target1 = norm * contour1 def objective ( limit , target ) : w = np . where ( H > limit ) count = H [ w ] return count . sum ( ) - target level1 = scipy . optimize . bisect ( objective , H . min ( ) , H . max ( ) , args = ( target1 , ) ) levels = [ level1 ] data = np . array ( data ) sns . kdeplot ( np . array ( pointsX ) , np . array ( pointsY ) , shade = True , ax = ax ) sns . kdeplot ( np . array ( pointsX ) , np . array ( pointsY ) , n_levels = 3 , ax = ax , cmap = "Reds" ) plt . show ( )
Plots, given a set of scores, the density map on a triangle.
Plots given a set of scores the density map on a triangle .
"""Plots, given a set of scores, the density map on a triangle.

    Parameters
    ----------
    scores : list
        List of scores, where each score is a 3-dimensional list.

    """
scores