Example usage for weka.core Attribute getLowerNumericBound

List of usage examples for weka.core Attribute getLowerNumericBound

Introduction

In this page you can find the example usage for weka.core Attribute getLowerNumericBound.

Prototype

public finaldouble getLowerNumericBound() 

Source Link

Document

Returns the lower bound of a numeric attribute.

Usage

From source file:cn.ict.zyq.bestConf.bestConf.sampler.DDSSampler.java

License:Open Source License

private static void uniBoundsGeneration(double[] bounds, Attribute crntAttr, int sampleSetSize) {
    bounds[0] = crntAttr.getLowerNumericBound();
    bounds[sampleSetSize] = crntAttr.getUpperNumericBound();
    double pace = (bounds[sampleSetSize] - bounds[0]) / sampleSetSize;
    for (int j = 1; j < sampleSetSize; j++) {
        bounds[j] = bounds[j - 1] + pace;
    }/* w  ww  .j av a2  s.c  om*/
}

From source file:cn.ict.zyq.bestConf.bestConf.sampler.LHSSampler.java

License:Open Source License

/**
 * Assumptions:(1)Numberic is continuous and has lower/upper bounds; (2) Nominals have domains permutable
 * //from   www  .  j  av  a 2s  .co  m
 * @param useMid true if to use the middle point of a subdomain, false if to use a random point within a subdomain
 */
private static Instances getMultiDim(ArrayList<Attribute> atts, int sampleSetSize, boolean useMid) {

    int L = Math.min(7, Math.max(sampleSetSize, atts.size()));//7 is chosen for no special reason
    double maxMinDist = 0, crntMinDist;//work as the threshold to select the sample set
    ArrayList<Integer>[] setWithMaxMinDist = null;
    //generate L sets of sampleSetSize points
    for (int i = 0; i < L; i++) {
        ArrayList<Integer>[] setPerm = generateOneSampleSet(sampleSetSize, atts.size());
        //compute the minimum distance minDist between any sample pair for each set
        crntMinDist = minDistForSet(setPerm);
        //select the set with the maximum minDist
        if (crntMinDist > maxMinDist) {
            setWithMaxMinDist = setPerm;
            maxMinDist = crntMinDist;
        }
    }

    //generate and output the set with the maximum minDist as the result

    //first, divide the domain of each attribute into sampleSetSize equal subdomain
    double[][] bounds = new double[atts.size()][sampleSetSize + 1];//sampleSetSize+1 to include the lower and upper bounds
    Iterator<Attribute> itr = atts.iterator();
    Attribute crntAttr;
    double pace;
    for (int i = 0; i < bounds.length; i++) {
        crntAttr = itr.next();

        if (crntAttr.isNumeric()) {
            bounds[i][0] = crntAttr.getLowerNumericBound();
            bounds[i][sampleSetSize] = crntAttr.getUpperNumericBound();
            pace = (crntAttr.getUpperNumericBound() - crntAttr.getLowerNumericBound()) / sampleSetSize;
            for (int j = 1; j < sampleSetSize; j++) {
                bounds[i][j] = bounds[i][j - 1] + pace;
            }
        } else {//crntAttr.isNominal()
            if (crntAttr.numValues() >= sampleSetSize) {
                //randomly select among the set
                for (int j = 0; j <= sampleSetSize; j++)
                    bounds[i][j] = uniRand.nextInt(crntAttr.numValues());//the position of one of the nominal values
            } else {
                //first round-robin
                int lastPart = sampleSetSize % crntAttr.numValues();
                for (int j = 0; j < sampleSetSize - lastPart; j++)
                    bounds[i][j] = j % crntAttr.numValues();
                //then randomly select
                for (int j = sampleSetSize - lastPart; j <= sampleSetSize; j++)
                    bounds[i][j] = uniRand.nextInt(crntAttr.numValues());
            }
        } //nominal attribute
    } //get all subdomains

    //second, generate the set according to setWithMaxMinDist
    Instances data = new Instances("InitialSetByLHS", atts, sampleSetSize);
    for (int i = 0; i < sampleSetSize; i++) {
        double[] vals = new double[atts.size()];
        for (int j = 0; j < vals.length; j++) {
            if (atts.get(j).isNumeric()) {
                vals[j] = useMid
                        ? (bounds[j][setWithMaxMinDist[j].get(i)] + bounds[j][setWithMaxMinDist[j].get(i) + 1])
                                / 2
                        : bounds[j][setWithMaxMinDist[j].get(i)] + ((bounds[j][setWithMaxMinDist[j].get(i) + 1]
                                - bounds[j][setWithMaxMinDist[j].get(i)]) * uniRand.nextDouble());
            } else {//isNominal()
                vals[j] = bounds[j][setWithMaxMinDist[j].get(i)];
            }
        }
        data.add(new DenseInstance(1.0, vals));
    }

    //third, return the generated points
    return data;
}

