当前位置: 首页>>代码示例>>Python>>正文


Python Parameter.checkClass方法代码示例

本文整理汇总了Python中sandbox.util.Parameter.Parameter.checkClass方法的典型用法代码示例。如果您正苦于以下问题:Python Parameter.checkClass方法的具体用法?Python Parameter.checkClass怎么用?Python Parameter.checkClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sandbox.util.Parameter.Parameter的用法示例。


在下文中一共展示了Parameter.checkClass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: parallelPenaltyGridRbf

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
def parallelPenaltyGridRbf(svm, X, y, fullX, gridPoints, pdfX, pdfY1X, pdfYminus1X):
    """
    Find out the "ideal" penalty.
    """
    Parameter.checkClass(X, numpy.ndarray)
    Parameter.checkClass(y, numpy.ndarray)
    chunkSize = 10

    idealPenalties = numpy.zeros((svm.Cs.shape[0], svm.gammas.shape[0]))
    paramList = []

    for i in range(svm.Cs.shape[0]):
        for j in range(svm.gammas.shape[0]):
            paramList.append((X, y, fullX, svm.Cs[i], svm.gammas[j], gridPoints, pdfX, pdfY1X, pdfYminus1X))

    pool = multiprocessing.Pool()
    resultsIterator = pool.imap(computeIdealPenalty, paramList, chunkSize)

    for i in range(svm.Cs.shape[0]):
        for j in range(svm.gammas.shape[0]):
            idealPenalties[i, j] = resultsIterator.next()

    pool.terminate()

    return idealPenalties
开发者ID:charanpald,项目名称:wallhack,代码行数:27,代码来源:ModelSelectUtils.py

示例2: random2Choice

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def random2Choice(V, n=1):
        """
        Make a random binary choice from a vector V of values which are unnormalised
        probabilities. Return the corresponding index. For example if v = [1, 2]
        then the probability of the indices repectively are [1/3, 2/3]. The
        parameter n is the number of random choices to make. If V is a matrix,
        then the rows are taken as probabilities, and a choice is made for each
        row.
        """
        Parameter.checkClass(V, numpy.ndarray)

        if V.ndim == 1 and V.shape[0] != 2:
            raise ValueError("Function only works on binary probabilities")
        if V.ndim == 2 and V.shape[1] != 2:
            raise ValueError("Function only works on binary probabilities")

        if V.ndim == 1:
            cumV = numpy.cumsum(V)
            p = numpy.random.rand(n) * cumV[-1]
            cumV2 = numpy.ones(n) * cumV[0] - p
            return numpy.array(cumV2 <= 0, numpy.int)
        elif V.ndim == 2:
            cumV = numpy.cumsum(V, 1)
            P = numpy.random.rand(V.shape[0], n) * numpy.array([cumV[:, -1]]).T
            cumV2 = numpy.outer(cumV[:, 0], numpy.ones(n)) - P
            return numpy.array(cumV2 <= 0, numpy.int)
        else:
            raise ValueError("Invalid number of dimensions")
开发者ID:kentwang,项目名称:sandbox,代码行数:30,代码来源:Util.py

示例3: evaluate

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def evaluate(self, X1, X2):
        """
        Find kernel evaluation between two matrices X1 and X2 whose rows are
        examples and have an identical number of columns.


        :param X1: First set of examples.
        :type X1: :class:`numpy.ndarray`

        :param X2: Second set of examples.
        :type X2: :class:`numpy.ndarray`
        """
        Parameter.checkClass(X1, numpy.ndarray)
        Parameter.checkClass(X2, numpy.ndarray)
        
        if X1.shape[1] != X2.shape[1]:
            raise ValueError("Invalid matrix dimentions: " + str(X1.shape) + " " + str(X2.shape))

        j1 = numpy.ones((X1.shape[0], 1))
        j2 = numpy.ones((X2.shape[0], 1))

        diagK1 = numpy.sum(X1**2, 1)
        diagK2 = numpy.sum(X2**2, 1)

        X1X2 = numpy.dot(X1, X2.T)

        Q = (2*X1X2 - numpy.outer(diagK1, j2) - numpy.outer(j1, diagK2) )/ (2*self.sigma**2)

        return numpy.exp(Q)
