void SkeletonBlendedGeometry::addJointBlending(UInt32 VertexIndex, UInt32 JointIndex, Real32 BlendAmount) { if(getWeightIndexes() == NULL) { GeoUInt32PropertyUnrecPtr Indexes = GeoUInt32Property::create(); setWeightIndexes(Indexes); } if(getWeights() == NULL) { GeoVec1fPropertyUnrecPtr Weights = GeoVec1fProperty::create(); setWeights(Weights); } //Vertex Index getWeightIndexes()->push_back(VertexIndex); //Joint Index getWeightIndexes()->push_back(JointIndex); //Weight Index getWeightIndexes()->push_back(getWeights()->getSize()); getWeights()->push_back(Pnt1f(BlendAmount)); }
void readAndLoop(char name[], peak_param *peak, SMC_ABC_t *ABC, error **err) { clock_t start = clock(); ABC->t++; read_particle_arr(name, ABC->oldPart, ABC->diffList->array, err); forwardError(*err, __LINE__,); particle_arr *newPart = ABC->newPart; particle_t **newPartArr = newPart->array; printf("-- Begin loop %d\n\n", ABC->t); printf("Tolerance = %.5f\n", ABC->oldPart->epsilon); int i; for (i=0; i<ABC->p; i++) { acceptParticle(peak, ABC, newPartArr[i], err); forwardError(*err, __LINE__,); } setWeights(ABC); printf("\n"); print_particle_arr(newPart); updateEpsilon_particle_arr(newPart, ABC->diffList->array); updateMean_particle_arr(newPart); updateCovariance_particle_arr(newPart); printf("\n-- End loop %d, ", ABC->t); routineTime(start, clock()); printf("------------------------------------------------------------------------\n"); return; }
const tPoseV& CTemporalFilter::interpolatePoses(const tPairV &lNNDist) { // std::cout << lNNDist.size() << std::endl; // std::cout << mWPose << std::endl << std::endl; if(lNNDist.empty()) { mWPose.setZero(); throw EMPTYPOSELISTERROR; } reset(lNNDist); setWeights(); computeWeightedPose(); mPoseList.sort(cmpW); if(mPoseList.size()>MAXINFLUENCENN) reduceNNN(MAXINFLUENCENN); saveBestPoses(); if(mPoseList.empty()) { mWPose.setZero(); throw EMPTYPOSELISTERROR; } mPoseW=(mPoseList.front().getWeight() < 0.05)?0.3:0.7; mWPose = mPoseList.front().getPose(); // CONSIDERING BEST POSE AS WPOSE!!! return mWPose; }
void SkeletonBlendedGeometry::addJointBlending(UInt32 VertexIndex, Joint* const TheJoint, Real32 BlendAmount) { if(getWeightIndexes() == NULL) { GeoUInt32PropertyUnrecPtr Indexes = GeoUInt32Property::create(); setWeightIndexes(Indexes); } if(getWeights() == NULL) { GeoVec1fPropertyUnrecPtr Weights = GeoVec1fProperty::create(); setWeights(Weights); } Int32 JointIndex(getMFInternalJoints()->findIndex(TheJoint)); if(JointIndex < 0) { SFATAL << "Cannot add weight for joint, because that joint is not connected." << std::endl; return; } //Vertex Index getWeightIndexes()->push_back(VertexIndex); //Joint Index getWeightIndexes()->push_back(JointIndex); //Weight Index getWeightIndexes()->push_back(getWeights()->getSize()); getWeights()->push_back(Pnt1f(BlendAmount)); }
Neuron::Neuron( int num, double *in_weights, int num_weights ) { if( config == NULL ) DataCollector::debug << "Neuron::config is NULL." << endline; init( num ); setWeights( in_weights, num_weights ); }
NeuralLayer::NeuralLayer(int inputLength, int outputLength) { setInputLength(inputLength); setOutputLength(outputLength); setThreshhold(0); setWeights(QVector<int>(inputLength_ * outputLength_)); }
void Adaline::setInputSize(int n) { if(n != (int) weights.size()){ setWeights(getRandomValues((int)n)); setThreshold(getRandomValues(1)[0]); }else{ qWarning("No se realizo cambio alguno porque el numero de entradas no vario"); } }
/** * Manipulate the particles including samples and their weights */ void BFilterCUDA::setParticles(fmat newSamples,frowvec newWeights) { nthr = (unsigned int)floor(((float)nthr/number)*newSamples.n_cols); number = newSamples.n_cols; if (number != newWeights.n_cols) { perror("number of particles and weights is inconsistent!"); return; } setSamples(newSamples); setWeights(newWeights); }
void Adaline::init(const vector<double> &weights, TransferFunctionType tf) { size_t sWeights = weights.size(); if(sWeights > 0){ setWeights(weights); setAlfa(1); setThreshold(getRandomValues(1)[0]); setTransferFunction(tf); }else{ qWarning() << "Se debe asignar al menos una entrada a un perceptron simple"; } }
void updateWeights(Array tValues, float eta, float a){ errors = computeErrors(tValues); oGrads = computeOutputGradients(tValues); hGrads = computeHiddenGradients(); Array hiddenDeltas = computeHiddenDeltas(eta, a); Array outputDeltas = computeOutputDeltas(eta, a); Array deltas = combine(hiddenDeltas, outputDeltas); Array weights = getWeights(); for(int i = 0; i < weights.size(); i++){ weights[i] += deltas[i]; } setWeights(weights); }
void CGradientUpdateFunction::loadData(FILE *stream) { double *parameters = new double[getNumWeights()]; int bufNumParam; fscanf(stream, "Gradient Function\n"); fscanf(stream, "Parameters: %d\n", &bufNumParam); assert(bufNumParam == getNumWeights()); for (int i = 0; i < getNumWeights(); i ++) { fscanf(stream, "%lf ", ¶meters[i]); } fscanf(stream, "\n"); setWeights(parameters); delete [] parameters; }
SN_Priority::SN_Priority(SN_BaseWidget *w, QObject *parent) : QObject(parent) , _priority(-1) , _Pvisual(-1) , _Pinteract(-1) , _Ptemp(0) , _weight_visual(1.0) , _weight_interact(10.0) , _weight_temp(0.0) , _timeLastIntr(0) , _timeFirstIntr(QDateTime::currentMSecsSinceEpoch()) , _intrCounter(0) , _intrCounterPrev(0) , _widget(w) , _priorityGrid(0) , _evr_to_win(0.0) , _evr_to_wall(0) , _ipm(0) { setWeights(1.0, 10.0, 0); // default values }
NMPC::NMPC(bool position_control, int num_steps, const ReferenceInterpolation &reference_interpolation) :position_control_(position_control), num_steps_(num_steps), reference_interpolation_(reference_interpolation), running_weights_(base::MatrixXd::Identity(kNumOutputs, kNumOutputs)), terminal_weights_(base::MatrixXd::Identity(kNumOutputsN, kNumOutputsN)), control_derivative_(base::Vector6d::Zero()), elapsed_time_(0) { if (num_steps_ <= 0) throw std::runtime_error("The number of steps should be a positive " "value."); // Initialize the solver acado_initializeSolver(); // Initialize the control for (int i = 0; i < kNumControls * kHorizon; ++i) acadoVariables.u[ i ] = 0.0; // Initialize the states for (int i = 0; i < kNumDiffStates * (kHorizon + 1); ++i) acadoVariables.x[ i ] = 0.0; // Initialize the measurements/reference for (int i = 0; i < kNumOutputs * kHorizon; i++) acadoVariables.y[ i ] = 0.0; acadoVariables.yN[ 0 ] = 0.0; // Initialize the current state feedback for (int i = 0; i < kNumDiffStates; ++i) acadoVariables.x0[ i ] = 0.0; setWeights(running_weights_, terminal_weights_); }
// Given connections between nodes set minimum distance from nodeI void Foam::router::setWeights ( const label weight, const label nodeI ) { // Set weight at current node weights_[nodeI] = weight; const labelList& myNeighbours = connections_[nodeI]; forAll(myNeighbours, neighbourI) { if (weights_[myNeighbours[neighbourI]] > weight + 1) { // Distribute weight+1 to neighbours setWeights ( weight+1, myNeighbours[neighbourI] ); } } }
neuron::neuron(const vector<float>& WeightVector, const float& BiasNumber) //constructor 1 { setWeights(WeightVector); //gives provided parameters to the class setNumberOfInputs(Weights.size()); setBias(BiasNumber); }
std::shared_ptr<ClientPool> PoolFactory::parsePool(const std::string& name, const folly::dynamic& json) { auto seenPoolIt = pools_.find(name); if (seenPoolIt != pools_.end()) { return seenPoolIt->second; } if (json.isString()) { // get the pool from ConfigApi std::string jsonStr; checkLogic(configApi_.get(ConfigType::Pool, name, jsonStr), "Can not read pool: {}", name); return parsePool(name, parseJsonString(jsonStr)); } else { // one day we may add inheriting from local pool if (auto jinherit = json.get_ptr("inherit")) { checkLogic(jinherit->isString(), "Pool {}: inherit is not a string", name); auto path = jinherit->stringPiece().str(); std::string jsonStr; checkLogic(configApi_.get(ConfigType::Pool, path, jsonStr), "Can not read pool from: {}", path); auto newJson = parseJsonString(jsonStr); for (auto& it : json.items()) { newJson.insert(it.first, it.second); } newJson.erase("inherit"); return parsePool(name, newJson); } } // pool_locality std::chrono::milliseconds timeout{opts_.server_timeout_ms}; if (auto jlocality = json.get_ptr("pool_locality")) { if (!jlocality->isString()) { MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig, "Pool {}: pool_locality is not a string", name); } else { auto str = jlocality->stringPiece(); if (str == "cluster") { if (opts_.cluster_pools_timeout_ms != 0) { timeout = std::chrono::milliseconds(opts_.cluster_pools_timeout_ms); } } else if (str == "region") { if (opts_.regional_pools_timeout_ms != 0) { timeout = std::chrono::milliseconds(opts_.regional_pools_timeout_ms); } } else { MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig, "Pool {}: '{}' pool locality is not supported", name, str); } } } // region & cluster std::string region, cluster; if (auto jregion = json.get_ptr("region")) { if (!jregion->isString()) { MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig, "Pool {}: pool_region is not a string", name); } else { region = jregion->stringPiece().str(); } } if (auto jcluster = json.get_ptr("cluster")) { if (!jcluster->isString()) { MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig, "Pool {}: pool_cluster is not a string", name); } else { cluster = jcluster->stringPiece().str(); } } if (auto jtimeout = json.get_ptr("server_timeout")) { if (!jtimeout->isInt()) { MC_LOG_FAILURE(opts_, memcache::failure::Category::kInvalidConfig, "Pool {}: server_timeout is not an int", name); } else { timeout = std::chrono::milliseconds(jtimeout->getInt()); } } if (!region.empty() && !cluster.empty()) { auto& route = opts_.default_route; if (region == route.getRegion() && cluster == route.getCluster()) { if (opts_.within_cluster_timeout_ms != 0) { timeout = std::chrono::milliseconds(opts_.within_cluster_timeout_ms); } } else if (region == route.getRegion()) { if (opts_.cross_cluster_timeout_ms != 0) { timeout = std::chrono::milliseconds(opts_.cross_cluster_timeout_ms); } } else { if (opts_.cross_region_timeout_ms != 0) { timeout = std::chrono::milliseconds(opts_.cross_region_timeout_ms); } } } auto protocol = parseProtocol(json, mc_ascii_protocol); bool keep_routing_prefix = false; if (auto jkeep_routing_prefix = json.get_ptr("keep_routing_prefix")) { checkLogic(jkeep_routing_prefix->isBool(), "Pool {}: keep_routing_prefix is not a bool"); keep_routing_prefix = jkeep_routing_prefix->getBool(); } uint64_t qosClass = opts_.default_qos_class; uint64_t qosPath = opts_.default_qos_path; if (auto jqos = json.get_ptr("qos")) { parseQos(folly::sformat("Pool {}", name), *jqos, qosClass, qosPath); } bool useSsl = false; if (auto juseSsl = json.get_ptr("use_ssl")) { checkLogic(juseSsl->isBool(), "Pool {}: use_ssl is not a bool", name); useSsl = juseSsl->getBool(); } // servers auto jservers = json.get_ptr("servers"); checkLogic(jservers, "Pool {}: servers not found", name); checkLogic(jservers->isArray(), "Pool {}: servers is not an array", name); auto clientPool = std::make_shared<ClientPool>(name); for (size_t i = 0; i < jservers->size(); ++i) { const auto& server = jservers->at(i); std::shared_ptr<AccessPoint> ap; bool serverUseSsl = useSsl; uint64_t serverQosClass = qosClass; uint64_t serverQosPath = qosPath; checkLogic(server.isString() || server.isObject(), "Pool {}: server #{} is not a string/object", name, i); if (server.isString()) { // we support both host:port and host:port:protocol ap = AccessPoint::create(server.stringPiece(), protocol); checkLogic(ap != nullptr, "Pool {}: invalid server {}", name, server.stringPiece()); } else { // object auto jhostname = server.get_ptr("hostname"); checkLogic(jhostname, "Pool {}: hostname not found for server #{}", name, i); checkLogic(jhostname->isString(), "Pool {}: hostname is not a string for server #{}", name, i); if (auto jqos = server.get_ptr("qos")) { parseQos(folly::sformat("Pool {}, server #{}", name, i), *jqos, qosClass, qosPath); } if (auto juseSsl = server.get_ptr("use_ssl")) { checkLogic(juseSsl->isBool(), "Pool {}: use_ssl is not a bool for server #{}", name, i); serverUseSsl = juseSsl->getBool(); } ap = AccessPoint::create(jhostname->stringPiece(), parseProtocol(server, protocol)); checkLogic(ap != nullptr, "Pool {}: invalid server #{}", name, i); } auto client = clientPool->emplaceClient( timeout, std::move(ap), keep_routing_prefix, serverUseSsl, serverQosClass, serverQosPath); clients_.push_back(std::move(client)); } // servers // weights if (auto jweights = json.get_ptr("weights")) { clientPool->setWeights(*jweights); } pools_.emplace(name, clientPool); return clientPool; }
void Adaline::randomizeWeights(double min, double max) { setWeights(getRandomValues((int)weights.size(), min, max)); threshold = getRandomValues(1, min, max)[0]; }
Pp::Pp(SEXP Argspp) { int i,j; SEXP temp; /// constants /// n = INTEGER(getListElement(Argspp, "n"))[0]; dim = INTEGER(getListElement(Argspp, "dim"))[0]; /// set-up location data /// coordinates = REAL(getListElement(Argspp, "coord")); /// parse marks //// // type mark temp = getListElement(Argspp, "type"); if(!Rf_isNull(temp)){ types = INTEGER(temp); type_given = true; }else type_given = false; // If point types given, collect them to a vector if(type_given){ int old; typevec.clear(); for(i=0;i < n ;i++) { // also attach the type to each point old = 0; for(j=0;j<(int)typevec.size();j++) if(typevec.at(j)==types[i]){ old = 1;break;} if(!old) typevec.push_back(types[i]); } ntypes = typevec.size(); }else ntypes = 1; // real valued mark temp = getListElement(Argspp,"mass"); if(!Rf_isNull(temp)){ masses = REAL(temp); mass_given = true; } else mass_given = false; /// window /// // bounding box should be always present. bbox = REAL(getListElement(Argspp, "bbox")); // area temp = getListElement(Argspp, "area"); if(Rf_isNull(temp)){ windowArea = 1.0; for(i=0; i < dim ; i++) windowArea *= bbox[1+i*2]-bbox[i*2]; }else windowArea = REAL(temp)[0]; // Precomputed window area, in case of more complicated than rectangle. // split bbox to variables for easy access xlim = new double(2); xlim[0] = bbox[0]; xlim[1] = bbox[1]; ylim = new double(2); ylim[0] = bbox[2]; ylim[1] = bbox[3]; if(dim==3){ zlim = new double(2); zlim[0] = bbox[4]; zlim[1] = bbox[5]; } /// intensities /// lambda = 0; if(ntypes > 1){ for(i=0; i < ntypes; i++) { lambdas.push_back(0.0); for(j=0; j < n; j++) if(types[j]==i+1) lambdas[i]=lambdas[i]+1.0; lambdas[i]=lambdas[i]/windowArea; lambda += lambdas[i]; } } else lambda = (double)n / windowArea; /// distance metric /// toroidal = 0; // for past. setToroidal(&toroidal); /// if distances precomputed temp = getListElement(Argspp, "pairwise_distances"); if(!Rf_isNull(temp)){ setDistances(REAL(temp)); } /// translation weights /// temp = getListElement(Argspp, "weights"); if(!Rf_isNull(temp)){ setWeights(REAL(temp)); }else pweight = &Pp::weightAll1; // edge distance temp = getListElement(Argspp, "edgeDistances"); if(!Rf_isNull(temp)){ setEdgeDistances(REAL(temp)); pedgedist = &Pp::edgeDistancePrecalculated; }else pedgedist = &Pp::computeEdgeDistance; }
void Adaline::init(int ninputs, double *weights, TransferFunctionType ft){ setWeights(ninputs, weights); setAlfa(1); setThreshold(getRandomValues(1)[0]); setTransferFunction(ft); }