From source file:cn.ict.zyq.bestConf.bestConf.sampler.LHSSampler.java

License:Open Source License

private static void flexibleBoundsGeneration(double[] bounds, Attribute crntAttr, int sampleSetSize) {
    int howGen = 0;//div
    int step, crntStep;
    double pace;/*ww  w .j a va2s  .  c  o  m*/

    bounds[0] = crntAttr.getLowerNumericBound();
    bounds[sampleSetSize] = crntAttr.getUpperNumericBound();

    pace = (bounds[sampleSetSize] - bounds[0]) / sampleSetSize;
    crntStep = bounds[0] > 1 ? (int) Math.log10(bounds[sampleSetSize] / bounds[0])
            : (int) Math.log10(bounds[sampleSetSize]);
    if (crntStep > 0)
        step = sampleSetSize / crntStep;//num of points drawn after the multiplication of 10
    else
        step = 11;//anything larger than 10

    if (sampleSetSize < crntStep) {
        howGen = 3;
    } else if (0 < step && step < 10)//each hierarchy has fewer than 10 points
        howGen = 1;
    else if ((bounds[0] > 1 && (int) Math.log10(pace / bounds[0]) > BigStepPower)
            || (bounds[0] < 1 && (int) Math.log10(pace) > BigStepPower))//a big first step
        howGen = 2;
    else
        howGen = 0;

    switch (howGen) {
    case 1://use log
        int left = sampleSetSize % crntStep;
        while (bounds[0] == 0)
            bounds[0] = uniRand.nextInt(10);
        crntStep = 1;
        double theBound = bounds[sampleSetSize] / 10;
        for (int j = 1; j < sampleSetSize; j++) {
            //step?
            if (crntStep >= step && bounds[j - 1] <= theBound)
                crntStep = 0;

            if (crntStep == 0)
                bounds[j] = bounds[j - step] * 10;
            else if (crntStep < step)
                bounds[j] = bounds[j - crntStep] * ((double) crntStep * 10. / ((double) step + 1.));
            else//(crntStep>=step)
                bounds[j] = bounds[j - crntStep] * ((double) crntStep * 10. / (double) (left + step + 1));

            if (bounds[j] >= bounds[sampleSetSize]) {
                bounds[j] = bounds[sampleSetSize] - Math.random() * pace;
                System.err.println("============Be careful!!!!=============");
            }
            crntStep++;
        }
        break;
    case 2://first log, then pace
        //for smaller than pace
        int count = 0;
        while (bounds[count] < pace && count < sampleSetSize - 1) {
            count++;
            bounds[count] = bounds[count - 1] * 10;
        }
        //for larger than pace
        pace = (bounds[sampleSetSize] - bounds[count]) / (sampleSetSize - count);
        for (int j = count; j < sampleSetSize; j++) {
            bounds[j] = bounds[j - 1] + pace;
        }
        break;
    case 3://randomly choices
        pace = bounds[sampleSetSize] - bounds[0];
        for (int j = 1; j < sampleSetSize; j++) {
            bounds[j] = bounds[0] + Math.random() * pace;
        }
        break;
    default:
        for (int j = 1; j < sampleSetSize; j++) {
            bounds[j] = bounds[j - 1] + pace;
        }
        break;
    }
}

From source file:cn.ict.zyq.bestConf.bestConf.sampler.LHSSampler.java

License:Open Source License

