Hello, i'm have some confusion in terms of recursive functions. Can someone explain to me why this recursive function calls itself without the same number of arguments initially defined ? is that possible? What's the goal of not taking the other inputs into cosideration ?
function [output1 output2 output3] = TimeCourse(input, mode, geneIndex, dataForCurrentGene, newLogHypers, newCovarianceMatrixInverses)switch mode case 'init' data = input.data; nGenes = input.nGenes; nFeatures = input.nFeatures; sparseMatrix = zeros(nGenes,nFeatures); sparseVector = false(1,nGenes); maxNumberOfComponents = input.maxNumberOfComponents; featureNames = input.featureNames; featureNames = cellfun(@str2num,featureNames); [X, Y] = meshgrid(featureNames); timeDiffs = (-(X - Y).^2); hyperPriorParameters = [0, 1; 0, 1; 0, 1]; % [mean s.d.; ...]
lowerTriangularLogicalMatrix = logical(tril(ones(nFeatures))); % Define the cluster structure
clusterStruct(1,(maxNumberOfComponents+1)) = struct(... 'nFeatures', [], ... 'nGenesOverall', [], ... 'timeDiffs', [],... 'logHypers', [], ... 'logPriorOfLogHypers', [], ... 'squaredHypers', [], ... 'hyperPriorParams', [], ... 'lowerTriangularPartOfCovarianceMatrix', [], ... 'covarianceMatrixInverses', [], ... 'nGenes', [], ... 'logMarginalLikelihood', [],... 'dataCounts', [], ... 'squaredDataCounts', [], ... 'logicalGeneIDs', [], ... 'lowerTriangularLogicalMatrix', [], ... 'N', []); [clusterStruct.nFeatures ] = deal(nFeatures); [clusterStruct.nGenesOverall ] = deal(nGenes); [clusterStruct.hyperPriorParams] = deal(hyperPriorParameters); [clusterStruct.timeDiffs] = deal(timeDiffs); [clusterStruct.lowerTriangularLogicalMatrix] = deal(lowerTriangularLogicalMatrix); [clusterStruct.logMarginalLikelihood] = deal(0); [clusterStruct.nGenes] = deal(0); [clusterStruct.logicalGeneIDs] = deal(sparseVector); % Initialise clusters:
nStartingClusters = ceil(log(nGenes)); clusterIDs = random('unid', nStartingClusters, 1, nGenes); %row vector
uniqueIDs = unique(clusterIDs); for i = 1:maxNumberOfComponents clusterStruct(i).covarianceMatrixInverses(1,nGenes) =... struct('invertedCovarianceMatrix', [], 'determinant', []); end for i = uniqueIDs logicalIndices = clusterIDs == i; indices = find(logicalIndices); nGenesInCluster = length(indices); dataInCluster = sparseMatrix; dataInCluster(indices,:) = data(logicalIndices,:); currentCluster = clusterStruct(i); currentCluster.logicalGeneIDs = logicalIndices; currentCluster.dataCounts = sum(dataInCluster,1); currentCluster.squaredDataCounts = sum(dataInCluster.^2,1); currentCluster.nGenes = nGenesInCluster; currentCluster.N = nFeatures*nGenesInCluster; logHypers = TimeCourse(currentCluster, 'sampleHypers');
Best Answer