Exemplo n.º 1
0
 /**
  * Whether the instance is covered by this antecedent
  *
  * @param inst the instance in question
  * @return the boolean value indicating whether the instance is covered by this antecedent
  */
 public double covers(Instance inst) {
   double isCover = 0;
   if (!inst.isMissing(att)) {
     if ((int) inst.value(att) == (int) value) isCover = 1;
   }
   return isCover;
 }
  public Request<RegisterInstancesWithLoadBalancerRequest> marshall(
      RegisterInstancesWithLoadBalancerRequest registerInstancesWithLoadBalancerRequest) {
    Request<RegisterInstancesWithLoadBalancerRequest> request =
        new DefaultRequest<RegisterInstancesWithLoadBalancerRequest>(
            registerInstancesWithLoadBalancerRequest, "AmazonElasticLoadBalancing");
    request.addParameter("Action", "RegisterInstancesWithLoadBalancer");
    request.addParameter("Version", "2009-11-25");
    if (registerInstancesWithLoadBalancerRequest != null) {
      if (registerInstancesWithLoadBalancerRequest.getLoadBalancerName() != null) {
        request.addParameter(
            "LoadBalancerName",
            StringUtils.fromString(registerInstancesWithLoadBalancerRequest.getLoadBalancerName()));
      }
    }

    if (registerInstancesWithLoadBalancerRequest != null) {
      java.util.List<Instance> instancesList =
          registerInstancesWithLoadBalancerRequest.getInstances();
      int instancesListIndex = 1;
      for (Instance instancesListValue : instancesList) {
        if (instancesListValue != null) {
          if (instancesListValue.getInstanceId() != null) {
            request.addParameter(
                "Instances.member." + instancesListIndex + ".InstanceId",
                StringUtils.fromString(instancesListValue.getInstanceId()));
          }
        }

        instancesListIndex++;
      }
    }

    return request;
  }
Exemplo n.º 3
0
  @Override
  public double[] distributionForInstance(Instance xy) throws Exception {

    int L = xy.classIndex();

    double y[] = new double[L];
    double w = 0.0;

    /*
     * e.g. K = [3,3,5]
     * we push y_[] from [0,0,0] to [2,2,4] over all necessary iterations.
     */
    int K[] = getKs(xy.dataset());
    if (getDebug()) System.out.println("K[] = " + Arrays.toString(K));
    double y_[] = new double[L];

    for (int i = 0; i < 1000000; i++) { // limit to 1m
      // System.out.println(""+i+" "+Arrays.toString(y_));
      double w_ = A.product(super.probabilityForInstance(xy, y_));
      if (w_ > w) {
        if (getDebug()) System.out.println("y' = " + Arrays.toString(y_) + ", :" + w_);
        y = Arrays.copyOf(y_, y_.length);
        w = w_;
      }
      if (push(y_, K, 0)) {
        // Done !
        if (getDebug()) System.out.println("Tried all " + (i + 1) + " combinations.");
        break;
      }
    }

    return y;
  }
