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

回答(1 个)

类别

帮助中心File Exchange 中查找有关 Call Python from MATLAB 的更多信息

提问:

2017-2-17

回答:

2018-6-20

Community Treasure Hunt

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

Start Hunting!

Translated by