コード例 #1
0
ファイル: main.c プロジェクト: mmlind/mnist-3lnn
int main(int argc, const char * argv[]) {
    
    // remember the time in order to calculate processing time at the end
    time_t startTime = time(NULL);
    
    // clear screen of terminal window
    clearScreen();
    printf("    MNIST-3LNN: a simple 3-layer neural network processing the MNIST handwritten digit images\n\n");
    
    // Create neural network using a manually allocated memory space
    Network *nn = createNetwork(MNIST_IMG_HEIGHT*MNIST_IMG_WIDTH, 20, 10);
    
//    displayNetworkWeightsForDebugging(nn);
//    exit(1);
    
    // Training the network by adjusting the weights based on error using the  TRAINING dataset
    trainNetwork(nn);
    
    // Testing the during training derived network using the TESTING dataset
    testNetwork(nn);
    
    // Free the manually allocated memory for this network
    free(nn);
    
    locateCursor(36, 5);
    
    // Calculate and print the program's total execution time
    time_t endTime = time(NULL);
    double executionTime = difftime(endTime, startTime);
    printf("\n    DONE! Total execution time: %.1f sec\n\n",executionTime);

    return 0;
}
コード例 #2
0
MarOscInWindow::MarOscInWindow(string fileName)
{
	QWidget *w = new QWidget;
	setCentralWidget(w);

	QLabel  *gainLabel1  = new QLabel("gain");
	gainSlider_ = new QSlider(Qt::Horizontal);

	gainSlider_->setValue(100);

	createNetwork();

	QGridLayout *gridLayout = new QGridLayout;

	gridLayout->addWidget(gainLabel1, 2, 1);
	gridLayout->addWidget(gainSlider_, 3, 1);

	connect(gainSlider_, SIGNAL(valueChanged(int)), this, SLOT(gainChanged(int)));

	w->setLayout(gridLayout);

	startNetwork();

 	cout << "Playing file=(" << fileName << ")" << endl;
 	play(fileName);

}
コード例 #3
0
ファイル: BPNet.cpp プロジェクト: gpertzov/BPNet
//====================================================================
// Load network from file
//====================================================================
bool BPNet::load( ifstream &ist )
{
	if ( !ist.good() )
		return false;
	
	int numLayers	= 0;
	int numNodes	= 0;
	int numLinks	= 0;

	ist >> numLayers;	// num layers
	
	vector<int> layers(numLayers);
	for(int i = 0; i != numLayers; ++i)
		ist >> layers[i];	// number of nodes in each layer

	ist >> numNodes;
	ist >> numLinks;

	// create network structure (nodes and links)
	createNetwork(0, 0, layers);
	
	// load nodes data
	for (i = 0; i != numNodes; ++i)
		_nodes[i]->load(ist);

	// load links data
	for(i = 0; i != numLinks; ++i)
		_links[i]->load(ist);


	if (!ist.good())
		return false;

	return true;
}
コード例 #4
0
	void EmbedderOptimalFlexDraw::optimizeOverEmbeddings(
		StaticPlanarSPQRTree &T,
		node parent,
		node mu,
		int bends,
		NodeArray<int> cost[],
		NodeArray<long long> embedding[])
	{
		cost[bends][mu] = numeric_limits<int>::max();
		long long embeddingsCount = T.numberOfNodeEmbeddings(mu);
		for (long long currentEmbedding = 0; currentEmbedding < embeddingsCount; ++currentEmbedding) {

			T.embed(mu, currentEmbedding);

			Skeleton &skeleton = T.skeleton(mu);
			Graph skeletonGraph = skeleton.getGraph();
			ConstCombinatorialEmbedding skeletonEmbedding(skeletonGraph);
			NodeArray<node> vertexNode(skeletonGraph);
			EdgeArray<node> edgeNode(skeletonGraph);
			FaceArray<node> faceNode(skeletonEmbedding);

			Graph N;
			EdgeArray<int> upper(N);
			EdgeArray<int> perUnitCost(N);
			NodeArray<int> supply(N);

			createNetwork(
				parent,
				mu,
				bends,
				cost,
				embedding,
				skeleton,
				edgeNode,
				N,
				upper,
				perUnitCost,
				supply);

			EdgeArray<int> lower(N, 0);
			EdgeArray<int> flow(N);
			NodeArray<int> dual(N);

			m_minCostFlowComputer.get().call(N, lower, upper, perUnitCost, supply, flow, dual);

			int currentCost = 0;
			for (edge e = N.firstEdge(); e != nullptr; e = e->succ())
				currentCost += perUnitCost[e] * flow[e];

			for (adjEntry adj = mu->firstAdj(); adj != nullptr; adj = adj->succ())
				currentCost += cost[0][adj->twinNode()];

			if (currentCost < cost[bends][mu]) {
				cost[bends][mu] = currentCost;
				embedding[bends][mu] = currentEmbedding;
			}
		}
	}
