Example #1
0
  @Override
  public Double set(int index, Double element) {
    if (index < n) stateIn.setEntry(index, element);
    else if (index < n + h) stateHidden.setEntry(index - n, element);
    else stateOut.setEntry(index - n - h, element);

    return element;
  }
Example #2
0
  @Override
  public void step() {
    stateHidden.setSubVector(0, weights0.operate(stateIn));

    for (int i : series(h)) stateHidden.setEntry(i, activation.function(stateHidden.getEntry(i)));

    stateOut.setSubVector(0, weights1.operate(stateHidden));
  }
Example #3
0
 public static RealVector randVector(int dim) {
   Random r = new Random();
   r.setSeed(System.currentTimeMillis());
   RealVector res = MathFactory.createRealVector(dim);
   for (int i = 0; i < dim; i++) {
     res.setEntry(i, r.nextDouble());
   }
   return res;
 }
 public RepeatingLSH(List<LSH> lshList) throws MathException {
   super(lshList.get(0).getDim(), lshList.get(0).getRandomGenerator());
   this.lshList = lshList;
   RandomGenerator rg = lshList.get(0).getRandomGenerator();
   RandomData rd = new RandomDataImpl(rg);
   /*
    * Compute a random vector of lshList.size() with each component taken from U(0,10)
    */
   randomVec = new ArrayRealVector(lshList.size());
   for (int i = 0; i < randomVec.getDimension(); ++i) {
     randomVec.setEntry(i, rd.nextUniform(0, 10.0));
   }
 }
