Пример #1
0
/**
 * main function
 */
int main(){

	srand(time(NULL));
	int size = 10;

	queue *li = (queue*)malloc(sizeof(queue));
	init(li,size);

	int i;
	for(i = 0; i < size;++i){
		enqueue(li,i+1);
	}

	printf("B/F size: %d \n",getInputSize(li));
	while(!isEmpty(li)){
			printf("dequeue: %d \n",dequeue(li));
		}
	if(isEmpty(li))
		printf("empty \n");
	else
		printf("not empty \n");


	printf("A/F size: %d \n",getInputSize(li));

	return 0;
}
Пример #2
0
  Real SpatialPooler::blankScore(InIter begin1) const
  {
    Real blankScore = 0, val = 0;
    std::vector<UInt>::const_iterator b_it, b_end;
    b_it = boundaries_.begin();
    b_end = --boundaries_.end();

    switch (mode_) {
    case dot:
    case dot_maxD:
      blankScore = *begin1;
      while (b_it != b_end)
        blankScore += *(begin1 + *b_it++);
      break;
    case product:
    case product_maxD:
      blankScore = *begin1;
      while (b_it != b_end)
        blankScore *= *(begin1 + *b_it++);
      break;
    case gaussian:
      blankScore = 1;
      InIter end = begin1 + getInputSize();
      nta::Exp<Real> exp_f;
      while (begin1 != end) {
        val = *begin1++;
        blankScore *= exp_f(k2_ * val * val);
      }
      break;
    }
    return blankScore;
  }
