本文整理汇总了C++中fvec类的典型用法代码示例。如果您正苦于以下问题:C++ fvec类的具体用法?C++ fvec怎么用?C++ fvec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了fvec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: assert
void
LPC::process(fvec& in, fvec& out)
{
// fprintf( stderr, "%i %i %i %i\n", in.size(), inSize_, out.size(), outSize_ );
assert((in.size() == inSize_) && (out.size() == outSize_));
unsigned int i,j;
autocorr_->process(in, corr_);
pitch_ = autocorr_->pitch();
for (i=1; i<order_; i++)
for (j=1; j<order_; j++)
{
rmat_(i-1,j-1) = corr_(abs((int)(i-j)));
}
rmat_.invert(temp_);
for (i=0; i < order_-1; i++)
{
out(i) = 0.0;
for (j=0; j < order_-1; j++)
{
out(i) += (rmat_(i,j) * corr_(1+j));
}
}
predict(in, out);
out(order_-1) = pitch_;
out(order_) = power_;
}
示例2: RandFourierMap
int RandFourierMap(int nKernelType, const fvec& x, const std::vector<fvec> &W, const fvec &b, fvec &result)
{
int nErrCode = 0;
if(W.empty() || b.empty())
{
return 1;
}
int nKernelRank = W[0].size();
switch(nKernelType)
{
case RAND_KERNEL_RBF:
for(int rank_idx = 0; rank_idx < nKernelRank; ++rank_idx)
{
float sum = 0.0;
for(int dim_idx = 0; dim_idx < x.size(); ++dim_idx)
{
sum += W[dim_idx][rank_idx] * x[dim_idx];
}
result.push_back(sqrt(2.0 / nKernelRank) * cos(sum + b[rank_idx]));
}
break;
default:
nErrCode = 1;
}
return nErrCode;
}
示例3: RandFourierFactorize
int RandFourierFactorize(int nKernelType, int nKernelRank, float fGamma, const std::vector<fvec>& X, std::vector<fvec> &G, std::vector<fvec> &W, fvec &b)
{
int nErrCode = 0;
int m = X.size();
if(m == 0)
{
return nErrCode;
}
int dim = X[0].size();
G.clear();
W.clear();
b.clear();
//generate random features
dlib::rand r;
std::ostringstream seed;
seed << (unsigned int) time(0);
r.set_seed(seed.str());
switch(nKernelType)
{
case RAND_KERNEL_RBF:
for(int ind = 0; ind < dim; ++ind)
{
fvec tmp_vec;
for(int rank_idx = 0; rank_idx < nKernelRank; ++rank_idx)
{
tmp_vec.push_back(r.get_random_gaussian() * fGamma);
}
W.push_back(tmp_vec);
}
for(int ind = 0; ind < nKernelRank; ++ind)
{
b.push_back(r.get_random_float() * 2.0 * PI);
}
for(int ind = 0; ind < m; ++ind)
{
fvec tmp_vec;
RandFourierMap(nKernelType, X[ind], W, b, tmp_vec);
G.push_back(tmp_vec);
}
break;
default:
//unknown kernel type
//printf("unknown type\n");
nErrCode = 1;
break;
};
return nErrCode;
}
示例4: SetParams
void ClassMLP::SetParams(Classifier *classifier, fvec parameters)
{
if(!classifier) return;
float alpha = parameters.size() > 0 ? parameters[0] : 1;
float beta = parameters.size() > 1 ? parameters[1] : 1;
int layers = parameters.size() > 2 ? parameters[2] : 1;
int neurons = parameters.size() > 3 ? parameters[3] : 1;
int activation = parameters.size() > 4 ? parameters[4] : 0;
((ClassifierMLP *)classifier)->SetParams(activation, neurons, layers, alpha, beta);
}
示例5: assert
void
DownSampler::process(fvec& in, fvec& out)
{
assert((in.size() == inSize_) && (out.size() == outSize_));
unsigned int size = in.size();
unsigned int i;
for (i=0; i< size / factor_; i++)
{
out(i) = in(i * factor_);
}
}
示例6: Test
fvec ClustererDBSCAN::Test( const fvec &sample)
{
fvec res;
res.resize(nbClusters+1,0);
//convert input to Point
Point v (sample.size());
for (int i = 0; i < sample.size(); ++i)
{
v(i)=sample[i];
}
// find the nearest point in our samples
int nearest = -1;
double dist = INFINITY;
double temp_d = 0;
if (_type==0) //if DBSCAN we set _depth like _eps
{
_depth=_eps;
}
for (int j = 0; j < pts.size(); ++j)
{
// according to the selected metric
if(_metric == 0)
{
Metrics::Distance<Metrics::Cosine<Point> > d;
temp_d = d.distance(v, pts[j]);
}
else
{
Metrics::Distance<Metrics::Euclidean<Point> > d;
temp_d = d.distance(v, pts[j]);
}
if (temp_d < dist && temp_d < _eps && _pointId_to_clusterId[j] > 0 && _core[j]){
dist = temp_d;
nearest = j;
}
}
// did we find something?
if (nearest > -1){
if (dist < _depth){ // is it near enough?
res[_pointId_to_clusterId[nearest]-1] = 1; //take the color of that cluster
}
else if (abs(dist - _eps) < _eps*0.01) //in OPTICS, we are at the border of _eps : draw a thin line, darker
{
res[_pointId_to_clusterId[nearest]-1] = 0.5;
}
}
return res;
}
示例7:
void operator /= (fvec &a, const float b)
{
if (a.size() == 2)
{
a[0] /= b;
a[1] /= b;
}
else
{
for (int i = 0; i < a.size(); i++) a[i] /= b;
}
}
示例8: fmagnitude
void
MFCC::process(fvec& in, fvec& out)
{
unsigned int i,k;
if ((in.size() != inSize_) || (out.size() != outSize_))
{
cerr << "Warnging: MFCC::process: inSize_ and input window size do not agree" << endl;
return;
}
hamming_->process(in, windowed);
magfft_->process(windowed, magnitude);
for (i=0; i < inSize_/2; i++)
fmagnitude(i) = magnitude(i);
for (i=0; i< inSize_/2; i++)
fmagnitude(i+ inSize_/2) = fmagnitude(inSize_/2 - i);
float sum =0.0;
// Calculate the filterbank responce
for (i=0; i<totalFilters_; i++)
{
sum = 0.0;
for (k=0; k<fftSize_; k++)
{
sum += (mfccFilterWeights_(i, k) * fmagnitude(k));
}
if (sum != 0.0)
earMagnitude_(i) = log10(sum);
else
earMagnitude_(i) = 0.0;
}
// Take the DCT
for (i=0; i < cepstralCoefs_; i++)
{
sum =0.0;
for (k=0; k < totalFilters_; k++)
{
sum += (mfccDCT_(i,k) * earMagnitude_(k));
}
out(i) = sum;
}
}
示例9: test_coverage
// SANITY TEST
void test_coverage(const fvec& lower, const fvec& upper, const vector<Rectangle>& recs, uint nsamples)
{
// first, test the rectangles
uint N = lower.size();
for (uint r = 0; r < recs.size(); r++)
{
for (uint k = 0; k < N; k++)
{
if (recs[r].center[k] != recs[r].lb[k] + (recs[r].ub[k]-recs[r].lb[k])/2)
{
cout << "***** rec " << r << " expected center at " << recs[r].center[k] << ", got " << recs[r].lb[k] + (recs[r].ub[k]-recs[r].lb[k])/2 << endl;
}
if (recs[r].lb[k] < 0.0)
cout << "***** rec " << r << " invalid lower bound " << recs[r].lb[k] << "!" << endl;
if (recs[r].ub[k] > 1.0)
cout << "***** rec " << r << " invalid upper bound " << recs[r].ub[k] << "!" << endl;
}
}
for (uint i = 0; i < nsamples; i++)
{
uint hits = 0;
fvec rvec = fvec(N, 0.0);
srand (i);
for (uint j = 0; j < N; j++) rvec[j] = double(rand()) / double(RAND_MAX);
for (uint r = 0; r < recs.size(); r++)
{
if (DEBUG)
{
cout << "\t check [";
for (uint k = 0; k < N; k++) cout << " " << recs[r].lb[k];
cout << " ]" << endl;
for (uint k = 0; k < N; k++) cout << " " << recs[r].ub[k];
cout << " ]" << endl;
}
bool found = true;
for (uint k = 0; k < N; k++)
{
if (rvec[k] < recs[r].lb[k] || rvec[k] > recs[r].ub[k])
{
found = false;
break;
}
}
if (found) hits += 1;
}
if (hits != 1)
{
cout << "random vector [";
for (uint k = 0; k < N; k++) cout << " " << rvec[k];
cout << " ] has " << hits << " hits!" << endl;
}
}
}
示例10: fvec
Rectangle::Rectangle(const fvec& lower, const fvec& upper, Direct* D)
{
lb = fvec(lower);
ub = fvec(upper);
center = fvec(lower.size(), 0.0);
d = 0.0;
for (unsigned int i = 0; i < lower.size(); i++)
{
center[i] = lb[i] + (ub[i]-lb[i]) / 2.;
d += pow((lb[i]-center[i]), 2);
}
d = sqrt(d);
// if (DEBUG) cout << "***** d = " << d << endl;
y = D->samplef(center);
}
示例11: heapSort
void heapSort(fvec &height, ivec &index, int tsize)
{
int i = 0;
float ftemp = 0.0;
int itemp = 0;
int size = index.size();
if (tsize != height.size())
{
tsize = height.size();
}
else
;
if (tsize != size)
{
cout << "\nfuck you\n" << flush;
}
else
;
i = tsize;
i /= 2;
i -= 1;
for (; i >= 0; i--)
{
siftDown(height, index, i, tsize);
}
i = tsize - 1;
for (; i >= 1; i--)
{
ftemp = height[0];
height[0] = height[i];
height[i] = ftemp;
itemp = index[0];
index[0] = index[i];
index[i] = itemp;
siftDown(height, index, 0, i - 1);
}
}
示例12: in
void
RMS::process(fvec& in, fvec& out)
{
float rmsEnergy = 0.0;
unsigned int i;
if ((in.size() != inSize_) || (out.size() != outSize_))
{
cerr << "Warning: RMS::process: inSize_ and input window size do not agree" << endl;
return;
}
float val;
/* Compute centroid using moments */
for (i=0; i < inSize_; i++)
{
val = in(i);
rmsEnergy += (val * val);
}
rmsEnergy /= inSize_;
rmsEnergy = sqrt(rmsEnergy);
out(0) = rmsEnergy;
}
示例13: doubleArea
//returns 2*area( triangle(a, b ,c) )
float doubleArea(const fvec &a, const fvec &b, const fvec &c)
{
int asize = a.size();
int bsize = b.size();
int csize = c.size();
float da = 0;
if ((asize == 3) && (asize == bsize) && (asize == csize))
{
float cyclic = (a[0] * b[1] * c[2] + a[1] * b[2] * c[0] + a[2] * b[0] * c[1]);
float anti_cyclic = (a[0] * b[2] * c[1] + a[1] * b[0] * c[2] + a[2] * b[1] * c[0]);
da = (cyclic - anti_cyclic);
}
else if ((asize == 2) && (asize == bsize) && (asize == csize))
{
da = (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
}
else
;
return da;
}
示例14: update
void PFilterSIRCUDA::update(fvec measurement) {
float neff=0.0;
float* measurementDev;
cudaMalloc( &measurementDev, (size_t) measurement.n_rows * sizeof(float)) ;
cudaMemcpy(measurementDev,measurement.memptr(),(size_t) measurement.n_rows * sizeof(float), cudaMemcpyHostToDevice);
//fmat virtualMeasurementOfParticles;
//fmat differences = zeros<fmat>(measurement.n_rows,particles.samples.n_cols);
frowvec evals;
//virtualMeasurementOfParticles = process->hfun(&particles.samples);
measurementOnGPU = process->hfun_gpu(samplesOnGPU, particles.samples.n_cols, particles.samples.n_rows);
// calculate differences
//differences = virtualMeasurementOfParticles - inputMatrix;
/*for (unsigned int i=0; i< virtualMeasurementOfParticles.n_cols; ++i)
{
for(unsigned int j=0; j<virtualMeasurementOfParticles.n_rows;++j)
{
differences(j,i) = virtualMeasurementOfParticles(j,i) - measurement(j);
}
}*/
callDeviationKernel(measurementOnGPU, measurementDev, particles.samples.n_rows,
particles.samples.n_cols, deviationsOnGPU);
evals = process->eval_gpu(deviationsOnGPU, particles.samples.n_cols);
// % is the Schur product (elementwise vector multiplication
particles.weights = particles.weights % evals;
// get samples from graphics card
cudaMemcpy(particles.samples.memptr(),samplesOnGPU, particles.samples.n_elem * sizeof(float), cudaMemcpyDeviceToHost);
normalizeWeights();
neff=calculateNeff();
if (neff <= nthr) {
#ifdef VERBOSE
printf("too few particles. 1/N for all particles\n");
#endif
particles.weights = ones<frowvec>(particles.weights.n_cols) / (float)particles.weights.n_cols;
}
else particles = resampler->resample(&particles);
}
示例15: utProcess
//function [y,Y,P,Y1]=ut(f,X,Wm,Wc,n,R)
void BFilterUKF::utProcess(fmat X,fvec Wm, fvec Wc, unsigned int n, fmat R)
{
//Unscented Transformation
//Input:
// f: nonlinear map
// X: sigma points
// Wm: weights for mean
// Wc: weights for covraiance
// n: numer of outputs of f
// R: additive covariance
//Output:
// y: transformed mean
// Y: transformed smapling points
// P: transformed covariance
// Y1: transformed deviations
unsigned int L=X.n_cols;
x1 = zeros<fvec>(n);
X1 = zeros<fmat>(n,L);
//for k=1:L
for (unsigned int k=0; k < L; ++k)
{
fmat XColK = X.col(k);
X1.col(k)= process->ffun(&XColK);
x1=x1+Wm(k)*X1.col(k);
}
//X2=X1-x1(:,ones(1,L)); // generate duplicates of vector x1
X2 = X1;
for (unsigned int j = 0; j < L; ++j)
{
for (unsigned int i = 0; i < x1.n_rows; ++i)
{
X2(i,j) -= x1(i);
}
}
P1=X2*Wc.diag()*X2.t()+R;
}