开发者ID:charanpald,项目名称:sandbox,代码行数:31,代码来源:GaussianKernel.py

示例4: predict

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def predict(self, X):
        """
        Make a prediction for a set of examples given as the rows of the matrix X.

        :param X: A matrix with examples as rows
        :type X: :class:`ndarray`

        :return: A vector of scores corresponding to each example. 
        """
        Parameter.checkClass(X, numpy.ndarray)
        Parameter.checkArray(X)

        scores = numpy.zeros(X.shape[0])
        root = self.tree.getVertex((0, 0))
        root.setTestInds(numpy.arange(X.shape[0]))

        #We go down the tree making predictions at each stage 
        for d in range(self.maxDepth+1):
            for k in range(2**d):
                if self.tree.vertexExists((d, k)):
                    self.classifyNode(self.tree, X, d, k)

                    node = self.tree.getVertex((d,k))
                    if node.isLeafNode():
                        inds = node.getTestInds()
                        scores[inds] = node.getScore()

        return scores 
开发者ID:charanpald,项目名称:sandbox,代码行数:30,代码来源:TreeRank.py

示例5: parallelVfcvRbf

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def parallelVfcvRbf(self, X, y, idx, type="C_SVC"):
        """
        Perform parallel cross validation model selection using the RBF kernel
        and then pick the best one. Using the best set of parameters train using
        the whole dataset.

        :param X: The examples as rows
        :type X: :class:`numpy.ndarray`

        :param y: The binary -1/+1 labels 
        :type y: :class:`numpy.ndarray`

        :param idx: A list of train/test splits

        :params returnGrid: Whether to return the error grid
        :type returnGrid: :class:`bool`
        """
        Parameter.checkClass(X, numpy.ndarray)
        Parameter.checkClass(y, numpy.ndarray)

        self.setKernel("gaussian")

        if type == "C_SVC":
            paramDict = {}
            paramDict["setC"] = self.getCs()
            paramDict["setGamma"] = self.getGammas()
        else:
            paramDict = {}
            paramDict["setC"] = self.getCs()
            paramDict["setGamma"] = self.getGammas()
            paramDict["setEpsilon"] = self.getEpsilons()

        return self.parallelModelSelect(X, y, idx, paramDict)
开发者ID:kentwang,项目名称:sandbox,代码行数:35,代码来源:LibSVM.py

示例6: __init__

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
 def __init__(self, fileName):
     """
     Lock a job whose results are saved as fileName. 
     """
     Parameter.checkClass(fileName, str)
     self.fileName = fileName
     self.lockFileName = self.fileName + ".lock"
开发者ID:charanpald,项目名称:sandbox,代码行数:9,代码来源:FileLock.py

示例7: learnModel

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def learnModel(self, X, Y):
        Parameter.checkClass(X, numpy.ndarray)
        Parameter.checkClass(Y, numpy.ndarray)
        Parameter.checkArray(X)
        Parameter.checkArray(Y)

        if numpy.unique(Y).shape[0] < 2:
            raise ValueError("Vector of labels must be binary, currently numpy.unique(Y) = " + str(numpy.unique(Y)))

        #If Y is 1D make it 2D
        if Y.ndim == 1:
            Y = numpy.array([Y]).T
        
        XY = self._getDataFrame(X, Y)
        formula = robjects.Formula('class ~ .')
        self.learnModelDataFrame(formula, XY)

        gc.collect()
        robjects.r('gc(verbose=TRUE)')
        robjects.r('memory.profile()')
        gc.collect()

        if self.printMemStats:
            logging.debug(self.getLsos()())
            logging.debug(ProfileUtils.memDisplay(locals()))
开发者ID:charanpald,项目名称:sandbox,代码行数:27,代码来源:AbstractTreeRankR.py