/**
 * At current version, we assume all attributes are numeric attributes with bounds
 * //from   w w w .jav a2s . c o  m
 * Let PACE be upper-lower DIVided by the sampleSetSize
 * 
 * @param useMid true if to use the middle point of a subdomain, false if to use a random point within a subdomain
 */
private static Instances getMultiDimContinuousDiv(ArrayList<Attribute> atts, int sampleSetSize,
        boolean useMid) {

    int L = Math.min(7, Math.max(sampleSetSize, atts.size()));//7 is chosen for no special reason
    double maxMinDist = 0, crntMinDist;//work as the threshold to select the sample set
    ArrayList<Integer>[] setWithMaxMinDist = null;
    //generate L sets of sampleSetSize points
    for (int i = 0; i < L; i++) {
        ArrayList<Integer>[] setPerm = generateOneSampleSet(sampleSetSize, atts.size());
        //compute the minimum distance minDist between any sample pair for each set
        crntMinDist = minDistForSet(setPerm);
        //select the set with the maximum minDist
        if (crntMinDist > maxMinDist) {
            setWithMaxMinDist = setPerm;
            maxMinDist = crntMinDist;
        }
    }

    //generate and output the set with the maximum minDist as the result

    //first, divide the domain of each attribute into sampleSetSize equal subdomain
    double[][] bounds = new double[atts.size()][sampleSetSize + 1];//sampleSetSize+1 to include the lower and upper bounds
    Iterator<Attribute> itr = atts.iterator();
    Attribute crntAttr;
    double pace;
    for (int i = 0; i < bounds.length; i++) {
        crntAttr = itr.next();

        bounds[i][0] = crntAttr.getLowerNumericBound();
        bounds[i][sampleSetSize] = crntAttr.getUpperNumericBound();
        pace = (bounds[i][sampleSetSize] - bounds[i][0]) / sampleSetSize;
        for (int j = 1; j < sampleSetSize; j++) {
            bounds[i][j] = bounds[i][j - 1] + pace;
        }
    }

    //second, generate the set according to setWithMaxMinDist
    Instances data = new Instances("InitialSetByLHS", atts, sampleSetSize);
    for (int i = 0; i < sampleSetSize; i++) {
        double[] vals = new double[atts.size()];
        for (int j = 0; j < vals.length; j++) {
            vals[j] = useMid
                    ? (bounds[j][setWithMaxMinDist[j].get(i)] + bounds[j][setWithMaxMinDist[j].get(i) + 1]) / 2
                    : bounds[j][setWithMaxMinDist[j].get(i)] + ((bounds[j][setWithMaxMinDist[j].get(i) + 1]
                            - bounds[j][setWithMaxMinDist[j].get(i)]) * uniRand.nextDouble());
        }
        data.add(new DenseInstance(1.0, vals));
    }

    //third, return the generated points
    return data;
}

From source file:cn.ict.zyq.bestConf.util.LHSInitializer.java

License:Open Source License

/**
 * Assumptions:(1)Numberic is continuous and has lower/upper bounds; (2) Nominals have domains permutable
 * //from w  w w  .  j  a v  a  2s. c  om
 * @param useMid true if to use the middle point of a subdomain, false if to use a random point within a subdomain
 */
