Пример #1
0
// Performs one round of validation on the given bin, after training
double checkBin(unsigned bin, const std::vector<Examples>& sets,
                const std::vector<unsigned>& topology, unsigned total)
{
    NeuralNet network(topology);
    std::vector<Example> toTrainOn;
    reconcile(sets, toTrainOn, bin);

    // Train on training set
    Transformation t = getTransformation(toTrainOn);
    applyTransformation(toTrainOn, t, false);
    network.train(toTrainOn, 1.0, 0.001, 4000 * total);

    // Compute average error in validation set, unscaled
    const std::vector<Example>& validation = sets[bin];
    double error;
    for(std::size_t i = 0; i < validation.size(); i++) {
        const Example& original = validation[i];
        network.computeActivation(original.input);
        Output netOut = network.getActivation();
        applyTransformation(netOut, t, true);

        for(std::size_t j = 0; j < netOut.values.size(); j++) {
            error += std::fabs(netOut.values[j] - original.output.values[j]);
        }
    }
    return error / validation.size();
}
void G_parser::recover(vector<int>& seq_t){
    
    cout << "recover" << endl;
    
    fin_updated = false;
    cad_updated = false;
    cadenced = false;
    
    update_optimal(seq_t);
    reconcile(seq_t);//place "rec" in between!
}
Пример #3
0
TEST_F(KVStorageEngineTest, ReconcileIdentsTest) {
    auto opCtx = cc().makeOperationContext();

    // Add a collection, `db.coll1` to both the KVCatalog and KVEngine. The returned value is the
    // `ident` name given to the collection.
    auto swIdentName = createCollection(opCtx.get(), NamespaceString("db.coll1"));
    ASSERT_OK(swIdentName);
    // Create a table in the KVEngine not reflected in the KVCatalog. This should be dropped when
    // reconciling.
    ASSERT_OK(createCollTable(opCtx.get(), NamespaceString("db.coll2")));
    ASSERT_OK(reconcile(opCtx.get()).getStatus());
    auto identsVec = getAllKVEngineIdents(opCtx.get());
    auto idents = std::set<std::string>(identsVec.begin(), identsVec.end());
    // There are two idents. `_mdb_catalog` and the ident for `db.coll1`.
    ASSERT_EQUALS(static_cast<const unsigned long>(2), idents.size());
    ASSERT_TRUE(idents.find(swIdentName.getValue()) != idents.end());
    ASSERT_TRUE(idents.find("_mdb_catalog") != idents.end());

    // Create a catalog entry for the `_id` index. Drop the created the table.
    ASSERT_OK(createIndex(opCtx.get(), NamespaceString("db.coll1"), "_id"));
    ASSERT_OK(dropIndexTable(opCtx.get(), NamespaceString("db.coll1"), "_id"));
    // The reconcile response should include this index as needing to be rebuilt.
    auto reconcileStatus = reconcile(opCtx.get());
    ASSERT_OK(reconcileStatus.getStatus());
    ASSERT_EQUALS(static_cast<const unsigned long>(1), reconcileStatus.getValue().size());
    StorageEngine::CollectionIndexNamePair& toRebuild = reconcileStatus.getValue()[0];
    ASSERT_EQUALS("db.coll1", toRebuild.first);
    ASSERT_EQUALS("_id", toRebuild.second);

    // Now drop the `db.coll1` table, while leaving the KVCatalog entry.
    ASSERT_OK(dropIdent(opCtx.get(), swIdentName.getValue()));
    ASSERT_EQUALS(static_cast<const unsigned long>(1), getAllKVEngineIdents(opCtx.get()).size());

    // Reconciling this should result in an error.
    reconcileStatus = reconcile(opCtx.get());
    ASSERT_NOT_OK(reconcileStatus.getStatus());
    ASSERT_EQUALS(ErrorCodes::UnrecoverableRollbackError, reconcileStatus.getStatus());
}
Пример #4
0
int main(int argc, char** argv) {

  if (argc > 3) {
    const int n = atoi(argv[1]);
    const int dimension = 2 + n*8;

    const int sw = atoi(argv[2]);
    const int times = atoi(argv[3]);

    struct circuit circuit;
    struct daestruct_input* sigma = daestruct_input_create(dimension);    
    inst_circuit(sigma, &circuit, n);

    printf("Circuit created\n");

    struct daestruct_result* result = daestruct_analyse(sigma);

    if (times > 0) {
      struct daestruct_timer* model = daestruct_timer_new();
      struct daestruct_timer* analyse = daestruct_timer_new();
      daestruct_timer_stop(model);
      daestruct_timer_stop(analyse);
      
      daestruct_timer_resume(model);
      struct switch_event se = switch_sub_circuit(&circuit, sw);
      struct daestruct_changed* ch = daestruct_change_orig(sigma, result, se.diff);
      daestruct_timer_stop(model);

      for (int k = 0; k < times; k++) {
	daestruct_result_delete(result);

	daestruct_timer_resume(analyse);
	result = daestruct_changed_analyse(ch);
	daestruct_timer_stop(analyse);

	daestruct_timer_resume(model);
	reconcile(&circuit, &se, ch);
	daestruct_timer_stop(model);

	daestruct_diff_delete(se.diff);

	if (k < times - 1) { 
	  daestruct_timer_resume(model);
	  se = switch_sub_circuit(&circuit, sw);

	  struct daestruct_changed* old = ch;
	  ch = daestruct_change(old, result, se.diff);
	  daestruct_changed_delete(old);
	  daestruct_timer_stop(model);
	}
      }
      
      printf("Analysis of %d events done.\n", times);
      printf("Time spent in analysis:\n");
      daestruct_timer_report(analyse);
      printf("Time spent in modeling:\n");
      daestruct_timer_report(model);
      

      daestruct_timer_delete(analyse);
      daestruct_timer_delete(model);
      daestruct_changed_delete(ch);
    }


    daestruct_result_delete(result);
    daestruct_input_delete(sigma);

    free(circuit.subs);
  }
}