Exemplo n.º 4
0
 public void _loadAndRecompute(Instance _new, Instance old) {
   Instance obj = ((!DataUtil.equals(old, null)) ? old : _new);
   List<Instance> result = new ArrayList<Instance>();
   switch (obj._type()) {
   }
   Database.update(result);
 }
  public Instance pipe(Instance carrier) {
    if (!(carrier.getTarget() instanceof String)) {
      throw new IllegalArgumentException("Target must be of type String");
    }

    String featuresLine = (String) carrier.getTarget();

    String[] features = featuresLine.split(",?\\s+");

    double[] values = new double[features.length];
    Arrays.fill(values, 1.0);

    for (int i = 0; i < features.length; i++) {

      // Support the syntax "FEATURE=0.000342 OTHER_FEATURE=-2.32423"
      //        \

      if (features[i].indexOf("=") != -1) {
        String[] keyValuePair = features[i].split("=");
        features[i] = keyValuePair[0];
        values[i] = Double.parseDouble(keyValuePair[1]);
      }

      // ensure that the feature has a spot in the alphabet
      //        \

      getTargetAlphabet().lookupIndex(features[i], true);
    }

    FeatureVector target = new FeatureVector(getTargetAlphabet(), features, values);

    carrier.setTarget(target);

    return carrier;
  }
  public static InstanceList readFromFile(String inputfile) throws IOException {
    BufferedReader in = new BufferedReader(new FileReader(inputfile));

    InstanceList instanceList = new InstanceList();

    String line;

    while ((line = in.readLine()) != null) {
      String tokens[] = line.split(" ");

      int label = Integer.valueOf(tokens[0]);

      Instance ins = new Instance(label);

      for (int i = 1; i < tokens.length; i++) {
        String pair[] = tokens[i].split(":");

        int attr = Integer.valueOf(pair[0]);
        double value = Double.valueOf(pair[1]);

        ins.addAttribute(attr, value);

        instanceList.addInstance(ins);
      }
    }

    return instanceList;
  }
Exemplo n.º 7
0
    public static void printNeighbors(ArrayList neighbors) {
        int i = 0;
        for(Neighbor neighbor : neighbors) {
            Instance instance = neighbor.getInstance();

            System.out.println("\nNeighbor " + (i + 1) + ", distance: " + neighbor.getDistance());
            i++;
            for(Feature f : instance.getAttributes()) {
                System.out.print(f.getName() + ": ");
                if(f instanceof Category) {
                    System.out.println(((Category)f).getCategory().toString());
                }
                else if(f instanceof Distance) {
                    System.out.println(((Distance)f).getDistance().toString());
                }
                else if (f instanceof Expiration) {
                    System.out.println(((Expiration)f).getExpiry().toString());
                }
                else if (f instanceof Handset) {
                    System.out.print(((Handset)f).getOs().toString() + ", ");
                    System.out.println(((Handset)f).getDevice().toString());
                }
                else if (f instanceof Offer) {
                    System.out.println(((Offer)f).getOfferType().toString());
                }
                else if (f instanceof WSAction) {
                    System.out.println(((WSAction)f).getAction().toString());
                }
            }
        }
    }
Exemplo n.º 8
0
  /**
   * Precomit the transaction. If it is an optimistic transaction lock all resources. If any
   * resource has been changed, since acquired, the precommit fails.
   */
  public boolean precomit(int transactionId) {
    Validate.isTrue(transactionId != 0);
    Instance i = transactions.get(transactionId);
    Validate.isTrue(i.state == State.Optimistic || i.state == State.Precomit);

    if (i.state == State.Precomit) {
      return true;
    }

    for (String name : i.resources.keySet()) {

      //
      // Check that the resource hasn't been used and lock the
      // resource.
      //

      Resource localResource = i.resources.get(name);
      Resource masterResource = master.get(name);
      if (masterResource.hasChanged(localResource) || !masterResource.lock()) {
        rollback(transactionId);
        return false;
      }
    }
    i.state = State.Precomit;
    saveTransactionState();
    return true;
  }
Exemplo n.º 9
0
  /**
   * propogate the next signal from self to all instances. Callers must be synchronized on 'this'
   * object.
   */
  public synchronized boolean propogateNextSignalSelf(Debug debugObject)
      throws LemRuntimeException {
    /*
     * First propogate any elapsed delayed signals to self
     * into the signalSelfQueue.
     */
    while (delayedSignalSelfQueue.size() > 0) {
      DelayedSignal s;
      s = (DelayedSignal) delayedSignalSelfQueue.get(0);
      if (s.getDeliveryTime() <= context.getTimeObject().getTimeMs()) {
        delayedSignalSelfQueue.remove(s);
        addSignalSelf(s);
      } else break;
    }

    if (signalSelfQueue.size() > 0) {
      Signal s = (Signal) signalSelfQueue.remove(0);
      for (Iterator i = instances.iterator(); i.hasNext(); ) {
        Instance in = (Instance) i.next();
        if (in.isActive) {
          in.addSignalSelf(s);
          debugObject.addEntity();
        }
      }
      debugObject.delEntity();
      return true;
    }

    return false;
  }
