EclairJS/eclairjs · IsotonicRegression.js
javascript logo
function () {

    var JavaWrapper = require(EclairJS_Globals.NAMESPACE + '/JavaWrapper');
    var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
    var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');


    /**
     * Isotonic regression.
     * Currently implemented using parallelized pool adjacent violators algorithm.
     * Only univariate (single feature) algorithm supported.
     *
     * Sequential PAV implementation based on:
     * Tibshirani, Ryan J., Holger Hoefling, and Robert Tibshirani.
     *   "Nearly-isotonic regression." Technometrics 53.1 (2011): 54-61.
     *   Available from [[http://www.stat.cmu.edu/~ryantibs/papers/neariso.pdf]]
     *
     * Sequential PAV parallelization based on:
     * Kearsley, Anthony J., Richard A. Tapia, and Michael W. Trosset.
     *   "An approach to parallelizing isotonic regression."
     *   Applied Mathematics and Parallel Computing. Physica-Verlag HD, 1996. 141-147.
     *   Available from [[http://softlib.rice.edu/pub/CRPC-TRs/reports/CRPC-TR96640.pdf]]
     *
     * @see [[http://en.wikipedia.org/wiki/Isotonic_regression Isotonic regression (Wikipedia)]]
     * @memberof module:eclairjs/mllib/regression
     * @classdesc
     */

    /**
     * Constructs IsotonicRegression instance with default parameter isotonic = true.
     *
     *  @class
     */
    var IsotonicRegression = function (jvmObject) {

        this.logger = Logger.getLogger("IsotonicRegression_js");
        if (!jvmObject || !(jvmObject instanceof org.apache.spark.mllib.regression.IsotonicRegression)) {
            jvmObject = new org.apache.spark.mllib.regression.IsotonicRegression();
        }

        JavaWrapper.call(this, jvmObject);

    };

    IsotonicRegression.prototype = Object.create(JavaWrapper.prototype);

    IsotonicRegression.prototype.constructor = IsotonicRegression;


    /**
     * Sets the isotonic parameter.
     *
     * @param {boolean} isotonic  Isotonic (increasing) or antitonic (decreasing) sequence.
     * @returns {module:eclairjs/mllib/regression.IsotonicRegression}  This instance of IsotonicRegression.
     */
    IsotonicRegression.prototype.setIsotonic = function (isotonic) {
        var javaObject = this.getJavaObject().setIsotonic(isotonic);
        return new IsotonicRegression(javaObject);
    };


    /**
     * Run IsotonicRegression algorithm to obtain isotonic regression model.
     *
     * @param {module:eclairjs.RDD} input  RDD of tuples (label, feature, weight) where label is dependent variable
     *              for which we calculate isotonic regression, feature is independent variable
     *              and weight represents number of measures with default 1.
     *              If multiple labels share the same feature value then they are ordered before
     *              the algorithm is executed.
     * @returns {module:eclairjs/mllib/regression.IsotonicRegressionModel}  Isotonic regression model.
     */
    IsotonicRegression.prototype.run = function (input) {
    // // TODO: handle Tuple conversion for 'input'
        var input_uw = Utils.unwrapObject(input);
        var javaObject = this.getJavaObject().run(input_uw);
        return Utils.javaToJs(javaObject);
    };


    module.exports = IsotonicRegression;

}
Similar code snippets
1.
EclairJS/eclairjs · IsotonicRegressionModel.js
Match rating: 84.37% · See similar code snippets
javascript logo
function () {

    var JavaWrapper = require(EclairJS_Globals.NAMESPACE + '/JavaWrapper');
    var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
    var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');

    /**
     * Regression model for isotonic regression.
     *
     * @param boundaries Array of boundaries for which predictions are known.
     *                   Boundaries must be sorted in increasing order.
     * @param predictions Array of predictions associated to the boundaries at the same index.
     *                    Results of isotonic regression and therefore monotone.
     * @param isotonic indicates whether this is isotonic or antitonic.
     *
     * @memberof module:eclairjs/mllib/regression
     * @classdesc
     */

    /**
     * @param {float[]} boundaries
     * @param {float[]} predictions
     * @param {boolean} isotonic
     *  @class
     */
    var IsotonicRegressionModel = function (boundaries, predictions, isotonic) {
        this.logger = Logger.getLogger("IsotonicRegressionModel_js");
        var jvmObject;
        if (boundaries instanceof org.apache.spark.mllib.regression.IsotonicRegressionModel) {
            jvmObject = boundaries;
        } else {
            jvmObject = new org.apache.spark.mllib.regression.IsotonicRegressionModel(boundaries, predictions, isotonic);
        }

        JavaWrapper.call(this, jvmObject);

    };

    IsotonicRegressionModel.prototype = Object.create(JavaWrapper.prototype);

    IsotonicRegressionModel.prototype.constructor = IsotonicRegressionModel;


    /**
     * Predict labels for provided features, or single label..
     * Using a piecewise linear function.
     *
     * @param {module:eclairjs.RDD | module:eclairjs.FloatRDD | float} testData  Features to be labeled, if float.
     *          1) If testData exactly matches a boundary then associated prediction is returned.
     *           In case there are multiple predictions with the same boundary then one of them
     *           is returned. Which one is undefined (same as java.util.Arrays.binarySearch).
     *         2) If testData is lower or higher than all boundaries then first or last prediction
     *           is returned respectively. In case there are multiple predictions with the same
     *           boundary then the lowest or highest is returned respectively.
     *         3) If testData falls between two values in boundary array then prediction is treated
     *           as piecewise linear function and interpolated value is returned. In case there are
     *           multiple values with the same boundary then the same rules as in 2) are used.
     *
     * @returns {module:eclairjs.RDD | number}  Predicted labels or label.
     */
    IsotonicRegressionModel.prototype.predict = function (testData) {
        var testData_uw = Utils.unwrapObject(testData);
        var javaObject = this.getJavaObject().predict(testData_uw);

        return Utils.javaToJs(javaObject);
    };


    /**
     * @param {module:eclairjs.SparkContext} sc
     * @param {string} path
     */
    IsotonicRegressionModel.prototype.save = function (sc, path) {
        var sc_uw = Utils.unwrapObject(sc);
        this.getJavaObject().save(sc_uw.sc(), path);
    };


    //
    // static methods
    //


    /**
     * @param {module:eclairjs.SparkContext} sc
     * @param {string} path
     * @returns {module:eclairjs/mllib/regression.IsotonicRegressionModel}
     */
    IsotonicRegressionModel.load = function (sc, path) {
        var sc_uw = Utils.unwrapObject(sc);
        var javaObject = org.apache.spark.mllib.regression.IsotonicRegressionModel.load(sc_uw.sc(), path);
        return Utils.javaToJs(javaObject);
    };

    module.exports = IsotonicRegressionModel;

}
2.
EclairJS/eclairjs · IsotonicRegression.js
Match rating: 74.68% · See similar code snippets
javascript logo
function (jvmObject) {

        this.logger = Logger.getLogger("IsotonicRegression_js");
        if (!jvmObject || !(jvmObject instanceof org.apache.spark.mllib.regression.IsotonicRegression)) {
            jvmObject = new org.apache.spark.mllib.regression.IsotonicRegression();
        }

        JavaWrapper.call(this, jvmObject);

    }