コード例 #5
0
ファイル: main.cpp プロジェクト: Dewb/moody
int main()
{
    int width = 51 * 6; // lengths of strips
    int height = 4;
    uint8_t* buffer = (uint8_t*)malloc(width * height * 3);
    
    createNetwork(buffer, width, height);
    initEffects(width, height);
    
    while (1)
    {
        clearEffect(buffer);
        
        //runTestEffect(buffer);
        //runFlameEffect(buffer);
        runWaterfallEffect(buffer);

        applyFixups(buffer, width, height);
        
#if OSC_OUTPUT_ENABLED
        for (int ii = 0; ii < width; ii++)
        {
            for (int jj = 0; jj < height; jj++)
            {
                oscStream << osc::BeginBundleImmediate;
                oscStream << osc::BeginMessage("led");
                oscStream << ii * 3 << (height - jj - 1) * 10 << (ii + 1) * 3 << (height - jj) * 10;
                int s = (jj * width + ii) * 3;
                for (int c = 0; c < 3; c++)
                {
                    oscStream << buffer[s + c];
                }
                oscStream << osc::EndMessage;
                oscStream << osc::EndBundle;
                oscSocket.Send(oscStream.Data(), oscStream.Size());
                oscStream.Clear();
            }
        }
        
#endif
                
        for (int ii = 0; ii < supplies.size(); ii++)
        {
            supplies[ii]->go();
        }
        usleep(70);
    }
    
    free(buffer);
    return 0;
}
コード例 #6
0
ファイル: network.cpp プロジェクト: bvgastel/xmas
bool model::Network::emitNetwork(XMASNetwork &network) {

    auto &componentMap = network.getComponentMap();

    std::clock_t c_start = std::clock();
    QVariantList compList;
    for(auto &it : componentMap) {
        XMASComponent *comp = it.second;
        if (comp) {
            QVariantMap map;
            convertToQml(map, comp);
            compList.append(map);
        }
    }
    QVariantList channelList;
    for (auto &it : componentMap) {
        XMASComponent *comp = it.second;
        if (comp) {
            QVariantList list;
            connectInQml(list, comp);
            channelList.append(list);
        }
    }
    QVariantMap qmlNetwork;
    qmlNetwork["complist"] = compList;
    qmlNetwork["channellist"] = channelList;    emit packetChanged();

    emit packetChanged();
    // Var is not implemented in qml yet. No known semantics for var
    //qmlNetwork["var"] = QString(network.getVar().stl().c_str());

    auto cne = network.getNetworkExtension<CompositeNetworkExtension>(false);
    if(cne){
        this->m_alias = cne->alias.c_str();
        this->m_boxedImage = cne->boxedImage;
        this->m_imageName = cne->imageName.c_str();
    }

    auto cve = network.getNetworkExtension<CanvasNetworkExtension>(false);
    if(cve){
        this->m_size = QSize(cve->width,cve->height);
    }

    emit createNetwork(qmlNetwork);
    std::clock_t c_end = std::clock();
    qDebug() << "CPU time used: " << 1000.0 * (c_end-c_start) / CLOCKS_PER_SEC << " ms"
             << " for " << compList.length() << " components and " << channelList.length() << " channels";

    return true;
}
コード例 #7
0
      std::shared_ptr<consensus::yac::Yac> YacInit::createYac(std::string network_address,
                                                              std::shared_ptr<
                                                                  uvw::Loop> loop,
                                                              ClusterOrdering initial_order) {
        uint64_t delay_seconds = 5;

        return Yac::create(YacVoteStorage(),
                           createNetwork(std::move(network_address),
                                         initial_order.getPeers()),
                           createCryptoProvider(),
                           createTimer(std::move(loop)),
                           initial_order,
                           delay_seconds * 1000);

      }
コード例 #8
0
ファイル: BPNet.cpp プロジェクト: gpertzov/BPNet
BPNet::BPNet( double lr, double mt, int layers, ... )
{
	va_list vl;

	// construct layers vector according to argument list
	va_start(vl, layers );

	vector<int> layersVec(layers);
	for (int i = 0; i != layers; ++i)
		layersVec[i] = va_arg(vl, int);

	va_end( vl );

	// create network
	createNetwork( lr, mt, layersVec);
}
コード例 #9
0
ファイル: NUbot.cpp プロジェクト: BuddenD/robocup
/*! @brief Constructor for the nubot
    
    The parameters are for command line arguements. Webots gives the binary arguements which tell us the 
    robot's number. Consequently, these args are passed down to the webots platform.
 
    @param argc the number of command line arguements
    @param *argv[] the array of command line arguements
 */