Exemplo n.º 10
0
  /** This is (mostly) copied from CRF4.java */
  public boolean[][] labelConnectionsIn(
      Alphabet outputAlphabet, InstanceList trainingSet, String start) {
    int numLabels = outputAlphabet.size();
    boolean[][] connections = new boolean[numLabels][numLabels];
    for (int i = 0; i < trainingSet.size(); i++) {
      Instance instance = trainingSet.getInstance(i);
      FeatureSequence output = (FeatureSequence) instance.getTarget();
      for (int j = 1; j < output.size(); j++) {
        int sourceIndex = outputAlphabet.lookupIndex(output.get(j - 1));
        int destIndex = outputAlphabet.lookupIndex(output.get(j));
        assert (sourceIndex >= 0 && destIndex >= 0);
        connections[sourceIndex][destIndex] = true;
      }
    }

    // Handle start state
    if (start != null) {
      int startIndex = outputAlphabet.lookupIndex(start);
      for (int j = 0; j < outputAlphabet.size(); j++) {
        connections[startIndex][j] = true;
      }
    }

    return connections;
  }
Exemplo n.º 11
0
 protected boolean isEc2ProvisionedAmiSlave(Instance i, String ami, String templateDesc) {
   // Check if the ami matches
   if (ami == null || StringUtils.equals(ami, i.getImageId())) {
     // Check if there is a ec2slave tag...
     for (Tag tag : i.getTags()) {
       if (StringUtils.equals(tag.getKey(), EC2Tag.TAG_NAME_JENKINS_SLAVE_TYPE)) {
         if (ami == null || templateDesc == null) {
           return true;
         } else if (StringUtils.equals(tag.getValue(), EC2Cloud.EC2_SLAVE_TYPE_DEMAND)
             || StringUtils.equals(tag.getValue(), EC2Cloud.EC2_SLAVE_TYPE_SPOT)) {
           // To handle cases where description is null and also upgrade cases for existing slave
           // nodes.
           return true;
         } else if (StringUtils.equals(
                 tag.getValue(),
                 getSlaveTypeTagValue(EC2Cloud.EC2_SLAVE_TYPE_DEMAND, templateDesc))
             || StringUtils.equals(
                 tag.getValue(),
                 getSlaveTypeTagValue(EC2Cloud.EC2_SLAVE_TYPE_SPOT, templateDesc))) {
           return true;
         } else {
           return false;
         }
       }
     }
     return false;
   }
   return false;
 }
 /**
  * @param instances
  * @throws Exception
  */
 public void train(List<Instance> instances) {
   assert (instances.size() > 0);
   int numOfAttributes = instances.get(0).getNumOfAttributes();
   initializeWeights(numOfAttributes);
   // Stochastic gradient descent training algorithm
   int size = instances.size();
   for (int i = 0; i < numOfIterations; i++) {
     double logit = 0d, loss = 0d;
     int label, predicted, errorCount = 0;
     double[] oldWeights = new double[numOfAttributes];
     for (int j = 0; j < numOfAttributes; j++) oldWeights[j] = weights[j];
     for (Instance instance : instances) {
       double[] attributeValues = instance.getAttributes();
       label = instance.getLabel();
       logit = innerProduct(attributeValues);
       assert (label == 1 || label == -1);
       loss = sigmoid(label * logit);
       // prediction based on current weight
       if (sigmoid(logit) <= 0.5) predicted = -1;
       else predicted = 1;
       if (predicted != label) errorCount++;
       // Weights updating by stochastic gradient descent
       for (int j = 0; j < numOfAttributes; j++) {
         weights[j] += learningRate * label * attributeValues[j] * (1 - loss);
       }
     }
     if (i % 500 == 0)
       logger.debug("Iteration = {}, training error = {}", i, (double) errorCount / size);
   }
 }
 public void addCount(long c1, long c2) {
   if (!PerformanceState.threadStateEnabled() || PerformanceState.isRecordingSuspended()) {
     return;
   }
   Instance operationalObj = (Instance) this.instance();
   operationalObj.addCount(c1, c2);
 }