示例8: randomChoice

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def randomChoice(V, n=1):
        """
        Make a random choice from a vector V of values which are unnormalised
        probabilities. Return the corresponding index. For example if v = [1, 2, 4]
        then the probability of the indices repectively are [1/7, 2/7, 4/7]. The
        parameter n is the number of random choices to make. If V is a matrix,
        then the rows are taken as probabilities, and a choice is made for each
        row. 
        """
        Parameter.checkClass(V, numpy.ndarray)

        if V.shape[0] == 0:
            return -1

        if V.ndim == 1:
            cumV = numpy.cumsum(V)
            p = numpy.random.rand(n) * cumV[-1]
            return numpy.searchsorted(cumV, p)
        elif V.ndim == 2:
            cumV = numpy.cumsum(V, 1)
            P = numpy.random.rand(V.shape[0], n) * numpy.array([cumV[:, -1]]).T

            inds = numpy.zeros(P.shape, numpy.int)
            for i in range(P.shape[0]):
                inds[i, :] = numpy.searchsorted(cumV[i, :], P[i, :])

            return inds
        else:
            raise ValueError("Invalid number of dimensions")
开发者ID:kentwang,项目名称:sandbox,代码行数:31,代码来源:Util.py

示例9: __init__

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
 def __init__(self, kernel, tau1, tau2):
     Parameter.checkFloat(tau1, 0.0, float('inf'))
     Parameter.checkFloat(tau2, 0.0, float('inf'))
     Parameter.checkClass(kernel, AbstractKernel)
     self.tau1 = tau1
     self.tau2 = tau2
     self.kernel = kernel
开发者ID:charanpald,项目名称:sandbox,代码行数:9,代码来源:PrimalDualCCARegression.py

示例10: __init__

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def __init__(self, kernelX, tau1, tau2):
        Parameter.checkFloat(tau1, 0.0, 1.0)
        Parameter.checkFloat(tau2, 0.0, 1.0)
        Parameter.checkClass(kernelX, AbstractKernel)

        self.kernelX = kernelX
        self.tau1 = tau1
        self.tau2 = tau2
开发者ID:charanpald,项目名称:sandbox,代码行数:10,代码来源:PrimalDualCCA.py

示例11: predict

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def predict(self, X):
        """
        Basically, return the scores.
        """
        Parameter.checkClass(X, numpy.ndarray)

        scores = self.predictScores(X)
        return scores
开发者ID:charanpald,项目名称:sandbox,代码行数:10,代码来源:AbstractTreeRankR.py

示例12: evaluateLearn

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def evaluateLearn(X, y, idx, learnModel, predict, metricMethod, progress=True):
        """
        Evaluate this learning algorithm using the given list of training/test splits 
        The metricMethod is a method which takes (predictedY, realY) as input
        and returns a metric about the quality of the evaluation.

        :param X: A matrix with examples as rows 
        :type X: :class:`ndarray`

        :param y: A vector of labels 
        :type y: :class:`ndarray`

        :param idx: A list of training/test splits 
        :type idx: :class:`list`

        :param learnModel: A function such that learnModel(X, y) finds a mapping from X to y 
        :type learnModel: :class:`function`

        :param predict: A function such that predict(X) makes predictions for X
        :type predict: :class:`function`

        :param metricMethod: A function such that metricMethod(predY, testY) returns the quality of predicted labels predY
        :type metricMethod: :class:`function`

        Output: the mean and variation of the cross validation folds. 
        """
        #Parameter.checkClass(idx, list)
        Parameter.checkClass(X, numpy.ndarray)
        Parameter.checkArray(X, softCheck=True)
        Parameter.checkInt(X.shape[0], 1, float('inf'))
        Parameter.checkClass(y, numpy.ndarray)
        Parameter.checkArray(y, softCheck=True)

        if y.ndim != 1:
            raise ValueError("Dimention of y must be 1")
        
        i = 0
        metrics = numpy.zeros(len(idx))
        logging.debug("EvaluateLearn: Using " + str(len(idx)) + " splits on " + str(X.shape[0]) + " examples")

        for idxtr, idxts in idx:
            if progress:
                Util.printConciseIteration(i, 1, len(idx))

            trainX, testX = X[idxtr, :], X[idxts, :]
            trainY, testY = y[idxtr], y[idxts]
            #logging.debug("Distribution of labels in evaluateLearn train: " + str(numpy.bincount(trainY)))
            #logging.debug("Distribution of labels in evaluateLearn test: " + str(numpy.bincount(testY)))

            learnModel(trainX, trainY)
            predY = predict(testX)
            gc.collect()

            metrics[i] = metricMethod(predY, testY)
            i += 1

        return metrics
