def getBetas(idxPrc,<EOL>aryPrfTc,<EOL>lstAllMdlInd,<EOL>aryFuncChnk,<EOL>aryBstIndChnk,<EOL>betaSw,<EOL>queOut):
<EOL>varNumMtnDrctns = aryPrfTc.shape[<NUM_LIT:3>]<EOL>varNumVoxChnk = aryBstIndChnk.shape[<NUM_LIT:0>]<EOL>if type(betaSw) is sklearn.model_selection._split.KFold:<EOL><INDENT>aryEstimMtnCrvTrn = np.zeros((varNumVoxChnk, varNumMtnDrctns,<EOL>betaSw.get_n_splits()), dtype='<STR_LIT>')<EOL>aryEstimMtnCrvTst = np.zeros((varNumVoxChnk, varNumMtnDrctns,<EOL>betaSw.get_n_splits()), dtype='<STR_LIT>')<EOL>resTrn = np.zeros((varNumVoxChnk, betaSw.get_n_splits()),<EOL>dtype='<STR_LIT>')<EOL>resTst = np.zeros((varNumVoxChnk, betaSw.get_n_splits()),<EOL>dtype='<STR_LIT>')<EOL>aryErrorTrn = np.zeros((varNumVoxChnk), dtype='<STR_LIT>')<EOL>aryErrorTst = np.zeros((varNumVoxChnk), dtype='<STR_LIT>')<EOL>contrast = np.array([<EOL>[<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>],<EOL>[<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>],<EOL>[<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:0>],<EOL>[<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:0>],<EOL>])<EOL>denomTrn = np.zeros((varNumVoxChnk, betaSw.get_n_splits(),<EOL>len(contrast)), dtype='<STR_LIT>')<EOL>denomTst = np.zeros((varNumVoxChnk, betaSw.get_n_splits(),<EOL>len(contrast)), dtype='<STR_LIT>')<EOL><DEDENT>elif type(betaSw) is np.ndarray and betaSw.dtype == '<STR_LIT:bool>':<EOL><INDENT>aryEstimMtnCrvTrn = np.zeros((varNumVoxChnk, varNumMtnDrctns,<EOL>), dtype='<STR_LIT>')<EOL>aryEstimMtnCrvTst = np.zeros((varNumVoxChnk, varNumMtnDrctns,<EOL>), dtype='<STR_LIT>')<EOL>resTrn = np.zeros((varNumVoxChnk),<EOL>dtype='<STR_LIT>')<EOL>resTst = np.zeros((varNumVoxChnk),<EOL>dtype='<STR_LIT>')<EOL>aryErrorTrn = np.zeros((varNumVoxChnk), dtype='<STR_LIT>')<EOL>aryErrorTst = np.zeros((varNumVoxChnk), dtype='<STR_LIT>')<EOL>contrast = np.array([<EOL>[<NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>],<EOL>[<NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>],<EOL>[<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:0>, <NUM_LIT:0>],<EOL>[<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:1>, <NUM_LIT:0>],<EOL>])<EOL>denomTrn = np.zeros((varNumVoxChnk,<EOL>len(contrast)), dtype='<STR_LIT>')<EOL>denomTst = np.zeros((varNumVoxChnk,<EOL>len(contrast)), dtype='<STR_LIT>')<EOL><DEDENT>else:<EOL><INDENT>aryEstimMtnCrv = np.zeros((varNumVoxChnk, varNumMtnDrctns),<EOL>dtype='<STR_LIT>')<EOL><DEDENT>vecBstRes = np.zeros(varNumVoxChnk, dtype='<STR_LIT>')<EOL>vecBstRes[:] = np.inf<EOL>vecLgcCounter = np.zeros(varNumVoxChnk, dtype='<STR_LIT>')<EOL>aryFuncChnk = aryFuncChnk.T<EOL>aryFuncChnk = aryFuncChnk.astype(np.float32)<EOL>aryPrfTc = aryPrfTc.astype(np.float32)<EOL>if idxPrc == <NUM_LIT:0>:<EOL><INDENT>varStsStpSze = <NUM_LIT:20><EOL>varNumMdls = len(lstAllMdlInd)<EOL>vecStatPrf = np.linspace(<NUM_LIT:0>,<EOL>varNumMdls,<EOL>num=(varStsStpSze+<NUM_LIT:1>),<EOL>endpoint=True)<EOL>vecStatPrf = np.ceil(vecStatPrf)<EOL>vecStatPrf = vecStatPrf.astype(int)<EOL>vecStatPrc = np.linspace(<NUM_LIT:0>,<EOL><NUM_LIT:100>,<EOL>num=(varStsStpSze+<NUM_LIT:1>),<EOL>endpoint=True)<EOL>vecStatPrc = np.ceil(vecStatPrc)<EOL>vecStatPrc = vecStatPrc.astype(int)<EOL>varCntSts01 = <NUM_LIT:0><EOL>varCntSts02 = <NUM_LIT:0><EOL><DEDENT>for idx, mdlInd in enumerate(lstAllMdlInd):<EOL><INDENT>if idxPrc == <NUM_LIT:0>:<EOL><INDENT>if varCntSts02 == vecStatPrf[varCntSts01]:<EOL><INDENT>strStsMsg = ('<STR_LIT>' +<EOL>str(vecStatPrc[varCntSts01]) +<EOL>'<STR_LIT>' +<EOL>str(vecStatPrf[varCntSts01]) +<EOL>'<STR_LIT>' +<EOL>str(varNumMdls))<EOL>print(strStsMsg)<EOL>if varCntSts01 < varStsStpSze:<EOL><INDENT>varCntSts01 = varCntSts01 + int(<NUM_LIT:1>)<EOL><DEDENT><DEDENT><DEDENT>lgcTemp = [aryBstIndChnk == idx][<NUM_LIT:0>]<EOL>if np.greater(np.sum(lgcTemp), <NUM_LIT:0>):<EOL><INDENT>aryDsgnTmp = aryPrfTc[mdlInd].T<EOL>if betaSw is '<STR_LIT:train>':  <EOL><INDENT>aryTmpPrmEst, aryTmpRes = np.linalg.lstsq(<EOL>aryDsgnTmp, aryFuncChnk[:, lgcTemp])[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>aryEstimMtnCrv[lgcTemp, :] = aryTmpPrmEst.T<EOL>vecBstRes[lgcTemp] = aryTmpRes<EOL><DEDENT>elif type(betaSw) is np.ndarray and betaSw.dtype == '<STR_LIT:float>':<EOL><INDENT>aryEstimMtnCrv[lgcTemp, :] = np.linalg.lstsq(<EOL>aryDsgnTmp, aryFuncChnk[:, lgcTemp])[<NUM_LIT:0>].T<EOL>aryPredTc = np.dot(aryDsgnTmp,<EOL>betaSw[lgcTemp, :].T)<EOL>vecBstRes[lgcTemp] = np.sum((aryFuncChnk[:, lgcTemp] -<EOL>aryPredTc) ** <NUM_LIT:2>,  axis=<NUM_LIT:0>)<EOL><DEDENT>elif type(betaSw) is np.ndarray and betaSw.dtype == '<STR_LIT:bool>':<EOL><INDENT>betas, resTrn[lgcTemp] = np.linalg.lstsq(<EOL>aryDsgnTmp[betaSw, :], aryFuncChnk[betaSw][:, lgcTemp])[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>aryEstimMtnCrvTrn[lgcTemp, :] = betas.T<EOL>betas, resTst[lgcTemp] = np.linalg.lstsq(<EOL>aryDsgnTmp[~betaSw, :], aryFuncChnk[~betaSw][:, lgcTemp])[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>aryEstimMtnCrvTrn[lgcTemp, :] = betas.T<EOL>aryCcTrn = np.linalg.pinv(<EOL>np.dot(aryDsgnTmp[betaSw, :].T,<EOL>aryDsgnTmp[betaSw, :]))<EOL>aryCcTst = np.linalg.pinv(<EOL>np.dot(aryDsgnTmp[~betaSw, :].T,<EOL>aryDsgnTmp[~betaSw, :]))<EOL>aryErrorTrn[lgcTemp] = np.var(<EOL>np.subtract(aryFuncChnk[betaSw][:, lgcTemp],<EOL>np.dot(aryDsgnTmp[betaSw, :],<EOL>aryEstimMtnCrvTrn[lgcTemp, :].T)), axis=<NUM_LIT:0>)<EOL>aryErrorTst[lgcTemp] = np.var(<EOL>np.subtract(aryFuncChnk[~betaSw][:, lgcTemp],<EOL>np.dot(aryDsgnTmp[~betaSw, :],<EOL>aryEstimMtnCrvTst[lgcTemp, :].T)), axis=<NUM_LIT:0>)<EOL>for indContr, contr in enumerate(contrast):<EOL><INDENT>denomTrn[lgcTemp, indContr] = np.sqrt(<EOL>aryErrorTrn[lgcTemp] * np.dot(<EOL>np.dot(contr, aryCcTrn), contr.T))<EOL>denomTst[lgcTemp, indContr] = np.sqrt(<EOL>aryErrorTst[lgcTemp] * np.dot(<EOL>np.dot(contr, aryCcTst), contr.T))<EOL><DEDENT><DEDENT>elif type(betaSw) is sklearn.model_selection._split.KFold:<EOL><INDENT>for idxCV, (idxTrn, idxVal) in enumerate(betaSw.split(aryDsgnTmp)):<EOL><INDENT>betas, resTrn[lgcTemp, idxCV] = np.linalg.lstsq(<EOL>aryDsgnTmp[idxTrn], aryFuncChnk[idxTrn][:, lgcTemp])[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>aryEstimMtnCrvTrn[lgcTemp, :, idxCV] = betas.T<EOL>betas, resTst[lgcTemp, idxCV] = np.linalg.lstsq(<EOL>aryDsgnTmp[idxVal], aryFuncChnk[idxVal][:, lgcTemp])[<NUM_LIT:0>:<NUM_LIT:2>]<EOL>aryEstimMtnCrvTst[lgcTemp, :, idxCV] = betas.T<EOL>aryCcTrn = np.linalg.pinv(<EOL>np.dot(aryDsgnTmp[idxTrn].T,<EOL>aryDsgnTmp[idxTrn]))<EOL>aryCcTst = np.linalg.pinv(<EOL>np.dot(aryDsgnTmp[idxVal].T,<EOL>aryDsgnTmp[idxVal]))<EOL>aryErrorTrn[lgcTemp] = np.var(<EOL>np.subtract(aryFuncChnk[idxTrn][:, lgcTemp],<EOL>np.dot(aryDsgnTmp[idxTrn],<EOL>aryEstimMtnCrvTrn[lgcTemp, :, idxCV].T)), axis=<NUM_LIT:0>)<EOL>aryErrorTst[lgcTemp] = np.var(<EOL>np.subtract(aryFuncChnk[idxVal][:, lgcTemp],<EOL>np.dot(aryDsgnTmp[idxVal],<EOL>aryEstimMtnCrvTst[lgcTemp, :, idxCV].T)), axis=<NUM_LIT:0>)<EOL>for indContr, contr in enumerate(contrast):<EOL><INDENT>denomTrn[lgcTemp, idxCV, indContr] = np.sqrt(<EOL>aryErrorTrn[lgcTemp] * np.dot(<EOL>np.dot(contr, aryCcTrn), contr.T))<EOL>denomTst[lgcTemp, idxCV, indContr] = np.sqrt(<EOL>aryErrorTst[lgcTemp] * np.dot(<EOL>np.dot(contr, aryCcTst), contr.T))<EOL><DEDENT><DEDENT><DEDENT>vecLgcCounter[lgcTemp] += <NUM_LIT:1><EOL><DEDENT>if idxPrc == <NUM_LIT:0>:<EOL><INDENT>varCntSts02 = varCntSts02 + <NUM_LIT:1><EOL><DEDENT><DEDENT>strErrMsg = ('<STR_LIT>' +<EOL>'<STR_LIT>')<EOL>assert np.sum(vecLgcCounter) == len(vecLgcCounter), strErrMsg<EOL>if type(betaSw) is sklearn.model_selection._split.KFold:<EOL><INDENT>aryTvalsTrn = np.empty((varNumVoxChnk, contrast.shape[<NUM_LIT:0>],<EOL>betaSw.get_n_splits()))<EOL>aryTvalsTst = np.empty((varNumVoxChnk, contrast.shape[<NUM_LIT:0>],<EOL>betaSw.get_n_splits()))<EOL>for ind1, contr in enumerate(contrast):<EOL><INDENT>for ind2 in range(betaSw.get_n_splits()):<EOL><INDENT>aryTvalsTrn[:, ind1, ind2] = np.divide(<EOL>np.dot(contr, aryEstimMtnCrvTrn[:, :, ind2].T),<EOL>denomTrn[:, ind2, ind1])<EOL>aryTvalsTst[:, ind1, ind2] = np.divide(<EOL>np.dot(contr, aryEstimMtnCrvTst[:, :, ind2].T),<EOL>denomTst[:, ind2, ind1])<EOL><DEDENT><DEDENT>lstOut = [idxPrc,<EOL>aryEstimMtnCrvTrn,<EOL>aryEstimMtnCrvTst,<EOL>aryTvalsTrn,<EOL>aryTvalsTst,<EOL>]<EOL>queOut.put(lstOut)<EOL><DEDENT>elif type(betaSw) is np.ndarray and betaSw.dtype == '<STR_LIT:bool>':<EOL><INDENT>aryTvalsTrn = np.empty((varNumVoxChnk, contrast.shape[<NUM_LIT:0>],<EOL>))<EOL>aryTvalsTst = np.empty((varNumVoxChnk, contrast.shape[<NUM_LIT:0>],<EOL>))<EOL>for ind1, contr in enumerate(contrast):<EOL><INDENT>aryTvalsTrn[:, ind1] = np.divide(<EOL>np.dot(contr, aryEstimMtnCrvTrn.T),<EOL>denomTrn[:, ind1])<EOL>aryTvalsTst[:, ind1] = np.divide(<EOL>np.dot(contr, aryEstimMtnCrvTst.T),<EOL>denomTst[:, ind1])<EOL><DEDENT>lstOut = [idxPrc,<EOL>aryEstimMtnCrvTrn,<EOL>aryEstimMtnCrvTst,<EOL>aryTvalsTrn,<EOL>aryTvalsTst,<EOL>]<EOL>queOut.put(lstOut)<EOL><DEDENT>else:<EOL><INDENT>vecFuncMean = np.mean(aryFuncChnk, axis=<NUM_LIT:0>)<EOL>vecFuncDev = np.subtract(aryFuncChnk, vecFuncMean[None, :])<EOL>vecSsTot = np.sum(np.power(vecFuncDev,<EOL><NUM_LIT>),<EOL>axis=<NUM_LIT:0>)<EOL>vecBstR2 = np.subtract(<NUM_LIT:1.0>,<EOL>np.divide(vecBstRes,<EOL>vecSsTot))<EOL>lstOut = [idxPrc,<EOL>vecBstR2,<EOL>aryEstimMtnCrv]<EOL>queOut.put(lstOut)<EOL><DEDENT>
Calculate voxel betas and R^2 for the best model.

    Parameters
    ----------
    idxPrc : TODO
        (?)
    aryPrfTc : np.array, shape (?)
        Population receptive field time courses.
    lstAllMdlInd : list
        List of the indices of all models.
    aryFuncChnk : TODO
        Chunk of something(?)
    aryBstIndChnk : np.array, shape (?)
        Points for every voxel to the index of the best model
    betaSw : str, iterator, or np.array, shape (?)
        Best beta correlation coefficients found in training.
    queOut : TODO
        Queue output (?)

    Notes
    -----
    This is done after fitting with cross validation, since during the
    fitting process, we never fit the model to the entire data.