Exemplo n.º 14
0
 /**
  * Counts the number of instances in EC2 currently running that are using the specified image and
  * a template.
  *
  * @param ami If AMI is left null, then all instances are counted and template description is
  *     ignored.
  *     <p>This includes those instances that may be started outside Jenkins.
  * @param templateDesc
  */
 public int countCurrentEC2Slaves(String ami, String templateDesc) throws AmazonClientException {
   int n = 0;
   for (Reservation r : connect().describeInstances().getReservations()) {
     for (Instance i : r.getInstances()) {
       if (isEc2ProvisionedAmiSlave(i, ami, templateDesc)) {
         InstanceStateName stateName = InstanceStateName.fromValue(i.getState().getName());
         if (stateName == InstanceStateName.Pending || stateName == InstanceStateName.Running) {
           EC2AbstractSlave foundSlave = null;
           for (EC2AbstractSlave ec2Node : NodeIterator.nodes(EC2AbstractSlave.class)) {
             if (ec2Node.getInstanceId().equals(i.getInstanceId())) {
               foundSlave = ec2Node;
               break;
             }
           }
           // Don't count disconnected slaves as being used, we will connected them later is
           // required
           if (foundSlave != null && foundSlave.toComputer().isOffline()) continue;
           n++;
         }
       }
     }
   }
   // Count pending spot requests too
   for (SpotInstanceRequest sir :
       connect().describeSpotInstanceRequests().getSpotInstanceRequests()) {
     // Count Spot requests that are open and still have a
     // chance to be active.
     if (sir.getState().equals("open")) {
       n++;
     }
   }
   return n;
 }
Exemplo n.º 15
0
  public weka.core.Instances toWekaInstances() {
    // attributes
    FastVector wattrs = new FastVector();
    Iterator itr = attributes.iterator();
    while (itr.hasNext()) {
      Attribute attr = (Attribute) itr.next();
      wattrs.addElement(attr.toWekaAttribute());
    }
    // data instances
    weka.core.Instances winsts = new weka.core.Instances(name, wattrs, instances.size());
    itr = instances.iterator();

    while (itr.hasNext()) {
      Instance inst = (Instance) itr.next();
      Iterator itrval = inst.getValues().iterator();
      Iterator itrmis = inst.getMissing().iterator();
      double[] vals = new double[wattrs.size()];
      for (int i = 0; i < wattrs.size(); i++) {
        double val = (Double) itrval.next();
        if ((Boolean) itrmis.next()) {
          vals[i] = weka.core.Instance.missingValue();
        } else {
          vals[i] = val;
        }
      }
      weka.core.Instance winst = new weka.core.Instance(1, vals);
      winst.setDataset(winsts);
      winsts.add(winst);
    }
    winsts.setClassIndex(this.class_index);
    return winsts;
  }
Exemplo n.º 16
0
 /* returns a value in the table on the row and index */
 public String toString(int row, int index) {
   if (instances == null) {
     return "";
   }
   Instance inst = (Instance) instances.get(row);
   return inst.toString(this, index);
 }