Пример #3
0
int CentralSplitter::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QSplitter::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: buildInitialSizes(); break;
        case 1: { QList<int> _r = makeSizeList();
            if (_a[0]) *reinterpret_cast< QList<int>*>(_a[0]) = _r; }  break;
        case 2: refreshSizes((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
        case 3: refreshSizes(); break;
        case 4: showEvent((*reinterpret_cast< QShowEvent*(*)>(_a[1]))); break;
        case 5: setSizesInt((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2])),(*reinterpret_cast< int(*)>(_a[3]))); break;
        case 6: { int _r = getTopicSize();
            if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; }  break;
        case 7: { int _r = getCentralSize();
            if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; }  break;
        case 8: { int _r = getInputSize();
            if (_a[0]) *reinterpret_cast< int*>(_a[0]) = _r; }  break;
        default: ;
        }
        _id -= 9;
    }
    return _id;
}
Пример #4
0
void ConnSW_BP::_backprop(Layer_BP *to, const Layer_BP *from)
{
	LayerSW_BP *to_sw = dynamic_cast<LayerSW_BP *>(to);
	if(to_sw == nullptr)
		throw Exception("output layer is not derived from LayerSW_BP");
	
	const LayerSW_BP *from_sw = dynamic_cast<const LayerSW_BP *>(from);
	if(from_sw == nullptr)
		throw Exception("input layer is not derived from LayerSW_BP");
	
	float *output_error = to_sw->getOutputError().getData();
	const float *input_error = from_sw->getInputError().getData();
	const float *weight = getWeight().getData();
	int sx = getInputSize(), sy = getOutputSize();
	for(int ix = 0; ix < sx; ++ix)
	{
		for(int iy = 0; iy < sy; ++iy)
		{
			// TODO: fence in opencl to optimize cache
			output_error[ix] += weight[iy*sx + ix]*input_error[iy];
		}
	}
	
	_backprop(static_cast<const Layer *>(to), from);
}
Пример #5
0
void ConnSW::_transmit(const Layer *from, Layer *to) const
{
	const LayerSW *sw_from = dynamic_cast<const LayerSW *>(from);
	if(sw_from == nullptr)
		throw Exception("input layer is not derived from LayerSW");
	
	LayerSW *sw_to = dynamic_cast<LayerSW *>(to);
	if(sw_to == nullptr)
		throw Exception("output layer is not derived from LayerSW");
	
	const float *input = sw_from->getOutput().getData();
	float *output = sw_to->getInput().getData();
	const int out_size = getOutputSize();
	const int in_size = getInputSize();
	
	const float *weight = _weight.getData();
	const float *bias = _bias.getData();
	for(int j = 0; j < out_size; ++j)
	{
		float sum = 0.0;
		for(int i = 0; i < in_size; ++i)
		{
			sum += input[i]*weight[in_size*j + i];
		}
		output[j] += sum + bias[j];
	}
}
Пример #6
0
void ConnSW_BP::_backprop(const Layer *to, const Layer_BP *from)
{
	const LayerSW *to_sw = dynamic_cast<const LayerSW *>(to);
	if(to_sw == nullptr)
		throw Exception("output layer is not derived from LayerSW");
	
	const LayerSW_BP *from_sw = dynamic_cast<const LayerSW_BP *>(from);
	if(from_sw == nullptr)
		throw Exception("input layer is not derived from LayerSW_BP");
	
	const float *input_error = from_sw->getInputError().getData();
	int sx = getInputSize(), sy = getOutputSize();
	
	float *weight_grad = getWeightGrad().getData();
	float *bias_grad = getBiasGrad().getData();
	for(int i = 0; i < sy; ++i)
	{
		bias_grad[i] = input_error[i];
	}
	
	const float *output = to_sw->getOutput().getData();
	for(int iy = 0; iy < sy; ++iy)
	{
		for(int ix = 0; ix < sx; ++ix)
		{
			weight_grad[iy*sx + ix] += output[ix]*input_error[iy];
		}
	}
}
Пример #7
0
const bool V3Ntk::setBddOrder(V3NtkHandler* const handler, const bool& file) const {
  unsigned supportSize = getInputSize() + getInoutSize() + 2*getLatchSize();
  if(supportSize >= bddMgrV->getNumSupports()) {
    Msg(MSG_ERR) << "BDD Support Size is Smaller Than Current Design Required !!" << endl;
    return false;
  }
  // build support
  unsigned supportId = 1;
  for(unsigned i = 0, n = getInputSize(); i < n; ++i) {
    const V3NetId& nId = (file)? getInput(i) : getInput(n-i-1);
    bddMgrV->addBddNodeV(nId.id, bddMgrV->getSupport(supportId)());
    bddMgrV->addBddNodeV(handler->getNetNameOrFormedWithId(nId),
        bddMgrV->getSupport(supportId)());
    ++supportId;
  }
  for(unsigned i = 0, n = getInoutSize(); i < n; ++i) {
    const V3NetId& nId = (file)? getInout(i) : getInout(n-i-1);
    bddMgrV->addBddNodeV(nId.id, bddMgrV->getSupport(supportId)());
    bddMgrV->addBddNodeV(handler->getNetNameOrFormedWithId(nId),
        bddMgrV->getSupport(supportId)());
    ++supportId;
  }
  for(unsigned i = 0, n = getLatchSize(); i < n; ++i) {
    const V3NetId& nId = (file)? getLatch(i) : getLatch(n-i-1);
    bddMgrV->addBddNodeV(nId.id, bddMgrV->getSupport(supportId)());
    bddMgrV->addBddNodeV(handler->getNetNameOrFormedWithId(nId),
        bddMgrV->getSupport(supportId)());
    ++supportId;
  }
  // Next State
  for(unsigned i = 0, n = getLatchSize(); i < n; ++i) {
    const V3NetId& nId = (file)? getLatch(i) : getLatch(n-i-1);
    bddMgrV->addBddNodeV(handler->getNetNameOrFormedWithId(nId)+"_ns",
        bddMgrV->getSupport(supportId)());
    ++supportId;
  }

  // Constants
  for (uint32_t i = 0; i < getConstSize(); ++i) {
    assert(getGateType(getConst(i)) == AIG_FALSE);
    bddMgrV->addBddNodeV(getConst(i).id, BddNodeV::_zero());
  }

  return true;
}
Пример #8
0
void TrainingSet::setInputSize(int is, double fill)
{
	int ls = getInputSize();
	resizeVectorSet(inputs, is, fill);
//	inputSize = is;

	//Si realmente hubo un cambio en el tamaño de las entradas
	if(is != ls){
		emit inputSizeChanged(is);
		emit inputSizeChanged(ls, is);
	}
}
Пример #9
0
void MultilayerPerceptron::randomizeWeights(double min, double max)
{
	size_t
			nLayers = layerWeights.size(),
			layer, neuron,
			nNeurons,
			nOutputs;

	srand(clock());
	for(layer = 0; layer < nLayers; layer++){
		nNeurons = layerWeights[layer].size();
		for(neuron = 0; neuron < nNeurons; neuron++){
			layerWeights[layer][neuron] = (layer == 0 ? getRandomValues(getInputSize()+1, min, max) : getRandomValues(layerWeights[layer-1].size()+1, min, max));
		}
	}
	nOutputs = outputWeights.size();
	for(size_t i = 0; i < nOutputs; i++){
		outputWeights[i] = getRandomValues(layerWeights[nLayers-1].size() + 1, min, max);
	}
}
Пример #10
0
size_t SoftmaxLayer::getInputCount() const
{
    return getInputSize().product();
}
Пример #11
0
Dimension SoftmaxLayer::getOutputSize() const
{
    return getInputSize();
}
Пример #12
0
ConnSW::ConnSW() : ConnSW(getID(), getInputSize(), getOutputSize())
{
	
}
Пример #13
0
	ConnSW_BP() : ConnSW_BP(getID(), getInputSize(), getOutputSize()) {}
