示例#1
0
/* Process command line parameters:
 argv[1]: Name of data file or '-' for stdin
 argv[2]: Number of changepoints
 argv[3]: Number of iterations
 argv[4]: seed for random number generator
 argv[5]: (optional) Prefix for output files
*/
void getFixedArgs(int argc, char **argv) {
  char* endptr;
  const char* usage="icmcstatFixed FILE NK ITERATIONS SEED [OUTPUTPREFIX]";
  double alpha=1, beta=1;

  if(argc<5) fprintf(ERR, "%s\n", usage), exit(1);
  dataFn=argv[1];  
  printf("Reading data from ");

  if(!strcmp(dataFn, "-")) printf("stdin\n");
  else printf("%s\n", dataFn);

  printf("%s nK\n", argv[2]);
  nK = strtol(argv[2], &endptr, 10);
  nProb=nK+1;

  printf("%s iterations\n", argv[3]);
  nIter = strtol(argv[3], &endptr, 10);

  seed = strtol(argv[4], &endptr, 10);
  printf("Seed for random number generator: %i\n", seed);

  /* Optional parameter*/
  if(argc==6) {
    prefix=argv[5];
    printf("Prefix prepended to output files: %s\n", prefix); 
  }

  fprintf(ERR, "Setting alpha=%g, beta=%g\n", alpha, beta);
  setAlpha(alpha); setBeta(beta);
}
示例#2
0
bool Pareto::setSlotBeta(const Number* const x)
{
  bool ok = false;
  if(x != nullptr)
    ok = setBeta(x->getDouble());
  return ok;
}
示例#3
0
FrechetDistribution::FrechetDistribution(double alpha, double beta) 
  : UncertaintyDescription(boost::shared_ptr<detail::UncertaintyDescription_Impl>(
        new detail::UncertaintyDescription_Impl(FrechetDistribution::type())))
{
  setAlpha(alpha);
  setBeta(beta);
}
示例#4
0
GumbelDistribution::GumbelDistribution(double alpha, double beta) 
  : UncertaintyDescription(std::shared_ptr<detail::UncertaintyDescription_Impl>(
        new detail::UncertaintyDescription_Impl(GumbelDistribution::type())))
{
  setAlpha(alpha);
  setBeta(beta);
}
示例#5
0
 void ChainArray::initialise(uint id, const Eigen::VectorXd& sample, 
     double energy, double sigma, double beta)
 {
   setSigma(id, sigma);
   setBeta(id, beta);
   cache_[id].push_back({ sample, energy, sigma_[id], beta_[id], true, SwapType::NoAttempt});
   lastState_[id] = cache_[id].back();
 }
