summaryrefslogtreecommitdiff
path: root/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java
diff options
context:
space:
mode:
authorAndrej Shadura <andrewsh@debian.org>2019-03-09 22:30:30 +0000
committerAndrej Shadura <andrewsh@debian.org>2019-03-09 22:30:30 +0000
commit21d13de881e43d4ab86369af4c5fc744b342b3f9 (patch)
tree6588cebc4e1dbad3ac5b5d52bc21255925c2c93e /src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java
parent6160961591bfbfeab2ea5f7c249f58c78e893347 (diff)
Import Upstream version 0.4.0
Diffstat (limited to 'src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java')
-rw-r--r--src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java125
1 files changed, 48 insertions, 77 deletions
diff --git a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java
index 6400a747..eef7b13d 100644
--- a/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java
+++ b/src/de/lmu/ifi/dbs/elki/data/synthetic/bymodel/GeneratorMain.java
@@ -23,14 +23,18 @@ package de.lmu.ifi.dbs.elki.data.synthetic.bymodel;
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-import java.io.IOException;
-import java.io.OutputStreamWriter;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
-import de.lmu.ifi.dbs.elki.data.synthetic.bymodel.distribution.Distribution;
+import de.lmu.ifi.dbs.elki.data.ClassLabel;
+import de.lmu.ifi.dbs.elki.data.DoubleVector;
+import de.lmu.ifi.dbs.elki.data.SimpleClassLabel;
+import de.lmu.ifi.dbs.elki.data.type.TypeUtil;
+import de.lmu.ifi.dbs.elki.data.type.VectorFieldTypeInformation;
+import de.lmu.ifi.dbs.elki.datasource.bundle.MultipleObjectsBundle;
import de.lmu.ifi.dbs.elki.math.linearalgebra.Vector;
-import de.lmu.ifi.dbs.elki.utilities.FormatUtil;
import de.lmu.ifi.dbs.elki.utilities.exceptions.UnableToComplyException;
/**
@@ -63,14 +67,9 @@ import de.lmu.ifi.dbs.elki.utilities.exceptions.UnableToComplyException;
*/
public class GeneratorMain {
/**
- * Line separator for output
- */
- public final static String LINE_SEPARATOR = System.getProperty("line.separator");
-
- /**
* List of clusters to generate
*/
- private LinkedList<GeneratorInterface> clusters = new LinkedList<GeneratorInterface>();
+ private LinkedList<GeneratorInterface> generators = new LinkedList<GeneratorInterface>();
/**
* Add a cluster to the cluster list.
@@ -78,7 +77,7 @@ public class GeneratorMain {
* @param c cluster to add
*/
public void addCluster(GeneratorInterface c) {
- clusters.add(c);
+ generators.add(c);
}
/**
@@ -94,18 +93,18 @@ public class GeneratorMain {
*/
public void generate() throws UnableToComplyException {
// we actually need some clusters.
- if(clusters.size() < 1) {
+ if(generators.size() < 1) {
throw new UnableToComplyException("No clusters specified.");
}
// Assert that cluster dimensions agree.
- int dim = clusters.get(0).getDim();
- for(GeneratorInterface c : clusters) {
+ final int dim = generators.get(0).getDim();
+ for(GeneratorInterface c : generators) {
if(c.getDim() != dim) {
throw new UnableToComplyException("Cluster dimensions do not agree.");
}
}
// generate clusters
- for(GeneratorInterface curclus : clusters) {
+ for(GeneratorInterface curclus : generators) {
while(curclus.getPoints().size() < curclus.getSize()) {
// generate the "missing" number of points
List<Vector> newp = curclus.generate(curclus.getSize() - curclus.getPoints().size());
@@ -115,7 +114,7 @@ public class GeneratorMain {
if(testAgainstModel) {
double max = 0.0;
double is = 0.0;
- for(GeneratorInterface other : clusters) {
+ for(GeneratorInterface other : generators) {
double d = other.getDensity(p) * other.getSize();
if(other == curclus) {
is = d;
@@ -143,66 +142,6 @@ public class GeneratorMain {
}
/**
- * Write the resulting clusters to an output stream.
- *
- * @param outStream output stream
- * @throws IOException thrown on write errors
- */
- public void writeClusters(OutputStreamWriter outStream) throws IOException {
- // compute global discard values
- int totalsize = 0;
- int totaldisc = 0;
- assert (clusters.size() > 0);
- for(GeneratorInterface curclus : clusters) {
- totalsize = totalsize + curclus.getSize();
- if(curclus instanceof GeneratorSingleCluster) {
- totaldisc = totaldisc + ((GeneratorSingleCluster) curclus).getDiscarded();
- }
- }
- double globdens = (double) (totalsize + totaldisc) / totalsize;
- outStream.write("########################################################" + LINE_SEPARATOR);
- outStream.write("## Number of clusters: " + clusters.size() + LINE_SEPARATOR);
- for(GeneratorInterface curclus : clusters) {
- outStream.write("########################################################" + LINE_SEPARATOR);
- outStream.write("## Cluster: " + curclus.getName() + LINE_SEPARATOR);
- outStream.write("########################################################" + LINE_SEPARATOR);
- outStream.write("## Size: " + curclus.getSize() + LINE_SEPARATOR);
- if(curclus instanceof GeneratorSingleCluster) {
- GeneratorSingleCluster cursclus = (GeneratorSingleCluster) curclus;
- Vector cmin = cursclus.getClipmin();
- Vector cmax = cursclus.getClipmax();
- if(cmin != null && cmax != null) {
- outStream.write("## Clipping: " + cmin.toString() + " - " + cmax.toString() + LINE_SEPARATOR);
- }
- outStream.write("## Density correction factor: " + cursclus.getDensityCorrection() + LINE_SEPARATOR);
- outStream.write("## Generators:" + LINE_SEPARATOR);
- for(Distribution gen : cursclus.getAxes()) {
- outStream.write("## " + gen.toString() + LINE_SEPARATOR);
- }
- if(cursclus.getTrans() != null && cursclus.getTrans().getTransformation() != null) {
- outStream.write("## Affine transformation matrix:" + LINE_SEPARATOR);
- outStream.write(FormatUtil.format(cursclus.getTrans().getTransformation(), "## ") + LINE_SEPARATOR);
- }
- }
- if(curclus instanceof GeneratorInterfaceDynamic) {
- GeneratorSingleCluster cursclus = (GeneratorSingleCluster) curclus;
- outStream.write("## Discards: " + cursclus.getDiscarded() + " Retries left: " + cursclus.getRetries() + LINE_SEPARATOR);
- double corf = /* cursclus.overweight */(double) (cursclus.getSize() + cursclus.getDiscarded()) / cursclus.getSize() / globdens;
- outStream.write("## Density correction factor estimation: " + corf + LINE_SEPARATOR);
-
- }
- outStream.write("########################################################" + LINE_SEPARATOR);
- for(Vector p : curclus.getPoints()) {
- for(int i = 0; i < p.getRowDimensionality(); i++) {
- outStream.write(p.get(i) + " ");
- }
- outStream.write(curclus.getName());
- outStream.write(LINE_SEPARATOR);
- }
- }
- }
-
- /**
* Return value of the {@link #testAgainstModel} flag
*
* @return value of testAgainstModel
@@ -219,4 +158,36 @@ public class GeneratorMain {
public void setTestAgainstModel(boolean testAgainstModel) {
this.testAgainstModel = testAgainstModel;
}
-}
+
+ /**
+ * Access the generators.
+ *
+ * @return generators
+ */
+ public List<GeneratorInterface> getGenerators() {
+ return Collections.unmodifiableList(generators);
+ }
+
+ /**
+ * Get the objects bundle
+ *
+ * @return Bundle
+ */
+ public MultipleObjectsBundle getBundle() {
+ final int dim = generators.get(0).getDim();
+ final DoubleVector factory = new DoubleVector(new double[dim]);
+ MultipleObjectsBundle bundle = new MultipleObjectsBundle();
+ VectorFieldTypeInformation<DoubleVector> type = new VectorFieldTypeInformation<DoubleVector>(DoubleVector.class, dim, factory);
+ bundle.appendColumn(type, new ArrayList<Object>());
+ bundle.appendColumn(TypeUtil.CLASSLABEL, new ArrayList<Object>());
+
+ for(GeneratorInterface generator : generators) {
+ ClassLabel l = new SimpleClassLabel(generator.getName());
+ for(Vector v : generator.getPoints()) {
+ DoubleVector dv = new DoubleVector(v);
+ bundle.appendSimple(dv, l);
+ }
+ }
+ return bundle;
+ }
+} \ No newline at end of file