Exemplo n.º 17
0
 private void getEndpointsTrace(Reference ref, EndpointI[] endpoints, boolean cached) {
   if (endpoints != null && endpoints.length > 0) {
     if (cached) {
       trace("found endpoints in locator table", ref, endpoints);
     } else {
       trace("retrieved endpoints from locator, adding to locator table", ref, endpoints);
     }
   } else {
     final Instance instance = ref.getInstance();
     StringBuilder s = new StringBuilder(128);
     s.append("no endpoints configured for ");
     if (ref.getAdapterId().length() > 0) {
       s.append("adapter\n");
       s.append("adapter = ");
       s.append(ref.getAdapterId());
       s.append("\n");
     } else {
       s.append("object\n");
       s.append("object = ");
       s.append(instance.identityToString(ref.getIdentity()));
       s.append("\n");
     }
     instance.initializationData().logger.trace(instance.traceLevels().locationCat, s.toString());
   }
 }
 @Override
 public Label predict(Instance instance) {
   Label l = null;
   if (instance.getLabel() instanceof ClassificationLabel || instance.getLabel() == null) {
     // ----------------- declare variables ------------------
     double lambda = 0.0;
     RealVector x_instance = new ArrayRealVector(matrixX.getColumnDimension(), 0);
     double result = 0.0;
     // -------------------------- initialize xi -------------------------
     for (int idx = 0; idx < matrixX.getColumnDimension(); idx++) {
       x_instance.setEntry(idx, instance.getFeatureVector().get(idx + 1));
     }
     // ------------------ get lambda -----------------------
     for (int j = 0; j < alpha.getDimension(); j++) {
       lambda += alpha.getEntry(j) * kernelFunction(matrixX.getRowVector(j), x_instance);
     }
     // ----------------- make prediction -----------------
     Sigmoid g = new Sigmoid(); // helper function
     result = g.value(lambda);
     l = new ClassificationLabel(result < 0.5 ? 0 : 1);
   } else {
     System.out.println("label type error!");
   }
   return l;
 }
  public int accept(int ins_num, int income_seq, String content) throws RemoteException {
    if (!work) return -1;

    Instance res = instances.get(ins_num);

    if (res == null) return -1;
    else {

      if (income_seq >= res.n_p) {

        res.n_p = income_seq;

        res.n_a = income_seq;

        res.content = content;

        res.decided = true;

        INS_NUM++;

        return income_seq;
      }
    }

    return -1;
  }
 /** Add 1 to the count of the specific type. */
 public void addCount(String type) {
   if (!PerformanceState.threadStateEnabled() || PerformanceState.isRecordingSuspended()) {
     return;
   }
   Instance operationalObj = (Instance) this.instance();
   operationalObj.addCount(1, 0, type);
 }
Exemplo n.º 21
0
 private void initUI() {
   tblMain.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   refresh();
   btAdd.addActionListener(
       e -> {
         PropertyForm.start(null);
         refresh();
       });
   btEdit.addActionListener(e -> editAction());
   btRemove.addActionListener(
       e -> {
         Instance instance =
             ((InstanceTableModel) tblMain.getModel()).getItem(tblMain.getSelectedRow());
         if (instance != null && !instance.isNew()) {
           int dialogButton = JOptionPane.YES_NO_OPTION;
           int dialogResult =
               JOptionPane.showConfirmDialog(null, "Remove row ?", "Confirm", dialogButton);
           if (dialogResult == 0) {
             ConfigHelper.getInstance().remove(instance);
             refresh();
           }
         }
       });
   btRun.addActionListener(e -> this.startLoad(this));
   progressBar.setMinimum(0);
   progressBar.setStringPainted(true);
   tblMain.addMouseListener(
       new MouseAdapter() {
         public void mousePressed(MouseEvent me) {
           if (me.getClickCount() == 2) {
             editAction();
           }
         }
       });
 }
