def getModelSize(self): ''' Function to get aimed model size ''' nnzW, sizeW, sparseW = utils.countnnZ(self.bonsaiObj.W, self.sW) nnzV, sizeV, sparseV = utils.countnnZ(self.bonsaiObj.V, self.sV) nnzT, sizeT, sparseT = utils.countnnZ(self.bonsaiObj.T, self.sT) totalnnZ = (nnzT + nnzV + nnzW) totalSize = (sizeW + sizeV + sizeT) hasSparse = (sparseW or sparseV or sparseT) return totalnnZ, totalSize, hasSparse
def getModelSize(matrixList, sparcityList, expected=True, bytesPerVar=4): ''' expected: Expected size according to the parameters set. The number of zeros could actually be more than that is required to satisfy the sparsity constraint. ''' nnzList, sizeList, isSparseList = [], [], [] hasSparse = False for i in range(len(matrixList)): A, s = matrixList[i], sparcityList[i] assert A.ndim == 2 assert s >= 0 assert s <= 1 nnz, size, sparse = utils.countnnZ(A, s, bytesPerVar=bytesPerVar) nnzList.append(nnz) sizeList.append(size) hasSparse = (hasSparse or sparse) totalnnZ = np.sum(nnzList) totalSize = np.sum(sizeList) if expected: return totalnnZ, totalSize, hasSparse numNonZero = 0 totalSize = 0 hasSparse = False for i in range(len(matrixList)): A, s = matrixList[i], sparcityList[i] numNonZero_ = np.count_nonzero(A) numNonZero += numNonZero_ hasSparse = (hasSparse or (s < 0.5)) if s <= 0.5: totalSize += numNonZero_ * 2 * bytesPerVar else: totalSize += A.size * bytesPerVar return numNonZero, totalSize, hasSparse
def getModelSize(self): ''' Function to get aimed model size ''' totalnnZ = 0 totalSize = 0 hasSparse = False for i in range(0, self.numMatrices[0]): nnz, size, sparseFlag = utils.countnnZ(self.FastParams[i], self.sW) totalnnZ += nnz totalSize += size hasSparse = hasSparse or sparseFlag for i in range(self.numMatrices[0], self.totalMatrices): nnz, size, sparseFlag = utils.countnnZ(self.FastParams[i], self.sU) totalnnZ += nnz totalSize += size hasSparse = hasSparse or sparseFlag for i in range(self.totalMatrices, len(self.FastParams)): nnz, size, sparseFlag = utils.countnnZ(self.FastParams[i], 1.0) totalnnZ += nnz totalSize += size hasSparse = hasSparse or sparseFlag # Replace this with classifier class call nnz, size, sparseFlag = utils.countnnZ(self.FC, 1.0) totalnnZ += nnz totalSize += size hasSparse = hasSparse or sparseFlag nnz, size, sparseFlag = utils.countnnZ(self.FCbias, 1.0) totalnnZ += nnz totalSize += size hasSparse = hasSparse or sparseFlag return totalnnZ, totalSize, hasSparse