summaryrefslogtreecommitdiff
path: root/gi/posterior-regularisation/prjava/src/optimization/util/Interpolation.java
diff options
context:
space:
mode:
authordesaicwtf <desaicwtf@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-09 16:59:55 +0000
committerdesaicwtf <desaicwtf@ec762483-ff6d-05da-a07a-a48fb63a330f>2010-07-09 16:59:55 +0000
commitbdea91300c85539ab7153ccba58689612f66bb4d (patch)
treee778ffa1ea4d04a239b58c6e6191c0d4549006f0 /gi/posterior-regularisation/prjava/src/optimization/util/Interpolation.java
parent0d1d84630a08f1c901cf09b4bcc9356c4165302f (diff)
add optimization library source code
git-svn-id: https://ws10smt.googlecode.com/svn/trunk@204 ec762483-ff6d-05da-a07a-a48fb63a330f
Diffstat (limited to 'gi/posterior-regularisation/prjava/src/optimization/util/Interpolation.java')
-rw-r--r--gi/posterior-regularisation/prjava/src/optimization/util/Interpolation.java37
1 files changed, 37 insertions, 0 deletions
diff --git a/gi/posterior-regularisation/prjava/src/optimization/util/Interpolation.java b/gi/posterior-regularisation/prjava/src/optimization/util/Interpolation.java
new file mode 100644
index 00000000..cdbdefc6
--- /dev/null
+++ b/gi/posterior-regularisation/prjava/src/optimization/util/Interpolation.java
@@ -0,0 +1,37 @@
+package optimization.util;
+
+public class Interpolation {
+
+ /**
+ * Fits a cubic polinomyal to a function given two points,
+ * such that either gradB is bigger than zero or funcB >= funcA
+ *
+ * NonLinear Programming appendix C
+ * @param funcA
+ * @param gradA
+ * @param funcB
+ * @param gradB
+ */
+ public final static double cubicInterpolation(double a,
+ double funcA, double gradA, double b,double funcB, double gradB ){
+ if(gradB < 0 && funcA > funcB){
+ System.out.println("Cannot call cubic interpolation");
+ return -1;
+ }
+
+ double z = 3*(funcA-funcB)/(b-a) + gradA + gradB;
+ double w = Math.sqrt(z*z - gradA*gradB);
+ double min = b -(gradB+w-z)*(b-a)/(gradB-gradA+2*w);
+ return min;
+ }
+
+ public final static double quadraticInterpolation(double initFValue,
+ double initGrad, double point,double pointFValue){
+ double min = -1*initGrad*point*point/(2*(pointFValue-initGrad*point-initFValue));
+ return min;
+ }
+
+ public static void main(String[] args) {
+
+ }
+}