Beispiel #1
0
  private static String get_clpequspec(Tgm tgm) {
    String clpequspecCall = null;
    String clpequCall = null;
    int count = 0;
    KMatrixPanelModel kMatrixPanel = tgm.getDat().getKMatrixPanel();
    int size = kMatrixPanel.getContrainsMatrix().getData().size();
    for (int i = 0; i < size; i++) { // to
      for (int j = 0; j < size; j++) { // from
        Double min = kMatrixPanel.getContrainsMatrix().getData().get(i).getMin().get(j);
        Double max = kMatrixPanel.getContrainsMatrix().getData().get(i).getMax().get(j);
        Double scal;
        if (!kMatrixPanel.getContrainsMatrix().getData().get(i).getScal().isEmpty()) {
          scal = kMatrixPanel.getContrainsMatrix().getData().get(i).getScal().get(j);
        } else {
          scal = 1.0;
        }
        if (min != null && max != null) {
          if (count == 0) {
            clpequspecCall = "clpequspec = list(";
            clpequCall = "clpequ = c(";
          }
          clpequspecCall =
              clpequspecCall
                  + "list("
                  + "to="
                  + String.valueOf(i + 1)
                  + ",from="
                  + String.valueOf(j + 1)
                  + ",low="
                  + String.valueOf(min)
                  + ",high="
                  + String.valueOf(max)
                  + "),";
          if (scal != null) {
            clpequCall = clpequCall + String.valueOf(scal) + ',';
          } else {
            clpequCall = clpequCall + "1,";
          }
          count++;
        }
      }
    }
    // Removes last comma:

    if (count > 0) {
      clpequspecCall = clpequspecCall.substring(0, clpequspecCall.length() - 1);
      clpequCall = clpequCall.substring(0, clpequCall.length() - 1);
      clpequspecCall = clpequspecCall + ")";
      clpequCall = clpequCall + ")";
      clpequspecCall = clpequspecCall + "," + clpequCall;
    }

    if (addToFixed == null) {
      addToFixed = "clpequ=1:" + count;
    } else {
      addToFixed = addToFixed + ", clpequ=1:" + count;
    }
    return clpequspecCall;
  }
Beispiel #2
0
  private static String get_relations(Tgm tgm) {
    String relationsCall = null;
    String fixed = null;
    KMatrixPanelModel kMatrixPanel = tgm.getDat().getKMatrixPanel();
    int size = kMatrixPanel.getRelationsMatrix().getData().size();
    // prelspec = list(list(what1="kinpar", what2="kinpar",ind1=6,ind2=1, start=c(0.05,0))),
    Double c0, c1;
    Boolean fc0, fc1;
    int count = 0;
    for (int i = 0; i < size; i++) {
      for (int j = 0; j < size; j++) {
        c0 = kMatrixPanel.getRelationsMatrix().getData().get(i).getC0().get(j);
        c1 = kMatrixPanel.getRelationsMatrix().getData().get(i).getC1().get(j);
        fc0 = kMatrixPanel.getRelationsMatrix().getData().get(i).getC0Fixed().get(j);
        fc1 = kMatrixPanel.getRelationsMatrix().getData().get(i).getC1Fixed().get(j);
        if ((!Double.isNaN(c0)) && (!Double.isNaN(c1))) {
          if (count == 0) {
            relationsCall = "prelspec = list(";
          } else {
            relationsCall = relationsCall + ",";
          }
          relationsCall =
              relationsCall
                  + "list(what1=\"kinpar\", what2=\"kinpar\",ind1="
                  + (i + 1)
                  + ", ind2="
                  + (j + 1)
                  + ", start=c("
                  + c1
                  + ","
                  + c0
                  + "))";

          if (fc1) {
            if (fixed == null) {
              fixed = "prel = c(";
            } else if (count != 0) {
              fixed = fixed + ",";
            }
            fixed = fixed + (2 * count + 1);
          }

          if (fc0) {
            if (fixed == null) {
              fixed = "prel = c(";
            } else {
              if ((count != 0) || ((count == 0) && (fc0))) {
                fixed = fixed + ",";
              }
            }

            fixed = fixed + (2 * count + 2);
          }
          count++;
        }
      }
    }
    if (relationsCall != null) {
      relationsCall = relationsCall + ")";
    }
    if (fixed != null) {
      fixed = fixed + ")";
      if (addToFixed != null) {
        addToFixed = addToFixed + "," + fixed;
      } else {
        addToFixed = fixed;
      }
    }
    return relationsCall;
  }
