summaryrefslogtreecommitdiff
path: root/java/src/org/singinst/uf/model/MooreAsymptote.java
blob: 0b2a04898eacfd8e8d8803256b2d4302b1c7616b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package org.singinst.uf.model;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import org.singinst.uf.math.SimplePoint;
import org.singinst.uf.presenter.DraggableLine;
import org.singinst.uf.presenter.HtmlUtil;
import org.singinst.uf.presenter.LineBounds;
import org.singinst.uf.presenter.ScalarValuePointList;
import org.singinst.uf.presenter.SimpleStyle;

public class MooreAsymptote {
	private final ScalarSchema scalarSchema;
	private final LineBounds domain;
	private final ScalarValuePointList curvePointList;
	private final DraggableLine asymptotePointList;

	public MooreAsymptote(Node node, LineBounds domain, LineBounds asymptoteRange, NotablePercentile percentile) {
		asymptotePointList = new MooreDraggableLine(this, percentile);
		SimpleStyle style = new SimpleStyle(percentile.getColor());
		curvePointList = new ScalarValuePointList(style);
		this.domain = domain;
		int percentileValue = percentile.getValue();
		String name = "k" + percentileValue;
		scalarSchema = new ScalarSchema(node, name, asymptoteRange, "(log) FLOPS/$", HtmlUtil.style(style, percentile.getText("early", "late") + " stop: 10 to the "), "", null, true);
	}

	public Collection<? extends ScalarValuePointList> getPointLists() {
		return Arrays.asList(asymptotePointList(), curvePointList());
	}

	private ScalarValuePointList curvePointList() {
		List<SimplePoint> pointSamples = new ArrayList<SimplePoint>();
		for (double x : domain.getSpanningSamples(101)) {
			pointSamples.add(new SimplePoint(x, yFromX(x)));
		}
		curvePointList.setHypothesisPoints(pointSamples);
		return curvePointList;
	}

	private static final long T0 = 2008;
	private static final double P0_NON_LOG = 10280000;
	private static final double P0_LOG = Math.log(P0_NON_LOG);	
	private static final double DOUBLING_TIME_IN_YEARS = 1.5;
	private static final double R = Math.log(2) / DOUBLING_TIME_IN_YEARS;
	private double yFromX(double x) {
		double exponentialGrowthFactor = Math.exp(R * (x - T0));
		double kNoLog = Math.pow(10, getConjecture().getValue());
		double numerator = (kNoLog) * P0_NON_LOG * exponentialGrowthFactor;
		double denominator = (kNoLog) + P0_NON_LOG * (exponentialGrowthFactor - 1);
		double functionalYNoLog = numerator / denominator;
		return Math.log10(functionalYNoLog);
	}

	private ScalarValuePointList asymptotePointList() {
		double y = getConjecture().getValue();
		asymptotePointList.setHypothesisPoints(Arrays.asList(
				new SimplePoint(domain.getLowerBound(), y),
				new SimplePoint(domain.getUpperBound(), y)));
		return asymptotePointList;
	}

	public ScalarValueHolder getConjecture() {
		return scalarSchema.getScalarValueHolder();
	}

	public ScalarSchema getScalar() {
		return scalarSchema;
	}

	public void setY(double y) {
		scalarSchema.getScalarValueHolder().setValue(y);	
	}

	public static double unboundedLnFlopsPerDollarAtYear(double year) {
		double unboundedLnFlopsPerDollar = P0_LOG + (R * (year - T0));
		//LogUtil.info("at year " + year + ", natural log unbounded flops per dollar is " + unboundedLnFlopsPerDollar);
		return unboundedLnFlopsPerDollar;
	}
}