/** getCellsBinary */
  private void createCells() {
    ConstraintDefinition constraint = model.createConstraintDefinition(template);
    // int count = template.parameterCount();
    ActivityDefinitonCell[] cells = new ActivityDefinitonCell[constraint.parameterCount()];
    // ActivityDefinition [] params = new ActivityDefinition [count];
    double total = 0;
    int c = 0;
    for (Parameter parameter : constraint.getParameters()) {

      ActivityDefinition activityDefinition = model.addActivityDefinition();
      activityDefinition.setName(parameter.getName());
      // params[i] = activityDefinition;
      constraint.addBranch(parameter, activityDefinition);

      ActivityDefinitonCell activityDefinitionCell =
          view.getActivityDefinitionCell(activityDefinition);
      total = activityDefinitionCell.getWidth() + 10;
      cells[c++] = activityDefinitionCell;
    }

    double radius = total / 2 + 100;
    Point[] points = Circle.getPoints(radius, cells.length);

    for (int i = 0; i < cells.length; i++) {
      ActivityDefinitonCell cell = cells[i];
      int x = points[i].x + (new Double(cell.getWidth() / 2)).intValue();
      int y = points[i].y + (new Double(cell.getHeight() / 2)).intValue();
      cell.setPosition(new Point(x, y));
    }
    model.addConstraintDefiniton(constraint);
  }
示例#2
0
  private void repaintContent() {
    if (content != null) {
      remove(content);
    }
    content = new JPanel();

    content.setLayout(new GridBagLayout());
    content.setBackground(Colors.TEMPLATE);
    int gridY = 0;
    GridBagConstraints c;
    for (Parameter p : shownParams.getParamList()) {
      c = new GridBagConstraints();
      c.gridx = 0;
      c.gridy = gridY;
      c.anchor = GridBagConstraints.WEST;
      c.fill = GridBagConstraints.NONE;
      c.insets = new Insets(0, 0, 0, 8);
      content.add(new JLabel(p.getName()), c);

      c = new GridBagConstraints();
      c.gridx = 1;
      c.gridy = gridY++;
      c.fill = GridBagConstraints.HORIZONTAL;
      c.weightx = 1;
      final Parameter pFinal = p;
      final JTextField jTextField = new DJTextField();
      jTextField.setText(p.getValue());
      jTextField.addKeyListener(
          new KeyListener() {
            public void keyTyped(KeyEvent keyEvent) {
              // TODO
            }

            public void keyPressed(KeyEvent keyEvent) {
              // TODO
            }

            public void keyReleased(KeyEvent keyEvent) {
              pFinal.setValue(jTextField.getText());
            }
          });
      content.add(jTextField, c);
    }

    GridBagConstraints nc = new GridBagConstraints();
    nc.gridx = 0;
    nc.gridy = 0;
    nc.weightx = 1;
    nc.fill = GridBagConstraints.HORIZONTAL;

    add(content, nc);

    content.updateUI();
    content.repaint();
    this.repaint();
  }
示例#3
0
 /**
  * Sets the mass. Overrides PointMass method.
  *
  * @param mass the mass
  */
 public void setMass(double mass) {
   super.setMass(mass);
   mass = super.getMass();
   massField.setValue(mass);
   // refresh mass parameter in paramPanel if changed
   Parameter massParam = (Parameter) getParamEditor().getObject("m"); // $NON-NLS-1$
   if (massParam != null && massParam.getValue() != mass) {
     functionPanel.getParamEditor().setExpression("m", String.valueOf(mass), false); // $NON-NLS-1$
     refreshSteps();
   }
 }
示例#4
0
 /** Refreshes initial time parameter for this model. */
 protected void refreshInitialTime() {
   if (trackerPanel == null) return;
   double t0 = trackerPanel.getPlayer().getFrameTime(getStartFrame()) / 1000;
   String t = timeFormat.format(t0);
   Parameter param = (Parameter) getInitEditor().getObject("t"); // $NON-NLS-1$
   if (param.getValue() != t0) {
     boolean prev = refreshing;
     refreshing = true;
     getInitEditor().setExpression("t", t, false); // $NON-NLS-1$
     refreshing = prev;
   }
 }
  private double paramValue(SemIm im, Parameter parameter) {
    double paramValue = im.getParamValue(parameter);

    if (parameter.getType() == ParamType.VAR) {
      paramValue = Math.sqrt(paramValue);
    }

    return paramValue;
  }