Beispiel #3
0
  private static String get_fixed(Tgm tgm) {
    String fixedStr = null;
    KinparPanelModel kinparPanelModel = tgm.getDat().getKinparPanel();
    int count = 0;
    for (int i = 0; i < kinparPanelModel.getKinpar().size(); i++) {
      if (kinparPanelModel.getKinpar().get(i).isFixed()) {
        if (count > 0) {
          fixedStr = fixedStr + ",";
        } else {
          fixedStr = "fixed = list(kinpar=c(";
        }
        fixedStr = fixedStr + String.valueOf(i + 1);
        count++;
      }
    }
    if (count > 0) {
      fixedStr = fixedStr + ")";
    }

    count = 0;

    KMatrixPanelModel kmatPanel = tgm.getDat().getKMatrixPanel();
    for (int i = 0; i < kmatPanel.getKinScal().size(); i++) {
      if (kmatPanel.getKinScal().get(i).isFixed()) {
        if (count > 0) {
          fixedStr = fixedStr + ",";
        } else {
          if (fixedStr != null) {
            fixedStr = fixedStr + ", kinscal=c(";
          } else {
            fixedStr = "fixed = list(kinscal=c(";
          }
        }
        fixedStr = fixedStr + String.valueOf(i + 1);
        count++;
      }
    }
    if (count > 0) {
      fixedStr = fixedStr + ")";
    }

    count = 0;
    IrfparPanelModel irfPanel = tgm.getDat().getIrfparPanel();
    for (int i = 0; i < irfPanel.getFixed().size(); i++) {
      if (irfPanel.getFixed().get(i)) {
        if (count > 0) {
          fixedStr = fixedStr + ",";
        } else {
          if (fixedStr != null) {
            fixedStr = fixedStr + ", irfpar=c(";
          } else {
            fixedStr = "fixed = list(irfpar=c(";
          }
        }
        fixedStr = fixedStr + String.valueOf(i + 1);
        count++;
      }
    }
    if (count > 0) {
      fixedStr = fixedStr + ")";
    }

    if (irfPanel.getParmu() != null) {
      if (irfPanel.isParmufixed() != null && irfPanel.isParmufixed()) {
        if (fixedStr != null) {
          fixedStr = fixedStr + ", parmu=c(";
        } else {
          fixedStr = "fixed = list(parmu=c(";
        }

        String[] doubles = irfPanel.getParmu().split(",");
        fixedStr = fixedStr + "1:" + String.valueOf(doubles.length);
        fixedStr = fixedStr + ")";
      }
    }

    if (irfPanel.getPartau() != null) {
      if (irfPanel.isPartaufixed()) {
        if (fixedStr != null) {
          fixedStr = fixedStr + ", partau=c(";
        } else {
          fixedStr = "fixed = list(partau=c(";
        }

        String[] doubles = irfPanel.getPartau().split(",");
        fixedStr = fixedStr + "1:" + String.valueOf(doubles.length);
        fixedStr = fixedStr + ")";
      }
    }
    count = 0;
    for (int i = 0; i < tgm.getDat().getCohspecPanel().getCohspec().getFixed().size(); i++) {
      if (tgm.getDat().getCohspecPanel().getCohspec().getFixed().get(i)) {
        if (count > 0) {
          fixedStr = fixedStr + ",";
        } else {
          if (fixedStr != null) {
            fixedStr = fixedStr + ", coh=c(";
          } else {
            fixedStr = "fixed = list(coh=c(";
          }
        }
        fixedStr = fixedStr + String.valueOf(i + 1);
        count++;
      }
    }
    if (count > 0) {
      fixedStr = fixedStr + ")";
    }

    if (tgm.getDat().getOscspecPanel() != null) {
      if (tgm.getDat().getOscspecPanel().getOscspec() != null) {
        count = 0;
        for (int i = 0; i < tgm.getDat().getOscspecPanel().getOscspec().getFixed().size(); i++) {
          if (tgm.getDat().getOscspecPanel().getOscspec().getFixed().get(i)) {
            if (count > 0) {
              fixedStr = fixedStr + ",";
            } else {
              if (fixedStr != null) {
                fixedStr = fixedStr + ", oscpar=c(";
              } else {
                fixedStr = "fixed = list(oscpar=c(";
              }
            }
            fixedStr = fixedStr + String.valueOf(i + 1);
            count++;
          }
        }
        if (count > 0) {
          fixedStr = fixedStr + ")";
        }
      }
    }

    count = 0;
    KMatrixPanelModel kMatrix = tgm.getDat().getKMatrixPanel();
    for (int i = 0; i < kMatrix.getJVector().getFixed().size(); i++) {
      if (kMatrix.getJVector().getFixed().get(i)) {
        if (count > 0) {
          fixedStr = fixedStr + ",";
        } else {
          if (fixedStr != null) {
            fixedStr = fixedStr + ", jvec=c(";
          } else {
            fixedStr = "fixed = list(jvec=c(";
          }
        }
        fixedStr = fixedStr + String.valueOf(i + 1);
        count++;
      }
    }
    if (count > 0) {
      fixedStr = fixedStr + ")";
    }
    // TODO: add additional paramters for fixed here:

    // This closes the "fixed" argument
    if (fixedStr != null) {
      if (addToFixed != null) {
        fixedStr = fixedStr + "," + addToFixed + ")";
      } else {
        fixedStr = fixedStr + ")";
      }
    } else {
      if (addToFixed != null) {
        fixedStr = "fixed = list(" + addToFixed + ")";
      }
    }

    return fixedStr;
  }
