• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ VariableVector类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中VariableVector的典型用法代码示例。如果您正苦于以下问题:C++ VariableVector类的具体用法?C++ VariableVector怎么用?C++ VariableVector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了VariableVector类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: vector_of_zeros

VariableVector vector_of_zeros(const vector<string>& var_names) {
	VariableVector zeros;
	for (vector<string>::const_iterator name = var_names.begin(); name != var_names.end(); ++name) {
		zeros.insert(make_pair(*name, 0));
	}
	return zeros;
}
开发者ID:aravinho,项目名称:tensorflow,代码行数:7,代码来源:GradientDescent.cpp


示例2: getOrderedVars

    XMLSerializer* ResultSet::toHtmlTable (XMLSerializer* xml, const char* tableClass) {
	if (xml == NULL) xml = new XMLSerializer("  ");
	xml->open("table");
	if (tableClass != NULL)
	    xml->attribute("class", "results");
	{
	    const VariableVector cols = getOrderedVars();
	    xml->open("tr"); {
		for (VariableVector::const_iterator col = cols.begin();
		     col != cols.end(); ++col)
		    xml->leaf("th", (*col)->toString());
	    } xml->close();
	    for (ResultSetConstIterator row = begin(); row != end(); ++row) {
		xml->open("tr"); {
		    for (VariableVector::const_iterator col = cols.begin();
			 col != cols.end(); ++col) {
			const POS* val = (*row)->get(*col);
			if (val != NULL)
			    xml->leaf("td", val->toString());
			else
			    xml->leaf("td", "");
		    }
		} xml->close();
	    }
	} xml->close();
	return xml;
    }
开发者ID:RubenVerborgh,项目名称:SWObjects,代码行数:27,代码来源:ResultSet.cpp


示例3: scale_variable_vector

VariableVector scale_variable_vector(const VariableVector& vec, double scaling_factor) {

	VariableVector scaled;

	for (VariableVector::const_iterator it = vec.begin(); it != vec.end(); ++it) {
		scaled.insert(make_pair(it->first, it->second * scaling_factor));
	}

	return scaled;
}
开发者ID:aravinho,项目名称:tensorflow,代码行数:10,代码来源:GradientDescent.cpp


示例4: add_variable_vectors

VariableVector add_variable_vectors(const VariableVector& vec1, const VariableVector& vec2) {
	
	VariableVector empty;
	VariableVector sum;
	string var_name;
	double component_sum;

	// if the vectors are of different sizes, return empty
	if (vec1.size() != vec2.size()) return empty;

	for (VariableVector::const_iterator it1 = vec1.begin(); it1 != vec1.end(); ++it1) {

		var_name = it1->first;

		// if this variable is in both vectors, add the values
		if (vec2.count(var_name) != 0) {
			component_sum = it1->second + vec2.at(var_name);
			sum.insert(make_pair(var_name, component_sum));
		} 
		// if this variable is only in vec1, return empty
		else {
			return empty;
		}
	}

	// if we reach this point, every variable in vec1 is also in vec2
	// since both vectors are of the same size, it is safe to return

	return sum;
}
开发者ID:aravinho,项目名称:tensorflow,代码行数:30,代码来源:GradientDescent.cpp


示例5: increment_weight_vector

VariableVector increment_weight_vector(const VariableVector& weights, const VariableVector& scaled_gradient) {

	VariableVector empty;
	

	if (weights.size() != scaled_gradient.size()) {
		return empty;
	}

	VariableVector incremented;
	string partial_name, weight_name;
	double scaled_partial, weight_val;

	for (VariableVector::const_iterator it = scaled_gradient.begin(); it != scaled_gradient.end(); ++it) {
		partial_name = it->first;
		scaled_partial = it->second;

		weight_name = partial_name_to_weight_name(partial_name);

		if (weights.count(weight_name) == 0) {
			return empty;
		}

		weight_val = weights.at(weight_name);

		incremented.insert(make_pair(weight_name, weight_val + scaled_partial));
	}

	return incremented;
}
开发者ID:aravinho,项目名称:tensorflow,代码行数:30,代码来源:GradientDescent.cpp


示例6: component_wise_div

VariableVector component_wise_div(const VariableVector& vec, double divisor) {

	VariableVector quotient;

	if (divisor == 0) {
		cerr << "Cannot divide by 0." << endl;
		return quotient;
	}

	for (VariableVector::const_iterator it = vec.begin(); it != vec.end(); ++it) {
		quotient.insert(make_pair(it->first, it->second / divisor));
	}

	return quotient;
}
开发者ID:aravinho,项目名称:tensorflow,代码行数:15,代码来源:GradientDescent.cpp


示例7: avg_gradient

