int main(int argc, char **argv) { float Score; float BestScore = HugeScore; int p, i; SetupParams(argc, argv); clock_t Clock0; KK K1; // main KK class, for all data K1.penaltyMix = PenaltyMix; Clock0 = clock(); // start timer K1.LoadData(); // load .fet file // Seed random number generator srand(RandomSeed); // open distance dump file if required if (DistDump) Distfp = fopen("DISTDUMP", "w"); // start with provided file, if required if (*StartCluFile) { Output("Starting from cluster file %s\n", StartCluFile); BestScore = K1.CEM(StartCluFile, 1, 1); Output("%d->%d Clusters: Score %f\n\n", K1.nStartingClusters, K1.nClustersAlive, BestScore); for(p=0; p<K1.nPoints; p++) K1.BestClass[p] = K1.Class[p]; SaveOutput(K1.BestClass); } // loop through numbers of clusters ... for(K1.nStartingClusters=MinClusters; K1.nStartingClusters<=MaxClusters; K1.nStartingClusters++) for(i=0; i<nStarts; i++) { // do CEM iteration Output("Starting from %d clusters...\n", K1.nStartingClusters); Score = K1.Cluster(); Output("%d->%d Clusters: Score %f, best is %f\n", K1.nStartingClusters, K1.nClustersAlive, Score, BestScore); if (Score < BestScore) { Output("THE BEST YET!\n"); // New best classification found BestScore = Score; for(p=0; p<K1.nPoints; p++) K1.BestClass[p] = K1.Class[p]; SaveOutput(K1.BestClass); } Output("\n"); } SaveOutput(K1.BestClass); Output("That took %f seconds.\n", (clock()-Clock0)/(float) CLOCKS_PER_SEC); if (DistDump) fclose(Distfp); return 0; }
cgUIButton::cgUIButton(void) { SetupParams(); m_strName = "cgUIButton"; }
cgUIButton::cgUIButton( const string & strName ) { SetupParams(); m_strName = strName; }
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] ) { float Score; float BestScore = HugeScore; int p, i; SetupParams(nrhs,prhs); clock_t Clock0; KK K1; // main KK class, for all data K1.penaltyMix = PenaltyMix; Clock0 = clock(); // start timer K1.LoadData(prhs[0]); // load .fet file mwSize dim1[2] = {1,K1.nPoints}; plhs[0] = mxCreateNumericArray(2, dim1, mxDOUBLE_CLASS, mxREAL); double *OutputArray = mxGetPr(plhs[0]); // Seed random number generator srand(RandomSeed); // open distance dump file if required //if (DistDump) Distfp = fopen("DISTDUMP", "w"); // start with provided file, if required if (!mxIsEmpty(prhs[1])) { Output("Starting from existing clusters \n"); BestScore = K1.CEM(prhs[1], 1, 1); Output("%d->%d Clusters: Score %f\n\n", K1.nStartingClusters, K1.nClustersAlive, BestScore); for(p=0; p<K1.nPoints; p++) K1.BestClass[p] = K1.Class[p]; SaveOutput(K1.BestClass, OutputArray); } // loop through numbers of clusters ... for(K1.nStartingClusters=MinClusters; K1.nStartingClusters<=MaxClusters; K1.nStartingClusters++) for(i=0; i<nStarts; i++) { // do CEM iteration Output("Starting from %d clusters...\n", K1.nStartingClusters); Score = K1.Cluster(); Output("%d->%d Clusters: Score %f, best is %f\n", K1.nStartingClusters, K1.nClustersAlive, Score, BestScore); if (Score < BestScore) { Output("THE BEST YET!\n"); // New best classification found BestScore = Score; for(p=0; p<K1.nPoints; p++) K1.BestClass[p] = K1.Class[p]; SaveOutput(K1.BestClass, OutputArray); } Output("\n"); } SaveOutput(K1.BestClass, OutputArray); Output("That took %f seconds.\n", (clock()-Clock0)/(float) CLOCKS_PER_SEC); //if (DistDump) fclose(Distfp); }
bool CBettingGuy::MoveToNewNode( bool force ) { CGoalManager* pGoalManager = Game::GetGoalManager(); Dbg_Assert( pGoalManager ); uint32 minigameId = pGoalManager->GetRandomBettingMinigame(); if ( minigameId == 0 || minigameId == m_currentMinigame ) return false; uint32 node_checksum; Script::CStruct* p_minigame_params = pGoalManager->GetGoal( minigameId )->GetParams(); Dbg_Assert( p_minigame_params ); p_minigame_params->GetChecksum( "betting_guy_node", &node_checksum, Script::ASSERT ); if ( force ) { // move him! // printf("moving betting guy\n"); // record his suspend state and turn off suspension Reset(); m_currentMinigame = minigameId; SetupParams(); uint32 betting_guy_id; mp_params->GetChecksum( "betting_guy_id", &betting_guy_id, Script::ASSERT ); // Obj::CMovingObject* p_bet_guy = (Obj::CMovingObject*)(Obj::CMovingObject::m_hash_table.GetItem( betting_guy_id )); Obj::CMovingObject* p_bet_guy = (Obj::CMovingObject*)(Obj::CCompositeObjectManager::Instance()->GetObjectByID( betting_guy_id )); Dbg_Assert( p_bet_guy ); // Mick: removed this, as suspension handled differently under new components system // bool suspend_state = p_bet_guy->m_never_suspend; // p_bet_guy->m_never_suspend = true; Script::CStruct* p_temp_params = new Script::CStruct(); p_temp_params->AddChecksum( "goal_id", GetGoalId() ); p_temp_params->AddChecksum( "new_node", node_checksum ); Script::RunScript( "betting_guy_move_to_node", p_temp_params ); delete p_temp_params; // make sure he's updated and restore his suspension state p_bet_guy->Update(); // p_bet_guy->m_never_suspend = suspend_state; mp_params->AddChecksum( "current_minigame", minigameId ); m_currentNode = node_checksum; return true; } // printf("got a minigameId of %x\n", minigameId); // get the local skater's position Mdl::Skate * skate_mod = Mdl::Skate::Instance(); Obj::CSkater* pSkater = skate_mod->GetLocalSkater(); Dbg_Assert( pSkater ); Mth::Vector skater_pos = pSkater->GetPos(); // see if the skater is too close to the betting guy Mth::Vector current_pos; if ( m_currentNode ) { int current_node = SkateScript::FindNamedNode( m_currentNode ); SkateScript::GetPosition( current_node, ¤t_pos ); float d = ( skater_pos - current_pos ).LengthSqr(); // printf("square distance from the skater to the betting guy: %f\n", d); if ( d < vMINSQUAREDIST ) { // printf("the skater is too close to the betting guy\n"); return false; } } // try out the destination node // get the node's position int node = SkateScript::FindNamedNode( node_checksum ); Mth::Vector node_pos; SkateScript::GetPosition(node, &node_pos); // get the square of the distance between them float distSqr = ( skater_pos - node_pos ).LengthSqr(); // make sure it isn't too close // printf("sqaure distance from skater to next node: %f\n", distSqr); if ( distSqr < vMINSQUAREDIST ) { // printf("the skater is too close to the betting guy's destination node\n"); return false; } else { // move him! // printf("moving betting guy\n"); Reset(); m_currentMinigame = minigameId; SetupParams(); Script::CStruct* p_temp_params = new Script::CStruct(); p_temp_params->AddChecksum( "goal_id", GetGoalId() ); p_temp_params->AddChecksum( "new_node", node_checksum ); Script::RunScript( "betting_guy_move_to_node", p_temp_params ); delete p_temp_params; mp_params->AddChecksum( "current_minigame", minigameId ); m_currentNode = node_checksum; return true; } return false; }