Class StochasticForests

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.WindowListener, java.lang.Runnable, java.util.EventListener

    public class StochasticForests
    extends AlgorithmBase
    • Field Detail

      • mask

        static final int[] mask
      • offset

        static final int[] offset
      • DEFAULT_MIN_NODE_SIZE_CLASSIFICATION

        final int DEFAULT_MIN_NODE_SIZE_CLASSIFICATION
        See Also:
        Constant Field Values
      • DEFAULT_MIN_NODE_SIZE_REGRESSION

        final int DEFAULT_MIN_NODE_SIZE_REGRESSION
        See Also:
        Constant Field Values
      • DEFAULT_MIN_NODE_SIZE_SURVIVAL

        final int DEFAULT_MIN_NODE_SIZE_SURVIVAL
        See Also:
        Constant Field Values
      • DEFAULT_MIN_NODE_SIZE_PROBABILITY

        final int DEFAULT_MIN_NODE_SIZE_PROBABILITY
        See Also:
        Constant Field Values
      • RAND_MAX

        public static int RAND_MAX
      • logprop

        public static double logprop
      • testUtility

        private boolean testUtility
      • testMain

        private boolean testMain
      • probability

        private boolean probability
      • verbose_out

        private boolean verbose_out
      • dependent_variable_name

        private java.lang.String dependent_variable_name
      • input_file

        private java.lang.String input_file
      • mtry

        private int mtry
      • output_prefix

        private java.lang.String output_prefix
      • num_trees

        private int num_trees
      • seed

        private long seed
      • num_threads

        private int num_threads
      • load_forest_filename

        private java.lang.String load_forest_filename
      • min_node_size

        private int min_node_size
      • split_select_weights_file

        private java.lang.String split_select_weights_file
      • always_split_variable_names

        private java.util.Vector<java.lang.String> always_split_variable_names
      • status_variable_name

        private java.lang.String status_variable_name
      • sample_with_replacement

        private boolean sample_with_replacement
      • unordered_variable_names

        private java.util.Vector<java.lang.String> unordered_variable_names
      • memory_saving_splitting

        private boolean memory_saving_splitting
      • case_weights_file

        private java.lang.String case_weights_file
      • predict_all

        private boolean predict_all
      • sample_fraction

        private double sample_fraction
      • alpha

        private double alpha
      • minprop

        private double minprop
      • holdout

        private boolean holdout
      • num_random_splits

        private int num_random_splits
      • write

        private boolean write
    • Constructor Detail

      • StochasticForests

        public StochasticForests()
      • StochasticForests

        public StochasticForests​(StochasticForests.TreeType treetype,
                                 boolean probability,
                                 boolean verbose_out,
                                 java.lang.String dependent_variable_name,
                                 StochasticForests.MemoryMode memory_mode,
                                 java.lang.String input_file,
                                 int mtry,
                                 java.lang.String output_prefix,
                                 int num_trees,
                                 long seed,
                                 int num_threads,
                                 java.lang.String load_forest_filename,
                                 StochasticForests.ImportanceMode importance_mode,
                                 int min_node_size,
                                 java.lang.String split_select_weights_file,
                                 java.util.Vector<java.lang.String> always_split_variable_names,
                                 java.lang.String status_variable_name,
                                 boolean sample_with_replacement,
                                 java.util.Vector<java.lang.String> unordered_variable_names,
                                 boolean memory_saving_splitting,
                                 StochasticForests.SplitRule splitrule,
                                 java.lang.String case_weights_file,
                                 boolean predict_all,
                                 double sample_fraction,
                                 double alpha,
                                 double minprop,
                                 boolean holdout,
                                 StochasticForests.PredictionType prediction_type,
                                 int num_random_splits,
                                 boolean write)
    • Method Detail

      • order

        private java.util.Vector<java.lang.Integer> order​(java.util.Vector<java.lang.Double> x,
                                                          boolean decreasing)
      • rank

        java.util.Vector<java.lang.Double> rank​(java.util.Vector<java.lang.Double> values)
        Sample ranks starting from 1. Ties are given the average rank.
        Parameters:
        values - Values to rank
        Returns:
        Ranks of input values
      • roundToNextMultiple

        private int roundToNextMultiple​(int value,
                                        int multiple)
      • shuffle

        private void shuffle​(java.util.Vector<java.lang.Integer> v,
                             java.util.Random random)
      • equalSplit

        private void equalSplit​(java.util.Vector<java.lang.Integer> result,
                                int start,
                                int end,
                                int num_parts)
      • loadDoubleVectorFromFile

        void loadDoubleVectorFromFile​(java.util.Vector<java.lang.Double> result,
                                      java.lang.String filename)
      • drawWithoutReplacementSkip

        private void drawWithoutReplacementSkip​(java.util.Vector<java.lang.Integer> result,
                                                java.util.Random random,
                                                int max,
                                                java.util.Vector<java.lang.Integer> skip,
                                                int num_samples)
      • drawWithoutReplacementSimple

        private void drawWithoutReplacementSimple​(java.util.Vector<java.lang.Integer> result,
                                                  java.util.Random random,
                                                  int max,
                                                  java.util.Vector<java.lang.Integer> skip,
                                                  int num_samples)
      • drawWithoutReplacementFisherYates

        private void drawWithoutReplacementFisherYates​(java.util.Vector<java.lang.Integer> result,
                                                       java.util.Random random,
                                                       int max,
                                                       java.util.Vector<java.lang.Integer> skip,
                                                       int num_samples)
      • drawWithoutReplacementWeighted

        private void drawWithoutReplacementWeighted​(java.util.Vector<java.lang.Integer> result,
                                                    java.util.Random random,
                                                    java.util.Vector<java.lang.Integer> indices,
                                                    int num_samples,
                                                    java.util.Vector<java.lang.Double> weights)
      • drawWithoutReplacementWeighted

        private void drawWithoutReplacementWeighted​(java.util.Vector<java.lang.Integer> result,
                                                    java.util.Random random,
                                                    int max_index,
                                                    int num_samples,
                                                    java.util.Vector<java.lang.Double> weights)
      • mostFrequentClass

        private int mostFrequentClass​(java.util.Vector<java.lang.Integer> class_count,
                                      java.util.Random random)
        Returns the most frequent class index of a vector with counts for the classes. Returns a random class if counts are equal.
        Parameters:
        class_count - Vector with class counts
        random_number_generator - Random number generator
        Returns:
        Most frequent class index. Out of range index if all 0.
      • mostFrequentDClass

        private int mostFrequentDClass​(java.util.Vector<java.lang.Double> class_count,
                                       java.util.Random random)
        Returns the most frequent class index of a vector with counts for the classes. Returns a random class if counts are equal.
        Parameters:
        class_count - Vector with class counts
        random_number_generator - Random number generator
        Returns:
        Most frequent class index. Out of range index if all 0.
      • mostFrequentValue

        private double mostFrequentValue​(java.util.HashMap<java.lang.Double,​java.lang.Integer> class_count,
                                         java.util.Random random)
      • computeConcordanceIndex

        private double computeConcordanceIndex​(StochasticForests.Data data,
                                               java.util.Vector<java.lang.Double> sum_chf,
                                               int dependent_varID,
                                               int status_varID,
                                               java.util.Vector<java.lang.Integer> sample_IDs)
      • uintToString

        private java.lang.String uintToString​(int number)
      • beautifyTime

        private java.lang.String beautifyTime​(int seconds)
      • splitString

        private void splitString​(java.util.Vector<java.lang.String> result,
                                 java.lang.String input,
                                 java.lang.String split_string)
      • shuffleAndSplit

        private void shuffleAndSplit​(java.util.Vector<java.lang.Integer> first_part,
                                     java.util.Vector<java.lang.Integer> second_part,
                                     int n_all,
                                     int n_first,
                                     java.util.Random random)
      • shuffleAndSplitAppend

        private void shuffleAndSplitAppend​(java.util.Vector<java.lang.Integer> first_part,
                                           java.util.Vector<java.lang.Integer> second_part,
                                           int n_all,
                                           int n_first,
                                           java.util.Vector<java.lang.Integer> mapping,
                                           java.util.Random random)
      • checkUnorderedVariables

        private java.lang.String checkUnorderedVariables​(StochasticForests.Data data,
                                                         java.util.Vector<java.lang.String> unordered_variable_names)
      • checkPositiveIntegers

        private boolean checkPositiveIntegers​(java.util.Vector<java.lang.Double> all_values)
      • maxstatPValueLau92

        private double maxstatPValueLau92​(double b,
                                          double minprop,
                                          double maxprop)
      • maxstatPValueLau94

        private double maxstatPValueLau94​(double b,
                                          double minprop,
                                          double maxprop,
                                          int N,
                                          java.util.Vector<java.lang.Integer> m)
      • maxstatPValueUnadjusted

        private double maxstatPValueUnadjusted​(double b)
      • dstdnorm

        private double dstdnorm​(double x)
      • pstdnorm

        private double pstdnorm​(double x)
      • erf

        private double erf​(double x)
      • adjustPvalues

        private java.util.Vector<java.lang.Double> adjustPvalues​(java.util.Vector<java.lang.Double> unadjusted_pvalues)
      • logrankScores

        private java.util.Vector<java.lang.Double> logrankScores​(java.util.Vector<java.lang.Double> time,
                                                                 java.util.Vector<java.lang.Double> status)
      • maxstat

        private void maxstat​(java.util.Vector<java.lang.Double> scores,
                             java.util.Vector<java.lang.Double> x,
                             java.util.Vector<java.lang.Integer> indices,
                             double[] best_maxstat,
                             double[] best_split_value,
                             double minprop,
                             double maxprop)
      • numSamplesLeftOfCutpoint

        private java.util.Vector<java.lang.Integer> numSamplesLeftOfCutpoint​(java.util.Vector<java.lang.Double> x,
                                                                             java.util.Vector<java.lang.Integer> indices)
      • saveVector1D

        private void saveVector1D​(java.util.Vector<java.lang.Integer> vector,
                                  java.io.BufferedWriter bw)
        Write a 1d vector to filestream. First the size is written, then all vector elements.
        Parameters:
        vector - Vector of type T to save
        file - ofstream object to write to.
      • saveBVector1D

        private void saveBVector1D​(java.util.Vector<java.lang.Boolean> vector,
                                   java.io.BufferedWriter bw)
        Write a 1d vector to filestream. First the size is written, then all vector elements.
        Parameters:
        vector - Vector of type T to save
        file - ofstream object to write to.
      • readVector1D

        private void readVector1D​(java.util.Vector<java.lang.Integer> result,
                                  java.io.BufferedReader br)
        Read a 1d vector written by saveVector1D() from filestream.
        Parameters:
        result - Result vector with elements of type T.
        file - ifstream object to read from.
      • readBVector1D

        private void readBVector1D​(java.util.Vector<java.lang.Boolean> result,
                                   java.io.BufferedReader br)
        Read a 1d vector written by saveVector1D() from filestream.
        Parameters:
        result - Result vector with elements of type T.
        file - ifstream object to read from.
      • saveDVector1D

        private void saveDVector1D​(java.util.Vector<java.lang.Double> vector,
                                   java.io.BufferedWriter bw)
        Write a 1d vector to filestream. First the size is written, then all vector elements.
        Parameters:
        vector - Vector of type T to save
        file - ofstream object to write to.
      • readDVector1D

        private void readDVector1D​(java.util.Vector<java.lang.Double> result,
                                   java.io.BufferedReader br)
        Read a 1d vector written by saveVector1D() from filestream.
        Parameters:
        result - Result vector with elements of type T.
        file - ifstream object to read from.
      • saveVector2D

        private void saveVector2D​(java.util.Vector<java.util.Vector<java.lang.Integer>> vector,
                                  java.io.BufferedWriter bw)
        Write a 2d vector to filestream. First the size of the first dim is written as size_t, then for all inner vectors the size and elements.
        Parameters:
        vector - Vector of vectors of type T to write to file.
        file - ofstream object to write to.
      • readVector2D

        private void readVector2D​(java.util.Vector<java.util.Vector<java.lang.Integer>> result,
                                  java.io.BufferedReader br)
        Read a 2d vector written by saveVector2D() from filestream.
        Parameters:
        result - Result vector of vectors with elements of type T.
        file - ifstream object to read from.
      • saveDVector2D

        private void saveDVector2D​(java.util.Vector<java.util.Vector<java.lang.Double>> vector,
                                   java.io.BufferedWriter bw)
        Write a 2d vector to filestream. First the size of the first dim is written as size_t, then for all inner vectors the size and elements.
        Parameters:
        vector - Vector of vectors of type T to write to file.
        file - ofstream object to write to.
      • readDVector2D

        private void readDVector2D​(java.util.Vector<java.util.Vector<java.lang.Double>> result,
                                   java.io.BufferedReader br)
        Read a 2d vector written by saveVector2D() from filestream.
        Parameters:
        result - Result vector of vectors with elements of type T.
        file - ifstream object to read from.
      • equalVectorInteger

        private boolean equalVectorInteger​(java.util.Vector<java.lang.Integer> v1,
                                           java.util.Vector<java.lang.Integer> v2,
                                           java.lang.String str)
      • equalVectorVectorInteger

        private boolean equalVectorVectorInteger​(java.util.Vector<java.util.Vector<java.lang.Integer>> v1,
                                                 java.util.Vector<java.util.Vector<java.lang.Integer>> v2,
                                                 java.lang.String str)
      • equalVectorDouble

        private boolean equalVectorDouble​(java.util.Vector<java.lang.Double> v1,
                                          java.util.Vector<java.lang.Double> v2,
                                          java.lang.String str)
      • equalVectorVectorDouble

        private boolean equalVectorVectorDouble​(java.util.Vector<java.util.Vector<java.lang.Double>> v1,
                                                java.util.Vector<java.util.Vector<java.lang.Double>> v2,
                                                java.lang.String str)
      • expectNear

        private boolean expectNear​(double val1,
                                   double val2,
                                   double error,
                                   java.lang.String str)
      • runAlgorithm

        public void runAlgorithm()
        Description copied from class: AlgorithmBase
        Actually runs the algorithm. Implemented by inheriting algorithms.
        Specified by:
        runAlgorithm in class AlgorithmBase