NUbot::NUbot(int argc, const char *argv[])
{
    #if DEBUG_NUBOT_VERBOSITY > 0
        debug << "NUbot::NUbot()." << endl;
    #endif
    NUbot::m_this = this;
    
    createErrorHandling();
    createPlatform(argc, argv);
    createBlackboard();
    createNetwork();
    createModules();
    createThreads();
    
    #if DEBUG_NUBOT_VERBOSITY > 0
        debug << "NUbot::NUbot(). Finished." << endl;
    #endif
}
コード例 #10
0
MarOscMultiGainWindow::MarOscMultiGainWindow(string fileName1, string fileName2, string fileName3)
{
	QWidget *w = new QWidget;
	setCentralWidget(w);

	QLabel  *gain1Label  = new QLabel(QString(fileName1.c_str()));
	gain1Slider_ = new QSlider(Qt::Horizontal);
	gain1Slider_->setValue(0);

	QLabel  *gain2Label  = new QLabel(QString(fileName2.c_str()));
	gain2Slider_ = new QSlider(Qt::Horizontal);
	gain2Slider_->setValue(0);

	QLabel  *gain3Label  = new QLabel(QString(fileName3.c_str()));
	gain3Slider_ = new QSlider(Qt::Horizontal);
	gain3Slider_->setValue(0);

	createNetwork(fileName1,fileName2,fileName3);

	QGridLayout *gridLayout = new QGridLayout;

	gridLayout->addWidget(gain1Label, 1, 1);
	gridLayout->addWidget(gain1Slider_, 2, 1);

	gridLayout->addWidget(gain2Label, 3, 1);
	gridLayout->addWidget(gain2Slider_, 4, 1);

	gridLayout->addWidget(gain3Label, 5, 1);
	gridLayout->addWidget(gain3Slider_, 6, 1);

	connect(gain1Slider_, SIGNAL(valueChanged(int)), this, SLOT(gain1Changed(int)));
	connect(gain2Slider_, SIGNAL(valueChanged(int)), this, SLOT(gain2Changed(int)));
	connect(gain3Slider_, SIGNAL(valueChanged(int)), this, SLOT(gain3Changed(int)));

	w->setLayout(gridLayout);

// 	startNetwork();

 	cout << "Playing files=(" << fileName1 << ")" << "(" << fileName2 << ")" << "(" << fileName3 << ")" << endl;
	play(fileName1,fileName2,fileName3);

}
コード例 #11
0
ファイル: simulator.cpp プロジェクト: yissac/project2
void Simulator::initializeNetwork(std::map<int,MechanicalNode*>* inMap)
{
    if (!timerID)
        killTimer(timerID);

    nodeMap.clear();
    edgeVec.clear();
    graphicalObjects.clear();

    network = inMap;

    xRot = yRot = zRot = 0;
    zHomeView = -40;
    timerID = startTimer(20);

    createNetwork();

    if (!timerID)
        updateGL();
}
コード例 #12
0
/* private slots */
void NetControlThread::run()
{
    Result result;
    switch (task.action) {
    case GET_ALL_ENTITY_STATE :
        result = getAllNetworkList();
        break;
    case CREATE_ENTITY :
        result = createNetwork();
        break;
    case DEFINE_ENTITY :
        result = defineNetwork();
        break;
    case START_ENTITY :
        result = startNetwork();
        break;
    case DESTROY_ENTITY :
        result = destroyNetwork();
        break;
    case UNDEFINE_ENTITY :
        result = undefineNetwork();
        break;
    case CHANGE_ENTITY_AUTOSTART :
        result = changeAutoStartNetwork();
        break;
    case GET_XML_DESCRIPTION :
        result = getVirtNetXMLDesc();
        break;
    default:
        break;
    };
    // task.srcConnPtr reference will closed in destructor as ptr_ConnPtr
    //virConnectClose(*task.srcConnPtr);
    result.type   = "network";
    result.number = number;
    result.action = task.action;
    emit resultData(result);
}
コード例 #13
0
ファイル: neurk.cpp プロジェクト: juliendehos/neurk
void Network::createMultiLayer(int M, int N, double weight, double parameter)
{
    int nbNeurons = (M+N)*(M-N+1)/2;
    createNetwork(nbNeurons);
    
    // init neurons
    _neuronParameters.fill(parameter);

    // init synapses
    // for all layer
    for (int i=M,k=0; i>N; i--)
    {
        // select a neuron of this main layer
        for (int j=0; j<i; j++)
        {
            // add synapses from neurons of the main layer to all neurons of the sub-layer
            for (int l=0; l<i-1; l++)
            {
                initSynapse(k+j, k+i+l, weight);
            }
        }
        k += i;
    }

    // input neurons
    for (int i=0; i<M; i++)
    {
        addInput(i);
    }

    // output neurons
    for (int i=0; i<N; i++)
    {
        addOutput(nbNeurons - N + i);
    }
}
コード例 #14
0
ファイル: main.c プロジェクト: Thib0/QWERTYUP
int main (int argc, char* argv[])
{
    if (argc == 1)
    {
        srand(time(NULL));

        struct neural_network *network = createNetwork(3, 3, 2);

        int loopCount = 0, count = 1, proceed = 0;
        double out00, out01, out10, out11;
        do
        {
            do
            {
                loopCount++;
                setInput(1,1, network);
                out11 = getOutput(network);
                learn(network, 0);
                setInput(0,0, network);
                out00 = getOutput(network);
                learn(network, 0);
                setInput(0,1,network);
                out01 = getOutput(network);
                learn(network, 1);
                setInput(1,0, network);
                out10 = getOutput(network);
                learn(network, 1);

                printf("0xor0: %f 0xor1: %f 1xor0: %f 1xor1: %f\n",out00, out01,
                        out10, out11);

            }while ((out00 > 0.05 || out01 < 0.95 || out10 < 0.95 ||
                        out11 > 0.05) && loopCount < 200000);
            proceed = loopCount == 200000;
            if(proceed)
            {
                printf("creating new network\n");
                resetWeights(network);
                printf("weights reset");
                count++;
                loopCount = 0;
            }
        }while(proceed);


        freeNetwork(network);
        printf("Network freed.\n");
        printf("Loop count : %i\n",(count - 1)*200000 + loopCount);
        printf("Everything went fine. Exiting...\n");
        _Exit(0);
    }

    else if (argc == 2)
    {
        IplImage *img = load(argv[1]);
        if(img != NULL)
        {
            const char* window_title = "Perfect Image";
            cvNamedWindow (window_title, CV_WINDOW_AUTOSIZE);
            cvShowImage (window_title, img);
            cvWaitKey(0);
            char path[] = "result.bmp";
            cvSaveImage(&path[0], img, NULL);
            cvDestroyAllWindows();
            cvReleaseImage(&img);
            printf("Everything went fine. Exiting...\n");
            return 0;
        }
        else
        {
            printf("Error loading image.\n");
            return -1;
        }
    }
    else
    {
        printf("Argument issue. Exiting...\n");
        return -1;
    }

}
コード例 #15
0
MarLpcWindow::MarLpcWindow()
{
	frequencyPole_ = 0;
	amplitudePole_ = .85;

	QWidget *w = new QWidget;
	setCentralWidget(w);

	createActions();
	createMenus();  

	QLabel  *breathinessLabel  = new QLabel("breathiness");
	breathinessSlider_ = new QSlider(Qt::Horizontal);

	QLabel  *cutOffLabel  = new QLabel("cutOff");
	QSlider *cutOffSlider = new QSlider(Qt::Horizontal);

	QLabel  *frequencyPoleLabel1  = new QLabel("frequencyPole");
	QLabel  *frequencyPoleLabel2  = new QLabel("frequencyPole");
	frequencyPoleSlider_ = new QSlider(Qt::Horizontal);

	QLabel  *amplitudePoleLabel1  = new QLabel("amplitudePole");
	QLabel  *amplitudePoleLabel2  = new QLabel("amplitudePole");
	amplitudePoleSlider_ = new QSlider(Qt::Horizontal);

	QLabel  *tiltLabel  = new QLabel("Tilt");
	tiltSlider_ = new QSlider(Qt::Horizontal);

	QLabel *posLabel = new QLabel("Pos");
	posSlider_ = new QSlider(Qt::Horizontal);

	breathinessLabel->setMinimumWidth(150);
	cutOffLabel->setMinimumWidth(150);

	frequencyPoleSlider_->setValue(50);
	amplitudePoleSlider_->setValue(50);
	tiltSlider_->setValue(50);

	createNetwork();

	QGridLayout *gridLayout = new QGridLayout;

	gridLayout->addWidget(breathinessLabel, 0, 0);
	gridLayout->addWidget(breathinessSlider_, 1, 0);

	gridLayout->addWidget(tiltLabel, 0, 1);
	gridLayout->addWidget(tiltSlider_, 1, 1);

	gridLayout->addWidget(frequencyPoleLabel1, 2, 0);
	gridLayout->addWidget(frequencyPoleSlider_, 3, 0);

	gridLayout->addWidget(amplitudePoleLabel1, 2, 1);
	gridLayout->addWidget(amplitudePoleSlider_, 3, 1);

	gridLayout->addWidget(posLabel, 5, 0);
	gridLayout->addWidget(posSlider_, 6, 0);
	gridLayout->addWidget(posControl_, 6, 1);

	gridLayout->addWidget(frequencyPoleControl_, 4, 0);
	gridLayout->addWidget(amplitudePoleControl_, 4, 1);

	connect(breathinessSlider_, SIGNAL(valueChanged(int)), this, SLOT(breathinessChanged(int)));
	connect(cutOffSlider, SIGNAL(valueChanged(int)), this, SLOT(cutOffChanged(int)));
	connect(frequencyPoleSlider_, SIGNAL(valueChanged(int)), this, SLOT(frequencyPoleChanged(int)));
	connect(amplitudePoleSlider_, SIGNAL(valueChanged(int)), this, SLOT(amplitudePoleChanged(int)));
	connect(tiltSlider_, SIGNAL(valueChanged(int)), this, SLOT(tiltChanged(int)));
	connect(posSlider_, SIGNAL(sliderReleased()), this, SLOT(posChanged()));

	connect(mwr_, SIGNAL(ctrlChanged(MarControlPtr)), this, SLOT(ctrlChanged(MarControlPtr)));

	w->setLayout(gridLayout);

	startNetwork();
}
コード例 #16
0
	void EmbedderOptimalFlexDraw::call(Graph &G, adjEntry &adjExternal)
	{
		StaticPlanarSPQRTree T(G);

		NodeArray<int> cost[4];
		NodeArray<long long> embedding[4];
		for (int bends = 0; bends < 4; ++bends) {
			cost[bends].init(T.tree());
			embedding[bends].init(T.tree());
		}

		int minCost = numeric_limits<int>::max();
		node minCostRoot;
		long long minCostEmbedding;

		for (node root = T.tree().firstNode(); root != nullptr; root = root->succ()) {

			T.rootTreeAt(root);

			for (adjEntry adj = root->firstAdj(); adj != nullptr; adj = adj->succ())
				computePrincipalSplitComponentCost(T, cost, embedding, root, adj->twinNode());

			optimizeOverEmbeddings(T, nullptr, root, 0, cost, embedding);

			if (cost[0][root] < minCost) {
				minCost = cost[0][root];
				minCostEmbedding = embedding[0][root];
				minCostRoot = root;
			}

		}

		T.rootTreeAt(minCostRoot);
		T.embed(minCostRoot, minCostEmbedding);

		for (adjEntry adj = minCostRoot->firstAdj(); adj != nullptr; adj = adj->succ())
			computePrincipalSplitComponentCost(T, cost, embedding, minCostRoot, adj->twinNode());

		Skeleton &skeleton = T.skeleton(minCostRoot);
		Graph skeletonGraph = skeleton.getGraph();
		ConstCombinatorialEmbedding skeletonEmbedding(skeletonGraph);
		EdgeArray<node> edgeNode(skeletonGraph);

		Graph N;
		EdgeArray<int> upper(N);
		EdgeArray<int> perUnitCost(N);
		NodeArray<int> supply(N);

		createNetwork(
			nullptr,
			minCostRoot,
			0,
			cost,
			embedding,
			skeleton,
			edgeNode,
			N,
			upper,
			perUnitCost,
			supply);

		EdgeArray<int> lower(N, 0);
		EdgeArray<int> flow(N);
		NodeArray<int> dual(N);

		m_minCostFlowComputer.get().call(N, lower, upper, perUnitCost, supply, flow, dual);

		for (node mu = T.tree().firstNode(); mu != nullptr; mu = mu->succ()) {

			if (mu == minCostRoot)
				continue;

			int bends = 0;
			for (adjEntry adj = edgeNode[T.skeleton(mu).referenceEdge()]->firstAdj(); adj != nullptr; adj = adj->succ())
				bends += abs(flow[adj->theEdge()]);

			T.embed(mu, embedding[bends][mu]);
		}

		T.embed(G);
		ConstCombinatorialEmbedding graphEmbedding(G);
		adjExternal = graphEmbedding.externalFace()->firstAdj();
	}