• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.vsplit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.vsplit函数的典型用法代码示例。如果您正苦于以下问题:Python vsplit函数的具体用法?Python vsplit怎么用?Python vsplit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: valid

def valid():
    rows = np.vsplit(puzzle, 9)
    cols = np.hsplit(puzzle, 9)
    grids = [grid for h in np.hsplit(puzzle, 3) for grid in np.vsplit(h, 3)]

    units = rows + cols + grids
    return all(np.max(np.bincount(unit[unit != 0])) == 1 for unit in units)
开发者ID:neingeist,项目名称:python-exercises,代码行数:7,代码来源:sudoku.py


示例2: fun_find_pairwise_distances

def fun_find_pairwise_distances(x, y):
    """
    A functional implementation of the same function
    """
    return np.array([[np.linalg.norm(x_elem - y_elem)
                      for y_elem in np.vsplit(y, y.shape[0])]
                     for x_elem in np.vsplit(x, x.shape[0])])
开发者ID:izmailovpavel,项目名称:Practicum,代码行数:7,代码来源:problem_7.py


示例3: cross_validation

def cross_validation(trndata, folds=3, **kwargs):
    """
        kwargs are parameters for the model
    """
    input = np.vsplit(trndata['input'], folds)
    target = np.vsplit(trndata['target'], folds)

    zipped = zip(input, target)

    accuracy_sum = 0
    for i in len(zipped):
        new_train = ClassificationDataSet(attributes, nb_classes=classes_number)
        new_test = ClassificationDataSet(attributes, nb_classes=classes_number)
        test_zipped = zipped[i]
        train_zipped = zipped[:i] + zipped[(i+1):]

        new_train.setField('input', np.vstack[train_zipped[0]])
        new_train.setField('target', np.vstack[train_zipped[1]])

        new_test.setField('input', test_zipped[0])
        new_test.setField('target', train_zipped[1])

        model = FNNClassifier()
        model.train(new_train, new_test, kwargs)
        out, targ = model.predict(new_test)
        accuracy_sum += accuracy(out, targ)

    return accuracy_sum / folds
开发者ID:sacherus,项目名称:pca-image,代码行数:28,代码来源:forest_main.py


示例4: ChangeSize

    def ChangeSize(self,n_nodes):
        self.masses.resize((1,n_nodes),refcheck=False)
        #self.masses=np.resize(self.masses,(1,n_nodes))
        #self.masses[0][-1] #bug in resize??
        self.initDisp.resize((1,n_nodes),refcheck=False)
        self.initVel.resize((1,n_nodes),refcheck=False)
        #self.initDisp=np.resize(self.initDisp,(1,n_nodes))
        #self.initVel=np.resize(self.initVel,(1,n_nodes))
        

        if n_nodes>self.n_nodes:
            #Take care of 2D array manipulation
            delta=n_nodes-self.n_nodes
            hor=np.zeros((self.n_nodes,delta))
            ver=np.zeros((delta,n_nodes))
            self.springs=np.vstack((np.hstack((self.springs,hor)),ver))
            self.dampers=np.vstack((np.hstack((self.dampers,hor)),ver))
            # Take care of displacement and forces list
            print self.n_nodes,n_nodes
            for i in range(0,n_nodes-self.n_nodes):
                #print i
                self.displacements.append(-1)
                self.forces.append(-1)
            #addArray=[0 for x in range(self.syst.n_nodes,n_nodes)]
        elif n_nodes<self.n_nodes:
            self.springs=np.hsplit(np.vsplit(self.springs,(n_nodes,n_nodes))[0],(n_nodes,n_nodes))[0]
            self.dampers=np.hsplit(np.vsplit(self.dampers,(n_nodes,n_nodes))[0],(n_nodes,n_nodes))[0]
            self.displacements=self.displacements[0:n_nodes]
            self.forces=self.forces[0:n_nodes]
        self.n_nodes=n_nodes