3.
EclairJS/eclairjs · IsotonicRegressionModel.js
Match rating: 72.19% · See similar code snippets
javascript logo
function (boundaries, predictions, isotonic) {
        this.logger = Logger.getLogger("IsotonicRegressionModel_js");
        var jvmObject;
        if (boundaries instanceof org.apache.spark.mllib.regression.IsotonicRegressionModel) {
            jvmObject = boundaries;
        } else {
            jvmObject = new org.apache.spark.mllib.regression.IsotonicRegressionModel(boundaries, predictions, isotonic);
        }

        JavaWrapper.call(this, jvmObject);

    }
4.
EclairJS/eclairjs · RegressionModel.js
Match rating: 61.2% · See similar code snippets
javascript logo
function () {

    var PredictionModel = require(EclairJS_Globals.NAMESPACE + '/ml/PredictionModel');
    var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
    var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');

    
    
    /**
     * @classdesc
     *
     * Model
     *
     * @class
     * @memberof module:eclairjs/ml/regression
     * @extends module:eclairjs/ml.PredictionModel
     */

    var RegressionModel = function(jvmObject) {
     	 this.logger = Logger.getLogger("RegressionModel_js");
     	 PredictionModel.call(this, jvmObject);
    
    };
    
    RegressionModel.prototype = Object.create(PredictionModel.prototype);
    
    RegressionModel.prototype.constructor = RegressionModel;
    
    
    module.exports = RegressionModel;

}
5.
EclairJS/eclairjs · LinearRegressionWithSGD.js
Match rating: 60.34% · See similar code snippets
javascript logo
function () {

    var JavaWrapper = require(EclairJS_Globals.NAMESPACE + '/JavaWrapper');
    var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
    var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');

    var LinearRegressionModel = require(EclairJS_Globals.NAMESPACE + '/mllib/regression/LinearRegressionModel');

    /**
     * Construct a LinearRegression object with default parameters: {stepSize: 1.0, numIterations: 100, miniBatchFraction: 1.0}.
     * @constructor
     * @memberof module:eclairjs/mllib/regression
     * @classdesc Train a linear regression model with no regularization using Stochastic Gradient Descent.
     * This solves the least squares regression formulation f(weights) = 1/n ||A weights-y||^2^ (which is the mean squared error).
     * Here the data matrix has n rows, and the input RDD holds the set of rows of A, each with its corresponding right hand side label y.
     * See also the documentation for the precise formulation.
     */
    var LinearRegressionWithSGD = {
        logger: Logger.getLogger("LinearRegressionWithSGD_js")
    }

    LinearRegressionWithSGD.DEFAULT_NUM_ITERATIONS = 100;

    /**
     * Train a Linear Regression model given an RDD of (label, features) pairs.
     * We run a fixed number of iterations of gradient descent using the specified step size.
     * Each iteration uses miniBatchFraction fraction of the data to calculate a stochastic gradient.
     * The weights used in gradient descent are initialized using the initial weights provided.
     *
     * @param {module:eclairjs.RDD} rdd of LabeledPoints
     * @param {integer} numIterations
     * @param {float} [stepSize] - step size to be used for each iteration of gradient descent, defaults to 1.0
     * @param {floar} [miniBatchFraction] - fraction of data to be used per iteration, defaults to 1.0
     * @param {module:eclairjs/mllib/linalg.Vector} [initialWeights] - initial set of weights to be used. Array should be equal in size to the number of features in the data.
     * @returns {module:eclairjs/mllib/regression.LinearRegressionModel}
     */
    LinearRegressionWithSGD.train = function (rdd, numIterations, stepSize, miniBatchFraction, initialWeights) {
        this.logger.debug("JavaRDD " + rdd);
        var lrdd = Utils.unwrapObject(rdd).rdd();
        this.logger.debug("calling train");
        var model;
        if (arguments.length === 5) {
            model = org.apache.spark.mllib.regression.LinearRegressionWithSGD.train(lrdd, numIterations, stepSize, miniBatchFraction, Utils.unwrapObject(initialWeights));
        } else if (arguments.length === 4) {
            model = org.apache.spark.mllib.regression.LinearRegressionWithSGD.train(lrdd, numIterations, stepSize, miniBatchFraction);
        } else if (arguments.length === 3) {
            model = org.apache.spark.mllib.regression.LinearRegressionWithSGD.train(lrdd, numIterations, stepSize);
        } else if (arguments.length === 2) {
            model = org.apache.spark.mllib.regression.LinearRegressionWithSGD.train(lrdd, numIterations);
        } else {
            throw "LinearRegressionWithSGD.train invalid arguments"
        }

        this.logger.debug("return model");
        return new LinearRegressionModel(model);

    };

    module.exports = LinearRegressionWithSGD;

}
6.
EclairJS/eclairjs · RegressionEvaluator.js
Match rating: 59.47% · See similar code snippets
javascript logo
function () {

    var JavaWrapper = require(EclairJS_Globals.NAMESPACE + '/JavaWrapper');
    var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
    var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');

    
    
    /**
     * @classdesc
     * :: Experimental ::
     * Evaluator for regression, which expects two input columns: prediction and label.
     *
     */
    
    /**
     * @param {string} uid
     * @class
     * @constructor
     * @memberof module:eclairjs/ml/evaluation
     */
    var RegressionEvaluator = function(uid) {
        var jvmObject;
        this.logger = Logger.getLogger("RegressionEvaluator_js");
        if (uid) {
            if (uid instanceof org.apache.spark.ml.evaluation.RegressionEvaluator) {
                jvmObject = uid;
            } else {
                jvmObject = new org.apache.spark.ml.evaluation.RegressionEvaluator(uid);
            }
        } else {
            jvmObject = new org.apache.spark.ml.evaluation.RegressionEvaluator();
        }
        JavaWrapper.call(this, jvmObject);
    
    };
    
    RegressionEvaluator.prototype = Object.create(JavaWrapper.prototype);
    
    RegressionEvaluator.prototype.constructor = RegressionEvaluator;
    
    
    
    /**
     * @returns {string} 
     */
    RegressionEvaluator.prototype.getMetricName = function() {
       return  this.getJavaObject().getMetricName();
    };
    
    
    /**
     * @param {string} value
     * @returns {module:eclairjs/ml/evaluation.RegressionEvaluator}
     */
    RegressionEvaluator.prototype.setMetricName = function(value) {
       var javaObject =  this.getJavaObject().setMetricName(value);
       return new RegressionEvaluator(javaObject);
    };
    
    
    /**
     * @param {string} value
     * @returns {module:eclairjs/ml/evaluation.RegressionEvaluator}
     */
    RegressionEvaluator.prototype.setPredictionCol = function(value) {
       var javaObject =  this.getJavaObject().setPredictionCol(value);
       return new RegressionEvaluator(javaObject);
    };
    
    
    /**
     * @param {string} value
     * @returns {module:eclairjs/ml/evaluation.RegressionEvaluator}
     */
    RegressionEvaluator.prototype.setLabelCol = function(value) {
       var javaObject =  this.getJavaObject().setLabelCol(value);
       return new RegressionEvaluator(javaObject);
    };
    
    
    /**
     * @param {modue:eclairjs/sql.Dataset} dataset
     * @returns {number} 
     */
    RegressionEvaluator.prototype.evaluate = function(dataset) {
       var dataset_uw = Utils.unwrapObject(dataset);
       return  this.getJavaObject().evaluate(dataset_uw);
    };
    
    
    /**
     * @returns {boolean} 
     */
    RegressionEvaluator.prototype.isLargerBetter = function() {
       return  this.getJavaObject().isLargerBetter();
    };
    
    
    /**
     * @param {module:eclairjs/ml/param.ParamMap} extra
     * @returns {module:eclairjs/ml/evaluation.RegressionEvaluator}
     */
    RegressionEvaluator.prototype.copy = function(extra) {
       var extra_uw = Utils.unwrapObject(extra);
       var javaObject =  this.getJavaObject().copy(extra_uw);
       return new RegressionEvaluator(javaObject);
    };
    
    //
    // static methods
    //
    
    
    /**
     * @param {string} path
     * @returns {module:eclairjs/ml/evaluation.RegressionEvaluator}
     */
    RegressionEvaluator.load = function(path) {
       var javaObject =  org.apache.spark.ml.evaluation.RegressionEvaluator.load(path);
       return new RegressionEvaluator(javaObject);
    };
    
    module.exports = RegressionEvaluator;

}
7.
EclairJS/eclairjs · GBTRegressionModel.js
Match rating: 55.7% · See similar code snippets
javascript logo
function () {

    var PredictionModel = require(EclairJS_Globals.NAMESPACE + '/ml/PredictionModel');
    var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
    var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');


    /**
     * @classdesc
     *
     * [Gradient-Boosted Trees (GBTs)]{@link http://en.wikipedia.org/wiki/Gradient_boosting}
     * model for regression.
     * It supports both continuous and categorical features.
     * @class
     * @extends module:eclairjs/ml.PredictionModel
     * @memberof module:eclairjs/ml/regression
     * @oaram {string} uid
     * @param {DecisionTreeRegressionModel[]} trees   Decision trees in the ensemble.
     * @param {float[]} treeWeights   Weights for the decision trees in the ensemble.

     */
    var GBTRegressionModel = function (uid, trees, treeWeights) {
        this.logger = Logger.getLogger("ml_regression_GBTRegressionModel_js");
        var jvmObject;
        if (uid instanceof org.apache.spark.ml.regression.GBTRegressionModel) {
            jvmObject = uid;
        } else {
            var tress_uw = Utils.unwrapObject(trees);
            jvmObject = new org.apache.spark.ml.regression.GBTRegressionModel(uid, tress_uw, treeWeights);
        }
        PredictionModel.call(this, jvmObject);

    };

    GBTRegressionModel.prototype = Object.create(PredictionModel.prototype);

    GBTRegressionModel.prototype.constructor = GBTRegressionModel;


    /**
     * An immutable unique ID for the object and its derivatives.
     * @returns {string}
     */
    GBTRegressionModel.prototype.uid = function () {
        return this.getJavaObject().uid();
    };

    /**
     * @returns {DecisionTreeModel[]}
     */
    GBTRegressionModel.prototype.trees = function () {
        var javaObject = this.getJavaObject().trees();
        return Utils.javaToJs(javaObject);
    };


    /**
     * @returns {float[]}
     */
    GBTRegressionModel.prototype.treeWeights = function () {
        return this.getJavaObject().treeWeights();
    };


    /**
     * @param {module:eclairjs/ml/param.ParamMap} extra
     * @returns {module:eclairjs/ml/regression.GBTRegressionModel}
     */
    GBTRegressionModel.prototype.copy = function (extra) {
        var extra_uw = Utils.unwrapObject(extra);
        var javaObject = this.getJavaObject().copy(extra_uw);
        return new GBTRegressionModel(javaObject);
    };


    /**
     * @returns {string}
     */
    GBTRegressionModel.prototype.toString = function () {
        return this.getJavaObject().toString();
    };

    /**
     * @returns {string}
     */
    GBTRegressionModel.prototype.toDebugString = function () {
        return this.getJavaObject().toDebugString();
    };

    
    /**
     * @returns {module:eclairjs/ml/util.MLWriter} 
     */
    GBTRegressionModel.prototype.write = function() {
       var javaObject =  this.getJavaObject().write();
       return Utils.javaToJs(javaObject);
    };
    
    //
    // static methods
    //
    
    
    /**
     * @returns {module:eclairjs/ml/util.MLReader} 
     */
    GBTRegressionModel.read = function() {
       var javaObject =  org.apache.spark.ml.regression.GBTRegressionModel.read();
       return Utils.javaToJs(javaObject);
    };
    
    
    /**
     * @param {string} path
     * @returns {module:eclairjs/ml/regression.GBTRegressionModel} 
     */
    GBTRegressionModel.load = function(path) {
       var javaObject =  org.apache.spark.ml.regression.GBTRegressionModel.load(path);
       return new GBTRegressionModel(javaObject);
    };


    module.exports = GBTRegressionModel;
}
8.
EclairJS/eclairjs · Transformer.js
Match rating: 51.53% · See similar code snippets
javascript logo
function () {

    var PipelineStage = require(EclairJS_Globals.NAMESPACE + '/ml/PipelineStage');
    var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
    var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');

    
    
    /**
     * @classdesc
     * Abstract class for transformers that transform one dataset into another.
     * @class
     * @memberof module:eclairjs/ml
     * @extends module:eclairjs/ml.PipelineStage
     */
    var Transformer = function(jvmObject) {
        this.logger = Logger.getLogger("Transformer_js");
        PipelineStage.call(this, jvmObject);
    
    };
    
    Transformer.prototype = Object.create(PipelineStage.prototype);
    
    Transformer.prototype.constructor = Transformer;
    
    
    
    /**
     * Transforms the dataset with optional parameters
     * @param {module:eclairjs/sql.Dataset} dataset  input dataset
     * @param {module:eclairjs/ml/param.ParamMap | module:eclairjs/ml/param.ParamPair} [params] additional parameters, overwrite embedded params, overwrite embedded params
     * @param {...module:eclairjs/ml/param.ParamPair} [otherParamPairs]  other param pairs, Only used if argument two is {@link module:eclairjs/ml/param.ParamPair}. Overwrite embedded params
     * @returns {module:eclairjs/sql.Dataset}  transformed dataset
     */
    Transformer.prototype.transform = function() {
        var ParamMap = require(EclairJS_Globals.NAMESPACE + '/ml/param/ParamMap');
       var dataset_uw = Utils.unwrapObject(arguments[0]);
        var javaObject;
        if (arguments.length == 1) {
            javaObject =  this.getJavaObject().transform(dataset_uw);
        } else if (arguments[1] instanceof ParamMap) {
            var paramMap_uw = Utils.unwrapObject(arguments[1]);
            javaObject =  this.getJavaObject().transform(dataset_uw,paramMap_uw);
        } else {
            var firstParamPair_uw = Utils.unwrapObject(arguments[1]);
            var otherParamPairs_uw = [];
            for (var i = 2; i < arguments.length; i++) {
                otherParamPairs_uw.push(Utils.unwrapObject(arguments[i])) ;
            }
            javaObject =  this.getJavaObject().transform(dataset_uw,firstParamPair_uw,otherParamPairs_uw);
        }
       return Utils.javaToJs(javaObject);
    };
    
    
    /**
     * @param {module:eclairjs/ml/param.ParamMap} extra
     * @returns {module:eclairjs/ml.Transformer} 
     */
    Transformer.prototype.copy = function(extra) {
       var extra_uw = Utils.unwrapObject(extra);
       var javaObject =  this.getJavaObject().copy(extra_uw);
       return Utils.javaToJs(javaObject);
    };
    
    module.exports = Transformer;
}
9.
EclairJS/eclairjs · PrefixSpan.js
Match rating: 47.75% · See similar code snippets
javascript logo
function () {

    var JavaWrapper = require(EclairJS_Globals.NAMESPACE + '/JavaWrapper');
    var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
    var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');

    var PrefixSpanModel = require(EclairJS_Globals.NAMESPACE + '/mllib/fpm/PrefixSpanModel');

    /**
     * :: Experimental ::
     *
     * A parallel PrefixSpan algorithm to mine frequent sequential patterns.
     * The PrefixSpan algorithm is described in J. Pei, et al., PrefixSpan: Mining Sequential Patterns
     * Efficiently by Prefix-Projected Pattern Growth ([[http://doi.org/10.1109/ICDE.2001.914830]]).
     *
     *
     * @see [[https://en.wikipedia.org/wiki/Sequential_Pattern_Mining Sequential Pattern Mining
     *       (Wikipedia)]]
     * @memberof module:eclairjs/mllib/fpm
     * @classdesc
     * Constructs a default instance with default parameters
     * {minSupport: `0.1`, maxPatternLength: `10`, maxLocalProjDBSize: `32000000L`}.
     * @class
     */
    var PrefixSpan = function(jvmObject) {
         
         this.logger = Logger.getLogger("PrefixSpan_js");
        if (!jvmObject) {
            jvmObject = new org.apache.spark.mllib.fpm.PrefixSpan();
        }
         JavaWrapper.call(this, jvmObject);

    };

    PrefixSpan.prototype = Object.create(JavaWrapper.prototype);

    PrefixSpan.prototype.constructor = PrefixSpan;



    /**
     * Get the minimal support (i.e. the frequency of occurrence before a pattern is considered
     * frequent).
     * @returns {float}
     */
    PrefixSpan.prototype.getMinSupport = function() {
        return  this.getJavaObject().getMinSupport();
    };


    /**
     * Sets the minimal support level (default: `0.1`).
     * @param {float} minSupport
     * @returns {module:eclairjs/mllib/fpm.PrefixSpan}
     */
    PrefixSpan.prototype.setMinSupport = function(minSupport) {
       var javaObject =  this.getJavaObject().setMinSupport(minSupport);
       return new PrefixSpan(javaObject);
    };


    /**
     * Gets the maximal pattern length (i.e. the length of the longest sequential pattern to consider.
     * @returns {integer}
     */
    PrefixSpan.prototype.getMaxPatternLength = function() {
        return  this.getJavaObject().getMaxPatternLength();
    };


    /**
     * Sets maximal pattern length (default: `10`).
     * @param {integer} maxPatternLength
     * @returns {module:eclairjs/mllib/fpm.PrefixSpan}
     */
    PrefixSpan.prototype.setMaxPatternLength = function(maxPatternLength) {
       var javaObject =  this.getJavaObject().setMaxPatternLength(maxPatternLength);
       return new PrefixSpan(javaObject);
    };


    /**
     * Gets the maximum number of items allowed in a projected database before local processing.
     * @returns {integer}
     */
    PrefixSpan.prototype.getMaxLocalProjDBSize = function() {
        return  this.getJavaObject().getMaxLocalProjDBSize();
    };


    /**
     * Sets the maximum number of items (including delimiters used in the internal storage format)
     * allowed in a projected database before local processing (default: `32000000L`).
     * @param {integer} maxLocalProjDBSize
     * @returns {module:eclairjs/mllib/fpm.PrefixSpan}
     */
    PrefixSpan.prototype.setMaxLocalProjDBSize = function(maxLocalProjDBSize) {
       var javaObject =  this.getJavaObject().setMaxLocalProjDBSize(maxLocalProjDBSize);
       return new PrefixSpan(javaObject);
    };


    /**
     * Finds the complete set of frequent sequential patterns in the input sequences of itemsets.
     * @param {module:eclairjs.RDD} data  sequences of itemsets.
     * @returns {module:eclairjs/mllib/fpm.PrefixSpanModel}  a [[module:eclairjs/mllib/fpm.PrefixSpanModel]] that contains the frequent patterns
     */
    PrefixSpan.prototype.run = function(data) {
       var data_uw = Utils.unwrapObject(data);
       var javaObject =  this.getJavaObject().run(data_uw);
       return new PrefixSpanModel(javaObject);
    };

    module.exports = PrefixSpan;

}
10.
EclairJS/eclairjs · LDA.js
Match rating: 47.45% · See similar code snippets
javascript logo
function () {

    var JavaWrapper = require(EclairJS_Globals.NAMESPACE + '/JavaWrapper');
    var Logger = require(EclairJS_Globals.NAMESPACE + '/Logger');
    var Utils = require(EclairJS_Globals.NAMESPACE + '/Utils');

    var BisectingKMeansModel = require(EclairJS_Globals.NAMESPACE + '/mllib/clustering/BisectingKMeansModel');

    /**
     * Latent Dirichlet Allocation (LDA), a topic model designed for text documents.
     *
     * Terminology:
     *  - "word" = "term": an element of the vocabulary
     *  - "token": instance of a term appearing in a document
     *  - "topic": multinomial distribution over words representing some concept
     *
     * References:
     *  - Original LDA paper (journal version):
     *    Blei, Ng, and Jordan.  "Latent Dirichlet Allocation."  JMLR, 2003.
     *
     * @see [[http://en.wikipedia.org/wiki/Latent_Dirichlet_allocation Latent Dirichlet allocation
     *       (Wikipedia)]]
     * @classdesc
     */

    /**
     * Constructs a LDA instance with default parameters.
     * @returns {??}
     * @class
     * @memberof module:eclairjs/mllib/clustering
     */
    var LDA = function () {
        var jvmObject;
        if (arguments[0]) {
            jvmObject = arguments[0];
        } else {
            jvmObject = new org.apache.spark.mllib.clustering.LDA();
        }
        this.logger = Logger.getLogger("LDA_js");
        JavaWrapper.call(this, jvmObject);

    };

    LDA.prototype = Object.create(JavaWrapper.prototype);

    LDA.prototype.constructor = LDA;


    /**
     * Number of topics to infer.  I.e., the number of soft cluster centers.
     *
     * @returns {integer}
     */
    LDA.prototype.getK = function () {
       return  this.getJavaObject().getK();
    };


    /**
     * Number of topics to infer.  I.e., the number of soft cluster centers.
     * (default = 10)
     * @param {integer} k
     * @returns {LDA}
     */
    LDA.prototype.setK = function (k) {
       var javaObject =  this.getJavaObject().setK(k);
       return new LDA(javaObject);
    };


    /**
     * Concentration parameter (commonly named "alpha") for the prior placed on documents'
     * distributions over topics ("theta").
     *
     * This is the parameter to a Dirichlet distribution.
     * @returns {module:eclairjs/mllib/linalg.Vector}
     */
    LDA.prototype.getAsymmetricDocConcentration = function () {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().getAsymmetricDocConcentration();
    //   return Utils.javaToJs(javaObject);
    };


    /**
     * Concentration parameter (commonly named "alpha") for the prior placed on documents'
     * distributions over topics ("theta").
     *
     * This method assumes the Dirichlet distribution is symmetric and can be described by a single
     * {@link Double} parameter. It should fail if docConcentration is asymmetric.
     * @returns {number}
     */
    LDA.prototype.getDocConcentration = function () {
        throw "not implemented by ElairJS";
    //   return  this.getJavaObject().getDocConcentration();
    };


    /**
     * Concentration parameter (commonly named "alpha") for the prior placed on documents'
     * distributions over topics ("theta").
     *
     * This is the parameter to a Dirichlet distribution, where larger values mean more smoothing
     * (more regularization).
     *
     * If set to a singleton vector Vector(-1), then docConcentration is set automatically. If set to
     * singleton vector Vector(t) where t != -1, then t is replicated to a vector of length k during
     * [[LDAOptimizer.initialize()]]. Otherwise, the {@link docConcentration} vector must be length k.
     * (default = Vector(-1) = automatic)
     *
     * Optimizer-specific parameter settings:
     *  - EM
     *     - Currently only supports symmetric distributions, so all values in the vector should be
     *       the same.
     *     - Values should be > 1.0
     *     - default = uniformly (50 / k) + 1, where 50/k is common in LDA libraries and +1 follows
     *       from Asuncion et al. (2009), who recommend a +1 adjustment for EM.
     *  - Online
     *     - Values should be >= 0
     *     - default = uniformly (1.0 / k), following the implementation from
     *       [[https://github.com/Blei-Lab/onlineldavb]].
     * @param {module:eclairjs/mllib/linalg.Vector} docConcentration
     * @returns {}
     */
    LDA.prototype.setDocConcentrationwithVector = function (docConcentration) {
        throw "not implemented by ElairJS";
    //   var docConcentration_uw = Utils.unwrapObject(docConcentration);
    //   var javaObject =  this.getJavaObject().setDocConcentration(docConcentration_uw);
    //   return new (javaObject);
    };


    /**
     * Replicates a {@link Double} docConcentration to create a symmetric prior.
     * @param {number} docConcentration
     * @returns {}
     */
    LDA.prototype.setDocConcentrationwithnumber = function (docConcentration) {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().setDocConcentration(docConcentration);
    //   return new (javaObject);
    };


    /**
     * Alias for {@link getAsymmetricDocConcentration}
     * @returns {module:eclairjs/mllib/linalg.Vector}
     */
    LDA.prototype.getAsymmetricAlpha = function () {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().getAsymmetricAlpha();
    //   return Utils.javaToJs(javaObject);
    };


    /**
     * Alias for {@link getDocConcentration}
     * @returns {number}
     */
    LDA.prototype.getAlpha = function () {
        throw "not implemented by ElairJS";
    //   return  this.getJavaObject().getAlpha();
    };


    /**
     * Alias for [[setDocConcentration()]]
     * @param {module:eclairjs/mllib/linalg.Vector} alpha
     * @returns {}
     */
    LDA.prototype.setAlphawithVector = function (alpha) {
        throw "not implemented by ElairJS";
    //   var alpha_uw = Utils.unwrapObject(alpha);
    //   var javaObject =  this.getJavaObject().setAlpha(alpha_uw);
    //   return new (javaObject);
    };


    /**
     * Alias for [[setDocConcentration()]]
     * @param {number} alpha
     * @returns {}
     */
    LDA.prototype.setAlphawithnumber = function (alpha) {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().setAlpha(alpha);
    //   return new (javaObject);
    };


    /**
     * Concentration parameter (commonly named "beta" or "eta") for the prior placed on topics'
     * distributions over terms.
     *
     * This is the parameter to a symmetric Dirichlet distribution.
     *
     * Note: The topics' distributions over terms are called "beta" in the original LDA paper
     * by Blei et al., but are called "phi" in many later papers such as Asuncion et al., 2009.
     * @returns {number}
     */
    LDA.prototype.getTopicConcentration = function () {
        throw "not implemented by ElairJS";
    //   return  this.getJavaObject().getTopicConcentration();
    };


    /**
     * Concentration parameter (commonly named "beta" or "eta") for the prior placed on topics'
     * distributions over terms.
     *
     * This is the parameter to a symmetric Dirichlet distribution.
     *
     * Note: The topics' distributions over terms are called "beta" in the original LDA paper
     * by Blei et al., but are called "phi" in many later papers such as Asuncion et al., 2009.
     *
     * If set to -1, then topicConcentration is set automatically.
     *  (default = -1 = automatic)
     *
     * Optimizer-specific parameter settings:
     *  - EM
     *     - Value should be > 1.0
     *     - default = 0.1 + 1, where 0.1 gives a small amount of smoothing and +1 follows
     *       Asuncion et al. (2009), who recommend a +1 adjustment for EM.
     *  - Online
     *     - Value should be >= 0
     *     - default = (1.0 / k), following the implementation from
     *       [[https://github.com/Blei-Lab/onlineldavb]].
     * @param {number} topicConcentration
     * @returns {}
     */
    LDA.prototype.setTopicConcentration = function (topicConcentration) {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().setTopicConcentration(topicConcentration);
    //   return new (javaObject);
    };


    /**
     * Alias for {@link getTopicConcentration}
     * @returns {number}
     */
    LDA.prototype.getBeta = function () {
        throw "not implemented by ElairJS";
    //   return  this.getJavaObject().getBeta();
    };


    /**
     * Alias for [[setTopicConcentration()]]
     * @param {number} beta
     * @returns {}
     */
    LDA.prototype.setBeta = function (beta) {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().setBeta(beta);
    //   return new (javaObject);
    };


    /**
     * Maximum number of iterations for learning.
     * @returns {number}
     */
    LDA.prototype.getMaxIterations = function () {
        throw "not implemented by ElairJS";
    //   return  this.getJavaObject().getMaxIterations();
    };


    /**
     * Maximum number of iterations for learning.
     * (default = 20)
     * @param {number} maxIterations
     * @returns {}
     */
    LDA.prototype.setMaxIterations = function (maxIterations) {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().setMaxIterations(maxIterations);
    //   return new (javaObject);
    };


    /**
     * Random seed
     * @returns {number}
     */
    LDA.prototype.getSeed = function () {
        throw "not implemented by ElairJS";
    //   return  this.getJavaObject().getSeed();
    };


    /**
     * Random seed
     * @param {number} seed
     * @returns {}
     */
    LDA.prototype.setSeed = function (seed) {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().setSeed(seed);
    //   return new (javaObject);
    };


    /**
     * Period (in iterations) between checkpoints.
     * @returns {number}
     */
    LDA.prototype.getCheckpointInterval = function () {
        throw "not implemented by ElairJS";
    //   return  this.getJavaObject().getCheckpointInterval();
    };


    /**
     * Period (in iterations) between checkpoints (default = 10). Checkpointing helps with recovery
     * (when nodes fail). It also helps with eliminating temporary shuffle files on disk, which can be
     * important when LDA is run for many iterations. If the checkpoint directory is not set in
     * {@link SparkContext}, this setting is ignored.
     *
     * @see [[org.apache.spark.SparkContext#setCheckpointDir]]
     * @param {number} checkpointInterval
     * @returns {}
     */
    LDA.prototype.setCheckpointInterval = function (checkpointInterval) {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().setCheckpointInterval(checkpointInterval);
    //   return new (javaObject);
    };


    /**
     * Set the LDAOptimizer used to perform the actual calculation by algorithm name.
     * Currently "em", "online" are supported.
     * @param {string} optimizerName
     * @returns {}
     */
    LDA.prototype.setOptimizer = function (optimizerName) {
        throw "not implemented by ElairJS";
    //   var javaObject =  this.getJavaObject().setOptimizer(optimizerName);
    //   return new (javaObject);
    };


    /**
     * Learn an LDA model using the given dataset.
     *
     * @param {module:eclairjs.RDD | PairRDD} documents   RDD of documents, which are term (word) count vectors paired with IDs.
     *                   The term count vectors are "bags of words" with a fixed-size vocabulary
     *                   (where the vocabulary size is the length of the vector).
     *                   Document IDs must be unique and >= 0.
     * @returns {LDAModel}   Inferred LDA model
     */
    LDA.prototype.run = function (documents) {
       var documents_uw = Utils.unwrapObject(documents);
       var javaObject =  this.getJavaObject().run(documents_uw);
       return Utils.javaToJs(javaObject);
    };

    module.exports = LDA;

}