Exemplo n.º 22
0
  /**
   * It reads the whole input data-set and it stores each example and its associated output value in
   * local arrays to ease their use.
   *
   * @param datasetFile String name of the file containing the dataset
   * @param train boolean It must have the value "true" if we are reading the training data-set
   * @throws IOException If there ocurs any problem with the reading of the data-set
   */
  public void readRegressionSet(String datasetFile, boolean train) throws IOException {
    try {
      // Load in memory a dataset that contains a regression problem
      IS.readSet(datasetFile, train);
      nData = IS.getNumInstances();
      nInputs = Attributes.getInputNumAttributes();
      nVars = nInputs + Attributes.getOutputNumAttributes();

      // outputIntegerheck that there is only one output variable
      if (Attributes.getOutputNumAttributes() > 1) {
        System.out.println("This algorithm can not process MIMO datasets");
        System.out.println("All outputs but the first one will be removed");
        System.exit(1);
      }
      boolean noOutputs = false;
      if (Attributes.getOutputNumAttributes() < 1) {
        System.out.println("This algorithm can not process datasets without outputs");
        System.out.println("Zero-valued output generated");
        noOutputs = true;
        System.exit(1);
      }

      // Initialice and fill our own tables
      X = new double[nData][nInputs];
      missing = new boolean[nData][nInputs];
      outputInteger = new int[nData];

      // Maximum and minimum of inputs
      emax = new double[nInputs];
      emin = new double[nInputs];
      for (int i = 0; i < nInputs; i++) {
        emax[i] = Attributes.getAttribute(i).getMaxAttribute();
        emin[i] = Attributes.getAttribute(i).getMinAttribute();
      }
      // All values are casted into double/integer
      nClasses = 0;
      for (int i = 0; i < nData; i++) {
        Instance inst = IS.getInstance(i);
        for (int j = 0; j < nInputs; j++) {
          X[i][j] = IS.getInputNumericValue(i, j); // inst.getInputRealValues(j);
          missing[i][j] = inst.getInputMissingValues(j);
          if (missing[i][j]) {
            X[i][j] = emin[j] - 1;
          }
        }

        if (noOutputs) {
          outputReal[i] = outputInteger[i] = 0;
        } else {
          outputReal[i] = IS.getOutputNumericValue(i, 0);
          outputInteger[i] = (int) outputReal[i];
        }
      }
    } catch (Exception e) {
      System.out.println("DBG: Exception in readSet");
      e.printStackTrace();
    }
    computeStatistics();
  }
Exemplo n.º 23
0
 @Override
 @SuppressWarnings("try")
 protected void run(StructuredGraph graph) {
   try (NodeEventScope scope = verifyImmutableGraph(graph)) {
     Instance inst = new Instance();
     inst.run(graph, selectedStrategy, immutableGraph);
   }
 }
Exemplo n.º 24
0
 /**
  * Returns the attribute of this object with the given name. All instances which constitute the
  * object are searched.
  *
  * @param attributeName the attribute to find
  * @return the attribute with the given name, or <code>null</code> if the named attribute doesn't
  *     exist
  */
 public Variable getAttribute(String attributeName) {
   for (Iterator i = instances.iterator(); i.hasNext(); ) {
     Instance in = (Instance) i.next();
     Variable v = in.getAttribute(attributeName);
     if (v != null) return v;
   }
   return null;
 }
Exemplo n.º 25
0
 /**
  * Private function to compute default number of accurate instances in the specified data for the
  * consequent of the rule
  *
  * @param data the data in question
  * @return the default accuracy number
  */
 private double computeDefAccu(Instances data) {
   double defAccu = 0;
   for (int i = 0; i < data.numInstances(); i++) {
     Instance inst = data.instance(i);
     if ((int) inst.classValue() == (int) m_Consequent) defAccu += inst.weight();
   }
   return defAccu;
 }
 @Override
 public Dataset copy() {
   DefaultDataset out = new DefaultDataset();
   for (Instance i : this) {
     out.add(i.copy());
   }
   return out;
 }
Exemplo n.º 27
0
 /** function to return the class names of all instances in this object */
 public Collection getClassNames() {
   Collection c = new LinkedList();
   Iterator i = instances.iterator();
   while (i.hasNext()) {
     Instance inst = (Instance) i.next();
     c.add(inst.getInstanceClass().getName());
   }
   return c;
 }
Exemplo n.º 28
0
 @Override
 public int hashCode() {
   int prime = 31;
   int result = 1;
   result = prime * result + ((data == null) ? 0 : data.hashCode());
   result = prime * result + ((dst == null) ? 0 : dst.hashCode());
   result = prime * result + ((src == null) ? 0 : src.hashCode());
   return result;
 }
