Package com.etsy.conjecture.data

Examples of com.etsy.conjecture.data.StringKeyedVector


    public void update(Collection<LabeledInstance<L>> instances) {
        optimizer.model = this; // avoid serialization stackoverflow
        if (epoch > 0) {
            param.incrementIteration();
        }
        StringKeyedVector updates = optimizer.getUpdates(instances);
        param.add(updates);
    }
View Full Code Here


    public void update(LabeledInstance<L> instance) {
        optimizer.model = this; // avoid serialization stackoverflow
        if (epoch > 0) {
            param.incrementIteration();
        }
        StringKeyedVector update = optimizer.getUpdate(instance);
        param.add(update);
        truncate(instance);
        epoch++;
    }
View Full Code Here

        return Math.log(1.0 + Math.exp(-label * inner));
    }

    @Override
    public StringKeyedVector getGradients(LabeledInstance<BinaryLabel> instance) {
        StringKeyedVector gradients = instance.getVector().copy();
        double label = instance.getLabel().getAsPlusMinus();
        double inner = instance.getVector().dot(param);
        double gradient = -label / (Math.exp(label * inner) + 1.0);
        gradients.mul(gradient);
        return gradients;
    }
View Full Code Here

        return 0.5 * (hypothesis - label) * (hypothesis - label);
    }

    @Override
    public StringKeyedVector getGradients(LabeledInstance<RealValuedLabel> instance) {
        StringKeyedVector gradients = instance.getVector().copy();
        double hypothesis = param.dot(instance.getVector());
        double label = instance.getLabel().getValue();
        gradients.mul((2 * (hypothesis-label)));
        return gradients;
    }
View Full Code Here

    /**
     *  Do minibatch gradient descent
     */
    public StringKeyedVector getUpdates(Collection<LabeledInstance<L>> minibatch) {
        StringKeyedVector updateVec = new StringKeyedVector();
        for (LabeledInstance<L> instance : minibatch) {
            updateVec.add(getUpdate(instance)); // accumulate gradient
            model.truncate(instance);
            model.epoch++;
        }
        updateVec.mul(1.0/minibatch.size()); // do a single update, scaling weights by the
                                           // average gradient over the minibatch
        return updateVec;
    }
View Full Code Here

            update = update * (2.0 * (instance.getLabel().getValue() - 0.5));
        } else if (instance.getLabel().getValue() - ((RealValuedLabel)model.predict(instance.getVector())).getValue() < 0.0) {
            /** Regression **/
            update = update * -1;
        }
        StringKeyedVector updateVec = instance.getVector().copy();
        updateVec.mul(update);
        return updateVec;
    }
View Full Code Here

  public abstract ClusterLabel predict(StringKeyedVector instance);

  protected ClusteringModel() {
    Map<String, StringKeyedVector> init_param = new HashMap<String, StringKeyedVector>();
    for (int i = 0; i < numClusters; i++) {
      init_param.put(Integer.toString(i), new StringKeyedVector());
    }
    this.param = init_param;
  }
View Full Code Here

    private StringKeyedVector summedGradients = new StringKeyedVector();

    @Override
    public StringKeyedVector getUpdate(LabeledInstance instance) {
        StringKeyedVector gradients = model.getGradients(instance);
        StringKeyedVector updateVec = new StringKeyedVector();
        Iterator<Map.Entry<String, Double>> it = gradients.iterator();
        while (it.hasNext()) {
            Map.Entry<String,Double> pairs = (Map.Entry)it.next();
            String feature = pairs.getKey();
            double gradient = pairs.getValue();
            double featureLearningRate = updateAndGetFeatureLearningRate(feature, gradient);
            updateVec.setCoordinate(feature, gradient * -featureLearningRate);
       }
       return updateVec;
    }
View Full Code Here

        return initialLearningRate/Math.sqrt(summedGradients.getCoordinate(feature));
    }

    @Override
    public void teardown() {
        summedGradients = new StringKeyedVector();
    }
View Full Code Here

TOP

Related Classes of com.etsy.conjecture.data.StringKeyedVector

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.