Пример #14
0
const char_t* TinfoDecVideo::TinfoValueDecVideo::getVal0(bool &wasChange, bool &splitline)
{
    int percent;
    switch (item->type) {
#ifdef OSDTIMETABALE
        case IDFF_OSDtype_timetable:
            tsprintf(s, _l("%3.2fms"), deciV->getOSDtime() / 10000.0);
            wasChange = true;
            return s;
#endif
        case IDFF_OSDtype_TimeOnffdshow:
            percent = deciV->get_time_on_ffdshow_percent();
            if (percent < 0 || percent > 300) {
                tsprintf(s, _l("%3dms (N/A )"), deciV->get_time_on_ffdshow());
            } else {
                tsprintf(s, _l("%3dms (%3d%%)"), deciV->get_time_on_ffdshow(), percent);
            }
            wasChange = true;
            return s;
        case IDFF_OSDtype_inputSize:
            return getInputSize(s, wasChange);
        case IDFF_OSDtype_inputAspect:
            return getInputAspect(s, wasChange, countof(s));
        case IDFF_OSDtype_inputSizeAspect: {
            bool wasChangeSize = false;
            getInputSize(sizeStr, wasChangeSize);
            bool wasChangeAspect = false;
            getInputAspect(aspectStr, wasChangeAspect, countof(aspectStr));
            if (wasChange = (wasChangeSize || wasChangeAspect)) {
                tsnprintf_s(s, countof(s), _TRUNCATE, _l("%s, %s"), sizeStr, aspectStr);
            }
            return s;
        }
        case IDFF_OSDtype_meanQuant: {
            char_t news[60];
            float q;
            if (deciV->calcMeanQuant(&q) == S_OK && q > 0) {
                tsprintf(news, _l("%-5.2f"), q);
            } else {
                ff_strncpy(news, _l("not available"), countof(news));
            }
            if (strcmp(news, olds) != 0) {
                ff_strncpy(s, news, countof(s));
                wasChange = true;
            }
            return s;
        }
        case IDFF_OSDtype_outputFOURCC:
            deciV->getOutputFourcc(s, 50);
            wasChange = strcmp(s, olds) != 0;
            return s;
        case IDFF_OSDtype_currentFrameTime: {
            int val;
            if (SUCCEEDED(deciV->getCurrentFrameTime((unsigned int*)&val))) {
                tsprintf(s, _l("%02i:%02i:%02i"), val / 3600, (val / 60) % 60, val % 60);
                wasChange = true;
            } else {
                strcpy(s, _l("failed"));
                wasChange = false;
            }
            return s;
        }
        case IDFF_OSDtype_remainingFrameTime: {
            int val;
            if (SUCCEEDED(deciV->getRemainingFrameTime((unsigned int*)&val))) {
                tsprintf(s, _l("%02i:%02i:%02i"), val / 3600, (val / 60) % 60, val % 60);
                wasChange = true;
            } else {
                strcpy(s, _l("failed"));
                wasChange = false;
            }
            return s;
        }
        case IDFF_OSDtype_accurDeblock:
            if (olds[0] == '\0') {
                tsprintf(s, deciV->quantsAvailable() == S_OK ? _l("yes") : _l("no"));
                wasChange = true;
            }
            return s;
        case IDFF_OSDtype_inputFPS: {
            unsigned int fps1000;
            if (deciV->getAVIfps(&fps1000) != S_OK) {
                s[0] = '\0';
            } else {
                tsprintf(s, _l("%-7.3f"), float(fps1000 / 1000.0));
            }
            wasChange = strcmp(s, olds) != 0;
            return s;
        }
        case IDFF_OSDtype_inputFOURCC: {
            fourcc2str(deciV->getMovieFOURCC(), s, countof(s));
            wasChange = strcmp(s, olds) != 0;
            return s;
        }
        case IDFF_OSDtype_QueueCount: {
            int val = deciV->getQueuedCount();
            wasChange = true;
            if (val >= 0) {
                tsprintf(s, _l("%2d"), val);
            } else {
                val = -1 * val;
                switch (val) {
                    case IDD_QUEUEMSG_1:
                    case IDD_QUEUEMSG_2:
                    case IDD_QUEUEMSG_3:
                    case IDD_QUEUEMSG_4:
                    case IDD_QUEUEMSG_5:
                    case IDD_QUEUEMSG_6:
                    case IDD_QUEUEMSG_7:
                        ff_strncpy(s, trans->translate(val), countof(s));
                        break;
                    case IDD_QUEUEMSG_8: {
                        int late = (int)((-1) * deciV->getLate() / 10000);
                        tsnprintf_s(s, countof(s), _TRUNCATE, _l("%s %4dms"), trans->translate(val), late > 0 ? late : 0);
                    }
                }
            }
            return s;
        }
        case IDFF_OSDtype_Late: {
            int late = (int)deciV->getLate() / 10000;
            tsprintf(s, _l("%7dms"), late > 0 ? late : 0);
            wasChange = true;
            return s;
        }
        case IDFF_OSDtype_idct: {
            const char *idct0 = deciV->get_current_idct();
            if (idct0) {
                text<char_t> idct(idct0);
                ff_strncpy(s, (const char_t*)idct, countof(s));
            } else {
                tsprintf(s, _l("unknown"));
            }
            return s;
        }
        case IDFF_OSDtype_AviSynth_Info: {
            const char *info0 = deciV->getAviSynthInfo();
            if (info0) {
                text<char_t> info(info0);
                ff_strncpy(s, (const char_t*)info, countof(s));
            } else {
                tsprintf(s, _l("unavailable"));
            }
            wasChange = true;
            return s;
        }
        default:
            return TinfoValueDec::getVal0(wasChange, splitline);
    }
}
Пример #15
0
void TrainingSet::normalize(NormalizationType no)
{
	size_t sPatterns = getPatternCount();
	size_t sInputs = getInputSize();
	size_t sTargets = getTargetSize();
	double mean;
	double stddv;
	double nor;
	vector<vector<double> >
			li = inputs,
			lt = targets;

	for(size_t p = 0; p < sPatterns; p++){
		mean = ANNFrameworkFunctions::getMean(inputs[p]);
		stddv = ANNFrameworkFunctions::getStandardDeviation(inputs[p]);
		for(size_t i = 0; i < sInputs; i++){
			nor = (inputs[p][i] - mean)/stddv;
			switch(no){
				case ITrainingSet::BipolarAutoThreshold:
					break;
				case ITrainingSet::UnipolarAutoThreshold:
					break;
				case ITrainingSet::Nothing:
					break;
				case ITrainingSet::BipolarFixedThreshold:
					break;
				case ITrainingSet::UnipolarFixedThreshold:
					break;
				case ITrainingSet::LinearFixedRange:
					break;
				case ITrainingSet::LinearAutoRange:
					break;
				case ITrainingSet::Sigmoid:
					//NOTE: no estoy seguro de que esto sea asi
					inputs[p][i] = 1/(1 + exp(-nor));
					break;
				case ITrainingSet::Tanh:
					inputs[p][i] = (1 - exp(-nor))/(1 + exp(-nor));
					break;
				case ITrainingSet::MeanDistance:
					break;
			}

		}
		mean = ANNFrameworkFunctions::getMean(targets[p]);
		stddv = ANNFrameworkFunctions::getStandardDeviation(targets[p]);
		for(size_t t = 0; t < sTargets; t++){
			nor = (targets[p][t] - mean)/stddv;
			switch(no){
				case ITrainingSet::BipolarAutoThreshold:
					break;
				case ITrainingSet::UnipolarAutoThreshold:
					break;
				case ITrainingSet::Nothing:
					break;
				case ITrainingSet::BipolarFixedThreshold:
					break;
				case ITrainingSet::UnipolarFixedThreshold:
					break;
				case ITrainingSet::LinearFixedRange:
					break;
				case ITrainingSet::LinearAutoRange:
					break;
				case ITrainingSet::Sigmoid:
					//NOTE: no estoy seguro de que esto sea asi
					targets[p][t] = 1/(1 + exp(-nor));
					break;
				case ITrainingSet::Tanh:
					targets[p][t] = (1 - exp(-nor))/(1 + exp(-nor));
					break;
				case ITrainingSet::MeanDistance:
					break;
			}
		}
	}
	inputsNorType = no;
	targetsNorType = no;

	if(li != inputs){
		emit inputsChanged(inputs);
		emit inputsChanged(li, inputs);
	}

	if(lt != targets){
		emit targetsChanged(targets);
		emit targetsChanged(lt, targets);
	}
}
Пример #16
0
Dimension CTCDecoderLayer::getOutputSize() const
{
    return getInputSize();
}
Пример #17
0
size_t CTCDecoderLayer::getInputCount() const
{
    return getInputSize().product();
}