示例#6
0
 /** This adds the mass and initial time parameters to the function panel. */
 protected void createMassAndTimeParameters() {
   Parameter param = new Parameter("m", String.valueOf(getMass())); // $NON-NLS-1$
   param.setNameEditable(false);
   param.setDescription(
       TrackerRes.getString("ParticleModel.Parameter.Mass.Description")); // $NON-NLS-1$
   getParamEditor().addObject(param, false);
   param = new Parameter("t", "0"); // $NON-NLS-1$ //$NON-NLS-2$
   param.setNameEditable(false);
   param.setDescription(
       TrackerRes.getString("ParticleModel.Parameter.InitialTime.Description")); // $NON-NLS-1$
   functionPanel.getInitEditor().addObject(param, false);
   getParamEditor()
       .addPropertyChangeListener(
           new PropertyChangeListener() {
             public void propertyChange(PropertyChangeEvent e) {
               if ("m".equals(e.getOldValue())) { // $NON-NLS-1$
                 Parameter param = (Parameter) getParamEditor().getObject("m"); // $NON-NLS-1$
                 if (ParticleModel.super.getMass() != param.getValue()) {
                   setMass(param.getValue());
                 }
               }
             }
           });
   getInitEditor()
       .addPropertyChangeListener(
           new PropertyChangeListener() {
             public void propertyChange(PropertyChangeEvent e) {
               if (refreshing) return;
               if ("t".equals(e.getOldValue()) && trackerPanel != null) { // $NON-NLS-1$
                 Parameter param = (Parameter) getInitEditor().getObject("t"); // $NON-NLS-1$
                 VideoClip clip = trackerPanel.getPlayer().getVideoClip();
                 double timeOffset = param.getValue() * 1000 - clip.getStartTime();
                 double dt = trackerPanel.getPlayer().getMeanStepDuration();
                 int n = clip.getStartFrameNumber();
                 boolean mustRound = timeOffset % dt > 0;
                 n += clip.getStepSize() * (int) Math.round(timeOffset / dt);
                 setStartFrame(n);
                 if (getStartFrame() != n || mustRound) Toolkit.getDefaultToolkit().beep();
               }
             }
           });
 }
  private String typeString(Parameter parameter) {
    ParamType type = parameter.getType();

    if (type == ParamType.COEF) {
      return "Coef";
    }

    if (type == ParamType.VAR) {
      // return "Variance";
      return "StdDev";
    }

    if (type == ParamType.COVAR) {
      return "Covar";
    }

    throw new IllegalStateException("Unknown param type.");
  }