Exemplo n.º 29
0
  /**
   * Determines whether the AMI of the given instance matches the AMI of template and has the
   * required label (if requiredLabel is non-null)
   */
  private boolean checkInstance(
      PrintStream logger,
      Instance existingInstance,
      Label requiredLabel,
      EC2AbstractSlave[] returnNode) {
    logProvision(logger, "checkInstance: " + existingInstance);
    if (StringUtils.isNotBlank(getIamInstanceProfile())) {
      if (existingInstance.getIamInstanceProfile() != null) {
        if (!existingInstance.getIamInstanceProfile().getArn().equals(getIamInstanceProfile())) {
          logProvision(logger, " false - IAM Instance profile does not match");
          return false;
        }
        // Match, fall through
      } else {
        logProvision(logger, " false - Null IAM Instance profile");
        return false;
      }
    }

    if (existingInstance
            .getState()
            .getName()
            .equalsIgnoreCase(InstanceStateName.Terminated.toString())
        || existingInstance
            .getState()
            .getName()
            .equalsIgnoreCase(InstanceStateName.ShuttingDown.toString())) {
      logProvision(logger, " false - Instance is terminated or shutting down");
      return false;
    }
    // See if we know about this and it has capacity
    for (EC2AbstractSlave node : NodeIterator.nodes(EC2AbstractSlave.class)) {
      if (node.getInstanceId().equals(existingInstance.getInstanceId())) {
        logProvision(logger, "Found existing corresponding Jenkins slave: " + node.getInstanceId());
        if (!node.toComputer().isPartiallyIdle()) {
          logProvision(logger, " false - Node is not partially idle");
          return false;
        }
        // REMOVEME - this was added to force provision to work, but might not allow
        // stopped instances to be found - need to investigate further
        else if (false && node.toComputer().isOffline()) {
          logProvision(logger, " false - Node is offline");
          return false;
        } else if (requiredLabel != null && !requiredLabel.matches(node.getAssignedLabels())) {
          logProvision(logger, " false - we need a Node having label " + requiredLabel);
          return false;
        } else {
          logProvision(logger, " true - Node has capacity - can use it");
          returnNode[0] = node;
          return true;
        }
      }
    }
    logProvision(logger, " true - Instance has no node, but can be used");
    return true;
  }
Exemplo n.º 30
0
  public void count() {

    TIntIntHashMap docCounts = new TIntIntHashMap();

    int index = 0;

    if (instances.size() == 0) {
      logger.info("Instance list is empty");
      return;
    }

    if (instances.get(0).getData() instanceof FeatureSequence) {

      for (Instance instance : instances) {
        FeatureSequence features = (FeatureSequence) instance.getData();

        for (int i = 0; i < features.getLength(); i++) {
          docCounts.adjustOrPutValue(features.getIndexAtPosition(i), 1, 1);
        }

        int[] keys = docCounts.keys();
        for (int i = 0; i < keys.length - 1; i++) {
          int feature = keys[i];
          featureCounts[feature] += docCounts.get(feature);
          documentFrequencies[feature]++;
        }

        docCounts = new TIntIntHashMap();

        index++;
        if (index % 1000 == 0) {
          System.err.println(index);
        }
      }
    } else if (instances.get(0).getData() instanceof FeatureVector) {

      for (Instance instance : instances) {
        FeatureVector features = (FeatureVector) instance.getData();

        for (int location = 0; location < features.numLocations(); location++) {
          int feature = features.indexAtLocation(location);
          double value = features.valueAtLocation(location);

          documentFrequencies[feature]++;
          featureCounts[feature] += value;
        }

        index++;
        if (index % 1000 == 0) {
          System.err.println(index);
        }
      }
    } else {
      logger.info("Unsupported data class: " + instances.get(0).getData().getClass().getName());
    }
  }