示例#6
0
Eigen::MatrixXd GLMMBelief::evaluateSecondDerivative(const Eigen::VectorXd& x,
						     const Parameters& parameters)
{
  setTheta(parameters.GLMMTheta);
  setBeta(parameters.GLMMBeta);
  auto family = parameters.GLMMFamily;
  auto linearPredictor = computeLinearPredictor(x);
  return LambdatThetaZt_ * family.evaluateSecondDerivative(linearPredictor, response_, weights_).matrix().asDiagonal() * LambdatThetaZt_.transpose();
}
示例#7
0
double GLMMBelief::evaluate(const Eigen::VectorXd& x,
			    const Parameters& parameters)
{
  setTheta(parameters.GLMMTheta);
  setBeta(parameters.GLMMBeta);
  auto family = parameters.GLMMFamily;
  auto linearPredictor = computeLinearPredictor(x);
  return family.evaluate(linearPredictor, response_, weights_);
}
示例#8
0
BetaDistribution::BetaDistribution(double alpha, double beta, double lowerBound, double upperBound) 
  : UncertaintyDescription(boost::shared_ptr<detail::UncertaintyDescription_Impl>(
        new detail::UncertaintyDescription_Impl(BetaDistribution::type())))
{
  setAlpha(alpha);
  setBeta(beta);
  setLowerBound(lowerBound);
  setUpperBound(upperBound);
}
InteractinSimpleGaussian::InteractinSimpleGaussian(System *system, double alpha, double beta) :
    WaveFunction(system)
{
    assert(alpha >= 0);
    m_numberOfParameters = 2;
    m_parameters.reserve(2);
    m_parameters.push_back(alpha);
    m_parameters.push_back(beta);
    setAlpha(alpha);
    setAlpha2(alpha*alpha);
    setBeta(beta);
}
AdaptiveSO2CPGSynPlas::AdaptiveSO2CPGSynPlas(Neuron* perturbingNeuron)
: ExtendedSO2CPG(perturbingNeuron){
    setAlpha(1.01);
    setPhi(0.3);
    setMu(1.00);

    setGamma(0.02);
    setEpsilon(0.03);
    setBeta(0.00);

    // for a range of P from -1 to 1
    setBetaDynamics   (-1.0, 0.003, 0.0000);
    setGammaDynamics  (-1.0, 0.003, 1.0000);
    setEpsilonDynamics(0.04, 0.003, 0.0001);
}
void AdaptiveSO2CPGSynPlas::updateWeights() {
    const double& phi     = getPhi();
    const double& beta    = getBeta();
    const double& gamma   = getGamma();
    const double& epsilon = getEpsilon();
    const double& mu      = getMu();
    const double& F       = getOutput(2);
    const double& w01     = getWeight(0,1);
    const double& x       = getOutput(0);
    const double& y       = getOutput(1);
    const double& P       = getPerturbation();

    // general approach
    setPhi    ( phi     + mu * gamma * F * w01 * y );
    setBeta   ( beta    + betaHebbRate    * x * F - betaDecayRate    * (beta    - betaZero) );
    setGamma  ( gamma   + gammaHebbRate   * x * F - gammaDecayRate   * (gamma   - gammaZero) );
    setEpsilon( epsilon + epsilonHebbRate * F * P - epsilonDecayRate * (epsilon - epsilonZero) );

}
示例#12
0
/* Process command line parameters:
 argv[1]: Name of data file or '-' for stdin
 argv[2]: Number of iterations
 argv[3]: seed for random number generator
 argv[4]: (optional) Prefix for output files

 argv[5]: (optional) For RESTART: Initial changepoint locations
 argv[6]: (optional) For RESTART: Initial success probabilities
*/
void getArgs(int argc, char **argv) {
  const int nArgs=4;
  const int nOpt=3;
  
  char* endptr;
  const char* usage="icmcstat FILE ITERATIONS SEED [OUTPUTPREFIX] [K0FILE] [P0FILE]";
  double alpha=1, beta=1;

  if( (argc<nArgs)|| (argc>nArgs+nOpt)) fprintf(ERR, "%s\n", usage), exit(1);
  dataFn=argv[1];  
  printf("Reading data from ");

  if(!strcmp(dataFn, "-")) printf("stdin\n");
  else printf("%s\n", dataFn);

  printf("%s iterations\n", argv[2]);
  nIter = strtol(argv[2], &endptr, 10);

  seed = strtol(argv[3], &endptr, 10);
  printf("Seed for random number generator: %i\n", seed);

  /* Optional parameters:*/
  /* Prefix */
  if(argc>=nArgs+1) {
    prefix=argv[4];
    printf("Prefix prepended to output files: %s\n", prefix); 
  }

  /* Restart */
  if(argc==nArgs+nOpt) {
    restart=1;
    re_K=argv[5];
    re_P=argv[6];
    printf("Restarting with parameters from:\n\t%s\n\t%s\n", re_K, re_P);
  }

  fprintf(ERR, "Setting alpha=%g, beta=%g\n", alpha, beta);
  setAlpha(alpha); setBeta(beta);
}
ExponentialDistribution::ExponentialDistribution(double beta) 
  : UncertaintyDescription(std::shared_ptr<detail::UncertaintyDescription_Impl>(
        new detail::UncertaintyDescription_Impl(ExponentialDistribution::type())))
{
  setBeta(beta);
}
void CyclicCoordinateDescent::kktSwindle(const ModeFindingArguments& arguments) {

	const auto maxIterations = arguments.maxIterations;
	const auto convergenceType = arguments.convergenceType;
	const auto epsilon = arguments.tolerance;

	// Make sure internal state is up-to-date
	checkAllLazyFlags();


	std::list<ScoreTuple> activeSet;
	std::list<ScoreTuple> inactiveSet;
	std::list<int> excludeSet;

	// Initialize sets
	int intercept = -1;
	if (hXI.getHasInterceptCovariate()) {
		intercept = hXI.getHasOffsetCovariate() ? 1 : 0;
	}

	for (int index = 0; index < J; ++index) {
		if (fixBeta[index]) {
			excludeSet.push_back(index);
		} else {
			if (index == intercept || // Always place intercept into active set
                !jointPrior->getSupportsKktSwindle(index)) {
// 				activeSet.push_back(index);
				activeSet.push_back(std::make_tuple(index, 0.0, true));
			} else {
				inactiveSet.push_back(std::make_tuple(index, 0.0, false));
			}
		}
	}

	bool done = false;
	int swindleIterationCount = 1;

//	int initialActiveSize = activeSet.size();
	int perPassSize = arguments.swindleMultipler;

	while (!done) {

		if (noiseLevel >= QUIET) {
			std::ostringstream stream;
			stream << "\nKKT Swindle count " << swindleIterationCount << ", activeSet size =  " << activeSet.size();
			logger->writeLine(stream);
		}

		// Enforce all beta[inactiveSet] = 0
		for (auto& inactive : inactiveSet) {
			if (getBeta(std::get<0>(inactive)) != 0.0) { // Touch only if necessary
				setBeta(std::get<0>(inactive), 0.0);
			}
		}

		double updateTime = 0.0;
		lastReturnFlag = SUCCESS;
		if (activeSet.size() > 0) { // find initial mode
			auto start = bsccs::chrono::steady_clock::now();

			findMode(begin(activeSet), end(activeSet), maxIterations, convergenceType, epsilon);

			auto end = bsccs::chrono::steady_clock::now();
			bsccs::chrono::duration<double> elapsed_seconds = end-start;
			updateTime = elapsed_seconds.count();
		}

		if (noiseLevel >= QUIET) {
			std::ostringstream stream;
			stream << "update time: " << updateTime << " in " << lastIterationCount << " iterations.";
			logger->writeLine(stream);
		}

		if (inactiveSet.size() == 0 || lastReturnFlag != SUCCESS) { // Computed global mode, nothing more to do, or failed

			done = true;

		} else { // still inactive covariates


			if (swindleIterationCount == maxIterations) {
				lastReturnFlag = MAX_ITERATIONS;
				done = true;
				if (noiseLevel > SILENT) {
					std::ostringstream stream;
					stream << "Reached maximum swindle iterations";
					logger->writeLine(stream);
				}
			} else {

				auto checkConditions = [this] (const ScoreTuple& score) {
					return (std::get<1>(score) <= jointPrior->getKktBoundary(std::get<0>(score)));
				};

//				auto checkAlmostConditions = [this] (const ScoreTuple& score) {
//					return (std::get<1>(score) < 0.9 * jointPrior->getKktBoundary(std::get<0>(score)));
//				};

				// Check KKT conditions

				computeKktConditions(inactiveSet);

				bool satisfied = std::all_of(begin(inactiveSet), end(inactiveSet), checkConditions);

				if (satisfied) {
					done = true;
				} else {
//					auto newActiveSize = initialActiveSize + perPassSize;

					auto count1 = std::distance(begin(inactiveSet), end(inactiveSet));
					auto count2 = std::count_if(begin(inactiveSet), end(inactiveSet), checkConditions);


					// Remove elements from activeSet if less than 90% of boundary
// 					computeKktConditions(activeSet); // TODO Already computed in findMode
//
// // 					for (auto& active : activeSet) {
// // 						std::ostringstream stream;
// // 						stream << "Active: " << std::get<0>(active) << " : " << std::get<1>(active) << " : " << std::get<2>(active);
// // 						logger->writeLine(stream);
// // 					}
//
// 					int countActiveViolations = 0;
// 					while(activeSet.size() > 0 &&
// 						checkAlmostConditions(activeSet.back())
// 					) {
// 						auto& back = activeSet.back();
//
// // 						std::ostringstream stream;
// // 						stream << "Remove: " << std::get<0>(back) << ":" << std::get<1>(back)
// // 						       << " cut @ " << jointPrior->getKktBoundary(std::get<0>(back))
// // 						       << " diff = " << (std::get<1>(back) - jointPrior->getKktBoundary(std::get<0>(back)));
// // 						logger->writeLine(stream);
//
// 						inactiveSet.push_back(back);
// 						activeSet.pop_back();
// 						++countActiveViolations;
// 					}
					// end

					// Move inactive elements into active if KKT conditions are not met
					while (inactiveSet.size() > 0
							&& !checkConditions(inactiveSet.front())
//  							&& activeSet.size() < newActiveSize
					) {
						auto& front = inactiveSet.front();

// 						std::ostringstream stream;
// 						stream << std::get<0>(front) << ":" << std::get<1>(front);
// 						logger->writeLine(stream);

						activeSet.push_back(front);
						inactiveSet.pop_front();
					}

					if (noiseLevel >= QUIET) {
						std::ostringstream stream;
// 						stream << "  Active set violations: " << countActiveViolations << std::endl;
						stream << "Inactive set violations: " << (count1 - count2);
						logger->writeLine(stream);
					}
				}
			}
		}
		++swindleIterationCount;
		perPassSize *= 2;

		logger->yield();			// This is not re-entrant safe
	}

	// restore fixBeta
	std::fill(fixBeta.begin(), fixBeta.end(), false);
	for (auto index : excludeSet) {
		fixBeta[index] = true;
	}
}