VariableVector avg_gradient(const string& gcp_filename, const vector<string>& partial_names, const VariableVector& weights, const vector<pair<VariableVector, VariableVector> >& training_data) {
	
	VariableVector empty;
	// check for trivial errors
	if (partial_names.size() != weights.size()) return empty;

	// initialize the sum_of_partials_vector
	VariableVector sum_of_partials = vector_of_zeros(partial_names);

	VariableVector *partials;
	int find_partials_success = 0;


	for (vector<pair<VariableVector, VariableVector> >::const_iterator datum = training_data.begin(); datum != training_data.end(); ++datum) {

		partials = new VariableVector();

		VariableVector inputs = datum->first;
		VariableVector outputs = datum->second;
		
		find_partials_success = find_partials(gcp_filename, partials, weights, inputs, outputs);
		if (find_partials_success != 0) return empty;

		sum_of_partials = add_variable_vectors(sum_of_partials, *partials);
		if (sum_of_partials.size() == 0) return empty;

		delete partials;
	}

	return component_wise_div(sum_of_partials, training_data.size());
}
开发者ID:aravinho,项目名称:tensorflow,代码行数:31,代码来源:GradientDescent.cpp


示例8: calculate_weights

VariableVector calculate_weights(const string& gcp_filename, const vector<string>& weight_names,
	const vector<string>& partial_names, const vector<pair<VariableVector, VariableVector> >& training_data) {

	VariableVector weights = initial_weight_guess(weight_names);
	VariableVector gradient = avg_gradient(gcp_filename, partial_names, weights, training_data);

	int num_iterations = 0;
	cout << "Calculating weights for GCP " << gcp_filename << "..." << endl;
	while (!approx_zero(gradient, partial_names) && num_iterations < MAX_NUM_ITERATIONS) {
		weights = increment_weight_vector(weights, scale_variable_vector(gradient, -1 * LEARNING_RATE));
		gradient = avg_gradient(gcp_filename, partial_names, weights, training_data);
		num_iterations++;
		if (gradient.size() == 0) break;
	}

	return weights;
}
开发者ID:aravinho,项目名称:tensorflow,代码行数:17,代码来源:GradientDescent.cpp


示例9: distance_between_variable_vectors

double distance_between_variable_vectors(const VariableVector& vec1, const VariableVector& vec2) {
	// Both vectors must have the same dimension
	if (vec1.size() != vec2.size()) {
		return -1;
	}

	double square_distance = 0;
	string var_name;
	double val1, val2;

	for (VariableVector::const_iterator it = vec1.begin(); it != vec1.end(); ++it) {

		var_name = it->first;

		// Both vectors must have exactly the same variables
		if (vec2.count(var_name) == 0) {
			return -1;
		}

		val1 = vec1.at(var_name);
		val2 = vec2.at(var_name);

		square_distance += pow((val1 - val2), 2);
	}

	return pow(square_distance, 0.5);
}
开发者ID:aravinho,项目名称:tensorflow,代码行数:27,代码来源:GradientDescent.cpp


示例10: operator

	bool operator() (const Result* lhs, const Result* rhs) {
	    for (VariableVectorConstIterator it = vars.begin();
		 it != vars.end(); ++it) {
		// 			SPARQLSerializer s;
		// 			pair.expression->express(&s);
		const POS* l = lhs->get(*it);
		const POS* r = rhs->get(*it);
		if (r == NULL) {
		    if (l == NULL)
			continue;
		    else
			return false;
		}
		if (l == NULL)
		    return true;
		if (dynamic_cast<const Bindable*>(l) && 
		    dynamic_cast<const Bindable*>(r))
		    continue;
		if (l != r)
		    return posFactory->lessThan(l, r);
	    }
	    return false;
	}
开发者ID:RubenVerborgh,项目名称:SWObjects,代码行数:23,代码来源:ResultSet.cpp


示例11: approx_zero

bool approx_zero(const VariableVector& vec, const vector<string>& partial_names) {
	if (vec.size() != partial_names.size()) {
		return false;
	}

	VariableVector zeros = vector_of_zeros(partial_names);
	double pyth_dist = distance_between_variable_vectors(vec, zeros);
	if (pyth_dist == -1) {
		return false;
	}

	return (pyth_dist <= GRADIENT_PRECISION);

}
开发者ID:aravinho,项目名称:tensorflow,代码行数:14,代码来源:GradientDescent.cpp


示例12: variable_vector_union

const VariableVector variable_vector_union(const VariableVector& vec1, const VariableVector& vec2) {

	VariableVector empty;
	VariableVector v;

	// add all the variables in Vec 1 first
	// if any of these variables are seen in Vec 2, this is an error. Return the empty Variable Vector.
	// if there is no overlap, then it is safe to add all the variables in Vec 2
	for (VariableVector::const_iterator it1 = vec1.begin(); it1 != vec1.end(); ++it1) {
		if (vec2.count(it1->first) != 0) {
			return empty;
		}
		v.insert(make_pair(it1->first, it1->second));
	}

	for (VariableVector::const_iterator it2 = vec2.begin(); it2 != vec2.end(); ++it2) {
		v.insert(make_pair(it2->first, it2->second));
	}

	return v;
}
开发者ID:aravinho,项目名称:tensorflow,代码行数:21,代码来源:GradientDescent.cpp


