http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ZipcodeRecord.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ZipcodeRecord.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ZipcodeRecord.java deleted file mode 100644 index ef54712..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datamodels/inputs/ZipcodeRecord.java +++ /dev/null @@ -1,90 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs; - -import java.io.Serializable; - -import org.apache.commons.lang3.tuple.Pair; - -public class ZipcodeRecord implements Serializable -{ - private static final long serialVersionUID = 1769986686070108470L; - - final String zipcode; - final Pair<Double, Double> coordinates; - final String city; - final String state; - final double medianHouseholdIncome; - final long population; - - public ZipcodeRecord(String zipcode, Pair<Double, Double> coordinates, - String city, String state, double medianHouseholdIncome, long population) - { - this.city = city; - this.state = state; - this.zipcode = zipcode; - this.coordinates = coordinates; - this.medianHouseholdIncome = medianHouseholdIncome; - this.population = population; - } - - public String getZipcode() - { - return zipcode; - } - - public Pair<Double, Double> getCoordinates() - { - return coordinates; - } - - public double getMedianHouseholdIncome() - { - return medianHouseholdIncome; - } - - public long getPopulation() - { - return population; - } - - public double distance(ZipcodeRecord other) - { - if(other.getZipcode().equals(zipcode)) - return 0.0; - - Pair<Double, Double> otherCoords = other.getCoordinates(); - - double dist = Math.sin(Math.toRadians(coordinates.getLeft())) * - Math.sin(Math.toRadians(otherCoords.getLeft())) + - Math.cos(Math.toRadians(coordinates.getLeft())) * - Math.cos(Math.toRadians(otherCoords.getLeft())) * - Math.cos(Math.toRadians(coordinates.getRight() - otherCoords.getRight())); - dist = Math.toDegrees(Math.acos(dist)) * 69.09; - - return dist; - } - - public String getCity() - { - return city; - } - - public String getState() - { - return state; - } -}
http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/NameReader.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/NameReader.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/NameReader.java deleted file mode 100644 index 5a847ea..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/NameReader.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.datareaders; - -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.util.Map; -import java.util.Scanner; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.Names; - -import com.google.common.collect.Maps; - -public class NameReader -{ - InputStream path; - - public NameReader(InputStream path) - { - this.path = path; - } - - public Names readData() throws FileNotFoundException - { - Scanner scanner = new Scanner(path); - - Map<String, Double> firstNames = Maps.newHashMap(); - Map<String, Double> lastNames = Maps.newHashMap(); - - while(scanner.hasNextLine()) - { - String line = scanner.nextLine(); - String[] cols = line.trim().split(","); - - String name = cols[0]; - double weight = Double.parseDouble(cols[5]); - - if(cols[4].equals("1")) - firstNames.put(name, weight); - if(cols[3].equals("1")) - lastNames.put(name, weight); - } - - scanner.close(); - - return new Names(firstNames, lastNames); - - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ZipcodeReader.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ZipcodeReader.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ZipcodeReader.java deleted file mode 100644 index 1612a92..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/datareaders/ZipcodeReader.java +++ /dev/null @@ -1,193 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.datareaders; - -import java.io.FileNotFoundException; -import java.io.InputStream; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Scanner; -import java.util.Set; -import java.util.Vector; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.commons.lang3.tuple.Pair; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; - -public class ZipcodeReader -{ - private static class ZipcodeLocationRecord - { - public final Pair<Double, Double> coordinates; - public final String state; - public final String city; - - public ZipcodeLocationRecord(Pair<Double, Double> coordinates, - String city, String state) - { - this.coordinates = coordinates; - this.city = city; - this.state = state; - } - } - - InputStream zipcodeIncomesFile = null; - InputStream zipcodePopulationFile = null; - InputStream zipcodeCoordinatesFile = null; - - public void setIncomesFile(InputStream path) - { - this.zipcodeIncomesFile = path; - } - - public void setPopulationFile(InputStream path) - { - this.zipcodePopulationFile = path; - } - - public void setCoordinatesFile(InputStream path) - { - this.zipcodeCoordinatesFile = path; - } - - private ImmutableMap<String, Double> readIncomeData(InputStream path) throws FileNotFoundException - { - Scanner scanner = new Scanner(path); - - // skip headers - scanner.nextLine(); - scanner.nextLine(); - - Map<String, Double> entries = Maps.newHashMap(); - while(scanner.hasNextLine()) - { - String line = scanner.nextLine().trim(); - String[] cols = line.split(","); - // zipcodes are in the form "ZCTA5 XXXXX" - String zipcode = cols[2].split(" ")[1].trim(); - try - { - double medianHouseholdIncome = Integer.parseInt(cols[5].trim()); - entries.put(zipcode, medianHouseholdIncome); - } - catch(NumberFormatException e) - { - - } - } - - scanner.close(); - - return ImmutableMap.copyOf(entries); - } - - private ImmutableMap<String, Long> readPopulationData(InputStream path) throws FileNotFoundException - { - Scanner scanner = new Scanner(path); - - // skip header - scanner.nextLine(); - - Map<String, Long> entries = Maps.newHashMap(); - while(scanner.hasNextLine()) - { - String line = scanner.nextLine().trim(); - - if(line.length() == 0) - continue; - - String[] cols = line.split(","); - - String zipcode = cols[0].trim(); - Long population = Long.parseLong(cols[1].trim()); - - if(entries.containsKey(zipcode)) - { - entries.put(zipcode, Math.max(entries.get(zipcode), population)); - } - else - { - entries.put(zipcode, population); - } - } - - scanner.close(); - - return ImmutableMap.copyOf(entries); - } - - private ImmutableMap<String, ZipcodeLocationRecord> readCoordinates(InputStream path) throws FileNotFoundException - { - Scanner scanner = new Scanner(path); - - // skip header - scanner.nextLine(); - - Map<String, ZipcodeLocationRecord> entries = Maps.newHashMap(); - while(scanner.hasNextLine()) - { - String line = scanner.nextLine().trim(); - - String[] cols = line.split(", "); - - // remove quote marks - String zipcode = cols[0].substring(1, cols[0].length() - 1); - String state = cols[1].substring(1, cols[1].length() - 1); - Double latitude = Double.parseDouble(cols[2].substring(1, cols[2].length() - 1)); - Double longitude = Double.parseDouble(cols[3].substring(1, cols[3].length() - 1)); - String city = cols[4].substring(1, cols[4].length() - 1); - - Pair<Double, Double> coords = Pair.of(latitude, longitude); - - ZipcodeLocationRecord record = new ZipcodeLocationRecord(coords, city, state); - - entries.put(zipcode, record); - } - - scanner.close(); - - return ImmutableMap.copyOf(entries); - } - - public ImmutableList<ZipcodeRecord> readData() throws FileNotFoundException - { - ImmutableMap<String, Double> incomes = readIncomeData(this.zipcodeIncomesFile); - ImmutableMap<String, Long> populations = readPopulationData(this.zipcodePopulationFile); - ImmutableMap<String, ZipcodeLocationRecord> coordinates = readCoordinates(this.zipcodeCoordinatesFile); - - Set<String> zipcodeSubset = new HashSet<String>(incomes.keySet()); - zipcodeSubset.retainAll(populations.keySet()); - zipcodeSubset.retainAll(coordinates.keySet()); - - List<ZipcodeRecord> table = new Vector<ZipcodeRecord>(); - for(String zipcode : zipcodeSubset) - { - ZipcodeRecord record = new ZipcodeRecord(zipcode, - coordinates.get(zipcode).coordinates, - coordinates.get(zipcode).city, - coordinates.get(zipcode).state, - incomes.get(zipcode), - populations.get(zipcode)); - table.add(record); - } - - return ImmutableList.copyOf(table); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/SeedFactory.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/SeedFactory.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/SeedFactory.java deleted file mode 100644 index aea004e..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/SeedFactory.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework; - -import java.util.Random; - -public class SeedFactory -{ - Random rng; - - public SeedFactory() - { - rng = new Random(); - } - - public SeedFactory(long seed) - { - rng = new Random(seed); - } - - public long getNextSeed() - { - return rng.nextLong(); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModel.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModel.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModel.java deleted file mode 100644 index 0b90e2b..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModel.java +++ /dev/null @@ -1,50 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels; - -import java.io.Serializable; -import java.util.Map; - -public class MarkovModel<T> implements Serializable -{ - private static final long serialVersionUID = 8378109656005603192L; - - final Map<T, Map<T, Double>> transitionWeights; - final Map<T, Double> startWeights; - - public MarkovModel(Map<T, Map<T, Double>> transitionWeights, Map<T, Double> startWeights) - { - this.transitionWeights = transitionWeights; - this.startWeights = startWeights; - } - - public Map<T, Map<T, Double>> getTransitionWeights() - { - return transitionWeights; - } - - public Map<T, Double> getStartWeights() - { - return startWeights; - } - - @Override - public String toString() - { - return "MarkModel(" + startWeights + "," + transitionWeights + ")"; - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModelBuilder.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModelBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModelBuilder.java deleted file mode 100644 index 861c0ef..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovModelBuilder.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableTable; - -public class MarkovModelBuilder<S> -{ - ImmutableTable.Builder<S, S, Double> transitionWeights; - ImmutableMap.Builder<S, Double> startWeights; - - public MarkovModelBuilder() - { - transitionWeights = ImmutableTable.builder(); - startWeights = ImmutableMap.builder(); - } - - public static <T> MarkovModelBuilder<T> create() - { - return new MarkovModelBuilder<T>(); - } - - public void addStartState(S state, double weight) - { - startWeights.put(state, weight); - } - - public void addTransition(S state1, S state2, double weight) - { - transitionWeights.put(state1, state2, weight); - } - - public MarkovModel<S> build() - { - return new MarkovModel<S>(transitionWeights.build().rowMap(), startWeights.build()); - } - - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovProcess.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovProcess.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovProcess.java deleted file mode 100644 index d0bd6c5..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/markovmodels/MarkovProcess.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.markovmodels; - -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; - -import com.google.common.collect.ImmutableMap; - -public class MarkovProcess<T> implements Sampler<T> -{ - final ImmutableMap<T, Sampler<T>> transitionSamplers; - final Sampler<T> startStateSampler; - - T currentState; - - - public MarkovProcess(MarkovModel<T> model, SeedFactory factory) - { - Map<T, Map<T, Double>> transitionTable = model.getTransitionWeights(); - - startStateSampler = RouletteWheelSampler.create(model.getStartWeights(), factory); - - ImmutableMap.Builder<T, Sampler<T>> builder = ImmutableMap.builder(); - for(Map.Entry<T, Map<T, Double>> entry : transitionTable.entrySet()) - { - builder.put(entry.getKey(), RouletteWheelSampler.create(entry.getValue(), factory)); - } - - - this.transitionSamplers = builder.build(); - - currentState = null; - } - - public static <T> MarkovProcess<T> create(MarkovModel<T> model, SeedFactory factory) - { - return new MarkovProcess<T>(model, factory); - } - - public T sample() throws Exception - { - if(currentState == null) - { - currentState = startStateSampler.sample(); - return currentState; - } - - currentState = transitionSamplers.get(currentState).sample(); - return currentState; - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ConditionalProbabilityDensityFunction.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ConditionalProbabilityDensityFunction.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ConditionalProbabilityDensityFunction.java deleted file mode 100644 index 5161761..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ConditionalProbabilityDensityFunction.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs; - -public interface ConditionalProbabilityDensityFunction<T, S> -{ - public double probability(T datum, S conditionalDatum); -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ExponentialPDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ExponentialPDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ExponentialPDF.java deleted file mode 100644 index dcc1278..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ExponentialPDF.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs; - -public class ExponentialPDF implements ProbabilityDensityFunction<Double> -{ - private final double lambda; - - public ExponentialPDF(double lambda) - { - this.lambda = lambda; - } - - public double probability(Double value) - { - return lambda * Math.exp(-1.0 * value * lambda); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/GaussianPDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/GaussianPDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/GaussianPDF.java deleted file mode 100644 index 55ebc93..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/GaussianPDF.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs; - -public class GaussianPDF implements ProbabilityDensityFunction<Double> -{ - private double mean; - private double std; - - public GaussianPDF(double mean, double std) - { - this.mean = mean; - this.std = std; - } - - public double probability(Double value) - { - double diff = (mean - value) * (mean - value); - double var = std * std; - double exp = Math.exp(-1.0 * diff / (2.0 * var)); - - return exp / (std * Math.sqrt(2.0 * Math.PI)); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/JointPDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/JointPDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/JointPDF.java deleted file mode 100644 index fdf2db0..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/JointPDF.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs; - -import java.util.List; - -public class JointPDF<T> implements ProbabilityDensityFunction<T> -{ - - double normalizationFactor; - ProbabilityDensityFunction<T>[] pdfs; - - public JointPDF(List<T> data, ProbabilityDensityFunction<T> ... pdfs) - { - this.pdfs = pdfs; - - normalizationFactor = 0.0d; - for(T datum : data) - { - double prob = 1.0; - for(ProbabilityDensityFunction<T> pdf : pdfs) - prob *= pdf.probability(datum); - normalizationFactor += prob; - } - - } - - public double probability(T datum) - { - double weight = 1.0; - for(ProbabilityDensityFunction<T> pdf : pdfs) - weight *= pdf.probability(datum); - - return weight / normalizationFactor; - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/MultinomialPDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/MultinomialPDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/MultinomialPDF.java deleted file mode 100644 index 7605156..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/MultinomialPDF.java +++ /dev/null @@ -1,57 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs; - -import java.util.Map; -import java.util.Set; - -import com.google.common.collect.ImmutableMap; - -public class MultinomialPDF<T> implements ProbabilityDensityFunction<T> -{ - private final ImmutableMap<T, Double> probabilities; - - public MultinomialPDF(Map<T, Double> probabilities) - { - this.probabilities = ImmutableMap.copyOf(probabilities); - } - - public Set<T> getData() - { - return probabilities.keySet(); - } - - public double probability(T value) - { - if(probabilities.containsKey(value)) - { - return probabilities.get(value); - } - - return 0.0; - } - - @Override - public String toString() - { - String str = ""; - for(Map.Entry<T, Double> entry: probabilities.entrySet()) - { - str += entry.getValue() + "," + entry.getKey() + "\n"; - } - return str; - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ProbabilityDensityFunction.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ProbabilityDensityFunction.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ProbabilityDensityFunction.java deleted file mode 100644 index 1b691ca..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/ProbabilityDensityFunction.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs; - -public interface ProbabilityDensityFunction<T> -{ - public double probability(T datum); -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/UniformPDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/UniformPDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/UniformPDF.java deleted file mode 100644 index ea8e77e..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/pdfs/UniformPDF.java +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs; - -public class UniformPDF<T> implements ProbabilityDensityFunction<T> -{ - private final double probability; - - public UniformPDF(long count) - { - probability = 1.0 / ((double) count); - } - - public UniformPDF(double probability) - { - this.probability = probability; - } - - public double probability(T datum) - { - return probability; - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/BoundedMultiModalGaussianSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/BoundedMultiModalGaussianSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/BoundedMultiModalGaussianSampler.java deleted file mode 100644 index 348f080..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/BoundedMultiModalGaussianSampler.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import java.util.List; -import java.util.Random; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.commons.lang3.tuple.Pair; - -import com.google.common.collect.ImmutableList; - -public class BoundedMultiModalGaussianSampler implements Sampler<Double> -{ - ImmutableList<Pair<Double, Double>> distributions; - - double min; - double max; - Random rng; - - public BoundedMultiModalGaussianSampler(List<Pair<Double, Double>> distributions, double min, double max, SeedFactory seedFactory) - { - rng = new Random(seedFactory.getNextSeed()); - this.distributions = ImmutableList.copyOf(distributions); - - this.min = min; - this.max = max; - } - - public Double sample() - { - while(true) - { - int idx = rng.nextInt(distributions.size()); - - double mean = distributions.get(idx).getLeft(); - double std = distributions.get(idx).getRight(); - - double value = mean + rng.nextGaussian() * std; - - if (value >= this.min && value <= this.max) - { - return value; - } - } - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ConditionalSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ConditionalSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ConditionalSampler.java deleted file mode 100644 index c521333..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ConditionalSampler.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -public interface ConditionalSampler<T, S> -{ - public T sample(S conditional) throws Exception; -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/DoubleSequenceSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/DoubleSequenceSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/DoubleSequenceSampler.java deleted file mode 100644 index 82e4d2d..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/DoubleSequenceSampler.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -public class DoubleSequenceSampler implements Sampler<Double> -{ - Double start; - Double end; - Double step; - Double next; - - public DoubleSequenceSampler() - { - start = 0.0; - end = null; - step = 1.0; - next = start; - } - - public DoubleSequenceSampler(Double start) - { - this.start = start; - end = null; - step = 1.0; - next = start; - } - - public DoubleSequenceSampler(Double start, Double end) - { - this.start = start; - this.end = end; - step = 1.0; - next = start; - } - - public DoubleSequenceSampler(Double start, Double end, Double step) - { - this.start = start; - this.end = end; - this.step = step; - next = start; - } - - public Double sample() throws Exception - { - if(end == null || next < end) - { - Double current = next; - next = current + step; - return current; - } - - throw new Exception("All values have been sampled"); - } - - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ExponentialSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ExponentialSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ExponentialSampler.java deleted file mode 100644 index 082f3ac..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/ExponentialSampler.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import java.util.Random; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; - -public class ExponentialSampler implements Sampler<Double> -{ - final private Random rng; - final private double lambda; - - public ExponentialSampler(double lambda, SeedFactory seedFactory) - { - rng = new Random(seedFactory.getNextSeed()); - this.lambda = lambda; - } - - public Double sample() - { - return - Math.log(1.0 - rng.nextDouble()) / lambda; - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/GaussianSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/GaussianSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/GaussianSampler.java deleted file mode 100644 index ed40cc8..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/GaussianSampler.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import java.util.Random; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; - -public class GaussianSampler implements Sampler<Double> -{ - double mean; - double std; - Random rng; - - public GaussianSampler(double mean, double std, SeedFactory seedFactory) - { - rng = new Random(seedFactory.getNextSeed()); - this.mean = mean; - this.std = std; - } - - public Double sample() - { - return rng.nextGaussian() * std + mean; - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/MonteCarloSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/MonteCarloSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/MonteCarloSampler.java deleted file mode 100644 index 0db8200..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/MonteCarloSampler.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import java.util.Random; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction; - - -public class MonteCarloSampler<T> implements Sampler<T> -{ - private final Sampler<T> stateSampler; - private final Random rng; - private final ProbabilityDensityFunction<T> acceptancePDF; - - public MonteCarloSampler(Sampler<T> stateGenerator, - ProbabilityDensityFunction<T> acceptancePDF, - SeedFactory seedFactory) - { - this.acceptancePDF = acceptancePDF; - this.stateSampler = stateGenerator; - - rng = new Random(seedFactory.getNextSeed()); - } - - public T sample() throws Exception - { - while(true) - { - T proposedState = this.stateSampler.sample(); - double probability = acceptancePDF.probability(proposedState); - double r = rng.nextDouble(); - - if(r < probability) - { - return proposedState; - } - } - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/RouletteWheelSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/RouletteWheelSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/RouletteWheelSampler.java deleted file mode 100644 index 0353708..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/RouletteWheelSampler.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import java.util.Collection; -import java.util.Map; -import java.util.Random; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.MultinomialPDF; -import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction; -import org.apache.commons.lang3.tuple.Pair; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Maps; - -public class RouletteWheelSampler<T> implements Sampler<T> -{ - Random rng; - final ImmutableList<Pair<T, Double>> wheel; - - public static <T> RouletteWheelSampler<T> create(Map<T, Double> domainWeights, SeedFactory factory) - { - return new RouletteWheelSampler<T>(domainWeights, factory); - } - - public static <T> RouletteWheelSampler<T> create(MultinomialPDF<T> pdf, SeedFactory factory) - { - return new RouletteWheelSampler<T>(pdf.getData(), pdf, factory); - } - - public static <T> RouletteWheelSampler<T> create(Collection<T> data, ProbabilityDensityFunction<T> pdf, SeedFactory factory) - { - return new RouletteWheelSampler<T>(data, pdf, factory); - } - - public static <T> RouletteWheelSampler<T> createUniform(Collection<T> data, SeedFactory factory) - { - Map<T, Double> pdf = Maps.newHashMap(); - for(T datum : data) - { - pdf.put(datum, 1.0); - } - - return create(pdf, factory); - } - - public RouletteWheelSampler(Map<T, Double> domainWeights, SeedFactory factory) - { - this.rng = new Random(factory.getNextSeed()); - this.wheel = this.normalize(domainWeights); - } - - public RouletteWheelSampler(Collection<T> data, ProbabilityDensityFunction<T> pdf, SeedFactory factory) - { - this.rng = new Random(factory.getNextSeed()); - - Map<T, Double> domainWeights = Maps.newHashMap(); - for(T datum : data) - { - double prob = pdf.probability(datum); - domainWeights.put(datum, prob); - } - - this.wheel = this.normalize(domainWeights); - } - - private ImmutableList<Pair<T, Double>> normalize(Map<T, Double> domainWeights) - { - double weightSum = 0.0; - for(Map.Entry<T, Double> entry : domainWeights.entrySet()) - { - weightSum += entry.getValue(); - } - - double cumProb = 0.0; - ImmutableList.Builder<Pair<T, Double>> builder = ImmutableList.builder(); - for(Map.Entry<T, Double> entry : domainWeights.entrySet()) - { - double prob = entry.getValue() / weightSum; - cumProb += prob; - - builder.add(Pair.of(entry.getKey(), cumProb)); - } - - return builder.build(); - } - - public T sample() - { - double r = rng.nextDouble(); - for(Pair<T, Double> cumProbPair : wheel) - if(r < cumProbPair.getValue()) - return cumProbPair.getKey(); - - throw new IllegalStateException("Invalid state -- RouletteWheelSampler should never fail to sample!"); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/Sampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/Sampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/Sampler.java deleted file mode 100644 index 08af7e0..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/Sampler.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -public interface Sampler<T> -{ - public T sample() throws Exception; -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/SequenceSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/SequenceSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/SequenceSampler.java deleted file mode 100644 index a81c846..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/SequenceSampler.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -public class SequenceSampler implements Sampler<Integer> -{ - Integer start; - Integer end; - Integer step; - Integer next; - - public SequenceSampler() - { - start = 0; - end = null; - step = 1; - next = start; - } - - public SequenceSampler(Integer start) - { - this.start = start; - end = null; - step = 1; - next = start; - } - - public SequenceSampler(Integer start, Integer end) - { - this.start = start; - this.end = end; - step = 1; - next = start; - } - - public SequenceSampler(Integer start, Integer end, Integer step) - { - this.start = start; - this.end = end; - this.step = step; - next = start; - } - - public Integer sample() throws Exception - { - if(end == null || next < end) - { - Integer current = next; - next = current + step; - return current; - } - - throw new Exception("All values have been sampled"); - } - - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/StatefulMonteCarloSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/StatefulMonteCarloSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/StatefulMonteCarloSampler.java deleted file mode 100644 index c447692..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/StatefulMonteCarloSampler.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import java.util.Random; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ConditionalProbabilityDensityFunction; - - -public class StatefulMonteCarloSampler<T> implements Sampler<T> -{ - private final Sampler<T> stateSampler; - private final Random rng; - private final ConditionalProbabilityDensityFunction<T, T> acceptancePDF; - private T currentState; - - public StatefulMonteCarloSampler(Sampler<T> stateGenerator, - ConditionalProbabilityDensityFunction<T, T> acceptancePDF, - T initialState, - SeedFactory seedFactory) - { - this.acceptancePDF = acceptancePDF; - this.stateSampler = stateGenerator; - - rng = new Random(seedFactory.getNextSeed()); - - this.currentState = initialState; - } - - public T sample() throws Exception - { - while(true) - { - T proposedState = this.stateSampler.sample(); - double probability = acceptancePDF.probability(proposedState, currentState); - double r = rng.nextDouble(); - - if(r < probability) - { - this.currentState = proposedState; - return proposedState; - } - } - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformIntSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformIntSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformIntSampler.java deleted file mode 100644 index 3fdf550..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformIntSampler.java +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import java.util.Random; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; - -public class UniformIntSampler implements Sampler<Integer> -{ - int lowerbound; - int upperbound; - Random rng; - - /* - * Upperbound is inclusive - */ - public UniformIntSampler(int lowerbound, int upperbound, SeedFactory seedFactory) - { - this.lowerbound = lowerbound; - this.upperbound = upperbound; - rng = new Random(seedFactory.getNextSeed()); - } - - public Integer sample() - { - int range = upperbound + 1 - lowerbound; - return rng.nextInt(range) + lowerbound; - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformSampler.java deleted file mode 100644 index 3f78471..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/samplers/UniformSampler.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.samplers; - -import java.util.Random; - -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; - -public class UniformSampler implements Sampler<Double> -{ - final Random rng; - final double lowerbound; - final double upperbound; - - public UniformSampler(SeedFactory seedFactory) - { - rng = new Random(seedFactory.getNextSeed()); - lowerbound = 0.0; - upperbound = 1.0; - } - - public UniformSampler(double lowerbound, double upperbound, SeedFactory seedFactory) - { - rng = new Random(seedFactory.getNextSeed()); - this.lowerbound = lowerbound; - this.upperbound = upperbound; - } - - public Double sample() - { - return (upperbound - lowerbound) * rng.nextDouble() + lowerbound; - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/ConditionalWeightFunction.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/ConditionalWeightFunction.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/ConditionalWeightFunction.java deleted file mode 100644 index 603e5e9..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/ConditionalWeightFunction.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.wfs; - -public interface ConditionalWeightFunction<T, S> -{ - public double weight(T datum, S given); -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/WeightFunction.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/WeightFunction.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/WeightFunction.java deleted file mode 100644 index 1145043..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/framework/wfs/WeightFunction.java +++ /dev/null @@ -1,21 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.framework.wfs; - -public interface WeightFunction<T> -{ - public double weight(T datum); -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerLocationPDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerLocationPDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerLocationPDF.java deleted file mode 100644 index bb97a60..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerLocationPDF.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.customer; - -import java.util.List; -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; - -public class CustomerLocationPDF implements ProbabilityDensityFunction<ZipcodeRecord> -{ - private final Map<ZipcodeRecord, Double> pdf; - - public CustomerLocationPDF(List<ZipcodeRecord> zipcodes, Store store, double averageDistance) - { - this.pdf = build(zipcodes, store, averageDistance); - } - - protected ImmutableMap<ZipcodeRecord, Double> build(List<ZipcodeRecord> zipcodeTable, - Store store, double averageDistance) - { - double lambda = 1.0 / averageDistance; - - Map<ZipcodeRecord, Double> zipcodeWeights = Maps.newHashMap(); - double totalWeight = 0.0; - for(ZipcodeRecord record : zipcodeTable) - { - double dist = record.distance(store.getLocation()); - - double weight = lambda * Math.exp(-1.0 * lambda * dist); - totalWeight += weight; - zipcodeWeights.put(record, weight); - } - - Map<ZipcodeRecord, Double> pdf = Maps.newHashMap(); - for(ZipcodeRecord record : zipcodeTable) - { - pdf.put(record, zipcodeWeights.get(record) / totalWeight); - } - - return ImmutableMap.copyOf(pdf); - } - - public double probability(ZipcodeRecord record) - { - if(!this.pdf.containsKey(record)) - return 0.0; - - return this.pdf.get(record); - } -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSampler.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSampler.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSampler.java deleted file mode 100644 index 8ef96f0..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSampler.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.customer; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ConditionalSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.commons.lang3.tuple.Pair; - -public class CustomerSampler implements Sampler<Customer> -{ - private final Sampler<Integer> idSampler; - private final Sampler<String> firstNameSampler; - private final Sampler<String> lastNameSampler; - private final Sampler<Store> storeSampler; - private final ConditionalSampler<ZipcodeRecord, Store> locationSampler; - - - public CustomerSampler(Sampler<Integer> idSampler, Sampler<String> firstNameSampler, - Sampler<String> lastNameSampler, Sampler<Store> storeSampler, - ConditionalSampler<ZipcodeRecord, Store> locationSampler) - { - this.idSampler = idSampler; - this.firstNameSampler = firstNameSampler; - this.lastNameSampler = lastNameSampler; - this.storeSampler = storeSampler; - this.locationSampler = locationSampler; - } - - public Customer sample() throws Exception - { - Integer id = idSampler.sample(); - Pair<String, String> name = Pair.of(firstNameSampler.sample(), - lastNameSampler.sample()); - Store store = storeSampler.sample(); - ZipcodeRecord location = locationSampler.sample(store); - - return new Customer(id, name, store, location); - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSamplerBuilder.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSamplerBuilder.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSamplerBuilder.java deleted file mode 100644 index 4b449e8..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerSamplerBuilder.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.customer; - -import java.util.List; -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.Constants; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Customer; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.InputData; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.inputs.ZipcodeRecord; -import org.apache.bigtop.bigpetstore.datagenerator.framework.SeedFactory; -import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.ConditionalSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.RouletteWheelSampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.Sampler; -import org.apache.bigtop.bigpetstore.datagenerator.framework.samplers.SequenceSampler; - -import com.google.common.collect.Maps; - -public class CustomerSamplerBuilder -{ - private final List<Store> stores; - private final InputData inputData; - private final SeedFactory seedFactory; - - public CustomerSamplerBuilder(List<Store> stores, InputData inputData, SeedFactory seedFactory) - { - this.stores = stores; - this.seedFactory = seedFactory; - this.inputData = inputData; - } - - protected ConditionalSampler<ZipcodeRecord, Store> buildLocationSampler() - { - final Map<Store, Sampler<ZipcodeRecord>> locationSamplers = Maps.newHashMap(); - for(Store store : stores) - { - ProbabilityDensityFunction<ZipcodeRecord> locationPDF = new CustomerLocationPDF(inputData.getZipcodeTable(), - store, Constants.AVERAGE_CUSTOMER_STORE_DISTANCE); - Sampler<ZipcodeRecord> locationSampler = RouletteWheelSampler.create(inputData.getZipcodeTable(), locationPDF, seedFactory); - locationSamplers.put(store, locationSampler); - } - - return new ConditionalSampler<ZipcodeRecord, Store>() - { - public ZipcodeRecord sample(Store store) throws Exception - { - return locationSamplers.get(store).sample(); - } - }; - } - - public Sampler<Customer> build() - { - ProbabilityDensityFunction<Store> storePDF = new CustomerStorePDF(stores); - - Sampler<Integer> idSampler = new SequenceSampler(); - Sampler<String> firstNameSampler = RouletteWheelSampler.create(inputData.getNames().getFirstNames(), seedFactory); - Sampler<String> lastNameSampler = RouletteWheelSampler.create(inputData.getNames().getLastNames(), seedFactory); - Sampler<Store> storeSampler = RouletteWheelSampler.create(stores, storePDF, seedFactory); - - return new CustomerSampler(idSampler, firstNameSampler, lastNameSampler, storeSampler, buildLocationSampler()); - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerStorePDF.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerStorePDF.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerStorePDF.java deleted file mode 100644 index 400b02a..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/customer/CustomerStorePDF.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.customer; - -import java.util.List; - -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Store; -import org.apache.bigtop.bigpetstore.datagenerator.framework.pdfs.ProbabilityDensityFunction; - -public class CustomerStorePDF implements ProbabilityDensityFunction<Store> -{ - double populationSum = 0.0; - - public CustomerStorePDF(List<Store> stores) - { - for(Store store : stores) - { - populationSum += (double) store.getLocation().getPopulation(); - } - } - - @Override - public double probability(Store store) - { - return ((double) store.getLocation().getPopulation()) / populationSum; - } - -} http://git-wip-us.apache.org/repos/asf/bigtop/blob/3bbbb557/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java ---------------------------------------------------------------------- diff --git a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java b/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java deleted file mode 100644 index c7dd0ab..0000000 --- a/bigtop-bigpetstore/bigpetstore-data-generator/src/main/java/org/apache/bigtop/bigpetstore/datagenerator/generators/products/ProductBuilderIterator.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.bigtop.bigpetstore.datagenerator.generators.products; - -import java.util.Iterator; -import java.util.Map; - -import org.apache.bigtop.bigpetstore.datagenerator.Constants; -import org.apache.bigtop.bigpetstore.datagenerator.datamodels.Product; - -import com.google.common.collect.Maps; - -public class ProductBuilderIterator implements Iterator<Product> -{ - Iterator<Map<String, ProductFieldValue>> productIterator; - double basePrice; - String productCategory; - - public ProductBuilderIterator(double basePrice, String productCategory, - Iterator<Map<String, ProductFieldValue>> productIterator) - { - this.productIterator = productIterator; - this.basePrice = basePrice; - this.productCategory = productCategory; - } - - @Override - public boolean hasNext() - { - return productIterator != null && productIterator.hasNext(); - } - - @Override - public Product next() - { - Map<String, ProductFieldValue> productComponents = productIterator.next(); - - double sum = 0.0; - double product = 1.0; - - Map<String, Object> productFields = Maps.newHashMap(); - - for(Map.Entry<String, ProductFieldValue> entry : productComponents.entrySet()) - { - productFields.put(entry.getKey(), entry.getValue().getValue()); - sum += entry.getValue().getAdd(); - product *= entry.getValue().getMultiply(); - } - - double quantity = (Double) productFields.get(Constants.PRODUCT_QUANTITY); - double price = product * (sum + basePrice); - double unitPrice = price / quantity; - - productFields.put(Constants.PRODUCT_UNIT_PRICE, unitPrice); - productFields.put(Constants.PRODUCT_PRICE, price); - productFields.put(Constants.PRODUCT_CATEGORY, productCategory); - - return new Product(productFields); - } - - @Override - public void remove() - { - throw new UnsupportedOperationException("ProductBuilder does not support remove()"); - } - -}
