本文整理汇总了C++中InitRandom函数的典型用法代码示例。如果您正苦于以下问题:C++ InitRandom函数的具体用法?C++ InitRandom怎么用?C++ InitRandom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InitRandom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitRandom
void NeuronalNet::CreateNet() {
// init random weights:
InitRandom(&inputWeights, 71);
InitRandom(&hiddenBias, 25);
InitRandom(&hiddenWeights, 25);
InitRandom(&outputBias, 1);
}
示例2: NextRandom
static void NextRandom(double *random, long n)
{
long j;
if (idum<=0) InitRandom(0.0);
while (n--) {
/* compute idum= (IA1*idum)%IM1 without overflow */
idum= IA1*(idum%IQ1) - IR1*(idum/IQ1);
if (idum<0) idum+= IM1;
/* compute idum2= (IA2*idum2)%IM2 without overflow */
idum2= IA2*(idum2%IQ2) - IR2*(idum2/IQ2);
if (idum2<0) idum2+= IM2;
/* previous result is used to determine which element of the shuffle
table to use for this result */
j= iy/NDIV; /* in range 0..NTAB-1 */
iy= iv[j]-idum2;
iv[j]= idum;
if (iy<1) iy+= IMM1;
/* Really only IMM1 possible values can be returned, 1<=iy<=IMM1.
Algorithm given by Press and Teukolsky has a slight bug.
Here, the return values are centered in IMM1 equal bins.
If 2.e9 distinct values are not enough, could use, say, idum2
to scoot the points around randomly within bins... */
*random++= AM*(iy-0.5);
}
}
示例3: main
int main( int argc, char **argv )
{
int num_sample=100000;
int t0=clock();
InitRandom(100000);
int t1=clock();
///Initialization performance
printf("** Time elapsed for initialization of %d sample is %d\n \n",num_sample,t1-t0);
Hash2D.Set(Allocated.begin(),Allocated.end());
///Box Query performance
t0=clock();
MyScalarType avg_test=TestBox(num_sample);
t1=clock();
printf("** Time elapsed for %d BOX queries is %d\n, average found %5.5f \n \n",num_sample,t1-t0,avg_test);
///Intersecting segment performance
t0=clock();
MyScalarType avg_int=TestIntersection(num_sample);
t1=clock();
printf("** Time elapsed for %d INTERSECTION queries is %d\n, average found %5.5f \n \n",num_sample,t1-t0,avg_int);
///closest test
t0=clock();
MyScalarType avg_clos=TestClosest(num_sample);
t1=clock();
printf("** Time elapsed for %d CLOSEST queries is %d\n, average found %5.5f \n \n",num_sample,t1-t0,avg_clos);
///reinitialize structure
MyMark.mark=0;
Hash2D.Clear();
int n_test=1000;
InitRandom(n_test,100,0.1);
Hash2D.Set(Allocated.begin(),Allocated.end());
int tested_int=TestCorrectIntersect(n_test);
printf("** Correct Intersect on %d test are %d \n",n_test,tested_int);
int tested_clos=TestCorrectClosest(n_test);
printf("** Correct Closest on %d test are %d \n",n_test,tested_clos);
return 0;
}
示例4: Y_random_seed
void Y_random_seed(int nArgs)
{
double seed= 0.0;
if (nArgs==1) {
if (YNotNil(sp)) seed= YGetReal(sp);
} else if (nArgs>0) {
YError("random_seed takes exactly zero or one arguments");
}
InitRandom(seed);
}
示例5: InitBackground
void InitBackground()
{
int x, y;
InitRandom();
for ( x = 0; x < PARALLAX_GRID_WIDTH; x++ ) {
for ( y = 0; y < PARALLAX_GRID_HEIGHT; y++ ) {
front_tiles[ x ][ y ] = GetRandom() % num_star_tiles;
back_tiles[ x ][ y ] = GetRandom() % num_star_tiles;
}
}
}
示例6: METIS_WPartGraphRecursive
/*************************************************************************
* This function is the entry point for PWMETIS that accepts exact weights
* for the target partitions
**************************************************************************/
void METIS_WPartGraphRecursive(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
idxtype *adjwgt, int *wgtflag, int *numflag, int *nparts,
floattype *tpwgts, int *options, int *edgecut, idxtype *part)
{
int i, j;
GraphType graph;
CtrlType ctrl;
floattype *mytpwgts;
if (*numflag == 1)
Change2CNumbering(*nvtxs, xadj, adjncy);
SetUpGraph(&graph, OP_PMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, *wgtflag);
if (options[0] == 0) { /* Use the default parameters */
ctrl.CType = PMETIS_CTYPE;
ctrl.IType = PMETIS_ITYPE;
ctrl.RType = PMETIS_RTYPE;
ctrl.dbglvl = PMETIS_DBGLVL;
}
else {
ctrl.CType = options[OPTION_CTYPE];
ctrl.IType = options[OPTION_ITYPE];
ctrl.RType = options[OPTION_RTYPE];
ctrl.dbglvl = options[OPTION_DBGLVL];
}
ctrl.optype = OP_PMETIS;
ctrl.CoarsenTo = 20;
ctrl.maxvwgt = 1.5*(idxsum(*nvtxs, graph.vwgt)/ctrl.CoarsenTo);
mytpwgts = fmalloc(*nparts, "PWMETIS: mytpwgts");
for (i=0; i<*nparts; i++)
mytpwgts[i] = tpwgts[i];
InitRandom(-1);
AllocateWorkSpace(&ctrl, &graph, *nparts);
IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl));
IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr));
*edgecut = MlevelRecursiveBisection(&ctrl, &graph, *nparts, part, mytpwgts, 1.000, 0);
IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr));
IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl));
FreeWorkSpace(&ctrl, &graph);
free(mytpwgts);
if (*numflag == 1)
Change2FNumbering(*nvtxs, xadj, adjncy, part);
}
示例7: METIS_EdgeND
/*************************************************************************
* This function is the entry point for OEMETIS
**************************************************************************/
void METIS_EdgeND(int *nvtxs, idxtype *xadj, idxtype *adjncy, int *numflag, int *options,
idxtype *perm, idxtype *iperm)
{
int i, j;
GraphType graph;
CtrlType ctrl;
if (*numflag == 1)
Change2CNumbering(*nvtxs, xadj, adjncy);
SetUpGraph(&graph, OP_OEMETIS, *nvtxs, 1, xadj, adjncy, NULL, NULL, 0);
if (options[0] == 0) { /* Use the default parameters */
ctrl.CType = OEMETIS_CTYPE;
ctrl.IType = OEMETIS_ITYPE;
ctrl.RType = OEMETIS_RTYPE;
ctrl.dbglvl = OEMETIS_DBGLVL;
}
else {
ctrl.CType = options[OPTION_CTYPE];
ctrl.IType = options[OPTION_ITYPE];
ctrl.RType = options[OPTION_RTYPE];
ctrl.dbglvl = options[OPTION_DBGLVL];
}
ctrl.oflags = 0;
ctrl.pfactor = -1;
ctrl.nseps = 1;
ctrl.optype = OP_OEMETIS;
ctrl.CoarsenTo = 20;
ctrl.maxvwgt = 1.5*(idxsum(*nvtxs, graph.vwgt)/ctrl.CoarsenTo);
InitRandom(-1);
AllocateWorkSpace(&ctrl, &graph, 2);
IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl));
IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr));
MlevelNestedDissection(&ctrl, &graph, iperm, ORDER_UNBALANCE_FRACTION, *nvtxs);
IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr));
IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl));
for (i=0; i<*nvtxs; i++)
perm[iperm[i]] = i;
FreeWorkSpace(&ctrl, &graph);
if (*numflag == 1)
Change2FNumberingOrder(*nvtxs, xadj, adjncy, perm, iperm);
}
示例8: m_vNum
SRBM::SRBM(int vNum, int hNum):
m_vNum(vNum), m_hNum(hNum)
{
// allocate space
m_pVB = (double *) m_pool.Allocate(sizeof(double) * vNum);
m_pHB = (double *) m_pool.Allocate(sizeof(double) * hNum);
m_ppW = (double **)m_pool.Allocate(sizeof(double*) * vNum);
for (int i = 0; i < vNum; ++i)
m_ppW[i] = (double *) m_pool.Allocate(sizeof(double) * hNum);
// randomly initialize
InitRandom();
}
示例9: METIS_NodeComputeSeparator
/*************************************************************************
* This function is the entry point for ONWMETIS. It requires weights on the
* vertices. It is for the case that the matrix has been pre-compressed.
**************************************************************************/
void METIS_NodeComputeSeparator(int *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
idxtype *adjwgt, float *ubfactor, int *options, int *sepsize, idxtype *part)
{
int i, j, tvwgt, tpwgts[2];
GraphType graph;
CtrlType ctrl;
SetUpGraph(&graph, OP_ONMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, 3);
tvwgt = idxsum(*nvtxs, graph.vwgt);
if (options[0] == 0) { /* Use the default parameters */
ctrl.CType = ONMETIS_CTYPE;
ctrl.IType = ONMETIS_ITYPE;
ctrl.RType = ONMETIS_RTYPE;
ctrl.dbglvl = ONMETIS_DBGLVL;
}
else {
ctrl.CType = options[OPTION_CTYPE];
ctrl.IType = options[OPTION_ITYPE];
ctrl.RType = options[OPTION_RTYPE];
ctrl.dbglvl = options[OPTION_DBGLVL];
}
ctrl.oflags = OFLAG_COMPRESS; /* For by-passing the pre-coarsening for multiple runs */
ctrl.RType = 2; /* Standard 1-sided node refinement code */
ctrl.pfactor = 0;
ctrl.nseps = 5; /* This should match NUM_INIT_MSECTIONS in ParMETISLib/defs.h */
ctrl.optype = OP_ONMETIS;
InitRandom(options[7]);
AllocateWorkSpace(&ctrl, &graph, 2);
/*============================================================
* Perform the bisection
*============================================================*/
tpwgts[0] = tvwgt/2;
tpwgts[1] = tvwgt-tpwgts[0];
MlevelNodeBisectionMultiple(&ctrl, &graph, tpwgts, *ubfactor*.95);
*sepsize = graph.pwgts[2];
idxcopy(*nvtxs, graph.where, part);
GKfree((void **)&graph.gdata, &graph.rdata, &graph.label, LTERM);
FreeWorkSpace(&ctrl, &graph);
}
示例10: METIS_NodeComputeSeparator
/*************************************************************************
* This function is the entry point for ONWMETIS. It requires weights on the
* vertices. It is for the case that the matrix has been pre-compressed.
**************************************************************************/
void METIS_NodeComputeSeparator(idxtype *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
idxtype *adjwgt, idxtype *options, idxtype *sepsize, idxtype *part)
{
idxtype i, j, tvwgt, tpwgts[2];
GraphType graph;
CtrlType ctrl;
SetUpGraph(&graph, OP_ONMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, 3);
tvwgt = idxsum(*nvtxs, graph.vwgt, 1);
if (options[0] == 0) { /* Use the default parameters */
ctrl.CType = ONMETIS_CTYPE;
ctrl.IType = ONMETIS_ITYPE;
ctrl.RType = ONMETIS_RTYPE;
ctrl.dbglvl = ONMETIS_DBGLVL;
}
else {
ctrl.CType = options[OPTION_CTYPE];
ctrl.IType = options[OPTION_ITYPE];
ctrl.RType = options[OPTION_RTYPE];
ctrl.dbglvl = options[OPTION_DBGLVL];
}
ctrl.oflags = 0;
ctrl.pfactor = 0;
ctrl.nseps = 3;
ctrl.optype = OP_ONMETIS;
ctrl.CoarsenTo = amin(100, *nvtxs-1);
ctrl.maxvwgt = 1.5*tvwgt/ctrl.CoarsenTo;
InitRandom(options[7]);
AllocateWorkSpace(&ctrl, &graph, 2);
/*============================================================
* Perform the bisection
*============================================================*/
tpwgts[0] = tvwgt/2;
tpwgts[1] = tvwgt-tpwgts[0];
MlevelNodeBisectionMultiple(&ctrl, &graph, tpwgts, 1.02);
*sepsize = graph.pwgts[2];
idxcopy(*nvtxs, graph.where, part);
FreeGraph(&graph, 0);
FreeWorkSpace(&ctrl, &graph);
}
示例11: METIS_mCPartGraphKway
/*************************************************************************
* This function is the entry point for KWMETIS
**************************************************************************/
void METIS_mCPartGraphKway(int *nvtxs, int *ncon, idxtype *xadj, idxtype *adjncy,
idxtype *vwgt, idxtype *adjwgt, int *wgtflag, int *numflag,
int *nparts, floattype *rubvec, int *options, int *edgecut,
idxtype *part)
{
int i, j;
GraphType graph;
CtrlType ctrl;
if (*numflag == 1)
Change2CNumbering(*nvtxs, xadj, adjncy);
SetUpGraph(&graph, OP_KMETIS, *nvtxs, *ncon, xadj, adjncy, vwgt, adjwgt, *wgtflag);
if (options[0] == 0) { /* Use the default parameters */
ctrl.CType = McKMETIS_CTYPE;
ctrl.IType = McKMETIS_ITYPE;
ctrl.RType = McKMETIS_RTYPE;
ctrl.dbglvl = McKMETIS_DBGLVL;
}
else {
ctrl.CType = options[OPTION_CTYPE];
ctrl.IType = options[OPTION_ITYPE];
ctrl.RType = options[OPTION_RTYPE];
ctrl.dbglvl = options[OPTION_DBGLVL];
}
ctrl.optype = OP_KMETIS;
ctrl.CoarsenTo = amax((*nvtxs)/(20*log2Int(*nparts)), 30*(*nparts));
ctrl.nmaxvwgt = 1.5/(1.0*ctrl.CoarsenTo);
InitRandom(-1);
AllocateWorkSpace(&ctrl, &graph, *nparts);
IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl));
IFSET(ctrl.dbglvl, DBG_TIME, starttimer(ctrl.TotalTmr));
ASSERT(CheckGraph(&graph));
*edgecut = MCMlevelKWayPartitioning(&ctrl, &graph, *nparts, part, rubvec);
IFSET(ctrl.dbglvl, DBG_TIME, stoptimer(ctrl.TotalTmr));
IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl));
FreeWorkSpace(&ctrl, &graph);
if (*numflag == 1)
Change2FNumbering(*nvtxs, xadj, adjncy, part);
}
示例12: METIS_WPartGraphKway2
/*************************************************************************
* This function is the entry point for KWMETIS with seed specification
* in options[7]
**************************************************************************/
void METIS_WPartGraphKway2(idxtype *nvtxs, idxtype *xadj, idxtype *adjncy, idxtype *vwgt,
idxtype *adjwgt, idxtype *wgtflag, idxtype *numflag, idxtype *nparts,
float *tpwgts, idxtype *options, idxtype *edgecut, idxtype *part)
{
idxtype i, j;
GraphType graph;
CtrlType ctrl;
if (*numflag == 1)
Change2CNumbering(*nvtxs, xadj, adjncy);
SetUpGraph(&graph, OP_KMETIS, *nvtxs, 1, xadj, adjncy, vwgt, adjwgt, *wgtflag);
if (options[0] == 0) { /* Use the default parameters */
ctrl.CType = KMETIS_CTYPE;
ctrl.IType = KMETIS_ITYPE;
ctrl.RType = KMETIS_RTYPE;
ctrl.dbglvl = KMETIS_DBGLVL;
}
else {
ctrl.CType = options[OPTION_CTYPE];
ctrl.IType = options[OPTION_ITYPE];
ctrl.RType = options[OPTION_RTYPE];
ctrl.dbglvl = options[OPTION_DBGLVL];
}
ctrl.optype = OP_KMETIS;
ctrl.CoarsenTo = 20*(*nparts);
ctrl.maxvwgt = 1.5*((graph.vwgt ? idxsum(*nvtxs, graph.vwgt, 1) : (*nvtxs))/ctrl.CoarsenTo);
InitRandom(options[7]);
AllocateWorkSpace(&ctrl, &graph, *nparts);
IFSET(ctrl.dbglvl, DBG_TIME, InitTimers(&ctrl));
IFSET(ctrl.dbglvl, DBG_TIME, gk_startcputimer(ctrl.TotalTmr));
*edgecut = MlevelKWayPartitioning(&ctrl, &graph, *nparts, part, tpwgts, 1.03);
IFSET(ctrl.dbglvl, DBG_TIME, gk_stopcputimer(ctrl.TotalTmr));
IFSET(ctrl.dbglvl, DBG_TIME, PrintTimers(&ctrl));
FreeWorkSpace(&ctrl, &graph);
if (*numflag == 1)
Change2FNumbering(*nvtxs, xadj, adjncy, part);
}
示例13: LearnableParameter
LearnableParameter<ElemType>::LearnableParameter(const ScriptableObjects::IConfigRecordPtr configp) :
LearnableParameter(configp->Get(L"deviceId"), L"<placeholder>", configp->Get(L"shape"))
{
// TODO: Change dimensions to take a generic tensor instead. That will be a (minor) breaking change that will require fix-ups when converting from NDL to BrainScript.
AttachInputsFromConfig(configp, this->GetExpectedNumInputs());
// parameters[rows, [cols=1]] plus other optional parameters (learningRateMultiplier=[1|0|float], init=[uniform|gaussian|fixedvalue], initValueScale=[1|float], value=[0|float])
if (configp->Exists(L"learningRateMultiplier"))
SetLearningRateMultiplier(configp->Get(L"learningRateMultiplier"));
else if (configp->Exists(L"needsGradient") || configp->Exists(L"needGradient") || configp->Exists(L"computeGradient"))
InvalidArgument("Deprecated parameter names needsGradient|needGradient|computeGradient are not supported in BrainScript. Use learningRateMultiplier instead.");
wstring initString = configp->Get(L"init");
if (initString == L"fixedValue")
Value().SetValue((ElemType) configp->Get(L"value"));
else if (initString == L"uniform" || initString == L"gaussian")
{
// TODO: add these options also to old NDL
static unsigned long randomSeed = 1;
int forcedRandomSeed = configp->Get(L"randomSeed"); // forcing a specific random seed is useful for testing to get repeatable initialization independent of evaluation order
InitRandom((initString == L"uniform"), forcedRandomSeed < 0 ? randomSeed++ : (unsigned long) forcedRandomSeed, configp->Get(L"initValueScale"), configp->Get(L"initOnCPUOnly"));
}
else if (initString == L"fromFile")
{
wstring initFromFilePath = configp->Get(L"initFromFilePath");
if (initFromFilePath.empty())
RuntimeError("initFromFilePath parameter must be provided when using \"fromFile\" initialization method");
InitFromFile(initFromFilePath);
}
else if (initString == L"fromLiteral")
{
wstring initFromLiteral = configp->Get(L"initFromLiteral");
if (initFromLiteral.empty())
RuntimeError("initFromLiteral parameter must be provided when using \"fromLiteral\" initialization method");
size_t numRows, numCols;
auto array = File::LoadMatrixFromStringLiteral<ElemType>(msra::strfun::utf8(initFromLiteral), numRows, numCols);
InitFromArray(array, numRows, numCols);
}
else
RuntimeError("init must be one of the values of [ uniform | gaussian | fixedValue | fromFile ]");
}
示例14: main
int main(int argc, char *argv[])
{
#if HAVE_SETBUF
setbuf(stdin, NULL);
#endif
OpenLogFile("Amy.log");
InitMoves();
InitAll();
HashInit();
/*
* Process rc file first, then command line options. This way command
* line options can override rc file settings.
*/
ProcessRCFile();
ProcessOptions(argc, argv);
ShowVersion();
AllocateHT();
InitEGTB(EGTBPath);
RecogInit();
DoBookLearning();
Print(0, "\n");
strcpy(AutoSaveFileName, GetTmpFileName());
/* Ensure true random behavior. */
InitRandom(GetTime());
StateMachine();
return 0;
}
示例15: InitNumBit16Table
void Util::InitUtil() {
// num_bit16_table_[]を初期化する。
InitNumBit16Table();
// attack_table_***_[][]を初期化する。
InitAttackTable();
// pawn_move_[][]を初期化する。
InitPawnMove();
// pawn_2step_move_[][]を初期化する。
InitPawn2StepMove();
// pawn_attack_[][]を初期化する。
InitPawnAttack();
// knight_move_[]を初期化する。
InitKnightMove();
// bishop_move_[]を初期化する。
InitBishopMove();
// rook_move_[]を初期化する。
InitRookMove();
// king_move_[]を初期化する。
InitKingMove();
// ランダム関連を初期化する。
InitRandom();
}