Example usage for org.apache.mahout.math.jet.random Exponential Exponential

List of usage examples for org.apache.mahout.math.jet.random Exponential Exponential

Introduction

In this page you can find the example usage for org.apache.mahout.math.jet.random Exponential Exponential.

Prototype

public Exponential(double lambda, Random randomGenerator) 

Source Link

Document

Provides a negative exponential distribution given a rate parameter lambda and an underlying random number generator.

Usage

From source file:com.mapr.franz.Traffic.java

License:Apache License

public static void main(String[] args) throws InterruptedException, IOException, ServiceException {
    Options options = parseOptions(args);
    log.warn("Options = {}", options.toString());

    double scale = Math.log(options.ratio) / 2;

    Client client = new Client(Collections.singleton(new PeerInfo(options.host, options.port)));

    History recorder = new History(1, 10, 30).logTicks();

    Random gen = RandomUtils.getRandom();
    ChineseRestaurant topicSampler = new ChineseRestaurant(options.alpha);
    Exponential interval = new Exponential(1, gen);
    double t = 0;
    long t0 = System.nanoTime();
    long messageId = 0;
    while (messageId < options.max) {
        double rate = options.peak * Math.exp(-scale * (Math.cos(2 * Math.PI * t / options.period) + 1));
        double dt = interval.nextDouble() / rate;
        t += dt;//from   w w  w .j  a v  a 2  s .c om
        double now = (System.nanoTime() - t0) / 1e9;
        if (t > now + 0.01) {
            double millis = Math.floor((t - now) * 1000);
            double nanos = Math.rint((t - now) * 1e9 - millis * 1e6);
            Thread.sleep((long) millis, (int) nanos);
        }

        String topic = "topic-" + topicSampler.sample();
        String message = "m-" + (++messageId);
        client.sendMessage(topic, message);
        recorder.message(topic);
        log.debug("Sent {} / {}", topic, message);
        if ((messageId % 10000) == 0) {
            log.warn("Sent {} messages", messageId);
        }
    }
}

From source file:com.mapr.synth.samplers.CommonPointOfCompromise.java

License:Apache License

@Override
public JsonNode sample() {
    ArrayNode r = nodeFactory.arrayNode();

    double t = start;
    double averageInterval = TimeUnit.MILLISECONDS.convert(1, TimeUnit.DAYS) / transactionsPerDay.nextDouble();
    Exponential interval = new Exponential(1 / averageInterval, gen);

    Date date = new Date();
    boolean compromised = false;
    while (t < end) {
        ObjectNode transaction = new ObjectNode(nodeFactory);
        t += interval.nextDouble();/*from w  ww .ja v a  2s .  c  o  m*/
        date.setTime((long) t);
        transaction.set("timestamp", new LongNode((long) (t / 1000)));
        transaction.set("date", new TextNode(df.format(date)));
        Integer merchantId = merchant.sample();
        transaction.set("merchant", new IntNode(merchantId));

        if (merchantId == 0 && t >= compromiseStart && t < compromiseEnd) {
            compromised = true;
            transaction.set("compromise", new IntNode(1));
        } else {
            transaction.set("compromise", new IntNode(0));
        }

        if (t > exploitEnd) {
            compromised = false;
        }

        double pFraud;
        if (t >= exploitStart && compromised) {
            pFraud = compromisedFraudRate;
        } else {
            pFraud = uncompromisedFraudRate;
        }

        transaction.set("fraud", new IntNode((gen.nextDouble() < pFraud) ? 1 : 0));

        r.add(transaction);
    }
    return r;
}

From source file:com.mapr.synth.User.java

License:Apache License

public User(InetAddress address, String geoCode, TermGenerator terms, double period) {
    this.terms = terms;
    this.geoCode = geoCode;
    this.address = address;
    this.rate = period;
    this.sessionTimeDistribution = new Exponential(period, RandomUtils.getRandom());

    id = idCounter.addAndGet(1);//from   w  w  w . j  a va  2s  . com
    nextSession = sessionTimeDistribution.nextDouble();
}