开发者ID:charanpald,项目名称:sandbox,代码行数:59,代码来源:AbstractPredictor.py

示例13: evaluateCvOuter

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def evaluateCvOuter(self, X, Y, folds):
        """
        Run cross validation and output some ROC curves. In this case Y is a 1D array.

        :param X: A matrix with examples as rows
        :type X: :class:`ndarray`

        :param y: A vector of labels
        :type y: :class:`ndarray`

        :param folds: The number of cross validation folds
        :type folds: :class:`int`
        """
        Parameter.checkClass(X, numpy.ndarray)
        Parameter.checkClass(Y, numpy.ndarray)
        Parameter.checkInt(folds, 2, float('inf'))
        if Y.ndim != 1:
            raise ValueError("Expecting Y to be 1D")

        indexList = cross_val.StratifiedKFold(Y, folds)

        bestParams = []
        bestTrainAUCs = numpy.zeros(folds)
        bestTrainROCs = []
        bestTestAUCs = numpy.zeros(folds)
        bestTestROCs = []
        bestMetaDicts = []
        i = 0

        for trainInds, testInds in indexList:
            Util.printIteration(i, 1, folds, "Outer CV: ")
            trainX, trainY = X[trainInds, :], Y[trainInds]
            testX, testY = X[testInds, :], Y[testInds]

            self.learnModel(trainX, trainY)
            #self.learnModelCut(trainX, trainY)

            predTrainY = self.predict(trainX)
            predTestY = self.predict(testX)
            bestTrainAUCs[i] = Evaluator.auc(predTrainY, trainY)
            bestTestAUCs[i] = Evaluator.auc(predTestY, testY)

            #Store the parameters and ROC curves
            bestTrainROCs.append(Evaluator.roc(trainY, predTrainY))
            bestTestROCs.append(Evaluator.roc(testY, predTestY))

            metaDict = {}
            bestMetaDicts.append(metaDict)

            i += 1

        logging.debug("Mean test AUC = " + str(numpy.mean(bestTestAUCs)))
        logging.debug("Std test AUC = " + str(numpy.std(bestTestAUCs)))
        allMetrics = [bestTrainAUCs, bestTrainROCs, bestTestAUCs, bestTestROCs]

        return (bestParams, allMetrics, bestMetaDicts)
开发者ID:charanpald,项目名称:sandbox,代码行数:58,代码来源:AbstractTreeRank.py

示例14: predictScores

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def predictScores(self, X):
        """
        Make predictions using the learnt tree. Returns the scores as a numpy array.
        """
        Parameter.checkClass(X, numpy.ndarray)

        predictFunc = robjects.r['predict']
        X = self.baseLib.data_frame(X)
        scores = self.baseLib.matrix(predictFunc(self.getModel(), X))
        return numpy.asarray(scores).ravel()
开发者ID:charanpald,项目名称:sandbox,代码行数:12,代码来源:AbstractTreeRankR.py

示例15: standardiseArray

# 需要导入模块: from sandbox.util.Parameter import Parameter [as 别名]
# 或者: from sandbox.util.Parameter.Parameter import checkClass [as 别名]
    def standardiseArray(self, X):
        """
        Centre and then normalise an array to have norm 1.
        """
        Parameter.checkClass(X, numpy.ndarray)

        X = self.centreArray(X)
        X = self.normaliseArray(X)

        return X
开发者ID:charanpald,项目名称:sandbox,代码行数:12,代码来源:Standardiser.py


注:本文中的sandbox.util.Parameter.Parameter.checkClass方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。