本文整理汇总了Python中sandbox.util.SparseUtils.SparseUtils.pruneMatrixRows方法的典型用法代码示例。如果您正苦于以下问题:Python SparseUtils.pruneMatrixRows方法的具体用法?Python SparseUtils.pruneMatrixRows怎么用?Python SparseUtils.pruneMatrixRows使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sandbox.util.SparseUtils.SparseUtils
的用法示例。
在下文中一共展示了SparseUtils.pruneMatrixRows方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: syntheticDataset1
# 需要导入模块: from sandbox.util.SparseUtils import SparseUtils [as 别名]
# 或者: from sandbox.util.SparseUtils.SparseUtils import pruneMatrixRows [as 别名]
def syntheticDataset1(m=500, n=200, k=8, u=0.1, sd=0, noise=5):
"""
Create a simple synthetic dataset
"""
w = 1-u
X, U, s, V, wv = SparseUtils.generateSparseBinaryMatrix((m,n), k, w, sd=sd, csarray=True, verbose=True, indsPerRow=200)
X = X + sppy.rand((m, n), noise/float(n), storagetype="row")
X[X.nonzero()] = 1
X.prune()
X = SparseUtils.pruneMatrixRows(X, minNnzRows=10)
logging.debug("Non zero elements: " + str(X.nnz) + " shape: " + str(X.shape))
U = U*s
return X, U, V
示例2: testPruneMatrixRows
# 需要导入模块: from sandbox.util.SparseUtils import SparseUtils [as 别名]
# 或者: from sandbox.util.SparseUtils.SparseUtils import pruneMatrixRows [as 别名]
def testPruneMatrixRows(self):
m = 30
n = 20
density = 0.5
X = sppy.rand((m, n), density)
X[X.nonzero()] = 1
newX, rowInds = SparseUtils.pruneMatrixRows(X, 10, verbose=True)
nnzRows = numpy.zeros(m)
for i in range(m):
nnzRows[i] = X.toarray()[i, :].nonzero()[0].shape[0]
if nnzRows[i] >= 10:
self.assertTrue(i in rowInds)
self.assertTrue((newX.sum(1) >= 10).all())
示例3: str
# 需要导入模块: from sandbox.util.SparseUtils import SparseUtils [as 别名]
# 或者: from sandbox.util.SparseUtils.SparseUtils import pruneMatrixRows [as 别名]
import os
import sys
import sppy.io
import numpy
import logging
from sandbox.util.SparseUtilsCython import SparseUtilsCython
from sandbox.util.SparseUtils import SparseUtils
from sandbox.util.PathDefaults import PathDefaults
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
numpy.random.seed(21)
m = 600
n = 300
k = 8
density = 0.1
X, U, V = SparseUtilsCython.generateSparseBinaryMatrixPL((m,n), k, density=density, alpha=1, csarray=True)
X = SparseUtils.pruneMatrixRows(X, minNnzRows=10)
resultsDir = PathDefaults.getDataDir() + "syntheticRanking/"
if not os.path.exists(resultsDir):
os.mkdir(resultsDir)
matrixFileName = resultsDir + "dataset1.mtx"
sppy.io.mmwrite(matrixFileName, X)
logging.debug("Non-zero elements: " + str(X.nnz) + " shape: " + str(X.shape))
logging.debug("Saved file: " + matrixFileName)