Ignore:
Timestamp:
08/28/16 15:04:25 (8 years ago)
Author:
oriona
Message:

Number of returned dimensions set to minimum of desired number and the number returned by mds.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mds-and-trees/mds_plot.py

    r599 r600  
    7777def compute_mds(distance_matrix, dim):
    7878        embed, evals = cmdscale(distance_matrix)
     79
    7980        variances = [np.var(embed[:,i]) for i in range(len(embed[0]))]
    80         embed = np.asarray([embed[:,i] for i in range(dim)]).T
    81 
    82         percent_variances = [sum(variances[:i+1])/sum(variances) for i in range(dim)]
     81        percent_variances = [sum(variances[:i+1])/sum(variances) for i in range(len(variances))]
    8382        for i,pv in enumerate(percent_variances):
    8483                print(i+1,"dimension:",pv)
     84
     85        dim = min(dim, len(embed[0]))
     86        embed = np.asarray([embed[:,i] for i in range(dim)]).T
    8587
    8688        return embed
Note: See TracChangeset for help on using the changeset viewer.