Beispiel #1
0
		const Eigen::MatrixXd & ClassificationValidation::yRandomizationTest(int runs, int k)
		{
			Eigen::MatrixXd y_backup = model_->Y_;
			Eigen::MatrixXd desc_backup = model_->descriptor_matrix_;
			//Eigen::MatrixXd res_backup = clas_model->training_result_;
			VMatrix dataY_backup = model_->data->Y_;
						
			//Eigen::VectorXd c(2, -1);
			//vector<Eigen::VectorXd > results(runs, 2);
			yRand_results_.resize(runs, 2);
			yRand_results_.fill(-1);
			class_results_.resize(clas_model->labels_.size());
			class_results_.setZero();

			for (int i = 0; i < runs; i++)
			{
				yRand(); // randomize all columns of Y_
				crossValidation(k, 0);
				testInputData(0);
				yRand_results_(i, 0) = quality_input_test_;
				yRand_results_(i, 1) = quality_cv_;
			}
			
			class_results_ = class_results_/runs;
			
			model_->Y_ = y_backup;
			model_->descriptor_matrix_ = desc_backup;
			//clas_model->training_result_ = res_backup;
			QSARData* data = const_cast <QSARData*> (model_->data);
			data->Y_ = dataY_backup;
			model_->train();
			
			return yRand_results_;
		}
    bool canInsertRoom( Level & level, vec4uint32 & newRoom, uint32_t & seed ) {
#ifdef FL_DEBUG
        log() << "Attempting room insert of " << newRoom << std::endl;
#endif

        vec2uint32 expandedRoomDimensions { newRoom.w + 2, newRoom.h + 2 };
        std::pair<bool, FreeEntryCache::FreeEntryIter> ce = freeEntrySelector_.findFreeEntryOfDimensions( freeEntryCache_,
                expandedRoomDimensions  );

        if( ce.first ) {
            FreeEntryCache::FreeEntryIter & fe( ce.second );
            const vec4uint32 & foundSegment( *(fe.entryListIter) );
#ifdef FL_DEBUG
            log() << "Found free entry: " << foundSegment << std::endl;
#endif

            // Choose a random x and y offset inside this segment based on how wide and high it is
            int32_t restrictedX( foundSegment.w - (expandedRoomDimensions.x ) );
            int32_t restrictedY( foundSegment.h - (expandedRoomDimensions.y ) );
#ifdef FL_DEBUG
            log() << "Restricted X/Y is " << restrictedX << " " << restrictedY << std::endl;
#endif
            uint32_t xRand( randGenerator_( seed ) );
            uint32_t yRand( randGenerator_( seed ) );
            uint32_t randXOffset( ( restrictedX > 0 ? ( xRand % restrictedX) : 0 ) );
            uint32_t randYOffset( ( restrictedY > 0 ? ( yRand % restrictedY) : 0 ) );
#ifdef FL_DEBUG
            log() << "Randoffsets are " << randXOffset << " " << randYOffset << std::endl;
#endif
            newRoom.x = foundSegment.x + randXOffset + 1;
            newRoom.y = foundSegment.y + randYOffset + 1;
#ifdef FL_DEBUG
            log() << "Room X and Y are " << newRoom.x << " " << newRoom.y << std::endl;
#endif

            freeEntryCache_.useFreeEntry( fe, newRoom );
//            vec4uint32 expandedRoom { newRoom.x - 1, newRoom.y - 1, newRoom.w + 2, newRoom.h + 2 };
            // We make the free space computations easier if we occlude an expanded room
            occlusionBuffer_.occludeWithBorder( newRoom );
#ifdef FL_DEBUG
            log() << "After free space use, occlusion buffer is now" << std::endl;
            occlusionBuffer_.debug();
#endif
            return true;
        }
        else {
#ifdef FL_DEBUG
            log() << "Unable to find free entry" << std::endl;
#endif
            return false;
        }
    }