Example usage for weka.core ProtectedProperties ProtectedProperties

List of usage examples for weka.core ProtectedProperties ProtectedProperties

Introduction

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

Prototype

public ProtectedProperties(Properties props) 

Source Link

Document

Creates a set of protected properties from a set of normal ones.

Usage

From source file:cn.ict.zyq.bestConf.bestConf.BestConf.java

License:Open Source License

public Instances loadPropertiesAsInstancesPre(String Path) {
    HashMap<String, String> pmap = null;
    try {/*from ww  w  .ja v a 2  s.  co  m*/
        pmap = Yaml.loadType(new FileInputStream(yamlPath), HashMap.class);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    atts = new ArrayList<Attribute>();
    Instance dfIns = new DenseInstance(pmap.size());
    int pos = 0;
    double[] vals = new double[pmap.size()];
    for (Map.Entry<String, String> ent : pmap.entrySet()) {
        try {
            double val = Double.valueOf(String.valueOf(ent.getValue()));
            vals[pos] = val;

            Properties p1 = new Properties();
            double upper, lower;
            if (val != 0) {
                upper = val * (1. + 0.5);
                lower = val * (1. - 0.5);
            } else {
                lower = val;
                upper = 1;
            }

            p1.setProperty("range", "[" + String.valueOf(lower) + "," + String.valueOf(upper) + "]");
            ProtectedProperties prop1 = new ProtectedProperties(p1);

            atts.add(new Attribute(String.valueOf(ent.getKey()), prop1));
            pos++;
        } catch (Exception e) {
        }
    }

    Instances dfProp = new Instances("DefaultConfig", atts, 1);
    dfProp.add(dfIns);
    dfIns.setDataset(dfProp);
    for (int i = 0; i < pos; i++) {
        dfIns.setValue(atts.get(i), vals[i]);
        //System.err.println(atts.get(i)+":"+vals[i]);
    }

    return dfProp;
}

From source file:cn.ict.zyq.bestConf.bestConf.BestConf.java

License:Open Source License

public Instances loadPropertiesAsInstances(String Path) {
    HashMap<String, String> pmap = null;
    HashMap rangeMap = null;//from   w  w w. java2 s.c o  m
    try {
        pmap = Yaml.loadType(new FileInputStream(yamlPath), HashMap.class);
        rangeMap = Yaml.loadType(new FileInputStream(yamlPath + "_range"), HashMap.class);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    atts = new ArrayList<Attribute>();
    int pos = 0;
    double[] vals = new double[pmap.size()];
    Object range = null;
    for (Map.Entry<String, String> ent : pmap.entrySet()) {
        try {
            double val = Double.valueOf(String.valueOf(ent.getValue()));
            vals[pos] = val;

            Properties p1 = new Properties();

            range = rangeMap.get(ent.getKey());
            if (range != null) {
                String list = (String) range;
                if (list.indexOf('[') == -1 && list.indexOf('(') == -1)
                    throw new Exception("No Range for You" + ent.getKey());
                p1.setProperty("range", list.trim());
            } else {
                double upper, lower;
                if (val != 0) {
                    upper = val * (1. + 0.5);
                    lower = val * (1. - 0.5);
                } else {
                    lower = val;
                    upper = 1;
                }
                p1.setProperty("range", "[" + String.valueOf(lower) + "," + String.valueOf(upper) + "]");
            }

            ProtectedProperties prop1 = new ProtectedProperties(p1);

            atts.add(new Attribute(String.valueOf(ent.getKey()), prop1));
            pos++;
        } catch (Exception e) {
        }
    }

    Instances dfProp = new Instances("DefaultConfig", atts, 1);
    Instance dfIns = new DenseInstance(atts.size());
    for (int i = 0; i < pos; i++) {
        dfIns.setValue(atts.get(i), vals[i]);
        //System.err.println(atts.get(i)+":"+vals[i]);
    }
    dfProp.add(dfIns);
    dfIns.setDataset(dfProp);

    return dfProp;
}

From source file:cn.ict.zyq.bestConf.bestConf.BestConf.java

License:Open Source License

public static ArrayList<Attribute> scaleDownDetour(Instances previousSet, Instance center) {
    ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
    int attNum = center.numAttributes();

    int pos = previousSet.attribute(PerformanceAttName).index();

    //traverse each dimension
    Enumeration<Instance> enu;
    double minDis;
    for (int i = 0; i < attNum; i++) {
        if (i == pos)
            continue;

        enu = previousSet.enumerateInstances();
        minDis = Double.MAX_VALUE;

        while (enu.hasMoreElements()) {
            Instance ins = enu.nextElement();
            if (!ins.equals(center))
                minDis = Math.min((double) ((int) (Math.abs(ins.value(i) - center.value(i)) * 100)) / 100.0,
                        minDis);/*ww  w . ja va 2s .c o m*/
        }

        //now we set the range
        Properties p1 = new Properties();
        double upper = center.value(i) + minDis, lower = center.value(i) - minDis;

        TreeSet<Double> detourSet = new TreeSet<Double>();
        detourSet.add(upper);
        detourSet.add(lower);
        detourSet.add(previousSet.attribute(i).getUpperNumericBound());
        detourSet.add(previousSet.attribute(i).getLowerNumericBound());
        switch (detourSet.size()) {
        case 1:
            upper = lower = detourSet.first();
            break;
        case 2:
            upper = detourSet.last();
            lower = detourSet.first();
            break;
        case 3:
            upper = lower = detourSet.higher(detourSet.first());
            break;
        default://case 4:
            upper = detourSet.lower(detourSet.last());
            lower = detourSet.higher(detourSet.first());
            break;
        }

        p1.setProperty("range", "[" + String.valueOf(lower) + "," + String.valueOf(upper) + "]");
        ProtectedProperties prop1 = new ProtectedProperties(p1);

        localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
    }

    return localAtts;
}

From source file:cn.ict.zyq.bestConf.bestConf.RBSoDDSOptimization.java

License:Open Source License

private ArrayList<Attribute> loadProps(String path) {
    ArrayList<Attribute> atts = new ArrayList<Attribute>();
    try {/* ww  w  . ja v a 2 s  .  c  om*/
        HashMap<String, ArrayList> rangeMap = Yaml.loadType(new FileInputStream(path), HashMap.class);

        for (Map.Entry<String, ArrayList> ent : rangeMap.entrySet()) {
            try {
                Properties p1 = new Properties();
                p1.setProperty("range", rangeArrayToStr(ent.getValue()));
                ProtectedProperties prop1 = new ProtectedProperties(p1);
                atts.add(new Attribute(String.valueOf(ent.getKey()), prop1));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return atts;
}

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

License:Open Source License

private static ArrayList<Attribute> scaleDownNeighbordists(Instances previousSet, Instance center) {
    ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
    int attNum = center.numAttributes();

    int pos = -1;
    if (previousSet.attribute(PerformanceAttName) != null)
        pos = previousSet.attribute(PerformanceAttName).index();

    //traverse each dimension
    Enumeration<Instance> enu;
    double[] minDists = new double[2];
    double val;
    for (int i = 0; i < attNum; i++) {
        if (i == pos)
            continue;

        enu = previousSet.enumerateInstances();
        minDists[0] = 1 - Double.MAX_VALUE;
        minDists[1] = Double.MAX_VALUE;

        while (enu.hasMoreElements()) {
            Instance ins = enu.nextElement();
            if (!ins.equals(center)) {
                val = ins.value(i) - center.value(i);
                if (val < 0)
                    minDists[0] = Math.max((double) ((int) ((ins.value(i) - center.value(i)) * 1000)) / 1000.0,
                            minDists[0]);
                else
                    minDists[1] = Math.min((double) ((int) ((ins.value(i) - center.value(i)) * 1000)) / 1000.0,
                            minDists[1]);
            }/*from  w ww  .jav  a  2s.  c  o m*/
        }

        //now we set the range
        Properties p1 = new Properties();
        double upper = center.value(i) + minDists[1], lower = center.value(i) + minDists[0];

        TreeSet<Double> detourSet = new TreeSet<Double>();
        detourSet.add(upper);
        detourSet.add(lower);
        detourSet.add(previousSet.attribute(i).getUpperNumericBound());
        detourSet.add(previousSet.attribute(i).getLowerNumericBound());
        switch (detourSet.size()) {
        case 1:
            upper = lower = detourSet.first();
            break;
        case 2:
            upper = detourSet.last();
            lower = detourSet.first();
            break;
        case 3:
            upper = lower = detourSet.higher(detourSet.first());
            break;
        default://case 4:
            upper = detourSet.lower(detourSet.last());
            lower = detourSet.higher(detourSet.first());
            break;
        }

        p1.setProperty("range", "[" + String.valueOf(lower) + "," + String.valueOf(upper) + "]");
        ProtectedProperties prop1 = new ProtectedProperties(p1);

        localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
    }

    return localAtts;
}

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

License:Open Source License

private static ArrayList<Attribute> scaleDownMindists(Instances previousSet, Instance center) {
    ArrayList<Attribute> localAtts = new ArrayList<Attribute>();
    int attNum = center.numAttributes();

    int pos = previousSet.attribute(PerformanceAttName).index();

    //traverse each dimension
    Enumeration<Instance> enu;
    double minDis;
    for (int i = 0; i < attNum; i++) {
        if (i == pos)
            continue;

        enu = previousSet.enumerateInstances();
        minDis = Double.MAX_VALUE;

        while (enu.hasMoreElements()) {
            Instance ins = enu.nextElement();
            if (!ins.equals(center))
                minDis = Math.min((double) ((int) (Math.abs(ins.value(i) - center.value(i)) * 1000)) / 1000.0,
                        minDis);/*  w ww.j  a  v a2 s  .c om*/
        }

        //now we set the range
        Properties p1 = new Properties();
        double upper = center.value(i) + minDis, lower = center.value(i) - minDis;

        TreeSet<Double> detourSet = new TreeSet<Double>();
        detourSet.add(upper);
        detourSet.add(lower);
        detourSet.add(previousSet.attribute(i).getUpperNumericBound());
        detourSet.add(previousSet.attribute(i).getLowerNumericBound());
        switch (detourSet.size()) {
        case 1:
            upper = lower = detourSet.first();
            break;
        case 2:
            upper = detourSet.last();
            lower = detourSet.first();
            break;
        case 3:
            upper = lower = detourSet.higher(detourSet.first());
            break;
        default://case 4:
            upper = detourSet.lower(detourSet.last());
            lower = detourSet.higher(detourSet.first());
            break;
        }

        p1.setProperty("range", "[" + String.valueOf(lower) + "," + String.valueOf(upper) + "]");
        ProtectedProperties prop1 = new ProtectedProperties(p1);

        localAtts.add(new Attribute(previousSet.attribute(i).name(), prop1));
    }

    return localAtts;
}

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

License:Open Source License

public static void main(String[] args) {
    ArrayList<Attribute> atts = new ArrayList<Attribute>();

    Properties p1 = new Properties();
    p1.setProperty("range", "[0,1]");
    ProtectedProperties prop1 = new ProtectedProperties(p1);

    Properties p2 = new Properties();
    p2.setProperty("range", "[321,1E9]");
    ProtectedProperties prop2 = new ProtectedProperties(p2);

    Properties p3 = new Properties();
    p3.setProperty("range", "[1,30]");
    ProtectedProperties prop3 = new ProtectedProperties(p3);

    ArrayList<String> attVals = new ArrayList<String>();
    for (int i = 0; i < 5; i++)
        attVals.add("val" + (i + 1));

    atts.add(new Attribute("att1", prop1));
    atts.add(new Attribute("att2", prop2));
    atts.add(new Attribute("att3", prop3));
    //atts.add(new Attribute("att4", attVals));
    //Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
    //Instances data = LHSInitializer.getMultiDim(atts, 10, false);
    DDSSampler sampler = new DDSSampler(3);

    sampler.setCurrentRound(0);/*from  w  w w .  j  a v a 2 s  .co  m*/
    Instances data = sampler.sampleMultiDimContinuous(atts, 2, false);
    System.out.println(data);

    sampler.setCurrentRound(01);
    data = sampler.sampleMultiDimContinuous(atts, 2, false);
    System.out.println(data);

    sampler.setCurrentRound(2);
    data = sampler.sampleMultiDimContinuous(atts, 2, false);
    System.out.println(data);
}

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

License:Open Source License

public static void main(String[] args) {
    ArrayList<Attribute> atts = new ArrayList<Attribute>();

    /*Properties p1 = new Properties();
    p1.setProperty("range", "[0,1]");/*from  w  w  w.java2 s  . c  o  m*/
    ProtectedProperties prop1 = new ProtectedProperties(p1);*/

    Properties p2 = new Properties();
    p2.setProperty("range", "[321,1E9]");
    ProtectedProperties prop2 = new ProtectedProperties(p2);

    ArrayList<String> attVals = new ArrayList<String>();
    for (int i = 0; i < 5; i++)
        attVals.add("val" + (i + 1));

    //atts.add(new Attribute("att1", prop1));
    atts.add(new Attribute("att2", prop2));
    //atts.add(new Attribute("att3", attVals));
    //Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
    //Instances data = LHSInitializer.getMultiDim(atts, 10, false);
    LHSSampler sampler = new LHSSampler();
    Instances data = sampler.sampleMultiDimContinuous(atts, 1, false);

    System.out.println(data);
}

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

License:Open Source License

public static void main(String[] args) {
    ArrayList<Attribute> atts = new ArrayList<Attribute>();

    /*Properties p1 = new Properties();
    p1.setProperty("range", "[0,1]");//from  w w  w .j  a va2s .  c om
    ProtectedProperties prop1 = new ProtectedProperties(p1);*/

    Properties p2 = new Properties();
    p2.setProperty("range", "[321,1E9]");
    ProtectedProperties prop2 = new ProtectedProperties(p2);

    ArrayList<String> attVals = new ArrayList<String>();
    for (int i = 0; i < 5; i++)
        attVals.add("val" + (i + 1));

    //atts.add(new Attribute("att1", prop1));
    atts.add(new Attribute("att2", prop2));
    //atts.add(new Attribute("att3", attVals));
    //Instances data = LHSInitializer.getMultiDimContinuous(atts, 10, false);
    //Instances data = LHSInitializer.getMultiDim(atts, 10, false);
    Instances data = LHSInitializer.getMultiDimContinuous(atts, 1, false);

    System.out.println(data);
}