示例#8
0
 /**
  * Loads an object with data from an XMLControl.
  *
  * @param control the control
  * @param obj the object
  * @return the loaded object
  */
 public Object loadObject(XMLControl control, Object obj) {
   // load track data
   XML.getLoader(TTrack.class).loadObject(control, obj);
   ParticleModel p = (ParticleModel) obj;
   p.mass = control.getDouble("mass"); // $NON-NLS-1$
   p.inspectorX = control.getInt("inspector_x"); // $NON-NLS-1$
   p.inspectorY = control.getInt("inspector_y"); // $NON-NLS-1$
   p.inspectorH = control.getInt("inspector_h"); // $NON-NLS-1$
   p.showInspector = control.getBoolean("inspector_visible"); // $NON-NLS-1$
   Parameter[] params = (Parameter[]) control.getObject("user_parameters"); // $NON-NLS-1$
   p.getParamEditor().setParameters(params);
   params = (Parameter[]) control.getObject("initial_values"); // $NON-NLS-1$
   // remove trailing "0" from initial condition parameters
   for (int i = 0; i < params.length; i++) {
     Parameter param = params[i];
     String name = param.getName();
     int n = name.lastIndexOf("0"); // $NON-NLS-1$
     if (n > -1) {
       // replace parameter with new one
       name = name.substring(0, n);
       Parameter newParam = new Parameter(name, param.getExpression());
       newParam.setDescription(param.getDescription());
       newParam.setNameEditable(false);
       params[i] = newParam;
     }
   }
   p.getInitEditor().setParameters(params);
   UserFunction[] functions =
       (UserFunction[]) control.getObject("main_functions"); // $NON-NLS-1$
   p.getFunctionEditor().setMainFunctions(functions);
   functions = (UserFunction[]) control.getObject("support_functions"); // $NON-NLS-1$
   if (functions != null) {
     for (int i = 0; i < functions.length; i++) {
       p.getFunctionEditor().addObject(functions[i], false);
     }
   }
   p.functionPanel.refreshFunctions();
   int n = control.getInt("start_frame"); // $NON-NLS-1$
   if (n != Integer.MIN_VALUE) p.startFrame = n;
   else {
     p.startFrameUndefined = true;
   }
   n = control.getInt("end_frame"); // $NON-NLS-1$
   if (n != Integer.MIN_VALUE) p.endFrame = n;
   return obj;
 }
  private String compileReport() {
    StringBuilder builder = new StringBuilder();

    builder.append("Datset\tFrom\tTo\tType\tValue\tSE\tT\tP");

    java.util.List<SemEstimator> estimators = wrapper.getMultipleResultList();

    for (int i = 0; i < estimators.size(); i++) {
      SemEstimator estimator = estimators.get(i);

      SemIm estSem = estimator.getEstimatedSem();
      String dataName = estimator.getDataSet().getName();

      for (Parameter parameter : estSem.getFreeParameters()) {
        builder.append("\n");
        builder.append(dataName + "\t");
        builder.append(parameter.getNodeA() + "\t");
        builder.append(parameter.getNodeB() + "\t");
        builder.append(typeString(parameter) + "\t");
        builder.append(asString(paramValue(estSem, parameter)) + "\t");
        /*
         Maximum number of free parameters for which statistics will be
         calculated. (Calculating standard errors is high complexity.) Set this to
         zero to turn  off statistics calculations (which can be problematic
         sometimes).
        */
        int maxFreeParamsForStatistics = 200;
        builder.append(
            asString(estSem.getStandardError(parameter, maxFreeParamsForStatistics)) + "\t");
        builder.append(asString(estSem.getTValue(parameter, maxFreeParamsForStatistics)) + "\t");
        builder.append(asString(estSem.getPValue(parameter, maxFreeParamsForStatistics)) + "\t");
      }

      List<Node> nodes = estSem.getVariableNodes();

      for (int j = 0; j < nodes.size(); j++) {
        Node node = nodes.get(j);

        int n = estSem.getSampleSize();
        int df = n - 1;
        double mean = estSem.getMean(node);
        double stdDev = estSem.getMeanStdDev(node);
        double stdErr = stdDev / Math.sqrt(n);

        double tValue = mean / stdErr;
        double p = 2.0 * (1.0 - ProbUtils.tCdf(Math.abs(tValue), df));

        builder.append("\n");
        builder.append(dataName + "\t");
        builder.append(nodes.get(j) + "\t");
        builder.append(nodes.get(j) + "\t");
        builder.append("Mean" + "\t");
        builder.append(asString(mean) + "\t");
        builder.append(asString(stdErr) + "\t");
        builder.append(asString(tValue) + "\t");
        builder.append(asString(p) + "\t");
      }
    }

    return builder.toString();
  }
示例#10
0
 /**
  * Gets the mass. Overrides PointMass method.
  *
  * @return the mass
  */
 public double getMass() {
   Parameter massParam = (Parameter) getParamEditor().getObject("m"); // $NON-NLS-1$
   if (massParam != null) return massParam.getValue();
   return super.getMass();
 }