开发者ID:snexus,项目名称:ODDS,代码行数:30,代码来源:odds.py


示例5: fit

    def fit(self, X, y):

        if self.__unsupervised_thresh is not None:

            # user can pass in a negative to let us decide
            if self.__unsupervised_thresh <= 0:
                self.__unsupervised_thresh = 20

            qb = dipy.segment.clustering.QuickBundles(
                threshold=self.__unsupervised_thresh, metric=dipy.segment.metric.AveragePointwiseEuclideanMetric())
            clusters = qb.cluster(numpy.vsplit(numpy.reshape(X, (-1, 3)), X.shape[0]))
            cluster_labels = list()
            for cluster in clusters:
                current_labels, current_label_counts = numpy.unique(y[cluster.indices], return_counts=True)
                cluster_labels.append(current_labels[numpy.argmax(current_label_counts)])
            self.__centroids = map(lambda cl: cl.centroid, clusters)
            self.__centroid_labels = numpy.array(cluster_labels)

        else:

            unique_labels = numpy.unique(y)
            centroids = numpy.full((len(unique_labels), X.shape[1]), numpy.nan)
            for index_label, unique_label in enumerate(unique_labels):
                centroids[index_label] = numpy.mean(X[y == unique_label], axis=0)
            self.__centroids = numpy.vsplit(centroids.reshape((-1, 3)), centroids.shape[0])
            self.__centroid_labels = unique_labels
开发者ID:danrsc,项目名称:neuro_atlas,代码行数:26,代码来源:neuro_atlas_analysis.py


示例6: create_batches

    def create_batches(self):
        self.num_batches = self.tensor.size / (self.batch_size * self.seq_length)

        newline = self.vocab['\n']
        nextnew = np.where(self.tensor == newline)
        n_tunes = nextnew[0].size

        print "preparing chunks..."
        pos = 0
        n_tune = 0
        x_chunks = np.array([], dtype=int)
        y_chunks = np.array([], dtype=int)
        for nl in nextnew[0]:
            while (pos + self.seq_length < nl):
                x_chunks = np.append(x_chunks, self.tensor[pos : pos + self.seq_length])
                y_chunks = np.append(y_chunks, self.tensor[pos + 1 : pos + self.seq_length + 1])
                pos += 1
            n_tune += 1
            print "done tune ", n_tune, "/", n_tunes
            pos += self.seq_length

        print "reshaping to seq_length..."
        x_chunks = np.copy(np.reshape(x_chunks, (-1, self.seq_length)))
        y_chunks = np.copy(np.reshape(y_chunks, (-1, self.seq_length)))

        print "truncating to match batch_size"
        x, y = x_chunks.shape
        self.num_batches = x / self.batch_size
        print "%i batches" % self.num_batches
        x_chunks.resize((self.num_batches * self.batch_size, self.seq_length))
        y_chunks.resize((self.num_batches * self.batch_size, self.seq_length))

        self.x_batches = np.vsplit(x_chunks, self.num_batches)
        self.y_batches = np.vsplit(y_chunks, self.num_batches)
        print "batches ready!"
开发者ID:pierrebeauguitte,项目名称:char-rnn-tensorflow,代码行数:35,代码来源:utils.py


示例7: test_validation_curve_cv_splits_consistency