示例13: size

    std::string ResultSet::toString (NamespaceMap* namespaces) const {
	std::stringstream s;
	if (resultType == RESULT_Boolean)
	    return size() > 0 ? "true\n" : "false\n" ;

	else if (resultType == RESULT_Graphs)
	    return std::string("<RdfDB result>\n") + db->toString() + "\n</RdfDB result>";

	/* Get column widths and fill namespace declarations. */
	std::vector< const POS* > vars;
	std::vector< size_t > widths;
	unsigned count = 0;
	unsigned lastInKnownVars = 0;
	{
	    std::map< const POS*, unsigned > pos2col;
	    const VariableVector cols = getOrderedVars();
//	    vars = getOrderedVars();
	    for (VariableVectorConstIterator varIt = cols.begin() ; varIt != cols.end(); ++varIt) {
		const POS* var = *varIt;
		pos2col[var] = count++;
		widths.push_back(var->toString().size());
		vars.push_back(var);
	    }

	    VariableList intruders;
	    lastInKnownVars = count;
	    for (ResultSetConstIterator row = results.begin() ; row != results.end(); ++row)
		for (BindingSetIterator b = (*row)->begin(); b != (*row)->end(); ++b) {
		    const POS* var = b->first;
		    if (pos2col.find(var) == pos2col.end()) {
			/* Error: a variable not listed in knownVars. */
			pos2col[var] = count++;
			std::string rendered(render(var, namespaces));
			widths.push_back(rendered.size());
			vars.push_back(var);
			intruders.insert(var);
		    }
		    std::string rendered(render(b->second.pos, namespaces));
		    size_t width = rendered.size();
		    if (width > widths[pos2col[var]])
			widths[pos2col[var]] = width;
		}
	}

	/* Generate ResultSet string. */
	/*   Top Border */
	unsigned i;
	for (i = 0; i < count; i++) {
	    s << (i == 0 ? (ordered == true ? BoxChars::GBoxChars->ordered : BoxChars::GBoxChars->ul) : BoxChars::GBoxChars->us);
	    s << STRING(widths[i]+2, BoxChars::GBoxChars->ub);
	}
	s << BoxChars::GBoxChars->ur << std::endl;

	/*   Column Headings */
	for (i = 0; i < count; i++) {
	    const POS* var = vars[i];
	    s << (i == 0 ? BoxChars::GBoxChars->rl : i < lastInKnownVars ? BoxChars::GBoxChars->rs : BoxChars::GBoxChars->unlistedVar) << ' ';
	    size_t width = var->toString().length();
	    s << var->toString() << STRING(widths[i] - width, BoxChars::GBoxChars->rb) << ' '; // left justified.
	}
	s << BoxChars::GBoxChars->rr << std::endl;

	/*  Rows */
	for (ResultSetConstIterator row = results.begin() ; row != results.end(); row++) {
#if (INTRA_ROW_SEPARATORS)
	    /*  Intra-row Border */
	    for (i = 0; i < count; i++) {
		s << (i == 0 ? BoxChars::GBoxChars->sl : BoxChars::GBoxChars->ss);
		s << std::string(widths[i]+2, BoxChars::GBoxChars->sb);
	    }
	    s << BoxChars::GBoxChars->sr << std::endl;
#endif
	    /*  Values */
	    for (i = 0; i < count; ++i) {
		const POS* var = vars[i];
		const POS* val = (*row)->get(var);
		const std::string str = render(val, namespaces);
		s << (i == 0 ? BoxChars::GBoxChars->rl : BoxChars::GBoxChars->rs) << ' ';
		size_t width = str.length();
		s << STRING(widths[i] - width, BoxChars::GBoxChars->rb) << str << ' '; // right justified.
	    }
	    s << BoxChars::GBoxChars->rr << std::endl;
	}

	/*   Bottom Border */
	for (i = 0; i < count; i++) {
	    s << (i == 0 ? BoxChars::GBoxChars->ll : BoxChars::GBoxChars->ls);
	    s << STRING(widths[i]+2, BoxChars::GBoxChars->lb);
	}
	s << BoxChars::GBoxChars->lr << std::endl;
	return s.str();
    }
开发者ID:RubenVerborgh,项目名称:SWObjects,代码行数:92,代码来源:ResultSet.cpp


示例14: TEST_F

