List of usage examples for weka.core Instances Instances
public Instances(String name, ArrayList<Attribute> attInfo, int capacity)
From source file:edu.oregonstate.eecs.mcplan.ml.GameTreeStateSimilarityDataset.java
License:Open Source License
@Override public void run() { System.out.println("*** Extracting state nodes"); final Visitor visitor = new Visitor(); tree_.root().accept(visitor);//w ww . j a va2s.c o m // This extracts only the level-1 nodes. // TODO: Do this somewhere better. final HashMap<List<ActionNode<S, A>>, List<StateNode<S, A>>> tx = new HashMap<List<ActionNode<S, A>>, List<StateNode<S, A>>>(); final ArrayList<StateNode<S, A>> depth_1 = new ArrayList<StateNode<S, A>>(); for (final Map.Entry<List<ActionNode<S, A>>, List<StateNode<S, A>>> e : visitor.xs.entrySet()) { if (e.getKey() == null || e.getKey().size() != 1) { continue; } else { depth_1.addAll(e.getValue()); } } tx.put(null, depth_1); final Comparator<Instance> weight_comp = new Comparator<Instance>() { @Override public int compare(final Instance a, final Instance b) { return (int) Math.signum(a.weight() - b.weight()); } }; final int max_cap = max_instances_ + 1; final PriorityQueue<Instance> positive = new PriorityQueue<Instance>(max_cap, weight_comp); final PriorityQueue<Instance> negative = new PriorityQueue<Instance>(max_cap, weight_comp); System.out.println("*** Building Instances"); for (final Map.Entry<List<ActionNode<S, A>>, List<StateNode<S, A>>> e : tx.entrySet()) { System.out.println("***** key = " + e.getKey() + ", value.size() = " + e.getValue().size()); final String name = (e.getKey() != null ? e.getKey().toString() : "null"); final List<StateNode<S, A>> values = e.getValue(); final int[] num_instances = { 0, 0 }; int count = 0; for (int i = 0; i < values.size(); ++i) { for (int j = i + 1; j < values.size(); ++j) { if (count++ % 100 == 0) { System.out.println("***** instance " + (count - 1)); } final StateNode<S, A> s_i = values.get(i); final StateNode<S, A> s_j = values.get(j); if (s_i.n() < min_samples_ || s_j.n() < min_samples_) { System.out.println("! skipping under-sampled state pair"); continue; } final double[] phi_i = s_i.token.phi(); final double[] phi_j = s_j.token.phi(); assert (phi_i.length == phi_j.length); if (phi_i.length != attributes_.size() - 1) { System.out.println("! phi_i.length = " + phi_i.length); System.out.println("! attributes_.size() = " + attributes_.size()); } assert (phi_i.length == attributes_.size() - 1); // Feature vector is absolute difference of the two state // feature vectors. final double[] phi_labeled = new double[phi_i.length + 1]; for (int k = 0; k < phi_i.length; ++k) { phi_labeled[k] = Math.abs(phi_i[k] - phi_j[k]); } final Tuple2<Integer, Double> labeled = label(e.getKey(), player_, s_i, s_j); final int label = labeled._1; final double weight = labeled._2; final String label_string = Integer.toString(label); phi_labeled[label_index] = label; //attributes.get( label_index ).indexOfValue( label_string ); num_instances[label] += 1; final Instance instance = new DenseInstance(weight, phi_labeled); if (label == 0) { negative.add(instance); if (negative.size() >= max_cap) { negative.poll(); } } else { positive.add(instance); if (positive.size() >= max_cap) { positive.poll(); } } } // for j } // for i System.out.println("num_instances = " + Arrays.toString(num_instances)); final Instances x = new Instances(name, attributes_, negative.size() + positive.size()); x.setClassIndex(label_index); x.addAll(negative); x.addAll(positive); xs_.put(e.getKey(), x); } }
From source file:edu.stanford.rsl.conrad.segmentation.GLCMFeatureExtractor.java
License:Open Source License
@Override public void configure() throws Exception { patchSize = UserUtil.queryInt("Set GLCM patch size", patchSize); imagelevels = UserUtil.queryInt("Set number of different grey levels", imagelevels); configured = true;/*from w w w .j a v a 2s . c om*/ String[] nameString = { "angular second moment", "contrast", "correlation", "variance", "linear difference moment", "entropy", "energy", "homogenity", "inertia" }; if (this.dataGrid instanceof MultiChannelGrid2D) { MultiChannelGrid2D multiChannelGrid = (MultiChannelGrid2D) this.dataGrid; attribs = new ArrayList<Attribute>(GLCMnumFeatures * multiChannelGrid.getNumberOfChannels() + 1); for (int i = 0; i < multiChannelGrid.getNumberOfChannels(); i++) { for (int j = 0; j < GLCMnumFeatures; j++) { String name = "Slice " + i + ": GLCM " + nameString[j]; attribs.add(new weka.core.Attribute(name)); } } } else { attribs = new ArrayList<Attribute>(GLCMnumFeatures + 1); for (int j = 0; j < GLCMnumFeatures; j++) { String name = "Slice " + j + ": GLCM " + nameString[j]; attribs.add(new weka.core.Attribute(name)); } } Attribute classAttribute = generateClassAttribute(); attribs.add(classAttribute); // leeres set von feature vectoren instances = new Instances(className, attribs, 0); instances.setClass(classAttribute); }
From source file:edu.stanford.rsl.conrad.segmentation.GridFeatureExtractor.java
License:Open Source License
public void clearInstances(Attribute classAttribute) { // leeres set von feature vectoren instances = new Instances(className, attribs, 0); instances.setClass(classAttribute);/*from www . j a va2 s. c o m*/ }
From source file:edu.stanford.rsl.conrad.segmentation.HistogramFeatureExtractor.java
License:Open Source License
@Override public void configure() throws Exception { patchSize = UserUtil.queryInt("Set histogram patch size", patchSize); numberOfBins = UserUtil.queryInt("Select number of histogram bins", numberOfBins); min = (float) UserUtil.queryDouble("Minimal histogram value", min); max = (float) UserUtil.queryDouble("Maximal histogram value ", max); configured = true;/*from ww w . java 2s . c o m*/ String[] nameString = { "mean grey value", "standard deviation", "entropy", "coefficient of variance", "skewness", "kurtosis" }; if (this.dataGrid instanceof MultiChannelGrid2D) { MultiChannelGrid2D multiChannelGrid = (MultiChannelGrid2D) this.dataGrid; attribs = new ArrayList<Attribute>(HistoFeatures * multiChannelGrid.getNumberOfChannels() + 1); for (int i = 0; i < multiChannelGrid.getNumberOfChannels(); i++) { for (int j = 0; j < HistoFeatures; j++) { String name = "Slice " + i + ": Histogram " + nameString[j]; attribs.add(new weka.core.Attribute(name)); } } } else { attribs = new ArrayList<Attribute>(HistoFeatures + 1); for (int j = 0; j < HistoFeatures; j++) { String name = ": Histogram " + nameString[j]; attribs.add(new weka.core.Attribute(name)); } } Attribute classAttribute = generateClassAttribute(); attribs.add(classAttribute); // leeres set von feature vectoren instances = new Instances(className, attribs, 0); instances.setClass(classAttribute); }
From source file:edu.stanford.rsl.conrad.segmentation.MetaFeatureExtractor.java
License:Open Source License
public void configure() throws Exception { knownExtractors = CONRAD.getInstancesFromConrad(GridFeatureExtractor.class); selection = new boolean[knownExtractors.size()]; GenericDialog gDialog = new GenericDialog("Feature Configuration"); gDialog.addMessage("Select features:"); for (int i = 0; i < knownExtractors.size(); i++) { GridFeatureExtractor gridFex = (GridFeatureExtractor) knownExtractors.get(i); if (!(gridFex instanceof MetaFeatureExtractor)) { gDialog.addCheckbox(gridFex.toString(), true); }/*w w w. jav a2 s . c o m*/ } gDialog.showDialog(); for (int i = 0; i < knownExtractors.size(); i++) { GridFeatureExtractor gridFex = (GridFeatureExtractor) knownExtractors.get(i); if (!(gridFex instanceof MetaFeatureExtractor)) { selection[i] = gDialog.getNextBoolean(); if (selection[i]) { gridFex.labelGrid = this.labelGrid; gridFex.dataGrid = this.dataGrid; gridFex.configure(); this.attribs = combineAttribs(this.attribs, gridFex.attribs); } } else { selection[i] = false; } } Attribute classAttribute = generateClassAttribute(); attribs.add(classAttribute); // leeres set von feature vectoren instances = new Instances(className, attribs, 0); instances.setClass(classAttribute); configured = true; }
From source file:edu.stanford.rsl.conrad.segmentation.MultiChannelGridFeatureExtractor.java
License:Open Source License
@Override public void configure() throws Exception { multiChannelGrid = (MultiChannelGrid2D) dataGrid; int numFeatures = multiChannelGrid.getNumberOfChannels(); // attribs entspricht features attribs = new ArrayList<Attribute>(numFeatures + 1); for (int i = 0; i < numFeatures; i++) { String nameString = multiChannelGrid.getChannelNames()[i]; attribs.add(new weka.core.Attribute(nameString)); }/*from w w w . ja va2s. c o m*/ Attribute classAttribute = generateClassAttribute(); attribs.add(classAttribute); //leeres set von feature vectoren instances = new Instances(className, attribs, 0); instances.setClass(classAttribute); configured = true; }
From source file:edu.stanford.rsl.conrad.segmentation.PolynomialMultiChannelGridFeatureExtractor.java
License:Open Source License
@Override public void configure() throws Exception { polydegree = UserUtil.queryInt("Enter degree of polynomial transformation:", polydegree); multiChannelGrid = (MultiChannelGrid2D) dataGrid; int numFeatures = multiChannelGrid.getNumberOfChannels(); attribs = new ArrayList<Attribute>(numFeatures + 1); int combinations = (int) Math.pow(polydegree + 1, numFeatures); int[] index = new int[numFeatures]; for (int i = 1; i < combinations; i++) { int current = i; String indexString = ""; for (int j = 0; j < numFeatures; j++) { index[j] = current % (polydegree + 1); current /= (polydegree + 1); indexString += " " + index[j]; }/* w w w .j av a 2s.c o m*/ String nameString = "Feature " + i + " degree " + indexString; attribs.add(new weka.core.Attribute(nameString)); } Attribute classAttribute = generateClassAttribute(); attribs.add(classAttribute); instances = new Instances(className, attribs, 0); instances.setClass(classAttribute); configured = true; }
From source file:edu.stanford.rsl.conrad.segmentation.VesselnessFeatureExtractor.java
License:Open Source License
@Override public void configure() throws Exception { ImagePlus trainingImage = ImageUtil.wrapGrid(new Grid2D(2, 2), "Data Grid"); if (dataGrid instanceof MultiChannelGrid2D) { int channels = ((MultiChannelGrid2D) dataGrid).getNumberOfChannels(); trainingImage = ImageUtil.wrapGrid(new MultiChannelGrid2D(2, 2, channels), "Data Grid"); }/*from w ww . j av a2 s . co m*/ FeatureStackArray featureStackArray = new FeatureStackArray(trainingImage.getImageStackSize(), minimumSigma, maximumSigma, useNeighbors, membraneThickness, membranePatchSize, enabledFeatures); for (int i = 0; i < trainingImage.getImageStackSize(); i++) { FeatureStack stack = new FeatureStack(trainingImage.getImageStack().getProcessor(i + 1)); stack.setEnabledFeatures(featureStackArray.getEnabledFeatures()); stack.setMembranePatchSize(membranePatchSize); stack.setMembraneSize(membraneThickness); stack.setMaximumSigma(maximumSigma); stack.setMinimumSigma(minimumSigma); stack.updateFeaturesMT(); featureStackArray.set(stack, i); } ImageJnumFeatures = featureStackArray.getNumOfFeatures(); String[] GaussianKernel = { "0,0", "1,0", "2,0", "4,0", "8,0", "16,0" }; attribs = new ArrayList<Attribute>(19); for (int i = 0; i < trainingImage.getImageStackSize(); i++) { for (int j = 0; j < GaussianKernel.length; j++) { String name = "Slice " + i + ": Veselness for Gaussian Kernel " + GaussianKernel[j]; attribs.add(new weka.core.Attribute(name)); } } Attribute classAttribute = generateClassAttribute(); attribs.add(classAttribute); // leeres set von feature vectoren instances = new Instances(className, attribs, 0); instances.setClass(classAttribute); configured = true; }
From source file:edu.tamu.recognition.paleo.PaleoFeatureExtractor.java
License:BSD License
/** * Builds and returns a new (and empty) dataset that contains the attributes * of this extractor to be used by WEKA/*from w w w. j av a 2 s . com*/ * * @return new empty dataset * @throws Exception */ public Instances getNewDataset() throws Exception { Instances dataset; FVector fv = getFeatureVector(); m_classLabels = new FastVector(); for (int j = 0; j < m_config.getShapesTurnedOn().size(); j++) m_classLabels.addElement(m_config.getShapesTurnedOn().get(j)); FastVector fast = new FastVector(fv.getNumFeatures()); for (int j = 0; j < fv.getNumFeatures(); j++) fast.addElement(new Attribute("a" + j)); fast.addElement(new Attribute("label", m_classLabels)); dataset = new Instances("PaleoTrain", fast, 0); return dataset; }
From source file:edu.tamu.recognition.paleo.PaleoFeatureExtractor.java
License:BSD License
/** * Builds and returns a new (and empty) dataset that contains the attributes * of this extractor to be used by WEKA//from w w w .j a v a 2 s . com * * @return new empty dataset * @throws Exception */ public Instances getDataset() throws Exception { Instances dataset; FVector fv = getFeatureVector(); m_classLabels = new FastVector(); m_classLabels.addElement("Toddler"); m_classLabels.addElement("SchoolAge"); FastVector fast = new FastVector(fv.getNumFeatures()); for (int j = 0; j < fv.getNumFeatures(); j++) fast.addElement(new Attribute("a" + j)); fast.addElement(new Attribute("label", m_classLabels)); dataset = new Instances("AgeTrain", fast, 0); return dataset; }