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개)

Thomas
Thomas 2018년 6월 20일

0 개 추천

Did you ever get anywhere with this?

카테고리

도움말 센터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