public static Instances getMultiDim(ArrayList<Attribute> atts, int sampleSetSize, boolean useMid) {

    int L = Math.min(7, Math.max(sampleSetSize, atts.size()));//7 is chosen for no special reason
    double maxMinDist = 0, crntMinDist;//work as the threshold to select the sample set
    ArrayList<Integer>[] setWithMaxMinDist = null;
    //generate L sets of sampleSetSize points
    for (int i = 0; i < L; i++) {
        ArrayList<Integer>[] setPerm = generateOneSampleSet(sampleSetSize, atts.size());
        //compute the minimum distance minDist between any sample pair for each set
        crntMinDist = minDistForSet(setPerm);
        //select the set with the maximum minDist
        if (crntMinDist > maxMinDist) {
            setWithMaxMinDist = setPerm;
            maxMinDist = crntMinDist;
        }
    }

    //generate and output the set with the maximum minDist as the result

    //first, divide the domain of each attribute into sampleSetSize equal subdomain
    double[][] bounds = new double[atts.size()][sampleSetSize + 1];//sampleSetSize+1 to include the lower and upper bounds
    Iterator<Attribute> itr = atts.iterator();
    Attribute crntAttr;
    double pace;
    for (int i = 0; i < bounds.length; i++) {
        crntAttr = itr.next();

        if (crntAttr.isNumeric()) {
            bounds[i][0] = crntAttr.getLowerNumericBound();
            bounds[i][sampleSetSize] = crntAttr.getUpperNumericBound();
            pace = (crntAttr.getUpperNumericBound() - crntAttr.getLowerNumericBound()) / sampleSetSize;
            for (int j = 1; j < sampleSetSize; j++) {
                bounds[i][j] = bounds[i][j - 1] + pace;
            }
        } else {//crntAttr.isNominal()
            if (crntAttr.numValues() >= sampleSetSize) {
                //randomly select among the set
                for (int j = 0; j <= sampleSetSize; j++)
                    bounds[i][j] = uniRand.nextInt(crntAttr.numValues());//the position of one of the nominal values
            } else {
                //first round-robin
                int lastPart = sampleSetSize % crntAttr.numValues();
                for (int j = 0; j < sampleSetSize - lastPart; j++)
                    bounds[i][j] = j % crntAttr.numValues();
                //then randomly select
                for (int j = sampleSetSize - lastPart; j <= sampleSetSize; j++)
                    bounds[i][j] = uniRand.nextInt(crntAttr.numValues());
            }
        } //nominal attribute
    } //get all subdomains

    //second, generate the set according to setWithMaxMinDist
    Instances data = new Instances("InitialSetByLHS", atts, sampleSetSize);
    for (int i = 0; i < sampleSetSize; i++) {
        double[] vals = new double[atts.size()];
        for (int j = 0; j < vals.length; j++) {
            if (atts.get(j).isNumeric()) {
                vals[j] = useMid
                        ? (bounds[j][setWithMaxMinDist[j].get(i)] + bounds[j][setWithMaxMinDist[j].get(i) + 1])
                                / 2
                        : bounds[j][setWithMaxMinDist[j].get(i)] + ((bounds[j][setWithMaxMinDist[j].get(i) + 1]
                                - bounds[j][setWithMaxMinDist[j].get(i)]) * uniRand.nextDouble());
            } else {//isNominal()
                vals[j] = bounds[j][setWithMaxMinDist[j].get(i)];
            }
        }
        data.add(new DenseInstance(1.0, vals));
    }

    //third, return the generated points
    return data;
}

From source file:cn.ict.zyq.bestConf.util.LHSInitializer.java

License:Open Source License

/**
 * At current version, we assume all attributes are numeric attributes with bounds
 * //from   w  ww  .  jav  a2  s . c o  m
 * Let PACE be log10(upper/lower)
 * 
 * @param useMid true if to use the middle point of a subdomain, false if to use a random point within a subdomain
 */