Beispiel #4
0
  private static String get_clp0(Tgm tgm) {
    String clp0Call = null;
    int indexOfComponent = 0;
    KMatrixPanelModel kMatrix = tgm.getDat().getKMatrixPanel();
    int size = kMatrix.getSpectralContraints().getMax().size();
    if (size > 0) {
      int count = 0;
      for (int i = 0; i < size; i++) {
        Double min = kMatrix.getSpectralContraints().getMin().get(i);
        Double max = kMatrix.getSpectralContraints().getMax().get(i);
        if (min != null && max != null) {
          if (count == 0) {
            clp0Call = "clp0 = list(";
          } else {
            clp0Call = clp0Call + ",";
          }

          clp0Call =
              clp0Call
                  + "list(low = "
                  + Double.valueOf(min)
                  + ", high ="
                  + Double.valueOf(max)
                  + ", comp = "
                  + (i + 1)
                  + ")";
          count++;
        }
      }
    }
    if (tgm.getDat().getCohspecPanel().isClp0Enabled() != null) {
      if (tgm.getDat().getCohspecPanel().isClp0Enabled()) {
        if (clp0Call != null) {
          clp0Call = clp0Call + ",";
        } else {
          clp0Call = "clp0 = list(";
        }
        if (kMatrix.getJVector() != null) {
          if (kMatrix.getJVector().getVector().size() > 0) {
            indexOfComponent = kMatrix.getJVector().getVector().size() + 1;
          } else {
            indexOfComponent = (tgm.getDat().getKinparPanel().getKinpar().size() + 1);
          }
        } else {
          indexOfComponent = (tgm.getDat().getKinparPanel().getKinpar().size() + 1);
        }
        clp0Call =
            clp0Call
                + "list(low = "
                + tgm.getDat().getCohspecPanel().getClp0Min()
                + ", high = "
                + tgm.getDat().getCohspecPanel().getClp0Max()
                + ", comp = "
                + indexOfComponent
                + ")";
      }
    }
    if (clp0Call != null) {
      clp0Call = clp0Call + ")";
    }
    return clp0Call;
  }
Beispiel #5
0
  // Private classes
  public static String get_kmatrix(Tgm tgm) {
    String kMatrixCall = null;

    KMatrixPanelModel kMatrix = tgm.getDat().getKMatrixPanel();

    int matrixSize = kMatrix.getJVector().getVector().size();
    if (matrixSize > 0) {
      kMatrixCall = "kmat = array(c(";
      kMatrixCall =
          kMatrixCall.concat(String.valueOf(kMatrix.getKMatrix().getData().get(0).getRow().get(0)));
      for (int j = 1; j < matrixSize; j++) {
        kMatrixCall =
            kMatrixCall.concat(
                "," + String.valueOf(kMatrix.getKMatrix().getData().get(j).getRow().get(0)));
      }
      for (int i = 1; i < matrixSize; i++) {
        for (int j = 0; j < matrixSize; j++) {
          kMatrixCall =
              kMatrixCall.concat(
                  "," + String.valueOf(kMatrix.getKMatrix().getData().get(j).getRow().get(i)));
        }
      }
      for (int i = 0; i < matrixSize; i++) {
        for (int j = 0; j < matrixSize; j++) {
          kMatrixCall =
              kMatrixCall.concat(
                  ","
                      + String.valueOf(
                          kMatrix.getKMatrix().getData().get(j + matrixSize).getRow().get(i)));
        }
      }

      kMatrixCall = kMatrixCall.concat("), dim = c(");
      kMatrixCall =
          kMatrixCall.concat(
              String.valueOf(matrixSize) + "," + String.valueOf(matrixSize) + ",2))");
      kMatrixCall = kMatrixCall.concat(", jvec = c(");
      // TODO: verify jVector
      kMatrixCall = kMatrixCall.concat(String.valueOf(kMatrix.getJVector().getVector().get(0)));
      for (int j = 1; j < matrixSize; j++) {
        kMatrixCall =
            kMatrixCall.concat("," + String.valueOf(kMatrix.getJVector().getVector().get(j)));
      }
      kMatrixCall = kMatrixCall.concat(")");

      int size = kMatrix.getKinScal().size();
      if (size > 0) {
        kMatrixCall = kMatrixCall.concat(", kinscal = c(");
        double k;
        for (int i = 0; i < size; i++) {
          if (i > 0) {
            kMatrixCall = kMatrixCall + ",";
          }
          k = kMatrix.getKinScal().get(i).getStart();
          kMatrixCall = kMatrixCall + Double.toString(k);
        }
        kMatrixCall = kMatrixCall + ")";
      }
    }
    return kMatrixCall;
  }