public static void main(String[] args) throws Exception { //We can open the data stream using the static class DataStreamLoader DataStream<DataInstance> data = DataStreamLoader.open("datasets/simulated/syntheticData.arff"); //We can save this data set to a new file using the static class DataStreamWriter DataStreamWriter.writeDataToFile(data, "datasets/simulated/tmp.arff"); } }
public static void main(String[] args) throws IOException { DataStream<DataInstance> data = eu.amidst.core.utils.DataSetGenerator.generate(0,1000,0,10); DataStreamWriter.writeDataToFile(data, "./datasets/artificialDataset.arff"); // DataStream<DynamicDataInstance> dataDynamic = eu.amidst.dynamic.utils.DataSetGenerator.generate(0,100, 100,0,10); // DataStreamWriter.writeDataToFile(dataDynamic, "./datasets/artificialDatasetDynamic.arff"); } }
public static void main(String[] args) throws Exception { //We can load a Bayesian network using the static class BayesianNetworkLoader BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/simulated/WasteIncinerator.bn"); //Now we print the loaded model System.out.println(bn.toString()); //Now we change the parameters of the model bn.randomInitialization(new Random(0)); //We can save this Bayesian network to using the static class BayesianNetworkWriter BayesianNetworkWriter.save(bn, "networks/simulated/tmp.bn"); } }
public static void main(String[] agrs) throws IOException, ClassNotFoundException { //We first load the WasteIncinerator bayesian network which has multinomial and Gaussian variables. BayesianNetwork bn = BayesianNetworkLoader.loadFromFile("./networks/simulated/WasteIncinerator.bn"); //We simply create an BayesianNetworkSampler object, passing to the constructor the BN model. BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn); sampler.setSeed(0); //The method sampleToDataStream returns a DataStream with ten DataInstance objects. DataStream<DataInstance> dataStream = sampler.sampleToDataStream(10); //We finally save the sampled data set to a arff file. DataStreamWriter.writeDataToFile(dataStream, "datasets/simulated/sample-WasteIncinerator.arff"); } }
public static void main(String[] args) throws IOException { //Load the datastream String filename = "datasets/simulated/docs.nips.small.arff"; DataStream<DataInstance> data = DataStreamLoader.open(filename); //Learn the model Model model = new LDA(data.getAttributes()); model.updateModel(data); BayesianNetwork bn = model.getModel(); //System.out.println(bn); // Save with .bn format BayesianNetworkWriter.save(bn, "networks/simulated/exampleBN.bn"); }
public static void process2(String[] args) throws IOException { DataStream<DataInstance> dataInstances = DataStreamLoader.open("/Users/andresmasegosa/Dropbox/Amidst/datasets/NFSAbstracts/docswords-joint.arff"); double minWord = Double.MAX_VALUE; double maxWord = -Double.MAX_VALUE; for (DataInstance dataInstance : dataInstances) { double word = dataInstance.getValue(dataInstance.getAttributes().getAttributeByName("word")); if (minWord>word) minWord = word; if (maxWord<word) maxWord=word; } System.out.println(minWord); System.out.println(maxWord); }
public static void main(String[] args) throws Exception { //We can open the data stream using the static class DataStreamLoader DataStream<DataInstance> data = DataStreamLoader.open("datasets/simulated/syntheticData.arff"); //ReservoirSampling allows to create a DataOnMemory object containing a unfiorm subsample of the data stream DataOnMemory<DataInstance> dataOnMemory = ReservoirSampling.samplingNumberOfSamples(100, data); //We can save this data set to a new file using the static class DataStreamWriter DataStreamWriter.writeDataToFile(data, "datasets/simulated/subsample.arff"); } }
public static void main(String[] args) throws Exception{ int nOfDisc; int nOfCont; DataStream<DynamicDataInstance> dataGaussians = null; String path = "datasets/simulated/"; nOfCont = 3; nOfDisc = 2; dataGaussians = DataSetGenerator.generate(1,1000,nOfDisc,nOfCont); DataStreamWriter.writeDataToFile(dataGaussians, path+"exampleDS_d"+nOfDisc+"_c"+nOfCont+".arff"); nOfCont = 5; nOfDisc = 0; dataGaussians = DataSetGenerator.generate(1,10000,nOfDisc,nOfCont); DataStreamWriter.writeDataToFile(dataGaussians, path+"exampleDS_d"+nOfDisc+"_c"+nOfCont+".arff"); dataGaussians = DataSetGenerator.generate(1,50,nOfDisc,nOfCont); DataStreamWriter.writeDataToFile(dataGaussians, path+"exampleDS_d"+nOfDisc+"_c"+nOfCont+"_small.arff"); nOfCont = 0; nOfDisc = 5; dataGaussians = DataSetGenerator.generate(1,1000,nOfDisc,nOfCont); DataStreamWriter.writeDataToFile(dataGaussians, path+"exampleDS_d"+nOfDisc+"_c"+nOfCont+".arff"); }
public static void main(String[] args) throws Exception { // load the true Bayesian network BayesianNetwork originalBnet = BayesianNetworkLoader.loadFromFile(args[0]); System.out.println("\n Network \n " + args[0]); System.out.println("\n Number of variables \n " + originalBnet.getDAG().getVariables().getNumberOfVars()); //Sampling from the input BN BayesianNetworkSampler sampler = new BayesianNetworkSampler(originalBnet); sampler.setSeed(0); // Defines the size of the data to be generated from the input BN int sizeData = Integer.parseInt(args[1]); System.out.println("\n Sampling and saving the data... \n "); DataStream<DataInstance> data = sampler.sampleToDataStream(sizeData); DataStreamWriter.writeDataToFile(data, "./data.arff"); }
public static void main(String[] args) throws ExceptionHugin, IOException { //Load the datastream String filename = "datasets/simulated/cajamar.arff"; DataStream<DataInstance> data = DataStreamLoader.open(filename); //Learn the model Model model = new FactorAnalysis(data.getAttributes()); // ((MixtureOfFactorAnalysers)model).setNumberOfLatentVariables(3); model.updateModel(data); BayesianNetwork bn = model.getModel(); System.out.println(bn); // Save with .bn format BayesianNetworkWriter.save(bn, "networks/simulated/exampleBN.bn"); // Save with hugin format //BayesianNetworkWriterToHugin.save(bn, "networks/simulated/exampleBN.net"); }
public static void main(String[] args) { //Load the data set DataStream<DataInstance> data = DataStreamLoader.open("./datasets/artificialDataset.arff"); //Define the model (internally the skeleton is fixed) Model model = new FactorAnalysis(data.getAttributes()); //Print the skeleton of the model System.out.println(model.getDAG()); //Learnt the parameters of the model model.updateModel(data); System.out.println(model.getModel()); } }
public static void shuflle(String[] args) throws IOException { //Utils.shuffleData("/Users/andresmasegosa/Dropbox/Amidst/datasets/uci-text/docword.nips.arff", "/Users/andresmasegosa/Dropbox/Amidst/datasets/uci-text/docword.nips.shuffled.arff"); DataStream<DataInstance> dataInstances = DataStreamLoader.open("/Users/andresmasegosa/Dropbox/Amidst/datasets/uci-text/docword.nips.arff"); List<DataOnMemory<DataInstance>> batches = BatchSpliteratorByID.streamOverDocuments(dataInstances, 1).collect(Collectors.toList()); Collections.shuffle(batches); DataOnMemoryListContainer<DataInstance> newData = new DataOnMemoryListContainer<DataInstance>(dataInstances.getAttributes()); for (DataOnMemory<DataInstance> batch : batches) { for (DataInstance dataInstance : batch) { newData.add(dataInstance); } } DataStreamWriter.writeDataToFile(newData,"/Users/andresmasegosa/Dropbox/Amidst/datasets/uci-text/docword.nips.shuffled.arff"); }
private static void sampleBayesianNetwork() throws IOException { BayesianNetwork bn = new BayesianNetwork(dag); BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn); sampler.setSeed(0); //The method sampleToDataStream returns a DataStream with ten DataInstance objects. DataStream<DataInstance> dataStream = sampler.sampleToDataStream(getSampleSize()); //We finally save the sampled data set to an arff file. DataStreamWriter.writeDataToFile(dataStream, "datasets/sampleBatchSize.arff"); }
public static void main(String[] args) { String filename = "datasets/bnaic2015/BCC/Month0.arff"; DataStream<DataInstance> data = DataStreamLoader.open(filename); //Learn the model Model model = new CustomGaussianMixture(data.getAttributes()); model.updateModel(data); BayesianNetwork bn = model.getModel(); System.out.println(bn); }
public static void runParallelKMeans() throws IOException { DataStream<DataInstance> data; if(isSampleData()) { BayesianNetworkGenerator.setNumberOfGaussianVars(getNumGaussVars()); BayesianNetworkGenerator.setNumberOfMultinomialVars(getNumDiscVars(), getNumStates()); BayesianNetwork bn = BayesianNetworkGenerator.generateBayesianNetwork(); data = new BayesianNetworkSampler(bn).sampleToDataStream(getSampleSize()); DataStreamWriter.writeDataToFile(data, pathToFile); } data = DataStreamLoader.open(pathToFile); ParallelKMeans.setBatchSize(batchSize); double[][] centroids = ParallelKMeans.learnKMeans(getK(),data); for (int clusterID = 0; clusterID < centroids.length; clusterID++) { System.out.println("Cluster "+(clusterID+1)+": "+Arrays.toString(centroids[clusterID])); } }
private static void sampleBayesianNetwork() throws IOException { BayesianNetwork bn = new BayesianNetwork(dag); BayesianNetworkSampler sampler = new BayesianNetworkSampler(bn); sampler.setSeed(0); //The method sampleToDataStream returns a DataStream with ten DataInstance objects. DataStream<DataInstance> dataStream = sampler.sampleToDataStream(getSampleSize()); //We finally save the sampled data set to an arff file. DataStreamWriter.writeDataToFile(dataStream, getPathToFile()); }
public static void generateData() throws Exception { DynamicBayesianNetwork network = createDynamicFireDetectorModel(); DynamicBayesianNetworkSampler sampler = new DynamicBayesianNetworkSampler(network); sampler.setSeed(1); sampler.setLatentVar(network.getDynamicVariables().getVariableByName("Temperature")); sampler.setLatentVar(network.getDynamicVariables().getVariableByName("Smoke")); DataStream<DynamicDataInstance> dataStream = sampler.sampleToDataBase(100,1000); DataStreamWriter.writeDataToFile(dataStream, "./datasets/TimeIndexedSensorReadings.arff"); dataStream = sampler.sampleToDataBase(1,10); DataStreamWriter.writeDataToFile(dataStream, "./datasets/TimeIndexedSensorReadingsEvidence.arff"); } public static void generateEvidenceData() throws Exception {
public static void generateEvidenceData() throws Exception { DynamicBayesianNetwork network = createDynamicFireDetectorModel(); DynamicBayesianNetworkSampler sampler = new DynamicBayesianNetworkSampler(network); sampler.setSeed(1); sampler.setLatentVar(network.getDynamicVariables().getVariableByName("Temperature")); sampler.setLatentVar(network.getDynamicVariables().getVariableByName("Smoke")); DataStream<DynamicDataInstance> dataStream = sampler.sampleToDataBase(1, 10); DataStreamWriter.writeDataToFile(dataStream, "./datasets/TimeIndexedSensorReadingsEvidence.arff"); }
public static void generateData(int seed, double tempMean, String outputFile) throws Exception { BayesianNetwork network = createFireDetectorModel(tempMean); BayesianNetworkSampler sampler = new BayesianNetworkSampler(network); sampler.setSeed(seed); sampler.setLatentVar(network.getVariables().getVariableByName("Temperature")); sampler.setLatentVar(network.getVariables().getVariableByName("Smoke")); DataStream<DataInstance> dataStream = sampler.sampleToDataStream(1000); DataStreamWriter.writeDataToFile(dataStream, outputFile); } public static void main(String[] args) throws Exception {
public static void generateData() throws Exception { BayesianNetwork network = createFireDetectorModel(); BayesianNetworkSampler sampler = new BayesianNetworkSampler(network); sampler.setSeed(0); sampler.setLatentVar(network.getVariables().getVariableByName("Temperature")); sampler.setLatentVar(network.getVariables().getVariableByName("Smoke")); DataStream<DataInstance> dataStream = sampler.sampleToDataStream(1000); DataStreamWriter.writeDataToFile(dataStream, "./datasets/sensorReadings.arff"); } public static void main(String[] args) throws Exception {