public static Instances getMultiDimContinuousLog(ArrayList<Attribute> atts, int sampleSetSize, boolean useMid) {

    int L = Math.min(7, Math.max(sampleSetSize, atts.size()));//7 is chosen for no special reason
    double maxMinDist = 0, crntMinDist;//work as the threshold to select the sample set
    ArrayList<Integer>[] setWithMaxMinDist = null;
    //generate L sets of sampleSetSize points
    for (int i = 0; i < L; i++) {
        ArrayList<Integer>[] setPerm = generateOneSampleSet(sampleSetSize, atts.size());
        //compute the minimum distance minDist between any sample pair for each set
        crntMinDist = minDistForSet(setPerm);
        //select the set with the maximum minDist
        if (crntMinDist > maxMinDist) {
            setWithMaxMinDist = setPerm;
            maxMinDist = crntMinDist;
        }
    }

    //generate and output the set with the maximum minDist as the result

    //first, divide the domain of each attribute into sampleSetSize equal subdomain
    double[][] bounds = new double[atts.size()][sampleSetSize + 1];//sampleSetSize+1 to include the lower and upper bounds
    Iterator<Attribute> itr = atts.iterator();
    Attribute crntAttr;
    int step, crntStep;
    for (int i = 0; i < bounds.length; i++) {
        crntAttr = itr.next();

        bounds[i][0] = crntAttr.getLowerNumericBound();
        bounds[i][sampleSetSize] = crntAttr.getUpperNumericBound();
        crntStep = (int) Math.log10(bounds[i][sampleSetSize] - bounds[i][0]);
        step = sampleSetSize / crntStep;//num of points drawn after the multiplication of 10
        int left = sampleSetSize % crntStep;
        if (bounds[i][0] == 0)
            bounds[i][0] = uniRand.nextInt(10);
        crntStep = 1;
        double theBound = bounds[i][sampleSetSize] / 10;
        for (int j = 1; j < sampleSetSize; j++) {
            if (crntStep >= step && bounds[i][j - 1] <= theBound)
                crntStep = 0;

            if (crntStep == 0)
                bounds[i][j] = bounds[i][j - step] * 10;
            else if (crntStep < step)
                bounds[i][j] = bounds[i][j - crntStep] * ((double) crntStep * 10. / ((double) step + 1.));
            else if (crntStep >= step)
                bounds[i][j] = bounds[i][j - crntStep] * ((double) crntStep * 10. / (double) (left + step + 1));

            if (bounds[i][j] >= bounds[i][sampleSetSize])
                System.err.println("be careful!!!!");
            crntStep++;
        }
    }

    //second, generate the set according to setWithMaxMinDist
    Instances data = new Instances("InitialSetByLHS", atts, sampleSetSize);
    for (int i = 0; i < sampleSetSize; i++) {
        double[] vals = new double[atts.size()];
        for (int j = 0; j < vals.length; j++) {
            vals[j] = useMid
                    ? (bounds[j][setWithMaxMinDist[j].get(i)] + bounds[j][setWithMaxMinDist[j].get(i) + 1]) / 2
                    : bounds[j][setWithMaxMinDist[j].get(i)] + ((bounds[j][setWithMaxMinDist[j].get(i) + 1]
                            - bounds[j][setWithMaxMinDist[j].get(i)]) * uniRand.nextDouble());
        }
        data.add(new DenseInstance(1.0, vals));
    }

    //third, return the generated points
    return data;
}

From source file:cn.ict.zyq.bestConf.util.LHSInitializer.java

License:Open Source License

private static void flexibleBoundsGeneration(double[] bounds, Attribute crntAttr, int sampleSetSize) {
    int howGen = 0;//div
    int step, crntStep;
    double pace;/*from   w w  w .jav  a2  s.  c  o m*/

    bounds[0] = crntAttr.getLowerNumericBound();
    bounds[sampleSetSize] = crntAttr.getUpperNumericBound();

    pace = (bounds[sampleSetSize] - bounds[0]) / sampleSetSize;
    crntStep = bounds[0] > 1 ? (int) Math.log10(bounds[sampleSetSize] / bounds[0])
            : (int) Math.log10(bounds[sampleSetSize]);
    if (crntStep > 0)
        step = sampleSetSize / crntStep;//num of points drawn after the multiplication of 10
    else
        step = 11;//anything larger than 10

    if (sampleSetSize < crntStep) {
        howGen = 3;
    } else if (0 < step && step < 10)//each hierarchy has fewer than 10 points
        howGen = 1;
    else if ((bounds[0] > 1 && (int) Math.log10(pace / bounds[0]) > BigStepPower)
            || (bounds[0] < 1 && (int) Math.log10(pace) > BigStepPower))//a big first step
        howGen = 2;
    else
        howGen = 0;

    switch (howGen) {
    case 1://use log
        int left = sampleSetSize % crntStep;//????
        while (bounds[0] == 0)
            bounds[0] = uniRand.nextInt(10);
        crntStep = 1;
        double theBound = bounds[sampleSetSize] / 10;
        for (int j = 1; j < sampleSetSize; j++) {
            //step?
            if (crntStep >= step && bounds[j - 1] <= theBound)
                crntStep = 0;

            if (crntStep == 0)
                bounds[j] = bounds[j - step] * 10;
            else if (crntStep < step)
                bounds[j] = bounds[j - crntStep] * ((double) crntStep * 10. / ((double) step + 1.));
            else//(crntStep>=step)
                bounds[j] = bounds[j - crntStep] * ((double) crntStep * 10. / (double) (left + step + 1));

            if (bounds[j] >= bounds[sampleSetSize]) {
                bounds[j] = bounds[sampleSetSize] - Math.random() * pace;
                System.err.println("============Be careful!!!!=============");
            }
            crntStep++;
        }
        break;
    case 2://first log, then pace
        //for smaller than pace
        int count = 0;
        while (bounds[count] < pace && count < sampleSetSize - 1) {
            count++;
            bounds[count] = bounds[count - 1] * 10;
        }
        //for larger than pace
        pace = (bounds[sampleSetSize] - bounds[count]) / (sampleSetSize - count);
        for (int j = count; j < sampleSetSize; j++) {
            bounds[j] = bounds[j - 1] + pace;
        }
        break;
    case 3://randomly choices
        pace = bounds[sampleSetSize] - bounds[0];
        for (int j = 1; j < sampleSetSize; j++) {
            bounds[j] = bounds[0] + Math.random() * pace;
        }
        break;
    default:
        for (int j = 1; j < sampleSetSize; j++) {
            bounds[j] = bounds[j - 1] + pace;
        }
        break;
    }
}

