Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright [2013-2014] eBay Software Foundation
  *  
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *    http://www.apache.org/licenses/LICENSE-2.0
  *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package ml.shifu.guagua.mapreduce.example.lr;
A model class to store logistic regression weight on first iteration by using parameters, while in other iterations parameters is used to store gradients.

To make all workers started at the same model, master will compute a consistent model weights at the first iteration and then send to all the workers. Workers will start computing from the second iteration.

Workers are responsible to compute local accumulated gradients and send to master while master accumulates all gradients together to build a global model.

public class LogisticRegressionParams extends HaltBytable {

    
Model weights in the first iteration, gradients in other iterations.
    private double[] parameters;

    
Model error in one worker one iteration.
    private double error;
    public LogisticRegressionParams() {
    }
    public LogisticRegressionParams(double[] parameters) {
        this. = parameters;
    }
    public LogisticRegressionParams(double[] parametersdouble error) {
        this. = parameters;
        this. = error;
    }
    public double[] getParameters() {
        return ;
    }
    public void setParameters(double[] parameters) {
        this. = parameters;
    }
    public double getError() {
        return ;
    }
    public void setError(double error) {
        this. = error;
    }
    @Override
    public void doWrite(DataOutput outthrows IOException {
        if( != null) {
            out.writeInt(this..length);
            for(int i = 0; i < this..lengthi++) {
                out.writeDouble(this.[i]);
            }
        }
        out.writeDouble(this.);
    }
    @Override
    public void doReadFields(DataInput inthrows IOException {
        int length = in.readInt();
         = new double[length];
        for(int i = 0; i < lengthi++) {
            [i] = in.readDouble();
        }
        this. = in.readDouble();
    }
New to GrepCode? Check out our FAQ X