def test_validation_curve_cv_splits_consistency():
    n_samples = 100
    n_splits = 5
    X, y = make_classification(n_samples=100, random_state=0)

    scores1 = validation_curve(SVC(kernel='linear', random_state=0), X, y,
                               'C', [0.1, 0.1, 0.2, 0.2],
                               cv=OneTimeSplitter(n_splits=n_splits,
                                                  n_samples=n_samples))
    # The OneTimeSplitter is a non-re-entrant cv splitter. Unless, the
    # `split` is called for each parameter, the following should produce
    # identical results for param setting 1 and param setting 2 as both have
    # the same C value.
    assert_array_almost_equal(*np.vsplit(np.hstack(scores1)[(0, 2, 1, 3), :],
                                         2))

    scores2 = validation_curve(SVC(kernel='linear', random_state=0), X, y,
                               'C', [0.1, 0.1, 0.2, 0.2],
                               cv=KFold(n_splits=n_splits, shuffle=True))

    # For scores2, compare the 1st and 2nd parameter's scores
    # (Since the C value for 1st two param setting is 0.1, they must be
    # consistent unless the train test folds differ between the param settings)
    assert_array_almost_equal(*np.vsplit(np.hstack(scores2)[(0, 2, 1, 3), :],
                                         2))

    scores3 = validation_curve(SVC(kernel='linear', random_state=0), X, y,
                               'C', [0.1, 0.1, 0.2, 0.2],
                               cv=KFold(n_splits=n_splits))

    # OneTimeSplitter is basically unshuffled KFold(n_splits=5). Sanity check.
    assert_array_almost_equal(np.array(scores3), np.array(scores1))
开发者ID:RomainBrault,项目名称:scikit-learn,代码行数:32,代码来源:test_validation.py


示例8: fold_eta

    def fold_eta(self):
        crap, self.ybins = np.split(self.ybins, 2)

        negeta, poseta = np.vsplit(self.Z, 2)
        negeta = negeta[::-1]
        self.Z = (negeta + poseta)/2

        negeta, poseta = np.vsplit(self.err2, 2)
        negeta = negeta[::-1]
        self.err2 = (negeta + poseta)/4
开发者ID:slindal,项目名称:ana,代码行数:10,代码来源:pyh2.py


示例9: get_batches