From source file:cn.ict.zyq.bestConf.util.LHSInitializer.java

License:Open Source License

/**
 * At current version, we assume all attributes are numeric attributes with bounds
 * //  ww  w .j  a va  2 s  .  c  o m
 * Let PACE be upper-lower DIVided by the sampleSetSize
 * 
 * @param useMid true if to use the middle point of a subdomain, false if to use a random point within a subdomain
 */
public static Instances getMultiDimContinuousDiv(ArrayList<Attribute> atts, int sampleSetSize, boolean useMid) {

    int L = Math.min(7, Math.max(sampleSetSize, atts.size()));//7 is chosen for no special reason
    double maxMinDist = 0, crntMinDist;//work as the threshold to select the sample set
    ArrayList<Integer>[] setWithMaxMinDist = null;
    //generate L sets of sampleSetSize points
    for (int i = 0; i < L; i++) {
        ArrayList<Integer>[] setPerm = generateOneSampleSet(sampleSetSize, atts.size());
        //compute the minimum distance minDist between any sample pair for each set
        crntMinDist = minDistForSet(setPerm);
        //select the set with the maximum minDist
        if (crntMinDist > maxMinDist) {
            setWithMaxMinDist = setPerm;
            maxMinDist = crntMinDist;
        }
    }

    //generate and output the set with the maximum minDist as the result

    //first, divide the domain of each attribute into sampleSetSize equal subdomain
    double[][] bounds = new double[atts.size()][sampleSetSize + 1];//sampleSetSize+1 to include the lower and upper bounds
    Iterator<Attribute> itr = atts.iterator();
    Attribute crntAttr;
    double pace;
    for (int i = 0; i < bounds.length; i++) {
        crntAttr = itr.next();

        bounds[i][0] = crntAttr.getLowerNumericBound();
        bounds[i][sampleSetSize] = crntAttr.getUpperNumericBound();
        pace = (bounds[i][sampleSetSize] - bounds[i][0]) / sampleSetSize;
        for (int j = 1; j < sampleSetSize; j++) {
            bounds[i][j] = bounds[i][j - 1] + pace;
        }
    }

    //second, generate the set according to setWithMaxMinDist
    Instances data = new Instances("InitialSetByLHS", atts, sampleSetSize);
    for (int i = 0; i < sampleSetSize; i++) {
        double[] vals = new double[atts.size()];
        for (int j = 0; j < vals.length; j++) {
            vals[j] = useMid
                    ? (bounds[j][setWithMaxMinDist[j].get(i)] + bounds[j][setWithMaxMinDist[j].get(i) + 1]) / 2
                    : bounds[j][setWithMaxMinDist[j].get(i)] + ((bounds[j][setWithMaxMinDist[j].get(i) + 1]
                            - bounds[j][setWithMaxMinDist[j].get(i)]) * uniRand.nextDouble());
        }
        data.add(new DenseInstance(1.0, vals));
    }

    //third, return the generated points
    return data;
}