Example #5
0
 public static void main(String[] args) {
   RealMatrix coefficients2 =
       new Array2DRowRealMatrix(
           new double[][] {
             {0.0D, 1.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D},
             {0.0D, 0.0D, 0.857D, 0.0D, 0.054D, 0.018D, 0.0D, 0.071D, 0.0D, 0.0D, 0.0D},
             {0.0D, 0.0D, 0.0D, 1.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D},
             {0.0D, 0.0D, 0.857D, 0.0D, 0.054D, 0.018D, 0.0D, 0.071D, 0.0D, 0.0D, 0.0D},
             {0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 1.0D, 0.0D, 0.0D, 0.0D, 0.0D},
             {0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 1.0D, 0.0D, 0.0D, 0.0D, 0.0D},
             {0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 1.0D, 0.0D, 0.0D},
             {0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.6D, 0.4D},
             {0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 1.0D},
             {0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 1.0D, 0.0D, 0.0D, 1.0D},
             {0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D, 0.0D}
           },
           false);
   for (int i = 0; i < 11; i++) {
     coefficients2.setEntry(i, i, -1d);
   }
   coefficients2 = coefficients2.transpose();
   DecompositionSolver solver = new LUDecompositionImpl(coefficients2).getSolver();
   System.out.println("1 method my Value :");
   RealVector constants =
       new ArrayRealVector(new double[] {-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, false);
   RealVector solution = solver.solve(constants);
   double[] data = solution.getData();
   DecimalFormat df = new DecimalFormat();
   df.setRoundingMode(RoundingMode.DOWN);
   System.out.println("Корни уравнения:");
   for (double dd : data) {
     System.out.print(df.format(dd) + " ");
   }
   System.out.println();
   System.out.println(
       "Среднее число процессорных операций, выполняемых при одном прогоне алгоритма: "
           + operationsByProcess(data, arr));
   System.out.println("Среднее число обращений к файлам:");
   for (int i = 1; i < 4; i++) {
     System.out.println("  Файл " + i + " : " + fileMiddleRequest(data, arr, i));
   }
   System.out.println("Среднее количество информации передаваемой при одном обращении к файлам:");
   for (int i = 1; i < 4; i++) {
     System.out.println("  Файл " + i + " : " + bitsPerFileTransfer(data, arr, i));
   }
   System.out.println(
       "Сумма среднего числа обращений к основным операторам: " + operatorExecute(data, arr));
   System.out.println("Средняя трудоемкость этапа: " + middleWork(data, arr));
 }
  /**
   * Compute the aggregated hash of a vector. This is done by taking the output of the k hashes as a
   * vector and computing the dot product with a vector of uniformly distributed components between
   * 0 and 10.
   *
   * <p>So, consider a_{0,k} such that a_i ~ U(0,10) and hash functions h_{0,k} treated as 2
   * k-dimensional vectors, we return the dot product of h(v) and a.
   */
  public long apply(RealVector vector) {
    long res = 0;

    for (int i = 0; i < lshList.size(); ++i) {
      res += randomVec.getEntry(i) * lshList.get(i).apply(vector);
    }
    return res;
  }
 /**
  * Build a constraint involving two linear equations.
  *
  * <p>A linear constraint with two linear equation has one of the forms:
  *
  * <ul>
  *   <li>l<sub>1</sub>x<sub>1</sub> + ... l<sub>n</sub>x<sub>n</sub> + l<sub>cst</sub> =
  *       r<sub>1</sub>x<sub>1</sub> + ... r<sub>n</sub>x<sub>n</sub> + r<sub>cst</sub>
  *   <li>l<sub>1</sub>x<sub>1</sub> + ... l<sub>n</sub>x<sub>n</sub> + l<sub>cst</sub> &lt;=
  *       r<sub>1</sub>x<sub>1</sub> + ... r<sub>n</sub>x<sub>n</sub> + r<sub>cst</sub>
  *   <li>l<sub>1</sub>x<sub>1</sub> + ... l<sub>n</sub>x<sub>n</sub> + l<sub>cst</sub> >=
  *       r<sub>1</sub>x<sub>1</sub> + ... r<sub>n</sub>x<sub>n</sub> + r<sub>cst</sub>
  * </ul>
  *
  * @param lhsCoefficients The coefficients of the linear expression on the left hand side of the
  *     constraint
  * @param lhsConstant The constant term of the linear expression on the left hand side of the
  *     constraint
  * @param relationship The type of (in)equality used in the constraint
  * @param rhsCoefficients The coefficients of the linear expression on the right hand side of the
  *     constraint
  * @param rhsConstant The constant term of the linear expression on the right hand side of the
  *     constraint
  */
 public LinearConstraint(
     final RealVector lhsCoefficients,
     final double lhsConstant,
     final Relationship relationship,
     final RealVector rhsCoefficients,
     final double rhsConstant) {
   this.coefficients = lhsCoefficients.subtract(rhsCoefficients);
   this.relationship = relationship;
   this.value = rhsConstant - lhsConstant;
 }
  /** {@inheritDoc} */
  @Override
  public boolean equals(Object other) {

    if (this == other) {
      return true;
    }

    if (other instanceof LinearConstraint) {
      LinearConstraint rhs = (LinearConstraint) other;
      return (relationship == rhs.relationship)
          && (value == rhs.value)
          && coefficients.equals(rhs.coefficients);
    }
    return false;
  }
 /**
  * Calculates the variance on the y by GLS.
  *
  * <pre>
  *  Var(y)=Tr(u' Omega^-1 u)/(n-k)
  * </pre>
  *
  * @return The Y variance
  */
 @Override
 protected double calculateYVariance() {
   RealVector residuals = calculateResiduals();
   double t = residuals.dotProduct(getOmegaInverse().operate(residuals));
   return t / (X.getRowDimension() - X.getColumnDimension());
 }
  public void test4() throws Throwable {

    java.lang.Double var0 = new java.lang.Double((-1.0d));
    double[] var1 = new double[] {var0};
    org.apache.commons.math.linear.OpenMapRealVector var2 =
        new org.apache.commons.math.linear.OpenMapRealVector(var1);
    int var3 = var2.getDimension();
    java.lang.Double var4 = new java.lang.Double((-1.0d));
    java.lang.Double var5 = new java.lang.Double(0.0d);
    java.lang.Double var6 = new java.lang.Double((-1.0d));
    double[] var7 = new double[] {var4, var5, var6};
    org.apache.commons.math.linear.ArrayRealVector var8 =
        new org.apache.commons.math.linear.ArrayRealVector(var7);
    java.lang.Double var9 = new java.lang.Double((-1.0d));
    java.lang.Double var10 = new java.lang.Double(0.0d);
    java.lang.Double var11 = new java.lang.Double((-1.0d));
    double[] var12 = new double[] {var9, var10, var11};
    org.apache.commons.math.linear.ArrayRealVector var13 =
        new org.apache.commons.math.linear.ArrayRealVector(var12);
    org.apache.commons.math.linear.RealVector var14 =
        var8.ebeDivide((org.apache.commons.math.linear.RealVector) var13);
    java.lang.Double var15 = new java.lang.Double((-1.0d));
    java.lang.Double var16 = new java.lang.Double(10.0d);
    java.lang.Double var17 = new java.lang.Double(100.0d);
    int var18 =
        org.apache.commons.math.util.MathUtils.compareTo(
            (double) var15, (double) var16, (double) var17);
    org.apache.commons.math.linear.RealVector var19 = var13.mapPowToSelf((double) var17);
    org.apache.commons.math.linear.ArrayRealVector var20 =
        new org.apache.commons.math.linear.ArrayRealVector(var3, var17);
    java.lang.Double var21 = new java.lang.Double((-1.0d));
    double[] var22 = new double[] {var21};
    org.apache.commons.math.linear.OpenMapRealVector var23 =
        new org.apache.commons.math.linear.OpenMapRealVector(var22);
    java.lang.Double var24 = new java.lang.Double((-1.0d));
    double[] var25 = new double[] {var24};
    org.apache.commons.math.linear.OpenMapRealVector var26 =
        new org.apache.commons.math.linear.OpenMapRealVector(var25);
    org.apache.commons.math.linear.OpenMapRealVector var27 = var23.add(var26);
    org.apache.commons.math.linear.OpenMapRealVector var28 =
        new org.apache.commons.math.linear.OpenMapRealVector(var27);
    java.lang.Double var29 = new java.lang.Double((-1.0d));
    java.lang.Double var30 = new java.lang.Double(0.0d);
    java.lang.Double var31 = new java.lang.Double((-1.0d));
    double[] var32 = new double[] {var29, var30, var31};
    org.apache.commons.math.linear.ArrayRealVector var33 =
        new org.apache.commons.math.linear.ArrayRealVector(var32);
    java.lang.Double var34 = new java.lang.Double((-1.0d));
    java.lang.Double var35 = new java.lang.Double(0.0d);
    java.lang.Double var36 = new java.lang.Double((-1.0d));
    double[] var37 = new double[] {var34, var35, var36};
    org.apache.commons.math.linear.ArrayRealVector var38 =
        new org.apache.commons.math.linear.ArrayRealVector(var37);
    org.apache.commons.math.linear.RealVector var39 =
        var33.ebeDivide((org.apache.commons.math.linear.RealVector) var38);
    java.lang.Double var40 = new java.lang.Double(0.0d);
    java.lang.Double var41 = new java.lang.Double((-1.0d));
    java.lang.Double var42 = new java.lang.Double((-1.0d));
    int var43 =
        org.apache.commons.math.util.MathUtils.compareTo(
            (double) var40, (double) var41, (double) var42);
    org.apache.commons.math.linear.RealVector var44 = var33.mapDivide((double) var41);
    org.apache.commons.math.linear.RealVector var45 = var28.mapSubtractToSelf((double) var41);
    org.apache.commons.math.linear.RealVector var46 = var20.projection(var45);

    // Checks the contract:  equals-hashcode on var19 and var44
    assertTrue(
        "Contract failed: equals-hashcode on var19 and var44",
        var19.equals(var44) ? var19.hashCode() == var44.hashCode() : true);

    // Checks the contract:  equals-hashcode on var44 and var19
    assertTrue(
        "Contract failed: equals-hashcode on var44 and var19",
        var44.equals(var19) ? var44.hashCode() == var19.hashCode() : true);
  }
  public void test11() throws Throwable {

    java.lang.Double var0 = new java.lang.Double((-1.0d));
    java.lang.Double var1 = new java.lang.Double(0.0d);
    java.lang.Double var2 = new java.lang.Double((-1.0d));
    double[] var3 = new double[] {var0, var1, var2};
    org.apache.commons.math.linear.ArrayRealVector var4 =
        new org.apache.commons.math.linear.ArrayRealVector(var3);
    java.lang.Double var5 = new java.lang.Double((-1.0d));
    java.lang.Double var6 = new java.lang.Double(0.0d);
    java.lang.Double var7 = new java.lang.Double((-1.0d));
    double[] var8 = new double[] {var5, var6, var7};
    org.apache.commons.math.linear.ArrayRealVector var9 =
        new org.apache.commons.math.linear.ArrayRealVector(var8);
    org.apache.commons.math.linear.RealVector var10 =
        var4.ebeDivide((org.apache.commons.math.linear.RealVector) var9);
    java.lang.Double var11 = new java.lang.Double((-1.0d));
    java.lang.Double var12 = new java.lang.Double(10.0d);
    java.lang.Double var13 = new java.lang.Double(100.0d);
    int var14 =
        org.apache.commons.math.util.MathUtils.compareTo(
            (double) var11, (double) var12, (double) var13);
    org.apache.commons.math.linear.RealVector var15 = var9.mapPowToSelf((double) var13);
    java.lang.Double[] var16 = new java.lang.Double[] {var13};
    org.apache.commons.math.linear.ArrayRealVector var17 =
        new org.apache.commons.math.linear.ArrayRealVector(var16);
    org.apache.commons.math.linear.RealVector var18 = var17.mapCbrtToSelf();
    org.apache.commons.math.linear.RealVector var19 = var17.mapFloorToSelf();
    org.apache.commons.math.linear.RealVector var20 = var17.mapCosh();
    org.apache.commons.math.linear.RealVector var21 = var17.mapAcos();
    java.lang.Double var22 = new java.lang.Double((-1.0d));
    double[] var23 = new double[] {var22};
    org.apache.commons.math.linear.OpenMapRealVector var24 =
        new org.apache.commons.math.linear.OpenMapRealVector(var23);
    java.lang.Double var25 = new java.lang.Double((-1.0d));
    double[] var26 = new double[] {var25};
    org.apache.commons.math.linear.OpenMapRealVector var27 =
        new org.apache.commons.math.linear.OpenMapRealVector(var26);
    org.apache.commons.math.linear.OpenMapRealVector var28 = var24.add(var27);
    org.apache.commons.math.linear.OpenMapRealVector var29 =
        new org.apache.commons.math.linear.OpenMapRealVector(var28);
    java.lang.Double var30 = new java.lang.Double((-1.0d));
    java.lang.Double var31 = new java.lang.Double(0.0d);
    java.lang.Double var32 = new java.lang.Double((-1.0d));
    double[] var33 = new double[] {var30, var31, var32};
    org.apache.commons.math.linear.ArrayRealVector var34 =
        new org.apache.commons.math.linear.ArrayRealVector(var33);
    java.lang.Double var35 = new java.lang.Double((-1.0d));
    java.lang.Double var36 = new java.lang.Double(0.0d);
    java.lang.Double var37 = new java.lang.Double((-1.0d));
    double[] var38 = new double[] {var35, var36, var37};
    org.apache.commons.math.linear.ArrayRealVector var39 =
        new org.apache.commons.math.linear.ArrayRealVector(var38);
    org.apache.commons.math.linear.RealVector var40 =
        var34.ebeDivide((org.apache.commons.math.linear.RealVector) var39);
    java.lang.Double var41 = new java.lang.Double(0.0d);
    java.lang.Double var42 = new java.lang.Double((-1.0d));
    java.lang.Double var43 = new java.lang.Double((-1.0d));
    int var44 =
        org.apache.commons.math.util.MathUtils.compareTo(
            (double) var41, (double) var42, (double) var43);
    org.apache.commons.math.linear.RealVector var45 = var34.mapDivide((double) var42);
    org.apache.commons.math.linear.RealVector var46 = var29.mapSubtractToSelf((double) var42);
    boolean var47 = var17.equals((java.lang.Object) var42);

    // Checks the contract:  equals-hashcode on var15 and var45
    assertTrue(
        "Contract failed: equals-hashcode on var15 and var45",
        var15.equals(var45) ? var15.hashCode() == var45.hashCode() : true);

    // Checks the contract:  equals-hashcode on var45 and var15
    assertTrue(
        "Contract failed: equals-hashcode on var45 and var15",
        var45.equals(var15) ? var45.hashCode() == var15.hashCode() : true);
  }
 /**
  * Returns the sum of squared residuals.
  *
  * @return residual sum of squares
  * @since 2.2
  */
 public double calculateResidualSumOfSquares() {
   final RealVector residuals = calculateResiduals();
   return residuals.dotProduct(residuals);
 }
  public void test13() throws Throwable {

    java.lang.Double var0 = new java.lang.Double((-1.0d));
    double[] var1 = new double[] {var0};
    org.apache.commons.math.linear.OpenMapRealVector var2 =
        new org.apache.commons.math.linear.OpenMapRealVector(var1);
    java.lang.Double var3 = new java.lang.Double((-1.0d));
    double[] var4 = new double[] {var3};
    org.apache.commons.math.linear.OpenMapRealVector var5 =
        new org.apache.commons.math.linear.OpenMapRealVector(var4);
    org.apache.commons.math.linear.OpenMapRealVector var6 = var2.add(var5);
    org.apache.commons.math.linear.OpenMapRealVector var7 =
        new org.apache.commons.math.linear.OpenMapRealVector(var6);
    java.lang.Double var8 = new java.lang.Double((-1.0d));
    java.lang.Double var9 = new java.lang.Double(0.0d);
    java.lang.Double var10 = new java.lang.Double((-1.0d));
    double[] var11 = new double[] {var8, var9, var10};
    org.apache.commons.math.linear.ArrayRealVector var12 =
        new org.apache.commons.math.linear.ArrayRealVector(var11);
    java.lang.Double var13 = new java.lang.Double((-1.0d));
    java.lang.Double var14 = new java.lang.Double(0.0d);
    java.lang.Double var15 = new java.lang.Double((-1.0d));
    double[] var16 = new double[] {var13, var14, var15};
    org.apache.commons.math.linear.ArrayRealVector var17 =
        new org.apache.commons.math.linear.ArrayRealVector(var16);
    org.apache.commons.math.linear.RealVector var18 =
        var12.ebeDivide((org.apache.commons.math.linear.RealVector) var17);
    java.lang.Double var19 = new java.lang.Double(0.0d);
    java.lang.Double var20 = new java.lang.Double((-1.0d));
    java.lang.Double var21 = new java.lang.Double((-1.0d));
    int var22 =
        org.apache.commons.math.util.MathUtils.compareTo(
            (double) var19, (double) var20, (double) var21);
    org.apache.commons.math.linear.RealVector var23 = var12.mapDivide((double) var20);
    org.apache.commons.math.linear.RealVector var24 = var7.mapSubtractToSelf((double) var20);
    double var25 = var7.getSparcity();
    java.lang.Double var26 = new java.lang.Double((-1.0d));
    double[] var27 = new double[] {var26};
    org.apache.commons.math.linear.OpenMapRealVector var28 =
        new org.apache.commons.math.linear.OpenMapRealVector(var27);
    int var29 = var28.getDimension();
    java.lang.Double var30 = new java.lang.Double((-1.0d));
    java.lang.Double var31 = new java.lang.Double(0.0d);
    java.lang.Double var32 = new java.lang.Double((-1.0d));
    double[] var33 = new double[] {var30, var31, var32};
    org.apache.commons.math.linear.ArrayRealVector var34 =
        new org.apache.commons.math.linear.ArrayRealVector(var33);
    java.lang.Double var35 = new java.lang.Double((-1.0d));
    java.lang.Double var36 = new java.lang.Double(0.0d);
    java.lang.Double var37 = new java.lang.Double((-1.0d));
    double[] var38 = new double[] {var35, var36, var37};
    org.apache.commons.math.linear.ArrayRealVector var39 =
        new org.apache.commons.math.linear.ArrayRealVector(var38);
    org.apache.commons.math.linear.RealVector var40 =
        var34.ebeDivide((org.apache.commons.math.linear.RealVector) var39);
    java.lang.Double var41 = new java.lang.Double((-1.0d));
    java.lang.Double var42 = new java.lang.Double(10.0d);
    java.lang.Double var43 = new java.lang.Double(100.0d);
    int var44 =
        org.apache.commons.math.util.MathUtils.compareTo(
            (double) var41, (double) var42, (double) var43);
    org.apache.commons.math.linear.RealVector var45 = var39.mapPowToSelf((double) var43);
    org.apache.commons.math.linear.ArrayRealVector var46 =
        new org.apache.commons.math.linear.ArrayRealVector(var29, var43);
    java.lang.Double var47 = new java.lang.Double((-1.0d));
    java.lang.Double var48 = new java.lang.Double(10.0d);
    java.lang.Double var49 = new java.lang.Double(1.0d);
    java.lang.Double var50 = new java.lang.Double(1.0d);
    boolean var51 = org.apache.commons.math.util.MathUtils.equals((double) var49, (double) var50);
    int var52 =
        org.apache.commons.math.util.MathUtils.compareTo(
            (double) var47, (double) var48, (double) var49);
    java.lang.Double var53 = new java.lang.Double((-1.0d));
    java.lang.Double var54 = new java.lang.Double(0.0d);
    java.lang.Double var55 = new java.lang.Double((-1.0d));
    double[] var56 = new double[] {var53, var54, var55};
    org.apache.commons.math.linear.ArrayRealVector var57 =
        new org.apache.commons.math.linear.ArrayRealVector(var56);
    java.lang.Double var58 = new java.lang.Double((-1.0d));
    java.lang.Double var59 = new java.lang.Double(0.0d);
    java.lang.Double var60 = new java.lang.Double((-1.0d));
    double[] var61 = new double[] {var58, var59, var60};
    org.apache.commons.math.linear.ArrayRealVector var62 =
        new org.apache.commons.math.linear.ArrayRealVector(var61);
    org.apache.commons.math.linear.RealVector var63 =
        var57.ebeDivide((org.apache.commons.math.linear.RealVector) var62);
    org.apache.commons.math.linear.RealVector var64 = var57.mapLog10ToSelf();
    java.lang.Double var65 = new java.lang.Double(1.0d);
    org.apache.commons.math.linear.RealVector var66 = var57.mapMultiplyToSelf((double) var65);
    double var67 = org.apache.commons.math.util.MathUtils.indicator((double) var65);
    java.lang.Double var68 = new java.lang.Double((-1.0d));
    java.lang.Double var69 = new java.lang.Double(10.0d);
    java.lang.Double var70 = new java.lang.Double(100.0d);
    int var71 =
        org.apache.commons.math.util.MathUtils.compareTo(
            (double) var68, (double) var69, (double) var70);
    double var72 =
        org.apache.commons.math.util.MathUtils.normalizeAngle((double) var65, (double) var69);
    java.lang.Integer var73 = new java.lang.Integer(10);
    java.lang.Integer var74 = new java.lang.Integer(10);
    double var75 =
        org.apache.commons.math.util.MathUtils.binomialCoefficientLog((int) var73, (int) var74);
    java.lang.Integer var76 = new java.lang.Integer(0);
    java.lang.Long var77 = new java.lang.Long(100L);
    int var78 = org.apache.commons.math.util.MathUtils.pow((int) var76, (long) var77);
    double var79 =
        org.apache.commons.math.util.MathUtils.binomialCoefficientLog((int) var74, (int) var76);
    boolean var80 =
        org.apache.commons.math.util.MathUtils.equalsIncludingNaN(
            (double) var49, (double) var69, (int) var76);
    org.apache.commons.math.linear.RealVector var81 = var46.mapMultiplyToSelf((double) var49);
    org.apache.commons.math.linear.RealVector var82 = var7.mapPow((double) var49);

    // Checks the contract:  equals-hashcode on var23 and var45
    assertTrue(
        "Contract failed: equals-hashcode on var23 and var45",
        var23.equals(var45) ? var23.hashCode() == var45.hashCode() : true);

    // Checks the contract:  equals-hashcode on var45 and var23
    assertTrue(
        "Contract failed: equals-hashcode on var45 and var23",
        var45.equals(var23) ? var45.hashCode() == var23.hashCode() : true);
  }
Example #14
0
 public static String realVecToString(RealVector r) {
   String res = "RealVector(" + r.getDimension() + ") of type '" + r.getClass().getName() + "'\n";
   return res += Arrays.toString(r.getData()) + "\n";
 }
Example #15
0
 @Override
 public Double get(int index) {
   if (index < n) return stateIn.getEntry(index);
   if (index < n + h) return stateHidden.getEntry(index - n);
   return stateOut.getEntry(index - n - h);
 }
 /** {@inheritDoc} */
 @Override
 public int hashCode() {
   return relationship.hashCode() ^ Double.valueOf(value).hashCode() ^ coefficients.hashCode();
 }
Example #17
0
  /**
   * Solve an estimation problem using a least squares criterion.
   *
   * <p>This method set the unbound parameters of the given problem starting from their current
   * values through several iterations. At each step, the unbound parameters are changed in order to
   * minimize a weighted least square criterion based on the measurements of the problem.
   *
   * <p>The iterations are stopped either when the criterion goes below a physical threshold under
   * which improvement are considered useless or when the algorithm is unable to improve it (even if
   * it is still high). The first condition that is met stops the iterations. If the convergence it
   * not reached before the maximum number of iterations, an {@link EstimationException} is thrown.
   *
   * @param problem estimation problem to solve
   * @exception EstimationException if the problem cannot be solved
   * @see EstimationProblem
   */
  @Override
  public void estimate(EstimationProblem problem) throws EstimationException {

    initializeEstimate(problem);

    // work matrices
    double[] grad = new double[parameters.length];
    ArrayRealVector bDecrement = new ArrayRealVector(parameters.length);
    double[] bDecrementData = bDecrement.getDataRef();
    RealMatrix wGradGradT = MatrixUtils.createRealMatrix(parameters.length, parameters.length);

    // iterate until convergence is reached
    double previous = Double.POSITIVE_INFINITY;
    do {

      // build the linear problem
      incrementJacobianEvaluationsCounter();
      RealVector b = new ArrayRealVector(parameters.length);
      RealMatrix a = MatrixUtils.createRealMatrix(parameters.length, parameters.length);
      for (int i = 0; i < measurements.length; ++i) {
        if (!measurements[i].isIgnored()) {

          double weight = measurements[i].getWeight();
          double residual = measurements[i].getResidual();

          // compute the normal equation
          for (int j = 0; j < parameters.length; ++j) {
            grad[j] = measurements[i].getPartial(parameters[j]);
            bDecrementData[j] = weight * residual * grad[j];
          }

          // build the contribution matrix for measurement i
          for (int k = 0; k < parameters.length; ++k) {
            double gk = grad[k];
            for (int l = 0; l < parameters.length; ++l) {
              wGradGradT.setEntry(k, l, weight * gk * grad[l]);
            }
          }

          // update the matrices
          a = a.add(wGradGradT);
          b = b.add(bDecrement);
        }
      }

      try {

        // solve the linearized least squares problem
        RealVector dX = new LUDecompositionImpl(a).getSolver().solve(b);

        // update the estimated parameters
        for (int i = 0; i < parameters.length; ++i) {
          parameters[i].setEstimate(parameters[i].getEstimate() + dX.getEntry(i));
        }

      } catch (InvalidMatrixException e) {
        throw new EstimationException("unable to solve: singular problem");
      }

      previous = cost;
      updateResidualsAndCost();

    } while ((getCostEvaluations() < 2)
        || (Math.abs(previous - cost) > (cost * steadyStateThreshold)
            && (Math.abs(cost) > convergence)));
  }
Example #18
0
  /**
   * Modifies this map through a single backpropagation iteration using the given error values on
   * the output nodes.
   *
   * @param error
   */
  public void train(List<Double> error, double learningRate) {
    RealVector eOut = new ArrayRealVector(error.size());
    for (int i : series(error.size())) eOut.setEntry(i, error.get(i));

    // * gHidden: delta for the non-bias nodes of the hidden layer
    gHidden.setSubVector(0, stateHidden.getSubVector(0, n)); // optimize

    for (int i : Series.series(gHidden.getDimension()))
      gHidden.setEntry(i, activation.derivative(gHidden.getEntry(i)));

    eHiddenL = weights1.transpose().operate(eOut);
    eHidden.setSubVector(0, eHiddenL.getSubVector(0, h));
    for (int i : series(h)) eHidden.setEntry(i, eHidden.getEntry(i) * gHidden.getEntry(i));

    weights1Delta = MatrixTools.outer(eOut, stateHidden);
    weights1Delta = weights1Delta.scalarMultiply(-1.0 * learningRate); // optimize

    weights0Delta = MatrixTools.outer(eHidden, stateIn);
    weights0Delta = weights0Delta.scalarMultiply(-1.0 * learningRate);

    weights0 = weights0.add(weights0Delta);
    weights1 = weights1.add(weights1Delta);
  }