Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hierarchy of variables using my own metric (MATLAB)?

I have 7 variables: A, B, C, D, E, F, and G. I have devised my own metric for an assignment that compares 2 variables and returns a scalar number. The closer the metric between 2 variables, the closer those variables are related. For example, if I compared A and B and got 2.2, then compare A and C and got 3.3, then A and B are more similar than A and C.

I want to prepare a hierarchy map, maybe something like a cluster or tree diagram that will map out the similarities if I assign all the combinations of similarities.

I know in MATLAB this is done via the linkage function, but the linkage function in MATLAB gives me precanned metrics for comparison such as "euclidean". I don't need this, I want to just put in my own metrics and map out the distances.

Does anyone have any insight on how this could be done?

like image 299
Yuri P. Avatar asked Nov 16 '25 23:11

Yuri P.


1 Answers

The Matlab pdist function allows you to compute a custom pairwise distance metric if you supply a function handle to a function you code that computes the distance.

The syntax is just

my_distance= pdist(pairs, @your_function)

where pairs is the data matrix containing your pairs, and @your_function is a handle to a custom distance metric function you define.

For specific requirements on the custom distance function syntax see the Matlab documentation for pdist.

You can then use the distance computed in the hierarchical clustering routines of the Statistics and Machine Learning toolbox, which I assumed you have because you mentioned linkage

like image 169
paisanco Avatar answered Nov 19 '25 15:11

paisanco



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!