Example #1
0
int CountResults(MData& testSet, int *predictions, int *&posSlideCnt, int *&negSlideCnt)
{
	int		result = 0;
	int		*slideIdx = testSet.GetSlideIndices();

	posSlideCnt = (int*)calloc(testSet.GetNumSlides(), sizeof(int));
	negSlideCnt = (int*)calloc(testSet.GetNumSlides(), sizeof(int));

	if( negSlideCnt && posSlideCnt ) {
		for(int i = 0; i < testSet.GetNumObjs(); i++) {
			if( predictions[i] == 1 ) {
				posSlideCnt[slideIdx[i]]++;
			} else {
				negSlideCnt[slideIdx[i]]++;
			}
		}
	}
	return result;
}
int CountTrainingObjs(MData& trainSet, MData& testSet, int *&posCount, int *&negCount)
{
	int result = 0,
		numTrainSlides = trainSet.GetNumSlides(),
		*slideIdx = trainSet.GetSlideIndices(),
		*labels = trainSet.GetLabels();

	posCount = (int*)calloc(numTrainSlides, sizeof(int));
	negCount = (int*)calloc(numTrainSlides, sizeof(int));

	for(int i = 0; i < trainSet.GetNumObjs(); i++) {
		if( labels[i] == 1 ) {
			posCount[slideIdx[i]]++;
		} else {
			negCount[slideIdx[i]]++;
		}
	}
	return result;
}
Example #3
0
bool Picker::RestoreSessionData(MData& testSet)
{
	bool	result = true;
	int 	numObjs = testSet.GetNumObjs(),
			numDims = testSet.GetDims();

	result = UpdateBuffers(numObjs, true);
	if( result ) {
		float	*floatData = NULL;
		int		*intData = NULL;

		intData = testSet.GetLabels();
		memcpy(m_labels, intData, numObjs * sizeof(int));

		intData = testSet.GetIdList();
		memcpy(m_ids, intData, numObjs * sizeof(int));

		floatData = testSet.GetXCentroidList();
		memcpy(m_xCentroid, floatData, numObjs * sizeof(float));

		floatData = testSet.GetXClickList();
		// Test sets created with earlier versions of HistomicsML don't have clicks
		if( floatData == NULL ) {
			// Use centroids for click location if not present.
			floatData = testSet.GetXCentroidList();
		}
		memcpy(m_xClick, floatData, numObjs * sizeof(float));

		floatData = testSet.GetYCentroidList();
		memcpy(m_yCentroid, floatData, numObjs * sizeof(float));

		floatData = testSet.GetYClickList();
		if( floatData == NULL ) {
			floatData = testSet.GetYCentroidList();
		}
		memcpy(m_yClick, floatData, numObjs * sizeof(float));

		floatData = testSet.GetData()[0];
		memcpy(m_trainSet[0], floatData, numObjs * numDims * sizeof(float));

		char **classNames = testSet.GetClassNames();
		// Older versions of al_server did not save class names, set
		// defaults if they can't be loaded.
		if( classNames ) {
			for(int i = 0; i < testSet.GetNumClasses(); i++) {
				m_classNames.push_back(string(classNames[i]));
			}
		} else {
			m_classNames.push_back(string("Negative"));
			m_classNames.push_back(string("Positive"));
		}

		// Get slide indices from the dataset, NOT from the training set.
		intData = testSet.GetSlideIndices();
		char **slideNames = testSet.GetSlideNames();
		int idx;


		for(int i = 0; i < numObjs; i++) {

			m_slideIdx[i] = m_dataset->GetSlideIdx(slideNames[intData[i]]);

			// Keep track fo selected items
			idx = m_dataset->FindItem(m_xCentroid[i], m_yCentroid[i], slideNames[intData[i]]);
			if( idx == -1 ) {
				gLogger->LogMsg(EvtLogger::Evt_ERROR, "Unable to find item in dataset:, %f, %f in %s",
								m_xCentroid[i], m_yCentroid[i], slideNames[intData[i]]);
				result = false;
				break;
			} else {
				m_samples.push_back(idx);
			}
		}
	}
	return result;
}