Recursive bisection function to matlab from python

Hi,
Could some one help me to translate this code from python to matlab? (it's an intersting code develped by Marcos López de Prado)
def getRecBipart(cov,sortIx):
# Compute HRP alloc
w=pd.Series(1,index=sortIx)
cItems=[sortIx] # initialize all items in one section
while len(cItems)>0:
cItems=[i[j:k] for i in cItems for j,k in ((0,len(i)/2), len(i)/2,len(i))) if len(i)>1]
# bi-section
for i in xrange(0,len(cItems),2): # parse in pairs
cItems0=cItems[i] # section 1
cItems1=cItems[i+1] # section 2
cVar0=getClusterVar(cov,cItems0)
cVar1=getClusterVar(cov,cItems1)
alpha=1-cVar0/(cVar0+cVar1)
w[cItems0]*=alpha # weight 1
w[cItems1]*=1-alpha # weight 2
return w
The Tricky part is this one:
cItems=[i[j:k] for i in cItems for j,k in ((0,len(i)/2), len(i)/2,len(i))) if len(i)>1]
Is the part where he use the recursive.
Thank you! Best Regards
Cihan

Antworten (1)

Thomas
Thomas am 20 Jun. 2018

0 Stimmen

Did you ever get anywhere with this?

Kategorien

Gefragt:

am 17 Feb. 2017

Beantwortet:

am 20 Jun. 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by