Exemple #1
0
std::vector<DistributionBase*> DistributionFactory::createDistributions(const std::vector<DistributionBaseObject*>& dist_objects) const {

	/* Container of user distributions */
	std::vector<DistributionBase*> distributions;

	/* Container of custom distributions */
	vector<DistributionCustomObject*> custom_object;

	/* Map of user IDs with the distribution objects */
	map<DistributionId,DistributionBase*> distribution_map;

	/* Create the distributions */
	vector<DistributionBaseObject*>::const_iterator it_distribution = dist_objects.begin();
	for(; it_distribution != dist_objects.end() ; ++it_distribution) {
		DistributionId id = (*it_distribution)->getUserId();
		if(distribution_map.find(id) != distribution_map.end())
			throw(DistributionBase::BadDistributionCreation(id,"Duplicated id"));
		if((*it_distribution)->getType() != "custom") {
			/* Create the distribution */
			DistributionBase* dist_ptr = createDistribution((*it_distribution));
			/* Update distribution map */
			distribution_map[id] = dist_ptr;
			/* Push it into the container */
			distributions.push_back(dist_ptr);
		} else
			custom_object.push_back(static_cast<DistributionCustomObject*>(*it_distribution));
	}

	/* Create custom definitions */
	vector<DistributionCustomObject*>::const_iterator it_custom = custom_object.begin();
	for(; it_custom != custom_object.end() ; ++it_custom) {
		/* Get distributions IDs */
		vector<DistributionId> dist_ids = (*it_custom)->getDistributionIds();
		/* Container to save the distributions */
		vector<DistributionBase*> dist_ptrs;
		for(vector<DistributionId>::iterator it = dist_ids.begin() ; it != dist_ids.end() ; ++it) {
			map<DistributionId,DistributionBase*>::const_iterator it_dist_id = distribution_map.find((*it));
			if(it_dist_id == distribution_map.end())
				throw(DistributionBase::BadDistributionCreation((*it_custom)->getUserId(),
					  "Distribution id " + toString((*it)) + " does not exist"));
			else
				dist_ptrs.push_back((*it_dist_id).second);
		}
		/* Create the distribution */
		DistributionBase* dist_custom = new DistributionCustom(*it_custom,dist_ptrs);
		/* Push this distribution on the map */
		distribution_map[(*it_custom)->getUserId()] = dist_custom;
		/* Push it into the container */
		distributions.push_back(dist_custom);
	}

	/* Return created distributions */
	return distributions;
}
Exemple #2
0
 void Random::produceOrTransform(Score &score,
                                 size_t beginAt,
                                 size_t endAt,
                                 const Eigen::MatrixXd &compositeCoordinates)
 {
   createDistribution(distribution);
   if(eventCount > 0)
     {
       double currentTime = 0;
       for (int i = 0; i < eventCount; i++)
         {
           //  Resample for every generated note.
           Event event(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
           Event transformedEvent;
           //ublas::axpy_prod(getRandomCoordinates(), event, transformedEvent);
           transformedEvent = getRandomCoordinates() * event;
           if (incrementTime)
             {
               double buffer = fabs(transformedEvent.getTime());
               transformedEvent.setTime(buffer + currentTime);
               currentTime += buffer;
             }
           score.push_back(transformedEvent);
         }
       // Apply the global transformation of coordinate system
       // to all child events produced by this node.
       size_t finalEndAt = score.size();
       for (size_t i = endAt; i < finalEndAt; i++) {
         score[i] = compositeCoordinates * score[i];
       }
     }
   else
     {
       for (size_t i = beginAt; i < endAt; i++)
         {
           score[i] = getRandomCoordinates() * score[i];
         }
     }
 }
Exemple #3
0
    ArrayDesc inferSchema(std::vector<ArrayDesc> schemas, std::shared_ptr<Query> query)
    {
        assert(schemas.size() == 1);
        ArrayDesc const& schema = schemas[0];
        Dimensions const& dims = schema.getDimensions();
        size_t nDims = dims.size();
        size_t nParams = _parameters.size();
        assert((nParams & 1) == 0 || nParams >= nDims*2);
        Dimensions newDims(nDims - nParams/2);
        if (newDims.size() <= 0)
            throw USER_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_OP_SLICE_ERROR1);
        std::vector<std::string> sliceDimName(nParams/2);
        for (size_t i = 0; i < nParams; i+=2) {
            sliceDimName[i >> 1]  = ((std::shared_ptr<OperatorParamReference>&)_parameters[i])->getObjectName();
        }
        _fixer.clear();
        size_t j = 0;
        for (size_t i = 0; i < nDims; i++) {
            const std::string dimName = dims[i].getBaseName();
            int k = safe_static_cast<int>(sliceDimName.size());
            while (--k >= 0
                   && sliceDimName[k] != dimName
                   && !(sliceDimName[k][0] == '_' && (size_t)atoi(sliceDimName[k].c_str()+1) == i+1));
            if (k < 0)
            {
                if (j >= newDims.size())
                    throw USER_QUERY_EXCEPTION(SCIDB_SE_INFER_SCHEMA, SCIDB_LE_DUPLICATE_DIMENSION_NAME,
                                               _parameters[i]->getParsingContext()) << dimName;
                _fixer.takeDimension(j).fromArray(0).fromDimension(i);
                newDims[j++] = dims[i];
            }
        }

        return ArrayDesc(schema.getName(), schema.getAttributes(), newDims,
                         createDistribution(psUndefined),
                         schema.getResidency());
    }