diff options
author | zero <zero@66b5f39b-87a2-44c3-adb7-4b08653a3962> | 2009-11-26 03:21:07 +0000 |
---|---|---|
committer | zero <zero@66b5f39b-87a2-44c3-adb7-4b08653a3962> | 2009-11-26 03:21:07 +0000 |
commit | d5c52cdd947c1d3307fc69254fde578f7c4b3c62 (patch) | |
tree | 39a7f3fa73cc600a320e49c851eb356d4c58fbad | |
parent | 0cdeb099d6881ea65107d2b66f72f67659a29fd9 (diff) | |
download | uncertainfuture-d5c52cdd947c1d3307fc69254fde578f7c4b3c62.tar.gz uncertainfuture-d5c52cdd947c1d3307fc69254fde578f7c4b3c62.zip |
Removed old org/
git-svn-id: svn+ssh://10.37.55.100/usr/local/svn/uf@6 66b5f39b-87a2-44c3-adb7-4b08653a3962
101 files changed, 0 insertions, 7320 deletions
diff --git a/java/src/org/apache/commons/math/MathException.java b/java/src/org/apache/commons/math/MathException.java deleted file mode 100644 index 7e153f5..0000000 --- a/java/src/org/apache/commons/math/MathException.java +++ /dev/null @@ -1,268 +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.commons.math; - -import java.io.PrintStream; -import java.io.PrintWriter; -import java.text.MessageFormat; -import java.util.Locale; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - - -/** -* Base class for commons-math checked exceptions. -* <p> -* Supports nesting, emulating JDK 1.4 behavior if necessary.</p> -* <p> -* Adapted from {@link org.apache.commons.collections.FunctorException}.</p> -* -* @version $Revision: 620312 $ $Date: 2008-02-10 12:28:59 -0700 (Sun, 10 Feb 2008) $ -*/ -public class MathException extends Exception { - - /** Serializable version identifier */ - private static final long serialVersionUID = -8602234299177097102L; - - /** - * Does JDK support nested exceptions? - */ - private static final boolean JDK_SUPPORTS_NESTED = true; - - /** Cache for resources bundle. */ - private static ResourceBundle cachedResources = null; - - /** - * Pattern used to build the message. - */ - private final String pattern; - - /** - * Arguments used to build the message. - */ - private final Object[] arguments; - - /** - * Root cause of the exception - */ - private final Throwable rootCause; - - /** - * Translate a string to a given locale. - * @param s string to translate - * @param locale locale into which to translate the string - * @return translated string or original string - * for unsupported locales or unknown strings - */ - private static String translate(String s, Locale locale) { - try { - if ((cachedResources == null) || (! cachedResources.getLocale().equals(locale))) { - // caching the resource bundle - cachedResources = - ResourceBundle.getBundle("org.apache.commons.math.MessagesResources", locale); - } - - if (cachedResources.getLocale().getLanguage().equals(locale.getLanguage())) { - // the value of the resource is the translated string - return cachedResources.getString(s); - } - - } catch (MissingResourceException mre) { - // do nothing here - } - - // the locale is not supported or the resource is unknown - // don't translate and fall back to using the string as is - return s; - - } - - /** - * Builds a message string by from a pattern and its arguments. - * @param pattern format specifier - * @param arguments format arguments - * @param locale Locale in which the message should be translated - * @return a message string - */ - private static String buildMessage(String pattern, Object[] arguments, Locale locale) { - // do it the hard way, for Java 1.3. compatibility - MessageFormat mf = new MessageFormat(translate(pattern, locale)); - mf.setLocale(locale); - return mf.format(arguments); - } - - /** - * Constructs a new <code>MathException</code> with no - * detail message. - */ - public MathException() { - super(); - this.pattern = null; - this.arguments = new Object[0]; - this.rootCause = null; - } - - /** - * Constructs a new <code>MathException</code> with specified - * detail message. - * - * @param msg the error message. - * @deprecated as of 1.2, replaced by {@link #MathException(String, Object[])} - */ - public MathException(String msg) { - super(msg); - this.pattern = msg; - this.arguments = new Object[0]; - this.rootCause = null; - } - - /** - * Constructs a new <code>MathException</code> with specified - * formatted detail message. - * Message formatting is delegated to {@link java.text.MessageFormat}. - * @param pattern format specifier - * @param arguments format arguments - */ - public MathException(String pattern, Object[] arguments) { - super(buildMessage(pattern, arguments, Locale.US)); - this.pattern = pattern; - this.arguments = (Object[]) arguments.clone(); - this.rootCause = null; - } - - /** - * Constructs a new <code>MathException</code> with specified - * nested <code>Throwable</code> root cause. - * - * @param rootCause the exception or error that caused this exception - * to be thrown. - */ - public MathException(Throwable rootCause) { - super((rootCause == null ? null : rootCause.getMessage())); - this.pattern = getMessage(); - this.arguments = new Object[0]; - this.rootCause = rootCause; - } - - /** - * Constructs a new <code>MathException</code> with specified - * detail message and nested <code>Throwable</code> root cause. - * - * @param msg the error message. - * @param rootCause the exception or error that caused this exception - * to be thrown. - * @deprecated as of 1.2, replaced by {@link #MathException(String, Object[], Throwable)} - */ - public MathException(String msg, Throwable rootCause) { - super(msg); - this.pattern = msg; - this.arguments = new Object[0]; - this.rootCause = rootCause; - } - - /** - * Constructs a new <code>MathException</code> with specified - * formatted detail message and nested <code>Throwable</code> root cause. - * Message formatting is delegated to {@link java.text.MessageFormat}. - * @param pattern format specifier - * @param arguments format arguments - * @param rootCause the exception or error that caused this exception - * to be thrown. - * @since 1.2 - */ - public MathException(String pattern, Object[] arguments, Throwable rootCause) { - super(buildMessage(pattern, arguments, Locale.US)); - this.pattern = pattern; - this.arguments = (Object[]) arguments.clone(); - this.rootCause = rootCause; - } - - /** Gets the pattern used to build the message of this throwable. - * - * @return the pattern used to build the message of this throwable - * @since 1.2 - */ - public String getPattern() { - return pattern; - } - - /** Gets the arguments used to build the message of this throwable. - * - * @return the arguments used to build the message of this throwable - * @since 1.2 - */ - public Object[] getArguments() { - return (Object[]) arguments.clone(); - } - - /** Gets the message in a specified locale. - * - * @param locale Locale in which the message should be translated - * - * @return localized message - * @since 1.2 - */ - public String getMessage(Locale locale) { - return (pattern == null) ? null : buildMessage(pattern, arguments, locale); - } - - /** - * Gets the cause of this throwable. - * - * @return the cause of this throwable, or <code>null</code> - */ - public Throwable getCause() { - return rootCause; - } - - /** - * Prints the stack trace of this exception to the standard error stream. - */ - public void printStackTrace() { - printStackTrace(System.err); - } - - /** - * Prints the stack trace of this exception to the specified stream. - * - * @param out the <code>PrintStream</code> to use for output - */ - public void printStackTrace(PrintStream out) { - synchronized (out) { - PrintWriter pw = new PrintWriter(out, false); - printStackTrace(pw); - // Flush the PrintWriter before it's GC'ed. - pw.flush(); - } - } - - /** - * Prints the stack trace of this exception to the specified writer. - * - * @param out the <code>PrintWriter</code> to use for output - */ - public void printStackTrace(PrintWriter out) { - synchronized (out) { - super.printStackTrace(out); - if (rootCause != null && JDK_SUPPORTS_NESTED == false) { - out.print("Caused by: "); - rootCause.printStackTrace(out); - } - } - } - -} diff --git a/java/src/org/singinst/uf/common/LogUtil.java b/java/src/org/singinst/uf/common/LogUtil.java deleted file mode 100644 index c316b54..0000000 --- a/java/src/org/singinst/uf/common/LogUtil.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.singinst.uf.common;
-
-
-public class LogUtil {
-
- public static void error(Exception e) {
- e.printStackTrace();
-
- }
-
- public static void info(String string) {
- System.err.println(string);
- }
-
-}
diff --git a/java/src/org/singinst/uf/common/StringUtil.java b/java/src/org/singinst/uf/common/StringUtil.java deleted file mode 100644 index 48004f7..0000000 --- a/java/src/org/singinst/uf/common/StringUtil.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.singinst.uf.common;
-
-import java.util.Collection;
-
-public class StringUtil {
- public static String join(String delimiter, Collection<String> collection) {
- StringBuilder builder = new StringBuilder();
- boolean first = true;
- for (String string : collection) {
- if (!first) {
- builder.append(delimiter);
- }
- first = false;
- builder.append(string);
- }
- return builder.toString();
- }
-}
diff --git a/java/src/org/singinst/uf/math/InvertableFunction.java b/java/src/org/singinst/uf/math/InvertableFunction.java deleted file mode 100644 index 7481da6..0000000 --- a/java/src/org/singinst/uf/math/InvertableFunction.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.singinst.uf.math;
-
-public abstract class InvertableFunction {
-
- public static final InvertableFunction IDENTITY = new InvertableFunction() {
-
- @Override
- public double apply(double x) {
- return x;
- }
-
- @Override
- public double invert(double y) {
- return y;
- }
-
- };
-
- public abstract double apply(double x);
- public abstract double invert(double y);
-
- public InvertableFunction invert() {
- return new InvertedFunction(this);
- }
-
-}
diff --git a/java/src/org/singinst/uf/math/InvertedFunction.java b/java/src/org/singinst/uf/math/InvertedFunction.java deleted file mode 100644 index ca91c27..0000000 --- a/java/src/org/singinst/uf/math/InvertedFunction.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.singinst.uf.math;
-
-public class InvertedFunction extends InvertableFunction {
-
- private final InvertableFunction originalFunction;
-
- public InvertedFunction(InvertableFunction originalFunction) {
- this.originalFunction = originalFunction;
- }
-
- @Override
- public double apply(double x) {
- return originalFunction.invert(x);
- }
-
- @Override
- public double invert(double y) {
- return originalFunction.apply(y);
- }
-
- @Override
- public InvertableFunction invert() {
- return originalFunction;
- }
-}
diff --git a/java/src/org/singinst/uf/math/LinearTransform.java b/java/src/org/singinst/uf/math/LinearTransform.java deleted file mode 100644 index 42f5a9d..0000000 --- a/java/src/org/singinst/uf/math/LinearTransform.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.singinst.uf.math;
-
-import org.singinst.uf.presenter.LineBounds;
-
-public class LinearTransform extends InvertableFunction {
-
- private final double scale;
- private final double offset;
-
- public LinearTransform(LineBounds from, LineBounds to) {
- scale = to.getLength() / from.getLength();
- offset = to.getFirst() - scale * from.getFirst();
- assert apply(from.getFirst()) == to.getFirst();
- assert apply(from.getSecond()) == to.getSecond();
- }
-
- @Override
- public final double apply(double x) {
- return scale * x + offset;
- }
-
- @Override
- public double invert(double y) {
- return (y - offset) / scale;
- }
-
-}
diff --git a/java/src/org/singinst/uf/math/MathUtil.java b/java/src/org/singinst/uf/math/MathUtil.java deleted file mode 100644 index 1f7c4b4..0000000 --- a/java/src/org/singinst/uf/math/MathUtil.java +++ /dev/null @@ -1,763 +0,0 @@ -package org.singinst.uf.math;
-
-import java.math.BigDecimal;
-import java.math.RoundingMode;
-import java.util.Random;
-
-import org.apache.commons.math.MathException;
-import org.apache.commons.math.distribution.NormalDistributionImpl;
-import org.apache.commons.math.special.Erf;
-
-public class MathUtil {
-
- public static double[] unwrapDoubleList(java.util.List<Double> l) {
- double[] retVal = new double[l.size()];
- for (int i=0; i<retVal.length; ++i) retVal[i] = l.get(i);
- return retVal;
- }
- public static java.util.ArrayList<Double> wrapDoubleArray(double[] a) {
- java.util.ArrayList<Double> retVal = new java.util.ArrayList<Double>(a.length);
- for (int i=0; i<a.length; ++i) retVal.add(a[i]);
- return retVal;
- }
-
- public static double clog(double p) {
- return -Math.log1p(-p);
- }
- public static double expc(double q) {
- return -Math.expm1(-q);
- }
-
- public static double logit(double p) {
- if (p<0 || p>1) { return Double.NaN; }
- if (p==0) { return Double.NEGATIVE_INFINITY; }
- if (p==1) { return Double.POSITIVE_INFINITY; }
- // if (p>0.25) { return Math.atanh(p*2-1)*2;...? oh }
- return Math.log(p/(1-p));
- }
- public static double logistic(double t) {
- return 1/(1+Math.exp(-t));
- }
-
- public static double log_logistic(double t) {
- //return Math.log(logistic(t));
- if (t <= -38) {
- return t;
- } else if (t > 38) {
- return -Math.exp(-t);
- }
- if (t<0) {
- return t - Math.log1p(Math.exp(t));
- } else {
- double r = Math.exp(-t);
- return Math.log1p(-r/(1+r));
- }
- }
- public static double logit_exp(double b) {
- //return logit(Math.exp(b));
- return b - Math.log(-Math.expm1(b));
- }
- public static double clog_logistic(double t) {
- return -log_logistic(-t);
- }
- public static double logit_expc(double q) {
- //return logit(expc(q));
- return q + Math.log(-Math.expm1(-q));
- }
-
- public static final double DOUBLE_EPS = 1-(1-(double)1.2e-16);
- static final double SQRT_ONE_OVER_EIGHT_PI = Math.sqrt(1/(8*Math.PI));
- static final double SQRT_ONE_HALF = Math.sqrt(0.5);
- public static double cumulativeNormalDistribution(double mean,
- double stdDev, double x) {
- try {
- double Z = (x - mean)/stdDev;
- if (Z<=-38.5) {
- return 0;
- } else if (Z>8.3) {
- return 1;
- } else if (Z<-1.15) {
- // absTol = DOUBLE_EPS/-Z because lg2(Z) mantissa bits in Z are lost as exponent bits in exp(-Z*Z/2)
- return SQRT_ONE_OVER_EIGHT_PI * normalTailCF(Z*Z/2, DOUBLE_EPS/-Z) * (-Z) * Math.exp(-Z*Z/2);
- } else if (Z>2) {
- double absTol = Math.exp(Z*Z/2)*DOUBLE_EPS/Z;
- return 1 - SQRT_ONE_OVER_EIGHT_PI * normalTailCF(Z*Z/2, absTol) * (Z) * Math.exp(-Z*Z/2);
- } else {
- // jakarta commons implementation is acceptable
- return 0.5 * (1+Erf.erf(Z*SQRT_ONE_HALF));
- }
- } catch (MathException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static double logitCumulativeNormalDistribution(double mean,
- double stdDev, double x) {
- try {
- double Z = (x - mean)/stdDev;
- double aZ = Math.abs(Z);
- if (aZ >= 1e9) {
- return Math.signum(Z)/2*Z*Z;
- } else if (aZ >= 2e4) {
- return Math.signum(Z)*(Z*Z/2-Math.log(SQRT_ONE_OVER_EIGHT_PI * 2/aZ));
- } else if (aZ >= 1.15) {
- double clogp = Z*Z/2-Math.log(SQRT_ONE_OVER_EIGHT_PI * normalTailCF(Z*Z/2, DOUBLE_EPS/aZ) * aZ);
- return Math.signum(Z)*(clogp+Math.log1p(-Math.exp(-clogp)));
- } else {
- double e = Erf.erf(Z*SQRT_ONE_HALF);
- return Math.log1p(e)-Math.log1p(-e);
- }
- } catch (MathException e) {
- throw new RuntimeException(e);
- }
- }
-
- public static double linterp(double x0, double x1, double y0, double y1, double x) {
- if (x0==x1) { return (y0+y1)/2; }
- if (Math.abs(x1)>Math.abs(x0)) {
- if (Math.abs(x) <= Math.abs(x0)) {
- double b = (x0/(x0-x1)) * (y1-y0) + y0;
- return (x/x1) * (y1-b) + b;
- } else {
- return ((x-x0)/(x1-x0)) * (y1-y0) + y0;
- }
- } else {
- if (Math.abs(x) <= Math.abs(x1)) {
- double b = (x1/(x1-x0)) * (y0-y1) + y1;
- return (x/x0) * (y0-b) + b;
- } else {
- return ((x-x1)/(x0-x1)) * (y0-y1) + y1;
- }
- }
- }
-
- public static double linterp(double[] x, double[] y, double nx) {
- if (y.length <= 1) { return y[0]; } // ArrayIndexOutOfBoundsException if y.length==0
- if (nx == Double.POSITIVE_INFINITY) {
- double yu = y[y.length-1], ypu = y[y.length-2];
- if (yu>ypu) {
- return Double.POSITIVE_INFINITY;
- } else if (yu<ypu) {
- return Double.NEGATIVE_INFINITY;
- } else {
- return yu;
- }
- }
- if (nx == Double.NEGATIVE_INFINITY) {
- double yu = y[0], ypu = y[1];
- if (yu>ypu) {
- return Double.POSITIVE_INFINITY;
- } else if (yu<ypu) {
- return Double.NEGATIVE_INFINITY;
- } else {
- return yu;
- }
- }
- int n = java.util.Arrays.binarySearch(x, nx);
- if (n >= 0) { return y[n]; }
- else if (n == -1) { n = -2; }
- else if (n == -x.length-1) { n = -x.length; }
- n = -n-1;
- return linterp(x[n-1], x[n], y[n-1], y[n], nx);
- }
-
- public static double[] linterp(double[] x, double[] y, double[] nx) {
- double[] ny = new double[nx.length];
- for (int i=0; i<nx.length; ++i) {
- ny[i] = linterp(x, y, nx[i]);
- }
- return ny;
- }
-
- public static double normalTailCF(double t, double absTol) {
- /* Disclaimer: I am not a numerical analyst */
- double p,q,r,s,pn,qn,rn,sn,b,f,fn;
- b = 0;
- pn = 0; qn = 1; rn = 1; sn = t;
- fn = 1/t;
- for (int k=1; k<400; k=k+2) {
- p = pn; q = qn; r = rn; s = sn; f = fn;
- /* continued fraction */
- pn = (k)*p + (q+q);
- qn = (k)*t*p + ((k+1)+(t+t))*q;
- rn = (k)*r + (s+s);
- sn = (k)*t*r + ((k+1)+(t+t))*s;
- // dirty trick, b=0 might go faster
- b = ((k+1)*(b+t))/((k)+(b+b)+(t+t));
- fn = (pn*b+qn)/(rn*b+sn);
- if (Math.abs(fn-f)<=absTol) {
- /* eh */
- break;
- }
- }
-// org.singinst.uf.common.LogUtil.info(String.format("Z = %20.16g, fn = %20.16g", Z, fn));
- return fn;
- }
-
- public static double inverseCumulativeProbability(double mean,
- double stdDev, double probability) {
- try {
- return new NormalDistributionImpl(mean, stdDev).inverseCumulativeProbability(probability);
- } catch (MathException e) {
- throw new RuntimeException(e);
- }
- }
-
- static final double EXPM1MX_IS_1_OVER_64_NEG = -0.18214213554545234604d;
- static final double EXPM1MX_IS_1_OVER_64_POS = 0.17171823868001516350d;
- public static double expm1mx(double x) {
- if (x>EXPM1MX_IS_1_OVER_64_POS || x<EXPM1MX_IS_1_OVER_64_NEG) {
- return Math.expm1(x)-x;
- } else {
- return ((((((((((1/39916800d)*x+1/3628800d)*x+1/362880d)*x+1/40320d)*x+1/5040d)*x+1/720d)*x+1/120d)*x+1/24d)*x+1/6d)*x+1/2d)*x*x;
- }
- }
- public static double expm1mxox(double x) {
- if (x>EXPM1MX_IS_1_OVER_64_POS || x<EXPM1MX_IS_1_OVER_64_NEG) {
- return (Math.expm1(x)-x)/x;
- } else {
- return ((((((((((1/39916800d)*x+1/3628800d)*x+1/362880d)*x+1/40320d)*x+1/5040d)*x+1/720d)*x+1/120d)*x+1/24d)*x+1/6d)*x+1/2d)*x;
- }
- }
- public static double exprel_2(double x) {
- if (x>EXPM1MX_IS_1_OVER_64_POS || x<EXPM1MX_IS_1_OVER_64_NEG) {
- return (Math.expm1(x)-x)/x/x;
- } else {
- return ((((((((((1/39916800d)*x+1/3628800d)*x+1/362880d)*x+1/40320d)*x+1/5040d)*x+1/720d)*x+1/120d)*x+1/24d)*x+1/6d)*x+1/2d);
- }
- }
- public static double exprel(double x) {
- if (x!=0) {
- return Math.expm1(x)/x;
- }
- else {
- return 1;
- }
- }
-
-
- static final double INTEGRAL_EXP_INTEGRAL_EXP_2O_LIM = 2.7878174747222281e-11d/24;
- public static double rpn_b_expm1_a_t_a_expm1_b_t_m_a_b_p_3_d_exp_d_a_d_b_d_a_b_m_d(double a, double b) {
- //return (b*Math.expm1(a)-a*Math.expm1(b))/Math.exp((a+b)/3)/a/b/(a-b);
- double s = (a*a + b*b - a*b)*(1/3d);
-
- if (s<INTEGRAL_EXP_INTEGRAL_EXP_2O_LIM) {
- return 0.5+s*(1/24d);
- }
-
- if (s>24) {
- double amb = a-b;
- if (Math.abs(amb)>Math.abs(a) && Math.abs(amb)>Math.abs(a)) {
- return Math.exp((-1/3d)*(a+b))*(expm1mxox(a)-expm1mxox(b))/(amb);
- } else if (Math.abs(a)>Math.abs(b)) {
- return Math.exp((1/3d)*(-amb+b))*(expm1mxox(amb)-expm1mxox(-b))/a;
- } else {
- return Math.exp((1/3d)*(amb+a))*(expm1mxox(-amb)-expm1mxox(-a))/b;
- }
- }
-
- double t = ((a-b+a)*(b-a+b)*(a+b))*(-1/27d);
-
- double r2 = s; double r1 = t; double r0 = s*s;
- double d = 720;
- double c = r0/d;
- boolean r0sm = false, rnsm = false;
- for (int i=7; i<60; ++i) {
- double rn = t*r2 + s*r1;
- r2 = r1; r1 = r0; r0 = rn; d = d*i;
- rn = rn/d;
- c = c + rn;
- r0sm = rnsm; rnsm = Math.abs(rn)<DOUBLE_EPS;
- if (r0sm && rnsm) { break; }
- }
- return ((c + t/120) + s/24) + 1/2d;
-
- }
-
- public static final double log_plus(double a, double b) {
- if (a<b) return b+Math.log1p(Math.exp(a-b));
- else return a+Math.log1p(Math.exp(b-a));
- }
-
- public static final double round(double value, int decimalPlaces) {
- if (!Double.isInfinite(value) & !Double.isNaN(value)) {
- return new BigDecimal(value).setScale(decimalPlaces, RoundingMode.HALF_EVEN).doubleValue();
- } else {
- return value;
- }
- }
-
- public static double otherExtreme(double extreme, double average) {
- return average * 2 - extreme;
- }
-
-// public static double[][] clogCompetingEvents(double[] t, double[][] clog_p ) {
-//
-// }
-
- public static double interpolate(SimplePoint p1,
- SimplePoint p2, double x) {
- double slope = (p2.y - p1.y) / (p2.x - p1.x);
- return p1.y + slope * (x - p1.x);
- }
-
- public static double bound(double value, double lowest, double highest) {
- if (value < lowest || Double.isNaN(value)) {
- return lowest;
- } else if (value > highest) {
- return highest;
- } else {
- return value;
- }
- }
-
- public static double average(double... doubleArray) {
- double total = 0;
- for (double d : doubleArray) {
- total += d;
- }
- return total / doubleArray.length;
- }
-
- static double DOUBLE_SINH_T_EQUALS_T_THRESHOLD = Math.sqrt(3*DOUBLE_EPS);
- static double DOUBLE_NEG_HALF_LOG_EPSILON = -Math.log(DOUBLE_EPS)/2;
- public static double exponentialIntervalAverage (double k0, double k1) {
- double t = Math.abs((k0-k1)/2);
- if (t<DOUBLE_SINH_T_EQUALS_T_THRESHOLD) {
- return Math.exp((k0+k1)/2);
- } else if (t>=DOUBLE_NEG_HALF_LOG_EPSILON) {
- return Math.exp(Math.max(k0, k1))/(t*2);
- } else {
- return Math.exp((k0+k1)/2)*(Math.sinh(t)/t);
- }
- }
- public static double exponentialIntervalIntegral (double k0, double k1, double width) {
- return width*exponentialIntervalAverage(k0,k1);
- }
-
- static double LOG_DOUBLE_MAX = Math.log(Double.MAX_VALUE);
- static double DOUBLE_MIN_NORMAL = 2.2250738585072014E-308; // = MathUtil.DOUBLE_MIN_NORMAL;
- static double LOG_DOUBLE_MIN_NORMAL = Math.log(DOUBLE_MIN_NORMAL);
- static double LOG_TWO = Math.log(2.0d);
- public static double weightedClogMix(double w0, double w1, double clog_p0, double clog_p1) {
- // disaster zone
- double clog_p;
- if(false) {
- if (clog_p0 < clog_p1) {
- clog_p = -Math.log((w0+w1*Math.exp(clog_p0-clog_p1))/(w0+w1))+clog_p0;
- if ((clog_p-clog_p0)<LOG_TWO) {
- clog_p = -Math.log1p((w0+w1*Math.expm1(clog_p0-clog_p1))/(w0+w1))+clog_p0;
- clog_p -= 100;
- }
- } else {
- clog_p = -Math.log((w0*Math.exp(clog_p1-clog_p0)+w1)/(w0+w1))+clog_p1;
- if ((clog_p-clog_p1)<LOG_TWO) {
- clog_p = -Math.log1p((w0*Math.expm1(clog_p1-clog_p0)+w1)/(w0+w1))+clog_p1;
- clog_p -= 100;
- }
- clog_p -= 200;
- }
-
- clog_p = clog((w0*expc(clog_p0)+w1*expc(clog_p1))/(w0+w1));
- clog_p = -Math.log1p(-(w0*-Math.expm1(-clog_p0)+w1*-Math.expm1(-clog_p1))/(w0+w1));
- }
-
- clog_p = -Math.log1p((w0*Math.expm1(-clog_p0)+w1*Math.expm1(-clog_p1))/(w0+w1));
- //double w0_times_expm1_neg_clog_p0 = w0*Math.expm1(-clog_p0);
- //double w1_times_expm1_neg_clog_p1 = w1*Math.expm1(-clog_p1);
- // clog_p = -Math.log1p((w0_times_expm1_neg_clog_p0+w1_times_expm1_neg_clog_p1)/(w0+w1));
- if (clog_p < LOG_TWO) {
- return clog_p;
- } else if (w0 == 0 && w1 != 0) {
- return clog_p1;
- } else if (w0 != 0 && w1 == 0) {
- return clog_p0;
- }
- double w0_times_exp_neg_clog_p0 = w0*Math.exp(-clog_p0);
- double w1_times_exp_neg_clog_p1 = w1*Math.exp(-clog_p1);
- double clog_p_by_log_exp = -Math.log((w0*Math.exp(-clog_p0)+w1*Math.exp(-clog_p1))/(w0+w1));
- if (w0_times_exp_neg_clog_p0 >= MathUtil.DOUBLE_MIN_NORMAL && w1_times_exp_neg_clog_p1 >= MathUtil.DOUBLE_MIN_NORMAL && clog_p_by_log_exp > Double.NEGATIVE_INFINITY && clog_p_by_log_exp < Double.POSITIVE_INFINITY) {
- return clog_p_by_log_exp;
- } else if /*(w1/w0 == 0 || w0/w1 == 0)*/ (true) {
- double l_w0 = Math.log(w0);
- double l_w1 = Math.log(w1);
-
- double m0 = -clog_p0 + l_w0;
- double m1 = -clog_p1 + l_w1;
-
- return log_plus(l_w0,l_w1)-log_plus(m0,m1);
-
- } else
-
- /* if (
- (clog_p0-clog_p1) < LOG_DOUBLE_MAX
- &&(clog_p0-clog_p1) > LOG_DOUBLE_MINNORMAL
- &&(clog_p0-clog_p1-Math.log(w0/w1)) < LOG_DOUBLE_MAX
- &&(clog_p0-clog_p1-Math.log(w0/w1)) > 0
- ) {
- } else */ {
-
- if (true) {
- //double discrim = clog_p0 + Math.log(Math.abs(w0)) - clog_p1 - Math.log(Math.abs(w1));
- //double discrim = -clog_p0 + Math.log(Math.abs(w0)) + clog_p1 - Math.log(Math.abs(w1));
- double discrim = Math.abs(clog_p0) + Math.abs(clog_p0-clog_p1-Math.log1p(Math.abs(w0/w1)))
- - Math.abs(clog_p1) - Math.abs(clog_p1-clog_p0-Math.log1p(Math.abs(w0/w1)));
- double center0_err =
- Math.abs(clog_p0)
- + Math.abs(1/(1+(Math.expm1(clog_p0-clog_p1))/(w0/w1+1)))
- * ( Math.abs(1/(w0/w1+1)) *
- ( Math.abs(clog_p0-clog_p1)
- + Math.abs(clog_p0)
- + Math.abs(clog_p1) )
- + Math.abs(Math.expm1(clog_p0-clog_p1)/(w0/w1+1)/(w0/w1+1) ) *
- ( Math.abs(1) ) );
- if (discrim < 0) {
- clog_p = clog_p0-Math.log1p((Math.expm1(clog_p0-clog_p1))/(w0/w1+1));
- //clog_p = clog_p0-Math.log1p((w1*Math.expm1(clog_p0-clog_p1))/(w0+w1));
- } else {
- clog_p = clog_p1-Math.log1p((Math.expm1(clog_p1-clog_p0))/(1+w1/w0));
- //clog_p = clog_p1-Math.log1p((w0*Math.expm1(clog_p1-clog_p0))/(w0+w1));
- }
- }
- }
-
- return clog_p;
- }
- public static double[] weightedClogMix(double w0, double w1, double[] clog_p0, double[] clog_p1) {
- double[] clog_p = new double[clog_p1.length];
- for (int i=0; i<clog_p.length; ++i)
- clog_p[i] = weightedClogMix(w0, w1, clog_p0[i], clog_p1[i]);
- return clog_p;
- }
-
- static double LOG_THREE = Math.log(3d);
- public static double weightedLogitMix(double w0, double w1, double logit_p0, double logit_p1) {
- double w = w0+w1;
- if ( !(w<0) && !(w>0) ) { return 0; }
- if (logit_p0 <= -LOG_THREE && logit_p1 <= -LOG_THREE) {
- return weightedLogitMixII(w0, w1, logit_p0, logit_p1);
- } else if (logit_p0 >= LOG_THREE && logit_p1 >= LOG_THREE) {
- return -weightedLogitMixII(w0, w1, -logit_p0, -logit_p1);
- }
- double p0z, p1z;
- if (logit_p0 >= 0) {
- p0z = -Math.expm1(-logit_p0)/(1+Math.exp(-logit_p0));
- } else {
- p0z = Math.expm1(logit_p0)/(1+Math.exp(logit_p0));
- }
- if (logit_p1 >= 0) {
- p1z = -Math.expm1(-logit_p1)/(1+Math.exp(-logit_p1));
- } else {
- p1z = Math.expm1(logit_p1)/(1+Math.exp(logit_p1));
- }
- double pz = (w0*p0z+w1*p1z)/w;
- if (Math.abs(pz)<=0.5) {
- return Math.log1p(pz)-Math.log1p(-pz);
- }
- if (pz<0) {
- return weightedLogitMixII(w0, w1, logit_p0, logit_p1);
- } else {
- return -weightedLogitMixII(w0, w1, -logit_p0, -logit_p1);
- }
- }
- static double weightedLogitMixII(double w0, double w1, double logit_p0, double logit_p1) {
- double lp;
- double lp0 = logit_p0-Math.log1p(Math.exp(logit_p0));
- double lp1 = logit_p1-Math.log1p(Math.exp(logit_p1));
- if (Math.abs(w0)<=Math.abs(w1)) {
- if (lp0 <= lp1) {
- lp = lp1 + Math.log1p((Math.expm1(lp0-lp1)*w0/w1)/(1+w0/w1));
- } else {
- lp = lp0 + Math.log1p(Math.expm1(lp1-lp0)/(1+w0/w1));
- }
- } else {
- if (lp0 <= lp1) {
- lp = lp1 + Math.log1p(Math.expm1(lp0-lp1)/(1+w1/w0));
- } else {
- lp = lp0 + Math.log1p((Math.expm1(lp1-lp0)*w1/w0)/(1+w1/w0));
- }
- }
- return lp-Math.log(-Math.expm1(lp));
- /*
- if (logit_p0 >= 0 && logit_p1 >= 0) {
- double t0 = (Math.exp(logit_p1)+1)*w0;
- double t1 = (Math.exp(logit_p0)+1)*w1;
- o = Math.log1p((t0*Math.expm1(logit_p0)+t1*Math.expm1(logit_p1))/(t0+t1));
- if (o > LOG_THREE) {
- o = -Math.log((t0*Math.exp(-logit_p0)+t1*Math.exp(-logit_p1))/(t0+t1));
- }
- return o;
- } else if (logit_p0 < 0 && logit_p1 < 0) {
- double t0 = (Math.exp(-logit_p1)+1)*w0;
- double t1 = (Math.exp(-logit_p0)+1)*w1;
- o = -Math.log1p((t0*Math.expm1(-logit_p0)+t1*Math.expm1(-logit_p1))/(t0+t1));
- if (o < -LOG_THREE) {
- o = Math.log((t0*Math.exp(logit_p0)+t1*Math.exp(logit_p1))/(t0+t1));
- }
- }
- double t0 = (Math.exp(logit_p1)+1)*w0;
- double t1 = (Math.exp(logit_p0)+1)*w1;
- return Math.log((t0*Math.exp(logit_p0)+t1*Math.exp(logit_p1))/(t0+t1));
- */
- }
-
-
- public static double clogIntervalAverage(double clog_p0, double clog_p1) {
- double d = Math.abs(clog_p0-clog_p1);
- double b = Math.min(clog_p0,clog_p1);
- if (d > 0.25) {
- return b-Math.log(-Math.expm1(-d)/d);
- } else {
- double dd = d*d;
- return (clog_p0+clog_p1)/2+(-1/24d)*dd*(1+(-1/120d)*dd*(1+(-1/63d)*dd*(1+(-3/160d)*dd*(1+(-2/99d)*dd))));
- }
- }
-
- /**
- *
- * @param t0 (assume cumulative probability of event is 0 at t0)
- * @param t1
- * @param mlr0 mean log hazard rate at t0
- * @param mlr1 mean log hazard rate at t1
- * @param sdlr0 standard deviation log hazard rate at t0
- * @param sdlr1 standard deviation log hazard rate at t1 (can have opposite sign to sdlr0)
- * @param t
- * @return array of complementary log probabilities of event by times t
- */
- public static double[] clogMarginalOfExponentiallyVaryingHazardModel (
- double t0, double t1,
- double mlr0, double mlr1,
- double sdlr0, double sdlr1,
- double[] t) {
- double[] clog_p = new double[t.length];
- for (int i=0; i<t.length; ++i) {
- double mlr_i = linterp(t0, t1, mlr0, mlr1, t[i]);
- double sdlr_i = linterp(t0, t1, sdlr0, sdlr1, t[i]);
- double clog_p_i = 0;
- double wt = 0;
- int j = -100;
- double z_l;
- double z_r = j/10d;
- double clog_d_l;
- double clog_d_r = exponentialIntervalIntegral(mlr0+z_r*sdlr0, mlr_i+z_r*sdlr_i, t[i]-t0);
- for (++j; j<100; ++j) {
- z_l = z_r;
- z_r = j/10d;
- clog_d_l = clog_d_r;
- clog_d_r = exponentialIntervalIntegral(mlr0+z_r*sdlr0, mlr_i+z_r*sdlr_i, t[i]-t0);
- double wt_z = exponentialIntervalIntegral(-z_l*z_l/2, -z_r*z_r/2, 1/10d);
- clog_p_i = weightedClogMix(wt, wt_z, clog_p_i, clogIntervalAverage(clog_d_l,clog_d_r));
- wt += wt_z;
- }
- clog_p[i] = Math.max(clog_p_i, 0);
- }
- return clog_p;
- }
-
- /**
- * a one-dimensional family of 5-dimensional weighted integrals of a 5-dimensional step function...
- * @param m
- * @param scienceEvents
- * @param rescheduledYears
- * @param iters
- * @return rescheduled_science_events
- */
- public static EventDiscreteDistributionSchedule clogMarginalScienceSpeedEventRescheduling(
- final ScienceSpeedModelParameters m,
- final EventDiscreteDistributionSchedule scienceEvents,
- final double[] rescheduledYears,
- int iters
- ) {
- int n = rescheduledYears.length;
- int e = scienceEvents.logitSubevents.length;
- EventDiscreteDistributionSchedule retVal = new EventDiscreteDistributionSchedule();
- retVal.time = rescheduledYears;
- retVal.clogProbEvent = new double[n];
- retVal.logitSubevents = new double[e][];
-
- // Monte Carlo
- double sequencedata_year_Z=0, sequencedata_factor_Z=0, population_year_Z=0, population_rate_Z=0, institutional_factor_Z=0;
- double dt0_seq, m_seq, b_seq;
- double dt0_pop, m_pop, b_pop;
- double m_inst;
- double dt, science_years=0;
- EventDiscreteDistribution ej;
- int i, j, k;
- double tn;
- for (i=0; i<iters; ++i) {
- if (i%2==0) {
- sequencedata_year_Z = RANDOM.nextGaussian();
- sequencedata_factor_Z = RANDOM.nextGaussian();
- population_year_Z = RANDOM.nextGaussian();
- population_rate_Z = RANDOM.nextGaussian();
- institutional_factor_Z = RANDOM.nextGaussian();
- } else {
- sequencedata_year_Z = -sequencedata_year_Z;
- sequencedata_factor_Z = -sequencedata_factor_Z;
- population_year_Z = -population_year_Z;
- population_rate_Z = -population_rate_Z;
- institutional_factor_Z = -institutional_factor_Z;
- }
- //sequencedata_year_Z = MathUtil.inverseCumulativeProbability(0, 1, (i+0.5d)/iters);
- dt0_seq = m.sequencedata_base_year + Math.exp(m.sequencedata_mean_log_year + sequencedata_year_Z * m.sequencedata_stddev_log_year) - m.institutional_base_year;
- m_seq = m.sequencedata_mean_slope_log_factor + sequencedata_factor_Z * m.sequencedata_stddev_slope_log_factor;
- b_seq = m.sequencedata_mean_init_log_factor + sequencedata_factor_Z * m.sequencedata_stddev_init_log_factor;
- dt0_pop = m.population_base_year + Math.exp(m.population_mean_log_year + population_year_Z * m.population_stddev_log_year) - m.institutional_base_year;
- m_pop = m.population_mean_slope_log_rate + population_rate_Z * m.population_stddev_slope_log_rate;
- b_pop = m.population_mean_init_log_rate + population_rate_Z * m.population_stddev_init_log_rate;
- m_inst = m.institutional_mean_slope_log_factor + institutional_factor_Z * m.institutional_stddev_slope_log_factor;
- for (j=0; j<n; ++j) {
- dt = rescheduledYears[j] - m.institutional_base_year;
- science_years = exprel( m_inst * dt ) * dt;
- if (dt>dt0_pop)
- science_years += (dt-dt0_pop)*(dt-dt0_pop) * Math.exp( m_inst*((1*dt0_pop+2*dt)/3/* - 0 */) + m_seq*((2*dt0_pop+1*dt)/3-dt0_seq)+b_seq + m_pop*((2*dt0_pop+1*dt)/3-dt0_pop)+b_pop ) * rpn_b_expm1_a_t_a_expm1_b_t_m_a_b_p_3_d_exp_d_a_d_b_d_a_b_m_d( -m_inst*(dt-dt0_pop), (m_pop+m_seq)*(dt-dt0_pop) );
- //science_years += (dt-dt0_pop)*(dt-dt0_pop) * Math.exp( m_inst*((1*dt0_pop+2*dt)/3/* - 0 */) + m_seq*((2*dt0_pop+1*dt)/3-dt0_seq)+b_seq + m_pop*((2*dt0_pop+1*dt)/3-dt0_pop)+b_pop ) * -threecancel( -(m_inst)*(t-t0_pop), (m_pop+m_seq)*(t-t0_pop) );
- //science_years += (dt-dt0_pop)*(dt-dt0_pop) * Math.exp( m_inst*((1*dt0_pop+2*dt)/3/* - 0 */) + (m_seq+m_pop)*((1*dt0_pop+2*dt)/3-dt0_seq)+b_seq+b_pop ) * rpn_b_expm1_a_t_a_expm1_b_t_m_a_b_p_3_d_exp_d_a_d_b_d_a_b_m_d( -(m_seq+m_inst)*(dt-dt0_pop), m_pop*(dt-dt0_pop) ) ;
- //science_years = org.singinst.uf.math.MathUtilTest.projectScienceYearsAnalytic(org.singinst.uf.math.MathUtilTest.applyScienceSpeedZValues(m, new ScienceSpeedZValues()), new double[] {dt})[0];
- ej = scienceEvents.logitnerp(science_years + m.institutional_base_year);
- ej = EventDiscreteDistribution.weightedMix(i/(i+1d), 1/(i+1d), retVal.get(j), ej);
- retVal.set(j, ej);
- }
- //org.singinst.uf.common.LogUtil.info(String.format("random %g leads to progress %g with dt0_seq=%+8.5f, m_seq=%+8.5f, b_seq=%+8.5f, dt0_pop=%+8.5f, m_pop=%+8.5f, b_pop=%+8.5f, m_inst=%+8.5f", dt0_pop, science_years, dt0_seq, m_seq, b_seq, dt0_pop, m_pop, b_pop, m_inst));
- }
-
- return retVal;
- }
-
- public static final Random RANDOM = new Random(1); /* not thread-safe? */
- public static final double NINETY_FIVE_PERCENTILE = 1.64485362695147;
-
- static public class ScienceSpeedModelParameters extends Object implements Cloneable {
- public double
- sequencedata_base_year,
- sequencedata_mean_log_year,
- sequencedata_stddev_log_year,
- sequencedata_mean_init_log_factor,
- sequencedata_stddev_init_log_factor,
- sequencedata_mean_slope_log_factor,
- sequencedata_stddev_slope_log_factor,
- population_base_year,
- population_mean_log_year,
- population_stddev_log_year,
- population_mean_init_log_rate,
- population_stddev_init_log_rate,
- population_mean_slope_log_rate,
- population_stddev_slope_log_rate,
- institutional_base_year,
- institutional_mean_slope_log_factor,
- institutional_stddev_slope_log_factor;
- public ScienceSpeedModelParameters clone() {
- try { return (ScienceSpeedModelParameters)(super.clone()); }
- catch (CloneNotSupportedException e) { throw new InternalError(e.getMessage()); }
- }
- }
-
- static public class EventDiscreteDistributionSchedule {
- public double[] time;
- public double[] clogProbEvent;
- public double[][] logitSubevents;
- public EventDiscreteDistribution get(int j) {
- EventDiscreteDistribution o = new EventDiscreteDistribution();
- o.clogProbEvent = clogProbEvent[j];
- o.logitSubevents = new double[logitSubevents.length];
- for (int i=0; i<logitSubevents.length; ++i) {
- o.logitSubevents[j] = logitSubevents[i][j];
- }
- return o;
- }
- public void set(int j, EventDiscreteDistribution e) {
- clogProbEvent[j] = e.clogProbEvent;
- for (int i=0; i<logitSubevents.length; ++i) {
- logitSubevents[i][j] = e.logitSubevents[j];
- }
- }
- public EventDiscreteDistribution logitnerp(double t) {
- EventDiscreteDistribution o = new EventDiscreteDistribution();
- o.clogProbEvent = MathUtil.linterp(time, clogProbEvent, t);
- o.logitSubevents = new double[logitSubevents.length];
- for (int i=0; i<logitSubevents.length; ++i) {
- o.logitSubevents[i] = MathUtil.linterp(time, logitSubevents[i], t);
- }
- return o;
- }
- public EventDiscreteDistributionSchedule logitnerp(double[] t) {
- EventDiscreteDistributionSchedule o = new EventDiscreteDistributionSchedule();
- o.clogProbEvent = MathUtil.linterp(time, clogProbEvent, t);
- o.logitSubevents = new double[logitSubevents.length][];
- for (int i=0; i<logitSubevents.length; ++i) {
- o.logitSubevents[i] = MathUtil.linterp(time, logitSubevents[i], t);
- }
- return o;
- }
- static public EventDiscreteDistributionSchedule weightedMix(double w0, double w1, EventDiscreteDistributionSchedule s0, EventDiscreteDistributionSchedule s1) {
- EventDiscreteDistributionSchedule o = new EventDiscreteDistributionSchedule();
- int j,i,m,n;
- n = s0.clogProbEvent.length;
- m = s0.logitSubevents.length;
- o.clogProbEvent = new double[n];
- o.logitSubevents = new double[m][];
- for (j=0; j<m; ++j)
- o.logitSubevents[j] = new double[n];
- for (i=0; i<n; ++i)
- o.set(i, EventDiscreteDistribution.weightedMix(w0,w1,s0.get(i),s1.get(i)) );
-
- return o;
- }
- }
-
- static public class ScienceSpeedScenario {
- public double
- sequencedata_year,
- sequencedata_init_log_factor,
- sequencedata_slope_log_factor,
- population_year,
- population_init_log_rate,
- population_slope_log_rate,
- institutional_base_year,
- institutional_slope_log_factor;
- }
-
- static public class ScienceSpeedScenarioReduced {
- public double
- institutional_slope_log_factor,
- sciencetalent_rel_year,
- sciencetalent_init_log_rate,
- sciencetalent_slope_log_rate;
- }
-
- static public class ScienceSpeedZValues {
- public double
- sequencedata_year_Z,
- sequencedata_factor_Z,
- population_year_Z,
- population_rate_Z,
- institutional_rate_Z;
- }
-
- static public class EventDiscreteDistribution {
- public double clogProbEvent;
- public double[] logitSubevents;
- public static EventDiscreteDistribution weightedMix(double w0, double w1, EventDiscreteDistribution e0, EventDiscreteDistribution e1) {
- EventDiscreteDistribution o = new EventDiscreteDistribution();
- o.clogProbEvent = MathUtil.weightedClogMix(w0, w1, e0.clogProbEvent, e1.clogProbEvent);
- o.logitSubevents = new double[e0.logitSubevents.length];
- double lw0, lw1;
- lw0 = Math.log(w0) + Math.log1p(-Math.exp(-e0.clogProbEvent));
- lw1 = Math.log(w1) + Math.log1p(-Math.exp(-e1.clogProbEvent));
- for (int i=0; i<e0.logitSubevents.length; ++i) {
- if (lw0>lw1) {
- lw1 = lw1 - lw0; lw0 = 0;
- } else {
- lw0 = lw0 - lw1; lw1 = 0;
- }
- o.logitSubevents[i] = MathUtil.weightedLogitMix(Math.exp(lw0), Math.exp(lw1), e0.logitSubevents[i], e1.logitSubevents[i]);
- lw0 = lw0 + MathUtil.log_logistic(-e0.logitSubevents[i]);
- lw1 = lw1 + MathUtil.log_logistic(-e1.logitSubevents[i]);
- }
- return o;
- }
- }
-
-
-}
-
diff --git a/java/src/org/singinst/uf/math/MathUtilTest.java b/java/src/org/singinst/uf/math/MathUtilTest.java deleted file mode 100644 index d5e4f79..0000000 --- a/java/src/org/singinst/uf/math/MathUtilTest.java +++ /dev/null @@ -1,596 +0,0 @@ -package org.singinst.uf.math; - -import junit.framework.TestCase; -import junit.framework.Assert; - -import org.singinst.uf.math.MathUtil; -//import org.singinst.uf.math.ScienceSpeedModelParameters; -//import org.singinst.uf.math.ScienceSpeedZValues; -//import org.singinst.uf.math.ScienceSpeedScenario; -//import org.singinst.uf.math.ScienceSpeedScenarioReduced; -//import org.singinst.uf.math.EventDiscreteDistribution; -//import org.singinst.uf.math.EventDiscreteDistributionSchedule; -import org.singinst.uf.common.LogUtil; -import org.apache.commons.math.analysis.UnivariateRealFunction; -import org.apache.commons.math.analysis.RombergIntegrator; - -public class MathUtilTest extends TestCase { - - static MathUtil.EventDiscreteDistributionSchedule heavisideSchedule(double t) { - MathUtil.EventDiscreteDistributionSchedule o = new MathUtil.EventDiscreteDistributionSchedule(); - double[] o_dot_time = {0, t*(1-MathUtil.DOUBLE_EPS), t, 1e100}; - o.time = o_dot_time; - double[] o_dot_clogProbEvent = {0,0,10,10}; - o.clogProbEvent = o_dot_clogProbEvent; - o.logitSubevents = new double[0][]; - return o; - } - - static MathUtil.ScienceSpeedModelParameters nullScienceModel() { - MathUtil.ScienceSpeedModelParameters o = new MathUtil.ScienceSpeedModelParameters(); - o.sequencedata_base_year = 0; - o.sequencedata_mean_log_year = 0; - o.sequencedata_stddev_log_year = 0; - o.sequencedata_mean_init_log_factor = 0; - o.sequencedata_stddev_init_log_factor = 0; - o.sequencedata_mean_slope_log_factor = 0; - o.sequencedata_stddev_slope_log_factor = 0; - o.population_base_year = 0; - o.population_mean_log_year = 0; - o.population_stddev_log_year = 0; - o.population_mean_init_log_rate = 0; - o.population_stddev_init_log_rate = 0; - o.population_mean_slope_log_rate = 0; - o.population_stddev_slope_log_rate = 0; - o.institutional_base_year = 0; - o.institutional_mean_slope_log_factor = 0; - o.institutional_stddev_slope_log_factor = 0; - return o; - } - - static MathUtil.ScienceSpeedZValues nullScienceSpeedZValues () { - MathUtil.ScienceSpeedZValues o = new MathUtil.ScienceSpeedZValues(); - return o; - } - - static MathUtil.ScienceSpeedModelParameters pointMassScienceSpeedModel(MathUtil.ScienceSpeedModelParameters m, MathUtil.ScienceSpeedScenario s) { - MathUtil.ScienceSpeedModelParameters o = nullScienceModel(); - o.institutional_mean_slope_log_factor = s.institutional_slope_log_factor; - if (s.population_year > m.population_base_year) { - o.population_mean_log_year = Math.log(s.population_year - m.population_base_year); - o.population_base_year = m.population_base_year; - } else { - o.population_mean_log_year = Double.NEGATIVE_INFINITY; - o.population_base_year = s.population_year; - } - o.population_mean_init_log_rate = s.population_init_log_rate; - o.population_mean_slope_log_rate = s.population_slope_log_rate; - if (s.sequencedata_year > m.sequencedata_base_year) { - o.sequencedata_mean_log_year = Math.log(s.sequencedata_year - m.sequencedata_base_year); - o.sequencedata_base_year = m.sequencedata_base_year; - } else { - o.sequencedata_mean_log_year = Double.NEGATIVE_INFINITY; - o.sequencedata_base_year = s.sequencedata_year; - } - o.sequencedata_mean_init_log_factor = s.sequencedata_init_log_factor; - o.sequencedata_mean_slope_log_factor = s.sequencedata_slope_log_factor; - return o; - } - - static MathUtil.ScienceSpeedScenario applyScienceSpeedZValues (MathUtil.ScienceSpeedModelParameters m, MathUtil.ScienceSpeedZValues z) { - MathUtil.ScienceSpeedScenario o = new MathUtil.ScienceSpeedScenario(); - o.institutional_slope_log_factor = - m.institutional_mean_slope_log_factor - + z.institutional_rate_Z*m.institutional_stddev_slope_log_factor; - o.population_year = - m.population_base_year - + Math.exp( - m.population_mean_log_year - + z.population_year_Z*m.population_stddev_log_year); - o.sequencedata_year = - m.sequencedata_base_year - + Math.exp( - m.sequencedata_mean_log_year - + z.sequencedata_year_Z*m.sequencedata_stddev_log_year); - o.population_init_log_rate = - m.population_mean_init_log_rate - + z.population_rate_Z*m.population_stddev_init_log_rate; - o.population_slope_log_rate = - m.population_mean_slope_log_rate - + z.population_rate_Z*m.population_stddev_slope_log_rate; - o.sequencedata_init_log_factor = - + m.sequencedata_mean_init_log_factor - + z.sequencedata_factor_Z*m.sequencedata_stddev_init_log_factor; - o.sequencedata_slope_log_factor = - + m.sequencedata_mean_slope_log_factor - + z.sequencedata_factor_Z*m.sequencedata_stddev_slope_log_factor; - return o; - } - - static MathUtil.ScienceSpeedScenarioReduced applyScienceSpeedZValuesReduce (MathUtil.ScienceSpeedModelParameters m, MathUtil.ScienceSpeedZValues z) { - MathUtil.ScienceSpeedScenarioReduced o = new MathUtil.ScienceSpeedScenarioReduced(); - o.institutional_slope_log_factor = - m.institutional_mean_slope_log_factor - + z.institutional_rate_Z*m.institutional_stddev_slope_log_factor; - o.sciencetalent_rel_year = - m.population_base_year - + Math.exp( - m.population_mean_log_year - + z.population_year_Z*m.population_stddev_log_year) - - m.institutional_base_year; - double sequencedata_rel_year = - m.sequencedata_base_year - + Math.exp( - m.sequencedata_mean_log_year - + z.sequencedata_year_Z*m.sequencedata_stddev_log_year) - - m.institutional_base_year; - o.sciencetalent_init_log_rate = - m.population_mean_init_log_rate - + z.population_rate_Z*m.population_stddev_init_log_rate - + m.sequencedata_mean_init_log_factor - + (o.sciencetalent_rel_year - sequencedata_rel_year) - * (m.sequencedata_mean_slope_log_factor) - + z.sequencedata_factor_Z * ( - m.sequencedata_stddev_init_log_factor - + (o.sciencetalent_rel_year - sequencedata_rel_year) - * (m.sequencedata_stddev_slope_log_factor) - ); - o.sciencetalent_slope_log_rate = - m.population_mean_slope_log_rate - + z.population_rate_Z*m.population_stddev_slope_log_rate - + m.sequencedata_mean_slope_log_factor - + z.sequencedata_factor_Z*m.sequencedata_stddev_slope_log_factor; - return o; - } - - static void logDoubleList(double[] l) { - StringBuilder b = new StringBuilder(); - for (int i=0; i<l.length; ++i) { - b.append(String.format("%20.16g ", l[i])); - } - org.singinst.uf.common.LogUtil.info(b.toString()); - } - - static void logDoubleList(String s, double[] l) { - StringBuilder b = new StringBuilder(s); - for (int i=0; i<l.length; ++i) { - b.append(String.format("%20.16g ", l[i])); - } - org.singinst.uf.common.LogUtil.info(b.toString()); - } - - static double[] projectScienceYearsNumerical(MathUtil.ScienceSpeedScenario s, double[] t) throws org.apache.commons.math.FunctionEvaluationException,org.apache.commons.math.ConvergenceException { - double[] o = new double[t.length]; - final double t0_seq, m_seq, b_seq; - final double t0_pop, m_pop, b_pop; - final double t0_inst, m_inst; - - t0_seq = s.sequencedata_year; - m_seq = s.sequencedata_slope_log_factor; - b_seq = s.sequencedata_init_log_factor; - t0_pop = s.population_year; - m_pop = s.population_slope_log_rate; - b_pop = s.population_init_log_rate; - t0_inst = s.institutional_base_year; - m_inst = s.institutional_slope_log_factor; - - UnivariateRealFunction science_rate_after_pop = new UnivariateRealFunction() { - public double value(double t) { - return (t-t0_pop)*MathUtil.exprel((m_seq+m_pop)*(t-t0_pop))*Math.exp(m_inst*(t-t0_inst)+b_pop+m_seq*(t0_pop-t0_seq)+b_seq); - //return (t-t0_pop)*MathUtil.exprel(m_pop*(t-t0_pop))*Math.exp(b_pop+m_inst*(t-t0_inst)+b_seq+m_seq*(t-t0_seq)); - } - }; - double baseyear = s.institutional_base_year; - double prevyear = t0_pop; double science_from_pop = 0; - double year; double science; - org.apache.commons.math.analysis.UnivariateRealIntegrator science_from_pop_integrator = new RombergIntegrator(science_rate_after_pop); - science_from_pop_integrator.setRelativeAccuracy(32*MathUtil.DOUBLE_EPS); - for (int i=0; i<t.length; ++i) { - year = t[i]; - science = (year-baseyear)*MathUtil.exprel(m_inst*(year-baseyear)); - if (year >= t0_pop) { - if (year > prevyear) { - science_from_pop = science_from_pop + science_from_pop_integrator.integrate(prevyear, year); - prevyear = year; - } else if (year < prevyear) { - science_from_pop = science_from_pop - science_from_pop_integrator.integrate(year, prevyear); - prevyear = year; - } - science = science + science_from_pop; - } - o[i] = science + baseyear; - } - return o; - } - - static double[] projectScienceYearsAnalytic(MathUtil.ScienceSpeedScenario s, double[] rescheduled_years) { - double[] o = new double[rescheduled_years.length]; - double dt0_seq, m_seq, b_seq; - double dt0_pop, m_pop, b_pop; - double t0_inst, m_inst; - - double dt, science_years; - - t0_inst = s.institutional_base_year; - m_inst = s.institutional_slope_log_factor; - dt0_seq = s.sequencedata_year - t0_inst; - m_seq = s.sequencedata_slope_log_factor; - b_seq = s.sequencedata_init_log_factor; - dt0_pop = s.population_year - t0_inst; - m_pop = s.population_slope_log_rate; - b_pop = s.population_init_log_rate; - - for (int j=0; j<rescheduled_years.length; ++j) { - dt = rescheduled_years[j] - t0_inst; - science_years = MathUtil.exprel( m_inst * dt ) * dt; - if (dt > dt0_pop) - science_years += (dt-dt0_pop)*(dt-dt0_pop) * Math.exp( m_inst*((1*dt0_pop+2*dt)/3/* - 0 */) + m_seq*((2*dt0_pop+1*dt)/3-dt0_seq)+b_seq + m_pop*((2*dt0_pop+1*dt)/3-dt0_pop)+b_pop ) * MathUtil.rpn_b_expm1_a_t_a_expm1_b_t_m_a_b_p_3_d_exp_d_a_d_b_d_a_b_m_d( -m_inst*(dt-dt0_pop), (m_pop+m_seq)*(dt-dt0_pop) ) ; - o[j] = science_years + t0_inst; - } - return o; - } - - static double[] projectScienceYearsAnalytic(MathUtil.ScienceSpeedScenarioReduced s, double[] reschedule_rel_years, double base_year) { - double[] o = new double[reschedule_rel_years.length]; - double dt0_tal, m_tal, b_tal; - double m_inst; - - double dt, science_years; - - m_inst = s.institutional_slope_log_factor; - dt0_tal = s.sciencetalent_rel_year; - m_tal = s.sciencetalent_slope_log_rate; - b_tal = s.sciencetalent_init_log_rate; - - for (int j=0; j<reschedule_rel_years.length; ++j) { - dt = reschedule_rel_years[j] - base_year; - science_years = MathUtil.exprel( m_inst * dt ) * dt; - if (dt > dt0_tal) - science_years += (dt-dt0_tal)*(dt-dt0_tal) * Math.exp( m_inst*((1*dt0_tal+2*dt)/3/* - 0 */) + m_tal*((2*dt0_tal+1*dt)/3-dt0_tal)+b_tal ) * MathUtil.rpn_b_expm1_a_t_a_expm1_b_t_m_a_b_p_3_d_exp_d_a_d_b_d_a_b_m_d( -m_inst*(dt-dt0_tal), m_tal*(dt-dt0_tal) ) ; - o[j] = science_years + base_year; - } - return o; - } - - static public void testShowMeWhatClogIntervalLooksLike() throws Exception { - double d = MathUtil.clogIntervalAverage(0, 4); - org.singinst.uf.common.LogUtil.info(new Double(d).toString()); - } - - void notclearonthis() throws Exception { - for (int i=0; i<2; ++i) { - final double d = MathUtil.RANDOM.nextDouble(); - UnivariateRealFunction f = new UnivariateRealFunction() { - public double value(double x) { - return d*x; - } - }; - RombergIntegrator ri = new RombergIntegrator(f); - - org.singinst.uf.common.LogUtil.info(String.format("%g %g", d/2, ri.integrate(0, 1))); - } - } - - public void testMeh() throws Exception { - { - - notclearonthis(); - notclearonthis(); - - MathUtil.EventDiscreteDistributionSchedule s = new MathUtil.EventDiscreteDistributionSchedule(); - double[] s_dot_time = {0, 1, 2, 3, 4, 4.1, 4.2, 4.3, 4.4}; - double[] t = {-0.5,0,0.5,1,1.5,2,2.5,3,3.5,4,4.05,4.1,4.15,4.2,4.25,4.3,4.35,4.4,4.45}; - - s.time = s_dot_time; - double[] s_dot_clogProbEvent = {0,1,2,3,4,5,6,7,8}; - s.clogProbEvent = s_dot_clogProbEvent; - s.logitSubevents = new double[0][]; - MathUtil.EventDiscreteDistributionSchedule r = s.logitnerp(t); - StringBuilder b = new StringBuilder(); - for (int i=0; i<r.clogProbEvent.length; ++i) { - b.append(r.clogProbEvent[i]).append(" "); - } - org.singinst.uf.common.LogUtil.info(b.toString()); - } - - { - MathUtil.EventDiscreteDistributionSchedule s = heavisideSchedule(1); - double[] t = {0,0.5,1,1.5,2}; - MathUtil.EventDiscreteDistributionSchedule r = s.logitnerp(t); - logDoubleList(r.clogProbEvent); - } - } - - static double LOG_DOUBLE_EPS = Math.log(MathUtil.DOUBLE_EPS); - static double square_clogged(double clog_p) { - if (clog_p >= -LOG_DOUBLE_EPS) return clog_p - MathUtil.LOG_TWO; - if (clog_p < LOG_DOUBLE_EPS) return 2*clog_p; - return -Math.log(Math.exp(-clog_p)*(2-Math.exp(-clog_p))); - } - static double[] square_clogged(double[] clog_p) { - double[] o = new double[clog_p.length]; - for (int i=0; i<clog_p.length; ++i) { - if (clog_p[i] >= -LOG_DOUBLE_EPS) o[i] = clog_p[i] - MathUtil.LOG_TWO; - if (clog_p[i] < LOG_DOUBLE_EPS) o[i] = 2*clog_p[i]; - o[i] = -Math.log(Math.exp(-clog_p[i])*(2-Math.exp(-clog_p[i]))); - } - return o; - } - - static double PHI = 0.618033988749894848d; - static double COS_TWO_THIRDS_PI_PHI = 0.272883452047768708d; - static double SIN_TWO_THIRDS_PI_PHI = 0.962047099469923622d; - - interface ScenarioSource { MathUtil.ScienceSpeedScenarioReduced scenario(int i); }; - - public void testWhatever() throws Exception { - int iters = 1000; - MathUtil.ScienceSpeedModelParameters m = nullScienceModel(); - MathUtil.ScienceSpeedScenario sss = new MathUtil.ScienceSpeedScenario(); - MathUtil.ScienceSpeedScenarioReduced sssr = new MathUtil.ScienceSpeedScenarioReduced(); - MathUtil.ScienceSpeedZValues z = new MathUtil.ScienceSpeedZValues(); - - sss.institutional_base_year = -MathUtil.RANDOM.nextDouble(); - //sss.institutional_base_year = -0.5; - sss.institutional_slope_log_factor = MathUtil.RANDOM.nextGaussian(); - //sss.institutional_slope_log_factor = Math.log(1.0001)*10; - sss.sequencedata_init_log_factor = MathUtil.RANDOM.nextGaussian(); - sss.sequencedata_slope_log_factor = MathUtil.RANDOM.nextGaussian(); - //sss.sequencedata_slope_log_factor = Math.log(1000); - sss.sequencedata_year = MathUtil.RANDOM.nextDouble(); - sss.population_init_log_rate = MathUtil.RANDOM.nextGaussian(); - // //sss.population_init_log_rate = Math.log(10000); - sss.population_slope_log_rate = MathUtil.RANDOM.nextGaussian(); - sss.population_year = MathUtil.RANDOM.nextDouble(); - - MathUtil.EventDiscreteDistributionSchedule s = heavisideSchedule(1); - m.institutional_base_year = sss.institutional_base_year; - m.population_base_year = 0; - m.population_mean_log_year = 0; - m.population_stddev_log_year = 1; - m.sequencedata_base_year = 0; - m.sequencedata_mean_log_year = 0; - m.sequencedata_stddev_log_year = 1; - m = pointMassScienceSpeedModel(m, sss); - //m.institutional_base_year = sss.institutional_base_year; - sss = applyScienceSpeedZValues(m,z); - sssr = applyScienceSpeedZValuesReduce(m,z); - double[] t = {0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,2.0}; - double[] clog_weird - = {0 ,0 ,1 ,1 ,2 ,2 ,3 ,3 ,4 ,4 ,5 ,5 ,6 ,6 ,7 ,7 ,8 }; - - logDoubleList(t); - logDoubleList(projectScienceYearsNumerical(sss,t)); - logDoubleList(projectScienceYearsAnalytic(sss,t)); - logDoubleList(projectScienceYearsAnalytic(sssr,t,m.institutional_base_year)); - s.time = t; - s.clogProbEvent = t; - //s.clogProbEvent = clog_weird; - MathUtil.EventDiscreteDistributionSchedule r = MathUtil.clogMarginalScienceSpeedEventRescheduling(m, s, t, iters); - logDoubleList(r.clogProbEvent); - - r = s; - MathUtil.EventDiscreteDistributionSchedule r_regular = s; - MathUtil.EventDiscreteDistributionSchedule r_montecarlo = s; - MathUtil.ScienceSpeedModelParameters m_v = m.clone(); - - double wt = 0, wt_i; - double[] squared_clog = new double[t.length]; - - m_v.institutional_stddev_slope_log_factor = 1; - for (int i=0; i<=200; ++i) { - z.institutional_rate_Z = (i-100)/10d; - sssr = applyScienceSpeedZValuesReduce(m_v,z); - wt_i = Math.exp(-z.institutional_rate_Z*z.institutional_rate_Z/2); - double[] rescheduled_t = projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year); - MathUtil.EventDiscreteDistributionSchedule s_i = s.logitnerp(rescheduled_t); - r_regular = MathUtil.EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s_i); - //r_regular = EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year))); - wt = wt + wt_i; - } - r_montecarlo = MathUtil.clogMarginalScienceSpeedEventRescheduling(m_v, s, t, iters); - logDoubleList(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year)); - logDoubleList(s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year)).clogProbEvent); - logDoubleList("inst rate Z by regular", r_regular.clogProbEvent); - logDoubleList("inst rate Z by regular", r_montecarlo.clogProbEvent); - m_v.institutional_stddev_slope_log_factor = 0; - z.institutional_rate_Z = 0; - - m_v.population_stddev_init_log_rate = 1; - wt = 0; - for (int i=0; i<=200; ++i) { - z.population_rate_Z = (i-100)/10d; - sssr = applyScienceSpeedZValuesReduce(m_v,z); - wt_i = Math.exp(-z.population_rate_Z*z.population_rate_Z/2); - double[] rescheduled_t = projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year); - MathUtil.EventDiscreteDistributionSchedule s_i = s.logitnerp(rescheduled_t); - r_regular = MathUtil.EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s_i); - //r_regular = EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year))); - wt = wt + wt_i; - } - r_montecarlo = MathUtil.clogMarginalScienceSpeedEventRescheduling(m_v, s, t, iters); - logDoubleList("pop init rate Z by regular", r_regular.clogProbEvent); - logDoubleList("pop init rate Z by MC ", r_montecarlo.clogProbEvent); - m_v.population_stddev_init_log_rate = 0; - z.population_rate_Z = 0; - - m_v.population_stddev_slope_log_rate = 1; - wt = 0; - for (int i=0; i<=200; ++i) { - z.population_rate_Z = (i-100)/10d; - sssr = applyScienceSpeedZValuesReduce(m_v,z); - wt_i = Math.exp(-z.population_rate_Z*z.population_rate_Z/2); - double[] rescheduled_t = projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year); - MathUtil.EventDiscreteDistributionSchedule s_i = s.logitnerp(rescheduled_t); - r_regular = MathUtil.EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s_i); - //r_regular = EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year))); - wt = wt + wt_i; - } - r_montecarlo = MathUtil.clogMarginalScienceSpeedEventRescheduling(m_v, s, t, iters); - logDoubleList("pop slope rate Z by regular", r_regular.clogProbEvent); - logDoubleList("pop slope rate Z by MC ", r_montecarlo.clogProbEvent); - m_v.population_stddev_slope_log_rate = 0; - z.population_rate_Z = 0; - - m_v.population_stddev_log_year = 1; - wt = 0; - for (int i=0; i<=200; ++i) { - z.population_year_Z = (i-100)/10d; - sssr = applyScienceSpeedZValuesReduce(m_v,z); - wt_i = Math.exp(-z.population_year_Z*z.population_year_Z/2); - double[] rescheduled_t = projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year); - MathUtil.EventDiscreteDistributionSchedule s_i = s.logitnerp(rescheduled_t); - r_regular = MathUtil.EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s_i); - //r_regular = EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year))); - wt = wt + wt_i; - } - logDoubleList("pop year Z by regular Z", r_regular.clogProbEvent); - for (int i=0; i<iters; ++i) { - z.population_year_Z = MathUtil.inverseCumulativeProbability(0, 1, (i+0.5d)/iters); - sssr = applyScienceSpeedZValuesReduce(m_v,z); - wt_i = 1; - double[] rescheduled_t = projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year); - MathUtil.EventDiscreteDistributionSchedule s_i = s.logitnerp(rescheduled_t); - r_regular = MathUtil.EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s_i); - //r_regular = EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year))); - wt = wt + wt_i; - //org.singinst.uf.common.LogUtil.info(String.format("regular %g leads to progress %g", sssr.sciencetalent_rel_year, rescheduled_t[rescheduled_t.length-1])); - } - logDoubleList("pop year Z by regular q", r_regular.clogProbEvent); - r_montecarlo = MathUtil.clogMarginalScienceSpeedEventRescheduling(m_v, s, t, iters); - logDoubleList("pop year Z by MC ", r_montecarlo.clogProbEvent); - m_v.population_stddev_log_year = 0; - z.population_year_Z = 0; - - m_v.sequencedata_stddev_init_log_factor = 1; - wt = 0; - for (int i=0; i<=200; ++i) { - z.sequencedata_factor_Z = (i-100)/10d; - sssr = applyScienceSpeedZValuesReduce(m_v,z); - wt_i = Math.exp(-z.sequencedata_factor_Z*z.sequencedata_factor_Z/2); - double[] rescheduled_t = projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year); - MathUtil.EventDiscreteDistributionSchedule s_i = s.logitnerp(rescheduled_t); - r_regular = MathUtil.EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s_i); - //r_regular = EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year))); - wt = wt + wt_i; - } - r_montecarlo = MathUtil.clogMarginalScienceSpeedEventRescheduling(m_v, s, t, iters); - logDoubleList("seqdata init factor Z by regular", r_regular.clogProbEvent); - logDoubleList("seqdata init factor Z by MC ", r_montecarlo.clogProbEvent); - m_v.sequencedata_stddev_init_log_factor = 0; - z.sequencedata_factor_Z = 0; - - m_v.sequencedata_stddev_slope_log_factor = 1; - wt = 0; - for (int i=0; i<=200; ++i) { - z.sequencedata_factor_Z = (i-100)/10d; - sssr = applyScienceSpeedZValuesReduce(m_v,z); - wt_i = Math.exp(-z.sequencedata_factor_Z*z.sequencedata_factor_Z/2); - double[] rescheduled_t = projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year); - MathUtil.EventDiscreteDistributionSchedule s_i = s.logitnerp(rescheduled_t); - r_regular = MathUtil.EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s_i); - //r_regular = EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year))); - wt = wt + wt_i; - } - r_montecarlo = MathUtil.clogMarginalScienceSpeedEventRescheduling(m_v, s, t, iters); - logDoubleList("seqdata slope factor Z by regular", r_regular.clogProbEvent); - logDoubleList("seqdata slope factor Z by MC ", r_montecarlo.clogProbEvent); - m_v.sequencedata_stddev_slope_log_factor = 0; - z.sequencedata_factor_Z = 0; - - m_v.sequencedata_stddev_log_year = 1; - wt = 0; - for (int i=0; i<=200; ++i) { - z.sequencedata_year_Z = (i-100)/10d; - sssr = applyScienceSpeedZValuesReduce(m_v,z); - wt_i = Math.exp(-z.sequencedata_year_Z*z.sequencedata_year_Z/2); - double[] rescheduled_t = projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year); - MathUtil.EventDiscreteDistributionSchedule s_i = s.logitnerp(rescheduled_t); - r_regular = MathUtil.EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s_i); - //r_regular = EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year))); - wt = wt + wt_i; - } - r_montecarlo = MathUtil.clogMarginalScienceSpeedEventRescheduling(m_v, s, t, iters); - logDoubleList("seqdata year Z by regular Z", r_regular.clogProbEvent); - for (int i=0; i<iters; ++i) { - z.sequencedata_year_Z = MathUtil.inverseCumulativeProbability(0, 1, (i+0.5d)/iters); - sssr = applyScienceSpeedZValuesReduce(m_v,z); - wt_i = 1; - double[] rescheduled_t = projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year); - MathUtil.EventDiscreteDistributionSchedule s_i = s.logitnerp(rescheduled_t); - r_regular = MathUtil.EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s_i); - //r_regular = EventDiscreteDistributionSchedule.weightedMix(wt, wt_i, r_regular, s.logitnerp(projectScienceYearsAnalytic(sssr,t,m_v.institutional_base_year))); - wt = wt + wt_i; - //org.singinst.uf.common.LogUtil.info(String.format("regular %g leads to progress %g", sssr.sciencetalent_rel_year, rescheduled_t[rescheduled_t.length-1])); - } - logDoubleList("seqdata year Z by regular q", r_regular.clogProbEvent); - logDoubleList("seqdata year Z by MC ", r_montecarlo.clogProbEvent); - m_v.sequencedata_stddev_log_year = 0; - z.sequencedata_year_Z = 0; - - - fail(); - } - - static double SQRT_EPS = Math.sqrt(MathUtil.DOUBLE_EPS); - public double u(double x) { - return x+SQRT_EPS*(Math.abs(x)+MathUtil.DOUBLE_MIN_NORMAL); - } - public double d(double x) { - return x-SQRT_EPS*(Math.abs(x)/*+MathUtil.DOUBLE_MIN_NORMAL*/); - } - - public void testWeightedClogMix() throws Exception { - int i,j,k,l; - double o, cl_p; - for (i=0; i<6; ++i) for (j=0; j<6; ++j) for (k=0; k<6; ++k) for (l=0; l<6; ++l) { - o = MathUtil.weightedClogMix(i, j, k, l); - cl_p = MathUtil.clog((i*MathUtil.expc(k)+j*MathUtil.expc(l))/(i+j)); - Assert.assertEquals(cl_p, o, 1e-14d*cl_p); - //LogUtil.info(String.format("%d %d %d %d %20.14g %20.14g %20.14g %20.14g", i,j,k,l, o, p, o-p, Math.exp(-((o-p)%100)) )); - } - double a,b,c,d; - double w0, w1, clog_p0, clog_p1; - double cl_p_hi, cl_p_lo; - for (a=-50; a<=50; a+=25) for (b=-50; b<50; b+=25) for (c=0; c<=100; c+=25) for (d=0; d<=100; d+=25) { - w0 = Math.exp(a); clog_p0 = c; - w1 = Math.exp(b); clog_p1 = d; - o = MathUtil.weightedClogMix(w0, w1, clog_p0, clog_p1); -// cl_p = clog_p0-Math.log1p((w1*Math.expm1(clog_p0-clog_p1))/(w0+w1)); -// Assert.assertEquals(cl_p, o, 16*MathUtil.DOUBLE_EPS*( -// Math.abs( clog_p0 ) -// + Math.abs( Math.log1p((w1*Math.expm1(clog_p0-clog_p1))/(w0+w1)) ) -// + Math.abs( 1/(1+(w1*Math.expm1(clog_p0-clog_p1))/(w0+w1)) ) -// ) ); - cl_p = clog_p0-Math.log1p((Math.expm1(clog_p0-clog_p1))/(w0/w1+1)); - cl_p_hi = u(u(clog_p0)-d(Math.log1p(Math.max(1,d(d(Math.expm1(d(d(clog_p0)-u(clog_p1))))/(w0/w1+1)))))); - cl_p_lo = d(d(clog_p0)-u(Math.log1p( u(u(Math.expm1(u(u(clog_p0)-d(clog_p1))))/(w0/w1+1)) ))); - try { - Assert.assertEquals(cl_p, o, 16*SQRT_EPS*(Math.abs(cl_p_hi-cl_p)+Math.abs(cl_p_lo-cl_p))); - } catch (junit.framework.AssertionFailedError e) { - o = MathUtil.weightedClogMix(w0, w1, clog_p0, clog_p1); - throw(e); - } - -// cl_p = clog_p1-Math.log1p((w0*Math.expm1(clog_p1-clog_p0))/(w0+w1)); -// Assert.assertEquals(cl_p, o, 16*MathUtil.DOUBLE_EPS*( -// Math.abs( clog_p1 ) -// + Math.abs( Math.log1p((w0*Math.expm1(clog_p1-clog_p0))/(w0+w1)) ) -// + Math.abs( 1/(1+(w0*Math.expm1(clog_p1-clog_p0))/(w0+w1)) ) -// ) ); - cl_p = clog_p1-Math.log1p((Math.expm1(clog_p1-clog_p0))/(w1/w0+1)); - cl_p_hi = u(u(clog_p1)-d(Math.log1p(Math.max(1,d(d(Math.expm1(d(d(clog_p1)-u(clog_p0))))/(w1/w0+1)))))); - cl_p_lo = d(d(clog_p1)-u(Math.log1p( u(u(Math.expm1(u(u(clog_p1)-d(clog_p0))))/(w1/w0+1)) ))); - try { - Assert.assertEquals(cl_p, o, 16*SQRT_EPS*(Math.abs(cl_p_hi-cl_p)+Math.abs(cl_p_lo-cl_p))); - } catch (junit.framework.AssertionFailedError e) { - o = MathUtil.weightedClogMix(w0, w1, clog_p0, clog_p1); - throw(e); - } - - } - } - - public void test() throws Exception { - } -} diff --git a/java/src/org/singinst/uf/math/SimplePoint.java b/java/src/org/singinst/uf/math/SimplePoint.java deleted file mode 100644 index e1f9ac1..0000000 --- a/java/src/org/singinst/uf/math/SimplePoint.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.singinst.uf.math;
-
-import java.util.Arrays;
-
-public class SimplePoint {
-
- public SimplePoint(double x, double y) {
- this.x = x;
- this.y = y;
- }
- public final double x;
- public final double y;
-
- @Override
- public boolean equals(Object obj) {
- if (obj instanceof SimplePoint) {
- SimplePoint other = (SimplePoint) obj;
- return other.x == x && other.y == y;
- } else {
- return false;
- }
- }
- @Override
- public int hashCode() {
- return canon().hashCode();
- }
- @Override
- public String toString() {
- return canon().toString();
- }
-
- private Object canon() {
- return Arrays.asList(x, y);
- }
-
-
-}
diff --git a/java/src/org/singinst/uf/model/AiRelation.java b/java/src/org/singinst/uf/model/AiRelation.java deleted file mode 100644 index f5e76af..0000000 --- a/java/src/org/singinst/uf/model/AiRelation.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.singinst.uf.model;
-
-import java.awt.Color;
-import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-
-
-
-public class AiRelation extends YearwiseCalculationRelation {
-
- public boolean displayHtml;
-
- public AiRelation(Node node) {
- super(node);
- this.displayHtml = displayHtml;
- }
-
- @Override
- protected Calculation getCalculation(double year) {
- return new MultiplicationCalculation("Probability of either sort of AI by year " + (int) year,
- probabilityAiIfAiIsPossible(year),
- probabilityAiIsPossible());
-
- }
-
- private Calculation probabilityAiIfAiIsPossible(final double year) {
- return new Calculation("Probability of AI (if AI is possible) by year " + (int) year) {
-
- @Override
- protected double rawEvaluate(StringBuilder htmlConsole) {
- return MathUtil.expc(
- MathUtil.clog(
- ScalarValueHolder.findById(NodeIDString.C1_5, ScalarSubIDString.yearProbabilityID(year)).evaluate(new StringBuilder())
- / probabilityAiIsPossible().evaluate()
- )
- + MathUtil.clog(getNonNeuromorphicAiCalculationForYear(year).evaluate())
- );
- }
-
- @Override
- public Color getColor() {
- return Color.BLUE;
- }
- };
-/* ScalarValueHolder.get(NodeIDString.C1_5, yearScalarName(year)),
- getNonNeuromorphicAiCalculationForYear(year)) {
- @Override
- protected double rawEvaluate(StringBuilder htmlConsole) {
- double probabilityOfNot = 1;
- for (Evaluable calculation : getCalculations()) {
- probabilityOfNot *= (1 - calculation.evaluate(htmlConsole));
- }
- htmlConsole.append(getDescription());
- return 1 - probabilityOfNot;
- }
- };*/
- }
- private Calculation getNonNeuromorphicAiCalculationForYear(final double year) {
- return new Calculation("Probability that non-neuromorphic AI will be created by year " + year, false) {
-
- @Override
- protected double rawEvaluate(StringBuilder htmlConsole) {
- double mean = ScalarValueHolder.findById(NodeIDString.Q1_6, ScalarSubIDString.MEAN).getValue();
- double stdDev = ScalarValueHolder.findById(NodeIDString.Q1_6, ScalarSubIDString.STD_DEV).getValue();
- return MathUtil.cumulativeNormalDistribution(mean, stdDev, Math.log10(year - ModelUtil.ANCHOR_FAR_YEAR));
- }
- };
- }
-}
diff --git a/java/src/org/singinst/uf/model/AtLeastOneHappensCalculation.java b/java/src/org/singinst/uf/model/AtLeastOneHappensCalculation.java deleted file mode 100644 index 90954c7..0000000 --- a/java/src/org/singinst/uf/model/AtLeastOneHappensCalculation.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.singinst.uf.model;
-
-
-public class AtLeastOneHappensCalculation extends CompositeCalculation {
-
- public AtLeastOneHappensCalculation(String description,
- Evaluable... calculations) {
- super(description, calculations);
- }
-
- @Override
- protected double rawEvaluate(StringBuilder htmlConsole) {
- double probabilityOfNot = 1;
- for (Evaluable calculation : getCalculations()) {
- probabilityOfNot *= (1 - calculation.evaluate(htmlConsole));
- }
- htmlConsole.append(getDescription());
- return 1 - probabilityOfNot;
- }
-}
diff --git a/java/src/org/singinst/uf/model/Axis.java b/java/src/org/singinst/uf/model/Axis.java deleted file mode 100644 index b8f7523..0000000 --- a/java/src/org/singinst/uf/model/Axis.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.singinst.uf.model;
-
-import org.singinst.uf.presenter.LineBounded;
-import org.singinst.uf.presenter.LineBounds;
-
-public class Axis implements LineBounded {
-
- private final LineBounds lineBounds;
- private final boolean visibleAxis;
-
- public Axis(LineBounds lineBounds) {
- this(lineBounds, true);
- }
-
- public Axis(LineBounds lineBounds, boolean visibleAxis) {
- this.lineBounds = lineBounds;
- this.visibleAxis = visibleAxis;
- }
-
- public LineBounds getLineBounds() {
- return lineBounds;
- }
-
- public boolean isVisibleAxis() {
- return visibleAxis;
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/Calculation.java b/java/src/org/singinst/uf/model/Calculation.java deleted file mode 100644 index 2c9cb7c..0000000 --- a/java/src/org/singinst/uf/model/Calculation.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.singinst.uf.model;
-
-import java.awt.Color;
-import org.singinst.uf.presenter.HtmlUtil;
-
-import org.singinst.uf.math.MathUtil;
-
-public abstract class Calculation implements Evaluable {
-
- private final String description;
- private StringBuilder htmlConsole = new StringBuilder();
- private final boolean prependDescription;
-
- public Calculation(String description) {
- this(description, true);
- }
-
- public Calculation(String description, boolean prependDescription) {
- this.description = description.intern();
- this.prependDescription = prependDescription;
- }
-
- public String getDescription() {
- return description;
- }
-
- public final double evaluate() {
- return evaluate(getHtmlConsole());
- }
-
- public final double evaluate(StringBuilder htmlConsole) {
- if (prependDescription) {
- htmlConsole.append(description);
- }
- double raw = rawEvaluate(htmlConsole);
- double rounded = MathUtil.round(raw, 12);
- htmlConsole.append(" = " + HtmlUtil.htmlcolorFromColor(getColor(), rounded) + "<br>\n");
- return rounded;
- }
-
- protected abstract double rawEvaluate(StringBuilder htmlConsole);
-
- /**
- * Returns the color for this calculation, so that we consistently display the correct one.
- *
- * @return
- * The color to display this calculation
- */
- public Color getColor() {
- return Color.BLACK;
- }
-
- public StringBuilder getHtmlConsole() {
- return htmlConsole;
- }
-
- public void setHtmlConsole(StringBuilder htmlConsole) {
- this.htmlConsole = htmlConsole;
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/CalculationRelation.java b/java/src/org/singinst/uf/model/CalculationRelation.java deleted file mode 100644 index 77f2ec9..0000000 --- a/java/src/org/singinst/uf/model/CalculationRelation.java +++ /dev/null @@ -1,143 +0,0 @@ -package org.singinst.uf.model;
-
-import java.awt.Color;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.Completion;
-import org.singinst.uf.presenter.ScalarValuePointList;
-import org.singinst.uf.presenter.LineBounds;
-
-public abstract class CalculationRelation extends ScalarRelation {
-
- private final Node node;
-
- private final List<ScalarSchema> scalarSchemata = new ArrayList<ScalarSchema>();
- private final List<ScalarValueHolder> scalarValueHolders = new ArrayList<ScalarValueHolder>();
- private final StringBuilder htmlConsole = new StringBuilder();
- private final ScalarValueDependency dependency = new ScalarValueDependency();
-
- private final ConclusionReportGenerator conclusion = new ConclusionReportGenerator() {
-
- public String getText(ScalarValueHolder scalarValueHolder, double value) {
- return htmlConsole.toString();
- }
-
- };
-
- private final ScalarValuePointList curveList = new ScalarValuePointList() {
-
- @Override
- public Runnable updater() {
- return new Runnable() {
-
- public void run() {
- Completion completion = Completion.getInstance();
- if (completion.init("Calculating " + node.getIdString(), ModelUtil.LATEST_YEAR - ModelUtil.EARLIEST_YEAR)) {
- for (int year = ModelUtil.EARLIEST_YEAR; year <= ModelUtil.LATEST_YEAR; year++) {
- ScalarValueHolder scalarValueHolder = ScalarValueHolder.findById(node.getIdString(), ScalarSubIDString.yearProbabilityID(year));
- scalarValueHolder.getValue();
- completion.tick();
- }
- }
- }
-
- };
- }
-
- };
-
- public CalculationRelation(Node node) {
- super(new Axis(new LineBounds(ModelUtil.EARLIEST_YEAR, ModelUtil.LATEST_YEAR)),
- new Axis(new LineBounds(0, 1)));
- this.node = node;
-
- List<Double> yearList = new ArrayList<Double>();
- for (double year = ModelUtil.EARLIEST_YEAR; year <= ModelUtil.LATEST_UNACCELERATED_YEAR; year += ModelUtil.YEAR_STEPSIZE) {
- yearList.add((double) year);
- }
- List<Calculation> calculations = getCalculations(yearList);
-
- for (double year = ModelUtil.EARLIEST_YEAR; year <= ModelUtil.LATEST_UNACCELERATED_YEAR; year += ModelUtil.YEAR_STEPSIZE) {
- ScalarSchema scalarSchema = new ScalarSchema(
- node, ScalarSubIDString.yearProbabilityID(year), new LineBounds(0, 1), "", "", "", null, true);
- scalarSchemata.add(scalarSchema);
- ScalarValueHolder scalarValueHolder = scalarSchema.getScalarValueHolder();
- if (year <= ModelUtil.LATEST_YEAR && ((year % 1d) == 0d) /* could use elementOf to ModelUtil.BASIC_MODEL_YEARS? */ ) {
- scalarValueHolders.add(scalarValueHolder);
- }
- scalarValueHolder.setCalculation(calculations.remove(0));
- }
- }
-
- protected abstract List<Calculation> getCalculations(List<Double> year);
-
- @Override
- public List<ScalarValuePointList> getPointLists() {
- List<SimplePoint> pointList = new ArrayList<SimplePoint>();
- ScalarValueHolder lastScalarValue = null;
- Boolean needsCalc = null;
- for (int year = ModelUtil.EARLIEST_YEAR; year <= ModelUtil.LATEST_YEAR; year++) {
- lastScalarValue = ScalarValueHolder.findById(node.getIdString(), ScalarSubIDString.yearProbabilityID(year));
- if (needsCalc == null) {
- if (lastScalarValue.needsCalc(new NeedsCalcCache())) {
- curveList.setHypothesisPoints(null);
- return Collections.singletonList(curveList);
- } else {
- needsCalc = false;
- }
- }
- double value = lastScalarValue.getValue();
-
- // TODO4
- // dependency.validate();
-
- pointList.add(new SimplePoint(year, value));
- }
- if (lastScalarValue != null) {
- StringBuilder newConsoleText = lastScalarValue.getCalculation().getHtmlConsole();;
- if (this instanceof AiRelation) {
- newConsoleText = new StringBuilder();
- lastScalarValue.getCalculation().setHtmlConsole( newConsoleText );
- }
-
- if (!htmlConsole.toString().equals(newConsoleText.toString())) {
- htmlConsole.setLength(0);
- htmlConsole.append(newConsoleText);
- lastScalarValue.notifyListeners();
- }
- }
- curveList.setHypothesisPoints(pointList);
- return Collections.singletonList(curveList);
- }
-
- public List<? extends ConclusionReportGenerator> getConclusionGenerators() {
- return Collections.singletonList(conclusion);
- }
-
- public List<ScalarValueHolder> getScalarValues() {
- return scalarValueHolders;
- }
-
- protected ScalarValueDependency getDependency() {
- return dependency;
- }
-
- protected Calculation probabilityAiIsPossible() {
- return new Calculation("Probability that AI is possible in principle") {
- @Override
- protected double rawEvaluate(StringBuilder htmlConsole) {
- return getDependency().value(NodeIDString.Q1_1, ScalarSubIDString.PROBABILITY) / 100;
- }
-
- @Override
- public Color getColor(){
- return Color.GREEN;
- }
-
-
- };
- }
-}
diff --git a/java/src/org/singinst/uf/model/CompositeCalculation.java b/java/src/org/singinst/uf/model/CompositeCalculation.java deleted file mode 100644 index 7361dd9..0000000 --- a/java/src/org/singinst/uf/model/CompositeCalculation.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.singinst.uf.model;
-
-public abstract class CompositeCalculation extends Calculation {
-
- private final Evaluable[] calculations;
-
- public CompositeCalculation(String description,
- Evaluable... calculations2) {
- super(description, false);
- this.calculations = calculations2;
- }
-
- public Evaluable[] getCalculations() {
- return calculations;
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/ConclusionReportGenerator.java b/java/src/org/singinst/uf/model/ConclusionReportGenerator.java deleted file mode 100644 index 5d9289e..0000000 --- a/java/src/org/singinst/uf/model/ConclusionReportGenerator.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.singinst.uf.model;
-
-public interface ConclusionReportGenerator {
- String getText(ScalarValueHolder scalarValueHolder, double value);
-
-}
diff --git a/java/src/org/singinst/uf/model/CumulativeHazardsRelation.java b/java/src/org/singinst/uf/model/CumulativeHazardsRelation.java deleted file mode 100644 index 0c17a4a..0000000 --- a/java/src/org/singinst/uf/model/CumulativeHazardsRelation.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.singinst.uf.model;
-
-//import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-
-public class CumulativeHazardsRelation extends YearwiseCalculationRelation {
-
- public CumulativeHazardsRelation(Node node) {
- super(node);
- }
-
- @Override
- protected Calculation getCalculation(double year) {
- return new AtLeastOneHappensCalculation("Probability of nuclear or other science-disrupting catastrophe by year " + (int) year,
- probabilityOneCumulativeHazard(NodeIDString.Q1_7, "Independent probability of nuclear catastrophe by year ", year),
- probabilityOneCumulativeHazard(NodeIDString.Q1_8, "Independent probability of non-nuclear catastrophe by year ", year));
-
- }
-
- private Calculation probabilityOneCumulativeHazard(final String nodeId, final String description, final double year) {
- return new Calculation(description + (int) year) {
-
- @Override
- protected double rawEvaluate(StringBuilder htmlConsole) {
- double t0, t1;
- t0 = ModelUtil.EARLIEST_YEAR;
- t1 = ModelUtil.LATEST_YEAR;
- double klow, khigh;
- klow = NotablePercentile.PERCENTILE5.getValue();
- khigh = NotablePercentile.PERCENTILE95.getValue();
- double zlow, zhigh;
- zlow = NotablePercentile.PERCENTILE5.getOffset();
- zhigh = NotablePercentile.PERCENTILE95.getOffset();
-
- double y0low, y0high, y1low, y1high;
- y0low = getDependency().value(nodeId, ScalarSubIDString.yearPercentileID(t0, klow ))*Math.log(10);
- y0high = getDependency().value(nodeId, ScalarSubIDString.yearPercentileID(t0, khigh))*Math.log(10);
- y1low = getDependency().value(nodeId, ScalarSubIDString.yearPercentileID(t1, klow ))*Math.log(10);
- y1high = getDependency().value(nodeId, ScalarSubIDString.yearPercentileID(t1, khigh))*Math.log(10);
-
- double mean_init, stddev_init, mean_final, stddev_final;
- mean_init = MathUtil.linterp(zlow, zhigh, y0low, y0high, 0);
- stddev_init = (y0high-y0low)/(zhigh-zlow);
- mean_final = MathUtil.linterp(zlow, zhigh, y1low, y1high, 0);
- stddev_final = (y1high-y1low)/(zhigh-zlow);
-
- double[] clogp = MathUtil.clogMarginalOfExponentiallyVaryingHazardModel(
- t0, t1,
- mean_init, mean_final,
- stddev_init, stddev_final,
- new double[]{year}
- );
-
- return MathUtil.expc(clogp[0]);
- }
-
- };
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/CumulativeNormalDistributionCalculation.java b/java/src/org/singinst/uf/model/CumulativeNormalDistributionCalculation.java deleted file mode 100644 index 97db54c..0000000 --- a/java/src/org/singinst/uf/model/CumulativeNormalDistributionCalculation.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.singinst.uf.model;
-
-import java.awt.Color;
-
-import org.singinst.uf.math.MathUtil;
-
-public class CumulativeNormalDistributionCalculation extends Calculation {
-
- private final Evaluable mean;
- private final Evaluable stdDev;
- private final double x;
- private final Color color;
-
- /**
- *
- * @param description
- * @param mean
- * @param stdDev
- * @param x
- * @param display
- * The color to display the result of this calculation.
- */
- public CumulativeNormalDistributionCalculation(String description, Evaluable mean, Evaluable stdDev, double x, Color display) {
- super(description, false);
- this.mean = mean;
- this.stdDev = stdDev;
- this.x = x;
- this.color = display;
- }
-
- @Override
- public double rawEvaluate(StringBuilder htmlConsole) {
- StringBuilder nullBuilder = new StringBuilder();
- double meanValue = mean.evaluate(nullBuilder);
- double stdDevValue = stdDev.evaluate(nullBuilder);
- double retVal = MathUtil.cumulativeNormalDistribution(
- meanValue, stdDevValue, x);
- //htmlConsole.append("Cumulative probability (mean = " + meanValue + "; stddev = " + stdDevValue + ") of " + getDescription() + " at " + x);
- htmlConsole.append(getDescription().replace("\'", ""));
- return retVal;
- }
-
- @Override
- public Color getColor(){
- return color;
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/DisruptionRelation.java b/java/src/org/singinst/uf/model/DisruptionRelation.java deleted file mode 100644 index f5d97ad..0000000 --- a/java/src/org/singinst/uf/model/DisruptionRelation.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.singinst.uf.model;
-
-//import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-
-public class DisruptionRelation extends YearwiseCalculationRelation {
-
- public DisruptionRelation(Node node) {
- super(node);
- }
-
- @Override
- protected Calculation getCalculation(double year) {
- return new AtLeastOneHappensCalculation("Probability that either AI, or a science-disrupting catastrophe, disrupts business as usual by year " + (int) year,
- ScalarValueHolder.findById(NodeIDString.C1_8, ScalarSubIDString.yearProbabilityID(year)),
- ScalarValueHolder.findById(NodeIDString.C1_9, ScalarSubIDString.yearProbabilityID(year)));
- }
-}
diff --git a/java/src/org/singinst/uf/model/Evaluable.java b/java/src/org/singinst/uf/model/Evaluable.java deleted file mode 100644 index 84b072c..0000000 --- a/java/src/org/singinst/uf/model/Evaluable.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.singinst.uf.model;
-
-public interface Evaluable {
- double evaluate(StringBuilder htmlConsole);
-}
diff --git a/java/src/org/singinst/uf/model/GeneLearningExtreme.java b/java/src/org/singinst/uf/model/GeneLearningExtreme.java deleted file mode 100644 index f3676d9..0000000 --- a/java/src/org/singinst/uf/model/GeneLearningExtreme.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.singinst.uf.model;
-
-import org.singinst.uf.presenter.HtmlUtil;
-import org.singinst.uf.presenter.LineBounds;
-import org.singinst.uf.presenter.NumericEntry;
-
-public class GeneLearningExtreme extends YearExtremeNodeMetadataContentsFactory {
-
- protected GeneLearningExtreme(Node node, LineBounds rangeBounds,
- double year) {
- //super(node, rangeBounds, year, " log speedup after " + (int) year + " yrs", "", "early", "late");
- super(node, rangeBounds, year, " log research speedup after " + (int) year + " yrs", "", "small", "large");
- }
-
- @Override
- public ConclusionReportGenerator getConclusionGenerator() {
- return new ConclusionReportGenerator() {
- public String getText(ScalarValueHolder scalarValueHolder, double value) {
- return "The research speedup " + getYearString() + " years later has a 90% chance of being between " +
- HtmlUtil.green(display(getScalars().get(0).getScalarValueHolder().getValue())) +
- " and " + HtmlUtil.red(display(getScalars().get(2).getScalarValueHolder().getValue()));
- }
-
- private String display(double value) {
- return NumericEntry.formatAsScalar(Math.pow(10, value)) + "x";
- }
- };
-
- }
-
-
-}
diff --git a/java/src/org/singinst/uf/model/GeneLearningNodeMetadataContentsFactory.java b/java/src/org/singinst/uf/model/GeneLearningNodeMetadataContentsFactory.java deleted file mode 100644 index 110c4b0..0000000 --- a/java/src/org/singinst/uf/model/GeneLearningNodeMetadataContentsFactory.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.ScalarValuePointList;
-import org.singinst.uf.presenter.LineBounds;
-
-public class GeneLearningNodeMetadataContentsFactory {
-
- private final YearExtremeNodeMetadataContentsFactory extreme;
- private final List<ScalarSchema> scalarSchemata = new ArrayList<ScalarSchema>();
- private final ScalarRelation relation;
-
- private final List<PercentileDraggableLine> pointLists = new ArrayList<PercentileDraggableLine>();
-
- private final List<ScalarValueHolder> scalarValueList = new ArrayList<ScalarValueHolder>();
-
- public GeneLearningNodeMetadataContentsFactory(Node node) {
- final LineBounds range = new LineBounds(0, 4, true);
- final LineBounds domain = new LineBounds(0, ModelUtil.LATEST_IA_DELAY);
- extreme = new GeneLearningExtreme(node, range, ModelUtil.LATEST_IA_DELAY);
- scalarSchemata.addAll(extreme.getScalars());
- for (ScalarSchema scalarSchema : scalarSchemata) {
- scalarValueList.add(scalarSchema.getScalarValueHolder());
- }
-
- for (final NotablePercentile percentile : NotablePercentile.values()) {
- PercentileDraggableLine pointList = new PercentileDraggableLine(percentile) {
-
- @Override
- public void dragTo(SimplePoint point) {
- GeneLearningNodeMetadataContentsFactory.this.dragTo(percentile, point);
- }};
- pointLists.add(pointList);
- }
-
- relation = new ScalarRelation(new Axis(domain), new Axis(range)) {
-
- @Override
- public List<? extends ScalarValuePointList> getPointLists() {
- for (PercentileDraggableLine incidentLine : pointLists) {
- List<SimplePoint> points = new ArrayList<SimplePoint>();
- points.add(new SimplePoint(domain.getFirst(), range.getFirst()));
- points.add(new SimplePoint(extreme.getYear(),
- extreme.getScalarSchema(incidentLine.getPercentile()).getScalarValueHolder().getValue()));
- incidentLine.setHypothesisPoints(points);
- }
- return pointLists;
- }
-
- public List<? extends ConclusionReportGenerator> getConclusionGenerators() {
- List<ConclusionReportGenerator> retVal = new ArrayList<ConclusionReportGenerator>();
- retVal.add(extreme.getConclusionGenerator());
- return retVal;
- }
-
- public List<ScalarValueHolder> getScalarValues() {
- return scalarValueList ;
- }
- };
- }
-
- public Collection<? extends ScalarSchema> getScalarSchemata() {
- return scalarSchemata;
- }
-
- public ScalarRelation getRelation() {
- return relation;
- }
-
- public void dragTo(NotablePercentile percentile, SimplePoint point) {
- SimplePoint anchorPoint = new SimplePoint(0, 0);
- double newExtremeY = MathUtil.interpolate(
- anchorPoint, point, ModelUtil.LATEST_IA_DELAY);
- extreme.getScalarSchema(percentile).getScalarValueHolder().setValue(newExtremeY);
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/HazardRateNodeMetadataContentsFactory.java b/java/src/org/singinst/uf/model/HazardRateNodeMetadataContentsFactory.java deleted file mode 100644 index 2cf1de4..0000000 --- a/java/src/org/singinst/uf/model/HazardRateNodeMetadataContentsFactory.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.ScalarValuePointList;
-import org.singinst.uf.presenter.LineBounds;
-
-public class HazardRateNodeMetadataContentsFactory {
-
- private final List<ScalarSchema> scalarSchemata = new ArrayList<ScalarSchema>();
- private final ScalarRelation relation;
- private final Map<Double, YearExtremeNodeMetadataContentsFactory> extremeByYear = new HashMap<Double, YearExtremeNodeMetadataContentsFactory>();
-
- private final List<PercentileDraggableLine> pointLists = new ArrayList<PercentileDraggableLine>();
-
- private final List<ScalarValueHolder> conjectureList = new ArrayList<ScalarValueHolder>();
-
- private static final double MID_YEAR = MathUtil.average(ModelUtil.EARLIEST_YEAR, ModelUtil.LATEST_YEAR);
-
- public HazardRateNodeMetadataContentsFactory(Node node) {
- IncidentBounds incidentBounds = new IncidentBounds();
- LineBounds yearBounds = new LineBounds(ModelUtil.EARLIEST_YEAR, ModelUtil.LATEST_YEAR);
- final List<IncidentExtremeNodeMetadataContentsFactory> extremes = IncidentExtremeNodeMetadataContentsFactory.createList(node, incidentBounds, yearBounds);
- for (YearExtremeNodeMetadataContentsFactory extreme : extremes) {
- extremeByYear.put(extreme.getYear(), extreme);
- scalarSchemata.addAll(extreme.getScalars());
- }
- for (ScalarSchema scalarSchema : scalarSchemata) {
- conjectureList.add(scalarSchema.getScalarValueHolder());
- }
-
- for (NotablePercentile percentile : NotablePercentile.values()) {
- PercentileDraggableLine pointList = new IncidentLine(this, percentile);
- pointLists.add(pointList);
- }
-
- relation = new ScalarRelation(new Axis(yearBounds), new Axis(incidentBounds)) {
-
- @Override
- public List<? extends ScalarValuePointList> getPointLists() {
- for (PercentileDraggableLine incidentLine : pointLists) {
- List<SimplePoint> points = new ArrayList<SimplePoint>();
- for (YearExtremeNodeMetadataContentsFactory extreme : extremes) {
- points.add(new SimplePoint(extreme.getYear(),
- extreme.getScalarSchema(incidentLine.getPercentile()).getScalarValueHolder().getValue()));
- }
- incidentLine.setHypothesisPoints(points);
- }
- return pointLists;
- }
-
- public List<? extends ConclusionReportGenerator> getConclusionGenerators() {
- List<ConclusionReportGenerator> retVal = new ArrayList<ConclusionReportGenerator>();
- for (YearExtremeNodeMetadataContentsFactory extreme : extremes) {
- retVal.add(extreme.getConclusionGenerator());
- }
- return retVal;
- }
-
- public List<ScalarValueHolder> getScalarValues() {
- return conjectureList ;
- }
- };
- }
-
- public Collection<? extends ScalarSchema> getScalars() {
- return scalarSchemata;
- }
-
- public ScalarRelation getRelation() {
- return relation;
- }
-
- public void dragTo(NotablePercentile percentile, SimplePoint point) {
- boolean selectLeft = point.x < MID_YEAR;
- double year = selectLeft ? ModelUtil.EARLIEST_YEAR : ModelUtil.LATEST_YEAR;
- double anchorYear = selectLeft ? ModelUtil.LATEST_YEAR : ModelUtil.EARLIEST_YEAR;
- YearExtremeNodeMetadataContentsFactory extreme = extremeByYear.get(year);
- if (extreme == null) {
- throw new NullPointerException("" + year);
- }
- YearExtremeNodeMetadataContentsFactory anchorExtreme = extremeByYear.get(anchorYear);
- if (anchorExtreme == null) {
- throw new NullPointerException("" + year);
- }
- SimplePoint anchorPoint = new SimplePoint(
- anchorYear, anchorExtreme.getScalarSchema(percentile).getScalarValueHolder().getValue());
- double newExtremeY = MathUtil.interpolate(
- anchorPoint, point, year);
- extreme.getScalarSchema(percentile).getScalarValueHolder().setValue(newExtremeY);
- }
-}
diff --git a/java/src/org/singinst/uf/model/IncidentBounds.java b/java/src/org/singinst/uf/model/IncidentBounds.java deleted file mode 100644 index c528023..0000000 --- a/java/src/org/singinst/uf/model/IncidentBounds.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.singinst.uf.math.InvertableFunction;
-import org.singinst.uf.presenter.AxisSample;
-import org.singinst.uf.presenter.CanvasString;
-import org.singinst.uf.presenter.LineBounds;
-import org.singinst.uf.presenter.NumericEntry;
-
-public class IncidentBounds extends LineBounds {
-
- private static final InvertableFunction toDisplay = new IncidentFunction();
-
- private static final double LOWER_DISPLAY = 0.001;
- private static final double UPPER_DISPLAY = 99;
-
- public IncidentBounds() {
- super(fromDisplay(LOWER_DISPLAY), fromDisplay(UPPER_DISPLAY));
- }
-
- @Override
- public Iterable<AxisSample> getAxisSamples(boolean majorTick) {
- return samples(0.001, 0.01, 0.1, 1, 10, 50, 99);
- }
-
- private Iterable<AxisSample> samples(double... displays) {
- List<AxisSample> samples = new ArrayList<AxisSample>();
- for (double display : displays) {
- samples.add(new AxisSample(fromDisplay(display),
- new CanvasString("" + NumericEntry.formatAsScalar(display))));
- }
- return samples;
- }
-
- @Override
- public InvertableFunction toDisplay() {
- return toDisplay;
- }
-
- @Override
- public String userFormat(double value) {
- return "" + NumericEntry.formatAsScalar(toDisplay.apply(value));
- }
-
- private static double fromDisplay(double display) {
- return toDisplay.invert(display);
- }
-}
diff --git a/java/src/org/singinst/uf/model/IncidentExtremeNodeMetadataContentsFactory.java b/java/src/org/singinst/uf/model/IncidentExtremeNodeMetadataContentsFactory.java deleted file mode 100644 index c370886..0000000 --- a/java/src/org/singinst/uf/model/IncidentExtremeNodeMetadataContentsFactory.java +++ /dev/null @@ -1,36 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.singinst.uf.presenter.HtmlUtil;
-import org.singinst.uf.presenter.LineBounds;
-
-public class IncidentExtremeNodeMetadataContentsFactory extends YearExtremeNodeMetadataContentsFactory {
-
-
- protected IncidentExtremeNodeMetadataContentsFactory(Node node, LineBounds rangeBounds,
- double year) {
- super(node, rangeBounds, year, " chance in " + (int) year, "%", "small", "large");
- }
-
- public static List<IncidentExtremeNodeMetadataContentsFactory> createList(Node node, LineBounds rangeBounds, LineBounds yearBounds) {
- IncidentExtremeNodeMetadataContentsFactory incidentEarly = new IncidentExtremeNodeMetadataContentsFactory(node, rangeBounds, yearBounds.getFirst());
- IncidentExtremeNodeMetadataContentsFactory incidentLate = new IncidentExtremeNodeMetadataContentsFactory(node, rangeBounds, yearBounds.getSecond());
- return Arrays.asList(incidentEarly, incidentLate);
- }
-
- @Override
- public ConclusionReportGenerator getConclusionGenerator() {
- return new ConclusionReportGenerator() {
- public String getText(ScalarValueHolder scalarValueHolder, double value) {
- return "The likelihood at year " + getYearString() + " has a 90% chance of being between " +
- HtmlUtil.green(getScalars().get(0).getScalarValueHolder().getValue()) +
- " and " + HtmlUtil.red(getScalars().get(2).getScalarValueHolder().getValue());
- }
- };
-
- }
-
-
-}
diff --git a/java/src/org/singinst/uf/model/IncidentFunction.java b/java/src/org/singinst/uf/model/IncidentFunction.java deleted file mode 100644 index f6c1aba..0000000 --- a/java/src/org/singinst/uf/model/IncidentFunction.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.singinst.uf.model;
-
-import org.singinst.uf.math.InvertableFunction;
-
-public class IncidentFunction extends InvertableFunction {
-
- @Override
- public double apply(double x) {
- double log1p = -1 * Math.pow(10, x);
- double probability = -1 * Math.expm1(log1p);
- return probability * 100;
- }
-
- @Override
- public double invert(double y) {
- double log1p = -1 * Math.log1p(-1 * y/100);
- return Math.log10(log1p);
- }
-}
diff --git a/java/src/org/singinst/uf/model/IncidentLine.java b/java/src/org/singinst/uf/model/IncidentLine.java deleted file mode 100644 index bb1db93..0000000 --- a/java/src/org/singinst/uf/model/IncidentLine.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.singinst.uf.model;
-
-import org.singinst.uf.math.SimplePoint;
-
-public class IncidentLine extends PercentileDraggableLine {
-
- private final HazardRateNodeMetadataContentsFactory hazardRateNodeMetadataContentsFactory;
-
- public IncidentLine(HazardRateNodeMetadataContentsFactory hazardRateNodeMetadataContentsFactory, NotablePercentile percentile) {
- super(percentile);
- this.hazardRateNodeMetadataContentsFactory = hazardRateNodeMetadataContentsFactory;
- }
-
- @Override
- public void dragTo(SimplePoint point) {
- hazardRateNodeMetadataContentsFactory.dragTo(getPercentile(), point);
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/LogBounds.java b/java/src/org/singinst/uf/model/LogBounds.java deleted file mode 100644 index d325b52..0000000 --- a/java/src/org/singinst/uf/model/LogBounds.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.singinst.uf.math.InvertableFunction;
-import org.singinst.uf.presenter.AxisSample;
-import org.singinst.uf.presenter.LineBounds;
-
-public class LogBounds extends LineBounds {
-
- private final double majorTickSpace;
- private final double minorTickSpace;
- private final double zero;
- private final double firstMajorTick;
- private final InvertableFunction toDisplay;
-
- public LogBounds(double firstMajorTick, double zero, double first, double second, double majorTickSpace, double minorTickSpace) {
- super(first, second);
- this.firstMajorTick = firstMajorTick;
- this.zero = zero;
- this.majorTickSpace = majorTickSpace;
- this.minorTickSpace = minorTickSpace;
- toDisplay = new PowerFunction(zero);
- }
-
- @Override
- public Iterable<AxisSample> getAxisSamples(boolean majorTick) {
- List<AxisSample> samples = new ArrayList<AxisSample>();
- double space;
- double display;
- if (majorTick) {
- space = majorTickSpace;
- display = firstMajorTick - zero;
- } else {
- space = minorTickSpace;
- display = Math.pow(10, getFirst());
- display += (minorTickSpace - display % minorTickSpace);
- }
- while (display <= Math.pow(10, getSecond())) {
- if (majorTick) {
- if (zero + display == 2050) {
- addSample(samples, 2010 - zero);
- addSample(samples, 2030 - zero);
- }
- if ((zero + display != 2350) && (zero + display != 2450)) {
- addSample(samples, display);
- }
- } else {
- samples.add(new AxisSample(Math.log10(display)));
- }
- display += space;
- }
- return samples;
- }
-
-
-
- @Override
- public InvertableFunction toDisplay() {
- return toDisplay;
- }
-
- @Override
- public String userFormat(double value) {
- return "" + Math.round(toDisplay.apply(value));
- }
-
- @Override
- public double constrain(double rounded) {
- double bounded = super.constrain(rounded);
- double display = toDisplay.apply(bounded);
- double intDisplay = Math.round(display);
- return toDisplay.invert(intDisplay);
- }
-
- private boolean addSample(List<AxisSample> samples, double display) {
- return samples.add(new AxisSample(Math.log10(display), getCanvasString(zero + display)));
- }
-}
diff --git a/java/src/org/singinst/uf/model/ModelUtil.java b/java/src/org/singinst/uf/model/ModelUtil.java deleted file mode 100644 index 452c195..0000000 --- a/java/src/org/singinst/uf/model/ModelUtil.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-public class ModelUtil {
- protected static final int EARLIEST_YEAR = 2010;
- protected static final int LATEST_YEAR = 2070;
- public static final int EARLIEST_FAR_YEAR = 2010;
- public static final int LATEST_FAR_YEAR = 2500;
- public static final int EARLIEST_IA_YEAR = 2010;
- public static final int LATEST_IA_YEAR = 2050;
-
- public static final int ANCHOR_FAR_YEAR = 1950;
- public static final int LATEST_IA_DELAY = 50;
- public static final int RESEARCH_CAREER_DELAY = 20;
-
- public static final int LATEST_UNACCELERATED_YEAR = 5000;
-
- public static final double[] BASIC_MODEL_YEARS;
- static {
- BASIC_MODEL_YEARS = new double[LATEST_YEAR-EARLIEST_YEAR+1];
- for (int i=EARLIEST_YEAR; i<=LATEST_YEAR; ++i) {
- BASIC_MODEL_YEARS[i-EARLIEST_YEAR] = i;
- }
- }
- public static final double YEAR_STEPSIZE = 0.5;
- // TODO document this parameter in UI
- public static final double UNENHANCED_RESEARCHERS = 100000d;
-}
diff --git a/java/src/org/singinst/uf/model/MooreAsymptote.java b/java/src/org/singinst/uf/model/MooreAsymptote.java deleted file mode 100644 index ac0c0f3..0000000 --- a/java/src/org/singinst/uf/model/MooreAsymptote.java +++ /dev/null @@ -1,84 +0,0 @@ -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.common.LogUtil;
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.DraggableLine;
-import org.singinst.uf.presenter.HtmlUtil;
-import org.singinst.uf.presenter.ScalarValuePointList;
-import org.singinst.uf.presenter.LineBounds;
-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;
- }
-}
diff --git a/java/src/org/singinst/uf/model/MooreConstraint.java b/java/src/org/singinst/uf/model/MooreConstraint.java deleted file mode 100644 index cb20bb1..0000000 --- a/java/src/org/singinst/uf/model/MooreConstraint.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.List;
-
-public class MooreConstraint extends NormalConstraint {
-
- public MooreConstraint(List<ScalarSchema> scalarSchemata) {
- super(scalarSchemata, 8);
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/MooreDraggableLine.java b/java/src/org/singinst/uf/model/MooreDraggableLine.java deleted file mode 100644 index eb8d9ea..0000000 --- a/java/src/org/singinst/uf/model/MooreDraggableLine.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.singinst.uf.model;
-
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.DraggableLine;
-import org.singinst.uf.presenter.SimpleStyle;
-
-public class MooreDraggableLine extends DraggableLine {
-
- private final MooreAsymptote mooreAsymptote;
-
- public MooreDraggableLine(MooreAsymptote mooreAsymptote, NotablePercentile percentile) {
- super(percentile.getPriority(), new SimpleStyle(percentile.getColor(), true));
- this.mooreAsymptote = mooreAsymptote;
- }
-
- @Override
- public void dragTo(SimplePoint point) {
- mooreAsymptote.setY(point.y);
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/MooresLawData.java b/java/src/org/singinst/uf/model/MooresLawData.java deleted file mode 100644 index 39fd48a..0000000 --- a/java/src/org/singinst/uf/model/MooresLawData.java +++ /dev/null @@ -1,151 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-import org.singinst.uf.math.SimplePoint;
-
-public class MooresLawData {
-
- private static MooresLawData instance;
-
- public static MooresLawData getInstance() {
- if (instance == null) {
- instance = new MooresLawData();
- }
- return instance;
- }
-
- public MooresLawData() {
- points = new ArrayList<SimplePoint>();
- addPoint(1950, 0.00060, "SEAC");
- addPoint(1951, 0.00077, "UNIVAC_I");
- addPoint(1952, 0.00001, "Zuse-5");
- addPoint(1952, 0.00225, "IBM_CPC");
- addPoint(1953, 0.00062, "IBM_650");
- addPoint(1954, 0.00044, "EDVAC");
- addPoint(1955, 0.04476, "Whirlwind");
- addPoint(1955, 0.00346, "IBM_704");
- addPoint(1956, 0.00184, "Librascope_LGP-30");
- addPoint(1959, 0.01521, "IBM_7090");
- addPoint(1960, 0.00074, "IBM_1620");
- addPoint(1960, 0.11821, "DEC_PDP-1");
- addPoint(1961, 0.04032, "Atlas");
- addPoint(1962, 0.01444, "Burroughs_5000");
- addPoint(1963, 0.01665, "IBM_7040");
- addPoint(1963, 0.01586, "Honeywell_1800");
- addPoint(1964, 0.0845, "DEC_PDP-6");
- addPoint(1964, 0.2628, "CDC_6600");
- addPoint(1965, 0.456, "IBM_1130");
- addPoint(1966, 0.07925, "IBM_360/75");
- addPoint(1967, 0.06655, "IBM_360/65");
- addPoint(1968, 0.22008, "DEC_PDP-10");
- addPoint(1969, 0.45489, "CDC_7600");
- addPoint(1969, 2.73651, "DG_Nova");
- addPoint(1970, 0.06068, "GE-635");
- addPoint(1971, 0.20475, "SDS_920");
- addPoint(1972, 0.43683, "IBM_360/195");
- addPoint(1972, 1.2625, "Honeywell_700");
- addPoint(1973, 9.06353, "Prime_Computer_100");
- addPoint(1974, 1.05672, "IBM-370/168");
- addPoint(1974, 4.76, "MITS_Altair");
- addPoint(1975, 2.4346, "DG_Eclipse");
- addPoint(1975, 1.1914, "DEC-KL-10");
- addPoint(1976, 0.73067, "DEC_PDP-11/70");
- addPoint(1976, 4.11, "Cray-1");
- addPoint(1977, 4.49231, "Apple_II");
- addPoint(1977, 1.46, "DEC_VAX_11/780");
- addPoint(1977, 5.84, "TRS-80");
- addPoint(1977, 11.68, "Commodore_PET");
- addPoint(1978, 4.71, "CDC_IPL");
- addPoint(1979, 2.45, "Nanodata_VMX200");
- addPoint(1980, 13.23333, "TRS-80_M3");
- addPoint(1980, 6.40493, "Sun-1");
- addPoint(1981, 3.5624, "CDC_Cyber-205");
- addPoint(1981, 62.79570, "Vic_20");
- addPoint(1982, 31.62, "IBM_PC");
- addPoint(1982, 17.22825, "Sun-2");
- addPoint(1982, 186, "Commodore_64");
- addPoint(1983, 96, "TRS-80_M4");
- addPoint(1983, 7.6704, "Vax_11/750");
- addPoint(1984, 104.208, "Macintosh-128K");
- addPoint(1984, 5.6613, "Vax_11/785");
- addPoint(1985, 42.7656, "Cray-2");
- addPoint(1985, 67.63910, "L.Edge_XT-7.16");
- addPoint(1985, 100.74706, "Atari_800XL");
- addPoint(1986, 108.445, "Sun-3");
- addPoint(1986, 32.62872, "DEC_VAX_8650");
- addPoint(1986, 564.972, "MIT_XT-8");
- addPoint(1987, 456.66667, "Mac_II");
- addPoint(1987, 102.476, "Sun-4");
- addPoint(1988, 239.58042, "Mac-IIx");
- addPoint(1988, 763.15036, "CompuAdd_386-16");
- addPoint(1988, 1002.16327, "PC_Brand_386-25");
- addPoint(1989, 120.77255, "Wang_VS_10000");
- addPoint(1989, 359.07621, "Macintosh_SE30");
- addPoint(1989, 304.98, "Solbourne_5/500");
- addPoint(1990, 193.24719, "Stardent_3000");
- addPoint(1990, 2715.51724, "Dell_320LX");
- addPoint(1990, 638.36255, "Mac_IIfx");
- addPoint(1990, 2386.36364, "Amiga_3000");
- addPoint(1991, 5205.46154, "Gateway-486DX2/66");
- addPoint(1991, 4212.52941, "ACT_468/33");
- addPoint(1991, 4381.32768, "Mac-Quadra-900");
- addPoint(1992, 6238.07143, "AST_Bravo");
- addPoint(1992, 3588.1, "IBM_PS/2_55-041");
- addPoint(1992, 3074.70833, "NEC_Powermate");
- addPoint(1993, 5053.25, "IBM_Valuepoint");
- addPoint(1993, 8861.85714, "Acer_Power");
- addPoint(1993, 3989.72414, "DECpc_LPv");
- addPoint(1994, 10367.5, "IBM_433/DX/Si");
- addPoint(1994, 11583, "Gateway_2000_486");
- addPoint(1994, 24663.67713, "PowerMac_7100/66");
- addPoint(1995, 33083.27082, "PowerMac_8500/120");
- addPoint(1995, 27741.08322, "PowerMac_9500/132");
- addPoint(1995, 25725, "Intel_Xpress/60");
- addPoint(1996, 34822, "Gateway_P5-75");
- addPoint(1996, 68922.61002, "Power_Tower_180e");
- addPoint(1996, 40386.79560, "PowerMac_7600/132");
- addPoint(1997, 91861.64802, "Gateway_G6-200");
- addPoint(1997, 116100, "Power_Center_210");
- addPoint(1997, 193500, "Mac_G3/266");
- addPoint(1998, 272076.92308, "iMac_G3/233");
- addPoint(1998, 165933.33333, "AcerPower8000/450B");
- addPoint(1998, 222130.43478, "Mac_G3/333");
- addPoint(1999, 301500, "Pentium_II/455");
- addPoint(1999, 263712, "Pentium_III/500");
- addPoint(1999, 275289.6, "Mac_G4/450");
- addPoint(2000, 75545.45455, "IBM_ASCI_White");
- addPoint(2000, 16620000.0, "Sony_Playstation_II");
- addPoint(2000, 356142.85714, "Mac_G4/500_dual");
- addPoint(2001, 392840, "CerfCube");
- addPoint(2001, 444080, "Mac_G4/867");
- addPoint(2001, 945093.33333, "Dell_Workst_340/2G");
- addPoint(2002, 596750, "iMac_G4/700");
- addPoint(2002, 1562400, "Dell_Workst_340/2.5");
- addPoint(2002, 1198997.33333, "Athlon_XP_2.6GHz");
- addPoint(2003, 1108750, "Mac_G4/Dual-1.25GHz");
- addPoint(2003, 1574957.2, "Dell_D_8300_P4/3.0");
- addPoint(2003, 1878666, "Mac_G5/Dual-2.0");
- addPoint(2004, 3871750, "Dell_P4-530_3.0");
- addPoint(2004, 2602857.14286, "Mac_G5/Dual-2.5");
- addPoint(2004, 3036666.66667, "VAtech_SysX_2.3G");
- addPoint(2004, 3097400, "Athlon64_FX55-2.6");
- addPoint(2005, 3485400, "Mac_Mini_G4-1.25");
- addPoint(2005, 4396000, "Opteron_252-2.6");
- addPoint(2005, 5382857.14286, "Mac_G5/Quad-2.5");
- addPoint(2006, 8576470.58824, "iMac-Core_Duo_2.0x2");
- addPoint(2006, 11664000, "Mac_Pro_Xeon_2.66x4");
- addPoint(2006, 10935000, "Mac_Mini_Duo_1.83x2");
- addPoint(2007, 12500000, "Mac_Pro/2_3GHzx8");
- addPoint(2007, 10000000, "Sun_Blackbox");
- addPoint(2007, 10769230.76923, "IBM_Blue_Gene/P");
- }
-
- private void addPoint(int year, double flopsPerDollar, String name) {
- points.add(new SimplePoint(year, Math.log10(flopsPerDollar)));
- }
-
- public final Collection<SimplePoint> points;
-
-}
diff --git a/java/src/org/singinst/uf/model/MooresLawNodeMetadataContentsFactory.java b/java/src/org/singinst/uf/model/MooresLawNodeMetadataContentsFactory.java deleted file mode 100644 index 98224bc..0000000 --- a/java/src/org/singinst/uf/model/MooresLawNodeMetadataContentsFactory.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.singinst.uf.presenter.HtmlUtil;
-import org.singinst.uf.presenter.ScalarValuePointList;
-import org.singinst.uf.presenter.LineBounds;
-
-class MooresLawNodeMetadataContentsFactory {
- private final List<MooreAsymptote> asymptotes = new ArrayList<MooreAsymptote>();
- private final List<ScalarSchema> scalarSchemata = new ArrayList<ScalarSchema>();
- private final List<ScalarValueHolder> scalarValueHolders = new ArrayList<ScalarValueHolder>();
- private final ScalarRelation relation;
-
- public MooresLawNodeMetadataContentsFactory(Node node) {
- LineBounds yearDomain = new LineBounds(1950, 2070);
- Axis year = new Axis(yearDomain);
- Axis flopsPerDollar = new Axis(new LineBounds(-4, 18, true));
-
- int asymptoteLowerBound = 8;
- for (NotablePercentile percentile : NotablePercentile.values()) {
- LineBounds asymptoteRange = new LineBounds(asymptoteLowerBound, 18);
- MooreAsymptote asymptote = new MooreAsymptote(node, yearDomain, asymptoteRange, percentile);
- asymptotes.add(asymptote);
- scalarSchemata.add(asymptote.getScalar());
- scalarValueHolders.add(asymptote.getConjecture());
- asymptoteLowerBound += 2;
- }
- new MooreConstraint(getScalars()).constrain();
-
- relation = new ScalarRelation(year, flopsPerDollar, MooresLawData.getInstance().points) {
-
- public List<? extends ConclusionReportGenerator> getConclusionGenerators() {
- return Collections.singletonList(new ConclusionReportGenerator() {
-
- public String getText(ScalarValueHolder scalarValueHolder, double value) {
- return "The limiting value of log(FLOPS/dollar) has a 90% chance of being between " +
- HtmlUtil.green(getScalars().get(0).getScalarValueHolder().getValue()) +
- " and " + HtmlUtil.red(getScalars().get(2).getScalarValueHolder().getValue());
- }
-
- });
- }
-
- public List<ScalarValueHolder> getScalarValues() {
- return scalarValueHolders;
- }
-
- @Override
- public List<ScalarValuePointList> getPointLists() {
- List<ScalarValuePointList> retVal = new ArrayList<ScalarValuePointList>();
- for (MooreAsymptote asymptote : asymptotes) {
- retVal.addAll(asymptote.getPointLists());
- }
- return retVal;
- }
- };
-
- }
- public ScalarRelation getRelation() {
- return relation;
- }
- public List<ScalarSchema> getScalars() {
- return scalarSchemata;
- }
-}
diff --git a/java/src/org/singinst/uf/model/MultiplicationCalculation.java b/java/src/org/singinst/uf/model/MultiplicationCalculation.java deleted file mode 100644 index 5fcfa0a..0000000 --- a/java/src/org/singinst/uf/model/MultiplicationCalculation.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.List;
-import org.singinst.uf.presenter.HtmlUtil;
-
-import org.singinst.uf.common.StringUtil;
-
-public class MultiplicationCalculation extends Calculation {
-
- private final Evaluable[] calculationArray;
-
- public MultiplicationCalculation(String description,
- Evaluable... calculationArray) {
- super(description, false);
- this.calculationArray = calculationArray;
- }
-
- @Override
- public double rawEvaluate(StringBuilder htmlConsole) {
- double retVal = 1;
- List<String> readableSubCalculationResultList = new ArrayList<String>();
- for (Evaluable subCalculation : calculationArray) {
- double subCalculationResult = subCalculation.evaluate(htmlConsole);
- retVal *= subCalculationResult;
- String str = HtmlUtil.htmlcolorFromColor(((Calculation)subCalculation).getColor(), "" + subCalculationResult);
- readableSubCalculationResultList.add(str);
- }
- htmlConsole.append(getDescription() + " = " + StringUtil.join(" * ", readableSubCalculationResultList));
- return retVal;
- }
-
-
-}
diff --git a/java/src/org/singinst/uf/model/NeedsCalcCache.java b/java/src/org/singinst/uf/model/NeedsCalcCache.java deleted file mode 100644 index 6371e47..0000000 --- a/java/src/org/singinst/uf/model/NeedsCalcCache.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class NeedsCalcCache {
-
- public Map<ScalarValueHolder, Boolean> cache = new HashMap<ScalarValueHolder, Boolean>();
-
- public boolean needsCalc(ScalarValueHolder scalarValueHolder) {
- Boolean needsCalc = cache.get(scalarValueHolder);
- if (needsCalc == null) {
- needsCalc = scalarValueHolder.needsCalc(this);
- cache.put(scalarValueHolder, needsCalc);
- }
- return needsCalc;
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/NeuromorphicAiRelation.java b/java/src/org/singinst/uf/model/NeuromorphicAiRelation.java deleted file mode 100644 index 9e3851a..0000000 --- a/java/src/org/singinst/uf/model/NeuromorphicAiRelation.java +++ /dev/null @@ -1,140 +0,0 @@ -package org.singinst.uf.model;
-
-import java.awt.Color;
-import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-
-public class NeuromorphicAiRelation extends YearwiseCalculationRelation {
-
- public NeuromorphicAiRelation(Node node) {
- super(node);
- }
-
- @Override
- protected Calculation getCalculation(final double year) {
- Calculation agiPossible =
- probabilityAiIsPossible();
- Calculation sufficientHardware =
- new Calculation("Probability of sufficient hardware in " + (int) year) {
-
- protected double rawEvaluate(StringBuilder htmlConsole) {
- return probabilityOfSufficientHardware(year);
- }
-
- @Override
- public Color getColor(){
- return Color.BLUE;
- }
- };
- Calculation sufficientBrainImaging = probabilityOfSufficientBrainImaging(year);
- return new MultiplicationCalculation(
- "Probability of a neuromorphic AI on or before " + (int) year,
- agiPossible,
- sufficientHardware,
- sufficientBrainImaging
- );
- }
-
- private Calculation probabilityOfSufficientBrainImaging(final double year) {
- return new CumulativeNormalDistributionCalculation(
- "'Probability of sufficient brain imaging in " + year + "'",
- ScalarValueHolder.findById(NodeIDString.Q1_5, ScalarSubIDString.MEAN),
- ScalarValueHolder.findById(NodeIDString.Q1_5, ScalarSubIDString.STD_DEV),
- Math.log10(year - ModelUtil.ANCHOR_FAR_YEAR),
- Color.RED);
- }
-
- private double probabilityOfSufficientHardware(double year) {
- double unboundedLogFlopsPerDollarForYear = MooreAsymptote.unboundedLnFlopsPerDollarAtYear(year);
- double meanLogComputingEfficiencyNeeded = meanComputingEfficiencyNeeded() * Math.log(10);
- double stdDevLogComputingEfficiencyNeeded = stdDevComputingEfficiencyNeeded() * Math.log(10);
- double muX = muX() * Math.log(10);
- double sigmaX = sigmaX() * Math.log(10);
-
- double numerator = 0;
- double denominator = 0;
- double z;
- org.singinst.uf.common.LogUtil.info(String.format("probabilityOfSufficientHardware called at year %5g, time %20.15g", (double)year, ((double) System.currentTimeMillis()) / 1000));
- if (meanLogComputingEfficiencyNeeded + 10.0 * stdDevLogComputingEfficiencyNeeded > unboundedLogFlopsPerDollarForYear) {
- /* brute force midpoint integral, hope for Gaussian Euler-Maclaurin edge term suppression */
- double logComputingEfficiency;
- for (int s = -100; s <= 100; s += 1) {
- z = (double)s/10;
- double slice = Math.exp(-0.5 * z * z);
- logComputingEfficiency = h(muX + sigmaX * z, unboundedLogFlopsPerDollarForYear);
- numerator += slice * MathUtil.cumulativeNormalDistribution(meanLogComputingEfficiencyNeeded, stdDevLogComputingEfficiencyNeeded, logComputingEfficiency);
- denominator += slice;
-// org.singinst.uf.common.LogUtil.info(String.format("at year %5g, z = %+8g (x = %+12.7g) d = %10g, num = %g, denom = %g", (double)year, z, sigmaX() * z, d(sigmaX() * z + muX(), year), numerator, denominator));
- }
- org.singinst.uf.common.LogUtil.info(String.format("needed = %8g +/- %8g, bound = %8g +/- %8g, unlimited = %8g", meanLogComputingEfficiencyNeeded, stdDevLogComputingEfficiencyNeeded, muX, sigmaX, unboundedLogFlopsPerDollarForYear));
- } else {
- double logComputingEfficiencyUpperBoundMinimum;
- for (int s = -100; s <= 100; s += 1) {
- z = (double)s/10;
- double slice = Math.exp(-0.5 * z * z);
- logComputingEfficiencyUpperBoundMinimum = hinv(meanLogComputingEfficiencyNeeded + stdDevLogComputingEfficiencyNeeded * z, unboundedLogFlopsPerDollarForYear);
- numerator += slice * MathUtil.cumulativeNormalDistribution(-muX, sigmaX, -logComputingEfficiencyUpperBoundMinimum);
- denominator += slice;
- }
- org.singinst.uf.common.LogUtil.info(String.format("bound = %8g +/- %8g, minimum = %8g +/- %8g, unlimited = %8g", muX, sigmaX, meanLogComputingEfficiencyNeeded, stdDevLogComputingEfficiencyNeeded, unboundedLogFlopsPerDollarForYear));
- }
- org.singinst.uf.common.LogUtil.info(String.format("probabilityOfSufficientHardware called at year %5g, time %20.15g, result %20.16g", (double)year, ((double) System.currentTimeMillis()) / 1000, numerator / denominator));
- return numerator / denominator;
- }
-
- private double meanComputingEfficiencyNeeded() {
- // flops divided by dollars available
- return getDependency().value(NodeIDString.Q1_3, ScalarSubIDString.MEAN) -
- getDependency().value(NodeIDString.Q1_4, ScalarSubIDString.MEAN);
- }
-
- private double stdDevComputingEfficiencyNeeded() {
- double stdDev1_3 = getDependency().value(NodeIDString.Q1_3, ScalarSubIDString.STD_DEV);
- double stdDev1_4 = getDependency().value(NodeIDString.Q1_4, ScalarSubIDString.STD_DEV);
- return Math.sqrt(
- stdDev1_3 * stdDev1_3 + stdDev1_4 * stdDev1_4);
- }
-
- /**
- * sum conjugated with logarithm, conjugated with negation
- * @param hypothetical log hardware production efficiency upper bound
- * @param hypothetical log hardware production efficiency if no upper bound
- * @return hypothetical log hardware production efficiency after effects of upper bound
- */
- static double h(double x, double unboundedLogFlopsPerDollarForYear) {
- //return Math.log(exp(k) * exp(unboundedLogFlopsPerDollarForYear) / (exp(k) + exp(unboundedLogFlopsPerDollarForYear)));
- if (x > unboundedLogFlopsPerDollarForYear) {
- return unboundedLogFlopsPerDollarForYear - Math.log1p(Math.exp(unboundedLogFlopsPerDollarForYear - x));
- } else {
- return x - Math.log1p(Math.exp(x - unboundedLogFlopsPerDollarForYear));
- }
- }
-
- /**
- *
- * @param hypothetical log hardware production efficiency after effects of upper bound
- * @param hypothetical log hardware production efficiency if no upper bound
- * @return hypothetical log hardware production efficiency upper bound
- */
- static double hinv(double h, double unboundedLogFlopsPerDollarForYear) {
- if (h >= unboundedLogFlopsPerDollarForYear) {
- return Double.POSITIVE_INFINITY;
- } else if ((h + Math.log(2)) >= unboundedLogFlopsPerDollarForYear) {
- return unboundedLogFlopsPerDollarForYear - Math.log(Math.expm1(unboundedLogFlopsPerDollarForYear-h));
- } else {
- return h - Math.log1p(-Math.exp(h-unboundedLogFlopsPerDollarForYear));
- }
- }
-
- private double muX() {
- return getDependency().value(
- NodeIDString.Q1_2, ScalarSubIDString.K50);
- }
-
- private double sigmaX() {
- return (muX() - getDependency().value(
- NodeIDString.Q1_2, ScalarSubIDString.K5)) / MathUtil.NINETY_FIVE_PERCENTILE;
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/Node.java b/java/src/org/singinst/uf/model/Node.java deleted file mode 100644 index 947a046..0000000 --- a/java/src/org/singinst/uf/model/Node.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.List;
-
-public class Node {
-
- private final String idString;
- private final List<NodeMetadata> dependencies;
-
- public Node(String name, List<NodeMetadata> dependencies) {
- this.idString = name;
- this.dependencies = dependencies;
-
- }
-
- public String getIdString() {
- return idString;
- }
-
- public List<NodeMetadata> getDependencies() {
- return dependencies;
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/NodeIDString.java b/java/src/org/singinst/uf/model/NodeIDString.java deleted file mode 100644 index 314a51d..0000000 --- a/java/src/org/singinst/uf/model/NodeIDString.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.singinst.uf.model;
-
-public class NodeIDString {
- public static final String Q1_1 = "Q1";
- public static final String Q1_2 = "Q2";
- public static final String Q1_3 = "Q3";
- public static final String Q1_4 = "Q4";
- public static final String Q1_5 = "Q5";
- public static final String C1_5 = "A5";
- public static final String Q1_6 = "Q6";
- public static final String C1_6 = "A6";
- public static final String Q1_7 = "Q7";
- public static final String Q1_8 = "Q8";
- public static final String C1_8 = "A8";
- public static final String Q1_9_1 = "Q9-1";
- public static final String Q1_9_2 = "Q9-2";
- public static final String Q1_9_3 = "Q9-3";
- public static final String Q1_9_4 = "Q9-4";
- public static final String Q1_9_5 = "Q9-5";
- public static final String C1_9 = "A9";
- public static final String C1_10 = "A10";
-}
diff --git a/java/src/org/singinst/uf/model/NodeMetadata.java b/java/src/org/singinst/uf/model/NodeMetadata.java deleted file mode 100644 index 9152b47..0000000 --- a/java/src/org/singinst/uf/model/NodeMetadata.java +++ /dev/null @@ -1,68 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-
-public class NodeMetadata {
- private final Node node;
- private final UiText uiText;
- private final List<ScalarSchema> scalarSchemata;
- private final List<ScalarSchema> simpleScalars; // never used
- private final List<ScalarRelation> scalarRelations;
- private final List<ScalarValueHolder> scalarValueHolders;
-
- public NodeMetadata(Node node, UiText uiText, List<ScalarSchema> scalarSchemata, List<ScalarSchema> simpleScalars, List<ScalarRelation> scalarRelations) {
- this.node = node;
- this.uiText = uiText;
- this.scalarSchemata = scalarSchemata;
- this.simpleScalars = simpleScalars;
- this.scalarRelations = scalarRelations;
- this.scalarValueHolders = new ArrayList<ScalarValueHolder>();
- for (ScalarSchema schema : scalarSchemata) {
- scalarValueHolders.add(schema.getScalarValueHolder());
- }
- }
-
- public List<ScalarSchema> getScalars() {
- return scalarSchemata;
- }
-
- public Node getNode() {
- return node;
- }
-
- public List<ScalarRelation> getScalarRelations() {
- return scalarRelations;
- }
-
- public List<ScalarSchema> getSimpleScalars() {
- return simpleScalars;
- }
-
- public UiText getUserText() {
- return uiText;
- }
-
- public Object monte() {
- if (!simpleScalars.isEmpty()) {
- return simpleScalars.get(0).monte();
- } else if (scalarSchemata.size() == 2) {
- double mean = scalarSchemata.get(0).getScalarValueHolder().getValue();
- double stdDev = scalarSchemata.get(1).getScalarValueHolder().getValue();
- return MathUtil.inverseCumulativeProbability(mean, stdDev, MathUtil.RANDOM.nextFloat());
- } else {
- double k5 = scalarSchemata.get(0).getScalarValueHolder().getValue();
- double k50 = scalarSchemata.get(1).getScalarValueHolder().getValue();
- return MathUtil.inverseCumulativeProbability(
- k50, (k50 - k5) / MathUtil.NINETY_FIVE_PERCENTILE,
- MathUtil.RANDOM.nextFloat());
- }
- }
-
- public List<ScalarValueHolder> getScalarValueHolders() {
- return scalarValueHolders;
- }
-}
diff --git a/java/src/org/singinst/uf/model/NodeMetadataBuilder.java b/java/src/org/singinst/uf/model/NodeMetadataBuilder.java deleted file mode 100644 index 1dd8401..0000000 --- a/java/src/org/singinst/uf/model/NodeMetadataBuilder.java +++ /dev/null @@ -1,113 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.singinst.uf.presenter.LineBounds;
-
-class NodeMetadataBuilder {
- private final Node node;
- private UiText uiText;
- private final List<ScalarSchema> scalarSchemata = new ArrayList<ScalarSchema>();
- private final List<ScalarSchema> simpleScalars = new ArrayList<ScalarSchema>();
- private final List<ScalarRelation> scalarRelations = new ArrayList<ScalarRelation>();
-
- public NodeMetadataBuilder(String name) {
- this(name, Collections.<NodeMetadata>emptyList());
- }
-
- public NodeMetadataBuilder(String name, List<NodeMetadata> dependencies) {
- this(new Node(name, dependencies));
- }
-
- public NodeMetadataBuilder(Node node) {
- this.node = node;
- }
-
- public NodeMetadataBuilder setBuilderUserText(UiText uiText) {
- this.uiText = uiText;
- return this;
- }
-
- public NodeMetadataBuilder buildNodeTypeAsProbability(ConclusionReportGenerator... generators) {
- LineBounds bounds = new LineBounds(0, 100);
- ScalarSchema scalarSchema = new ScalarSchema(node, ScalarSubIDString.PROBABILITY, bounds, "%", "Probability: ", "", bounds, true);
- scalarSchema.getConclusionGenerators().addAll(Arrays.asList(generators));
- scalarSchemata.add(scalarSchema);
- simpleScalars.add(scalarSchema);
- return this;
- }
-
- public NodeMetadata build() {
- return new NodeMetadata(node, uiText, scalarSchemata, simpleScalars, scalarRelations);
- }
-
- public NodeMetadataBuilder buildNodeTypeAsMooresLaw() {
- MooresLawNodeMetadataContentsFactory mooresLawNodeMetadataContentsFactory = new MooresLawNodeMetadataContentsFactory(node);
- scalarSchemata.addAll(mooresLawNodeMetadataContentsFactory.getScalars());
- scalarRelations.add(mooresLawNodeMetadataContentsFactory.getRelation());
- return this;
- }
-
- public NodeMetadataBuilder buildNodeTypeAsHazardRate() {
- HazardRateNodeMetadataContentsFactory hazardRateNodeMetadataContentsFactory = new HazardRateNodeMetadataContentsFactory(node);
- scalarSchemata.addAll(hazardRateNodeMetadataContentsFactory.getScalars());
- scalarRelations.add(hazardRateNodeMetadataContentsFactory.getRelation());
- return this;
- }
-
- public NodeMetadataBuilder buildNodeTypeAsGeneLearning() {
- GeneLearningNodeMetadataContentsFactory geneLearningNodeMetadataContentsFactory = new GeneLearningNodeMetadataContentsFactory(node);
- scalarSchemata.addAll(geneLearningNodeMetadataContentsFactory.getScalarSchemata());
- scalarRelations.add(geneLearningNodeMetadataContentsFactory.getRelation());
- return this;
- }
-
- public NodeMetadataBuilder buildNodeTypeAsOtherIa() {
- OtherIaNodeMetadataContentsFactory otherIaNodeMetadataPartialPrototype = new OtherIaNodeMetadataContentsFactory(node);
- scalarSchemata.addAll(otherIaNodeMetadataPartialPrototype.getScalars());
- scalarRelations.add(otherIaNodeMetadataPartialPrototype.getRelation());
- return this;
- }
-
- public NodeMetadataBuilder buildNodeTypeAsResearcher() {
- ResearchersNodeMetadataContentsFactory researchersNodeMetadataContentsFactory = new ResearchersNodeMetadataContentsFactory(node);
- scalarSchemata.addAll(researchersNodeMetadataContentsFactory.getScalars());
- scalarRelations.add(researchersNodeMetadataContentsFactory.getRelation());
- return this;
- }
-
- public NodeMetadataBuilder buildNodeTypeAsLogNormal(String units, double lowerBound, double upperBound) {
- NormalNodeMetadataContentsFactory logNormal = new NormalNodeMetadataContentsFactory(node, units, new LineBounds(lowerBound, upperBound, true), "");
- scalarSchemata.addAll(logNormal.getScalars());
- scalarRelations.add(logNormal.getRelation());
- return this;
- }
-
- public NodeMetadataBuilder buildNodeTypeAsYearLogNormal(int firstMajorTick, int boundaryYear, int lowerYear, int upperYear) {
- double lowerBound = Math.log10(lowerYear - boundaryYear);
- double upperBound = Math.log10(upperYear - boundaryYear);
- int majorTickSpace = upperYear == ModelUtil.LATEST_IA_YEAR ? 5 : 50;
- LineBounds bounds = new LogBounds(firstMajorTick, boundaryYear, lowerBound, upperBound, majorTickSpace, 10);
- //NormalNodeMetadataContentsFactory yearNormal = new NormalNodeMetadataContentsFactory(node, "(log) years after " + boundaryYear, bounds) {
- NormalNodeMetadataContentsFactory yearNormal = new NormalNodeMetadataContentsFactory(node, "years after " + boundaryYear, bounds, "10 to the") {
-
- @Override
- protected String meanUnits() {
- return "year";
- }
-
- };
- scalarSchemata.addAll(yearNormal.getScalars());
- scalarRelations.add(yearNormal.getRelation());
- return this;
- }
-
- public NodeMetadataBuilder addScalarRelation(ScalarRelation relation) {
- scalarRelations.add(relation);
- return this;
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/NodeMetadataFactory.java b/java/src/org/singinst/uf/model/NodeMetadataFactory.java deleted file mode 100644 index 07ce10c..0000000 --- a/java/src/org/singinst/uf/model/NodeMetadataFactory.java +++ /dev/null @@ -1,194 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.singinst.uf.presenter.NumericEntry;
-
-public class NodeMetadataFactory {
- public static List<NodeMetadata> createTheNetwork() {
- NodeMetadata q1_1 = constructQ1_1Builder().build();
- NodeMetadata q1_2 = constructQ1_2Builder().build();
- NodeMetadata q1_3 = constructQ1_3Builder().build();
- NodeMetadata q1_4 = constructQ1_4Builder().build();
- NodeMetadata q1_5 = constructQ1_5Builder().build();
- NodeMetadata c1_5 = constructC1_5Builder(Arrays.asList(q1_1, q1_2, q1_3, q1_4, q1_5)).build();
- NodeMetadata q1_6 = constructQ1_6Builder().build();
- NodeMetadata c1_6 = constructC1_6Builder(Arrays.asList(c1_5, q1_6)).build();
- NodeMetadata q1_7 = constructQ1_7Builder().build();
- NodeMetadata q1_8 = constructQ1_8Builder().build();
- NodeMetadata c1_8 = constructC1_8Builder(Arrays.asList(q1_7, q1_8)).build();
- NodeMetadata q1_9_1 = constructQ1_9_1Builder().build();
- NodeMetadata q1_9_2 = constructQ1_9_2Builder().build();
- NodeMetadata q1_9_3 = constructQ1_9_3Builder().build();
- NodeMetadata q1_9_4 = constructQ1_9_4Builder().build();
- NodeMetadata q1_9_5 = constructQ1_9_5Builder().build();
- //NodeMetadata c1_9 = constructQ1_9Builder(Arrays.asList(q1_9_1, q1_9_2, q1_9_3, q1_9_4, q1_9_5, c1_6, c1_5)).build();
- NodeMetadata c1_9 = constructQ1_9Builder(Arrays.asList(q1_1, q1_2, q1_3, q1_4, q1_5, q1_9_1, q1_9_2, q1_9_3, q1_9_4, q1_9_5, c1_5, c1_6)).build();
- NodeMetadata c1_10 = constructC1_10Builder(Arrays.asList(c1_8, c1_9)).build();
-
- setNodeScalars(q1_1, 99);
- setNodeScalars(q1_2, 10, 11, 12);
- setNodeScalars(q1_3, 12.5, 2.25);
- setNodeScalars(q1_4, 5, 1);
- //setNodeScalars(q1_5, 2018, 0.005);
- //setNodeScalars(q1_6);
-
- return Arrays.asList(new NodeMetadata[] {
- q1_1,
- q1_2,
- q1_3,
- q1_4,
- q1_5,
- c1_5,
- q1_6,
- c1_6,
- q1_7,
- q1_8,
- c1_8,
- q1_9_1,
- q1_9_2,
- q1_9_3,
- q1_9_4,
- q1_9_5,
- c1_9,
- c1_10
- });
- }
-
- private static void setNodeScalars(NodeMetadata qNotOnly1_1GoesHere, double... dArray) {
- int i = 0;
- for (double d : dArray) {
- ScalarValueHolder scalarValueHolder = qNotOnly1_1GoesHere.getScalars().get(i).getScalarValueHolder();
- scalarValueHolder.setValue(d);
- i++;
- }
-
- }
-
- private static NodeMetadataBuilder constructQ1_1Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_1)
- .setBuilderUserText(UiTextConstant.Q1_1_TEXT)
- .buildNodeTypeAsProbability(new ConclusionReportGenerator() {
-
- public String getText(ScalarValueHolder scalarValueHolder, double value) {
- return "The probability AI is possible in principle is " + NumericEntry.formatAsScalar(value) + "%";
- }
-
- },
- new ConclusionReportGenerator() {
-
- public String getText(ScalarValueHolder scalarValueHolder, double value) {
- return "The probability AI is not possible in principle is " + NumericEntry.formatAsScalar(100 - value) + "%";
- }
-
- });
- }
-
- private static NodeMetadataBuilder constructQ1_2Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_2)
- .setBuilderUserText(UiTextConstant.Q1_2_TEXT)
- .buildNodeTypeAsMooresLaw();
- }
-
- private static NodeMetadataBuilder constructQ1_3Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_3)
- .setBuilderUserText(UiTextConstant.Q1_3_TEXT)
- .buildNodeTypeAsLogNormal("flops", 7, 30);
- }
-
- private static NodeMetadataBuilder constructQ1_4Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_4)
- .setBuilderUserText(UiTextConstant.Q1_4_TEXT)
- .buildNodeTypeAsLogNormal("USD", 2, 11);
- }
-
- private static NodeMetadataBuilder constructQ1_5Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_5)
- .setBuilderUserText(UiTextConstant.Q1_5_TEXT)
- .buildNodeTypeAsYearLogNormal(2050, ModelUtil.ANCHOR_FAR_YEAR, ModelUtil.EARLIEST_FAR_YEAR, ModelUtil.LATEST_FAR_YEAR);
- }
-
- private static NodeMetadataBuilder constructC1_5Builder(List<NodeMetadata> dependencies) {
- Node node = new Node(NodeIDString.C1_5, dependencies);
- return new NodeMetadataBuilder(node)
- .setBuilderUserText(UiTextConstant.C1_5_TEXT)
- .addScalarRelation(new NeuromorphicAiRelation(node));
- }
-
- private static NodeMetadataBuilder constructQ1_6Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_6)
- .setBuilderUserText(UiTextConstant.Q1_6_TEXT)
- .buildNodeTypeAsYearLogNormal(2050, ModelUtil.ANCHOR_FAR_YEAR, ModelUtil.EARLIEST_FAR_YEAR, ModelUtil.LATEST_FAR_YEAR);
- }
-
- private static NodeMetadataBuilder constructC1_6Builder(List<NodeMetadata> dependencies) {
- Node node = new Node(NodeIDString.C1_6, dependencies);
- return new NodeMetadataBuilder(node)
- .setBuilderUserText(UiTextConstant.C1_6_TEXT)
- .addScalarRelation(new AiRelation(node));
- }
-
- private static NodeMetadataBuilder constructQ1_7Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_7)
- .setBuilderUserText(UiTextConstant.Q1_7_TEXT)
- .buildNodeTypeAsHazardRate();
- }
-
- private static NodeMetadataBuilder constructQ1_8Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_8)
- .setBuilderUserText(UiTextConstant.Q1_8_TEXT)
- .buildNodeTypeAsHazardRate();
- }
-
- private static NodeMetadataBuilder constructC1_8Builder(List<NodeMetadata> dependencies) {
- Node node = new Node(NodeIDString.C1_8, dependencies);
- return new NodeMetadataBuilder(node)
- .setBuilderUserText(UiTextConstant.C1_8_TEXT)
- .addScalarRelation(new CumulativeHazardsRelation(node));
- }
-
- private static NodeMetadataBuilder constructQ1_9_1Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_9_1)
- .setBuilderUserText(UiTextConstant.Q1_9_1_TEXT)
- .buildNodeTypeAsYearLogNormal(2010, ModelUtil.ANCHOR_FAR_YEAR, ModelUtil.EARLIEST_IA_YEAR, ModelUtil.LATEST_IA_YEAR);
- }
-
- private static NodeMetadataBuilder constructQ1_9_2Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_9_2)
- .setBuilderUserText(UiTextConstant.Q1_9_2_TEXT)
- .buildNodeTypeAsYearLogNormal(2010, ModelUtil.ANCHOR_FAR_YEAR, ModelUtil.EARLIEST_IA_YEAR, ModelUtil.LATEST_IA_YEAR);
- }
-
- private static NodeMetadataBuilder constructQ1_9_3Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_9_3)
- .setBuilderUserText(UiTextConstant.Q1_9_3_TEXT)
- .buildNodeTypeAsGeneLearning();
- }
-
- private static NodeMetadataBuilder constructQ1_9_4Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_9_4)
- .setBuilderUserText(UiTextConstant.Q1_9_4_TEXT)
- .buildNodeTypeAsResearcher();
- }
-
- private static NodeMetadataBuilder constructQ1_9_5Builder() {
- return new NodeMetadataBuilder(NodeIDString.Q1_9_5)
- .setBuilderUserText(UiTextConstant.Q1_9_5_TEXT)
- .buildNodeTypeAsOtherIa();
- }
-
- private static NodeMetadataBuilder constructQ1_9Builder(List<NodeMetadata> dependencies) {
- Node node = new Node(NodeIDString.C1_9, dependencies);
- return new NodeMetadataBuilder(node)
- .setBuilderUserText(UiTextConstant.C1_9_TEXT)
- .addScalarRelation(new RescheduledEventsRelation(node));
- }
-
- private static NodeMetadataBuilder constructC1_10Builder(List<NodeMetadata> dependencies) {
- Node node = new Node(NodeIDString.C1_10, dependencies);
- return new NodeMetadataBuilder(node)
- .setBuilderUserText(UiTextConstant.C1_10_TEXT)
- .addScalarRelation(new DisruptionRelation(node));
- }
-}
diff --git a/java/src/org/singinst/uf/model/NormalConstraint.java b/java/src/org/singinst/uf/model/NormalConstraint.java deleted file mode 100644 index 5ab2585..0000000 --- a/java/src/org/singinst/uf/model/NormalConstraint.java +++ /dev/null @@ -1,88 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.List;
-
-public class NormalConstraint {
- private final double lowerBound;
- private final List<ScalarSchema> scalarSchemata;
- private boolean disable;
-
- public NormalConstraint(List<ScalarSchema> scalarSchemata, double lowerBound) {
- this.scalarSchemata = scalarSchemata;
- this.lowerBound = lowerBound;
- }
-
- private final ValueListener leftAnchorListener = new MooreUpdateListener() {
- void adjust() {
- getRightConjecture().setValue(extrapolate(getLeftConjecture(), getMiddleConjecture()));
- }
- };
-
- private final ValueListener rightAnchorListener = new MooreUpdateListener() {
- void adjust() {
- getLeftConjecture().setValue(extrapolate(getRightConjecture(), getMiddleConjecture()));
- }
- };
-
- public void constrain() {
- getLeftConjecture().addUpdateListener(leftAnchorListener);
- getMiddleConjecture().addUpdateListener(leftAnchorListener);
- getRightConjecture().addUpdateListener(rightAnchorListener);
- }
-
- protected double extrapolate(ScalarValueHolder firstConjecture,
- ScalarValueHolder secondConjecture) {
- return secondConjecture.getValue() * 2 - firstConjecture.getValue();
- }
-
- private ScalarValueHolder getConjecture(int i) {
- return scalarSchemata.get(i).getScalarValueHolder();
- }
-
- private ScalarValueHolder getLeftConjecture() {
- return getConjecture(0);
- }
-
- private ScalarValueHolder getMiddleConjecture() {
- return getConjecture(1);
- }
-
- private ScalarValueHolder getRightConjecture() {
- return getConjecture(2);
- }
-
- private abstract class MooreUpdateListener implements ValueListener {
-
- public void fireUpdate(double value) {
- if (!disable) {
- disable = true;
- try {
- adjust();
- fixLeftToRight();
- } finally {
- disable = false;
- }
- }
- }
-
- abstract void adjust();
-
- private void fixLeftToRight() {
- double left = getLeftConjecture().getValue();
- double right = getRightConjecture().getValue();
- if (left > right) {
- getLeftConjecture().setValue(right);
- getRightConjecture().setValue(left);
- }
- if (getLeftConjecture().getValue() < lowerBound) {
- if (getMiddleConjecture().getValue() < lowerBound) {
- getMiddleConjecture().setValue(lowerBound);
- }
- getLeftConjecture().setValue(lowerBound);
- getRightConjecture().setValue(extrapolate(getLeftConjecture(), getMiddleConjecture()));
- }
- }
-
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/NormalNodeMetadataContentsFactory.java b/java/src/org/singinst/uf/model/NormalNodeMetadataContentsFactory.java deleted file mode 100644 index 14f06f3..0000000 --- a/java/src/org/singinst/uf/model/NormalNodeMetadataContentsFactory.java +++ /dev/null @@ -1,154 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.ClickableCurve;
-import org.singinst.uf.presenter.HtmlUtil;
-import org.singinst.uf.presenter.ScalarValuePointList;
-import org.singinst.uf.presenter.LineBounds;
-import org.singinst.uf.presenter.MouseClickListener;
-import org.singinst.uf.presenter.SimpleLine;
-import org.singinst.uf.presenter.SimpleStyle;
-
-public class NormalNodeMetadataContentsFactory implements MouseClickListener {
-
- private final Collection<ScalarSchema> scalarSchemata = new ArrayList<ScalarSchema>();
- private final List<ScalarValueHolder> scalarValueHolders = new ArrayList<ScalarValueHolder>();
-
- private final ScalarValuePointList curvePointList = new ClickableCurve(this);
- private final ScalarValuePointList pointList5 = new ScalarValuePointList(new SimpleStyle(SimpleColor.GREEN));
- private final ScalarValuePointList pointList50 = new ScalarValuePointList(new SimpleStyle(SimpleColor.BLACK));
- private final ScalarValuePointList pointList95 = new ScalarValuePointList(new SimpleStyle(SimpleColor.RED));
-
- private final ScalarRelation relation;
- private final ScalarSchema mean;
- //private final ScalarSchema median;
- private final ScalarSchema stdDev;
- private final String normalUnits;
-
- public NormalNodeMetadataContentsFactory(Node node, String units, final LineBounds meanBounds, String stdSuffix) {
- String powerStr = meanBounds.displayAsLog() ? " 10 to the " : " ";
- // if we are not displaying as log, it is going to be 'year', so add an 's'
- String plural = meanBounds.displayAsLog() ? "" : "s";
-
- this.normalUnits = units;
- mean = new ScalarSchema(node, ScalarSubIDString.MEAN, meanBounds, meanUnits(), "The median value is " + powerStr, plural, meanBounds, true);
- double maxStdDev = meanBounds.getLength() / 10;
- stdDev = new ScalarSchema(node, ScalarSubIDString.STD_DEV, new LineBounds(0, maxStdDev), units, "std dev is " + stdSuffix + powerStr, "", new LineBounds(0, maxStdDev * 100), true);
- Axis vertical = new Axis(new LineBounds(0, 5 / maxStdDev), false);
- Axis horizontal = new Axis(meanBounds);
- scalarSchemata.add(mean);
- scalarSchemata.add(stdDev);
- scalarValueHolders.add(mean.getScalarValueHolder());
- scalarValueHolders.add(stdDev.getScalarValueHolder());
-
- relation = new ScalarRelation(horizontal, vertical) {
-
- @Override
- public List<ScalarValuePointList> getPointLists() {
- List<SimplePoint> pointSamples = new ArrayList<SimplePoint>();
- Iterable<Double> samples =
- meanBounds.getVisualSamples(5001, mean.getScalarValueHolder().getValue(), Arrays.asList(getPercentile5(), getPercentile95()));
- for (double x : samples) {
- pointSamples.add(new SimplePoint(x, yFromX(x)));
- }
- curvePointList.setHypothesisPoints(pointSamples);
-
- pointList5.setHypothesisPoints(verticalLine(getPercentile5()));
- pointList50.setHypothesisPoints(verticalLine(mean.getScalarValueHolder().getValue()));
- pointList95.setHypothesisPoints(verticalLine(getPercentile95()));
-
- List<ScalarValuePointList> retVal = Arrays.asList(curvePointList, pointList5, pointList50, pointList95);
- for (ScalarValuePointList scalarValuePointList : retVal) {
- List<SimplePoint> filteredList = new ArrayList<SimplePoint>();
- for (SimplePoint simplePoint : scalarValuePointList.getHypothesisPoints()) {
- double x = simplePoint.x;
- if (x >= meanBounds.getFirst() && x <= meanBounds.getSecond()) {
- filteredList.add(simplePoint);
- }
- }
- scalarValuePointList.setHypothesisPoints(filteredList);
- }
- return retVal;
- }
-
- private List<SimplePoint> verticalLine(double x) {
- SimpleLine line = SimpleLine.vertical(x, 0, yFromX(x));
- return Arrays.asList(line.p1, line.p2);
- }
-
- public List<? extends ConclusionReportGenerator> getConclusionGenerators() {
- return Collections.singletonList(new ConclusionReportGenerator() {
- public String getText(ScalarValueHolder scalarValueHolder, double value) {
- boolean power = meanBounds.displayAsLog();
- // if we are not displaying as log, it is going to be 'year', so add an 's'
- String plural = power ? "" : "s";
- String str = "There is a 90% chance of being between ";
- if (power){
- str += HtmlUtil.green("10 <sup>" + mean.getBounds().userFormat(getPercentile5()) + "</sup>") +
- " and " +
- HtmlUtil.red("10 <sup>" + mean.getBounds().userFormat(getPercentile95()) + "</sup>") + " " + meanUnits() + plural;
- }
- else {
- str += HtmlUtil.green(mean.getBounds().userFormat(getPercentile5())) + " and " +
- HtmlUtil.red(mean.getBounds().userFormat(getPercentile95())) + " " + meanUnits() + plural;
- }
-
- return str;
- }
- });
- }
-
- public List<ScalarValueHolder> getScalarValues() {
- return scalarValueHolders;
- }
-
- };
- }
-
- private Double getPercentile5() {
- return mean.getScalarValueHolder().getValue() - MathUtil.NINETY_FIVE_PERCENTILE * stdDev.getScalarValueHolder().getValue();
- }
-
- private Double getPercentile95() {
- return mean.getScalarValueHolder().getValue() + MathUtil.NINETY_FIVE_PERCENTILE * stdDev.getScalarValueHolder().getValue();
- }
-
- protected double yFromX(double x) {
- double meanValue = mean.getScalarValueHolder().getValue();
- double stdDevValue = stdDev.getScalarValueHolder().getValue();
- double squaredDistanceFromMean = (meanValue - x) * (meanValue - x);
- double variance = stdDevValue * stdDevValue;
- double functionalY = (1 / Math.sqrt(2 * Math.PI * variance)) * Math.exp(-1 * squaredDistanceFromMean / (2 * variance));
- return functionalY;
- }
-
- public Collection<? extends ScalarSchema> getScalars() {
- return scalarSchemata;
- }
-
- public ScalarRelation getRelation() {
- return relation;
- }
-
- public void mouseClick(SimplePoint point) {
- double newMean = point.x;
- double newDensityAtMean = point.y;
- double newVariance = 1 / (2 * Math.PI * newDensityAtMean * newDensityAtMean);
- stdDev.getScalarValueHolder().setValue(Math.sqrt(newVariance));
- mean.getScalarValueHolder().setValue(newMean);
-
- }
-
- // TODO5 called from constructor
- protected String meanUnits() {
- return normalUnits;
- }
-}
diff --git a/java/src/org/singinst/uf/model/NotablePercentile.java b/java/src/org/singinst/uf/model/NotablePercentile.java deleted file mode 100644 index ff315c7..0000000 --- a/java/src/org/singinst/uf/model/NotablePercentile.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.singinst.uf.model;
-
-import org.singinst.uf.math.MathUtil;
-
-public enum NotablePercentile {
- PERCENTILE5(5, SimpleColor.GREEN, 1, -1 * MathUtil.NINETY_FIVE_PERCENTILE),
- PERCENTILE50(50, SimpleColor.BLACK, 2, 0),
- PERCENTILE95(95, SimpleColor.RED, 1, MathUtil.NINETY_FIVE_PERCENTILE);
-
- private final int value;
- private final SimpleColor color;
- private final int priority;
- private final double offset;
-
- private NotablePercentile(int value, SimpleColor color, int priority, double offset) {
- this.value = value;
- this.color = color;
- this.priority = priority;
- this.offset = offset;
- }
-
- public int getPriority() {
- return priority;
- }
-
- public int getValue() {
- return value;
- }
-
- public SimpleColor getColor() {
- return color;
- }
-
- public double getOffset() {
- return offset;
- }
-
- /**
- * Returns a human readable description of whether or not this is extremely high, mid or extremely low probability.
- *
- * @param adjectiveSmall
- * The adjective to use if it is astonishingly (blank) (5th percentile)
- * @param adjectiveLarge
- * The adjective to use if it is astonishingly (blank) (95th percentile)
- * @return
- * String describing the range this NotablePercentile covers.
- */
- public String getText(String adjectiveSmall, String adjectiveLarge) {
- switch (value) {
- case 5: return "Astonishingly " + adjectiveSmall;// + " (5th percentile)";
- case 50: return "Median";
- case 95: return "Astonishingly " + adjectiveLarge;// + " (95th percentile)";
- default: return "";
- }
- }
-}
diff --git a/java/src/org/singinst/uf/model/OtherIaExtreme.java b/java/src/org/singinst/uf/model/OtherIaExtreme.java deleted file mode 100644 index 431d125..0000000 --- a/java/src/org/singinst/uf/model/OtherIaExtreme.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.singinst.uf.model;
-
-import org.singinst.uf.presenter.HtmlUtil;
-import org.singinst.uf.presenter.LineBounds;
-import org.singinst.uf.presenter.NumericEntry;
-
-public class OtherIaExtreme extends YearExtremeNodeMetadataContentsFactory {
-
- protected OtherIaExtreme(Node node, LineBounds rangeBounds,
- double year) {
- super(node, rangeBounds, year, " log speedup in year " + (int) year , "", "low", "high");
- }
-
- @Override
- public ConclusionReportGenerator getConclusionGenerator() {
- return new ConclusionReportGenerator() {
- public String getText(ScalarValueHolder scalarValueHolder, double value) {
- return "The research speedup in the year " + getYearString() + " has a 90% chance of being between " +
- HtmlUtil.green(display(getScalars().get(0).getScalarValueHolder().getValue())) +
- " and " + HtmlUtil.red(display(getScalars().get(2).getScalarValueHolder().getValue()));
- }
-
- private String display(double value) {
- return NumericEntry.formatAsScalar(Math.pow(10, value)) + "x";
- }
- };
-
- }
-
-
-}
diff --git a/java/src/org/singinst/uf/model/OtherIaNodeMetadataContentsFactory.java b/java/src/org/singinst/uf/model/OtherIaNodeMetadataContentsFactory.java deleted file mode 100644 index f34b1dd..0000000 --- a/java/src/org/singinst/uf/model/OtherIaNodeMetadataContentsFactory.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.ScalarValuePointList;
-import org.singinst.uf.presenter.LineBounds;
-
-public class OtherIaNodeMetadataContentsFactory {
-
- private final YearExtremeNodeMetadataContentsFactory extreme;
- private final List<ScalarSchema> scalarSchemata = new ArrayList<ScalarSchema>();
- private final ScalarRelation relation;
-
- private final List<PercentileDraggableLine> pointLists = new ArrayList<PercentileDraggableLine>();
-
- private final List<ScalarValueHolder> conjectureList = new ArrayList<ScalarValueHolder>();
-
-
- public OtherIaNodeMetadataContentsFactory(Node node) {
- final LineBounds range = new LineBounds(0, 2, true);
- final LineBounds domain = new LineBounds(ModelUtil.EARLIEST_YEAR, ModelUtil.LATEST_YEAR);
- extreme = new OtherIaExtreme(node, range, ModelUtil.LATEST_YEAR);
- scalarSchemata.addAll(extreme.getScalars());
- for (ScalarSchema scalarSchema : scalarSchemata) {
- conjectureList.add(scalarSchema.getScalarValueHolder());
- }
-
- for (final NotablePercentile percentile : NotablePercentile.values()) {
- PercentileDraggableLine pointList = new PercentileDraggableLine(percentile) {
-
- @Override
- public void dragTo(SimplePoint point) {
- OtherIaNodeMetadataContentsFactory.this.dragTo(percentile, point);
- }};
- pointLists.add(pointList);
- }
-
- relation = new ScalarRelation(new Axis(domain), new Axis(range)) {
-
- @Override
- public List<? extends ScalarValuePointList> getPointLists() {
- for (PercentileDraggableLine incidentLine : pointLists) {
- List<SimplePoint> points = new ArrayList<SimplePoint>();
- points.add(new SimplePoint(domain.getFirst(), range.getFirst()));
- points.add(new SimplePoint(extreme.getYear(),
- extreme.getScalarSchema(incidentLine.getPercentile()).getScalarValueHolder().getValue()));
- incidentLine.setHypothesisPoints(points);
- }
- return pointLists;
- }
-
- public List<? extends ConclusionReportGenerator> getConclusionGenerators() {
- List<ConclusionReportGenerator> retVal = new ArrayList<ConclusionReportGenerator>();
- retVal.add(extreme.getConclusionGenerator());
- return retVal;
- }
-
- public List<ScalarValueHolder> getScalarValues() {
- return conjectureList ;
- }
- };
- }
-
- public Collection<? extends ScalarSchema> getScalars() {
- return scalarSchemata;
- }
-
- public ScalarRelation getRelation() {
- return relation;
- }
-
- public void dragTo(NotablePercentile percentile, SimplePoint point) {
- SimplePoint anchorPoint = new SimplePoint(ModelUtil.EARLIEST_YEAR, 0);
- double newExtremeY = MathUtil.interpolate(
- anchorPoint, point, ModelUtil.LATEST_YEAR);
- extreme.getScalarSchema(percentile).getScalarValueHolder().setValue(newExtremeY);
- }
-}
diff --git a/java/src/org/singinst/uf/model/PercentileDraggableLine.java b/java/src/org/singinst/uf/model/PercentileDraggableLine.java deleted file mode 100644 index 977458e..0000000 --- a/java/src/org/singinst/uf/model/PercentileDraggableLine.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.singinst.uf.model;
-
-import org.singinst.uf.presenter.DraggableLine;
-import org.singinst.uf.presenter.SimpleStyle;
-
-public abstract class PercentileDraggableLine extends DraggableLine {
-
- private final NotablePercentile percentile;
-
- public PercentileDraggableLine(NotablePercentile percentile) {
- super(percentile.getPriority(), new SimpleStyle(percentile.getColor()));
- this.percentile = percentile;
- }
-
- public NotablePercentile getPercentile() {
- return percentile;
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/PowerFunction.java b/java/src/org/singinst/uf/model/PowerFunction.java deleted file mode 100644 index b3da4eb..0000000 --- a/java/src/org/singinst/uf/model/PowerFunction.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.singinst.uf.model;
-
-import org.singinst.uf.math.InvertableFunction;
-
-public class PowerFunction extends InvertableFunction {
-
- private final double zero;
-
- public PowerFunction(double zero) {
- this.zero = zero;
- }
-
- @Override
- public double apply(double x) {
- return Math.pow(10, x) + zero;
- }
-
- @Override
- public double invert(double y) {
- return Math.log10(y - zero);
- }
-}
diff --git a/java/src/org/singinst/uf/model/RescheduledEventsRelation.java b/java/src/org/singinst/uf/model/RescheduledEventsRelation.java deleted file mode 100644 index cf7faab..0000000 --- a/java/src/org/singinst/uf/model/RescheduledEventsRelation.java +++ /dev/null @@ -1,235 +0,0 @@ -package org.singinst.uf.model; - -import java.util.ArrayList; -import java.util.List; -import java.util.TreeSet; - -import org.singinst.uf.math.MathUtil; - -public class RescheduledEventsRelation extends CalculationRelation { - - /*@Override - protected Calculation getCalculationForYear(double year) { - // TODO Auto-generated method stub - return null; - }*/ - - public RescheduledEventsRelation(Node node) { - super(node); - } - - - protected Calculation probabilityAiIsPossible() { - return new Calculation("Probability that AGI is possible") { - @Override - protected double rawEvaluate(StringBuilder htmlConsole) { - MathUtil.ScienceSpeedModelParameters scienceSpeedModelParameters = scienceSpeedModel(); - org.singinst.uf.common.LogUtil.info(String.format( - "institutional_base_year: %g\n" - + "institutional_mean_slope_log_factor: %g\n" - + "institutional_stddev_slope_log_factor: %g\n" - + "population_base_year: %g\n" - + "population_mean_log_year: %g\n" - + "population_stddev_log_year: %g\n" - + "population_mean_init_log_rate: %g\n" - + "population_stddev_init_log_rate: %g\n" - + "population_mean_slope_log_rate: %g\n" - + "population_stddev_slope_log_rate: %g\n" - + "sequencedata_base_year: %g\n" - + "sequencedata_mean_log_year: %g\n" - + "sequencedata_stddev_log_year: %g\n" - + "sequencedata_mean_init_log_factor: %g\n" - + "sequencedata_stddev_init_log_factor: %g\n" - + "sequencedata_mean_slope_log_factor: %g\n" - + "sequencedata_stddev_slope_log_factor: %g\n" - , scienceSpeedModelParameters.institutional_base_year - , scienceSpeedModelParameters.institutional_mean_slope_log_factor - , scienceSpeedModelParameters.institutional_stddev_slope_log_factor - , scienceSpeedModelParameters.population_base_year - , scienceSpeedModelParameters.population_mean_log_year - , scienceSpeedModelParameters.population_stddev_log_year - , scienceSpeedModelParameters.population_mean_init_log_rate - , scienceSpeedModelParameters.population_stddev_init_log_rate - , scienceSpeedModelParameters.population_mean_slope_log_rate - , scienceSpeedModelParameters.population_stddev_slope_log_rate - , scienceSpeedModelParameters.sequencedata_base_year - , scienceSpeedModelParameters.sequencedata_mean_log_year - , scienceSpeedModelParameters.sequencedata_stddev_log_year - , scienceSpeedModelParameters.sequencedata_mean_init_log_factor - , scienceSpeedModelParameters.sequencedata_stddev_init_log_factor - , scienceSpeedModelParameters.sequencedata_mean_slope_log_factor - , scienceSpeedModelParameters.sequencedata_stddev_slope_log_factor - )); - return getDependency().value(NodeIDString.Q1_1, ScalarSubIDString.PROBABILITY) / 100; - } - }; - } - - MathUtil.EventDiscreteDistributionSchedule rescheduledProbabilities; - - @Override - protected List<Calculation> getCalculations(final List<Double> years) { - List<Calculation> retVal = new ArrayList<Calculation>(); - for (final double year : years) { - retVal.add(new Calculation("Probability of AI by " + (int) year) { - - @Override - protected double rawEvaluate(StringBuilder htmlConsole) { - if (year == ModelUtil.BASIC_MODEL_YEARS[0]) { - calculate(MathUtil.wrapDoubleArray(ModelUtil.BASIC_MODEL_YEARS)); - } - return MathUtil.expc(rescheduledProbabilities.logitnerp(year).clogProbEvent); - } - }); - } - return retVal; - } - - private void calculate(List<Double> years) { - double[] yearsInOtherCalculations = ModelUtil.BASIC_MODEL_YEARS; - double[] yearsHere = MathUtil.unwrapDoubleList(years); - //new double[years.size()]; - //for (int i=0; i<yearsHere.length; ++i) - // yearsHere[i] = years.get(i); - - TreeSet<Double> beforeYearsSortedSet = new TreeSet<Double>(MathUtil.wrapDoubleArray(yearsInOtherCalculations)); - { - double i = ModelUtil.LATEST_YEAR - ModelUtil.EARLIEST_IA_YEAR; - double factor = - (yearsInOtherCalculations[yearsInOtherCalculations.length-1] - ModelUtil.EARLIEST_IA_YEAR) - / (yearsInOtherCalculations[yearsInOtherCalculations.length-2] - ModelUtil.EARLIEST_IA_YEAR) - ; - i *= factor; - while (i <= ModelUtil.LATEST_UNACCELERATED_YEAR - ModelUtil.EARLIEST_IA_YEAR) { - beforeYearsSortedSet.add(Math.round(i/ModelUtil.YEAR_STEPSIZE)*ModelUtil.YEAR_STEPSIZE + ModelUtil.EARLIEST_IA_YEAR); - i *= factor; - }; - i = ModelUtil.LATEST_YEAR - ModelUtil.EARLIEST_IA_YEAR; - i /= factor; - while (i <= ModelUtil.EARLIEST_YEAR - ModelUtil.EARLIEST_IA_YEAR) { - beforeYearsSortedSet.add(Math.round(i/ModelUtil.YEAR_STEPSIZE)*ModelUtil.YEAR_STEPSIZE + ModelUtil.EARLIEST_IA_YEAR); - i /= factor; - }; - } - - double[] beforeYears = MathUtil.unwrapDoubleList(new ArrayList<Double>(beforeYearsSortedSet)); - - //List<Double> clogPAiWrapped; - - double[] clogPAi; - //clogPAi = MathUtil.unwrapDoubleList(clogPAiWrapped); - clogPAi = new double[beforeYears.length]; - for (int i=0; i<clogPAi.length; ++i) { - // clogPAI[i] = 100; - clogPAi[i] = MathUtil.clog(ScalarValueHolder.findById(NodeIDString.C1_6, ScalarSubIDString.yearProbabilityID(beforeYears[i])).getValue()); - if (clogPAi[i]>300d) clogPAi[i]=300d; - } - MathUtil.EventDiscreteDistributionSchedule s_before = new MathUtil.EventDiscreteDistributionSchedule(); - MathUtil.EventDiscreteDistributionSchedule s_after; - - s_before.time = beforeYears; //ModelUtil.BASIC_MODEL_YEARS; - //s_before.time = java.util.Arrays.copyOf(ModelUtil.BASIC_MODEL_YEARS, yearsInOtherCalculations.length+2); - //s_before.time[yearsInOtherCalculations.length] = ModelUtil.LATEST_YEAR*(1+2*MathUtil.DOUBLE_EPS); - //s_before.time[yearsInOtherCalculations.length+1] = ModelUtil.LATEST_YEAR*(1+4*MathUtil.DOUBLE_EPS); - s_before.clogProbEvent = clogPAi; - //s_before.clogProbEvent = java.util.Arrays.copyOf(clogPAI, yearsInOtherCalculations.length+2); - s_before.logitSubevents = new double[][]{}; - - MathUtil.ScienceSpeedModelParameters scienceSpeedModelParameters = scienceSpeedModel(); - - - s_after = MathUtil.clogMarginalScienceSpeedEventRescheduling( - scienceSpeedModelParameters, - s_before, yearsHere, 1000); - - rescheduledProbabilities = s_after; - - //List<Double> rescheduledProbabilities = new java.util.ArrayList<Double>(years.size()); - //for (int i=0; i<rescheduledProbabilities.size(); ++i) { - // rescheduledProbabilities.set(i, MathUtil.expc(s_after.clogProbEvent[i])); - //} - - /* - yearsInOtherCalculations = new double[ModelUtil.]*/ - - //return rescheduledProbabilities; - - } - - // glue equations - private MathUtil.ScienceSpeedModelParameters scienceSpeedModel() { - MathUtil.ScienceSpeedModelParameters o = new MathUtil.ScienceSpeedModelParameters(); - - o.sequencedata_base_year = ModelUtil.ANCHOR_FAR_YEAR + ModelUtil.RESEARCH_CAREER_DELAY; - o.sequencedata_mean_log_year = getDependency().value(NodeIDString.Q1_9_1, ScalarSubIDString.MEAN)*Math.log(10); - o.sequencedata_stddev_log_year = getDependency().value(NodeIDString.Q1_9_1, ScalarSubIDString.STD_DEV)*Math.log(10); - - o.population_base_year = ModelUtil.ANCHOR_FAR_YEAR + ModelUtil.RESEARCH_CAREER_DELAY; - o.population_mean_log_year = getDependency().value(NodeIDString.Q1_9_2, ScalarSubIDString.MEAN)*Math.log(10); - o.population_stddev_log_year = getDependency().value(NodeIDString.Q1_9_2, ScalarSubIDString.STD_DEV)*Math.log(10); - - double t0, t1; - t0 = 0; // EARLIEST_IA_DELAY - t1 = ModelUtil.LATEST_IA_DELAY; - double klow, khigh; - klow = NotablePercentile.PERCENTILE5.getValue(); - khigh = NotablePercentile.PERCENTILE95.getValue(); - double zlow, zhigh; - zlow = NotablePercentile.PERCENTILE5.getOffset(); - zhigh = NotablePercentile.PERCENTILE95.getOffset(); - double y0low, y0high, y1low, y1high; - double mean_init, stddev_init, mean_slope, stddev_slope, mean_final, stddev_final; - //y0low = getDependency().value(NodeIDString.Q1_9_3, ScalarSubIDString.yearPercentileID(t0, klow ))*Math.log(10); - //y0high = getDependency().value(NodeIDString.Q1_9_3, ScalarSubIDString.yearPercentileID(t0, khigh))*Math.log(10); - y0low = 0; - y0high = 0; - y1low = getDependency().value(NodeIDString.Q1_9_3, ScalarSubIDString.yearPercentileID(t1, klow ))*Math.log(10); - y1high = getDependency().value(NodeIDString.Q1_9_3, ScalarSubIDString.yearPercentileID(t1, khigh))*Math.log(10); - mean_init = MathUtil.linterp(zlow, zhigh, y0low, y0high, 0); - stddev_init = (y0high-y0low)/(zhigh-zlow); - mean_final = MathUtil.linterp(zlow, zhigh, y1low, y1high, 0); - stddev_final = (y1high-y1low)/(zhigh-zlow); - mean_slope = (mean_final-mean_init)/(t1-t0); - stddev_slope = (stddev_final-stddev_init)/(t1-t0); - o.sequencedata_mean_init_log_factor = mean_init; - o.sequencedata_mean_slope_log_factor = mean_slope; - o.sequencedata_stddev_init_log_factor = stddev_init; - o.sequencedata_stddev_slope_log_factor = stddev_slope; - - t0 = 0; // EARLIEST_IA_DELAY - t1 = ModelUtil.LATEST_IA_DELAY; - y0low = getDependency().value(NodeIDString.Q1_9_4, ScalarSubIDString.yearPercentileID(t0, klow ))*Math.log(10); - y0high = getDependency().value(NodeIDString.Q1_9_4, ScalarSubIDString.yearPercentileID(t0, khigh))*Math.log(10); - y1low = getDependency().value(NodeIDString.Q1_9_4, ScalarSubIDString.yearPercentileID(t1, klow ))*Math.log(10); - y1high = getDependency().value(NodeIDString.Q1_9_4, ScalarSubIDString.yearPercentileID(t1, khigh))*Math.log(10); - mean_init = MathUtil.linterp(zlow, zhigh, y0low, y0high, 0); - stddev_init = (y0high-y0low)/(zhigh-zlow); - mean_final = MathUtil.linterp(zlow, zhigh, y1low, y1high, 0); - stddev_final = (y1high-y1low)/(zhigh-zlow); - mean_slope = (mean_final-mean_init)/(t1-t0); - stddev_slope = (stddev_final-stddev_init)/(t1-t0); - o.population_mean_init_log_rate = mean_init - Math.log(ModelUtil.UNENHANCED_RESEARCHERS); - o.population_mean_slope_log_rate = mean_slope - Math.log(ModelUtil.UNENHANCED_RESEARCHERS); - o.population_stddev_init_log_rate = stddev_init - Math.log(ModelUtil.UNENHANCED_RESEARCHERS); - o.population_stddev_slope_log_rate = stddev_slope - Math.log(ModelUtil.UNENHANCED_RESEARCHERS); - - t0 = ModelUtil.EARLIEST_YEAR; - t1 = ModelUtil.LATEST_YEAR; - y0low = 0; - y0high = 0; - y1low = getDependency().value(NodeIDString.Q1_9_5, ScalarSubIDString.yearPercentileID(t1, klow ))*Math.log(10); - y1high = getDependency().value(NodeIDString.Q1_9_5, ScalarSubIDString.yearPercentileID(t1, khigh))*Math.log(10); - mean_init = MathUtil.linterp(zlow, zhigh, y0low, y0high, 0); - stddev_init = (y0high-y0low)/(zhigh-zlow); - mean_final = MathUtil.linterp(zlow, zhigh, y1low, y1high, 0); - stddev_final = (y1high-y1low)/(zhigh-zlow); - mean_slope = (mean_final-mean_init)/(t1-t0); - stddev_slope = (stddev_final-stddev_init)/(t1-t0); - o.institutional_base_year = ModelUtil.EARLIEST_YEAR; - o.institutional_mean_slope_log_factor = mean_slope; - o.institutional_stddev_slope_log_factor = stddev_slope; - - return o; - } - -} diff --git a/java/src/org/singinst/uf/model/ResearcherExtreme.java b/java/src/org/singinst/uf/model/ResearcherExtreme.java deleted file mode 100644 index f3cc087..0000000 --- a/java/src/org/singinst/uf/model/ResearcherExtreme.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.singinst.uf.presenter.HtmlUtil;
-import org.singinst.uf.presenter.LineBounds;
-
-public class ResearcherExtreme extends YearExtremeNodeMetadataContentsFactory {
-
-
- protected ResearcherExtreme(Node node, LineBounds rangeBounds,
- double year) {
- super(node, rangeBounds, year, " log #, " + (int) year + " years later", "", "low", "high");
- }
-
- public static List<ResearcherExtreme> createList(Node node, LineBounds rangeBounds, LineBounds yearBounds) {
- ResearcherExtreme incidentEarly = new ResearcherExtreme(node, rangeBounds, yearBounds.getFirst());
- ResearcherExtreme incidentLate = new ResearcherExtreme(node, rangeBounds, yearBounds.getSecond());
- return Arrays.asList(incidentEarly, incidentLate);
- }
-
- @Override
- public ConclusionReportGenerator getConclusionGenerator() {
- return new ConclusionReportGenerator() {
- public String getText(ScalarValueHolder scalarValueHolder, double value) {
- return "The number of IA enhanced research scientists " + getYearString() + " years later " +
- "has a 90% chance of being between " +
- HtmlUtil.green(display(getScalars().get(0).getScalarValueHolder().getValue())) +
- " and " + HtmlUtil.red(display(getScalars().get(2).getScalarValueHolder().getValue()));
- }
-
- private String display(double value) {
- return "" + (int) (Math.pow(10, value));
- }
- };
-
- }
-
-
-}
diff --git a/java/src/org/singinst/uf/model/ResearchersNodeMetadataContentsFactory.java b/java/src/org/singinst/uf/model/ResearchersNodeMetadataContentsFactory.java deleted file mode 100644 index 4db91ba..0000000 --- a/java/src/org/singinst/uf/model/ResearchersNodeMetadataContentsFactory.java +++ /dev/null @@ -1,103 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.ScalarValuePointList;
-import org.singinst.uf.presenter.LineBounds;
-
-public class ResearchersNodeMetadataContentsFactory {
-
- private final List<ScalarSchema> scalarSchemata = new ArrayList<ScalarSchema>();
- private final ScalarRelation relation;
- private final Map<Double, YearExtremeNodeMetadataContentsFactory> extremeByYear = new HashMap<Double, YearExtremeNodeMetadataContentsFactory>();
-
- private final List<PercentileDraggableLine> pointLists = new ArrayList<PercentileDraggableLine>();
-
- private final List<ScalarValueHolder> conjectureList = new ArrayList<ScalarValueHolder>();
- private final LineBounds domain;
-
- public ResearchersNodeMetadataContentsFactory(Node node) {
- final LineBounds range = new LineBounds(1, 7, true);
- domain = new LineBounds(0, ModelUtil.LATEST_IA_DELAY);
- final List<ResearcherExtreme> extremes = ResearcherExtreme.createList(node, range, domain);
- for (YearExtremeNodeMetadataContentsFactory extreme : extremes) {
- extremeByYear.put(extreme.getYear(), extreme);
- scalarSchemata.addAll(extreme.getScalars());
- }
- for (ScalarSchema scalarSchema : scalarSchemata) {
- conjectureList.add(scalarSchema.getScalarValueHolder());
- }
-
- for (final NotablePercentile percentile : NotablePercentile.values()) {
- PercentileDraggableLine pointList = new PercentileDraggableLine(percentile) {
-
- @Override
- public void dragTo(SimplePoint point) {
- ResearchersNodeMetadataContentsFactory.this.dragTo(percentile, point);
- }};
- pointLists.add(pointList);
-
- }
- relation = new ScalarRelation(new Axis(domain), new Axis(range)) {
-
- @Override
- public List<? extends ScalarValuePointList> getPointLists() {
- for (PercentileDraggableLine incidentLine : pointLists) {
- List<SimplePoint> points = new ArrayList<SimplePoint>();
- for (YearExtremeNodeMetadataContentsFactory extreme : extremes) {
- points.add(new SimplePoint(extreme.getYear(),
- extreme.getScalarSchema(incidentLine.getPercentile()).getScalarValueHolder().getValue()));
- }
- incidentLine.setHypothesisPoints(points);
- }
- return pointLists;
- }
-
- public List<? extends ConclusionReportGenerator> getConclusionGenerators() {
- List<ConclusionReportGenerator> retVal = new ArrayList<ConclusionReportGenerator>();
- for (YearExtremeNodeMetadataContentsFactory extreme : extremes) {
- retVal.add(extreme.getConclusionGenerator());
- }
- return retVal;
- }
-
- public List<ScalarValueHolder> getScalarValues() {
- return conjectureList ;
- }
- };
- }
-
- public Collection<? extends ScalarSchema> getScalars() {
- return scalarSchemata;
- }
-
- public ScalarRelation getRelation() {
- return relation;
- }
-
- public void dragTo(NotablePercentile percentile, SimplePoint point) {
- boolean selectLeft = point.x < domain.getMidpoint();
- double year = selectLeft ? domain.getFirst() : domain.getSecond();
- double anchorYear = selectLeft ? domain.getSecond() : domain.getFirst();
- YearExtremeNodeMetadataContentsFactory extreme = extremeByYear.get(year);
- if (extreme == null) {
- throw new NullPointerException("" + year);
- }
- YearExtremeNodeMetadataContentsFactory anchorExtreme = extremeByYear.get(anchorYear);
- if (anchorExtreme == null) {
- throw new NullPointerException("" + year);
- }
- SimplePoint anchorPoint = new SimplePoint(
- anchorYear, anchorExtreme.getScalarSchema(percentile).getScalarValueHolder().getValue());
- double newExtremeY = MathUtil.interpolate(
- anchorPoint, point, year);
- extreme.getScalarSchema(percentile).getScalarValueHolder().setValue(newExtremeY);
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/ScalarRelation.java b/java/src/org/singinst/uf/model/ScalarRelation.java deleted file mode 100644 index f2e0a89..0000000 --- a/java/src/org/singinst/uf/model/ScalarRelation.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.ScalarValuePointList;
-
-
-public abstract class ScalarRelation implements SummarySource {
-
- public ScalarRelation(Axis domain, Axis range) {
- this(domain, range, EMPTY_POINTS);
- }
-
- public ScalarRelation(Axis domain, Axis range, Collection<SimplePoint> decorationPoints) {
- this.domain = domain;
- this.range = range;
- this.decorationPoints = decorationPoints;
- }
-
- public abstract List<? extends ScalarValuePointList> getPointLists();
-
- public Axis getDomain() {
- return domain;
- }
-
- public Axis getRange() {
- return range;
- }
-
- private final Axis domain;
- private final Axis range;
- public final Collection<SimplePoint> decorationPoints;
-
- private static final Collection<SimplePoint> EMPTY_POINTS = Collections.emptyList();
-
-}
diff --git a/java/src/org/singinst/uf/model/ScalarSchema.java b/java/src/org/singinst/uf/model/ScalarSchema.java deleted file mode 100644 index 9fd0a07..0000000 --- a/java/src/org/singinst/uf/model/ScalarSchema.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.presenter.LineBounded;
-import org.singinst.uf.presenter.LineBounds;
-
-public class ScalarSchema implements SummarySource, LineBounded {
- private final String prefix;
- private final String suffix;
-
- private final Node node;
- private final String idString;
- private final LineBounds bounds;
- private final String unit;
- private final List<ConclusionReportGenerator> conclusionReportGenerators = new ArrayList<ConclusionReportGenerator>();
- private boolean visibleAxis = true;
- private boolean visibleProperty = true;
-
- private final LineBounds boundsConstraint;
-
- public ScalarSchema(Node node, String idString, LineBounds bounds, String unit, String prefix, String suffix, LineBounds boundsConstraint, boolean visibleProperty) {
- this.node = node;
- this.idString = idString;
- this.bounds = bounds;
- this.unit = unit;
- this.prefix = prefix;
- this.suffix = suffix;
- this.boundsConstraint = boundsConstraint;
- this.visibleProperty = visibleProperty;
- }
-
- public String getPrefix() {
- return prefix;
- }
-
- public String getSuffix() {
- return suffix;
- }
-
- public String getKey() {
- return node.getIdString() + "." + idString;
- }
-
- @Override
- public String toString() {
- return getKey();
- }
-
- public List<ScalarValueHolder> getScalarValues() {
- return Collections.singletonList(getScalarValueHolder());
- }
- public ScalarValueHolder getScalarValueHolder() {
- return ScalarValueHolder.findById(this);
- }
- public List<ConclusionReportGenerator> getConclusionGenerators() {
- return conclusionReportGenerators;
- }
- public LineBounds getLineBounds() {
- return getBounds();
- }
- public LineBounds getBounds() {
- return bounds;
- }
- public boolean isVisibleAxis() {
- return visibleAxis;
- }
- public boolean displayProperty() {
- return visibleProperty;
- }
- public void setVisibleAxis(boolean visibleAxis) {
- this.visibleAxis = visibleAxis;
- }
- public Collection<NodeMetadata> getDependencies() {
- return node.getDependencies();
- }
-
- public static int getMaxDecimalDigits() {
- return 4;
- }
-
- public String getUnit() {
- return unit;
- }
-
- public LineBounds getBoundsConstraint() {
- return boundsConstraint;
- }
-
- public Object monte() {
- return MathUtil.RANDOM.nextFloat() * 100 < getScalarValueHolder().getValue();
- }
-}
diff --git a/java/src/org/singinst/uf/model/ScalarSubIDString.java b/java/src/org/singinst/uf/model/ScalarSubIDString.java deleted file mode 100644 index b39bce1..0000000 --- a/java/src/org/singinst/uf/model/ScalarSubIDString.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.singinst.uf.model;
-
-public class ScalarSubIDString {
-
- public static final String PROBABILITY = "probability";
- public static final String MEAN = "mean";
- public static final String STD_DEV = "stdDev";
- public static final String MEAN_INIT = "meanInit";
- public static final String STD_DEV_INIT = "stdDevInit";
- public static final String MEAN_SLOPE = "meanSlope";
- public static final String STD_DEV_SLOPE = "stdDevSlope";
-
- public static final String K95 = "k95";
- public static final String K50 = "k50";
- public static final String K5 = "k5";
-
- public static String yearPercentileID(double year, double percentile) {
- return "y" + year + "k" + percentile;
- }
-
- public static String yearProbabilityID(double year) {
- return "y" + year + "p";
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/ScalarValueDependency.java b/java/src/org/singinst/uf/model/ScalarValueDependency.java deleted file mode 100644 index 6bcd32b..0000000 --- a/java/src/org/singinst/uf/model/ScalarValueDependency.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class ScalarValueDependency {
- private boolean validityChecked = false;
- private Set<ScalarValueHolder> dependencies = new HashSet<ScalarValueHolder>();
-
- public void validate() {
- if (!validityChecked) {
- validityChecked = true;
- }
- }
-
- public double value(String namespace, String name) {
- ScalarValueHolder scalarValueHolder = ScalarValueHolder.findById(namespace, name);
- if (!validityChecked) {
- dependencies.add(scalarValueHolder);
- }
- return scalarValueHolder.getValue();
- }
-
-}
diff --git a/java/src/org/singinst/uf/model/ScalarValueHolder.java b/java/src/org/singinst/uf/model/ScalarValueHolder.java deleted file mode 100644 index 0b14a77..0000000 --- a/java/src/org/singinst/uf/model/ScalarValueHolder.java +++ /dev/null @@ -1,189 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.presenter.LineBounds;
-import org.singinst.uf.presenter.Store;
-
-public class ScalarValueHolder implements Evaluable {
- @Override
- public String toString() {
- return getScalar().getKey();
- }
-
- private static final Map<String, ScalarValueHolder> store = new HashMap<String, ScalarValueHolder>();
- private final List<ValueListener> valueListeners = new ArrayList<ValueListener>();
- private double value;
- private final ScalarSchema scalarSchema;
- private double timestamp;
- private Calculation calculation;
-
- public ScalarValueHolder(ScalarSchema scalarSchema, double value) {
- this.scalarSchema = scalarSchema;
- try {
- Store s = Store.getInstance();
- Double storedValue = s.get(scalarSchema.getKey());
- if (storedValue == null) {
- this.value = value;
- } else {
- this.value = storedValue;
- }
- } catch (Exception e) {
- e.printStackTrace();
- this.value = value;
- }
- }
-
- public synchronized void setValueFromUser(double requestedValue) {
- double fromDisplay = getScalar().getBounds().toDisplay().invert(requestedValue);
- setValue(fromDisplay);
- }
-
- public synchronized void setValue(double requestedValue) {
- double constrainedValue = constrain(requestedValue);
- timestamp = System.currentTimeMillis();
- this.value = constrainedValue;
- notifyListeners();
- org.singinst.uf.common.LogUtil.info("storing with key \"" + scalarSchema.getKey() + "\" and value of "+value);
- try {
- Store s = Store.getInstance();
- s.put(scalarSchema.getKey(), value);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void notifyListeners() {
- for (ValueListener valueListener : valueListeners) {
- valueListener.fireUpdate(value);
- }
- }
-
- private double constrain(double requestedValue) {
- double rounded = MathUtil.round(requestedValue, ScalarSchema.getMaxDecimalDigits());
- LineBounds boundsConstraint = getScalar().getBoundsConstraint();
- if (boundsConstraint != null) {
- return boundsConstraint.constrain(rounded);
- } else {
- return rounded;
- }
- }
-
- public void addUpdateListener(ValueListener valueListener) {
- valueListeners.add(valueListener);
- valueListener.fireUpdate(getCachedValue());
- }
-
- public void unshiftUpdateListener(ValueListener valueListener) {
- valueListeners.add(0, valueListener);
- valueListener.fireUpdate(getCachedValue());
- }
-
- public static ScalarValueHolder findById(ScalarSchema scalarSchema) {
- String key = scalarSchema.getKey();
- ScalarValueHolder retVal = store.get(key);
- if (retVal == null) {
- LineBounds bounds = scalarSchema.getLineBounds();
- retVal = new ScalarValueHolder(scalarSchema, bounds.getMidpoint());
- store.put(key, retVal);
- }
- return retVal;
- }
-
- public synchronized double getValue() {
- if (calculation != null && needsCalc(new NeedsCalcCache())) {
- calculation.getHtmlConsole().setLength(0);
- setValue(calculation.evaluate());
- }
- return value;
- }
-
- public synchronized double getCachedValue() {
- return value;
- }
-
- private static String constructKey(String namespace, String name) {
- return namespace + "." + name;
- }
-
- public static ScalarValueHolder findById(String namespace, String name) {
- String key = constructKey(namespace, name);
- return findById(key);
- }
-
- public static ScalarValueHolder findById(String key) {
- ScalarValueHolder scalarValueHolder = store.get(key);
- if (scalarValueHolder == null) {
- throw new NullPointerException("Key not found: " + key + "; available keys are: " + store.keySet());
- } else {
- return scalarValueHolder;
- }
- }
-
- public static Calculation getCalculation(String namespace, String name) {
- return findById(namespace, name).getCalculation();
- }
-
- public synchronized boolean needsCalc(NeedsCalcCache needsCalcCache) {
- if (getScalar().getDependencies().isEmpty()) {
- return false;
- }
- if (timestamp == 0) {
- return true;
- }
-
- Set<ScalarValueHolder> otherConjectures = new HashSet<ScalarValueHolder>();
- for (NodeMetadata nodeMetadata : getScalar().getDependencies()) {
- otherConjectures.addAll(nodeMetadata.getScalarValueHolders());
-// for (ScalarSchema otherScalar : nodeMetadata.getScalars()) {
-// otherConjectures.add(otherScalar.getScalarValueHolder());
-// }
- for (ScalarRelation relation : nodeMetadata.getScalarRelations()) {
- otherConjectures.addAll(relation.getScalarValues());
- }
- }
- for (ScalarValueHolder otherConjecture : otherConjectures) {
- if (needsCalcCache.needsCalc(otherConjecture) || timestamp < otherConjecture.timestamp) {
- return true;
- }
- }
- return false;
- }
-
- public void setCalculation(Calculation calculation) {
- this.calculation = calculation;
- }
-
- public Calculation getCalculation() {
- return calculation;
- }
-
- public double evaluate(StringBuilder htmlConsole) {
- double retVal = getValue();
- if (calculation != null) {
- htmlConsole.append(calculation.getDescription() + " = " + retVal + "<br>");
- }
- return retVal;
- }
-
- public ScalarSchema getScalar() {
- return scalarSchema;
- }
-
- public static void destroyAll() {
- for (ScalarValueHolder holder: store.values()) {
- holder.destroy();
- }
- store.clear();
- }
-
- private void destroy() {
- valueListeners.clear();
- }
-}
diff --git a/java/src/org/singinst/uf/model/SimpleColor.java b/java/src/org/singinst/uf/model/SimpleColor.java deleted file mode 100644 index 5a7e2e0..0000000 --- a/java/src/org/singinst/uf/model/SimpleColor.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.singinst.uf.model;
-
-public enum SimpleColor {
-
- GREEN, BLACK, RED, LIGHT_GRAY;
-
- public abstract static class Visitor<T> {
- public T visit(SimpleColor color) {
- switch(color) {
- case GREEN: return visit_GREEN();
- case BLACK: return visit_BLACK();
- case RED: return visit_RED();
- case LIGHT_GRAY: return visit_LIGHT_GRAY();
- default: throw new RuntimeException();
- }
- }
-
- public abstract T visit_GREEN();
- public abstract T visit_BLACK();
- public abstract T visit_RED();
- public abstract T visit_LIGHT_GRAY();
- }
-}
diff --git a/java/src/org/singinst/uf/model/SummarySource.java b/java/src/org/singinst/uf/model/SummarySource.java deleted file mode 100644 index 54c9a4f..0000000 --- a/java/src/org/singinst/uf/model/SummarySource.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.List;
-
-public interface SummarySource {
-
- List<? extends ConclusionReportGenerator> getConclusionGenerators();
-
- List<ScalarValueHolder> getScalarValues();
-
-}
diff --git a/java/src/org/singinst/uf/model/UiText.java b/java/src/org/singinst/uf/model/UiText.java deleted file mode 100644 index ca3e84c..0000000 --- a/java/src/org/singinst/uf/model/UiText.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.singinst.uf.model;
-
-public class UiText {
-
- private final String question;
- private final String help;
-
- public UiText(String question, String help) {
- this.question = question;
- this.help = help;
- }
-
- public String getHelp() {
- return help;
- }
-
- public String getQuestion() {
- return question;
- }
-}
\ No newline at end of file diff --git a/java/src/org/singinst/uf/model/UiTextConstant.java b/java/src/org/singinst/uf/model/UiTextConstant.java deleted file mode 100644 index 017b2a7..0000000 --- a/java/src/org/singinst/uf/model/UiTextConstant.java +++ /dev/null @@ -1,190 +0,0 @@ -package org.singinst.uf.model;
-
-public interface UiTextConstant {
-
- UiText Q1_1_TEXT =
- new UiText("Is artificial intelligence possible in principle?",
-// "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">" +
- "<html>" +
-// "<HEAD>" +
-// " <META HTTP-EQUIV=\"CONTENT-TYPE\" CONTENT=\"text/html; charset=windows-1252\">" +
-// " <TITLE>1)</TITLE>" +
-// " <META NAME=\"GENERATOR\" CONTENT=\"OpenOffice.org 3.0 (Win32)\">" +
-// " <META NAME=\"AUTHOR\" CONTENT=\"Michael Anissimov\">" +
-// " <META NAME=\"CREATED\" CONTENT=\"20081007;10570000\">" +
-// " <META NAME=\"CHANGEDBY\" CONTENT=\"Rolf Nelson\">" +
-// " <META NAME=\"CHANGED\" CONTENT=\"20090118;21592300\">" +
-// " <META NAME=\"CHANGEDBY\" CONTENT=\"Rolf Nelson\">" +
-// " <STYLE TYPE=\"text/css\">" +
-// " <!--" +
-// " @page { margin-left: 0.79in; margin-right: 1.25in; margin-top: 1in; margin-bottom: 1in }" +
-// " P { margin-bottom: 0.08in; direction: ltr; color: #000000; widows: 2; orphans: 2 }" +
-// " P.western { font-family: \"Times New Roman\", serif; font-size: 12pt; so-language: en-US }" +
-// " P.cjk { font-family: \"Times New Roman\", serif; font-size: 12pt }" +
-// " P.ctl { font-family: \"Times New Roman\", serif; font-size: 12pt; so-language: ar-SA }" +
-// " A:link { color: #0000ff }" +
-// " -->" +
-// " </STYLE>" +
-// "</HEAD>" +
- "<BODY LANG=\"en-US\" TEXT=\"#000000\" LINK=\"#0000ff\" DIR=\"LTR\">" +
- "<P CLASS=\"western\" STYLE=\"margin-bottom: 0in\">Gene sequencing costs" +
- "have been dropping exponentially for some time. Here is a graph (from" +
- "Kurzweil 2005) that shows the trend from 1990 to 2004:</P>" +
- "<P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><IMG SRC=\"data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcpp\n" +
- "V0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7\" " +
- "ALIGN=BOTTOM WIDTH=500 HEIGHT=383 BORDER=0></P>" +
- "<P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><BR>Germline genetic" +
- "modification for enhancing human intelligence would depend upon the" +
- "availability and cost of sequenced genomes. When will it be possible" +
- "to sequence an entire human genome for less than $1000?</P>" +
- "<P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><BR>" +
- "</P>" +
- "<UL>" +
- " <LI><P CLASS=\"western\" STYLE=\"margin-top: 0.19in; margin-bottom: 0in\">" +
- " <B>Claim: </B>According to the trendline in the Kurzweil graph," +
- " assuming a sequencing cost of $0.002 per base pair in 2008 (based on" +
- " a $60,000 full-genome sequence by Applied Biosystems in March 2008)" +
- " and a cost halving time of 1.9 years, we can assume $1,000 genomes" +
- " sometime around 2020.<BR><B>Implication: </B>$1,000 genomes in" +
- " 2020.<BR><B>Source: </B>Kurzweil, Ray. <I>The Singularity is Near:" +
- " When Humans Transcend Biology</I>. 2005. New York: Penguin" +
- " (Non-Classics).</P>" +
- " <LI><P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><B>Claim:</B> The" +
- " first human genome cost either $3 billion (Human Genome Project) or" +
- " $300 million (Celera Genomics) in 2001, James Watson’s genome" +
- " cost $2 million in 2007, and Applied Biosystems sequenced a human" +
- " genome for $60,000 in two weeks in March 2008. One company," +
- " Intelligent Bio-systems, has claimed they will be able to provide" +
- " $5,000, 24-hour genomes by the end of 2008. <BR><B>Implication: </B>The" +
- " number of human genomes we can sequence for a fixed cost has been" +
- " increasing at a sharp exponential, often exceeding earlier" +
- " expectations.<BR><B>Sources:</B> Chu, Wai Lang. "Applied Bio" +
- " sequences a human genome for $60,000." " +
- " LabTechnologist.com. 18 Mar. 2008. 9 Aug. 2008" +
- " <<A HREF=\"http://www.labtechnologist.com/products/applied-bio-sequences-a-human-genome-for-60-000\" TARGET=\"_blank\"><FONT COLOR=\"#0000ff\"><U>http://www.labtechnologist.com/products/applied-bio-sequences-a-human-genome-for-60-000</U></FONT></A>>. <BR>Singer," +
- " Emily. "The $2 Million Genome." Technology Review. 1" +
- " June <BR>2007. Massachusetts Institute of Technology. 9 Aug." +
- " 2008 <BR><<A HREF=\"http://www.technologyreview.com/biotech/18809/\" TARGET=\"_blank\"><FONT COLOR=\"#0000ff\"><U>http://www.technologyreview.com/biotech/18809/</U></FONT></A>>. <BR>Wang," +
- " Brian. "Whole genome sequencing costs continue to fall:" +
- " $300 <BR>million in 2003, $1 million 2007, $60,000 now, $5000" +
- " by year end." <BR>Next Big Future. 25 Mar. 2008. 9 Aug." +
- " 2008 <BR><<A HREF=\"http://nextbigfuture.com/2008/03/genome-sequencing-costs-continue-to.html\" TARGET=\"_blank\"><FONT COLOR=\"#0000ff\"><U>http://nextbigfuture.com/2008/03/genome-sequencing-costs-continue-to.html</U></FONT></A>>. </P>" +
- "</UL>" +
- "<UL>" +
- " <LI><P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><B>Claim:</B> The" +
- " cost of gene sequencing (per base pair) has been decreasing" +
- " exponentially since 1970.<BR><B>Implication:</B> Unless something" +
- " changes, exponential growth in capability will probably continue" +
- " into the future.<BR><B>Source:</B> Shendure, Jay, Robi D. Mitra," +
- " Chris Varma, and George M. Church. <BR>"Advanced" +
- " Sequencing Technologies: Methods and Goals." Nature" +
- " Reviews <BR>Genetics 5 (2004): 335-44. 9 Aug. 2008" +
- " <<A HREF=\"http://www.nature.com/nrg/journal/v5/n5/abs/nrg1325_fs.html\" TARGET=\"_blank\"><FONT COLOR=\"#0000ff\"><U>http://www.nature.com/nrg/journal/v5/n5/abs/nrg1325_fs.html</U></FONT></A>>.</P>" +
- "</UL>" +
- "<P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><BR>" +
- "</P>" +
- "<UL>" +
- " <LI><P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><B>Claim:</B> The" +
- " Archon X prize, for rapid sequencing of 100 human genomes at less" +
- " than $10,000 each, has a deadline of October 2013.<BR><B>Implication:</B>" +
- " Some scientists think that DNA sequencing costs will continue to" +
- " drop quickly enough that 2013 is a viable deadline.<BR><B>Source:</B>" +
- " X Prize Foundation. $10 Million Archon XPrize For Genomics." +
- " "Archon <BR>Genomics X Prize: Competition Guidelines."" +
- " 2 Nov. 2006. <BR>9 Aug. 2008" +
- " <<A HREF=\"http://genomics.xprize.org/files/downloads/genomics/archon_x_prize_for_genomics_competiton_guidelines.pdf\" TARGET=\"_blank\"><FONT COLOR=\"#0000ff\"><U>http://genomics.xprize.org/files/downloads/genomics/archon_x_prize_for_genomics_competiton_guidelines.pdf</U></FONT></A>>.</P>" +
- "</UL>" +
- "<P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><BR>" +
- "</P>" +
- "<UL>" +
- " <LI><P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><B>Claim:</B> The" +
- " NHGRI, a government institute, has awarded grants to researchers" +
- " with the goal of reducing sequencing costs to $1,000/human" +
- " genome.<BR><B>Implication:</B> A price of $1,000 per genome is a" +
- " viable research goal in the near term and is already being actively" +
- " funded.<BR><B>Source: </B>National Institutes of Health. National" +
- " Human Genome Research <BR>Institute. "NHGRI Aims to Make" +
- " DNA Sequencing Faster, More Cost <BR>Effective." Press" +
- " release. 4 Oct. 2006. 9 Aug. 2008 <<A HREF=\"http://www.genome.gov/19518500\" TARGET=\"_blank\"><FONT COLOR=\"#0000ff\"><U>http://www.genome.gov/19518500</U></FONT></A>>.</P>" +
- "</UL>" +
- "<P CLASS=\"western\" STYLE=\"margin-left: 0.25in; margin-bottom: 0in\"><BR>" +
- "</P>" +
- "<UL>" +
- " <LI><P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><B>Claim:</B> 23" +
- " and Me, a private company, will sequence 600,000 single nucleotide" +
- " polymorphisms (SNPs) for private individuals for" +
- " $1,000.<BR><B>Implication:</B> There is a large consumer demand for" +
- " genomics, so research in this area will continue to be heavily" +
- " funded.<BR><B>Source:</B> "23 and Me." 24 July 2008. 9" +
- " Aug. 2008 <<A HREF=\"https://www.23andme.com/\" TARGET=\"_blank\"><FONT COLOR=\"#0000ff\"><U>https://www.23andme.com/</U></FONT></A>>.</P>" +
- "</UL>" +
- "<P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><BR>" +
- "</P>" +
- "<P CLASS=\"western\" STYLE=\"margin-bottom: 0in\"><A NAME=\"0.1_01000004\"></A><A NAME=\"0.1_0100000A\"></A>" +
- "<BR>" +
- "</P>" +
- "</BODY>" +
- "</html>"
- );
-
- UiText Q1_2_TEXT = new UiText("When will computing power stop improving exponentially?",
- "TODO: implement help text");
-
- UiText Q1_3_TEXT = new UiText("How much computing power for neuromorphic (brain-like) AI?",
- "TODO: implement help text");
-
- UiText Q1_4_TEXT = new UiText("How much funding will the largest neuromorphic AI projects have to buy computers with?",
- "TODO: implement help text");
-
- UiText Q1_5_TEXT = new UiText("When will we have enough brain imaging technology that we can build neuromorphic (brain-like) AI?",
- "TODO: implement help text");
-
- UiText C1_5_TEXT = new UiText("<html><span style='color: #000;'><strong>The future, according to you:</strong><br> " +
-"Based on your answers, here is the (preliminary) probability that neuromorphic artificial intelligence will have been " + "created at different points in the future:</span>",
- "TODO: implement help text");
-
- UiText Q1_6_TEXT = new UiText("What about non-neuromorphic AI? When will that be feasible?",
- "TODO: implement help text");
-
- UiText C1_6_TEXT = new UiText("<html><span style='color: #000;'><strong>The future, according to you:</strong><br> " +
-"Based on your answers, here is the (preliminary) probability that artificial intelligence of any sort " +
-"(neuromorphic or non-neuromorphic) will have been created at different points in the future:</span>",
- "TODO: implement help text");
-
- UiText Q1_7_TEXT = new UiText("What is the probability per year of major nuclear war that disrupts scientific progress?",
- "TODO: implement help text");
-
- UiText Q1_8_TEXT = new UiText("What is the probability per year of a non-nuclear catastrophe that disrupts scientific progress?",
- "TODO: implement help text");
-
- UiText C1_8_TEXT = new UiText("<html><span style='color: #000;'><strong>The future, according to you:<br></strong> " +
-"Based on your answers, here is the probability that a science-disrupting disaster will have occurred by " +
-"different points in the future (assuming, for now, that AI has not occurred):</span>",
- "TODO: implemente help text");
-
- UiText Q1_9_1_TEXT = new UiText("When will it be possible to sequence an entire human genome for less than $1000?",
- "TODO: implement help text");
-
- UiText Q1_9_2_TEXT = new UiText("How long before artificial gametes?",
- "TODO: implement help text");
-
- UiText Q1_9_3_TEXT = new UiText("How much do genetic variations contribute to scientific achievement?",
- "TODO: implement help text");
-
- UiText Q1_9_4_TEXT = new UiText("How widely will iterated embryo selection technology be adopted?",
- "TODO: implement help text");
-
- UiText Q1_9_5_TEXT = new UiText("What about other methods for enhancing human intelligence?",
- "TODO: implement help text");
-
- UiText C1_9_TEXT = new UiText("<html><span style='color:#000;'<strong>The future, according to you:</strong><br> " +
-"Based on your answers, here is the probability that artificial intelligence will have been created at " +
-"different points in the future. This time, we're factoring in your probabilities for science-disrupting " +
-"disaster and for intelligence enhancement that speeds AI research.</span>",
- "TODO: implement help text");
-
- UiText C1_10_TEXT = new UiText("<html><span style='color: #000;'><strong>The future, according to you:</strong><br> " +
-"Based on your answers, here is the probability that there will have been a civilization-scale disruption " +
-"to business as usual by different points in the future.</span>",
- "TODO: implement help text");
-}
diff --git a/java/src/org/singinst/uf/model/ValueListener.java b/java/src/org/singinst/uf/model/ValueListener.java deleted file mode 100644 index 50964a7..0000000 --- a/java/src/org/singinst/uf/model/ValueListener.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.singinst.uf.model;
-
-public interface ValueListener {
- void fireUpdate(double value);
-}
diff --git a/java/src/org/singinst/uf/model/YearExtremeNodeMetadataContentsFactory.java b/java/src/org/singinst/uf/model/YearExtremeNodeMetadataContentsFactory.java deleted file mode 100644 index 9620a49..0000000 --- a/java/src/org/singinst/uf/model/YearExtremeNodeMetadataContentsFactory.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.singinst.uf.model;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.singinst.uf.presenter.HtmlUtil;
-import org.singinst.uf.presenter.LineBounds;
-import org.singinst.uf.presenter.SimpleStyle;
-
-public abstract class YearExtremeNodeMetadataContentsFactory {
-
- private final List<ScalarSchema> scalarSchemata = new ArrayList<ScalarSchema>();
- private final Map<NotablePercentile, ScalarSchema> scalarMap = new HashMap<NotablePercentile, ScalarSchema>();
- private final double year;
-
- protected YearExtremeNodeMetadataContentsFactory(Node node, LineBounds rangeBounds, double year,
- String subPrefix, String units, String adjSmall, String adjLarge) {
- this.year = year;
- for (NotablePercentile percentile : NotablePercentile.values()) {
- SimpleStyle style = new SimpleStyle(percentile.getColor());
-
- ScalarSchema scalarSchema = new ScalarSchema(
- node,
- ScalarSubIDString.yearPercentileID(year, percentile.getValue()),
- //"y" + year + "k" + percentile.getValue(),
- rangeBounds,
- units,
- HtmlUtil.style(style, percentile.getText(adjSmall, adjLarge) + subPrefix + ": "),
- //"y" + year + "k" + percentile.getValue(),
- "", null, true);
- ScalarValueHolder scalarValueHolder = scalarSchema.getScalarValueHolder();
- scalarValueHolder.setValue(scalarValueHolder.getValue() + percentile.getOffset() / 2);
- getScalars().add(scalarSchema);
- scalarMap.put(percentile, scalarSchema);
- }
- new NormalConstraint(scalarSchemata, -50).constrain();
- }
-
- public List<ScalarSchema> getScalars() {
- return scalarSchemata;
- }
-
- public ScalarSchema getScalarSchema(NotablePercentile percentile) {
- return scalarMap.get(percentile);
- }
-
- public double getYear() {
- return year;
- }
-
- public final String getYearString() {
- return "" + (int) year;
- }
-
- public abstract ConclusionReportGenerator getConclusionGenerator();
-}
diff --git a/java/src/org/singinst/uf/model/YearwiseCalculationRelation.java b/java/src/org/singinst/uf/model/YearwiseCalculationRelation.java deleted file mode 100644 index 2a99c13..0000000 --- a/java/src/org/singinst/uf/model/YearwiseCalculationRelation.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.singinst.uf.model; - -import java.util.ArrayList; -import java.util.List; - -abstract public class YearwiseCalculationRelation extends CalculationRelation { - - public YearwiseCalculationRelation(Node node) { - super(node); - } - - @Override - protected List<Calculation> getCalculations(List<Double> years) { - List<Calculation> retVal = new ArrayList<Calculation>(); - for (double year : years) { - retVal.add(getCalculation(year)); - } - return retVal; - } - - abstract protected Calculation getCalculation(double year); -} diff --git a/java/src/org/singinst/uf/presenter/AxisDirection.java b/java/src/org/singinst/uf/presenter/AxisDirection.java deleted file mode 100644 index a6de1dd..0000000 --- a/java/src/org/singinst/uf/presenter/AxisDirection.java +++ /dev/null @@ -1,111 +0,0 @@ -package org.singinst.uf.presenter;
-
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.model.Axis;
-import org.singinst.uf.model.ScalarRelation;
-
-public abstract class AxisDirection {
-
- public static final AxisDirection X = new AxisDirection() {
-
- @Override
- protected void drawPerpindicularLine(GraphCanvas canvas,
- double parallelOffset, double perpindicularOffset1,
- double perpindicularOffset2) {
- canvas.drawLine(SimpleLine.vertical(parallelOffset, perpindicularOffset1, perpindicularOffset2));
- }
-
- @Override
- protected Axis getAxis(ScalarRelation relation) {
- return relation.getDomain();
- }
-
- @Override
- protected Axis getPerpindicularAxis(ScalarRelation relation) {
- return relation.getRange();
- }
-
- @Override
- protected void write(GraphCanvas hypothesisCanvas, ScalarRelation relation,
- double parallelOffset,
- double centParallel, double centPerpindicular,
- CanvasString canvasString) {
- hypothesisCanvas.write(
- new SimplePoint(parallelOffset - 1.5 * centParallel,
- relation.getRange().getLineBounds().getLowerBound() - 5 * centPerpindicular),
- canvasString);
- }
- };
-
- public static final AxisDirection Y = new AxisDirection() {
-
- @Override
- protected void drawPerpindicularLine(GraphCanvas canvas,
- double parallelOffset, double perpindicularOffset1,
- double perpindicularOffset2) {
- canvas.drawLine(SimpleLine.horizontal(perpindicularOffset1, perpindicularOffset2, parallelOffset));
- }
-
- @Override
- protected Axis getAxis(ScalarRelation relation) {
- return relation.getRange();
- }
-
- @Override
- protected Axis getPerpindicularAxis(ScalarRelation relation) {
- return relation.getDomain();
- }
-
- @Override
- protected void write(GraphCanvas hypothesisCanvas, ScalarRelation relation,
- double parallelOffset,
- double centParallel, double centPerpindicular,
- CanvasString canvasString) {
- hypothesisCanvas.write(
- new SimplePoint(relation.getDomain().getLineBounds().getLowerBound() - 5 * centPerpindicular,
- parallelOffset - 2 * centParallel),
- canvasString);
- }
- };
-
- public void draw(GraphCanvas hypothesisCanvas, ScalarRelation relation) {
- if (!getAxis(relation).isVisibleAxis()) {
- return;
- }
-
- LineBounds parallelBounds = getAxis(relation).getLineBounds();
- LineBounds perpindicularBounds = getPerpindicularAxis(relation).getLineBounds();
- double centParallel = parallelBounds.getLength() / 100;
- double centPerpindicular = perpindicularBounds.getLength() / 100;
-
- for (AxisSample axisSample : parallelBounds.getAxisSamples(false)) {
- double parallelOffset = axisSample.getValue();
- drawPerpindicularLine(hypothesisCanvas,
- parallelOffset,
- perpindicularBounds.getLowerBound() - centPerpindicular,
- perpindicularBounds.getLowerBound() + centPerpindicular);
- }
- hypothesisCanvas.pushStyle(SimpleStyle.PLAIN);
- for (AxisSample axisSample : parallelBounds.getAxisSamples(true)) {
- double parallelOffset = axisSample.getValue();
- drawPerpindicularLine(hypothesisCanvas,
- parallelOffset,
- perpindicularBounds.getLowerBound() - centPerpindicular,
- perpindicularBounds.getLowerBound() + centPerpindicular);
- write(hypothesisCanvas, relation, parallelOffset, centParallel, centPerpindicular, axisSample.getLabel());
- }
- hypothesisCanvas.popStyle();
- }
-
- protected abstract void write(GraphCanvas hypothesisCanvas, ScalarRelation relation,
- double parallelOffset,
- double centParallel, double centPerpindicular,
- CanvasString canvasString);
-
- protected abstract void drawPerpindicularLine(GraphCanvas canvas,
- double parallelOffset, double perpindicularOffset1, double perpindicularOffset2);
-
- protected abstract Axis getAxis(ScalarRelation relation);
- protected abstract Axis getPerpindicularAxis(ScalarRelation relation);
-
-}
diff --git a/java/src/org/singinst/uf/presenter/AxisSample.java b/java/src/org/singinst/uf/presenter/AxisSample.java deleted file mode 100644 index 87e5fff..0000000 --- a/java/src/org/singinst/uf/presenter/AxisSample.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.singinst.uf.presenter;
-
-public class AxisSample {
-
- private final double value;
- private final CanvasString label;
-
- public AxisSample(double value) {
- this(value, null);
- }
-
- public AxisSample(double value, CanvasString label) {
- this.value = value;
- this.label = label;
- }
-
- public double getValue() {
- return value;
- }
-
- public CanvasString getLabel() {
- return label;
- }
-
-}
diff --git a/java/src/org/singinst/uf/presenter/CanvasString.java b/java/src/org/singinst/uf/presenter/CanvasString.java deleted file mode 100644 index 33184ce..0000000 --- a/java/src/org/singinst/uf/presenter/CanvasString.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.singinst.uf.presenter;
-
-public class CanvasString {
-
- private final String main;
- private final String optionalPower;
-
- public CanvasString(String main, String optionalPower) {
- this.main = main;
- this.optionalPower = optionalPower;
-
- }
-
- public CanvasString(String main) {
- this(main, null);
-
- }
-
- public String getMain() {
- return main;
- }
-
- public String getOptionalPower() {
- return optionalPower;
- }
-
-}
diff --git a/java/src/org/singinst/uf/presenter/ClickableCurve.java b/java/src/org/singinst/uf/presenter/ClickableCurve.java deleted file mode 100644 index b497191..0000000 --- a/java/src/org/singinst/uf/presenter/ClickableCurve.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.singinst.uf.presenter;
-
-import org.singinst.uf.math.SimplePoint;
-
-public class ClickableCurve extends ScalarValuePointList implements MouseClickListener {
- private final MouseClickListener listener;
-
- public ClickableCurve(MouseClickListener listener) {
- this.listener = listener;
-
- }
-
- public void draw(GraphCanvas canvas) {
- super.draw(canvas);
- canvas.addMouseClickListener(listener);
- }
-
- public void mouseClick(SimplePoint point) {
-
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/ClippedCanvas.java b/java/src/org/singinst/uf/presenter/ClippedCanvas.java deleted file mode 100644 index 245e92a..0000000 --- a/java/src/org/singinst/uf/presenter/ClippedCanvas.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.singinst.uf.presenter;
-
-
-public class ClippedCanvas extends ProxyCanvas {
-
- private final PlaneBounds clipBounds;
-
- public ClippedCanvas(GraphCanvas underlyingCanvas,
- PlaneBounds clipBounds) {
- super(underlyingCanvas);
- this.clipBounds = clipBounds;
- }
-
- public PlaneBounds getPlaneBounds() {
- return clipBounds;
- }
-
- GraphTransform proxyToUnderlyingCanvas() {
- return GraphTransform.IDENTITY;
- }
-
-}
diff --git a/java/src/org/singinst/uf/presenter/Completion.java b/java/src/org/singinst/uf/presenter/Completion.java deleted file mode 100644 index e7cc2a3..0000000 --- a/java/src/org/singinst/uf/presenter/Completion.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.singinst.uf.model.ValueListener;
-
-public class Completion {
- private static Completion singleton = new Completion();
- private String display;
- private int numStages;
- private int completed;
- private List<ValueListener> listeners = new ArrayList<ValueListener>();
-
- public static Completion getInstance() {
- return singleton;
- }
-
- public synchronized boolean init(String display, int numStages) {
- if (completed < this.numStages) {
- return false;
-
- }
- this.display = display;
- this.numStages = numStages;
- completed = 0;
- fireUpdate();
- return true;
- }
-
- private void fireUpdate() {
- for (ValueListener valueListener : listeners) {
- valueListener.fireUpdate(0);
- }
- }
-
- public synchronized void tick() {
- completed++;
- fireUpdate();
- }
-
- public synchronized int getCompleted() {
- return completed;
- }
-
- public synchronized int getNumStages() {
- return numStages;
- }
-
- public void addUpdateListener(ValueListener valueListener) {
- listeners.add(valueListener);
- }
-
- public String getDisplay() {
- return display;
- }
-
- public void destroy() {
- listeners.clear();
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/DraggableLine.java b/java/src/org/singinst/uf/presenter/DraggableLine.java deleted file mode 100644 index f743c1d..0000000 --- a/java/src/org/singinst/uf/presenter/DraggableLine.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.List;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.math.SimplePoint;
-
-public abstract class DraggableLine extends ScalarValuePointList implements MouseDragListener {
- private final int selectionPriority;
-
- public DraggableLine(int selectionPriority, SimpleStyle style) {
- super(style);
- this.selectionPriority = selectionPriority;
- }
-
- public void setLine(SimpleLine line) {
- setHypothesisPoints(Arrays.asList(line.p1, line.p2));
- }
-
- public int getSelectionPriority() {
- return selectionPriority;
- }
-
- @Override
- public void draw(GraphCanvas canvas) {
- super.draw(canvas);
- canvas.addMouseDragListener(this);
- }
-
- @Override
- public void setHypothesisPoints(List<SimplePoint> hypothesisPoints) {
- if (hypothesisPoints.size() != 2) {
- throw new IllegalArgumentException();
- }
- super.setHypothesisPoints(hypothesisPoints);
- }
-
- public abstract void dragTo(SimplePoint point);
-
- public int mouseDown(SimplePoint point) {
- double y = MathUtil.interpolate(getHypothesisPoints().get(0), getHypothesisPoints().get(1), point.x);
- if (Math.abs(y - point.y) < 0.5) {
- return selectionPriority;
- } else {
- return 0;
- }
- }
-
- public static final Comparator<DraggableLine> PRIORITY_COMPARATOR = new Comparator<DraggableLine>() {
-
- public int compare(DraggableLine o1, DraggableLine o2) {
- return ((Integer)o1.getSelectionPriority()).compareTo(o2.getSelectionPriority());
- }
-
- };
-}
diff --git a/java/src/org/singinst/uf/presenter/GraphCanvas.java b/java/src/org/singinst/uf/presenter/GraphCanvas.java deleted file mode 100644 index d11be41..0000000 --- a/java/src/org/singinst/uf/presenter/GraphCanvas.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.util.List;
-
-import org.singinst.uf.math.SimplePoint;
-
-public interface GraphCanvas extends PlaneBounded {
-
- void clear();
-
- void drawLine(SimpleLine line);
-
- void drawDecorationPoint(SimplePoint point);
-
- void drawCurve(List<SimplePoint> points);
-
- void addMouseDragListener(MouseDragListener listener);
- void addMouseClickListener(MouseClickListener listener);
-
- void invalidate();
-
- void pushStyle(SimpleStyle style);
- void popStyle();
-
- void write(SimplePoint point, CanvasString canvasString);
-
-}
diff --git a/java/src/org/singinst/uf/presenter/GraphTransform.java b/java/src/org/singinst/uf/presenter/GraphTransform.java deleted file mode 100644 index e848ef3..0000000 --- a/java/src/org/singinst/uf/presenter/GraphTransform.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.singinst.uf.presenter;
-
-import org.singinst.uf.math.InvertableFunction;
-import org.singinst.uf.math.LinearTransform;
-import org.singinst.uf.math.SimplePoint;
-
-public class GraphTransform {
-
- public static final GraphTransform IDENTITY = new GraphTransform(LinearTransform.IDENTITY, LinearTransform.IDENTITY);
- private final InvertableFunction transformX;
- private final InvertableFunction transformY;
-
- public GraphTransform(PlaneBounded from, PlaneBounded to) {
- transformX = new LinearTransform(from.getPlaneBounds().getBoundsX(), to.getPlaneBounds().getBoundsX());
- transformY = new LinearTransform(from.getPlaneBounds().getBoundsY(), to.getPlaneBounds().getBoundsY());
- }
-
- public GraphTransform(InvertableFunction transformX,
- InvertableFunction transformY) {
- this.transformX = transformX;
- this.transformY = transformY;
- }
-
- public SimplePoint apply(SimplePoint point) {
- return new SimplePoint(transformX.apply(point.x), transformY.apply(point.y));
- }
-
- public GraphTransform invert() {
- return new GraphTransform(transformX.invert(), transformY.invert());
- }
-
- public SimplePoint invert(SimplePoint point) {
- return invert().apply(point);
- }
-
-
-}
diff --git a/java/src/org/singinst/uf/presenter/HtmlUtil.java b/java/src/org/singinst/uf/presenter/HtmlUtil.java deleted file mode 100644 index 6af813a..0000000 --- a/java/src/org/singinst/uf/presenter/HtmlUtil.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.awt.Color;
-
-import org.singinst.uf.model.SimpleColor;
-
-public class HtmlUtil {
-
- public static String green(Object value) {
- return color("green", value);
- }
-
- /**
- * Takes a Color and an object, and wraps it around a span html element, and adds the color to it.
- *
- * @param c
- * Color to display value in
- * @param value
- * Value to display in color c
- * @return
- * HTML code.
- */
- public static String htmlcolorFromColor(Color c, Object value){
- return color("#" + Integer.toHexString((c.getRGB() & 0xffffff) | 0x1000000).substring(1) , value);
- }
-
- private static String color(String color, Object value) {
- return "<html><span color=" + color + ">" + value + "</span>";
- }
-
- public static String red(Object value) {
- return color("red", value);
- }
-
- public static String style(SimpleStyle style, String string) {
- return color(htmlColor(style), string);
- }
-
- private static String htmlColor(SimpleStyle style) {
- return new SimpleColor.Visitor<String>() {
-
- @Override
- public String visit_BLACK() {
- return "black";
- }
-
- @Override
- public String visit_GREEN() {
- return "green";
- }
-
- @Override
- public String visit_LIGHT_GRAY() {
- return "light gray";
- }
-
- @Override
- public String visit_RED() {
- return "red";
- }
-
- }.visit(style.getColor());
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/LineBounded.java b/java/src/org/singinst/uf/presenter/LineBounded.java deleted file mode 100644 index d7f525c..0000000 --- a/java/src/org/singinst/uf/presenter/LineBounded.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.singinst.uf.presenter;
-
-public interface LineBounded {
- LineBounds getLineBounds();
-}
diff --git a/java/src/org/singinst/uf/presenter/LineBounds.java b/java/src/org/singinst/uf/presenter/LineBounds.java deleted file mode 100644 index 1fbb267..0000000 --- a/java/src/org/singinst/uf/presenter/LineBounds.java +++ /dev/null @@ -1,119 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import org.singinst.uf.math.InvertableFunction;
-import org.singinst.uf.math.MathUtil;
-
-public class LineBounds implements LineBounded {
- private final double first;
- private final double second;
- private final boolean displayAsLog;
-
- public LineBounds(double first, double second) {
- this(first, second, false);
- }
-
- public LineBounds(double first, double second, boolean displayAsLog) {
- if (first == second) {
- throw new IllegalArgumentException();
- }
- this.first = first;
- this.second = second;
- this.displayAsLog = displayAsLog;
- }
-
- public double getLength() {
- return getSecond() - getFirst();
- }
-
- public double getLowerBound() {
- return getFirst();
- }
-
- public double getUpperBound() {
- return getSecond();
- }
-
- public LineBounds getLineBounds() {
- return this;
- }
-
- public double getMidpoint() {
- return constrain((getLowerBound() + getUpperBound()) / 2);
- }
-
- public Iterable<Double> getSpanningSamples(int sampleCount) {
- List<Double> samples = new ArrayList<Double>();
- for (int i = 0; i < sampleCount; i++) {
- samples.add(getUpperBound() * i / (sampleCount - 1)
- + getLowerBound() * (sampleCount - i - 1) / (sampleCount - 1)
- );
- }
- return samples;
- }
-
- public Iterable<Double> getVisualSamples(int maxSamples, double start, Collection<Double> requiredPoints) {
- double sampleSizeLowerBound = getLength() / maxSamples;
- double sampleSize = Math.pow(10, Math.ceil(Math.log10(sampleSizeLowerBound)));
- SortedSet<Double> samples = new TreeSet<Double>();
- for (double i = start; i <= getUpperBound(); i += sampleSize) {
- samples.add(i);
- }
- for (double i = start - sampleSize; i >= getLowerBound(); i -= sampleSize) {
- samples.add(i);
- }
- samples.addAll(requiredPoints);
- return samples;
- }
-
- public Iterable<AxisSample> getAxisSamples(boolean majorTick) {
- int maxReadableSamples = majorTick ? 10 : 100;
- List<AxisSample> retVal = new ArrayList<AxisSample>();
- for (double value : getVisualSamples(maxReadableSamples, getLowerBound(), Collections.<Double>emptyList())) {
- if (majorTick) {
- retVal.add(new AxisSample(value, getCanvasString(value)));
- } else {
- retVal.add(new AxisSample(value));
- }
- }
- return retVal;
- }
-
- protected CanvasString getCanvasString(double x) {
- if (displayAsLog) {
- return new CanvasString("" + 10, NumericEntry.formatAsScalar(x));
- } else {
- return new CanvasString(NumericEntry.formatAsScalar(x));
- }
- }
-
- public double getFirst() {
- return first;
- }
-
- public double getSecond() {
- return second;
- }
-
- public boolean displayAsLog(){
- return displayAsLog;
- }
-
- public InvertableFunction toDisplay() {
- return InvertableFunction.IDENTITY;
- }
-
- public String userFormat(double value) {
- return NumericEntry.getScalarFormat().format(value);
- }
-
- public double constrain(double rounded) {
- return MathUtil.bound(rounded, getFirst(), getSecond());
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/MouseClickListener.java b/java/src/org/singinst/uf/presenter/MouseClickListener.java deleted file mode 100644 index dcf13cc..0000000 --- a/java/src/org/singinst/uf/presenter/MouseClickListener.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.singinst.uf.presenter;
-
-import org.singinst.uf.math.SimplePoint;
-
-public interface MouseClickListener {
- void mouseClick(SimplePoint point);
-
-}
diff --git a/java/src/org/singinst/uf/presenter/MouseDragListener.java b/java/src/org/singinst/uf/presenter/MouseDragListener.java deleted file mode 100644 index b21461f..0000000 --- a/java/src/org/singinst/uf/presenter/MouseDragListener.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.singinst.uf.presenter;
-
-import org.singinst.uf.math.SimplePoint;
-
-public interface MouseDragListener {
- int mouseDown(SimplePoint point);
- void dragTo(SimplePoint point);
-}
diff --git a/java/src/org/singinst/uf/presenter/NumericEntry.java b/java/src/org/singinst/uf/presenter/NumericEntry.java deleted file mode 100644 index 137409d..0000000 --- a/java/src/org/singinst/uf/presenter/NumericEntry.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.text.DecimalFormat;
-import java.text.Format;
-
-import org.singinst.uf.math.MathUtil;
-import org.singinst.uf.model.ScalarSchema;
-
-public class NumericEntry {
- private static String SCALAR_FORMAT_STRING;
- static {
- SCALAR_FORMAT_STRING = "##0.";
- for (int i = 0; i < ScalarSchema.getMaxDecimalDigits(); i++) {
- SCALAR_FORMAT_STRING += "#";
- }
- }
- public static Format getScalarFormat() {
- return new DecimalFormat(SCALAR_FORMAT_STRING);
- }
- public static String formatAsScalar(double value) {
- return getScalarFormat().format(value);
- }
-
- private static int MAX_COLUMNS = 4 + ScalarSchema.getMaxDecimalDigits();
-
- public static int maxColumns() {
- return MAX_COLUMNS;
- }
- public static double round(double roundMe) {
- return MathUtil.round(roundMe, ScalarSchema.getMaxDecimalDigits());
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/PlaneBounded.java b/java/src/org/singinst/uf/presenter/PlaneBounded.java deleted file mode 100644 index c96bac8..0000000 --- a/java/src/org/singinst/uf/presenter/PlaneBounded.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.singinst.uf.presenter;
-
-public interface PlaneBounded {
-
- PlaneBounds getPlaneBounds();
-}
diff --git a/java/src/org/singinst/uf/presenter/PlaneBounds.java b/java/src/org/singinst/uf/presenter/PlaneBounds.java deleted file mode 100644 index ab29274..0000000 --- a/java/src/org/singinst/uf/presenter/PlaneBounds.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.singinst.uf.presenter;
-
-
-public class PlaneBounds implements PlaneBounded {
-
- private LineBounds boundsX;
- private LineBounds boundsY;
-
- public PlaneBounds(double left, double right, double bottom, double top) {
- boundsX = new LineBounds(left, right);
- boundsY = new LineBounds(bottom, top);
- }
-
- public PlaneBounds(LineBounded boundedX, LineBounded boundedY) {
- this.boundsX = boundedX.getLineBounds();
- this.boundsY = boundedY.getLineBounds();
- }
-
- public LineBounds getBoundsX() {
- return boundsX;
- }
-
- public LineBounds getBoundsY() {
- return boundsY;
- }
-
- public PlaneBounds getPlaneBounds() {
- return this;
- }
-
-}
diff --git a/java/src/org/singinst/uf/presenter/ProxyCanvas.java b/java/src/org/singinst/uf/presenter/ProxyCanvas.java deleted file mode 100644 index 459930d..0000000 --- a/java/src/org/singinst/uf/presenter/ProxyCanvas.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.SortedMap;
-import java.util.TreeMap;
-
-import org.singinst.uf.math.SimplePoint;
-
-abstract class ProxyCanvas implements GraphCanvas, MouseDragListener, MouseClickListener {
- private final GraphCanvas underlyingCanvas;
- private final Set<MouseDragListener> dragListeners = new HashSet<MouseDragListener>();
- private final Set<MouseClickListener> clickListeners = new HashSet<MouseClickListener>();
- private MouseDragListener selectedDragListener;
-
- ProxyCanvas(GraphCanvas underlyingCanvas) {
- this.underlyingCanvas = underlyingCanvas;
- }
-
- public void clear() {
- getUnderlyingCanvas().clear();
- }
-
- public void drawDecorationPoint(SimplePoint point) {
- getUnderlyingCanvas().drawDecorationPoint(toUnderlyingCanvas(point));
- }
-
- private SimplePoint toUnderlyingCanvas(SimplePoint point) {
- return proxyToUnderlyingCanvas().apply(point);
- }
-
- private SimplePoint fromUnderlyingCanvas(SimplePoint point) {
- return proxyToUnderlyingCanvas().invert(point);
- }
-
- abstract GraphTransform proxyToUnderlyingCanvas();
-
- public void drawLine(SimpleLine line) {
- getUnderlyingCanvas().drawLine(new SimpleLine(toUnderlyingCanvas(line.p1), toUnderlyingCanvas(line.p2)));
- }
-
- public void drawCurve(List<SimplePoint> points) {
- List<SimplePoint> underlyingCanvasPoints = new ArrayList<SimplePoint>();
- for (SimplePoint point : points) {
- underlyingCanvasPoints.add(toUnderlyingCanvas(point));
- }
- getUnderlyingCanvas().drawCurve(underlyingCanvasPoints);
- }
-
- public void addMouseDragListener(final MouseDragListener listener) {
- dragListeners.add(listener);
- getUnderlyingCanvas().addMouseDragListener(this);
- }
-
- public void addMouseClickListener(final MouseClickListener listener) {
- clickListeners.add(listener);
- getUnderlyingCanvas().addMouseClickListener(this);
- }
-
- public void mouseClick(SimplePoint point) {
- SimplePoint ourPoint = fromUnderlyingCanvas(point);
- for (MouseClickListener listener : clickListeners) {
- listener.mouseClick(ourPoint);
- }
- }
-
- public void dragTo(SimplePoint point) {
- SimplePoint ourPoint = fromUnderlyingCanvas(point);
- selectedDragListener.dragTo(ourPoint);
- }
-
- public int mouseDown(SimplePoint point) {
- SimplePoint ourPoint = fromUnderlyingCanvas(point);
-
- SortedMap<Integer, MouseDragListener> listenersByPriority = new TreeMap<Integer, MouseDragListener>();
- for (MouseDragListener listener : dragListeners) {
- listenersByPriority.put(listener.mouseDown(ourPoint), listener);
- }
- int maxPriority = listenersByPriority.lastKey();
- if (maxPriority > 0) {
- selectedDragListener = listenersByPriority.get(maxPriority);
- }
- return maxPriority;
- }
-
-
-
- public void invalidate() {
- underlyingCanvas.invalidate();
- }
-
-
-
- public void pushStyle(SimpleStyle style) {
- underlyingCanvas.pushStyle(style);
- }
-
-
-
- public void popStyle() {
- underlyingCanvas.popStyle();
- }
-
- public GraphCanvas getUnderlyingCanvas() {
- return underlyingCanvas;
- }
-
- public void write(SimplePoint point, CanvasString canvasString) {
- underlyingCanvas.write(toUnderlyingCanvas(point), canvasString);
- }
-
-
-}
diff --git a/java/src/org/singinst/uf/presenter/RelationPresentation.java b/java/src/org/singinst/uf/presenter/RelationPresentation.java deleted file mode 100644 index 763a1dd..0000000 --- a/java/src/org/singinst/uf/presenter/RelationPresentation.java +++ /dev/null @@ -1,76 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.util.List;
-
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.model.ScalarValueHolder;
-import org.singinst.uf.model.ScalarRelation;
-import org.singinst.uf.model.ValueListener;
-
-public class RelationPresentation implements ValueListener {
-
- private static final SimplePoint ORIGIN = new SimplePoint(0,0);
- private static final SimplePoint UPPER_LEFT = new SimplePoint(0,1);
- private static final SimplePoint LOWER_RIGHT = new SimplePoint(1,0);
- private final GraphCanvas viewCanvas;
- private final ScalarRelation relation;
-
- private final GraphCanvas unitPlusMarginCanvas;
- private final GraphCanvas hypothesisCanvas;
-
- public RelationPresentation(GraphCanvas viewCanvas, ScalarRelation relation) {
- this.viewCanvas = viewCanvas;
- this.relation = relation;
-
- unitPlusMarginCanvas = new ScaledCanvas(viewCanvas,
- new PlaneBounds(-0.1, 1.06, -0.1, 1.02));
- GraphCanvas unitCanvas = new ClippedCanvas(unitPlusMarginCanvas, new PlaneBounds(0, 1, 0, 1));
- hypothesisCanvas = new ScaledCanvas(unitCanvas, new PlaneBounds(relation.getDomain(), relation.getRange()));
-
- for (ScalarValueHolder scalarValueHolder : relation.getScalarValues()) {
- scalarValueHolder.addUpdateListener(this);
- }
- }
-
-
- public Runnable draw() {
- viewCanvas.clear();
-
- for (SimplePoint point : relation.decorationPoints) {
- hypothesisCanvas.pushStyle(SimpleStyle.DECORATION_POINT);
- hypothesisCanvas.drawDecorationPoint(point);
- hypothesisCanvas.popStyle();
- }
-
- drawAxes();
-
- List<? extends ScalarValuePointList> pointLists = relation.getPointLists();
- for (ScalarValuePointList pointList : pointLists) {
- if (pointList.getHypothesisPoints() == null) {
- return pointList.updater();
- }
- pointList.draw(hypothesisCanvas);
- }
- return null;
- }
-
-
- private void drawAxes() {
- unitPlusMarginCanvas.pushStyle(SimpleStyle.AXIS);
- if (relation.getDomain().isVisibleAxis()) {
- unitPlusMarginCanvas.drawLine(new SimpleLine(ORIGIN, LOWER_RIGHT));
- }
- if (relation.getRange().isVisibleAxis()) {
- unitPlusMarginCanvas.drawLine(new SimpleLine(ORIGIN, UPPER_LEFT));
- }
-
- AxisDirection.X.draw(hypothesisCanvas, relation);
- AxisDirection.Y.draw(hypothesisCanvas, relation);
-
- unitPlusMarginCanvas.popStyle();
- }
-
- public void fireUpdate(double value) {
- viewCanvas.invalidate();
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/ScalarValuePointList.java b/java/src/org/singinst/uf/presenter/ScalarValuePointList.java deleted file mode 100644 index a7fc8e0..0000000 --- a/java/src/org/singinst/uf/presenter/ScalarValuePointList.java +++ /dev/null @@ -1,38 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.util.List;
-
-import org.singinst.uf.math.SimplePoint;
-
-
-public class ScalarValuePointList {
-
- private List<SimplePoint> hypothesisPoints;
- private final SimpleStyle style;
-
- public ScalarValuePointList() {
- this(null);
- }
-
- public ScalarValuePointList(SimpleStyle style) {
- this.style = style;
- }
-
- public void setHypothesisPoints(List<SimplePoint> hypothesisPoints) {
- this.hypothesisPoints = hypothesisPoints;
- }
-
- public void draw(GraphCanvas canvas) {
- canvas.pushStyle(style);
- canvas.drawCurve(getHypothesisPoints());
- canvas.popStyle();
- }
-
- public List<SimplePoint> getHypothesisPoints() {
- return hypothesisPoints;
- }
-
- public Runnable updater() {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/ScaledCanvas.java b/java/src/org/singinst/uf/presenter/ScaledCanvas.java deleted file mode 100644 index 1e6d061..0000000 --- a/java/src/org/singinst/uf/presenter/ScaledCanvas.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.singinst.uf.presenter;
-
-
-public class ScaledCanvas extends ProxyCanvas {
-
- private final PlaneBounded ourBounds;
-
- public ScaledCanvas(GraphCanvas underlyingCanvas, PlaneBounded us) {
- super(underlyingCanvas);
- this.ourBounds = us.getPlaneBounds();
- }
-
- protected GraphTransform proxyToUnderlyingCanvas() {
- return new GraphTransform(ourBounds, getUnderlyingCanvas());
- }
-
- public PlaneBounds getPlaneBounds() {
- return ourBounds.getPlaneBounds();
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/SimpleLine.java b/java/src/org/singinst/uf/presenter/SimpleLine.java deleted file mode 100644 index 3f2d545..0000000 --- a/java/src/org/singinst/uf/presenter/SimpleLine.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.singinst.uf.presenter;
-
-import org.singinst.uf.math.SimplePoint;
-
-public class SimpleLine {
-
- public final SimplePoint p1;
- public final SimplePoint p2;
-
- public SimpleLine(SimplePoint p1, SimplePoint p2) {
- this.p1 = p1;
- this.p2 = p2;
- }
-
- public static SimpleLine vertical(double x, double y1, double y2) {
- return new SimpleLine(new SimplePoint(x, y1), new SimplePoint(x, y2));
- }
-
- public static SimpleLine horizontal(double x1, double x2, double y) {
- return new SimpleLine(new SimplePoint(x1, y), new SimplePoint(x2, y));
- }
-
-}
diff --git a/java/src/org/singinst/uf/presenter/SimpleStyle.java b/java/src/org/singinst/uf/presenter/SimpleStyle.java deleted file mode 100644 index f3846d8..0000000 --- a/java/src/org/singinst/uf/presenter/SimpleStyle.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.singinst.uf.presenter;
-
-import org.singinst.uf.model.SimpleColor;
-
-public class SimpleStyle {
-
- private final SimpleColor color;
- private final boolean dottedLine;
-
- public SimpleStyle(SimpleColor color) {
- this(color, false);
- }
-
- public SimpleStyle(SimpleColor color, boolean dottedLine) {
- this.color = color;
- this.dottedLine = dottedLine;
- }
-
- public static final SimpleStyle DECORATION_POINT = new SimpleStyle(SimpleColor.LIGHT_GRAY);
- public static final SimpleStyle AXIS = new SimpleStyle(SimpleColor.LIGHT_GRAY);
- public static final SimpleStyle PLAIN = new SimpleStyle(SimpleColor.BLACK);
-
- public SimpleColor getColor() {
- return color;
- }
-
- public boolean isDottedLine() {
- return dottedLine;
- }
-
-}
diff --git a/java/src/org/singinst/uf/presenter/Status.java b/java/src/org/singinst/uf/presenter/Status.java deleted file mode 100644 index 6acb276..0000000 --- a/java/src/org/singinst/uf/presenter/Status.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-
-public class Status {
- public static Status singleton = new Status();
- private String value;
-
- private PropertyChangeSupport support = new PropertyChangeSupport(this);
-
- public void setValue(String value) {
- String oldValue = this.value;
- this.value = value;
- support.firePropertyChange(new PropertyChangeEvent(this, "display", oldValue, value));
- }
-
- public String getValue() {
- return value;
- }
-
- public void addListener(PropertyChangeListener listener) {
- support.addPropertyChangeListener(listener);
- }
-
- public PropertyChangeSupport getSupport() {
- return support;
- }
-
- public void destroy() {
- support = new PropertyChangeSupport(this);
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/Store.java b/java/src/org/singinst/uf/presenter/Store.java deleted file mode 100644 index 92a79ef..0000000 --- a/java/src/org/singinst/uf/presenter/Store.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.singinst.uf.presenter;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.TreeMap;
-import java.util.Map.Entry;
-
-import org.singinst.uf.model.ScalarValueHolder;
-
-public abstract class Store {
- private static Store instance = null;
-
- public abstract Double get(String key);
- public abstract void put(String key, double value);
-
- public void loadData(String jsonSubset) {
- try {
- attemptLoad(jsonSubset);
- } catch (Exception e) {
- Status.singleton.setValue("<html>" + HtmlUtil.red("Load failed!"));
- e.printStackTrace();
- }
- }
-
- /**
- * example: {"caption": "loaded foo", "Q2-3.value": "1.35"}
- */
- private void attemptLoad(String jsonSubset) {
- Map<String, String> map = new TreeMap<String, String>();
-
- String[] properties = jsonSubset.replaceFirst("\\{(.+)\\}", "$1").split("\\,");
- for (String property : properties) {
- String[] keyValue = property.split("\\:");
- String key = scrub(keyValue[0]);
- String value = scrub(keyValue[1]);
- map.put(key, value);
- }
- String caption = map.remove("caption");
- if (caption == null) {
- caption = "loaded: " + map.toString();
- }
- for (Entry<String, String> e: map.entrySet()) {
-
- ScalarValueHolder.findById(e.getKey()).setValue(Double.valueOf(e.getValue()));
- }
- Status.singleton.setValue(caption);
- }
-
- private String scrub(String string) {
- return string.trim().replaceFirst("\\\"(.+)\\\"", "$1").replaceFirst("\\'(.+)\\'", "$1");
- }
-
- public static void setInstance(Store instance) {
- Store.instance = instance;
- }
- public static Store getInstance() {
- return instance;
- }
-}
diff --git a/java/src/org/singinst/uf/presenter/UfHelp.java b/java/src/org/singinst/uf/presenter/UfHelp.java deleted file mode 100644 index a85e783..0000000 --- a/java/src/org/singinst/uf/presenter/UfHelp.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.singinst.uf.presenter;
-
-public class UfHelp {
-
- public static String getMainHelpString() {
- return "TODO: initial help text";
- }
-
-}
diff --git a/java/src/org/singinst/uf/view/AppletBrowser.java b/java/src/org/singinst/uf/view/AppletBrowser.java deleted file mode 100644 index 637d125..0000000 --- a/java/src/org/singinst/uf/view/AppletBrowser.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.singinst.uf.view;
-
-import java.applet.Applet;
-
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.html.HTMLDocument;
-
-import com.sun.java.browser.dom.DOMAccessor;
-import com.sun.java.browser.dom.DOMAction;
-import com.sun.java.browser.dom.DOMService;
-
-public class AppletBrowser {
-
-
- private DOMService service;
- private static AppletBrowser instance;
- private final Applet applet;
- public AppletBrowser(Applet applet) {
- this.applet = applet;
- try {
- service = DOMService.getService(applet);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public void loadPage(final String helpName) {
- if (service != null) {
- try {
- service.invokeAndWait(new DOMAction()
- {
- public Object run(DOMAccessor accessor)
- {
- HTMLDocument doc = (HTMLDocument) accessor.getDocument(applet);
- Element element = doc.getElementById("sidebar");
- //for (int i = 0; i < nodeList.getLength(); i++) {
- //Node node = nodeList.item(i);
- //if (node instanceof Element) {
- //Element element = (Element) node;
- if (element.getAttribute("name").startsWith("ufHelp")) {
- String pageName = "ufHelp/" + helpName + ".html";
- element.setAttribute("src", pageName);
- }
- //}
- //}
- return null;
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- public static void init(Applet applet) {
- instance = new AppletBrowser(applet);
- }
-
- public static AppletBrowser getInstance() {
- return instance;
- }
-
-}
diff --git a/java/src/org/singinst/uf/view/AppletStore.java b/java/src/org/singinst/uf/view/AppletStore.java deleted file mode 100644 index 344bc92..0000000 --- a/java/src/org/singinst/uf/view/AppletStore.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.singinst.uf.view;
-
-import java.applet.AppletContext;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.UnsupportedEncodingException;
-
-import org.singinst.uf.presenter.Store;
-
-public class AppletStore extends Store {
-
- private final AppletContext appletContext;
-
- public AppletStore(AppletContext appletContext) {
- this.appletContext = appletContext;
- }
-
- @Override
- public Double get(String key) {
- InputStream stream = appletContext.getStream(key);
- if (stream == null) {
- return null;
- }
- try {
- String string = new BufferedReader(new InputStreamReader(stream, "UTF-8")).readLine();
- return Double.valueOf(string);
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void put(String key, double value) {
- try {
- appletContext.setStream(key, new ByteArrayInputStream(("" + value).getBytes("UTF-8")));
- } catch (UnsupportedEncodingException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
-}
diff --git a/java/src/org/singinst/uf/view/Graph.java b/java/src/org/singinst/uf/view/Graph.java deleted file mode 100644 index 629fcca..0000000 --- a/java/src/org/singinst/uf/view/Graph.java +++ /dev/null @@ -1,96 +0,0 @@ -package org.singinst.uf.view;
-
-import java.awt.Component;
-import java.awt.Dimension;
-import java.awt.Graphics;
-import java.awt.Graphics2D;
-
-import javax.swing.JPanel;
-
-import org.singinst.uf.model.ScalarRelation;
-import org.singinst.uf.presenter.RelationPresentation;
-
-public class Graph {
-
- private final SwingGraphCanvas swingGraphCanvas;
- private final RelationPresentation relationPresentation;
- private final JPanel panel;
-
- @SuppressWarnings("serial")
- public Graph(final ScalarRelation relation) {
- swingGraphCanvas = new SwingGraphCanvas();
- relationPresentation = new RelationPresentation(swingGraphCanvas, relation);
- panel = new JPanel() {
- @Override
- protected void paintComponent(Graphics g) {
- swingGraphCanvas.setGraphics((Graphics2D) g);
- swingGraphCanvas.setSize(getSize());
- final Runnable updater = relationPresentation.draw();
- if (updater != null) {
- new Thread(new Runnable() {
- public void run() {
- updater.run();
- panel.invalidate();
- }
- }).start();
- }
- }
- };
- panel.setMinimumSize(new Dimension(500, 400));
- panel.setPreferredSize(new Dimension(500, 400));
- swingGraphCanvas.setPanel(panel);
-
- }
-
- public Component getPanel() {
- return panel;
-// for (GraphLine graphLine : modelBean.getInitializedGraphLines()) {
-// double startDrawingPoint = graphLine.getStartDrawingPoint();
-// drawGraph(g2, graphLine, startDrawingPoint, 1);
-// drawGraph(g2, graphLine, startDrawingPoint, 0);
-// }
-
-// g2.draw(GraphUtil.line(new Line2D.Double(new UnitGraph(xUserSpace(0), yUserSpace(1), xUserSpace(1), yUserSpace(1)));
-// if (!model.getModelBean().getUnitSmallTickListY().isEmpty()) {
-// g2.draw(new Line2D.Double(xUserSpace(0), yUserSpace(1), xUserSpace(0), yUserSpace(0)));
-// }
-//
-// for (double smallTickX : model.getModelBean().getUnitSmallTickListX()) {
-// g2.draw(new Line2D.Double(xUserSpace(smallTickX), yUserSpace(1 + 0.02), xUserSpace(smallTickX), yUserSpace(1 - 0.02)));
-// }
-//
-// FontRenderContext frc = g2.getFontRenderContext();
-// for (LabeledTick labelX : model.getModelBean().getUnitLabeledTickListX()) {
-// double unitX = labelX.getUnitCoordinate();
-// g2.draw(new Line2D.Double(xUserSpace(unitX), yUserSpace(1 + 0.05), xUserSpace(unitX), yUserSpace(1 - 0.05)));
-// TextLayout textLayout = new TextLayout(labelX.getAttributedCharacterIterator(), frc);
-// textLayout.draw(g2, (float) xUserSpace(unitX), (float) yUserSpace(1 - 0.05));
-// }
-//
-// for (double smallTickY : model.getModelBean().getUnitSmallTickListY()) {
-// g2.draw(new Line2D.Double(xUserSpace(-0.02), yUserSpace(smallTickY), xUserSpace(0.02), yUserSpace(smallTickY)));
-// }
-//
-// for (LabeledTick labelY : model.getModelBean().getUnitLabeledTickListY()) {
-// double unitY = labelY.getUnitCoordinate();
-// g2.draw(new Line2D.Double(xUserSpace(-0.05), yUserSpace(unitY), xUserSpace(0.05), yUserSpace(unitY)));
-// TextLayout textLayout = new TextLayout(labelY.getAttributedCharacterIterator(), frc);
-// textLayout.draw(g2, (float) xUserSpace(-0.05), (float) yUserSpace(unitY));
-// }
-//
-// double dotSize = 1;
-// for (GraphObservationPoint gop : model.getModelBean().decorationPointSet()) {
-// g2.draw(new Ellipse2D.Double(
-// xUserSpace(gop.getUnitX()) - dotSize / 2, yUserSpace(gop.getUnitY()) - dotSize / 2, dotSize, dotSize));
-// }
-//
-// g2.setFont(g2.getFont().deriveFont(Font.ITALIC));
-// String xUnitLabel = model.getModelBean().xUnitLabel();
-//
-// g2.drawString(xUnitLabel, (float) xUserSpace(0.5), (float) yUserSpace(1 + 0.10));
-//
-// String yUnitLabel = model.getModelBean().yUnitLabel();
-// g2.drawString(yUnitLabel, (float) xUserSpace(-0.10), (float) yUserSpace(0.5));
- }
-
-}
diff --git a/java/src/org/singinst/uf/view/MainWindow.java b/java/src/org/singinst/uf/view/MainWindow.java deleted file mode 100644 index 2da47d8..0000000 --- a/java/src/org/singinst/uf/view/MainWindow.java +++ /dev/null @@ -1,302 +0,0 @@ -package org.singinst.uf.view;
-
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Component;
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseAdapter;
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.swing.BorderFactory;
-import javax.swing.Box;
-import javax.swing.JButton;
-import javax.swing.JFormattedTextField;
-import javax.swing.JLabel;
-import javax.swing.JPanel;
-import javax.swing.JProgressBar;
-import javax.swing.JSlider;
-import javax.swing.JTabbedPane;
-import javax.swing.JTextArea;
-import javax.swing.RootPaneContainer;
-import javax.swing.SwingConstants;
-import javax.swing.border.Border;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-import org.singinst.uf.model.ConclusionReportGenerator;
-import org.singinst.uf.model.ScalarValueHolder;
-import org.singinst.uf.model.NodeMetadata;
-import org.singinst.uf.model.NodeMetadataFactory;
-import org.singinst.uf.model.ScalarSchema;
-import org.singinst.uf.model.ScalarRelation;
-import org.singinst.uf.model.SummarySource;
-import org.singinst.uf.model.ValueListener;
-import org.singinst.uf.presenter.Completion;
-import org.singinst.uf.presenter.LineBounds;
-import org.singinst.uf.presenter.NumericEntry;
-import org.singinst.uf.presenter.Status;
-
-class MainWindow {
- // TODO5
- // Required for adding actionlisteners to the previous and next buttons
- private JTabbedPane pane;
-
- Container createContainer() {
- JPanel mainPanel = new JPanel(new BorderLayout());
- mainPanel.setBorder(border());
-
- List<NodeMetadata> nodeMetadataObjs = NodeMetadataFactory.createTheNetwork();
-
- final ArrayList<String> nodeNames = new ArrayList<String>();
- pane = new JTabbedPane();
-
- for (NodeMetadata nodeMetadata : nodeMetadataObjs) {
- pane.addTab(nodeMetadata.getNode().getIdString(), createPane(nodeMetadata, nodeNames));
- nodeNames.add(nodeMetadata.getNode().getIdString());
- }
- pane.setSelectedIndex(0);
-
- pane.addChangeListener(new ChangeListener() {
-
- public void stateChanged(ChangeEvent e) {
- AppletBrowser.getInstance().loadPage(nodeNames.get(pane.getSelectedIndex()));
- Status.singleton.setValue("");
- }
-
- });
-
- mainPanel.add(pane, BorderLayout.CENTER);
-
-// pane.setSelectedIndex(pane.getComponentCount() - 1);
- return mainPanel;
- }
-
- private Border border() {
- return BorderFactory.createEmptyBorder(3, 3, 3, 3);
- }
-
- private Border largeBorder() {
- return BorderFactory.createEmptyBorder(12, 12, 12, 12);
- }
-
- private Component createPane(final NodeMetadata nodeMetadata, final ArrayList<String> nodeNames) {
- Box vertical = Box.createVerticalBox();
- vertical.setBorder(border());
- vertical.setName(nodeMetadata.getNode().getIdString());
-
- Box summaries = Box.createVerticalBox();
- JPanel panePanel = new JPanel(new BorderLayout());
-
- panePanel.add(createUserQuestion(nodeMetadata, nodeNames), BorderLayout.NORTH);
- for (ScalarSchema simpleScalar : nodeMetadata.getSimpleScalars()) {
- vertical.add(createGraph(simpleScalar));
- for (Component summary : createSummaries(simpleScalar)) {
- summaries.add(summary);
- }
- }
- for (ScalarRelation relation : nodeMetadata.getScalarRelations()) {
- vertical.add(createGraph(relation));
- for (Component summary : createSummaries(relation)) {
- summaries.add(summary);
- }
- }
-
- //if (nodeMetadata.getNode().getIdString() != "A6")
- addProperties(nodeMetadata, vertical, nodeNames);
- vertical.add(summaries);
-
- Box statusBox = Box.createHorizontalBox();
- statusBox.setBorder(largeBorder());
- final JLabel label = new JLabel("Application loaded.");
- statusBox.add(label);
- Status.singleton.addListener(new PropertyChangeListener() {
-
- public void propertyChange(PropertyChangeEvent evt) {
- label.setText(Status.singleton.getValue());
- }
-
- });
- vertical.add(statusBox);
-
-// Box helpBox = Box.createHorizontalBox();
-// helpBox.setBorder(largeBorder());
-// JButton helpButton = new JButton("Help");
-// helpButton.addActionListener(new ActionListener() {
-// public void actionPerformed(ActionEvent e) {
-// SwingHelp.getInstance().help(nodeMetadata.getUserText().getHelp());
-// }
-// });
-// helpBox.add(helpButton);
-// vertical.add(helpBox);
-
- vertical.add(Box.createGlue());
- panePanel.add(vertical, BorderLayout.CENTER);
- return panePanel;
- }
-
- private void addProperties(NodeMetadata nodeMetadata, Box vertical, final ArrayList<String> nodeNames) {
- Box properties = null;
-
- int i = 0;
- for (ScalarSchema scalarSchema : nodeMetadata.getScalars()) {
- if (i % 3 == 0) {
- properties = attachHorizontalBox(vertical);
- }
- Component newProp = createPropertyPanel(scalarSchema);
- if (newProp != null) {
- properties.add(newProp);
- i++;
- }
- }
- }
-
- private Box attachHorizontalBox(Box vertical) {
- Box properties = Box.createHorizontalBox();
- vertical.add(properties);
- return properties;
- }
-
- private Component createGraph(ScalarRelation relation) {
- return new Graph(relation).getPanel();
- }
-
-
- private List<Component> createSummaries(final SummarySource summarySource) {
- final List<Component> labels = new ArrayList<Component>();
- for (final ConclusionReportGenerator conclusionReportGenerator : summarySource.getConclusionGenerators()) {
- final JLabel label = new JLabel("<html>Calculating...<br></html>");
- label.setMinimumSize(new Dimension(100, 15));
- label.setHorizontalAlignment(SwingConstants.CENTER);
- label.setAlignmentX(0.5f);
- labels.add(label);
- for (final ScalarValueHolder scalarValueHolder : summarySource.getScalarValues()) {
- scalarValueHolder.addUpdateListener(new ValueListener() {
- public void fireUpdate(double value) {
- String text = conclusionReportGenerator.getText(scalarValueHolder, value);
- label.setText("<html>" + text + "</html>");
- }
- });
- }
- }
- return labels;
- }
-
- private Component createUserQuestion(NodeMetadata nodeMetadata, final ArrayList<String> nodeNames) {
- //JLabel question = new JLabel(nodeMetadata.getUserText().getQuestion(), SwingConstants.CENTER);
- JLabel question = new JLabel(nodeMetadata.getUserText().getQuestion());
- //question.setEditable(false);
- question.setForeground(Color.RED);
- //question.setLineWrap(true);
- //question.setWrapStyleWord(true);
- question.setMaximumSize(question.getPreferredSize());
-
- JPanel prevQuestionNextBox = new JPanel(new BorderLayout());//Box.createHorizontalBox();
-
- JButton prev = new JButton("Previous");
- prev.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int index = pane.getSelectedIndex();
- if (index > 0) {
- AppletBrowser.getInstance().loadPage(nodeNames.get(index-1));
- pane.setSelectedIndex(index-1);
- }
- Status.singleton.setValue("");
- }
-
- });
- prevQuestionNextBox.add(prev, BorderLayout.WEST);
-
- prevQuestionNextBox.add(question, BorderLayout.CENTER);
-
- JButton next = new JButton("Next");
- next.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- int index = pane.getSelectedIndex();
- if (index+1 < nodeNames.size()) {
- AppletBrowser.getInstance().loadPage(nodeNames.get(index+1));
- pane.setSelectedIndex(index+1);
- }
- Status.singleton.setValue("");
- }
-
- });
- prevQuestionNextBox.add(next, BorderLayout.EAST);
-
- return prevQuestionNextBox;
- }
-
- /**
- *
- *
- * @param scalarSchema
- * @return
- * THe new property to add if scalarSchema.visibleProperty is set to true, else returns null.
- */
- private Component createPropertyPanel(ScalarSchema scalarSchema) {
- if (!scalarSchema.displayProperty())
- return null;
- JFormattedTextField propertyValueDisplay = new JFormattedTextField(
- NumericEntry.getScalarFormat());
- propertyValueDisplay.setColumns(NumericEntry.maxColumns());
- propertyValueDisplay.setHorizontalAlignment(SwingConstants.RIGHT);
- propertyValueDisplay.setMaximumSize(propertyValueDisplay.getMinimumSize());
-
- Box propertyPanel = Box.createHorizontalBox();
- propertyPanel.add(new JLabel("<html>" + scalarSchema.getPrefix() + "</html>", SwingConstants.RIGHT));
- propertyPanel.add(propertyValueDisplay);
- propertyPanel.add(new JLabel(scalarSchema.getUnit() + scalarSchema.getSuffix()));
- propertyPanel.setAlignmentX(0.5f);
- propertyPanel.setBorder(largeBorder());
- propertyPanel.setMaximumSize(propertyPanel.getPreferredSize());
-
- new TextScalarBinder().bind(scalarSchema.getScalarValueHolder(), propertyValueDisplay);
- propertyPanel.setPreferredSize(propertyPanel.getMinimumSize());
- return propertyPanel;
- }
-
- private Component createGraph(ScalarSchema scalarSchema) {
- LineBounds bounds = scalarSchema.getLineBounds();
- JSlider slider = new JSlider((int) bounds.getLowerBound(), (int) bounds.getUpperBound());
- new RangeScalarBinder().bind(scalarSchema.getScalarValueHolder(), slider.getModel());
- return slider;
- }
-
- public Component createGlassPane(final RootPaneContainer container) {
- final JPanel glassPane = new JPanel();
- final JProgressBar bar = new JProgressBar();
- final JLabel label = new JLabel();
- glassPane.add(label);
- glassPane.add(bar);
- glassPane.addMouseListener(new MouseAdapter() {});
- final Completion completion = Completion.getInstance();
- // TODO5 update listener
- completion.addUpdateListener(new ValueListener() {
- public void fireUpdate(double value) {
- if (value == 0) {
- container.setGlassPane(glassPane);
- glassPane.setVisible(true);
- }
-
- int completed = completion.getCompleted();
- int numStages = completion.getNumStages();
- if (completed < numStages) {
- label.setText(completion.getDisplay());
- bar.setMaximum(numStages);
- bar.setValue(completed);
- } else {
- glassPane.setVisible(false);
- }
- }
-
- });
- return glassPane;
- }
-
-
-}
diff --git a/java/src/org/singinst/uf/view/RangeScalarBinder.java b/java/src/org/singinst/uf/view/RangeScalarBinder.java deleted file mode 100644 index cb13478..0000000 --- a/java/src/org/singinst/uf/view/RangeScalarBinder.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.singinst.uf.view;
-
-import javax.swing.BoundedRangeModel;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
-
-import org.singinst.uf.model.ScalarValueHolder;
-import org.singinst.uf.model.ValueListener;
-
-public class RangeScalarBinder {
-
- public void bind(final ScalarValueHolder scalarValueHolder, final BoundedRangeModel model) {
- scalarValueHolder.addUpdateListener(new ValueListener() {
- public void fireUpdate(double value) {
- model.setValue((int)value);
- }
- });
-
- model.addChangeListener(new ChangeListener() {
- public void stateChanged(ChangeEvent e) {
- scalarValueHolder.setValue((double) model.getValue());
- }
-
- });
-
- }
-
-}
diff --git a/java/src/org/singinst/uf/view/SwingGraphCanvas.java b/java/src/org/singinst/uf/view/SwingGraphCanvas.java deleted file mode 100644 index 9df55b8..0000000 --- a/java/src/org/singinst/uf/view/SwingGraphCanvas.java +++ /dev/null @@ -1,241 +0,0 @@ -package org.singinst.uf.view;
-
-import java.awt.BasicStroke;
-import java.awt.Dimension;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.awt.font.FontRenderContext;
-import java.awt.font.TextAttribute;
-import java.awt.font.TextLayout;
-import java.awt.geom.Ellipse2D;
-import java.awt.geom.GeneralPath;
-import java.awt.geom.Line2D;
-import java.awt.geom.Point2D;
-import java.text.AttributedCharacterIterator;
-import java.text.AttributedString;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.Stack;
-
-import javax.swing.JPanel;
-
-import org.singinst.uf.math.SimplePoint;
-import org.singinst.uf.presenter.CanvasString;
-import org.singinst.uf.presenter.GraphCanvas;
-import org.singinst.uf.presenter.MouseClickListener;
-import org.singinst.uf.presenter.MouseDragListener;
-import org.singinst.uf.presenter.PlaneBounds;
-import org.singinst.uf.presenter.SimpleLine;
-import org.singinst.uf.presenter.SimpleStyle;
-
-public class SwingGraphCanvas implements GraphCanvas, MouseListener, MouseMotionListener {
-
- private Graphics2D g2;
- private Stack<SwingStyle> styleStack;
- private Dimension size;
- private PlaneBounds bounds;
- private final Set<MouseDragListener> dragListeners = new HashSet<MouseDragListener>();
- private final Set<MouseClickListener> clickListeners = new HashSet<MouseClickListener>();
- private JPanel panel;
- private MouseDragListener selectedDragListener;
-
- public SwingGraphCanvas() {
-// MainWindow.pane.addChangeListener(new ChangeListener() {
-//
-// public void stateChanged(ChangeEvent e) {
-//// dragListeners.clear();
-//// clickListeners.clear();
-// }
-//
-// });
- }
-
- public void setPanel(JPanel panel) {
- this.panel = panel;
- }
-
- public void setGraphics(Graphics2D g2) {
- this.g2 = g2;
- this.styleStack = new Stack<SwingStyle>();
- styleStack.push(new SwingStyle(g2));
- }
-
- public void setSize(Dimension size) {
- this.size = size;
- this.bounds = new PlaneBounds(0, size.width, size.height, 0);
- }
-
- public void clear() {
- g2.clearRect(0,0,size.width,size.height);
- }
-
- public void drawLine(SimpleLine line) {
- g2.draw(new Line2D.Double(point(line.p1), point(line.p2)));
- }
-
- private Point2D point(SimplePoint p) {
- return new Point2D.Double(p.x, p.y);
- }
-
- public void drawDecorationPoint(SimplePoint point) {
- double dotDiameter = size.width / 200;
- double dotRadius = dotDiameter / 2;
- g2.draw(new Ellipse2D.Double(point.x - dotRadius, point.y - dotRadius, dotDiameter, dotDiameter));
- }
-
- public PlaneBounds getPlaneBounds() {
- return bounds;
- }
-
- public void drawCurve(List<SimplePoint> points) {
- if (points.isEmpty()) {
- return;
- }
- GeneralPath curve = new GeneralPath();
- Iterator<SimplePoint> iterator = points.iterator();
- curveMoveTo(curve, iterator.next());
- while (iterator.hasNext()) {
- curveLineTo(curve, iterator.next());
- }
- g2.draw(curve);
-
- }
-
- private void curveLineTo(GeneralPath curve, SimplePoint point) {
- curve.lineTo((float) point.x, (float) point.y);
- }
-
- private void curveMoveTo(GeneralPath curve, SimplePoint point) {
- curve.moveTo((float) point.x, (float) point.y);
- }
-
- public void addMouseClickListener(MouseClickListener listener) {
- clickListeners.add(listener);
- if (dragListeners.size() + dragListeners.size() > 1) {
- throw new UnsupportedOperationException();
- }
- panel.addMouseListener(this);
- }
-
- public void addMouseDragListener(MouseDragListener listener) {
- dragListeners.add(listener);
- if (dragListeners.size() + clickListeners.size() > 1) {
- throw new UnsupportedOperationException();
- }
- panel.addMouseListener(this);
- panel.addMouseMotionListener(this);
- }
-
- public void mouseClicked(MouseEvent e) {
- }
-
- public void mouseEntered(MouseEvent e) {
-
- }
-
- public void mouseExited(MouseEvent e) {
- selectedDragListener = null;
- }
-
- public void mousePressed(MouseEvent e) {
- for (MouseClickListener listener : clickListeners) {
- listener.mouseClick(simplePoint(e.getPoint()));
- }
- if (dragListeners.size() > 0) {
- MouseDragListener dragListener = dragListeners.iterator().next();
- int priority = dragListener.mouseDown(simplePoint(e.getPoint()));
- if (priority > 0) {
- selectedDragListener = dragListener;
- }
- }
- }
-
- public void mouseReleased(MouseEvent e) {
- if (selectedDragListener != null) {
- selectedDragListener.dragTo(simplePoint(e.getPoint()));
- selectedDragListener = null;
- }
- }
-
- public void mouseDragged(MouseEvent e) {
- if (selectedDragListener != null) {
- selectedDragListener.dragTo(simplePoint(e.getPoint()));
- }
- }
-
- private SimplePoint simplePoint(Point point) {
- return new SimplePoint(point.getX(), point.getY());
- }
-
- public void mouseMoved(MouseEvent e) {
- }
-
- public void invalidate() {
- if (panel != null) {
- panel.repaint();
- }
- }
-
-
-
- public void popStyle() {
- styleStack.pop();
- setStyle(styleStack.peek());
- }
-
-
-
- private void setStyle(SwingStyle style) {
- g2.setColor(style.getColor());
- if (style.isDottedLine()) {
- g2.setStroke(new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, 10, new float[] {2}, 0));
- } else {
- g2.setStroke(new BasicStroke());
- }
- }
-
- public void pushStyle(SimpleStyle style) {
- SwingStyle swingStyle;
- if (style == null) {
- swingStyle = styleStack.peek();
- } else {
- swingStyle = new SwingStyle(style);
- }
- styleStack.push(swingStyle);
- setStyle(swingStyle);
- }
-
-
-
- public void write(SimplePoint point, CanvasString canvasString) {
- FontRenderContext frc = g2.getFontRenderContext();
- TextLayout textLayout = new TextLayout(getAttributedCharacterIterator(canvasString), frc);
- textLayout.draw(g2, (float) point.x, (float) point.y);
- }
-
- private AttributedCharacterIterator getAttributedCharacterIterator(
- CanvasString canvasString) {
- String main = canvasString.getMain();
- String optionalPower = canvasString.getOptionalPower();
- AttributedString string;
- if (optionalPower == null) {
- string = new AttributedString(main);
- } else {
- if (ViewUtil.renderExponentsAsSuperscript()) {
- String plainText = main + optionalPower;
- string = new AttributedString(plainText);
- string.addAttribute(TextAttribute.SUPERSCRIPT, TextAttribute.SUPERSCRIPT_SUPER, main.length(), plainText.length());
- } else {
- string = new AttributedString(main + "^" + optionalPower);
- }
- }
- string.addAttribute(TextAttribute.SIZE, 18f);
- return string.getIterator();
- }
-
-}
diff --git a/java/src/org/singinst/uf/view/SwingHelp.java b/java/src/org/singinst/uf/view/SwingHelp.java deleted file mode 100644 index 9d22307..0000000 --- a/java/src/org/singinst/uf/view/SwingHelp.java +++ /dev/null @@ -1,63 +0,0 @@ -package org.singinst.uf.view;
-
-import java.awt.BorderLayout;
-import java.awt.Component;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseAdapter;
-
-import javax.swing.Box;
-import javax.swing.JButton;
-import javax.swing.JEditorPane;
-import javax.swing.JPanel;
-import javax.swing.JScrollPane;
-import javax.swing.RootPaneContainer;
-
-public class SwingHelp {
- private static final SwingHelp instance = new SwingHelp();
- private final JPanel helpPanel = new JPanel(new BorderLayout());
- private final JEditorPane helpText = new JEditorPane();
- private RootPaneContainer root;
- private Component oldGlassPane;
-
- public void init(final RootPaneContainer root, String mainHelpString) {
- this.root = root;
- helpText.setEditable(false);
- helpText.setContentType("text/html");
- helpPanel.add(new JScrollPane(helpText));
- helpPanel.addMouseListener(new MouseAdapter() {});
- Box southBox = Box.createHorizontalBox();
-
- JButton helpButton = new JButton("OK");
- helpButton.setAlignmentX(Component.CENTER_ALIGNMENT);
- helpButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- root.setGlassPane(oldGlassPane);
- oldGlassPane.setVisible(false);
- }
-
- });
-
- southBox.add(Box.createHorizontalGlue());
- southBox.add(helpButton);
- southBox.add(Box.createHorizontalGlue());
- helpPanel.add(southBox, BorderLayout.SOUTH);
- helpPanel.setAlignmentX(Component.CENTER_ALIGNMENT);
-
- if (mainHelpString != null) {
- help(mainHelpString);
- }
- }
-
- public void help(String helpString) {
- helpText.setText(helpString);
- oldGlassPane = root.getGlassPane();
- root.setGlassPane(helpPanel);
- helpPanel.setVisible(true);
- }
-
- public static SwingHelp getInstance() {
- return instance;
- }
-
-}
diff --git a/java/src/org/singinst/uf/view/SwingStyle.java b/java/src/org/singinst/uf/view/SwingStyle.java deleted file mode 100644 index 3b2c434..0000000 --- a/java/src/org/singinst/uf/view/SwingStyle.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.singinst.uf.view;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-
-import org.singinst.uf.model.SimpleColor;
-import org.singinst.uf.presenter.SimpleStyle;
-
-public class SwingStyle {
-
- private final Color color;
- private final boolean dottedLine;
-
- public SwingStyle(Graphics2D g2) {
- color = g2.getColor();
- // TODO5
- dottedLine = false;
- }
-
- public SwingStyle(SimpleStyle style) {
- SimpleColor simpleColor = style.getColor();
- color = new SimpleColor.Visitor<Color>() {
-
- @Override
- public Color visit_BLACK() {
- return Color.BLACK;
- }
-
- @Override
- public Color visit_GREEN() {
- return Color.GREEN;
- }
-
- @Override
- public Color visit_LIGHT_GRAY() {
- return Color.LIGHT_GRAY;
- }
-
- @Override
- public Color visit_RED() {
- return Color.RED;
- }
- }.visit(simpleColor);
-
- dottedLine = style.isDottedLine();
- }
-
- public Color getColor() {
- return color;
- }
-
- public boolean isDottedLine() {
- return dottedLine;
- }
-}
diff --git a/java/src/org/singinst/uf/view/TextScalarBinder.java b/java/src/org/singinst/uf/view/TextScalarBinder.java deleted file mode 100644 index c5d8903..0000000 --- a/java/src/org/singinst/uf/view/TextScalarBinder.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.singinst.uf.view;
-
-import java.beans.PropertyChangeEvent;
-import java.beans.PropertyChangeListener;
-import java.text.ParseException;
-
-import javax.swing.JFormattedTextField;
-
-import org.singinst.uf.common.LogUtil;
-import org.singinst.uf.model.ScalarValueHolder;
-import org.singinst.uf.model.ValueListener;
-
-public class TextScalarBinder {
- private boolean userEntry = true;
-
- public void bind(final ScalarValueHolder scalarValueHolder,
- final JFormattedTextField propertyValueDisplay) {
- scalarValueHolder.unshiftUpdateListener(new ValueListener() {
- public void fireUpdate(double value) {
- userEntry = false;
- try {
- String formattedString = scalarValueHolder.getScalar().getLineBounds().userFormat(value);
- propertyValueDisplay.setText(formattedString);
- try {
- propertyValueDisplay.commitEdit();
- } catch (ParseException e) {
- LogUtil.error(e);
- }
- } finally {
- userEntry = true;
- }
- }
- });
-
- propertyValueDisplay.addPropertyChangeListener(new PropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent evt) {
- if (userEntry) {
- if ("value".equals(evt.getPropertyName())) {
- scalarValueHolder.setValueFromUser(((Number) evt.getNewValue()).doubleValue());
- }
- }
- }
- });
- }
-
-}
diff --git a/java/src/org/singinst/uf/view/UfApplet.java b/java/src/org/singinst/uf/view/UfApplet.java deleted file mode 100644 index f71da15..0000000 --- a/java/src/org/singinst/uf/view/UfApplet.java +++ /dev/null @@ -1,102 +0,0 @@ -package org.singinst.uf.view;
-
-import java.awt.Component;
-import java.awt.Container;
-import java.awt.event.ActionListener;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.beans.PropertyChangeListener;
-
-import javax.swing.AbstractButton;
-import javax.swing.JApplet;
-import javax.swing.JPanel;
-import javax.swing.UIManager;
-
-import org.singinst.uf.model.ScalarValueHolder;
-import org.singinst.uf.presenter.Completion;
-import org.singinst.uf.presenter.Status;
-import org.singinst.uf.presenter.Store;
-
-@SuppressWarnings("serial")
-public class UfApplet extends JApplet {
-
- @Override
- public void init() {
- try {
- javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
- public void run() {
- createGUI();
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- public void loadData(String jsonSubset) {
- Store.getInstance().loadData(jsonSubset);
- }
-
- /**
- *
- */
- private void createGUI() {
- try {
- UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
- }
- catch (Exception e) {
- try {
- UIManager.setLookAndFeel("com.sun.java.swing.plaf.metal.OceanTheme");
- }
- catch (Exception e1) {}
- }
-
- Store.setInstance(new AppletStore(getAppletContext()));
- AppletBrowser.init(this);
-
- MainWindow mainWindow = new MainWindow();
- setContentPane(mainWindow.createContainer());
- JPanel glassPane = new JPanel();
- glassPane.add(mainWindow.createGlassPane(this));
- setGlassPane(glassPane);
- SwingHelp.getInstance().init(this, null);
-// SwingHelp.getInstance().init(this, UfHelp.getMainHelpString());
- }
-
- @Override
- public void destroy() {
- System.err.println("destroying applet and removing listeners");
- removeListenersAndChildren(this);
- Store.setInstance(null);
- Status.singleton.destroy();
- Completion.getInstance().destroy();
- ScalarValueHolder.destroyAll();
- }
-
- private void removeListenersAndChildren(Component component) {
- for (MouseListener listener : component.getMouseListeners()) {
- component.removeMouseListener(listener);
- }
- for (MouseMotionListener listener : component.getMouseMotionListeners()) {
- component.removeMouseMotionListener(listener);
- }
- for (PropertyChangeListener listener : component.getPropertyChangeListeners()) {
- component.removePropertyChangeListener(listener);
- }
-
- if (component instanceof AbstractButton) {
- AbstractButton button = (AbstractButton) component;
- for (ActionListener listener : button.getActionListeners()) {
- button.removeActionListener(listener);
- }
- }
-
- if (component instanceof Container) {
- Container container = (Container) component;
- for (Component child : container.getComponents()) {
- removeListenersAndChildren(child);
- remove(child);
- }
- }
- }
-}
diff --git a/java/src/org/singinst/uf/view/ViewUtil.java b/java/src/org/singinst/uf/view/ViewUtil.java deleted file mode 100644 index ce4c843..0000000 --- a/java/src/org/singinst/uf/view/ViewUtil.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.singinst.uf.view;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-
-public class ViewUtil {
- private static Boolean isApple = isApple();
-
- public static boolean renderExponentsAsSuperscript() {
- return !isApple;
- }
-
- private static URL apple() throws MalformedURLException {
- return new URL("http://apple.com/");
- }
-
- private static boolean isApple() {
- try {
- // this seems surprisingly slow on FireFox, try to only call it once
- return apple().equals(new URL(System.getProperty("java.vendor.url")));
- } catch (MalformedURLException e) {
- throw new RuntimeException(e);
- }
- }
-}
|