Giter Club home page Giter Club logo

distributedlogisticregression's Introduction

DistributedLigisticRegression

This is a distributed implementation of logistic regression algorithm.

This includes two parts:

client

The client compute gradients based on its subet of data using weights pull from server, and send new gradients to server

server

The server takes gradients from clients, update weights, and send weights to clients if requested by clients.

Implementation:

The communication is managed by ZeroMQ (http://zeromq.org/), and message serialization/deserialization is done by Goolgle Protobuf (https://github.com/google/protobuf).

The server side code looks like this:

'''

while (true) {
	zmq::message_t request;
        //  Wait for next request from client
        socket->recv (&request);
		// get the request and read them into string
		std::string req_data = std::string(static_cast<char*>(request.data()), request.size());

		// parse the request data into protobuf data structure
		zmqprotobuf::PSMSG pmsg;
		pmsg.ParseFromString(req_data);
		
		if (pmsg.type() == PULL_REQUEST){ // client asking for weights
			//  package current weight into protobuf struture 
			memcpy(rep_weight.mutable_weights()->mutable_data(), weight, sizeof(float)*num_weight);
			std::string rep_data = rep_weight.SerializeAsString();

			// send reply back to client
			zmq::message_t reply (rep_data.length());
			memcpy ((void *) reply.data (), rep_data.data(), rep_data.length());
			socket->send (reply);

		} else if (pmsg.type() == PUSH_REQUEST){
			// update gradients
			update_weight(pmsg);
			++ iter;

			// reply to client anyway, not efficient, requreied by the socket type
			std::string rep_msg = "weights updated"; 
			zmq::message_t request (rep_msg.length());
			memcpy ((void *) request.data (), rep_msg.data(), rep_msg.length());
			// send the message through socket
			socket->send (request);
		}else{
			std::cout << "unknown requirement!" << std::endl;
		}
	}

'''

Compile

The code is compiled in Windows Visual Studio. Windows version of Goolgle protobuf and Zeromq are required.

distributedlogisticregression's People

Contributors

fujun-liu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.