def get_batches(X, Y, batch_size):
    '''
    Return a random data sample of size n from data X
    and their respective labels from Y.
    '''
    n_data, m_data = X.shape
    shuffled_inds = np.random.permutation(n_data)
    shuffled_data = X[shuffled_inds]
    shuffled_targ = Y[shuffled_inds]
    partitioned_data = np.vsplit(shuffled_data, n_data//batch_size)
    partitioned_targ = np.vsplit(shuffled_targ, n_data//batch_size)
    return partitioned_data, partitioned_targ
开发者ID:pkukulak,项目名称:PHL348_A3,代码行数:12,代码来源:load_data.py


示例10: kernelLDA

def kernelLDA(trainFile, validFile, labelsFile, gamma):

	trainData = np.loadtxt(open(trainFile))
	validationData = np.loadtxt(open(validFile))
	labels = np.loadtxt(open(labelsFile))

	print "Read training and validation data from files..."

	class1 = []
	class2 = []

	for i in range(len(labels)):
		if labels[i] == 1:
			class1.append(trainData[i])
		else:
			class2.append(trainData[i])

	class1 = np.vstack(tuple(class1))
	class2 = np.vstack(tuple(class2))

	data = np.concatenate((class1, class2))

	kernel_mat, kernelCentered_mat = getKernelMatrix(data, gamma)

	print "Kernel matrix obtained."

	K1 = np.vsplit(kernelCentered_mat, [class1.shape[0], data.shape[0]])[0]
	K2 = np.vsplit(kernelCentered_mat, [class1.shape[0], data.shape[0]])[1]

	mat_N1 = K1.T.dot( \
	 		(np.identity(K1.shape[0]) - (np.ones((K1.shape[0], K1.shape[0])) / K1.shape[0]))).dot( \
	 		K1)

	mat_N2 = K2.T.dot( \
	 		(np.identity(K2.shape[0]) - (np.ones((K2.shape[0], K2.shape[0])) / K2.shape[0]))).dot( \
	 		K2)

	N = mat_N1 + mat_N2

	M1 = np.average(K1, axis = 0)
	M2 = np.average(K2, axis = 0)

	#alpha = np.linalg.inv(N).dot(M2 - M1)
	alpha = (M2 - M1)

	getDimensionReducedData(alpha, kernelCentered_mat, 1, 'train', trainFile.split('_')[0])

	sq_distances_valid = cdist(data, validationData, 'sqeuclidean')
	kernel_mat_valid = np.exp(-1 * gamma * sq_distances_valid)

	getDimensionReducedData(alpha, kernel_mat_valid, 1, 'valid', trainFile.split('_')[0])

	print "Finished."
开发者ID:prameelakavya,项目名称:naive-bayes-and-dimensinality-reduction-techniques,代码行数:53,代码来源:kernelLDA.py


示例11: selectSubsample

def selectSubsample(matrixX, matrixY, splits):
    separateX = numpy.vsplit(matrixX, splits)
    separateY = numpy.vsplit(matrixY, splits)
    trainXFinal = []
    trainYFinal = []
    testXFinal = []
    testYFinal = []
    for i in range(len(separateX)):
        x_train, x_test, y_train, y_test = train_test_split(
            separateX[i], separateY[i], train_size=trainPercent, random_state=finalSeed)
        trainXFinal.append(x_train)
        trainYFinal.append(y_train)
        testXFinal.append(x_test)
        testYFinal.append(y_test)
    return [trainXFinal, trainYFinal, testXFinal, testYFinal]
开发者ID:noraw,项目名称:CyborgBugs,代码行数:15,代码来源:transformFeatures.py


示例12: predict_old

def predict_old(test):
    img = cv2.imread('digits.png')
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

    # now we split the image to 5000 cells, each 20*20 size
    cells = [np.hsplit(row, 100) for row in np.vsplit(gray,50)]

    # Make it into a Numpy array. It size will be (50,100,20,20)
    x = np.array(cells)

    # now we prepare train_data and test_data
    train = x[:,:50].reshape(-1,400).astype(np.float32)     #Gives a new shape to an array without changing its data.
    if test==None: test = x[:, 50:100].reshape(-1,400).astype(np.float32)
    # create labels for train and test data
    k = np.arange(10)

    train_labels = np.repeat(k,250)[:, np.newaxis]  # Repeat elements of an array.
    test_labels = train_labels.copy()

    #cv2.KNearest.find_nearest(samples, k[, results[, neighborResponses[, dists]]]) → retval, results, neighborResponses, dists
    ret,result,neighbours,dist = knn.findNearest(test.reshape(-1,400).astype(np.float32),k=5)
    print '2-----:',result


    # Now we check the accuracy of classification
    # For that, compare the result with test_labels and check which are wrong
    matches = result==test_labels
    correct = np.count_nonzero(matches) # Counts the number of non-zero values in the array a.

    accuracy = correct*100.0/result.size
    print 'accuracy:',accuracy

    np.savez('knn_data.npz',train=train,train_labels=train_labels)
开发者ID:JamesPei,项目名称:PythonProjects,代码行数:33,代码来源:knn.py


示例13: evaluate_local_remainder_at

    def evaluate_local_remainder_at(self, grid, position, diagonal_component=None, entry=None):
        r"""Numerically evaluate the non-quadratic remainder :math:`W(x)` of the quadratic
        approximation :math:`U(x)` of the potential's eigenvalue :math:`\lambda(x)` at the
        given nodes :math:`\Gamma`.

        :param grid: The grid nodes :math:`\Gamma` the remainder :math:`W` gets evaluated at.
        :param position: The point :math:`q \in \mathbb{R}^D` where the Taylor series is computed.
        :param diagonal_component: Dummy parameter that has no effect here.
        :keyword entry: Dummy parameter that has no effect here.
        :return: A list with a single entry consisting of an ``ndarray`` containing the
                 values of :math:`W(\Gamma)`. The array is of shape :math:`(1,|\Gamma|)`.
        """
        grid = self._grid_wrap(grid)
        position = numpy.atleast_2d(position)

        # Evaluate the remainder at the given nodes
        args = grid.get_nodes(split=True) + numpy.vsplit(position, position.shape[0])
        values = self._remainder_n[0](*args)

        # Test for potential being constant
        if numpy.atleast_1d(values).shape == (1,):
            values = values * numpy.ones(grid.get_number_nodes(), dtype=numpy.complexfloating)

        # Put the result in correct shape (1, #gridnodes)
        N = grid.get_number_nodes(overall=True)
        result = [ values.reshape((1,N)) ]

        # TODO: Consider unpacking single ndarray iff entry != None
        if entry is not None:
            result = result[0]

        return result
开发者ID:GaZ3ll3,项目名称:WaveBlocksND,代码行数:32,代码来源:MatrixPotential1S.py


示例14: R_z

def R_z(x, y, z, alpha=0):
    """
    Rotation matrix for rotation about the z axis

    Parameters
    ----------
    x : `np.ndarray` with dims (1, N)
    y : `np.ndarray` with dims (1, N)
    z : `np.ndarray` with dims (1, N)
    alpha : float
        angle [radians] to rotate about the `z` axis counterclockwise

    Returns
    -------
    x2 : `np.ndarray` with dims (1, N)
        Rotated x positions
    y2 : `np.ndarray` with dims (1, N)
        Rotated y positions
    z2 : `np.ndarray` with dims (1, N)
        Rotated z positions
    """
    original_shape = x.shape
    xyz = np.vstack([x.ravel(), y.ravel(), z.ravel()])
    r_z = np.array([[np.cos(alpha), np.sin(alpha), 0],
                    [-np.sin(alpha), np.cos(alpha), 0],
                    [0, 0, 1]])
    new_xyz = np.dot(r_z, xyz)
    x2, y2, z2 = np.vsplit(new_xyz, 3)
    x2.resize(original_shape)
    y2.resize(original_shape)
    z2.resize(original_shape)
    return x2, y2, z2
开发者ID:bmorris3,项目名称:friedrich,代码行数:32,代码来源:orientation.py


示例15: process_mirror

 def process_mirror(cls, img, mode):
     if mode == 'Vertical':
         org = numpy.asarray(img)
         flip = numpy.fliplr(org)
         data1 = numpy.hsplit(org, 2)
         data2 = numpy.hsplit(flip, 2)
         data = numpy.hstack((data1[0], data2[1]))
         img = Image.fromarray(data)
     elif mode == 'Horizontal':
         org = numpy.asarray(img)
         flip = numpy.flipud(org)
         data1 = numpy.vsplit(org, 2)
         data2 = numpy.vsplit(flip, 2)
         data = numpy.vstack((data1[0], data2[1]))
         img = Image.fromarray(data)
     return img
开发者ID:jfhu,项目名称:kamera,代码行数:16,代码来源:other.py


示例16: _least_square_evoked

def _least_square_evoked(data, events, event_id, tmin, tmax, sfreq):
    """Least square estimation of evoked response from data.

    Parameters
    ----------
    data : ndarray, shape (n_channels, n_times)
        The data to estimates evoked
    events : ndarray, shape (n_events, 3)
        The events typically returned by the read_events function.
        If some events don't match the events of interest as specified
        by event_id, they will be ignored.
    event_id : dict
        The id of the events to consider
    tmin : float
        Start time before event.
    tmax : float
        End time after event.
    sfreq : float
        Sampling frequency.

    Returns
    -------
    evokeds_data : dict of ndarray
        A dict of evoked data for each event type in event_id.
    toeplitz : dict of ndarray
        A dict of toeplitz matrix for each event type in event_id.
    """
    nmin = int(tmin * sfreq)
    nmax = int(tmax * sfreq)

    window = nmax - nmin
    n_samples = data.shape[1]
    toeplitz_mat = dict()
    full_toep = list()
    for eid in event_id:
        # select events by type
        ix_ev = events[:, -1] == event_id[eid]

        # build toeplitz matrix
        trig = np.zeros((n_samples, 1))
        ix_trig = (events[ix_ev, 0]) + nmin
        trig[ix_trig] = 1
        toep_mat = linalg.toeplitz(trig[0:window], trig)
        toeplitz_mat[eid] = toep_mat
        full_toep.append(toep_mat)

    # Concatenate toeplitz
    full_toep = np.concatenate(full_toep)

    # least square estimation
    predictor = np.dot(linalg.pinv(np.dot(full_toep, full_toep.T)), full_toep)
    all_evokeds = np.dot(predictor, data.T)
    all_evokeds = np.vsplit(all_evokeds, len(event_id))

    # parse evoked response
    evoked_data = dict()
    for idx, eid in enumerate(event_id):
        evoked_data[eid] = all_evokeds[idx].T

    return evoked_data, toeplitz_mat
开发者ID:vwyart,项目名称:mne-python,代码行数:60,代码来源:xdawn.py


示例17: _least_square_evoked

def _least_square_evoked(epochs_data, events, tmin, sfreq):
    """Least square estimation of evoked response from epochs data.

    Parameters
    ----------
    epochs_data : array, shape (n_channels, n_times)
        The epochs data to estimate evoked.
    events : array, shape (n_events, 3)
        The events typically returned by the read_events function.
        If some events don't match the events of interest as specified
        by event_id, they will be ignored.
    tmin : float
        Start time before event.
    sfreq : float
        Sampling frequency.

    Returns
    -------
    evokeds : array, shape (n_class, n_components, n_times)
        An concatenated array of evoked data for each event type.
    toeplitz : array, shape (n_class * n_components, n_channels)
        An concatenated array of toeplitz matrix for each event type.
    """

    n_epochs, n_channels, n_times = epochs_data.shape
    tmax = tmin + n_times / float(sfreq)

    # Deal with shuffled epochs
    events = events.copy()
    events[:, 0] -= events[0, 0] + int(tmin * sfreq)

    # Contruct raw signal
    raw = _construct_signal_from_epochs(epochs_data, events, sfreq, tmin)

    # Compute the independent evoked responses per condition, while correcting
    # for event overlaps.
    n_min, n_max = int(tmin * sfreq), int(tmax * sfreq)
    window = n_max - n_min
    n_samples = raw.shape[1]
    toeplitz = list()
    classes = np.unique(events[:, 2])
    for ii, this_class in enumerate(classes):
        # select events by type
        sel = events[:, 2] == this_class

        # build toeplitz matrix
        trig = np.zeros((n_samples, 1))
        ix_trig = (events[sel, 0]) + n_min
        trig[ix_trig] = 1
        toeplitz.append(linalg.toeplitz(trig[0:window], trig))

    # Concatenate toeplitz
    toeplitz = np.array(toeplitz)
    X = np.concatenate(toeplitz)

    # least square estimation
    predictor = np.dot(linalg.pinv(np.dot(X, X.T)), X)
    evokeds = np.dot(predictor, raw.T)
    evokeds = np.transpose(np.vsplit(evokeds, len(classes)), (0, 2, 1))
    return evokeds, toeplitz
开发者ID:annapasca,项目名称:mne-python,代码行数:60,代码来源:xdawn.py


示例18: get_intra_design

def get_intra_design(mat_file, n_scans, contrasts, memory=Memory(None)):
    mat = memory.cache(load_matfile)(mat_file)['SPM']
    doc = {}

    design_matrix = mat.xX.X.tolist()           # xX: model
    conditions = [str(i) for i in mat.xX.name]

    n_sessions = len(n_scans)
    design_matrices = np.vsplit(design_matrix, np.cumsum(n_scans[:-1]))
    conditions = np.array(conditions)

    sessions_dm = []
    sessions_contrast = {}
    for i, dm in zip(range(n_sessions), design_matrices):
        mask = np.array(
            [cond.startswith('Sn(%s)' % (i + 1)) for cond in conditions])
        sessions_dm.append(dm[:, mask][:, :-1].tolist())

        for contrast_id in contrasts:
            sessions_contrast.setdefault(contrast_id, []).append(
                np.array(contrasts[contrast_id])[mask][:-1].tolist())

    doc['design_matrices'] = sessions_dm
    doc['contrasts'] = sessions_contrast
    return doc
开发者ID:schwarty,项目名称:nignore,代码行数:25,代码来源:spm.py


示例19: __init__

	def __init__(self, name, paneSize, colsrows) :
		fullsize = [a*b for a,b in zip(paneSize,colsrows)]
		pygame.init()
		pygame.display.set_caption(name)
		pygame.display.set_mode(fullsize,
#			pygame.DOUBLEBUF|
#			pygame.HWSURFACE|
#			pygame.FULLSCREEN|
#			pygame.OPENGL|
			0)
		self.screen = pygame.display.get_surface()
		self.colsrows = colsrows
		self.screenBuffer = pygame.surfarray.pixels2d(self.screen).swapaxes(0,1)
		self.splits = [np.hsplit(v,self.colsrows[0]) for v in np.vsplit(self.screenBuffer,self.colsrows[1])]
		self.videoSink = None
		self.letterR = np.array([[c!=" " for c in row] for row in [
			"******* ",
			"********",
			"**    **",
			"**   ***",
			"******* ",
			"******  ",
			"**  *** ",
			"**   ***",
			"**    **",
			"**    **",
		]], dtype=bool)
		self.blink = 0
开发者ID:hejibo,项目名称:freenect_python_processing,代码行数:28,代码来源:panelgrid.py


示例20: validate_sentence

def validate_sentence(session, model, validation_batch, encoder_state, current_step):
    encoder_inputs, single_decoder_inputs, decoder_weights = validation_batch.next()
    print(BatchGenerator.batches2string(encoder_inputs))
    print(BatchGenerator.batches2string(single_decoder_inputs))
    # replicate to full batch size so we have multiple results agains the whole state
    encoder_inputs = [np.repeat(x, BATCH_SIZE, axis=0) for x in encoder_inputs]
    decoder_inputs = [np.repeat(x, BATCH_SIZE, axis=0) for x in single_decoder_inputs]
    decoder_weights = [np.repeat(x, BATCH_SIZE, axis=0) for x in decoder_weights]
    # _, eval_loss, prediction = model.step(sess, current_step - 1, encoder_inputs, decoder_inputs,
    #                                      decoder_weights, enc_state[-1:], 1.0, True)
    _, eval_loss, prediction = model.step(session, current_step - 1, encoder_inputs, decoder_inputs,
                                          decoder_weights, encoder_state, 1.0, True)
    # split into 'no of batches' list then average across batches
    reshaped = np.reshape(prediction, (prediction.shape[0] / BATCH_SIZE, BATCH_SIZE, prediction.shape[1]))
    averaged = np.mean(reshaped, axis=1)
    # now roll as in case of single batch
    rolled = np.rollaxis(np.asarray([averaged]), 1, 0)
    splitted = np.vsplit(rolled, rolled.shape[0])
    squeezed = [np.squeeze(e,0) for e in splitted]
    print(BatchGenerator.batches2string(squeezed))
    # compute character to character perplexity
    val_perp = float(np.exp(BatchGenerator.logprob(np.concatenate(squeezed),
                                                   np.concatenate(single_decoder_inputs[1:]))))
    print('--validation perp.: %.2f' % val_perp)
    return val_perp
开发者ID:rudolfix,项目名称:deeplearning,代码行数:25,代码来源:reverse_seq.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.vstack函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.void函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap