void terminal_t::schedule_solve_after(const netlist_time after) { // Nets may belong to railnets which do not have a solver attached if (this->has_net()) if (net().solver() != nullptr) net().solver()->update_after(after); }
ATTR_COLD netlist_analog_output_t::netlist_analog_output_t() : netlist_output_t(OUTPUT, ANALOG) { net().m_last.Analog = 0.97; net().m_cur.Analog = 0.98; net().m_new.Analog = 0.99; }
void terminal_t::solve_now() { // Nets may belong to railnets which do not have a solver attached if (this->has_net()) if (net().solver() != nullptr) net().solver()->update_forced(); }
NetUdpSocket* Net::udpSocket() { //NetTcpSocket on default if if ( net().m_defaultIf == NULL ) return NULL; NetUdpSocket* pNetUdpSocket = net().m_defaultIf->udpSocket(); pNetUdpSocket->m_refs++; return pNetUdpSocket; }
/** * @return true of the net is selected. */ bool CGSegment::selected() { if ( net() != NULL ) { return net()->isSelected(); } return false; }
ATTR_COLD analog_output_t::analog_output_t(core_device_t &dev, const pstring &aname) : analog_t(OUTPUT), m_proxied_net(nullptr) { this->set_net(m_my_net); set_state(STATE_OUT); net().m_cur_Analog = NL_FCONST(0.99); analog_t::init_object(dev, aname); net().init_object(dev.netlist(), aname + ".net"); net().register_railterminal(*this); }
int main(void) { /* Read network from stdin. */ std::auto_ptr<NetType> netPointer(readNet<EdgeData>()); NetType& net = *netPointer; // Create a reference for easier handling of net. /* strength of each node and average strength */ float strengthSum=0; for (size_t i=0; i<net.size(); ++i) { std::cout << net(i).weight() << "\n"; strengthSum += net(i).weight(); } std::cerr << "\nAverage strength in the network: " << strengthSum / net.size() << "\n\n"; }
//unsigned char buffer[STATIC_ALLOCATOR_SIZE]; //StaticAllocator myAlloc(buffer, STATIC_ALLOCATOR_SIZE); int main() { //Alloc::init(&myAlloc); // DummyAgent agent; QLearningEGreedyPolicy egreedy(0.1f); NeuralNetwork net(DIM_OBSERVATIONS + DIM_ACTIONS, N_HIDDEN, 1, 0.1f); QLearningAgent agent(&net, DIM_OBSERVATIONS, DIM_ACTIONS, N_ACTIONS, 1.0f, 0.1f, &egreedy, false); // lambda = 1.0 => no history LibMapperEnvironment env; RLQualia qualia(&agent, &env); qualia.init(); qualia.start(); for (;;) { // for (int i=0; i<10; i++) { qualia.step(); #if is_computer() printf("Current agent action: %d\n", agent.currentAction.conflated()); printf("Current environment observation: %f %f\n", (double)env.currentObservation.observations[0], (double)env.currentObservation.observations[1]); #endif } // if (myAlloc.nLeaks) // printf("WARNING: Static Allocator has leaks: %d\n", myAlloc.nLeaks); return 0; }
ATTR_COLD netlist_analog_output_t::netlist_analog_output_t() : netlist_output_t(OUTPUT, ANALOG), m_proxied_net(NULL) { this->set_net(m_my_net); net().as_analog().m_cur_Analog = 0.98; }
QString process_socket_file(const QString &filename, QString *symlink, int sock, F fp) { Q_ASSERT(symlink); QFile net(filename); net.open(QIODevice::ReadOnly | QIODevice::Text); if(net.isOpen()) { QTextStream in(&net); QString line; // ditch first line, it is just table headings in.readLine(); // read in the first line we care about line = in.readLine(); // a null string means end of file (but not an empty string!) while(!line.isNull()) { QString lline(line); const QStringList lst = lline.replace(":", " ").split(" ", QString::SkipEmptyParts); if(fp(symlink, sock, lst)) { break; } line = in.readLine(); } } return *symlink; }
int main(int argc, char* argv[]) { struct MarsiliArgs args; readMarsiliArgs(args, argc, argv); RandNumGen<> generator(args.randseed); _NetType net(args.netSize); //time_t starttime = time(NULL); // Generate the network Marsili(net, args, generator); //time_t endtime = time(NULL); //std::cerr << "Time taken by generation: " << difftime(endtime, starttime) << " s\n"; std::auto_ptr<_NetType> netPointer2(findLargestComponent<_NetType>(net)); _NetType& net2 = *netPointer2; // Create a reference for easier handling of net. double avg_clust = 0; for (size_t i = 0; i < net2.size(); i++) avg_clust += clusteringCoefficient(net2, i); size_t edges = numberOfEdges(net2); std::cout << net2.size() << " " << (double)2*edges/net2.size() << " " << avg_clust/net2.size() << " " << pearsonCoeff2(net2) << "\n"; }
/* Run a regular ring network test, but with an additional variable-sized * population of unconnected neurons of a different type. * * The additional Poisson source neurons should not have any effect on the * simulation but should expose errors related to mixing local/global partition * indices. */ void testNeuronTypeMixture(backend_t backend, unsigned szOthers, bool izFirst) { const unsigned szRing = 1024; boost::scoped_ptr<nemo::Network> net(new nemo::Network()); if(izFirst) { createRing(net.get(), szRing); } unsigned poisson = net->addNeuronType("PoissonSource"); float p = 0.001f; for(unsigned n=szRing; n<szRing+szOthers; ++n) { net->addNeuron(poisson, n, 1, &p); } if(!izFirst) { createRing(net.get(), szRing); } nemo::Configuration conf = configuration(false, 1024, backend); boost::scoped_ptr<nemo::Simulation> sim; BOOST_REQUIRE_NO_THROW(sim.reset(nemo::simulation(*net, conf))); /* Stimulate a single neuron to get the ring going */ sim->step(std::vector<unsigned>(1, 0)); const unsigned duration = 1000; for(unsigned ms=1; ms < duration; ++ms) { std::vector<unsigned> fired = sim->step(); BOOST_REQUIRE(fired.size() > 0); std::sort(fired.begin(), fired.end()); BOOST_REQUIRE_EQUAL(fired[0], ms % szRing); if(fired.size() > 1) { BOOST_REQUIRE(fired[1] >= szRing); } } }
int main() { // Construct Network Network net("name", Network::Undirected); net.populate(10000); net.erdos_renyi(5); cout << "days_ahead" << "," << "transmissibility1" << "," << "transmissibility2" << "," << "strain1" << "," << "strain2" << endl; for (int days_ahead = 0; days_ahead < 20; days_ahead ++){ for (double transmissibility1 = 0.2; transmissibility1 <= 0.5; transmissibility1 += 0.05){ for (double transmissibility2 = 0.2; transmissibility2 <= 0.5; transmissibility2 += 0.05){ int i = 0; while ( i < 100){ // Choose and run simulation Two_Strain_Percolation_Sim sim(&net); sim.set_transmissibility1(transmissibility1); sim.set_transmissibility2(transmissibility2); sim.rand_infect(5, 0); sim.run_headstart_simulation(days_ahead, 5); if(sim.epidemic_size1() > 50){ cout << days_ahead << "," << transmissibility1 << "," << transmissibility2 << "," << sim.epidemic_size1() << "," << sim.epidemic_size2() << endl; i++; } sim.reset(); } } } } return 0; }
void Daemon::join( InputMessage &message, Channel channel ) { NOTE(); OutputMessage response( MessageType::Control ); int peerId; std::string peerName; message >> peerId >> peerName; channel->receive( message ); if ( _state != State::FormingGroup ) { response.tag( Code::Refuse ); channel->send( response ); return; } response.tag( Code::OK ); channel->send( response ); std::string address( net().peerAddress( *channel ) ); Line peer = std::make_shared< Peer >( peerId, std::move( peerName ), address.c_str(), std::move( channel ) ); connections().lockedInsert( peerId, std::move( peer ) ); }
network user_settings_io::read_network_from_yaml(const YAML::Node& node) { const YAML::Node& nodes = node[usc::nodes]; const std::size_t size = nodes.size(); network net(size); node_positions_type node_positions; for(std::size_t i = 0; i < size; ++i) { const point_type& position = nodes[i].as<point_type>(); net.set_node_position(i, position); node_positions.push_back(position); } settings_.set_node_positions(node_positions); if(node[usc::links]) { std::vector<std::pair<std::size_t, std::size_t>> links; const YAML::Node& links_node = node[usc::links]; for(std::size_t i = 0; i < links_node.size(); ++i) { std::pair<std::size_t, std::size_t> link = links_node[i].as<std::pair<std::size_t, std::size_t>>(); links.push_back(link); net.add_link(link.first, link.second); } settings_.set_links(links); } return net; }
const Error *Init( Amp &, uint16 slot, uint16 numAxes ) { CML_ASSERT( numAxes <= MAX_AXIS ); if( numAxes > MAX_AXIS ) return &AmpError::BadAxis; axisCt = numAxes; RefObjLocker<Network> net( amp.GetNetworkRef() ); if( !net ) return &NodeError::NetworkUnavailable; netRef = net->GrabRef(); const Error *err = SetType( 255 ); for( int i=0; i<numAxes; i++ ) { uint16 val; if( !err ) err = amp.Upld16( OBJID_CONTROL + 0x800*i, 0, val ); ctrl[i].Write( val ); if( !err ) err = ctrl[i].Init( OBJID_CONTROL+0x800*i, 0 ); if( !err ) err = AddVar( ctrl[i] ); } if( !err ) err = amp.PdoSet( slot, *this ); return err; }
int main(int argc, char* argv[]) { if ( argc < 4 ) { std::cerr << "\nPlease specify arguments: \n\tN, p, randseed\n\n"; exit(1); } size_t netSize = atoi(argv[1]); float p = atof(argv[2]); size_t randseed = atoi(argv[3]); RandNumGen<> generator(randseed); NetType net(netSize); // Generate the network ErdosRenyi2(net, p, generator); std::auto_ptr<NetType> netPointer2(findLargestComponent<NetType>(net)); NetType& net2 = *netPointer2; // Create a reference for easier handling of net. // Calculate average clustering coefficient double avg_clust = 0; for (size_t i = 0; i < net.size(); i++) avg_clust += clusteringCoefficient(net, i); size_t edges = numberOfEdges(net2); std::cout << net2.size() << " " << (double)2*edges/net2.size() << " " << avg_clust/net2.size() << " " << pearsonCoeff(net2) << "\n"; }
int main() { // Construct Network Network net("name", false); net.populate(10000); // Let's connect the network using an arbitrary degree distribution // Out of 10 nodes, none will have degrees 0 or 1, 1 will have degree 2 // 3 with degree 3, 2 with degree 4, 1 with degree 5, and 3 with degree 3 vector<double> degree_dist; double tmp_array[] = {0, 0, 1, 3, 2, 1, 3}; degree_dist.assign(tmp_array,tmp_array+7); // 5 == the length of tmp_array // Now make those probabilities that sum to 1 degree_dist = normalize_dist(degree_dist, sum(degree_dist)); // Finally, connect up the network using that user-defined degree distribution // Note that poisson, exponential, and scale-free random network generators are built-in net.rand_connect_user(degree_dist); // Simulation parameters int infectious_period = 10; // 10 days, hours, whatever double T = 0.05; // per timestep, per outbound edge probability of transmission for (int i = 0; i < 10; i++){ // Choose and run simulation ChainBinomial_Sim sim(&net, infectious_period, T); sim.rand_infect(1); sim.run_simulation(); cout << sim.epidemic_size() << endl; sim.reset(); } return 0; }
int main() { int inputs = 2; int outputs = 1; int depth = 3; int hidden_layer_size = 2; double learning_speed = 0.1; double momentum = 0.9; double error = 0.001; neural_network net(inputs, depth, hidden_layer_size, outputs, learning_speed, momentum); vector<pair<vector<double>, vector<double> > > tests; vector<double> test(2); vector<double> ans(1); for (int i = 0; i < 2; i++) { for (int j = 0; j < 2; j++) { test[0] = i; test[1] = j; ans[0] = (i + j) % 2; tests.push_back(make_pair(test, ans)); } } net.teach(tests, error); for (int i = 0; i < tests.size(); i++) { vector<double> ans = net.calculate(tests[i].first); printf("input: %d %d\n", (int)tests[i].first[0], (int)tests[i].first[1]); printf("output: %f\n\n", ans[0]); } return 0; }
void CttView::ADTFill(const COLORREF color){ if (m_point.size() <= 2)return; CDC* pDC = GetWindowDC(); CPen pen1(0, 0, color); pDC->SelectObject(&pen1); int start, end, msz=m_point.size(); start = 10000; end = 0; for (int i = 0; i < msz; i++){ start = min(start, m_point[i].y); end = max(end, m_point[i].y); } vector<EdgeTable> net(end+1); net.assign(end + 1, EdgeTable()); Edge te; int miny; for (int i = 0; i < msz-1; i++){ te = Edge(m_point[i], m_point[i + 1], miny); net[miny].Add(te); } te = Edge(m_point[msz-1], m_point[0], miny); net[miny].Add(te); EdgeTable adt = EdgeTable(start); for (int i = start; i <= end; i++){ for (int j = 0; j < net[i].e.size(); j++) adt.Add(net[i].e[j]); for (int j = 1; j < adt.e.size(); j += 2){ pDC->MoveTo((int)adt.e[j-1].x0, i); pDC->LineTo((int)adt.e[j].x0, i); } adt.Update(); } }
double lodDistanceBetweenPos(Vec2i a, Vec2i b, int blockSize) { int baseBlockSize = 8; Vec2i net(a.x-b.x, a.y-b.y); return std::sqrt(net.x*net.x + net.y*net.y) * blockSize / baseBlockSize; }
void testCurrentStimulus(backend_t backend) { unsigned ncount = 1500; unsigned duration = ncount * 2; nemo::Configuration conf = configuration(false, 1024, backend); boost::scoped_ptr<nemo::Network> net(createRing(ncount)); boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf)); nemo::Simulation::current_stimulus istim; // add some noise before and after istim.push_back(std::make_pair(5U, 0.001f)); istim.push_back(std::make_pair(8U, 0.001f)); istim.push_back(std::make_pair(0U, 1000.0f)); istim.push_back(std::make_pair(100U, 0.001f)); istim.push_back(std::make_pair(1U, 0.001f)); /* Simulate a single neuron to get the ring going */ sim->step(istim); for(unsigned ms=1; ms < duration; ++ms) { const std::vector<unsigned>& fired = sim->step(); BOOST_CHECK_EQUAL(fired.size(), 1U); BOOST_REQUIRE_EQUAL(fired.front(), ms % ncount); } }
NetworkType Node::GetNetworkType( void ) { RefObjLocker<Network> net( GetNetworkRef() ); if( !net ) return NET_TYPE_INVALID; return net->GetNetworkType(); }
BaseBulkRound::BaseBulkRound(const Group &group, const PrivateIdentity &ident, const Id &round_id, const QSharedPointer<Network> &network, GetDataCallback &get_data, const QSharedPointer<BuddyMonitor> &bm, CreateRound create_shuffle) : Round(group, ident, round_id, network, get_data, bm), _get_shuffle_data(this, &BaseBulkRound::GetShuffleData) { QVariantHash headers = GetNetwork()->GetHeaders(); headers["bulk"] = true; GetNetwork()->SetHeaders(headers); QSharedPointer<Network> net(GetNetwork()->Clone()); headers["bulk"] = false; net->SetHeaders(headers); Id sr_id(Hash().ComputeHash(GetRoundId().GetByteArray())); _shuffle_round = create_shuffle(GetGroup(), GetPrivateIdentity(), sr_id, net, _get_shuffle_data, bm); _shuffle_round->SetSink(&_shuffle_sink); QObject::connect(_shuffle_round.data(), SIGNAL(Finished()), this, SLOT(SlotShuffleFinished())); }
int main() { MTRand mtrand = MTRand(); for (int i = 0; i < 20; i++ ) { cout << i << endl; Network net("test", false ); net.populate(N_NODES); //cout << net.size() << " "; //net.erdos_renyi(4); net.rand_connect_poisson(10); // sleep(5); //cout << net.mean_deg() << endl; //cout << net.transitivity(net.get_nodes()) << endl; //vector<Node*> comp = net.get_major_component(); //cout << comp.size() << endl; //net.graphviz(""); /* vector<Node*> my_nodes = net.get_nodes(); my_nodes[1] = my_nodes[2]; vector<Node*> your_nodes = net.get_nodes(); if (my_nodes[1] == your_nodes[2]) cerr << "Yikes!!\n"; for (int i = 0; i < N_NODES; i++) { net.get_node(i)->mean_min_path(); cout << i << " mean dist: " << setprecision(10) << net.get_node(i)->mean_min_path() << endl; vector<int> distances = net.get_node(i)->min_paths(); cout << i << " to 1 " << distances[1] << endl; }*/ } return 0; }
const Error *Amp::RequestStatUpdt( void ) { // For secondary axis objects, do this through the primary axis if( primaryAmpRef ) { RefObjLocker<Amp> pri( primaryAmpRef ); if( !pri ) return &AmpError::NotInit; return pri->RequestStatUpdt(); } // Note that 8367 based products don't support remote // requests well, so we use an SDO to request the PDO if( (hwType & 0xFF00) != 0x0300 ) { RefObjLocker<Network> net( GetNetworkRef() ); if( !net ) return &NodeError::NetworkUnavailable; if( !statPDO ) return &AmpError::NotInit; return statPDO->Request(*net); } else return Dnld8( OBJID_PDOREQUEST, 0, (uint8)0 ); }
void runRing(backend_t backend, unsigned ncount, unsigned delay) { /* Make sure we go around the ring at least a couple of times */ const unsigned duration = ncount * 5 / 2; nemo::Configuration conf = configuration(false, 1024); setBackend(backend, conf); boost::scoped_ptr<nemo::Network> net(createRing(ncount, 0, false, 1, delay)); boost::scoped_ptr<nemo::Simulation> sim(nemo::simulation(*net, conf)); /* Stimulate a single neuron to get the ring going */ sim->step(std::vector<unsigned>(1, 0)); for(unsigned ms=1; ms < duration; ++ms) { const std::vector<unsigned>& fired = sim->step(); if(delay == 1) { BOOST_CHECK_EQUAL(fired.size(), 1U); BOOST_REQUIRE_EQUAL(fired.front(), ms % ncount); } else if(ms % delay == 0) { BOOST_CHECK_EQUAL(fired.size(), 1U); BOOST_REQUIRE_EQUAL(fired.front(), (ms / delay) % ncount); } else { BOOST_CHECK_EQUAL(fired.size(), 0U); } } }
void MainWindow::fileNew() { if (_sdata) if (!_sdata->isSaved()) maybeSave(); fileClose(); // if project exist, // if not saved, //maybe save? // close // run wizard QMdiSubWindow * world = _mdiArea->addSubWindow(new WorldWidget()); world->setWindowTitle("*untitled"); world->setMinimumSize(300, 200); world->show(); _sdata = new SimulationData(); _sdata->setSaved(false); connect(_sdata, SIGNAL(fileNameChanged(QString)), world, SLOT(setWindowTitle(QString))); SensorNetwork net(40); net.push(); net.start(); _fileSaveAsAct->setEnabled(true); _fileCloseAct->setEnabled(true); }
int main(int argc, char** argv) { QCoreApplication app(argc, argv); QHostAddress dest_addr; unsigned int fft_send_interval = 1024; if (argc > 1) { QHostInfo host_info = QHostInfo::fromName(argv[1]); if (host_info.error() != QHostInfo::NoError || host_info.addresses().empty()) { qFatal("Could not resolve host: %s: %s", argv[1], host_info.errorString().toUtf8().constData()); exit(1); } dest_addr = host_info.addresses().first(); // Increase the FFT send interval when sending data over the network fft_send_interval *= 4; } else { dest_addr = QHostAddress::LocalHost; } qDebug() << "Sending FFT data to" << dest_addr << "port" << TRANSMIT_PORT << "interval" << fft_send_interval; JackClient jc(fft_send_interval); Networking net(dest_addr, TRANSMIT_PORT); QObject::connect(&jc, SIGNAL(onset_detected()), &net, SLOT(transmit_onset())); QObject::connect(&jc, SIGNAL(fft_data(int, float*)), &net, SLOT(transmit_fft_data(int, float*))); QObject::connect(&jc, SIGNAL(pitch_data(float,float)), &net, SLOT(transmit_pitch_data(float,float))); return app.exec(); }
/* Make sure that calling applyStdp gives an error */ void testInvalidStdpUsage(backend_t backend) { boost::scoped_ptr<nemo::Network> net(createRing(10, 0, true)); nemo::Configuration conf; setBackend(backend, conf); BOOST_REQUIRE_THROW(simpleStdpRun(*net, conf), nemo::exception); }