TEST_F(ProjectFixture, RubyMeasureRecord_RubyScript) {
    // Measures
    MeasureVector measures;

    // Null Measure
    measures.push_back(NullMeasure());

    openstudio::path rubyLibDirPath = openstudio::toPath(rubyLibDir());
    openstudio::path perturbScript = rubyLibDirPath/openstudio::toPath("openstudio/runmanager/rubyscripts/PerturbObject.rb");
    RubyMeasure rubyMeasure(perturbScript,
                            FileReferenceType::OSM,
                            FileReferenceType::OSM);
    rubyMeasure.addArgument("inputPath", "in.osm");
    rubyMeasure.addArgument("outputPath", "out.osm");
    rubyMeasure.addArgument("objectType", "OS:Material");
    rubyMeasure.addArgument("nameRegex", "I02 50mm insulation board");
    rubyMeasure.addArgument("field", "3");
    rubyMeasure.addArgument("value", "0.10");

    // RubyMeasure
    measures.push_back(rubyMeasure);

    // Variables
    VariableVector variables;

    variables.push_back(MeasureGroup("Wall Construction",measures));

    // Workflow
    openstudio::runmanager::Workflow workflow;

    // Problem
    Problem problem("Variable",variables,workflow);

    // Save to database
    {
        ProjectDatabase database = getCleanDatabase("RubyMeasureRecord_RubyScript");

        bool didStartTransaction = database.startTransaction();
        EXPECT_TRUE(didStartTransaction);

        // Problem Record
        ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);

        database.save();
        if (didStartTransaction) {
            EXPECT_TRUE(database.commitTransaction());
        }

        // Variable Records
        InputVariableRecordVector measureGroupRecords = problemRecord.inputVariableRecords();
        EXPECT_EQ(1u,measureGroupRecords.size());

        // Discrete Variable Record
        MeasureGroupRecord measureGroupRecord = measureGroupRecords.at(0).cast<MeasureGroupRecord>();
        EXPECT_EQ(2u,measureGroupRecord.measureRecordIds(true).size());
        EXPECT_EQ(2u,measureGroupRecord.measureRecords(true).size());
        RubyMeasureRecord rubyMeasureRecord(rubyMeasure,measureGroupRecord,0);
        EXPECT_EQ("MeasureRecords",rubyMeasureRecord.databaseTableName());
        ObjectRecordVector objectRecordVector = rubyMeasureRecord.children();
        EXPECT_EQ(6u,objectRecordVector.size()); // arguments
        objectRecordVector = rubyMeasureRecord.resources();
        EXPECT_EQ(1u,objectRecordVector.size()); // script
        FileReferenceRecord scriptRecord = rubyMeasureRecord.fileReferenceRecord();
        EXPECT_EQ("FileReferenceRecords",scriptRecord.databaseTableName());

        Measure measure = rubyMeasureRecord.measure();
        EXPECT_EQ(true,measure.isSelected());
        ASSERT_TRUE(measure.optionalCast<RubyMeasure>());
        RubyMeasure rubyMeasureCopy = measure.cast<RubyMeasure>();
        EXPECT_FALSE(rubyMeasureCopy.usesBCLMeasure());
        EXPECT_FALSE(rubyMeasureCopy.isUserScript());
        EXPECT_EQ(6u,rubyMeasureCopy.arguments().size());

        MeasureGroupRecord measureGroupRecordFromRuby = rubyMeasureRecord.measureGroupRecord().get();
        EXPECT_EQ(measureGroupRecord.databaseTableName(),measureGroupRecordFromRuby.databaseTableName());
        EXPECT_EQ(measureGroupRecord.id(),measureGroupRecordFromRuby.id());
    }

    // Reopen database
    {
        ProjectDatabase database = getExistingDatabase("RubyMeasureRecord_RubyScript");

        ProblemRecordVector problemRecords = ProblemRecord::getProblemRecords(database);
        ASSERT_FALSE(problemRecords.empty());
        EXPECT_EQ(1u,problemRecords.size());
        ProblemRecord problemRecord = problemRecords[0];

        // COPY-PASTED FROM ABOVE

        // Variable Records
        InputVariableRecordVector measureGroupRecords = problemRecord.inputVariableRecords();
        EXPECT_EQ(1u,measureGroupRecords.size());

        // Discrete Variable Record
        MeasureGroupRecord measureGroupRecord = measureGroupRecords.at(0).cast<MeasureGroupRecord>();
        EXPECT_EQ(2u,measureGroupRecord.measureRecordIds(true).size());
        EXPECT_EQ(2u,measureGroupRecord.measureRecords(true).size());
        RubyMeasureRecord rubyMeasureRecord(rubyMeasure,measureGroupRecord,0);
        EXPECT_EQ("MeasureRecords",rubyMeasureRecord.databaseTableName());
        ObjectRecordVector objectRecordVector = rubyMeasureRecord.children();
//.........这里部分代码省略.........
开发者ID:whztt07,项目名称:OpenStudio,代码行数:101,代码来源:RubyMeasureRecord_GTest.cpp


示例15: TEST_F

TEST_F(AnalysisFixture, DDACEAlgorithmOptions) {

  // problem with three variables
  VariableVector variables;
  BCLMeasure bclMeasure(resourcesPath() / toPath("utilities/BCL/Measures/v2/SetWindowToWallRatioByFacade"));
  RubyMeasure measure(bclMeasure);
  variables.push_back(RubyContinuousVariable("Var 1",OSArgument::makeDoubleArgument("wwr1"),measure));
  variables.push_back(RubyContinuousVariable("Var 2",OSArgument::makeDoubleArgument("wwr2"),measure));
  variables.push_back(RubyContinuousVariable("Var 3",OSArgument::makeDoubleArgument("wwr3"),measure));
  Problem problem("Null Problem",variables,runmanager::Workflow());

  DDACEAlgorithmOptions options(DDACEAlgorithmType::grid);
  EXPECT_EQ(DDACEAlgorithmType(DDACEAlgorithmType::grid),options.algorithmType());
  EXPECT_FALSE(options.samples());
  options.setSamplesForGrid(2,problem);
  ASSERT_TRUE(options.samples());
  EXPECT_EQ(8,options.samples().get());

  options.setSamplesForGrid(5,problem);
  ASSERT_TRUE(options.samples());
  EXPECT_EQ(125,options.samples().get());

  DDACEAlgorithmOptions optionsClone = options.clone().cast<DDACEAlgorithmOptions>();
  // all Attributes should be equivalent but have different UUIDs
  AttributeVector attributes = options.options();
  AttributeVector attributeClones = optionsClone.options();
  ASSERT_EQ(attributes.size(),attributeClones.size());
  for (unsigned i = 0, n = attributes.size(); i < n; ++i) {
    EXPECT_TRUE(attributes[i] == attributeClones[i]);
    EXPECT_FALSE(attributes[i].uuid() == attributeClones[i].uuid());
    EXPECT_FALSE(attributes[i].versionUUID() == attributeClones[i].versionUUID());
  }

  options = DDACEAlgorithmOptions(DDACEAlgorithmType::lhs);
  options.setSeed(891678);
  options.setSamples(62);
  ASSERT_TRUE(options.seed());
  EXPECT_EQ(891678,options.seed().get());
  ASSERT_TRUE(options.samples());
  EXPECT_EQ(62,options.samples().get());
  EXPECT_FALSE(options.symbols());
  options.setSeed(1);
  ASSERT_TRUE(options.seed());
  EXPECT_EQ(1,options.seed().get());
  options.clearSeed();
  EXPECT_FALSE(options.seed());

  options = DDACEAlgorithmOptions(DDACEAlgorithmType::oas);
  options.setSamplesAndSymbolsForOrthogonalArray(13,1);
  EXPECT_TRUE(options.seed()); // default is to generate a fixed seed
  ASSERT_TRUE(options.symbols());
  EXPECT_EQ(13,options.symbols().get());
  ASSERT_TRUE(options.samples());
  EXPECT_EQ(169,options.samples().get());

  optionsClone = options.clone().cast<DDACEAlgorithmOptions>();
  // all Attributes should be equivalent but have different UUIDs
  attributes = options.options();
  attributeClones = optionsClone.options();
  ASSERT_EQ(attributes.size(),attributeClones.size());
  for (unsigned i = 0, n = attributes.size(); i < n; ++i) {
    EXPECT_TRUE(attributes[i] == attributeClones[i]);
    EXPECT_FALSE(attributes[i].uuid() == attributeClones[i].uuid());
    EXPECT_FALSE(attributes[i].versionUUID() == attributeClones[i].versionUUID());
  }

  options.clearSymbols();
  EXPECT_FALSE(options.symbols());
  EXPECT_TRUE(options.samples());
  options.clearSamples();
  EXPECT_FALSE(options.samples());

  int n = DDACEAlgorithmOptions::samplesForCentralComposite(problem);
  EXPECT_EQ(15,n);
  n = DDACEAlgorithmOptions::samplesForBoxBehnken(problem);
  EXPECT_EQ(13,n);
}
开发者ID:jtanaa,项目名称:OpenStudio,代码行数:77,代码来源:DDACEAlgorithm_GTest.cpp


示例16: TEST_F

TEST_F(ProjectFixture, ProblemRecord)
{
  //Logger::instance().logLevel(Debug);

  openstudio::path rubyLibDirPath = openstudio::toPath(rubyLibDir());
  openstudio::path perturbScript = rubyLibDirPath/openstudio::toPath("openstudio/runmanager/rubyscripts/PerturbObject.rb");

  // Workflow
  Workflow workflow;

  // Variables
  VariableVector variables;

  // Measures
  MeasureVector perturbations1;
  MeasureVector perturbations2;

  // Discrete Variable Records
  InputVariableRecordVector measureGroupRecords;

  {
    // Problem
    Problem problem("0 Variables",variables,workflow);

    // Project Database
    ProjectDatabase database = getCleanDatabase("ProblemRecord");

    // Problem Record
    ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);

    InputVariableRecordVector measureGroupRecords = problemRecord.inputVariableRecords();

    EXPECT_EQ(0u,measureGroupRecords.size());
  }

  {
    perturbations1.push_back(NullMeasure());

    variables.push_back(analysis::MeasureGroup("",perturbations1));

    // Problem
    Problem problem("perturbations1",variables,workflow);

    // Project Database
    ProjectDatabase database = getCleanDatabase("ProblemRecord");

    // Problem Record
    ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);

    measureGroupRecords = problemRecord.inputVariableRecords();

    EXPECT_EQ(1u,measureGroupRecords.size());

    // Discrete Variable Record
    MeasureGroupRecord measureGroupRecord = measureGroupRecords.at(0).cast<MeasureGroupRecord>();

    EXPECT_EQ(1u,measureGroupRecord.measureRecordIds(true).size());
    EXPECT_EQ(1u,measureGroupRecord.measureRecords(true).size());
  }

  {
    variables.push_back(MeasureGroup("Wall Construction",perturbations1));

    // Problem
    Problem problem("perturbations1",variables,workflow);

    // Project Database
    ProjectDatabase database = getCleanDatabase("ProblemRecord");

    // Problem Record
    ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);

    measureGroupRecords = problemRecord.inputVariableRecords();

    EXPECT_EQ(2u,measureGroupRecords.size());

    // Discrete Variable Record
    MeasureGroupRecord variable1 = measureGroupRecords.at(0).cast<MeasureGroupRecord>();

    EXPECT_EQ(static_cast<unsigned>(1), variable1.measureRecords(true).size());
    EXPECT_EQ(static_cast<unsigned>(1), variable1.measureRecords(false).size());
    EXPECT_EQ(static_cast<unsigned>(2), problemRecord.inputVariableRecords().size());
  }

  {
    perturbations2.push_back(NullMeasure());

    variables.push_back(MeasureGroup("Roof Construction",perturbations2));

    // Problem
    Problem problem("perturbations2",variables,workflow);

    // Project Database
    ProjectDatabase database = getCleanDatabase("ProblemRecord");

    // Problem Record
    ProblemRecord problemRecord = ProblemRecord::factoryFromProblem(problem,database);

    measureGroupRecords = problemRecord.inputVariableRecords();

//.........这里部分代码省略.........
开发者ID:ORNL-BTRIC,项目名称:OpenStudio,代码行数:101,代码来源:ProblemRecord_GTest.cpp


示例17: problem

openstudio::analysis::Analysis AnalysisFixture::analysis1(AnalysisState state) {
  // Create problem and analysis
  Problem problem("My Problem");

  BCLMeasure bclMeasure(resourcesPath() / toPath("utilities/BCL/Measures/SetWindowToWallRatioByFacade"));
  RubyMeasure measure(bclMeasure);

  // Measure Group
  StringVector choices;
  choices.push_back("North");
  choices.push_back("South");
  choices.push_back("East");
  choices.push_back("West");
  OSArgument facade = OSArgument::makeChoiceArgument("facade",choices);
  OSArgument arg = facade.clone();
  arg.setValue("South");
  measure.setArgument(arg);
  OSArgument wwr = OSArgument::makeDoubleArgument("wwr");
  MeasureVector measures(1u,NullMeasure());
  measures.push_back(measure.clone().cast<Measure>());
  arg = wwr.clone();
  arg.setValue(0.1);
  measures.back().cast<RubyMeasure>().setArgument(arg);
  measures.push_back(measure.clone().cast<Measure>());
  arg = wwr.clone();
  arg.setValue(0.2);
  measures.back().cast<RubyMeasure>().setArgument(arg);
  measures.push_back(measure.clone().cast<Measure>());
  arg = wwr.clone();
  arg.setValue(0.3);
  measures.back().cast<RubyMeasure>().setArgument(arg);
  problem.push(MeasureGroup("South Windows",measures));

  // Continuous Variables Attached to Arguments
  arg = facade.clone();
  arg.setValue("North");
  measure.setArgument(arg);
  arg = wwr.clone();
  RubyContinuousVariable wwrCV("Window to Wall Ratio",arg,measure);
  wwrCV.setMinimum(0.0);
  wwrCV.setMaximum(1.0);
  TriangularDistribution td(0.2,0.0,0.5);
  wwrCV.setUncertaintyDescription(td);
  problem.push(wwrCV);
  OSArgument offset = OSArgument::makeDoubleArgument("offset");
  RubyContinuousVariable offsetCV("Offset",offset,measure);
  offsetCV.setMinimum(0.0);
  offsetCV.setMaximum(1.5);
  NormalDistribution nd(0.9,0.05);
  offsetCV.setUncertaintyDescription(nd);
  problem.push(offsetCV);

  // Simulation
  problem.push(WorkItem(JobType::ModelToIdf));
  problem.push(WorkItem(JobType::EnergyPlusPreProcess));
  problem.push(WorkItem(JobType::EnergyPlus));
  problem.push(WorkItem(JobType::OpenStudioPostProcess));

  // Responses
  LinearFunction response1("Energy Use Intensity",
                           VariableVector(1u,OutputAttributeVariable("EUI","site.eui")));
  problem.pushResponse(response1);
  VariableVector vars;
  vars.push_back(OutputAttributeVariable("Heating Energy","heating.energy.gas"));
  vars.push_back(OutputAttributeVariable("Cooling Energy","cooling.energy.elec"));
  DoubleVector coeffs;
  coeffs.push_back(1.0); // approx. source factor
  coeffs.push_back(2.5); // approx. source factor
  LinearFunction response2("Approximate Source Energy",vars,coeffs);
  problem.pushResponse(response2);
  LinearFunction response3("North WWR",VariableVector(1u,wwrCV)); // input variable as output
  problem.pushResponse(response3);

  Analysis analysis("My Analysis",problem,FileReferenceType::OSM);

  if (state == PreRun) {
    // Add three DataPoints
    std::vector<QVariant> values;
    values.push_back(0);
    values.push_back(0.2);
    values.push_back(0.9);
    OptionalDataPoint dataPoint = problem.createDataPoint(values);
    analysis.addDataPoint(*dataPoint);
    values[0] = 1; values[1] = 0.21851789; values[2] = 1.1681938;
    dataPoint = problem.createDataPoint(values);
    analysis.addDataPoint(*dataPoint);
    values[0] = 2; values[1] = 0.0; values[2] = 0.581563892;
    dataPoint = problem.createDataPoint(values);
    analysis.addDataPoint(*dataPoint);
  }
  else {
    // state == PostRun
    // Add one complete DataPoint
    std::vector<QVariant> values;
    values.push_back(1);
    values.push_back(0.3);
    values.push_back(0.9);
    DoubleVector responseValues;
    responseValues.push_back(58.281967);
    responseValues.push_back(718952.281);
//.........这里部分代码省略.........
开发者ID:ORNL-BTRIC,项目名称:OpenStudio,代码行数:101,代码来源:AnalysisFixture.cpp


示例18: TEST_F

TEST_F(AnalysisFixture, Problem_Constructors) {
  VariableVector variables;
  MeasureVector measures;
  runmanager::Workflow workflow;

  // almost-default constructor
  Problem problem("Problem",variables,workflow);
  EXPECT_EQ(0,problem.numVariables());
  OptionalInt combinatorialSize = problem.combinatorialSize(true);
  ASSERT_TRUE(combinatorialSize);
  EXPECT_EQ(0,*combinatorialSize);

  // variables with consistent file types
  variables.clear();
  measures.clear();
  measures.push_back(NullMeasure());
  openstudio::path rubyScriptPath = toPath(rubyLibDir()) /
                                    toPath("openstudio/runmanager/rubyscripts/PerturbObject.rb");
  measures.push_back(RubyMeasure(rubyScriptPath,
                                           FileReferenceType::OSM,
                                           FileReferenceType::OSM));
  measures.push_back(RubyMeasure(rubyScriptPath,
                                           FileReferenceType::OSM,
                                           FileReferenceType::OSM));
  variables.push_back(MeasureGroup("Variable 1",measures));
  measures.clear();
  measures.push_back(RubyMeasure(rubyScriptPath,
                                           FileReferenceType::OSM,
                                           FileReferenceType::IDF));
  variables.push_back(MeasureGroup("Variable 2",measures));
  measures.clear();
  measures.push_back(NullMeasure());
  measures.push_back(RubyMeasure(rubyScriptPath,
                                           FileReferenceType::IDF,
                                           FileReferenceType::IDF));
  variables.push_back(MeasureGroup("Variable 3",measures));
  problem = Problem("Problem",variables,workflow);
  EXPECT_EQ(3,problem.numVariables());
  EXPECT_EQ(6,problem.combinatorialSize(true).get());

  // variables with inconistent file types
  variables.clear();
  measures.clear();
  measures.push_back(NullMeasure());
  measures.push_back(RubyMeasure(rubyScriptPath,
                                           FileReferenceType::OSM,
                                           FileReferenceType::OSM));
  measures.push_back(RubyMeasure(rubyScriptPath,
                                           FileReferenceType::OSM,
                                           FileReferenceType::OSM));
  variables.push_back(MeasureGroup("Variable 1",measures));
  measures.clear();
  measures.push_back(NullMeasure());
  measures.push_back(RubyMeasure(rubyScriptPath,
                                           FileReferenceType::IDF,
                                           FileReferenceType::IDF));
  variables.push_back(MeasureGroup("Variable 2",measures));
  EXPECT_THROW(Problem("Problem",variables,workflow),std::exception);

  // variables and non-null workflow with consistent file types
  variables.clear();
  measures.clear();
  measures.push_back(NullMeasure());
  measures.push_back(RubyMeasure(rubyScriptPath,
                                           FileReferenceType::IDF,
                                           FileReferenceType::IDF));
  variables.push_back(MeasureGroup("Variable 1",measures));
  workflow = runmanager::Workflow();
  workflow.addJob(openstudio::runmanager::JobType::EnergyPlus);
  problem = Problem("Problem",variables,workflow);
  problem.setDisplayName("Display Name");
  problem.setDescription("long winded description");
  EXPECT_EQ(1,problem.numVariables());
  EXPECT_EQ(2,problem.combinatorialSize(true).get());

  // deserialization
  Problem problemCopy(problem.uuid(),
                      problem.versionUUID(),
                      problem.name(),
                      problem.displayName(),
                      problem.description(),
                      problem.workflow(),
                      problem.responses());
  EXPECT_FALSE(problem == problemCopy); // different impls
  EXPECT_TRUE(problem.uuid() == problemCopy.uuid());
  EXPECT_TRUE(problem.versionUUID() == problemCopy.versionUUID());
  EXPECT_EQ(problem.name(),problemCopy.name());
  EXPECT_EQ(problem.displayName(),problemCopy.displayName());
  EXPECT_EQ(problem.description(),problemCopy.description());
  EXPECT_TRUE(problem.workflow() == problemCopy.workflow());

  // variables and non-null workflow with inconsistent file types
  workflow = runmanager::Workflow();
  workflow.addJob(openstudio::runmanager::JobType::ModelToIdf);
  workflow.addJob(openstudio::runmanager::JobType::EnergyPlus);
  EXPECT_THROW(Problem("Problem",variables,workflow),std::exception);
}
开发者ID:MatthewSteen,项目名称:OpenStudio,代码行数:97,代码来源:Problem_GTest.cpp


示例19: ip

void Stepper::unregisterProcess( Process* aProcess )
{ 
    ProcessVector::iterator ip( std::find( theProcessVector.begin(), 
                                    theProcessVector.end(),
                                    aProcess ) );
    
    if( ip == theProcessVector.end() )
    {
        THROW_EXCEPTION_INSIDE( NotFound,
                                asString() + ": Failed to dissociate [" +
                                aProcess->asString() + "] (no such Process is "
                                "associated to this stepper)" );
    }

    typedef std::set< Variable* > VariableSet;
    VariableSet aVarSet;
    Process::VariableReferenceVector const& aVarRefVector(
        aProcess->getVariableReferenceVector() );
    std::transform( aVarRefVector.begin(), aVarRefVector.end(),
                    inserter( aVarSet, aVarSet.begin() ),
                    std::mem_fun_ref( &VariableReference::getVariable ) );

    VariableVector aNewVector;
    VariableVector::size_type aReadWriteVariableOffset,
                             aReadOnlyVariableOffset;

    for( VariableVector::iterator i( theVariableVector.begin() ),
                                  e( theVariableVector.begin()
                                     + theReadWriteVariableOffset );
         i != e; ++i )
    {
        VariableSet::iterator j( aVarSet.find( *i ) );
        if ( j != aVarSet.end() )
            aVarSet.erase( j );
        else
            aNewVector.push_back( *i );
    }

    aReadWriteVariableOffset = aNewVector.size();

    for( VariableVector::iterator i( theVariableVector.begin()
                                     + theReadWriteVariableOffset ),
                                  e( theVariableVector.begin()
                                     + theReadOnlyVariableOffset );
         i != e; ++i )
    {
        VariableSet::iterator j( aVarSet.find( *i ) );
        if ( j != aVarSet.end() )
            aVarSet.erase( j );
        else
            aNewVector.push_back( *i );
    }

    aReadOnlyVariableOffset = aNewVector.size();

    for( VariableVector::iterator i( theVariableVector.begin()
                                     + theReadOnlyVariableOffset ),
                                  e( theVariableVector.end() );
         i != e; ++i )
    {
        VariableSet::iterator j( aVarSet.find( *i ) );
        if ( j != aVarSet.end() )
            aVarSet.erase( j );
        else
            aNewVector.push_back( *i );
    }

    theVariableVector.swap( aNewVector );
    theReadWriteVariableOffset = aReadWriteVariableOffset;
    theReadOnlyVariableOffset = aReadOnlyVariableOffset;

    theProcessVector.erase( ip );
}
开发者ID:ecell,项目名称:spatiocyte,代码行数:73,代码来源:Stepper.cpp


示例20: TEST_F

TEST_F(AnalysisFixture, SequentialSearch) {
  // define dummy problem
  VariableVector variables;
  std::stringstream ss;
  for (int i = 0; i < 5; ++i) {
    MeasureVector measures;
    measures.push_back(NullMeasure());
    measures.push_back(RubyMeasure(toPath("in.rb"),FileReferenceType::OSM,FileReferenceType::OSM));
    ss << "var " << i + 1;
    variables.push_back(MeasureGroup(ss.str(),measures));
    ss.str("");
  }
  FunctionVector functions;
  functions.push_back(LinearFunction("",VariableVector(1u,OutputAttributeContinuousVariable("f1","f1"))));
  functions.push_back(LinearFunction("",VariableVector(1u,OutputAttributeContinuousVariable("f2","f2"))));
  OptimizationProblem problem("By-Hand Problem",functions,variables,runmanager::Workflow());

  // solve dummy problem and check results
  SequentialSearch algorithm(SequentialSearchOptions(0));
  FileReference seed(toPath("in.osm"));
  Analysis analysis("By-Hand Analysis",problem,algorithm,seed);

  int numAdded = algorithm.createNextIteration(analysis);
  EXPECT_EQ(1,numAdded);
  OptimizationDataPointVector nextIteration =
      castVector<OptimizationDataPoint>(analysis.dataPointsToQueue());
  EXPECT_EQ(1u,nextIteration.size());
  while (!nextIteration.empty()) {
    int n = analysis.dataPoints().size();
    LOG(Debug,"Conducting iteration " << algorithm.iter() << " of Sequential Search.");
    OptimizationDataPointVector completeDataPoints =
        castVector<OptimizationDataPoint>(analysis.completeDataPoints());
    OptimizationDataPointVector currentDataPoints =
        castVector<OptimizationDataPoint>(analysis.getDataPoints("current"));
    EXPECT_EQ(1u,currentDataPoints.size());
    ASSERT_FALSE(currentDataPoints.empty());
    EXPECT_EQ(unsigned(algorithm.iter()),analysis.getDataPoints("explored").size());
    if (algorithm.iter() == 0) {
      EXPECT_EQ(1,n);
      EXPECT_EQ(0u,completeDataPoints.size());
    }
    else if (algorithm.iter() == 1) {
      EXPECT_DOUBLE_EQ(20.0,currentDataPoints[0].objectiveValues()[0]);
      EXPECT_DOUBLE_EQ(20.0,currentDataPoints[0].objectiveValues()[1]);
      EXPECT_EQ(6,n);
      EXPECT_EQ(1u,completeDataPoints.size());
      EXPECT_TRUE(currentDataPoints[0] == completeDataPoints[0]);
      EX 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ Variables类代码示例发布时间:2022-05-31
下一篇:
C++ VariableTablePtr类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap